--- old/src/hotspot/share/memory/filemap.cpp 2018-10-21 17:55:04.459198748 -0700 +++ new/src/hotspot/share/memory/filemap.cpp 2018-10-21 17:55:04.179187987 -0700 @@ -914,6 +914,20 @@ return; } + if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::early_class_hook_env()) { + ShouldNotReachHere(); // CDS should have been disabled. + // The archived objects are mapped at JVM start-up, but we don't know if + // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook, + // which would make the archived String or mirror objects invalid. Let's be safe and not + // use the archived objects. These 2 classes are loaded during the JVMTI "early" stage + // (aka JVMTI_PHASE_PRIMORDIAL). + // + // If JvmtiExport::early_class_hook_env() is false, the classes of some objects + // in the archived subgraphs may be replaced by the ClassFileLoadHook. But that's OK + // because we won't install an archived object subgraph if the klass of any of the + // referenced objects are replaced. See HeapShared::initialize_from_archived_subgraph(). + } + MemRegion heap_reserved = Universe::heap()->reserved_region(); log_info(cds)("CDS archive was created with max heap size = " SIZE_FORMAT "M, and the following configuration:", @@ -1224,6 +1238,15 @@ bool FileMapInfo::initialize() { assert(UseSharedSpaces, "UseSharedSpaces expected."); + if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::early_class_hook_env()) { + // CDS assumes that no classes resolved in SystemDictionary::resolve_well_known_classes + // are replaced at runtime by JVMTI ClassFileLoadHook. All of those classes are resolved + // during the JVMTI "early" stage (JVMTI_PHASE_PRIMORDIAL), so we're OK if + // JvmtiExport::early_class_hook_env() is not requested by native agent(s). + FileMapInfo::fail_continue("CDS is disabled because early JVMTI ClassFileLoadHook is in use."); + return false; + } + if (!open_for_read()) { return false; }