diff a/src/hotspot/share/oops/klass.cpp b/src/hotspot/share/oops/klass.cpp --- a/src/hotspot/share/oops/klass.cpp +++ b/src/hotspot/share/oops/klass.cpp @@ -201,12 +201,12 @@ // The constructor is also used from CppVtableCloner, // which doesn't zero out the memory before calling the constructor. Klass::Klass(KlassID id) : _id(id), _prototype_header(markWord::prototype()), _shared_class_path_index(-1) { - CDS_ONLY(_shared_class_flags = 0;) - CDS_JAVA_HEAP_ONLY(_archived_mirror = narrowOop::null;) + CDS_ONLY(_shared_class_flags = 0); + CDS_JAVA_HEAP_ONLY(_archived_mirror_index = -1); _primary_supers[0] = this; set_super_check_offset(in_bytes(primary_supers_offset())); } jint Klass::array_layout_helper(BasicType etype) { @@ -571,14 +571,13 @@ // If an exception happened during CDS restore, some of these fields may already be // set. We leave the class on the CLD list, even if incomplete so that we don't // modify the CLD list outside a safepoint. if (class_loader_data() == NULL) { - // Restore class_loader_data to the null class loader data set_class_loader_data(loader_data); - // Add to null class loader list first before creating the mirror + // Add to class loader list first before creating the mirror // (same order as class file parsing) loader_data->add_class(this); } Handle loader(THREAD, loader_data->class_loader()); @@ -595,11 +594,11 @@ module_entry = ModuleEntryTable::javabase_moduleEntry(); } // Obtain java.lang.Module, if available Handle module_handle(THREAD, ((module_entry != NULL) ? module_entry->module() : (oop)NULL)); - if (this->has_raw_archived_mirror()) { + if (this->has_archived_mirror_index()) { ResourceMark rm(THREAD); log_debug(cds, mirror)("%s has raw archived mirror", external_name()); if (HeapShared::open_archive_heap_region_mapped()) { bool present = java_lang_Class::restore_archived_mirror(this, loader, module_handle, protection_domain, @@ -610,11 +609,11 @@ } // No archived mirror data log_debug(cds, mirror)("No archived mirror data for %s", external_name()); clear_java_mirror_handle(); - this->clear_has_raw_archived_mirror(); + this->clear_archived_mirror_index(); } // Only recreate it if not present. A previous attempt to restore may have // gotten an OOM later but keep the mirror if it was created. if (java_mirror() == NULL) { @@ -622,25 +621,26 @@ java_lang_Class::create_mirror(this, loader, module_handle, protection_domain, Handle(), CHECK); } } #if INCLUDE_CDS_JAVA_HEAP -// Used at CDS dump time to access the archived mirror. No GC barrier. -oop Klass::archived_java_mirror_raw() { - assert(has_raw_archived_mirror(), "must have raw archived mirror"); - return CompressedOops::decode(_archived_mirror); +oop Klass::archived_java_mirror() { + assert(has_archived_mirror_index(), "must have archived mirror"); + return HeapShared::get_root(_archived_mirror_index); } -narrowOop Klass::archived_java_mirror_raw_narrow() { - assert(has_raw_archived_mirror(), "must have raw archived mirror"); - return _archived_mirror; +void Klass::clear_archived_mirror_index() { + if (_archived_mirror_index >= 0) { + HeapShared::clear_root(_archived_mirror_index); + } + _archived_mirror_index = -1; } // No GC barrier -void Klass::set_archived_java_mirror_raw(oop m) { +void Klass::set_archived_java_mirror(oop m) { assert(DumpSharedSpaces, "called only during runtime"); - _archived_mirror = CompressedOops::encode(m); + _archived_mirror_index = HeapShared::append_root(m); } #endif // INCLUDE_CDS_JAVA_HEAP Klass* Klass::array_klass_or_null(int rank) { EXCEPTION_MARK;