Skip to content

Commit

Permalink
8316319: Generational ZGC: The SoftMaxHeapSize might be wrong when CD…
Browse files Browse the repository at this point in the history
…S decreases the MaxHeapSize

Backport-of: fe862639e7ce40f5adef0e482b1fb9c718e061a3
  • Loading branch information
yaqsun authored and shipilev committed Jan 23, 2024
1 parent 2697a9d commit 8084244
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/x/xArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/gc/x/xArguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions src/hotspot/share/gc/z/shared/zSharedArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/gc/z/shared/zSharedArguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 13 additions & 10 deletions src/hotspot/share/gc/z/zArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/gc/z/zArguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ZArguments : 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();
Expand Down

1 comment on commit 8084244

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.