Does my java application continue running while jmap is taking its memory dump?
Jmap is the tool which gives you the possibility with one command to take the dump. The problem with that way is that it can take several minutes, even hours, to finish. It depends of the size of the configured java heap size.
jmap is a tool to print statistics about memory in a running JVM. We can use it for local or remote processes. Along with that option, we should specify several parameters: live: if set, it only prints objects which have active references and discards the ones that are ready to be garbage collected.
Right-click on one of the Java process. Click on the 'Heap Dump' option on the drop-down menu. Heap dump will be generated. File path where heap dump is generated will be specified in the Summary Tab > Basic Info > File section.
So, by triggering a heap dump, you are forcing a Full GC - regardless of whether the heap needs one or not. That is why the GC didn't occur automatically - it did not need to run, but you forced it to. It is very unlikely that there is a regression or other problem with JDK 10 running JDK 8 bytecode.
I had an issue with trying to do this on a production machine creating the hprof file with jmap took ages and naturally locked up the java webapp for ages.
I found this page:
http://blogs.atlassian.com/2013/03/so-you-want-your-jvms-heap/
Which explained that you can also use gdb (on linux systems) to dump the core of the java process.
With this core file you can then generate the hprof file for analysis in a separate process which prevent your java server process from being interrupted for such a long time. Which is what would happen if you were to run the same operation with jmap.
To summarise:
download and install gdb
apt-get update
apt-get install gdb
...
get the java process id of the java process you're interested in
jps ...
start a gdb session with that process
gdb [pid] ...
then generate the core file:
gcore /tmp/jvm.core
end the gdb session
detach quit
then use the core file generated to make an hprof file:
sudo jmap -dump:format=b,file=jvm.hprof /usr/bin/java /tmp/jvm.core
then (g)zip the file up and copy it to your machine for further analysis.
Your application is stopped. The only practical way to get an accurate heap dump would be to stop all application activity while the dump is being created.
Whether this is a "brief" pause or a "long" pause depends on how much is dumped. If you use "-dump" then you will dump the entire heap, including unreachable objects. If you use "-dump:live" you will only dump reachable objects ... but that also entails (at least) marking the heap to figure out which objects are reachable.
But if you are dumping a gigabyte sized heap, expect the pause time to be measured in minutes rather than seconds.
Re the suggestion that you could avoid stopping the JVM by using fork, it turns out that forking a multi-threaded process can be problematic:
Then there is is the resource usage issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With