Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a list of all the bootstrap classes on the JVM?

There is a method called findBootstrapClass for a ClassLoader that returns a Class if it is bootstrapped. Is there a way to find classes has been loaded?

like image 270
zcaudate Avatar asked Mar 21 '14 11:03

zcaudate


People also ask

What is bootstrap in JVM?

The Bootstrap class loader loads the basic runtime classes provided by the JVM, plus any classes from JAR files present in the system extensions directory. It is parent to the System class loader. To add JAR files to the system extensions, directory, see Using the Java Optional Package Mechanism.

Which loads all the classes into JVM?

At the root of the hierarchy, Java is the bootstrap class loader. It loads the system classes required to run the JVM itself.

What are bootstrap classes in Java?

Bootstrap classes are the classes that implement the Java 2 Platform. Bootstrap classes are in the rt. jar and several other jar files in the jre/lib directory. These archives are specified by the value of the bootstrap class path which is stored in the sun.

How many Classloaders are there in Java?

There are three types of built-in ClassLoader in Java.


1 Answers

You could try to first get the bootstrap class loader by e.g. calling

ClassLoader bootstrapLoader = ClassLoader.getSystemClassLoader().getParent();

and then get the classes of this class loader as explained here: How can I list all classes loaded in a specific class loader.

But note, that getting the bootstrap class loader is not reliable, because it may not explicitly exist. So ClassLoader.getSystemClassLoader().getParent() may return null, as explained in the Javadoc of ClassLoader#getParent():

Returns the parent class loader for delegation. Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class loader's parent is the bootstrap class loader.

like image 112
Balder Avatar answered Oct 05 '22 00:10

Balder