Java Memory Diagnostics is easy and requires:
1 Get heap Dump
2 Analysis Heap Dump
Get dump 1 VM arguments:-xx:+heapdumponoutofmemoryerror-xx:heapdumppath=./java_pid<pid>.hprof
Reference for VM options:http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
If not specified, the dump file is output to User.dir by default.
Java.lang.OutOfMemoryError:Java Heap Space
Dumping heap to java_pid8096.hprof ...
Heap dump file created [168062394 bytes in 1.306 secs]
Note that after you get the file, you can analyze it using the following command:
Jmap-histo./java_pid<pid>.hprof
Get dump 2 Jmap/jcmd
Jmap-dump:format=b,file=snapshot.jmap <pid>
Jcmd <process id/main class> gc.heap_dump filename=myheapdump
or direct access (histogram):
Jcmd <pid> Gc.class_histogram
Jmap-histo <pid>
Get dump 3 Jconsole + hotspotdiagnosticmxbean (install JDK)
Note that the files are stored under User.dir. (can be obtained with jinfo)
Analyze dump's jhat (requires JDK)
Referenc:
Http://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks.html#CIHGFAEG
Java in-Memory diagnostics