Skip to main content

Verbose class loading

At work, a couple of long time experience Java devs were having build issues. They didn't know where their build system was pulling in a class from.
They didn't know that the JVM has a verbose class loading option.

If you run java -h, you will see this in the output:

    -verbose:[class|gc|jni]
                 enable verbose output

If you invoke your JVM like this:

java -verbose:class myHelloWorld

then the output will be very verbose as the class loader prints out detailed of all the classes loaded during startup and during the finding and running of your class.

e.g.

[Loaded java.net.URLConnection from /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar]
[Loaded sun.net.www.URLConnection from /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar]
[Loaded sun.net.www.protocol.file.FileURLConnection from /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar]
[Loaded sun.net.www.MessageHeader from /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar]
[Loaded java.io.FilePermission from /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar]



References:



Popular posts from this blog

Overcome Java JNI gdb errors on GNU/Linux

If you happen to try to debug any Java JNI programs using gdb on GNU/Linux you will soon come across error messages. For example : $ gdb --args java MyJavaProgramUsingJNI cannot find user-level thread for LWP nnn: generic error warning: Cannot initialize thread debugging library: versions of libpthread and libthread_db do not match The reason for this is that the java program mucks around with LD_LIBRARY_PATH and that prevents gdb from running correctly. To overcome this, you have to run your Java program and place a pause in the Java code, such as reading a key, and then in another shell, run gdb to attach to the running Java process. You can then set your breakpoint on your JNI code and debug it. Here is an example : Compile your Java program: $ javac JNITest.java Generate the JNI header file: $ javah -jni JNITest.java Create and compile your C code library: $ cat jnilib.c #include "JNITest.h" JNIEXPORT jint JNICALL Java_JNITest_addValues( JNIEnv...