Search code examples
javadllcrashjava-native-interfacehid

java hid communication dll makes jvm crash


I am developing an application in Java that needs to communicate with a microprocessor msp430 from TI. To communicate with the device, I use the hidDemo java code and the DLL provided (that uses the hid API C code).

My problem is that I get errors at the DLL level that crash the JVM. Problems occurs when I'm communicating with the device, and when I unplug the device.

I have tried to handle the error at the DLL level with no success. I also tried recompiling the DLL with a newer hid API version; still no luck.

The error trace generated by the JRE is the following:

Instructions: (pc=0x74672874) 0x74672864:
[error occurred during error reporting (printing registers, top of stack, instructions near pc), id 0xc0000005]

Stack: [0x4f7c0000,0x4f9c0000], sp=0x4f9bf1c0, free space=2044k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C 0x74672874 C [hidcommunicationmanager.dll+0x11db3] C [hidcommunicationmanager.dll+0x13844] j com.ti.msp430.usb.hiddemo.management.HidCommunicationManager.getSerialsForVidPid(II)[Ljava/lang/String;+0

The error is an EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x74672874, pid=3336, tid=5444, which is like a NullPointer exception.

Any tips on how to solve this?


Solution

  • Java doesn't allow you trap memory errors created in DLLs.

    What you can do is start another process to run the DLL in. This can be useful if say you have a 32-bit DLL and a 64-bit JVM, or a thrid party library you don't trust (JAR or DLL)

    You can communicate with the JVM you start up via pipes, sockets or shared memory. If the process dies, your main program keeps running and it can restart the process.