Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How IBM JVM classloaders hold classes?

In HotSpot JVM java.lang.Classloader class has a Vector of all classes loaded by this classloader. And so all classes are held in memory as long as their's classloader is alive. In IBM JVM J9's java.lang.Classloader there is no such field. At least I was unable to find one. So my questions are:

  1. Where does IBM JVM's classloaders hold class cache?

  2. If differs from the point above: what hard-references classes in IBM JVM, thus preventing from unloading?

like image 727
Nikem Avatar asked Oct 22 '22 21:10

Nikem


2 Answers

Looking at the code of my IBM JVM it seems that java.lang.ClassLoader is an abstract class, so it will be implemented somewhere. Using the debugger I found that is a synthetic class called sun.misc.Launcher$AppClassLoader.
Then, to retrieve a class there is a native method
private native Class findLoadedClassImpl(String className);
so it seems the caching is done outside Java, in a native method.

At the beginning of loadClass method I see:

// Ask the VM to look in its cache.
Class loadedClass = findLoadedClass(className);

then it checks whether loadedClass is null, and if so tries to use the parent clasloader.
So, I'd say that, unless the method is overridden by the inheriting classloader, caching happens outside Java, in some native component of IBM VM.

like image 81
Jacopofar Avatar answered Oct 31 '22 20:10

Jacopofar


The IBM J9 JVM has no PermGen on Heap and stores Classes in native memory. You can use -Xdump to generate a javacore.* file, it will contain a list of all classloaders and classes.

BTW: Java8 will do a similiar thing.

like image 36
eckes Avatar answered Oct 31 '22 20:10

eckes