JVM crash using JNI

Post your Java discussions here
Post Reply
shenrotin
Newbie
Posts: 0
Joined: Mon Jul 15, 2013 11:40 am

JVM crash using JNI

Post by shenrotin »

Hello,

I'm trying to develop a simple wrapper for the PS5000a library. I'm using a picoscope 5444B. I'm developping under Windows 7 (x64).
I'm using MingW gcc to compile the C code. (32 bits)
I'm using the JDK 7 (32 bits). 32 bits is required because I don't have the 64 bits library (PS5000a.lib and PS5000a.dll)

Up to now, the implementation is really simple. I only have the function:

JNIEXPORT void JNICALL Java_com_iba_device_PicoNative_connect(JNIEnv * env, jobject object)
{
PICO_STATUS status;
UNIT unit;
status = ps5000aOpenUnit(&(unit->handle), NULL, PS5000A_DR_8BIT);
}

When I call this function from Java:
-I can hear that the software is communicating with the picoscope (a relay gets activated and the led turns green for a quick instant)
-I can see the typical "picoscope" splashscreen appearing, except that the progress bar is full and green.
-After a second, the JVM crashes, in the logfile, I can see:

# Problematic frame:
# C [ps5000a.dll+0x5ccd7] ps5000aCurrentPowerSource+0xf097

and

0x70cc0000 - 0x70d3a000 D:\Documents\Project\Tzigan\EclipseWS\Device\lib\PicoNative.dll
0x0f230000 - 0x0f5d0000 C:\Program Files (x86)\Pico Technology\PicoScope6\ps5000a.dll

If I call the same dll from an other EXE file, everything works and the splashscreen is normal (progress bar dashed and blue)

Did you meet a similar issue ? I wonder if the same system dll's are loaded in both cases.

Thanks.

Sébastien.

Hitesh

Re: JVM crash using JNI

Post by Hitesh »

Hi Sébastien,

An up to date version of the lib and dll files for 64-bit has been requested.

Is the DC power supply plugged in or are you you using the double-headed USB cable?

The progress bar appearing as green is fine (I get this with the 2000 and 3000a examples I have worked on).

It might be worth returning the status value into your Java code to see what is returned if anything.

I've attached my 3000a code below (Java and C) and will post the projects later. There is a PicoScope.jar file containing reusable classes. The code only handles opening a unit, displaying info and closing the unit.

Regards,
Attachments
PS3000a_Java.zip
PS3000a Java code
(16.83 KiB) Downloaded 806 times

shenrotin
Newbie
Posts: 0
Joined: Mon Jul 15, 2013 11:40 am

Re: JVM crash using JNI

Post by shenrotin »

Hi Hitesh,

Thanks for your code. I checked and it is really similar to mine.

1) Just to be clear: I built a dll: "PicoNative.dll" that implements the function "JNIEXPORT void JNICALL Java_com_iba_device_PicoNative_connect(JNIEnv * env, jobject object)"

-I'm calling this function from Java using the method "public native void connect()". This gives a crash.
-I'm calling this exact same function in the same dll from another C executable and it works perfectly.

2) I checked this with the double-head USB cable and with the external PS and it gives the same behaviour.

3) Unfortunately, the C function creating the problem ("ps5000aCurrentPowerSource") does not give back any status code (neither in C, neither in Java)

3) I used the tool DependencyWalker and I noticed I don't have the same system dll loaded in both cases:
a. When I execute the code from the EXE file (without java), the system loads the dll's from C:\Windows\System32
(VERSION.DLL, SETUPAPI.DLL,KERNEL32.DLL,USER32.DLL,GDI32.DLL,NTDLL.DLL,...)
b. When I execute the code from Java, the system loads the dll's from C:\Windows\SysWOW64\

I'm currently trying to force Java to load the same dll's, but without success until now. I'm also hoping that the 64-bits dll will solve this issue. If I can have this working, I will publish my wrapper.

Thanks a lot for your help.

Sébastien.

Hitesh

Re: JVM crash using JNI

Post by Hitesh »

Hi Sébastien,

I've uploaded the 64-bit dll and lib file to your original post in the C and C++ part:

http://www.picotech.com/support/post35685.html#p35685

It may be a case of how your path is setup.

Hope this helps.

shenrotin
Newbie
Posts: 0
Joined: Mon Jul 15, 2013 11:40 am

Re: JVM crash using JNI

Post by shenrotin »

Hi Hitesh,

It works! I finally have Java communicating with the pico, in 64 bits.

I didn't understand why the JVM-32 bits was behaving like this.

I'll post my wrapper when it will be completely developped.

Thanks again.

Sébastien.

Hitesh

Re: JVM crash using JNI

Post by Hitesh »

Hi,

Just an update to indicate that the JVM crash may have been due to a Stack Overflow Exception (this was seen with another Customer using the ps3000a driver with Java Native Access (JNA)).

The stack size in the Java Virtual Machine can be increased when calling the 'java' command e.g.

Code: Select all

java -Xss4m classname
The following drivers have been updated and will be available in a future SDK release:
  • ps2000a
  • ps3000a
  • ps4000a
  • ps5000a
  • ps6000
Hope this helps,

Post Reply