From cb1c73663e91e632d643c23e6c5acc1c5118ac8b Mon Sep 17 00:00:00 2001 From: Roman Kennke Date: Mon, 25 Nov 2024 13:48:02 +0000 Subject: [PATCH] 8344363: FullGCForwarding::initialize_flags is called after ObjLayout::initialize Reviewed-by: stefank, shade, ayang --- src/hotspot/share/gc/g1/g1Arguments.cpp | 3 --- src/hotspot/share/gc/g1/g1Arguments.hpp | 1 - .../share/gc/parallel/parallelArguments.cpp | 3 ++- .../share/gc/serial/serialArguments.cpp | 6 +++--- .../share/gc/serial/serialArguments.hpp | 2 +- .../gc/shenandoah/shenandoahArguments.cpp | 7 ++----- .../gc/shenandoah/shenandoahArguments.hpp | 1 - src/hotspot/share/memory/universe.cpp | 3 +++ src/hotspot/share/runtime/arguments.cpp | 18 +++++++++++------- src/hotspot/share/runtime/arguments.hpp | 1 + src/hotspot/share/runtime/threads.cpp | 3 --- 11 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1Arguments.cpp b/src/hotspot/share/gc/g1/g1Arguments.cpp index 35dfbb7290e..1ae5f2ce76f 100644 --- a/src/hotspot/share/gc/g1/g1Arguments.cpp +++ b/src/hotspot/share/gc/g1/g1Arguments.cpp @@ -244,10 +244,7 @@ void G1Arguments::initialize() { if (max_parallel_refinement_threads > UINT_MAX / divisor) { vm_exit_during_initialization("Too large parallelism for remembered sets."); } -} -void G1Arguments::initialize_heap_flags_and_sizes() { - GCArguments::initialize_heap_flags_and_sizes(); FullGCForwarding::initialize_flags(heap_reserved_size_bytes()); } diff --git a/src/hotspot/share/gc/g1/g1Arguments.hpp b/src/hotspot/share/gc/g1/g1Arguments.hpp index 234e61d4ff0..73fa0557f7d 100644 --- a/src/hotspot/share/gc/g1/g1Arguments.hpp +++ b/src/hotspot/share/gc/g1/g1Arguments.hpp @@ -39,7 +39,6 @@ class G1Arguments : public GCArguments { static void parse_verification_type(const char* type); 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/parallel/parallelArguments.cpp b/src/hotspot/share/gc/parallel/parallelArguments.cpp index 4035259e6d6..d9972ccc146 100644 --- a/src/hotspot/share/gc/parallel/parallelArguments.cpp +++ b/src/hotspot/share/gc/parallel/parallelArguments.cpp @@ -83,6 +83,8 @@ void ParallelArguments::initialize() { if (FLAG_IS_DEFAULT(ParallelRefProcEnabled) && ParallelGCThreads > 1) { FLAG_SET_DEFAULT(ParallelRefProcEnabled, true); } + + FullGCForwarding::initialize_flags(heap_reserved_size_bytes()); } // The alignment used for boundary between young gen and old gen @@ -128,7 +130,6 @@ void ParallelArguments::initialize_heap_flags_and_sizes() { // Redo everything from the start initialize_heap_flags_and_sizes_one_pass(); } - FullGCForwarding::initialize_flags(heap_reserved_size_bytes()); } size_t ParallelArguments::heap_reserved_size_bytes() { diff --git a/src/hotspot/share/gc/serial/serialArguments.cpp b/src/hotspot/share/gc/serial/serialArguments.cpp index f8efa192807..c9d2caf9063 100644 --- a/src/hotspot/share/gc/serial/serialArguments.cpp +++ b/src/hotspot/share/gc/serial/serialArguments.cpp @@ -24,12 +24,12 @@ #include "precompiled.hpp" #include "gc/shared/fullGCForwarding.hpp" -#include "gc/shared/genArguments.hpp" +#include "gc/shared/gcArguments.hpp" #include "gc/serial/serialArguments.hpp" #include "gc/serial/serialHeap.hpp" -void SerialArguments::initialize_heap_flags_and_sizes() { - GenArguments::initialize_heap_flags_and_sizes(); +void SerialArguments::initialize() { + GCArguments::initialize(); FullGCForwarding::initialize_flags(MaxHeapSize); } diff --git a/src/hotspot/share/gc/serial/serialArguments.hpp b/src/hotspot/share/gc/serial/serialArguments.hpp index d12bd7d8e59..90c3225ff8d 100644 --- a/src/hotspot/share/gc/serial/serialArguments.hpp +++ b/src/hotspot/share/gc/serial/serialArguments.hpp @@ -31,8 +31,8 @@ class CollectedHeap; class SerialArguments : public GenArguments { private: + virtual void initialize(); virtual CollectedHeap* create_heap(); - virtual void initialize_heap_flags_and_sizes(); }; #endif // SHARE_GC_SERIAL_SERIALARGUMENTS_HPP diff --git a/src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp b/src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp index ca95cde83b1..4376e9d1150 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp @@ -176,6 +176,8 @@ void ShenandoahArguments::initialize() { if (FLAG_IS_DEFAULT(TLABAllocationWeight)) { FLAG_SET_DEFAULT(TLABAllocationWeight, 90); } + + FullGCForwarding::initialize_flags(MaxHeapSize); } size_t ShenandoahArguments::conservative_max_heap_alignment() { @@ -199,11 +201,6 @@ void ShenandoahArguments::initialize_alignments() { HeapAlignment = align; } -void ShenandoahArguments::initialize_heap_flags_and_sizes() { - GCArguments::initialize_heap_flags_and_sizes(); - FullGCForwarding::initialize_flags(MaxHeapSize); -} - CollectedHeap* ShenandoahArguments::create_heap() { return new ShenandoahHeap(new ShenandoahCollectorPolicy()); } diff --git a/src/hotspot/share/gc/shenandoah/shenandoahArguments.hpp b/src/hotspot/share/gc/shenandoah/shenandoahArguments.hpp index ad54b1d235c..bc73d9a2d12 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahArguments.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahArguments.hpp @@ -35,7 +35,6 @@ private: virtual void initialize(); virtual size_t conservative_max_heap_alignment(); - virtual void initialize_heap_flags_and_sizes(); virtual CollectedHeap* create_heap(); }; diff --git a/src/hotspot/share/memory/universe.cpp b/src/hotspot/share/memory/universe.cpp index 6daeb2f1045..ad4dd045bcb 100644 --- a/src/hotspot/share/memory/universe.cpp +++ b/src/hotspot/share/memory/universe.cpp @@ -62,6 +62,7 @@ #include "oops/instanceMirrorKlass.hpp" #include "oops/klass.inline.hpp" #include "oops/objArrayOop.inline.hpp" +#include "oops/objLayout.hpp" #include "oops/oop.inline.hpp" #include "oops/oopHandle.inline.hpp" #include "oops/typeArrayKlass.hpp" @@ -868,6 +869,8 @@ jint universe_init() { // Initialize CPUTimeCounters object, which must be done before creation of the heap. CPUTimeCounters::initialize(); + ObjLayout::initialize(); + #ifdef _LP64 MetaspaceShared::adjust_heap_sizes_for_dumping(); #endif // _LP64 diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index 0b16a634489..1917108519e 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -3654,33 +3654,35 @@ jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) { Arguments::print_on(&st); } + return JNI_OK; +} + +void Arguments::set_compact_headers_flags() { #ifdef _LP64 if (UseCompactObjectHeaders && FLAG_IS_CMDLINE(UseCompressedClassPointers) && !UseCompressedClassPointers) { warning("Compact object headers require compressed class pointers. Disabling compact object headers."); FLAG_SET_DEFAULT(UseCompactObjectHeaders, false); } - if (UseCompactObjectHeaders && LockingMode != LM_LIGHTWEIGHT) { - FLAG_SET_DEFAULT(LockingMode, LM_LIGHTWEIGHT); - } if (UseCompactObjectHeaders && !UseObjectMonitorTable) { // If UseCompactObjectHeaders is on the command line, turn on UseObjectMonitorTable. if (FLAG_IS_CMDLINE(UseCompactObjectHeaders)) { FLAG_SET_DEFAULT(UseObjectMonitorTable, true); - // If UseObjectMonitorTable is on the command line, turn off UseCompactObjectHeaders. + // If UseObjectMonitorTable is on the command line, turn off UseCompactObjectHeaders. } else if (FLAG_IS_CMDLINE(UseObjectMonitorTable)) { FLAG_SET_DEFAULT(UseCompactObjectHeaders, false); - // If neither on the command line, the defaults are incompatible, but turn on UseObjectMonitorTable. + // If neither on the command line, the defaults are incompatible, but turn on UseObjectMonitorTable. } else { FLAG_SET_DEFAULT(UseObjectMonitorTable, true); } } + if (UseCompactObjectHeaders && LockingMode != LM_LIGHTWEIGHT) { + FLAG_SET_DEFAULT(LockingMode, LM_LIGHTWEIGHT); + } if (UseCompactObjectHeaders && !UseCompressedClassPointers) { FLAG_SET_DEFAULT(UseCompressedClassPointers, true); } #endif - - return JNI_OK; } jint Arguments::apply_ergo() { @@ -3693,6 +3695,8 @@ jint Arguments::apply_ergo() { GCConfig::arguments()->initialize(); + set_compact_headers_flags(); + if (UseCompressedClassPointers) { CompressedKlassPointers::pre_initialize(); } diff --git a/src/hotspot/share/runtime/arguments.hpp b/src/hotspot/share/runtime/arguments.hpp index 2105d21430a..0b4d89f3ad2 100644 --- a/src/hotspot/share/runtime/arguments.hpp +++ b/src/hotspot/share/runtime/arguments.hpp @@ -264,6 +264,7 @@ class Arguments : AllStatic { static void set_conservative_max_heap_alignment(); static void set_use_compressed_oops(); static jint set_ergonomics_flags(); + static void set_compact_headers_flags(); // Limits the given heap size by the maximum amount of virtual // memory this process is currently allowed to use. It also takes // the virtual-to-physical ratio of the current GC into account. diff --git a/src/hotspot/share/runtime/threads.cpp b/src/hotspot/share/runtime/threads.cpp index 73f2e87f5c7..f6b7b7956e2 100644 --- a/src/hotspot/share/runtime/threads.cpp +++ b/src/hotspot/share/runtime/threads.cpp @@ -497,9 +497,6 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { // Timing (must come after argument parsing) TraceTime timer("Create VM", TRACETIME_LOG(Info, startuptime)); - // Initialize object layout after parsing the args - ObjLayout::initialize(); - // Initialize the os module after parsing the args jint os_init_2_result = os::init_2(); if (os_init_2_result != JNI_OK) return os_init_2_result;