changeset 7819:4b68a3e8c19d

Use WhitBox support to call JVM Module APIs and add -Dsun.reflect.useHotSpotAccessCheck=true where needed
author hseigel
date Wed, 18 Feb 2015 11:29:28 -0500
parents 8208edcf540b
children 8a0166d6fb79
files src/share/vm/prims/whitebox.cpp test/runtime/modules/AccessCheckExp.java test/runtime/modules/AccessCheckRead.java test/runtime/modules/AccessCheckSuper.java test/runtime/modules/AccessCheckToUnnamed.java test/runtime/modules/AccessCheckUnnamed.java test/runtime/modules/AccessCheckWorks.java test/runtime/modules/ExportTwice.java test/runtime/modules/JVMAddModuleExports.java test/runtime/modules/JVMAddModulePackage.java test/runtime/modules/JVMAddReadsModule.java test/runtime/modules/JVMCanReadModule.java test/runtime/modules/JVMDefineModule.java test/runtime/modules/JVMIsExportedToModule.java test/runtime/modules/LoadUnloadModuleStress.java test/runtime/modules/ModuleHelper.java
diffstat 16 files changed, 123 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/prims/whitebox.cpp	Tue Feb 17 12:45:53 2015 -0800
+++ b/src/share/vm/prims/whitebox.cpp	Wed Feb 18 11:29:28 2015 -0500
@@ -1090,6 +1090,32 @@
   MetadataFactory::free_array(cld, (Array<u1>*)(uintptr_t)addr);
 WB_END
 
+WB_ENTRY(jobject, WB_DefineModule(JNIEnv* env, jobject o, jstring name, jstring version, jstring location,
+                                  jobject loader, jobjectArray packages))
+  return Modules::define_module(env, name, version, location, loader, packages);
+WB_END
+
+WB_ENTRY(void, WB_AddModuleExports(JNIEnv* env, jobject o, jobject from_module, jstring package, jobject to_module))
+  Modules::add_module_exports(env, from_module, package, to_module);
+WB_END
+
+WB_ENTRY(void, WB_AddReadsModule(JNIEnv* env, jobject o, jobject from_module, jobject to_module))
+  Modules::add_reads_module(env, from_module, to_module);
+WB_END
+
+WB_ENTRY(jboolean, WB_CanReadModule(JNIEnv* env, jobject o, jobject asking_module, jobject target_module))
+  return Modules::can_read_module(env, asking_module, target_module);
+WB_END
+
+WB_ENTRY(jboolean, WB_IsExportedToModule(JNIEnv* env, jobject o, jobject from_module, jstring package, jobject to_module))
+  return Modules::is_exported_to_module(env, from_module, package, to_module);
+WB_END
+
+WB_ENTRY(void, WB_AddModulePackage(JNIEnv* env, jobject o, jclass module, jstring package))
+  Modules::add_module_package(env, module, package);
+WB_END
+
+
 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc))
   if (inc < 0) {
     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
@@ -1338,6 +1364,18 @@
   {CC"getCodeBlob",        CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob        },
   {CC"getThreadStackSize", CC"()J",                   (void*)&WB_GetThreadStackSize },
   {CC"getThreadRemainingStackSize", CC"()J",          (void*)&WB_GetThreadRemainingStackSize },
+  {CC"DefineModule",       CC"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;",
+                                                      (void*)&WB_DefineModule },
+  {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
+                                                      (void*)&WB_AddModuleExports },
+  {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
+                                                      (void*)&WB_AddReadsModule },
+  {CC"CanReadModule",      CC"(Ljava/lang/Object;Ljava/lang/Object;)Z",
+                                                      (void*)&WB_CanReadModule },
+  {CC"IsExportedToModule", CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Z",
+                                                      (void*)&WB_IsExportedToModule },
+  {CC"AddModulePackage",   CC"(Ljava/lang/Object;Ljava/lang/String;)V",
+                                                      (void*)&WB_AddModulePackage },
   {CC"readImageFile",     CC"(Ljava/lang/String;)Z",  (void*)&WB_ReadImageFile },
   {CC"assertMatchingSafepointCalls", CC"(ZZ)V",       (void*)&WB_AssertMatchingSafepointCalls },
   {CC"isMonitorInflated",  CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
--- a/test/runtime/modules/AccessCheckExp.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/AccessCheckExp.java	Wed Feb 18 11:29:28 2015 -0500
@@ -23,10 +23,13 @@
 
 /*
  * @test
- * @library /testlibrary
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
  * @compile p2/c2.java
  * @compile p1/c1.java
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc AccessCheckExp
+ * @build AccessCheckExp
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc -Dsun.reflect.useHotSpotAccessCheck=true AccessCheckExp
  */
 
 import java.lang.reflect.Module;
--- a/test/runtime/modules/AccessCheckRead.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/AccessCheckRead.java	Wed Feb 18 11:29:28 2015 -0500
@@ -23,11 +23,13 @@
 
 /*
  * @test
- * @library /testlibrary
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
  * @compile p2/c2.java
  * @compile p1/c1.java
  * @build AccessCheckRead
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc AccessCheckRead AccessCheckRead
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc -Dsun.reflect.useHotSpotAccessCheck=true AccessCheckRead
  */
 
 import com.oracle.java.testlibrary.*;
--- a/test/runtime/modules/AccessCheckSuper.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/AccessCheckSuper.java	Wed Feb 18 11:29:28 2015 -0500
@@ -23,9 +23,12 @@
 
 /*
  * @test
- * @library /testlibrary
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
  * @compile p2/c2.java
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc AccessCheckSuper
+@build AccessCheckSuper
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc -Dsun.reflect.useHotSpotAccessCheck=true AccessCheckSuper
  */
 
 import java.lang.reflect.Module;
--- a/test/runtime/modules/AccessCheckToUnnamed.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/AccessCheckToUnnamed.java	Wed Feb 18 11:29:28 2015 -0500
@@ -23,10 +23,13 @@
 
 /*
  * @test
- * @library /testlibrary
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
  * @compile p2/c2.java
  * @compile p1/c1.java
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc AccessCheckToUnnamed
+ * @build AccessCheckToUnnamed
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc  -Dsun.reflect.useHotSpotAccessCheck=true AccessCheckToUnnamed
  */
 
 import java.lang.reflect.Module;
--- a/test/runtime/modules/AccessCheckUnnamed.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/AccessCheckUnnamed.java	Wed Feb 18 11:29:28 2015 -0500
@@ -26,10 +26,13 @@
 
 /*
  * @test
- * @library /testlibrary
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
  * @compile p2/c2.java
  * @compile p1/c1.java
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc AccessCheckUnnamed
+ * @build AccessCheckUnnamed
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc -Dsun.reflect.useHotSpotAccessCheck=true AccessCheckUnnamed
  */
 
 public class AccessCheckUnnamed {
--- a/test/runtime/modules/AccessCheckWorks.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/AccessCheckWorks.java	Wed Feb 18 11:29:28 2015 -0500
@@ -23,10 +23,13 @@
 
 /*
  * @test
- * @library /testlibrary
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
  * @compile p2/c2.java
  * @compile p1/c1.java
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc AccessCheckWorks
+ * @build AccessCheckWorks
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc -Dsun.reflect.useHotSpotAccessCheck=true AccessCheckWorks
  */
 
 import java.lang.reflect.Module;
--- a/test/runtime/modules/ExportTwice.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/ExportTwice.java	Wed Feb 18 11:29:28 2015 -0500
@@ -23,10 +23,13 @@
 
 /*
  * @test
- * @library /testlibrary
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
  * @compile p2/c2.java
  * @compile p1/c1.java
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc ExportTwice
+ * @build ExportTwice
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc -Dsun.reflect.useHotSpotAccessCheck=true ExportTwice
  */
 
 import java.lang.reflect.Module;
--- a/test/runtime/modules/JVMAddModuleExports.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/JVMAddModuleExports.java	Wed Feb 18 11:29:28 2015 -0500
@@ -23,8 +23,11 @@
 
 /*
  * @test
- * @library /testlibrary
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc JVMAddModuleExports
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
+ * @build JVMAddModuleExports
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc JVMAddModuleExports
  */
 
 import java.lang.reflect.Module;
--- a/test/runtime/modules/JVMAddModulePackage.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/JVMAddModulePackage.java	Wed Feb 18 11:29:28 2015 -0500
@@ -23,8 +23,11 @@
 
 /*
  * @test
- * @library /testlibrary
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc JVMAddModulePackage
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
+ * @build JVMAddModulePackage
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc JVMAddModulePackage
  */
 
 import static com.oracle.java.testlibrary.Asserts.*;
--- a/test/runtime/modules/JVMAddReadsModule.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/JVMAddReadsModule.java	Wed Feb 18 11:29:28 2015 -0500
@@ -23,8 +23,11 @@
 
 /*
  * @test
- * @library /testlibrary
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc JVMAddReadsModule
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
+ * @build JVMAddReadsModule
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc JVMAddReadsModule
  */
 
 import static com.oracle.java.testlibrary.Asserts.*;
--- a/test/runtime/modules/JVMCanReadModule.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/JVMCanReadModule.java	Wed Feb 18 11:29:28 2015 -0500
@@ -23,8 +23,11 @@
 
 /*
  * @test
- * @library /testlibrary
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc JVMCanReadModule
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
+ * @build JVMCanReadModule
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc JVMCanReadModule
  */
 
 import static com.oracle.java.testlibrary.Asserts.*;
--- a/test/runtime/modules/JVMDefineModule.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/JVMDefineModule.java	Wed Feb 18 11:29:28 2015 -0500
@@ -23,8 +23,11 @@
 
 /*
  * @test
- * @library /testlibrary
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc JVMDefineModule
+ * @library /testlibrary  /../../test/lib /compiler/whitebox ..
+ * @build JVMDefineModule
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc JVMDefineModule
  */
 
 import static com.oracle.java.testlibrary.Asserts.*;
--- a/test/runtime/modules/JVMIsExportedToModule.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/JVMIsExportedToModule.java	Wed Feb 18 11:29:28 2015 -0500
@@ -23,8 +23,11 @@
 
 /*
  * @test
- * @library /testlibrary
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc JVMIsExportedToModule
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
+ * @build JVMIsExportedToModule
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:AddModuleExports=java.base/sun.misc JVMIsExportedToModule
  */
 
 import static com.oracle.java.testlibrary.Asserts.*;
--- a/test/runtime/modules/LoadUnloadModuleStress.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/LoadUnloadModuleStress.java	Wed Feb 18 11:29:28 2015 -0500
@@ -24,8 +24,11 @@
 /*
  * @test
  * @summary Ensure module information is cleaned when owning class loader unloads
- * @library /testlibrary
- * @run main/othervm -XX:AddModuleExports=java.base/sun.misc -Xmx64m LoadUnloadModuleStress 15000
+ * @library /testlibrary /../../test/lib /compiler/whitebox ..
+ * @build LoadUnloadModuleStress
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx64m -XX:AddModuleExports=java.base/sun.misc -Xmx64m LoadUnloadModuleStress 15000
  */
 
 import java.lang.ref.WeakReference;
--- a/test/runtime/modules/ModuleHelper.java	Tue Feb 17 12:45:53 2015 -0800
+++ b/test/runtime/modules/ModuleHelper.java	Wed Feb 18 11:29:28 2015 -0500
@@ -21,57 +21,47 @@
  * questions.
  */
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.lang.reflect.Module;
+import com.oracle.java.testlibrary.*;
+import sun.hotspot.WhiteBox;
 
 public class ModuleHelper {
 
     public static Module DefineModule(String name, Object loader, String[] pkgs) throws Throwable {
-        return DefineModule(name, "1.0", "location", loader, pkgs);
+        WhiteBox wb = WhiteBox.getWhiteBox();
+        return (Module)wb.DefineModule(name, "1.0", "/location", loader, pkgs);
     }
 
     public static Module DefineModule(String name, String version, String location,
                                       Object loader, String[] pkgs) throws Throwable {
-        return (Module)invoke(findMethod("defineModule"), name, version, location, loader, pkgs);
+        WhiteBox wb = WhiteBox.getWhiteBox();
+        return (Module)wb.DefineModule(name, version, location, loader, pkgs);
     }
 
     public static void AddModuleExports(Object from, String pkg, Object to) throws Throwable {
-        invoke(findMethod("addModuleExports"), from, pkg, to);
+        WhiteBox wb = WhiteBox.getWhiteBox();
+        wb.AddModuleExports(from, pkg, to);
     }
 
     public static void AddReadsModule(Object from, Object to) throws Throwable {
-        invoke(findMethod("addReadsModule"), from, to);
+        WhiteBox wb = WhiteBox.getWhiteBox();
+        wb.AddReadsModule(from, to);
     }
 
     public static void AddModulePackage(Object m, String pkg) throws Throwable {
-        invoke(findMethod("addModulePackage"), m, pkg);
+        WhiteBox wb = WhiteBox.getWhiteBox();
+        wb.AddModulePackage(m, pkg);
     }
 
     public static boolean CanReadModule(Object from, Object to) throws Throwable {
-        return (boolean)invoke(findMethod("canReadModule"), from, to);
+        WhiteBox wb = WhiteBox.getWhiteBox();
+        return wb.CanReadModule(from, to);
     }
 
     public static boolean IsExportedToModule(Object from, String pkg,
                                              Object to) throws Throwable {
-        return (boolean)invoke(findMethod("isExportedToModule"), from, pkg, to);
+        WhiteBox wb = WhiteBox.getWhiteBox();
+        return wb.IsExportedToModule(from, pkg, to);
     }
 
-    private static Object invoke(Method m, Object... args) throws Throwable {
-        try {
-            return m.invoke(null, args);
-        } catch (InvocationTargetException e) {
-            throw e.getCause();
-        }
-    }
-
-    private static Method findMethod(String name) {
-        for (Method m : sun.misc.ModuleHelper.class.getDeclaredMethods()) {
-            if (m.getName().equals(name)) {
-                m.setAccessible(true);
-                return m;
-            }
-        }
-        throw new RuntimeException("Failed to find method " + name + "in sun.misc.ModuleHelper");
-    }
 }