JNI call crashes the JVM

Solly Ezekiel sol_ezekiel@yahoo.com
Sun Nov 7 04:59:00 GMT 2004


I've searched the archives for an answer to this
question without success, so maybe this is a new
problem after all...

What I'm trying to do: Call gettimeofday() from Java
via JNI.

Why I'm doing this: System.currentTimeMillis() isn't
accurate enough.  It appears to have an accuracy of
only about 10 ms under XP.  I want 1 ms accuracy or
better, and unfortunately, the various "real-time"
extensions to Java (like javax.realtime) rely on
System.currentTimeMills().

What I've tried: I wrote a native Java method, wrote a
C++ body that calls gettimeofday(), compiled and
linked as described at
http://www.inonit.com/cygwin/jni/helloWorld/, loaded
the DLL using System.loadLibrary(), and made the call
from Java.  I'm using Cygwin v1.5.11-1, g++ v3.3.3-3
and Mingw32 v20040810-1.

What happened: The call to System.loadLibrary() never
returns.

What I tried next: Using the 'ar' command, I extracted
only the .o files I needed from libc.a (I also tried
doing the same with libcygwin.a) and linked them into
the DLL.

What happened: System.loadLibrary returned fine, but
when I called gettimeofday() the JVM crashed with an
access violation.

What I tried next: I figured the DLL wasn't getting
initialized when it was being loaded, so I added a
call to cygwin_dll_init().  (I had to add a few more
.o files for that to link.)

What happened: Again, System.loadLibrary() returned
fine, but when I called cygwin_dll_init() the JVM once
again crashed with an access violation.

So, that's where I am.  I could delve into the innards
of Cygwin to figure out what is (or isn't) happening,
but I don't really have the time to do that.  Has
anyone tried to do what I'm doing, and do you have any
wisdom you can share?  I can't be the first person to
have tried making calls to the Cygwin DLLs from JNI...
can I?

Thanks,
Sol Ezekiel



		
__________________________________ 
Do you Yahoo!? 
Check out the new Yahoo! Front Page. 
www.yahoo.com 
 


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list