8064701: Some CDS optimizations should be disabled if bootclasspath is modified by JVMTI
authoriklam
Tue, 18 Nov 2014 03:38:50 -0800
changeset 27672 d24adedd3655
parent 27671 d1e2e443e43a
child 27673 df559a888b9f
8064701: Some CDS optimizations should be disabled if bootclasspath is modified by JVMTI Summary: Added API to track bootclasspath modification Reviewed-by: jiangli, dholmes, minqi
hotspot/src/share/vm/classfile/classLoaderExt.hpp
hotspot/src/share/vm/prims/jvmtiEnv.cpp
hotspot/src/share/vm/prims/whitebox.cpp
hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java
--- a/hotspot/src/share/vm/classfile/classLoaderExt.hpp	Tue Nov 18 20:51:55 2014 +0000
+++ b/hotspot/src/share/vm/classfile/classLoaderExt.hpp	Tue Nov 18 03:38:50 2014 -0800
@@ -63,6 +63,9 @@
                                    ClassPathEntry* new_entry) {
     ClassLoader::add_to_list(new_entry);
   }
+  static void append_boot_classpath(ClassPathEntry* new_entry) {
+    ClassLoader::add_to_list(new_entry);
+  }
   static void setup_search_paths() {}
 };
 
--- a/hotspot/src/share/vm/prims/jvmtiEnv.cpp	Tue Nov 18 20:51:55 2014 +0000
+++ b/hotspot/src/share/vm/prims/jvmtiEnv.cpp	Tue Nov 18 03:38:50 2014 -0800
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "classfile/classLoaderExt.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "classfile/vmSymbols.hpp"
 #include "interpreter/bytecodeStream.hpp"
@@ -472,7 +473,7 @@
     if (TraceClassLoading) {
       tty->print_cr("[Opened %s]", zip_entry->name());
     }
-    ClassLoader::add_to_list(zip_entry);
+    ClassLoaderExt::append_boot_classpath(zip_entry);
     return JVMTI_ERROR_NONE;
   } else {
     return JVMTI_ERROR_WRONG_PHASE;
--- a/hotspot/src/share/vm/prims/whitebox.cpp	Tue Nov 18 20:51:55 2014 +0000
+++ b/hotspot/src/share/vm/prims/whitebox.cpp	Tue Nov 18 03:38:50 2014 -0800
@@ -64,6 +64,7 @@
 #endif // INCLUDE_NMT
 
 #include "compiler/compileBroker.hpp"
+#include "jvmtifiles/jvmtiEnv.hpp"
 #include "runtime/compilationPolicy.hpp"
 
 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
@@ -113,6 +114,31 @@
   return closure.found();
 WB_END
 
+WB_ENTRY(void, WB_AddToBootstrapClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) {
+#if INCLUDE_JVMTI
+  ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
+  const char* seg = env->GetStringUTFChars(segment, NULL);
+  JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION);
+  jvmtiError err = jvmti_env->AddToBootstrapClassLoaderSearch(seg);
+  assert(err == JVMTI_ERROR_NONE, "must not fail");
+  env->ReleaseStringUTFChars(segment, seg);
+#endif
+}
+WB_END
+
+WB_ENTRY(void, WB_AddToSystemClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) {
+#if INCLUDE_JVMTI
+  ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
+  const char* seg = env->GetStringUTFChars(segment, NULL);
+  JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION);
+  jvmtiError err = jvmti_env->AddToSystemClassLoaderSearch(seg);
+  assert(err == JVMTI_ERROR_NONE, "must not fail");
+  env->ReleaseStringUTFChars(segment, seg);
+#endif
+}
+WB_END
+
+
 WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) {
   return (jlong)Arguments::max_heap_for_compressed_oops();
 }
@@ -1102,6 +1128,10 @@
       CC"(Ljava/lang/String;[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
       (void*) &WB_ParseCommandLine
   },
+  {CC"addToBootstrapClassLoaderSearch", CC"(Ljava/lang/String;)V",
+                                                      (void*)&WB_AddToBootstrapClassLoaderSearch},
+  {CC"addToSystemClassLoaderSearch",    CC"(Ljava/lang/String;)V",
+                                                      (void*)&WB_AddToSystemClassLoaderSearch},
   {CC"getCompressedOopsMaxHeapSize", CC"()J",
       (void*)&WB_GetCompressedOopsMaxHeapSize},
   {CC"printHeapSizes",     CC"()V",                   (void*)&WB_PrintHeapSizes    },
--- a/hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java	Tue Nov 18 20:51:55 2014 +0000
+++ b/hotspot/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java	Tue Nov 18 03:38:50 2014 -0800
@@ -84,6 +84,10 @@
   }
   private native boolean isClassAlive0(String name);
 
+  // JVMTI
+  public native void addToBootstrapClassLoaderSearch(String segment);
+  public native void addToSystemClassLoaderSearch(String segment);
+
   // G1
   public native boolean g1InConcurrentMark();
   public native boolean g1IsHumongous(Object o);