I am currently having the problem that I have a (partial) program that is trying to load a class but fails because it cannot find this class. Looking at the stack trace, I cannot see any particular reason for why the VM tries to load this particular class at the first place. Are there any tools that would let me figure out why a particular class is being loaded?
Hint:
I am already getting a stack trace at the exact point where the JVM tries to load the class (through an agent). However, the stack trace contains no line numbers. Therefore I only know which method triggers the class being loaded, not which statement. Then, even knowing the statement may not be enough. A single statement can cause a class to be loaded in many ways, because sometimes the VM needs to load part of the transitive closure of classes.
Run your program with the
-XX:+TraceClassLoadingand-XX:+TraceClassResolutionflags. This will create a LOT of output that looks like the following:You’ll need to trace the chain of RESOLVE messages for a particular class. Or more likely, you’ll see an error when your program attempts to load the class, preceeded by resolve messages for the class that loads it).