Test and Measurement Forum

JVM crash using JNI

Post your Java discussions here

JVM crash using JNI

Postby shenrotin » Thu Jul 18, 2013 3:45 pm

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.
shenrotin
Newbie
 
Posts: 0
Joined: Mon Jul 15, 2013 11:40 am

Re: JVM crash using JNI

Postby Hitesh » Thu Jul 18, 2013 4:16 pm

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 161 times
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: JVM crash using JNI

Postby shenrotin » Fri Jul 19, 2013 9:52 am

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.
shenrotin
Newbie
 
Posts: 0
Joined: Mon Jul 15, 2013 11:40 am

Re: JVM crash using JNI

Postby Hitesh » Fri Jul 19, 2013 12:28 pm

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.
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: JVM crash using JNI

Postby shenrotin » Fri Jul 19, 2013 2:45 pm

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.
shenrotin
Newbie
 
Posts: 0
Joined: Mon Jul 15, 2013 11:40 am

Re: JVM crash using JNI

Postby Hitesh » Fri Oct 03, 2014 12:57 pm

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,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire


Return to Java

Who is online

Users browsing this forum: No registered users and 0 guests