Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to trace jvm loading class info.

 
jing hu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi.

for the simple java program.


I can input "java HelloWorld -verbose" to see which classes are loaded by jvm.

But I want to know more.
For example, for the HelloWorld program java.io.File will be loaded. I want to know why java.io.File be loaded, which class will let jvm load java.io.File.
How to do this?
Thanks
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too difficult a question for beginners. Moving thread.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if the -Xdepend flag still exists. This article shows how to extract static dependencies using BCEL (ASM can do the same thing). I'm not sure what could be used at runtime, although it might be easy enough to tweak a classloader.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any I/O code will probably use one of the static fields of the File class, like.separator and such.
 
jing hu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Any I/O code will probably use one of the static fields of the File class, like.separator and such.

yeah´╝îBut the class java.io.File is just a example. There are many other classes which i don't know when and why be loaded.

 
jing hu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article shows how to extract static dependencies using BCEL (ASM can do the same thing).

Now , I use ASM to trace the classes dependency. But I find there are some classes which i don't get when using ASM to trace classes dependency. So I want to know these classes which I don't get why are loaded and which classes depend these classes. So ASM will not be my choice.

although it might be easy enough to tweak a classloader


Can you tell how to do this. I am not family with the classloader.

tks.
 
Gaurav Purandare
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Jconsole to view the runtime information of any java application
you might have to keep the application running though

you can do the following

1. start the application and keep it running
2. start jconsole, which is present in the bin directory of the jdk installation
3. select your application from the menu

I am not sure if it shows all the classes that are loaded but its worth a try
 
jing hu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to trace the class dependency in the runtime, not find all classes. using the argument "-verbose", it can return all classes loaded by jvm.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic