From fe862639e7ce40f5adef0e482b1fb9c718e061a3 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 22 Sep 2023 06:38:45 +0000 Subject: [PATCH] 8316319: Generational ZGC: The SoftMaxHeapSize might be wrong when CDS decreases the MaxHeapSize Reviewed-by: aboldtch, serb --- src/hotspot/share/gc/x/xArguments.cpp | 4 ++++ src/hotspot/share/gc/x/xArguments.hpp | 1 + .../share/gc/z/shared/zSharedArguments.cpp | 10 ++++++++ .../share/gc/z/shared/zSharedArguments.hpp | 1 + src/hotspot/share/gc/z/zArguments.cpp | 23 +++++++++++-------- src/hotspot/share/gc/z/zArguments.hpp | 1 + 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/hotspot/share/gc/x/xArguments.cpp b/src/hotspot/share/gc/x/xArguments.cpp index 8c02c800247..60e78d2c756 100644 --- a/src/hotspot/share/gc/x/xArguments.cpp +++ b/src/hotspot/share/gc/x/xArguments.cpp @@ -37,6 +37,10 @@ void XArguments::initialize_alignments() { HeapAlignment = SpaceAlignment; } +void XArguments::initialize_heap_flags_and_sizes() { + // Nothing extra to do +} + void XArguments::initialize() { // Check mark stack size const size_t mark_stack_space_limit = XAddressSpaceLimit::mark_stack(); diff --git a/src/hotspot/share/gc/x/xArguments.hpp b/src/hotspot/share/gc/x/xArguments.hpp index aaa586a2df2..196dd994cad 100644 --- a/src/hotspot/share/gc/x/xArguments.hpp +++ b/src/hotspot/share/gc/x/xArguments.hpp @@ -31,6 +31,7 @@ class CollectedHeap; class XArguments : AllStatic { public: static void initialize_alignments(); + static void initialize_heap_flags_and_sizes(); static void initialize(); static size_t heap_virtual_to_physical_ratio(); static CollectedHeap* create_heap(); diff --git a/src/hotspot/share/gc/z/shared/zSharedArguments.cpp b/src/hotspot/share/gc/z/shared/zSharedArguments.cpp index 8a00a851acb..4d7e9827f18 100644 --- a/src/hotspot/share/gc/z/shared/zSharedArguments.cpp +++ b/src/hotspot/share/gc/z/shared/zSharedArguments.cpp @@ -38,6 +38,16 @@ void ZSharedArguments::initialize_alignments() { } } +void ZSharedArguments::initialize_heap_flags_and_sizes() { + GCArguments::initialize_heap_flags_and_sizes(); + + if (ZGenerational) { + ZArguments::initialize_heap_flags_and_sizes(); + } else { + XArguments::initialize_heap_flags_and_sizes(); + } +} + void ZSharedArguments::initialize() { GCArguments::initialize(); diff --git a/src/hotspot/share/gc/z/shared/zSharedArguments.hpp b/src/hotspot/share/gc/z/shared/zSharedArguments.hpp index 74659f581b9..c53f28ee0f9 100644 --- a/src/hotspot/share/gc/z/shared/zSharedArguments.hpp +++ b/src/hotspot/share/gc/z/shared/zSharedArguments.hpp @@ -31,6 +31,7 @@ class CollectedHeap; class ZSharedArguments : public GCArguments { private: virtual void initialize_alignments(); + virtual void initialize_heap_flags_and_sizes(); virtual void initialize(); virtual size_t conservative_max_heap_alignment(); diff --git a/src/hotspot/share/gc/z/zArguments.cpp b/src/hotspot/share/gc/z/zArguments.cpp index 01ecf8f3fc4..5ebfeb75f89 100644 --- a/src/hotspot/share/gc/z/zArguments.cpp +++ b/src/hotspot/share/gc/z/zArguments.cpp @@ -37,6 +37,19 @@ void ZArguments::initialize_alignments() { HeapAlignment = SpaceAlignment; } +void ZArguments::initialize_heap_flags_and_sizes() { + if (!FLAG_IS_CMDLINE(MaxHeapSize) && + !FLAG_IS_CMDLINE(MaxRAMFraction) && + !FLAG_IS_CMDLINE(MaxRAMPercentage) && + !FLAG_IS_CMDLINE(SoftMaxHeapSize)) { + // We are really just guessing how much memory the program needs. + // When that is the case, we don't want the soft and hard limits to be the same + // as it can cause flakyness in the number of GC threads used, in order to keep + // to a random number we just pulled out of thin air. + FLAG_SET_ERGO(SoftMaxHeapSize, MaxHeapSize * 90 / 100); + } +} + void ZArguments::select_max_gc_threads() { // Select number of parallel threads if (FLAG_IS_DEFAULT(ParallelGCThreads)) { @@ -126,16 +139,6 @@ void ZArguments::initialize() { FLAG_SET_ERGO_IF_DEFAULT(ZCollectionIntervalMajor, ZCollectionInterval); } - if (!FLAG_IS_CMDLINE(MaxHeapSize) && - !FLAG_IS_CMDLINE(MaxRAMFraction) && - !FLAG_IS_CMDLINE(MaxRAMPercentage)) { - // We are really just guessing how much memory the program needs. - // When that is the case, we don't want the soft and hard limits to be the same - // as it can cause flakyness in the number of GC threads used, in order to keep - // to a random number we just pulled out of thin air. - FLAG_SET_ERGO_IF_DEFAULT(SoftMaxHeapSize, MaxHeapSize * 90 / 100); - } - if (FLAG_IS_DEFAULT(ZFragmentationLimit)) { FLAG_SET_DEFAULT(ZFragmentationLimit, 5.0); } diff --git a/src/hotspot/share/gc/z/zArguments.hpp b/src/hotspot/share/gc/z/zArguments.hpp index ac1e613d4cc..7d1c00d30d1 100644 --- a/src/hotspot/share/gc/z/zArguments.hpp +++ b/src/hotspot/share/gc/z/zArguments.hpp @@ -34,6 +34,7 @@ private: public: static void initialize_alignments(); + static void initialize_heap_flags_and_sizes(); static void initialize(); static size_t heap_virtual_to_physical_ratio(); static CollectedHeap* create_heap();