Java System.loadLibrary call on Linux freezes
I have a very small .so file (Available here: https://docs.google.com/leaf?id=0B4MxFm-ACB3INjhkMjhlNzktYzkxYy00Zjk5LTk0Y2MtZDE2MWQ2MzY1OWUy&hl=en_US&authkey=CMrJguwN)
I am trying to load this into Java on RHEL and the Java main
just freezes (No errors or exceptions). I have the directory with the .so file on the LD_LIBRARY_PATH, so I know it's actually trying to load it.
Any ideas how I can troubleshoot this?
public class SmallTester {
public static void main(String[] args){
for(String s: System.getenv("LD_LIBRARY_PATH").split(":")){
System.out.println(s);
}
System.loadLibrary("TestAda");
System.out.println("Here");
}
}
EDIT:
Based on the post below, I did a strace.. It looks like its repeating this call over and over again (I'm not sure what this means though?):
[pid 31464] clock_gettime(CLOCK_MONOTONIC, {3605675, 624255544}) = 0
[pid 31464] gettimeofday({1306417113, 168967}, NULL) = 0
[pid 31464] clock_gettime(CLOCK_MONOTONIC, {3605675, 624435576}) = 0
[pid 31464] clock_gettime(CLOCK_MONOTONIC, {3605675, 624518205}) = 0
[pid 31464] gettimeofday({1306417113, 169216}, NULL) = 0
[pid 31464] clock_gettime(CLOCK_REALTIME, {1306417113, 169306590}) = 0
[pid 31464] futex(0x88b3f04, FUTEX_WAIT_PRIVATE, 1, {0, 49909410}) = -1 ETIMEDOUT (Connection timed out)
Here is a full version of the log: https://docs.google.com/leaf?id=0B4MxFm-ACB3IYzdhZWIwNWEtYjUzMS00NGM5LWEzZjQtYzMzOWE3MWNhYWQ0&hl=en_US&authkey=CJ-Lv_wG
EDIT2: I tried to load the library with JNA as well:
public class SmallTesterJNA {
public interface CLibrary extends Library {
CLibrary INSTANCE1 = (CLibrary)
Native.loadLibrary("TestAda", // <<< our library goes here
CLibrary.class);
}
public static void main(String[] args){
for(String s: System.getenv("LD_LIBRARY_PATH").split(":")){
System.out.println(s);
}
System.loadLibrary(CLibrary.INSTANCE1.toString());
System.out.println("Here");
}
}
Here is the output.. It looks very similar: https://docs.google.com/leaf?id=0B4MxFm-ACB3IYzdhZWIwNWEtYjUzMS00NGM5LWEzZjQtYzMzOWE3MWNhYWQ0&hl=en_US&authkey=CJ-Lv_wG
Edit2:
Here is my gcore output attached to the process.. not sure what this is telling me:
(no debugging symbols found)
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
[New Thread 0xb7fb26c0 (LWP 8326)]
[New Thread 0x7fa8eb90 (LWP 8340)]
[New Thread 0x7fe2db90 (LWP 8339)]
[New Thread 0x7fe7eb90 (LWP 8338)]
[New Thread 0x7feffb90 (LWP 8337)]
[New Thread 0x800afb90 (LWP 8336)]
[New Thread 0x80100b90 (LWP 8335)]
[New Thread 0x80351b90 (LWP 8334)]
[New Thread 0x803a2b90 (LWP 8333)]
[New Thread 0x80423b90 (LWP 8332)]
[New Threa开发者_运维知识库d 0x8066db90 (LWP 8331)]
[New Thread 0x806eeb90 (LWP 8330)]
[New Thread 0x8076fb90 (LWP 8329)]
[New Thread 0x807f0b90 (LWP 8328)]
[New Thread 0xb7474b90 (LWP 8327)]
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
0xb7fcd402 in __kernel_vsyscall ()
Saved corefile core.8326
If I had to guess, I'd say that a likely culprit is the shared object's initialization code.
Grab a core dump of your JVM process (using gcore
) or attach gdb
to get the stack trace of where exactly it's freezing.
I usually try strace before gdb (tracing all system calls). Execute:
strace -f java SmallTester > logfile 2>&1
You will get a lot of info in logfile, the last part is the most interesting. You will find the jvm process looking for your TestAda.so file and see if it successfully loaded the .so file. If this doesn't work, revert to gdb.
Have a look at your JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
function in your C++ code. It might have an infinite loop :) Also try defining this if it isn't defined already.
See here for details about JNI_OnLoad
.
精彩评论