Thursday 16 August 2018

jmap: Force heap dump generation

You can run -dump:<dump-options> <pid> or -histo command with -F option to force the heap dump generation process. Use -F option, when the process with given id is not responding.

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
18612
4692 sun.tools.jcmd.JCmd
2600 HelloWorld

As you see jcmd output, HelloWorld application is running with process id 2600.

Execute the command 'jmap -F -dump:live,format=b,file=heap.bin 2600' to make forceful heap dump generation.
C:\Users\krishna\Documents\Study\Miscellaneous>jmap -F -dump:live,format=b,file=heap.bin  2600
Attaching to process ID 2600, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.171-b11
Dumping heap to heap.bin ...
Heap dump file created


Note: The "live" suboption is not supported in this mode. "live" suboption is used to dump only live objects.




Previous                                                 Next                                                 Home

No comments:

Post a Comment