diff -r 540c1a848dd8 -r 628909466216 src/hotspot/share/oops/instanceKlass.cpp --- a/src/hotspot/share/oops/instanceKlass.cpp Fri Sep 28 14:53:41 2018 -0700 +++ b/src/hotspot/share/oops/instanceKlass.cpp Mon Oct 01 00:52:37 2018 -0400 @@ -686,15 +686,6 @@ return Verifier::verify(this, should_verify_class(), THREAD); } - -// Used exclusively by the shared spaces dump mechanism to prevent -// classes mapped into the shared regions in new VMs from appearing linked. - -void InstanceKlass::unlink_class() { - assert(is_linked(), "must be linked"); - _init_state = loaded; -} - void InstanceKlass::link_class(TRAPS) { assert(is_loaded(), "must be loaded"); if (!is_linked()) { @@ -2300,10 +2291,12 @@ return; } - // Unlink the class - if (is_linked()) { - unlink_class(); - } + // Reset to the 'allocated' state to prevent any premature accessing to + // a shared class at runtime while the class is still being loaded and + // restored. A class' init_state is set to 'loaded' at runtime when it's + // being added to class hierarchy (see SystemDictionary:::add_to_hierarchy()). + _init_state = allocated; + { MutexLocker ml(Compile_lock); init_implementor(); @@ -2350,6 +2343,10 @@ } void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) { + // SystemDictionary::add_to_hierarchy() sets the init_state to loaded + // before the InstanceKlass is added to the SystemDictionary. Make + // sure the current state is