src/hotspot/share/memory/filemap.cpp
changeset 52319 625f6c742392
parent 52314 e53af5fa0dae
child 52402 72d4e10305b9
--- a/src/hotspot/share/memory/filemap.cpp	Mon Oct 29 12:33:41 2018 -0700
+++ b/src/hotspot/share/memory/filemap.cpp	Wed Oct 17 15:57:10 2018 -0700
@@ -914,6 +914,19 @@
     return;
   }
 
+  if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_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.
+    //
+    // If JvmtiExport::has_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 +1237,15 @@
 bool FileMapInfo::initialize() {
   assert(UseSharedSpaces, "UseSharedSpaces expected.");
 
+  if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_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, so we can still use CDS if
+    // JvmtiExport::has_early_class_hook_env() is false.
+    FileMapInfo::fail_continue("CDS is disabled because early JVMTI ClassFileLoadHook is in use.");
+    return false;
+  }
+
   if (!open_for_read()) {
     return false;
   }