Thursday, 16 August 2018

jmap: -clstats: Print class loader statistics

Use 'jmap -clstats {PROCESS_ID}' to print the classloader statistics.

Let me explain with an example.

HelloWorld.java
public class HelloWorld {
 public static void main(String args[]) throws Exception {
  int count = 0;
  
  Thread t1 = new Thread() {
   public void run() {
    while(true){
     try{
      Thread.sleep(2000);
     }catch(Exception e){
      
     }
    }
   }
  };

  t1.start();
 }
}


Compile and run HelloWorld application.

Open command prompt and execute jcmd command.
C:\>jcmd
18484 HelloWorld
18612
18904 sun.tools.jcmd.JCmd


As you see the output of jcmd command, HelloWorld application is running with process id 18484.


Execute the command ‘jmap -clstats 18484 > classLoaderStats.txt’, it copies all the class loader statistics to classLoaderStats.txt file.
C:\>jmap -clstats 18484 > classLoaderStats.txt
finding class loader instances ..done.
computing per loader stat ..done.
please wait.. computing liveness.................................................done.

classLoaderStats.txt contain below data.
Attaching to process ID 18484, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.171-b11
class_loader classes bytes parent_loader alive? type

<bootstrap> 400 767939   null   live <internal>
0x00000006c1e00ba8 2 1455 0x00000006c1e00c18 live sun/misc/Launcher$AppClassLoader@0x00000007c000f8c8
0x00000006c1e00c18 0 0   null   live sun/misc/Launcher$ExtClassLoader@0x00000007c000fc70

total = 3 402 769394     N/A     alive=3, dead=0     N/A    




Previous                                                 Next                                                 Home

No comments:

Post a Comment