How to debug JVM resources loading?

13,727

Solution 1

I suppose you need to look at using a profiler. Or something that uses the instrumentation interface.

Not sure how stable it is, but there is BTrace, which is kind of a Java version of DTrace.

BTrace is a safe, dynamic tracing tool for the Java platform. BTrace can be used to dynamically trace a running Java program. BTrace dynamically instruments the classes of the target application to inject tracing code ("bytecode tracing"). Tracing code is expressed in Java programming language.

If you are doing this on a development machine, and the number of events (resources being loaded) is not too frequent, you could also just set a breakpoint in the debugger.

Solution 2

Resources are provided as URLs. So, I guess to do it in "pure" Java: Install a custom ClassLoader that copies URLs into a version with a custom URLStreamHandler. Put your monitoring code in the stream handler and forward to the original.

Solution 3

You could use InTrace to instrument the Classloader classes which do the loading.

For the Sun JVM, I would suggest using the following Include patterns to trace appropriate classes:

  • ClassLoader
  • URLClassPath
  • Loader

Solution 4

In a Linux environment you can try:

lsof -p <jvm pid>

It will give you a list with the descriptors used by the program associated with the specified pid.

More Info

Solution 5

There exist a couple of techniques to debug classloading problems. Here are good slides from the JRebel creators summarizing those techniques: Do you really get class loaders?

Share:
13,727
aows
Author by

aows

Updated on June 03, 2022

Comments

  • aows
    aows almost 2 years

    To debug class loading in a JVM we can use the param -verbose:class, but... Anyone knows how to debug resources loading (e.g. properties files)?

  • Daniel H.
    Daniel H. about 15 years
    I agree, in that case I think the best option is to go with the ClassLoader solution
  • hansvb
    hansvb over 8 years
    @FastSnail: it seems they moved to Github. Link updated.