JVM Crash (SIGSEGV/SIGACCERR)

1,129 views
Skip to first unread message

Tim Cronin

unread,
Mar 28, 2016, 3:35:55 PM3/28/16
to usb4java
Hello,

This does not occur on Windows, but does occur on Linux.  It also occurs intermittently, but often (meaning when it happens it's not always in the same spot and it doesn't always happen).  I've seen it crash is two separate places since analyzing.  Is it a problem to pass context/devices/handles as references - I'm still closing them when necessary?  What else am I missing?

Main Error (STDERR) 
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f3cb30d071f, pid=5313, tid=139898936805120
#
# JRE version: Java(TM) SE Runtime Environment (8.0_72-b15) (build 1.8.0_72-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.72-b15 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libusb4java.so+0x1c71f]  libusb_submit_transfer+0x1ef
#
# Core dump written. Default location: /tmp/core or core.5313
#
# An error report file with more information is saved as:
# /tmp/hs_err_pid5313.log

In the hs_err log:
 ---------------  T H R E A D  ---------------

Current thread (0x00007f3ceb14b000):  JavaThread "printManagerExecutorService-1" [_thread_in_native, id=5505, stack(0x00007f3cc25ec000,0x00007f3cc26ed000)]

siginfo: si_signo: 11 (SIGSEGV), si_code: 2 (SEGV_ACCERR), si_addr: 0x00007f3d003b0010
[...]
Stack: [0x00007f3cc25ec000,0x00007f3cc26ed000],  sp=0x00007f3cc26e9720,  free space=1013k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libusb4java.so+0x1c71f]  libusb_submit_transfer+0x1ef

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.usb4java.LibUsb.bulkTransfer(Lorg/usb4java/DeviceHandle;BLjava/nio/ByteBuffer;Ljava/nio/IntBuffer;J)I+0
j  com.company.connections.usb.UsbConnection.sendData([B)V+69 
[...] 

System Info
USB4Java 1.2.0

java -version
java version "1.8.0_72"
Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)

cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.7 (Santiago)

Two places where this has occurred in code
public static DeviceHandle createDeviceHandle(Device device) throws LibUsbException {
   
DeviceHandle handle = new DeviceHandle();
   
if(device != null){
       
int result = LibUsb.open(device, handle);  // <=== RIGHT HERE
       
if (result != LibUsb.SUCCESS) {
           
throw new LibUsbException("Unable to open USB device", result);
        }
   
} else {
         LOG
.error("Unable to create a USB device handle because no device was specified.");
   
}
   
   
return handle;
}

try {
   
ByteBuffer buffer = ByteBuffer.allocateDirect(data.length);
    buffer
.put(data);
   
IntBuffer transfered = IntBuffer.allocate(1);
   
int result = LibUsb.bulkTransfer(handle, endpoint, buffer, transfered, connTimeout); // <=== RIGHT HERE
   
if (result != LibUsb.SUCCESS) {
       
throw new LibUsbException("Bulk transfer failed", result);
   
}
} catch (LibUsbException e) {
   
String detailMsg = "Failed to send data to device: " + usbConnectionData.getDisplayName() + ". Error: "+ e.getLocalizedMessage();
    LOG
.error(detailMsg);
}

Tim Cronin

unread,
Mar 28, 2016, 4:05:12 PM3/28/16
to usb4java
I've now seen it in LibUsb.close() as well

Stack: [0x00007fdcdaecf000,0x00007fdcdafd0000],  sp=0x00007fdcdafcdea0,  free space=1019k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libusb4java.so+0x19c8f]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.usb4java.LibUsb.close(Lorg/usb4java/DeviceHandle;)V+0

public static void destroyDeviceHandle(Usb4JavaConnectionData connData){
    if(connData.getHandle() != null){
        LibUsb.close(connData.getHandle());
    }
    
    connData
.setHandle(null);
}

Tim Cronin

unread,
Mar 29, 2016, 4:36:06 PM3/29/16
to usb4java
More info:

I found that some of this is a timing issue.  The crashes that occur in open don't seem to happen if I add a Thread.sleep().  So, rather than discovering devices by opening a handle and closing it, I include the handle to the device along with metadata about the device.  With this, I can use the same handles to access the device multiple times.  This seems to get around the SIGSEGV issues occurring with an ACCERR.  However, now I get alternating seg faults in bulkTransfer:

siginfo: si_signo: 11 (SIGSEGV), si_code: 128 (SI_KERNEL), si_addr: 0x0000000000000000
siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000000000008

Anybody have any ideas?  Maybe I'll have to try async transfers?

I'll keep at it, in any case.

Thanks,
Tim

On Monday, March 28, 2016 at 3:35:55 PM UTC-4, Tim Cronin wrote:

Tim Cronin

unread,
Mar 29, 2016, 6:36:03 PM3/29/16
to usb4java
I'm now debugging with GDB while my program is running, but it's difficult without the debug symbols.  Is there a pre-built .so with debug symbols or is that something that I need to build?

Thanks,
Tim

Stel Al

unread,
Jun 2, 2016, 3:20:09 AM6/2/16
to usb4java
Hello I have this code package prospa8wusb;

import org.usb4java.Device;
import org.usb4java.DeviceDescriptor;
import org.usb4java.DeviceList;
import org.usb4java.LibUsb;
import org.usb4java.LibUsbException;

public class Test {

public static void main(String[] args) {
findDevice((short)0x0BDA,(short)0x0129);

}
public static Device findDevice(short vendorId, short productId)
{
   // Read the USB device list
   DeviceList list = new DeviceList();
   int result = LibUsb.getDeviceList(null, list);
   if (result < 0) throw new LibUsbException("Unable to get device list", result);

   try
   {
       // Iterate over all devices and scan for the right one
       for (Device device: list)
       {
           DeviceDescriptor descriptor = new DeviceDescriptor();
           result = LibUsb.getDeviceDescriptor(device, descriptor);
           if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to read device descriptor", result);
           if (descriptor.idVendor() == vendorId && descriptor.idProduct() == productId) return device;
       }
   }
   finally
   {
       // Ensure the allocated device list is freed
       LibUsb.freeDeviceList(list, true);
   }

   // Device not found
   return null;
}
}


and this message when i compile the code

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000000000000, pid=4036, tid=10048
#
# JRE version: Java(TM) SE Runtime Environment (8.0_91-b14) (build 1.8.0_91-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.91-b14 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  0x0000000000000000
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\stelios\workspace\prospa8wusb\hs_err_pid4036.log
#
# If you would like to submit a bug report, please visit:
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
Reply all
Reply to author
Forward
0 new messages