--- a/src/hotspot/share/classfile/systemDictionary.cpp Fri Sep 07 14:44:52 2018 -0400
+++ b/src/hotspot/share/classfile/systemDictionary.cpp Fri Sep 07 15:18:14 2018 -0400
@@ -2028,6 +2028,22 @@
#if INCLUDE_CDS
if (UseSharedSpaces) {
resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK);
+
+ // It's unsafe to access the archived heap regions before they
+ // are fixed up, so we must do the fixup as early as possible
+ // before the archived java objects are accessed by functions
+ // such as java_lang_Class::restore_archived_mirror and
+ // ConstantPool::restore_unshareable_info (restores the archived
+ // resolved_references array object).
+ //
+ // MetaspaceShared::fixup_mapped_heap_regions() fills the empty
+ // spaces in the archived heap regions and may use
+ // SystemDictionary::Object_klass(), so we can do this only after
+ // Object_klass is resolved. See the above resolve_wk_klasses_through()
+ // call. No mirror objects are accessed/restored in the above call.
+ // Mirrors are restored after java.lang.Class is loaded.
+ MetaspaceShared::fixup_mapped_heap_regions();
+
// Initialize the constant pool for the Object_class
Object_klass()->constants()->restore_unshareable_info(CHECK);
resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);