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?
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.
At the root of the hierarchy, Java is the bootstrap class loader. It loads the system classes required to run the JVM itself.
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.
There are three types of built-in ClassLoader in Java.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With