Summary
The proposed change is to add a new JVM option -XX:FullGCHeapDumpLimit=n
to limit the number of heap dumps triggered by HeapDumpBeforeFullGC
and HeapDumpAfterFullGC
.
Problem
When encountering a full GC, developers will enable HeapDumpBeforeFullGC
or HeapDumpAfterFullGC
to capture the heap dump(s) to help with troubleshooting.
In the current implementation, these two flags will generate dumps for every full GC, increasing the risk of getting a full diskl. And mostly, only the first one or two dumps are used.
Although these two flags are manageable, disabling them in a timely manner in production may not be easy.
To enhance production-friendliness, it would be beneficial to have the ability to limit the number of dumps triggered by these two flags.
Solution
Add a new manageable JVM option -XX:FullGCHeapDumpLimit
to limit the number of heap dumps triggered by HeapDumpBeforeFullGC
and HeapDumpAfterFullGC
. The default value is 0 which means no limit.
When developers need to capture the heap dump(s) at a full GC, they can enable HeapDumpBeforeFullGC
or HeapDumpAfterFullGC
and also limit the total number of dumps with -XX:FullGCHeapDumpLimit=n
. E.g.
java -XX:FullGCHeapDumpLimit=1 -XX:+HeapDumpBeforeFullGC ...
Making the flag manageable improves flexibility.
Specification
diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp
index dce90c78eb4..d463971488c 100644
--- a/src/hotspot/share/runtime/globals.hpp
+++ b/src/hotspot/share/runtime/globals.hpp
@@ -546,10 +546,17 @@ const int ObjectAlignmentInBytes = 8;
"thrown from JVM") \
\
product(bool, HeapDumpBeforeFullGC, false, MANAGEABLE, \
- "Dump heap to file before any major stop-the-world GC") \
+ "Dump heap to file before any major stop-the-world GC " \
+ "(also see FullGCHeapDumpLimit)") \
\
product(bool, HeapDumpAfterFullGC, false, MANAGEABLE, \
- "Dump heap to file after any major stop-the-world GC") \
+ "Dump heap to file after any major stop-the-world GC " \
+ "(also see FullGCHeapDumpLimit)") \
+ \
+ product(uint, FullGCHeapDumpLimit, 0, MANAGEABLE, \
+ "Limit the number of heap dumps triggered by " \
+ "HeapDumpBeforeFullGC or HeapDumpAfterFullGC " \
+ "(0 means no limit)") \
\
product(bool, HeapDumpOnOutOfMemoryError, false, MANAGEABLE, \
"Dump heap to file when java.lang.OutOfMemoryError is thrown " \ \
- csr of
-
JDK-8321404 Limit the number of heap dumps triggered by HeapDumpBeforeFullGC/AfterFullGC
- Resolved