From 0f10c9db408318b189d081a59f52e1395c83d409 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Wed, 16 Oct 2024 11:53:08 +0200 Subject: [PATCH] Fix --- src/hotspot/share/cds/heapShared.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/hotspot/share/cds/heapShared.cpp b/src/hotspot/share/cds/heapShared.cpp index 81aa7ac94dc21..879ff4ee24111 100644 --- a/src/hotspot/share/cds/heapShared.cpp +++ b/src/hotspot/share/cds/heapShared.cpp @@ -386,6 +386,14 @@ void HeapShared::set_scratch_java_mirror(Klass* k, oop mirror) { } void HeapShared::remove_scratch_objects(Klass* k) { + // Before we remove the Java mirror from the table, we need to break the link + // from mirror to the Klass. Java mirror can still be alive, and it should + // not point to dead klass. See how InstanceKlass::deallocate_contents does it + // for normal mirrors. + oop mirror = _scratch_java_mirror_table->get_oop(k); + if (mirror != nullptr) { + java_lang_Class::set_klass(mirror, nullptr); + } _scratch_java_mirror_table->remove_oop(k); if (k->is_instance_klass()) { _scratch_references_table->remove(InstanceKlass::cast(k)->constants());