File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes how to trace jvm loading class info. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to trace jvm loading class info." Watch "how to trace jvm loading class info." New topic
Author

how to trace jvm loading class info.

jing hu
Ranch Hand

Joined: Jun 30, 2009
Posts: 63
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

Joined: Oct 13, 2005
Posts: 38007
    
  22
Too difficult a question for beginners. Moving thread.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
Marshal

Joined: Mar 22, 2005
Posts: 41106
    
  45
Any I/O code will probably use one of the static fields of the File class, like.separator and such.


Ping & DNS - my free Android networking tools app
jing hu
Ranch Hand

Joined: Jun 30, 2009
Posts: 63
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

Joined: Jun 30, 2009
Posts: 63
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

Joined: Apr 06, 2009
Posts: 19
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


Gaurav
jing hu
Ranch Hand

Joined: Jun 30, 2009
Posts: 63
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to trace jvm loading class info.
 
Similar Threads
Finding out # of instantiations of a class
Class Already Been Loaded
Problem with Reflection...Incorrect sequence of methods returned.
Query on Source File name
Class loading