aows
aows

Reputation: 526

How to debug JVM resources loading?

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)?

Upvotes: 14

Views: 14315

Answers (5)

Thilo
Thilo

Reputation: 262494

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.

Upvotes: 3

rmoestl
rmoestl

Reputation: 3155

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?

Upvotes: 1

mchr
mchr

Reputation: 6251

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

Upvotes: 2

Daniel H.
Daniel H.

Reputation: 1842

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

Upvotes: 1

Tom Hawtin - tackline
Tom Hawtin - tackline

Reputation: 147154

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.

Upvotes: 2

Related Questions