How to reliably take JVM core dump if application is in GC?

筅森魡賤 提交于 2019-12-04 11:55:10

You cannot take a heap dump while a GC is being performed. You need to take a heap dump before or after the GC. If you want to know why it is taking so long it is usueful to determine which pahse is taking so long. To see this to add -verbosegc This will indicate if it is taking a long time to reach a safe point, copy objects, scan the tenrured space, check references or something else.

It could be taking along time because you have lots of objects to clean up. As a guessimate it can take about a worst case 1 second per 2 GB of heap objects.

What you need to do is take the heap dump before the heap is so close to full that the GC locks up the application.

In my experience, an OutOfMemory exception or long GC cycles do not indicate a memory leak for certain.

In order to search for a memory leak, take 2 separate heap dumps some time apart (I've used jvisualvm, nowadays a version is bundled in with the JDK) and analyze them. Hint: Inspecting retain size of objects helps.

Depending on what your application does and if an apparent memory leak does not turn up, tweaking JVM GC options is your best bet. Look for generation ratios, generations after a new object is tenured etc.

Hope this helps a bit.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!