Saturday 4 August 2018

About Memory Dumps and Commands

Java Heap Memory



Most of the newly created objects are located in the Eden Memory space


  • When Eden space is filled with objects, Minor GC is performed and all the survivor objects are moved to one of the survivor spaces. Objects not being unreferenced will be copied by the new generation garbage collector into the survivor spaces.
  • Minor GC also checks the survivor objects and moves them to the other survivor space. So at a time, one of the survivor space is always empty. They may get copied in some special cases directly into the old generation pool.
  • Objects that have survived many cycles of GC, are moved to the Old generation memory space. Usually it is done by setting a threshold for the age of the nursery objects before they become eligible to promote to old generation.
  • When the old generation becomes full, garbage is collected there and the process is called as old collection. Old generation memory contains the objects that are long lived and survived after many rounds of Minor GC
  • Usually garbage collection is performed in Old generation memory when it’s full. Old generation garbage collection is called as Major GC and usually takes longer time.
  • Permanent Generation or “Perm Gen” contains the application metadata required by the JVM to describe the classes and methods used in the application. Perm Gen is populated by JVM at runtime based on the classes used by the application. Perm Gen also contains Java SE library classes and methods. Perm Gen objects are garbage collected in a full garbage collection.


<JAVA_HOME>/bin/jstat –gc <JAVA_PID>

Example - C:\Program Files\Java\jdk1.8.0_151\bin>jstat -gc 30372







JMAP

The jmap utility prints the memory-related statistics for a running VM or core file. 

<JAVA_HOME>/bin/jmap –heap <JAVA_PID>

Example: C:\Program Files\Java\jdk1.8.0_151\bin>jmap -heap 30372

Command for Creating HPROF file

C:\Program Files\Java\jdk1.8.0_151\bin>jmap -dump:file=c:\Tutorials\heap-dump.prof 30372




Ques:- How to Get the heap dump using JMap command?
Answer:- 



jcmd


jcmd <JAVA_PID> GC.heap_dump filename=<FILE>

The jcmd utility is used to send diagnostic command requests to the JVM, where these requests are useful for controlling Java Flight Recordings, troubleshoot, and diagnose JVM and Java applications. It must be used on the same machine where the JVM is running, and have same effective user and group identifiers that were used to launch the JVM.

jhat

The jhat tool provides a convenient means to browse the object topology in a heap snapshot. This tool replaces the Heap Analysis Tool (HAT). The tool parses a heap dump in binary format (for example, a heap dump produced by jcmd).

Command

C:\Program Files\Java\jdk1.8.0_151\bin>jhat c:\Tutorials\heap-dump.prof




No comments:

Post a Comment