1

I'm trying to figure out how to unload classes.

Unloading classes in java?

However, I wish to be able to figure out what classes are already loaded. How can this be found?

Community
  • 1
  • 1
zcaudate
  • 13,998
  • 7
  • 64
  • 124

2 Answers2

1

Watch the method getInitiatedClasses:

http://docs.oracle.com/javase/7/docs/api/java/lang/instrument/Instrumentation.html

Andres
  • 10,561
  • 4
  • 45
  • 63
  • Hi Andres... How would I be able to get n instance of the Instrumentation object? I need to do it after jVM startup but not sure how this can be done – zcaudate Jan 01 '14 at 19:22
  • Watch this: http://javaevangelist.blogspot.com.es/2013/04/determining-what-classes-are-loaded-by.html – Andres Jan 01 '14 at 19:33
1

Only as an alternative to Andres answer you can turn on -verbose:class and redirect stdout to a file. There we'll get this log

...
[Loaded java.lang.Object from C:\Program Files\Java\jre7\lib\rt.jar]
[Loaded java.io.Serializable from C:\Program Files\Java\jre7\lib\rt.jar]
[Loaded java.lang.Comparable from C:\Program Files\Java\jre7\lib\rt.jar]
...

We can extract a class name, load it

Class cls = Class.forName(className); 

if cls.getClassLoader() returns null it was loaded with bootstrap class loader.

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275