8149076: [JVMCI] missing ResourceMark in JVMCIRuntime::initialize_HotSpotJVMCIRuntime
authornever
Fri, 05 Feb 2016 12:27:02 -0800
changeset 35835 7fade08f69b2
parent 35828 495df8a5e28a
child 35836 020a9af9151d
8149076: [JVMCI] missing ResourceMark in JVMCIRuntime::initialize_HotSpotJVMCIRuntime Reviewed-by: twisti, iignatyev
hotspot/src/share/vm/jvmci/jvmciRuntime.cpp
hotspot/test/compiler/jvmci/JVM_GetJVMCIRuntimeTest.java
--- a/hotspot/src/share/vm/jvmci/jvmciRuntime.cpp	Fri Feb 05 18:24:41 2016 +0000
+++ b/hotspot/src/share/vm/jvmci/jvmciRuntime.cpp	Fri Feb 05 12:27:02 2016 -0800
@@ -634,6 +634,7 @@
 
 void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(TRAPS) {
   if (JNIHandles::resolve(_HotSpotJVMCIRuntime_instance) == NULL) {
+    ResourceMark rm;
 #ifdef ASSERT
     // This should only be called in the context of the JVMCI class being initialized
     TempNewSymbol name = SymbolTable::new_symbol("jdk/vm/ci/runtime/JVMCI", CHECK);
--- a/hotspot/test/compiler/jvmci/JVM_GetJVMCIRuntimeTest.java	Fri Feb 05 18:24:41 2016 +0000
+++ b/hotspot/test/compiler/jvmci/JVM_GetJVMCIRuntimeTest.java	Fri Feb 05 12:27:02 2016 -0800
@@ -35,6 +35,16 @@
  *      -Dcompiler.jvmci.JVM_GetJVMCIRuntimeTest.positive=false
  *      -XX:-EnableJVMCI
  *      compiler.jvmci.JVM_GetJVMCIRuntimeTest
+ * @run main/othervm -XX:+UnlockExperimentalVMOptions
+ *      -Dcompiler.jvmci.JVM_GetJVMCIRuntimeTest.positive=true
+ *      -Dcompiler.jvmci.JVM_GetJVMCIRuntimeTest.threaded=true
+ *      -XX:+EnableJVMCI
+ *      compiler.jvmci.JVM_GetJVMCIRuntimeTest
+ * @run main/othervm -XX:+UnlockExperimentalVMOptions
+ *      -Dcompiler.jvmci.JVM_GetJVMCIRuntimeTest.positive=false
+ *      -Dcompiler.jvmci.JVM_GetJVMCIRuntimeTest.threaded=true
+ *      -XX:-EnableJVMCI
+ *      compiler.jvmci.JVM_GetJVMCIRuntimeTest
 
  */
 
@@ -43,22 +53,27 @@
 import jdk.vm.ci.runtime.JVMCI;
 import jdk.test.lib.Asserts;
 
-import java.lang.reflect.Method;
-
-public class JVM_GetJVMCIRuntimeTest {
+public class JVM_GetJVMCIRuntimeTest implements Runnable {
     private static final boolean IS_POSITIVE = Boolean.getBoolean(
             "compiler.jvmci.JVM_GetJVMCIRuntimeTest.positive");
-
-    private final Method initializeRuntime;
+    private static final boolean IN_THREAD = Boolean.getBoolean(
+            "compiler.jvmci.JVM_GetJVMCIRuntimeTest.threaded");
 
-    public static void main(String[] args) {
-        new JVM_GetJVMCIRuntimeTest().runTest();
+    public static void main(String[] args) throws Throwable {
+        JVM_GetJVMCIRuntimeTest instance = new JVM_GetJVMCIRuntimeTest();
+        if (IN_THREAD) {
+            Thread t = new Thread(instance);
+            t.start();
+            t.join();
+        } else {
+            instance.run();
+        }
     }
 
-    private void runTest() {
+    public void run() {
         Object result;
         try {
-            result = invoke();
+            result = JVMCI.getRuntime();
         } catch (InternalError e) {
             if (IS_POSITIVE) {
                 throw new AssertionError("unexpected exception", e);
@@ -70,28 +85,8 @@
         }
         Asserts.assertNotNull(result,
                 "initializeRuntime returned null");
-        Asserts.assertEQ(result, invoke(),
+        Asserts.assertEQ(result, JVMCI.getRuntime(),
                 "initializeRuntime returns different results");
 
     }
-    private Object invoke() {
-        Object result;
-        try {
-            result = initializeRuntime.invoke(JVMCI.class);
-        } catch (ReflectiveOperationException e) {
-            throw new Error("can't invoke initializeRuntime", e);
-        }
-        return result;
-    }
-
-    private JVM_GetJVMCIRuntimeTest() {
-        Method method;
-        try {
-            method = JVMCI.class.getDeclaredMethod("initializeRuntime");
-            method.setAccessible(true);
-        } catch (NoSuchMethodException e) {
-            throw new Error("can't find JVMCI::initializeRuntime", e);
-        }
-        initializeRuntime = method;
-    }
 }