![]() |
JVM is comprised of three memory segments: heap memory, non-heap memory, and the code for itself. |
A JVM heap is allocated at the start-up of every program. By default the initial heap size is 2MB and the max heap size is set to 64MB. But, in the event that your program needs more memory you can initialize it to have more using:
%java -Xmsn
Specifies the initial size of the memory allocation pool. This value must be a multiple of 1024 greater than 1 MB. Append the letter k or K to indicate kilobytes, the letter m or M to indicate megabytes, the letter g or G to indicate gigabytes, or the letter t or T to indicate terabytes. The default value is 2MB. Examples:
- -Xms6291456
- -Xms6144k
- -Xms6m
Likewise, we can set a maximum heap size using:
%java -Xmsn
Heap Dump Snapshots
There are a couple of commands you can use to obtain a view of your program's heap. The first one being Java's tool, HPROF, which enables CPU, heap, or monitor profiling. The second command is the Java Heap Analysis Tool (JHAT).
%java -Xrunhprof:format=b, file=snapshot.hprof Classname
%jhat snapshot.hprof
%jhat snapshot.hprof
Without formatting the snapshot, HPROF will return the heap dump in a text file. But because sifting through possibly 40k+ lines of text, we can format the dump so that it easer to browse, as well as make use of Object Query Language (OQL).
After running these two commands, you can view the heap file by opening up your browser and going to http://localhost:7000.
JConsole
![]() |
Overview tab |
Some useful tabs that are provided: Overview, Memory, Threads, Classes, and the VM Summary. You can adjust the time frames for even more specific analysis.
No comments:
Post a Comment