From 164d0368f608ff43789d2abd96cd0f5449458122 Mon Sep 17 00:00:00 2001 From: Thomas Stuefe Date: Wed, 30 Jul 2025 04:55:03 +0000 Subject: [PATCH] 8364202: CDS without G1 gives build error in slowdebug, asserts in fastdebug Reviewed-by: ccheung, iklam --- src/hotspot/share/cds/metaspaceShared.cpp | 13 +++++++++---- .../share/classfile/classLoaderDataShared.hpp | 4 +++- src/hotspot/share/memory/universe.cpp | 2 ++ src/hotspot/share/oops/compressedKlass.cpp | 3 ++- src/hotspot/share/oops/compressedKlass.hpp | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/hotspot/share/cds/metaspaceShared.cpp b/src/hotspot/share/cds/metaspaceShared.cpp index 2f817ec3e71..8db2195c434 100644 --- a/src/hotspot/share/cds/metaspaceShared.cpp +++ b/src/hotspot/share/cds/metaspaceShared.cpp @@ -1603,8 +1603,7 @@ MapArchiveResult MetaspaceShared::map_archives(FileMapInfo* static_mapinfo, File // Set up compressed Klass pointer encoding: the encoding range must // cover both archive and class space. - const address encoding_base = (address)mapped_base_address; - const address klass_range_start = encoding_base + prot_zone_size; + const address klass_range_start = (address)mapped_base_address; const size_t klass_range_size = (address)class_space_rs.end() - klass_range_start; if (INCLUDE_CDS_JAVA_HEAP || UseCompactObjectHeaders) { // The CDS archive may contain narrow Klass IDs that were precomputed at archive generation time: @@ -1615,13 +1614,19 @@ MapArchiveResult MetaspaceShared::map_archives(FileMapInfo* static_mapinfo, File // mapping start (including protection zone), shift should be the shift used at archive generation time. CompressedKlassPointers::initialize_for_given_encoding( klass_range_start, klass_range_size, - encoding_base, ArchiveBuilder::precomputed_narrow_klass_shift() // precomputed encoding, see ArchiveBuilder + klass_range_start, ArchiveBuilder::precomputed_narrow_klass_shift() // precomputed encoding, see ArchiveBuilder ); + assert(CompressedKlassPointers::base() == klass_range_start, "must be"); } else { // Let JVM freely choose encoding base and shift CompressedKlassPointers::initialize(klass_range_start, klass_range_size); + assert(CompressedKlassPointers::base() == nullptr || + CompressedKlassPointers::base() == klass_range_start, "must be"); + } + // Establish protection zone, but only if we need one + if (CompressedKlassPointers::base() == klass_range_start) { + CompressedKlassPointers::establish_protection_zone(klass_range_start, prot_zone_size); } - CompressedKlassPointers::establish_protection_zone(encoding_base, prot_zone_size); // map_or_load_heap_region() compares the current narrow oop and klass encodings // with the archived ones, so it must be done after all encodings are determined. diff --git a/src/hotspot/share/classfile/classLoaderDataShared.hpp b/src/hotspot/share/classfile/classLoaderDataShared.hpp index 4ba1c6c2196..6ef338f0f34 100644 --- a/src/hotspot/share/classfile/classLoaderDataShared.hpp +++ b/src/hotspot/share/classfile/classLoaderDataShared.hpp @@ -35,8 +35,9 @@ class SerializeClosure; class ClassLoaderDataShared : AllStatic { static bool _full_module_graph_loaded; - static void ensure_module_entry_table_exists(oop class_loader); + CDS_JAVA_HEAP_ONLY(static void ensure_module_entry_table_exists(oop class_loader);) public: +#if INCLUDE_CDS_JAVA_HEAP static void ensure_module_entry_tables_exist(); static void allocate_archived_tables(); static void iterate_symbols(MetaspaceClosure* closure); @@ -49,6 +50,7 @@ public: static void restore_java_system_loader_from_archive(ClassLoaderData* loader_data); static ModuleEntry* archived_boot_unnamed_module(); static ModuleEntry* archived_unnamed_module(ClassLoaderData* loader_data); +#endif // INCLUDE_CDS_JAVA_HEAP static bool is_full_module_graph_loaded() { return _full_module_graph_loaded; } }; diff --git a/src/hotspot/share/memory/universe.cpp b/src/hotspot/share/memory/universe.cpp index a2d58ae545a..bd47a054bc0 100644 --- a/src/hotspot/share/memory/universe.cpp +++ b/src/hotspot/share/memory/universe.cpp @@ -909,9 +909,11 @@ jint universe_init() { ClassLoaderData::init_null_class_loader_data(); #if INCLUDE_CDS +#if INCLUDE_CDS_JAVA_HEAP if (CDSConfig::is_using_full_module_graph()) { ClassLoaderDataShared::restore_archived_entries_for_null_class_loader_data(); } +#endif // INCLUDE_CDS_JAVA_HEAP if (CDSConfig::is_dumping_archive()) { CDSConfig::prepare_for_dumping(); } diff --git a/src/hotspot/share/oops/compressedKlass.cpp b/src/hotspot/share/oops/compressedKlass.cpp index a1a634b6aab..c075dd4024b 100644 --- a/src/hotspot/share/oops/compressedKlass.cpp +++ b/src/hotspot/share/oops/compressedKlass.cpp @@ -141,7 +141,8 @@ void CompressedKlassPointers::calc_lowest_highest_narrow_klass_id() { address lowest_possible_klass_location = _klass_range_start; // A Klass will never be placed at the Encoding range start, since that would translate to a narrowKlass=0, which - // is disallowed. Note that both Metaspace and CDS prvent allocation at the first address for this reason. + // is disallowed. If the encoding range starts at the klass range start, both Metaspace and CDS establish an + // mprotected zone for this reason (see establish_protection_zone). if (lowest_possible_klass_location == _base) { lowest_possible_klass_location += klass_alignment_in_bytes(); } diff --git a/src/hotspot/share/oops/compressedKlass.hpp b/src/hotspot/share/oops/compressedKlass.hpp index cec86a70a90..748a954ab06 100644 --- a/src/hotspot/share/oops/compressedKlass.hpp +++ b/src/hotspot/share/oops/compressedKlass.hpp @@ -124,7 +124,7 @@ class CompressedKlassPointers : public AllStatic { static address _base; static int _shift; - // Start and end of the Klass Range. + // Start and end of the Klass Range. Start includes the protection zone if one exists. // Note: guaranteed to be aligned to 1<