8364202: CDS without G1 gives build error in slowdebug, asserts in fastdebug

Reviewed-by: ccheung, iklam
This commit is contained in:
Thomas Stuefe 2025-07-30 04:55:03 +00:00
parent c671089d6e
commit 164d0368f6
5 changed files with 17 additions and 7 deletions

View File

@ -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.

View File

@ -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; }
};

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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<<shift (klass_alignment_in_bytes)
static address _klass_range_start;
static address _klass_range_end;