Recent Changes - Search:

edit SideBar

RxTxHanging

The simple test at https://github.com/NeuronRobotics/nrjavaserial seems to hang.

Example Code From GitHub

The code at https://github.com/NeuronRobotics/nrjavaserial is

String port = "COM3";
int baudRate = 115200;
NRSerialPort serial = new NRSerialPort(port, baudRate);
serial.connect();

DataInputStream ins = new DataInputStream(serial.getInputStream());
DataOutputStream outs = new DataOutputStream(serial.getOutputStream());

byte b = ins.read();
outs.write(b);

serial.disconnect();

Example Code in PTII

The above code needs modifications to run, so we created $PTII/ptolemy/actor/lib/jjs/modules/serial/SerialTest.java:

public class SerialTest {
    public static void main(String [] args) throws Exception {

        String port = "/dev/tty.Bluetooth-Incoming-Port";

        if (args.length != 1) {
            System.err.println("Usage: java -classpath $PTII:${PTII}/lib/nrjavaserial-3.11.0.jar ptolemy.actor.lib.io.comm.SerialTest /dev/tty");
            System.err.println("Below are the ports:");
            // Enumerate the available ports.                                                                
            Enumeration ports = CommPortIdentifier.getPortIdentifiers();
            while (ports.hasMoreElements()) {
                CommPortIdentifier identifier = (CommPortIdentifier) ports
                    .nextElement();
                if (identifier.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                    System.err.println(identifier.getName());
                }
            }
            StringUtilities.exit(1);
        } else {
            port = args[0];
        }

        int baudRate = 9600;
        NRSerialPort serialPort = new NRSerialPort(port, baudRate);
        serialPort.connect();
        System.out.println("Connected to " + serialPort);

        DataInputStream inputStream = new DataInputStream(serialPort.getInputStream());
        DataOutputStream outputStream = new DataOutputStream(serialPort.getOutputStream());

        byte b = (byte)inputStream.read();
        System.out.println("Read a byte: " + b);
        outputStream.write(b);
        System.out.println("Wrote a byte: " + b);

        serialPort.disconnect();
        System.out.println("Called serialPort.disconnect()");
    }
}

Hangs Under Mac OS X

Under Mac OS X 10.11.1, which I run the program, it calls disconnect but does not end

bash-3.2$ java -classpath $PTII:${PTII}/lib/nrjavaserial-3.11.0.jar ptolemy.actor.lib.jjs.modules.serial.test.SerialTest /dev/cu.usbserial-DA01R74U
java -classpath $PTII:${PTII}/lib/nrjavaserial-3.11.0.jar ptolemy.actor.lib.jjs.modules.serial.test.SerialTest /dev/cu.usbserial-DA01R74U
Connected to gnu.io.NRSerialPort@28a418fc
Read a byte: -1
Wrote a byte: -1
Called serialPort.disconnect()

If I hit Control-Z, put it in the background and use kill -3 %3 to get a stack trace, I see that a thread is running:

  ^Z
[3]+  Stopped                 java -classpath $PTII:${PTII}/lib/nrjavaserial-3.11.0.jar ptolemy.actor.lib.jjs.modules.serial.test.SerialTest /dev/cu.usbserial-DA01R74U
bash-3.2$ bg
bg
[3]+ java -classpath $PTII:${PTII}/lib/nrjavaserial-3.11.0.jar ptolemy.actor.lib.jjs.modules.serial.test.SerialTest /dev/cu.usbserial-DA01R74U &
bash-3.2$ kill -3 %3
kill -3 %3
bash-3.2$ 2015-12-07 12:38:44
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.65-b01 mixed mode):

"DestroyJavaVM" #11 prio=5 os_prio=31 tid=0x00007fd36d044000 nid=0x1703 waiting on condition [0x0000000000000\
000]
   java.lang.Thread.State: RUNNABLE

"Thread-0" #10 prio=5 os_prio=31 tid=0x00007fd36c04b000 nid=0x5b03 runnable [0x00007000015d5000]
   java.lang.Thread.State: RUNNABLE
        at gnu.io.RXTXPort.eventLoop(Native Method)
        at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1611)

"Service Thread" #9 daemon prio=9 os_prio=31 tid=0x00007fd36d822000 nid=0x5203 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C1 CompilerThread3" #8 daemon prio=9 os_prio=31 tid=0x00007fd36d821800 nid=0x5003 waiting on condition [0x00\
00000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread2" #7 daemon prio=9 os_prio=31 tid=0x00007fd36d001000 nid=0x4e03 waiting on condition [0x00\
00000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" #6 daemon prio=9 os_prio=31 tid=0x00007fd36c810000 nid=0x4c03 waiting on condition [0x00\
00000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #5 daemon prio=9 os_prio=31 tid=0x00007fd36c032800 nid=0x4a03 waiting on condition [0x00\
00000000000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" #4 daemon prio=9 os_prio=31 tid=0x00007fd36c01b800 nid=0x3e0f waiting on condition [0x000\
0000000000000]
   java.lang.Thread.State: RUNNABLE
"Finalizer" #3 daemon prio=8 os_prio=31 tid=0x00007fd36c838000 nid=0x3803 in Object.wait() [0x0000700000d3a00\
0]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x000000076ab070b8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
        - locked <0x000000076ab070b8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)

"Reference Handler" #2 daemon prio=10 os_prio=31 tid=0x00007fd36c837000 nid=0x3603 in Object.wait() [0x000070\
0000c37000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x000000076ab06af8> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:502)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:157)
        - locked <0x000000076ab06af8> (a java.lang.ref.Reference$Lock)

"VM Thread" os_prio=31 tid=0x00007fd36c834800 nid=0x3403 runnable

"GC task thread#0 (ParallelGC)" os_prio=31 tid=0x00007fd36c013800 nid=0x2403 runnable

"GC task thread#1 (ParallelGC)" os_prio=31 tid=0x00007fd36c014000 nid=0x2603 runnable

"GC task thread#2 (ParallelGC)" os_prio=31 tid=0x00007fd36c015000 nid=0x2803 runnable

"GC task thread#3 (ParallelGC)" os_prio=31 tid=0x00007fd36c802800 nid=0x2a03 runnable

"GC task thread#4 (ParallelGC)" os_prio=31 tid=0x00007fd36c803000 nid=0x2c03 runnable

"GC task thread#5 (ParallelGC)" os_prio=31 tid=0x00007fd36c803800 nid=0x2e03 runnable

"GC task thread#6 (ParallelGC)" os_prio=31 tid=0x00007fd36c804800 nid=0x3003 runnable

"GC task thread#7 (ParallelGC)" os_prio=31 tid=0x00007fd36c805000 nid=0x3203 runnable

"VM Periodic Task Thread" os_prio=31 tid=0x00007fd36d823000 nid=0x5403 waiting on condition

JNI global references: 6
Heap
 PSYoungGen      total 76288K, used 7864K [0x000000076ab00000, 0x0000000770000000, 0x00000007c0000000)
  eden space 65536K, 12% used [0x000000076ab00000,0x000000076b2ae3a8,0x000000076eb00000)
  from space 10752K, 0% used [0x000000076f580000,0x000000076f580000,0x0000000770000000)
  to   space 10752K, 0% used [0x000000076eb00000,0x000000076eb00000,0x000000076f580000)
 ParOldGen       total 175104K, used 0K [0x00000006c0000000, 0x00000006cab00000, 0x000000076ab00000)
  object space 175104K, 0% used [0x00000006c0000000,0x00000006c0000000,0x00000006cab00000)
 Metaspace       used 3070K, capacity 4664K, committed 4864K, reserved 1056768K
  class space    used 337K, capacity 424K, committed 512K, reserved 1048576K

If, in the Mac OS X Activity Monitor, I select the java process (consuming 100% of my cpu) and select sample and search for RxTX, I get:

                       2683 JavaCalls::call_helper(JavaValue*, methodHandle*, JavaCallArguments*, Thread*)  (in libjvm.dylib) + 1710  [0x1078eab02]
                          2683 ???  (in <unknown binary>)  [0x1085897a7]
                            2683 ???  (in <unknown binary>)  [0x108590c4d]
                              2683 ???  (in <unknown binary>)  [0x10859e954]
                                2501 Java_gnu_io_RXTXPort_eventLoop  (in libNRJavaSerial.jnilib) + 263  [0x124fa2317]
                                ! 2427 __select  (in libsystem_kernel.dylib) + 10  [0x7fff8d4b2222]
                                ! 33 cerror  (in libsystem_kernel.dylib) + 5,6,...  [0x7fff8d4ad419,0x7fff8d4ad41a,...]
                                ! 20 cerror  (in libsystem_kernel.dylib) + 13  [0x7fff8d4ad421]
                                ! : 15 _pthread_exit_if_canceled  (in libsystem_pthread.dylib) + 0,37,...  [0x7fff8b1e1c13,0x7fff8b1e1c38,...]
                                ! : 5 _pthread_exit_if_canceled  (in libsystem_kernel.dylib) + 0  [0x7fff8d49c398]
                                ! 11 select$1050  (in libsystem_kernel.dylib) + 0,30  [0x7fff8d4af8c9,0x7fff8d4af8e7]
                                ! 5 _pthread_exit_if_canceled  (in libsystem_kernel.dylib) + 7,10  [0x7fff8d49c39f,0x7fff8d49c3a2]
                                ! 5 cerror_nocancel  (in libsystem_kernel.dylib) + 22  [0x7fff8d4ad405]
                                91 Java_gnu_io_RXTXPort_eventLoop  (in libNRJavaSerial.jnilib) + 263,281,...  [0x124fa2317,0x124fa2329,...]
                                46 Java_gnu_io_RXTXPort_eventLoop  (in libNRJavaSerial.jnilib) + 336  [0x124fa2360]
                                ! 46 initialise_event_info_struct  (in libNRJavaSerial.jnilib) + 431,475,...  [0x124fa202f,0x124fa205b,...]
                                18 __error  (in libsystem_kernel.dylib) + 9,12  [0x7fff8d4ad3e0,0x7fff8d4ad3e3]
                                12 DYLD-STUB$$__error  (in libNRJavaSerial.jnilib) + 0  [0x124fa3c94]
                                6 Java_gnu_io_RXTXPort_eventLoop  (in libNRJavaSerial.jnilib) + 278  [0x124fa2326]
                                ! 6 __error  (in libsystem_kernel.dylib) + 23  [0x7fff8d4ad3ee]
                                4 Java_gnu_io_RXTXPort_eventLoop  (in libNRJavaSerial.jnilib) + 297  [0x124fa2339]
                                ! 4 __error  (in libsystem_kernel.dylib) + 23,0  [0x7fff8d4ad3ee,0x7fff8d4ad3d7]
                                4 __select  (in libsystem_kernel.dylib) + 12,0  [0x7fff8d4b2224,0x7fff8d4b2218]
                                1 DYLD-STUB$$select$1050  (in libNRJavaSerial.jnilib) + 0  [0x124fa3d66]
 

Source Code that is hanging.

We are using https://github.com/NeuronRobotics/nrjavaserial

The trace above:

                                2501 Java_gnu_io_RXTXPort_eventLoop  (in libNRJavaSerial.jnilib) + 263  [0x124fa2317]
                                ! 2427 __select  (in libsystem_kernel.dylib) + 10  [0x7fff8d4b2222]
                                ! 33 cerror  (in libsystem_kernel.dylib) + 5,6,...  [0x7fff8d4ad419,0x7fff8d4ad41a,...]
                                ! 20 cerror  (in libsystem_kernel.dylib) + 13  [0x7fff8d4ad421]

shows that the native code Java_gnu_io_RXTXPort_eventLoop() is looping

Interestingly, https://github.com/NeuronRobotics/nrjavaserial/tree/master/src/main/c/src shows a recent Mac OS X update:

   SerialImp.c 	Mark defunct ports as closing on OS X. 	17 days ago

Bingo! https://github.com/NeuronRobotics/nrjavaserial/tree/master/src/main/c/src says:

MrDOS Mark defunct ports as closing on OS X. …
Without this, CPU usage goes to 100% and stays there on OS X after calling CommPort.close().

The change to src/main/c/src/SerialImp.c from https://github.com/NeuronRobotics/nrjavaserial/commit/74c4f8c77caf51134d52445f6af16230ca14bd5e#diff-665a7a30164f5c2dc46596d456077413 is below:


@@ -4929,7 +4929,8 @@ JNIEXPORT void JNICALL RXTXPort(interruptEventLoop)(JNIEnv *env,
        to close indefinetly.
        */
 #if defined(__APPLE__)
-       //If you continue on in OSX you get an invalid memory access error
+       index->closing = 1;
+       /* Continuing on OS X causes an invalid memory access. */
        return;
 #endif
        if (index->drain_loop_running != 0) {

You can see that cerror() is getting called, so this probably has something to do with it.

On to nrjavaserial for building.

Edit - History - Print - Recent Changes - Search
Page last modified on December 07, 2015, at 01:33 PM