changeset 18562:4f27e4a4b4c5

added check that HotSpotGraalRuntimeProvider is accessed correctly within the scope of a replay compilation
author Doug Simon <doug.simon@oracle.com>
date Wed, 26 Nov 2014 23:24:13 +0100
parents 84bef219afc7
children e43065342bab
files graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/remote/Context.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java
diffstat 3 files changed, 34 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/remote/Context.java	Wed Nov 26 23:11:03 2014 +0100
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/remote/Context.java	Wed Nov 26 23:24:13 2014 +0100
@@ -488,16 +488,19 @@
         return true;
     }
 
-    private Leave leave;
+    private NoContext leave;
     int activeInvocations;
 
-    public Leave leave() {
-        return new Leave();
+    /**
+     * Enters a scope that disables the {@linkplain Context#getCurrent() current} context. The
+     * disabled scope is exited when {@link NoContext#close()} is called on the returned object.
+     */
+    public NoContext leave() {
+        return new NoContext();
     }
 
-    public class Leave implements AutoCloseable {
-
-        Leave() {
+    public class NoContext implements AutoCloseable {
+        NoContext() {
             assert currentContext.get() == Context.this;
             assert Context.this.leave == null;
             Context.this.leave = this;
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java	Wed Nov 26 23:11:03 2014 +0100
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java	Wed Nov 26 23:24:13 2014 +0100
@@ -734,11 +734,15 @@
     protected CompilationResult recompile(Context c, Mode mode, ResolvedJavaMethod installedCodeOwner) {
         try (Debug.Scope s = Debug.scope(mode.name(), new DebugDumpScope(mode.name(), true))) {
 
-            StructuredGraph graphToCompile = parseForCompile(installedCodeOwner);
+            StructuredGraph graphToCompile;
+            CallingConvention cc;
 
-            lastCompiledGraph = graphToCompile;
-
-            CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graphToCompile.method(), false);
+            try (Context.NoContext l = c.leave()) {
+                graphToCompile = parseForCompile(installedCodeOwner);
+                lastCompiledGraph = graphToCompile;
+                cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graphToCompile.method(), false);
+            }
+            graphToCompile = c.get(graphToCompile);
             Request<CompilationResult> request = c.get(new GraalCompiler.Request<>(graphToCompile, null, cc, installedCodeOwner, getProviders(), getBackend(), getCodeCache().getTarget(), null,
                             getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, getProfilingInfo(graphToCompile), getSpeculationLog(), getSuites(), new CompilationResult(),
                             CompilationResultBuilderFactory.Default));
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java	Wed Nov 26 23:11:03 2014 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java	Wed Nov 26 23:24:13 2014 +0100
@@ -41,6 +41,7 @@
 import com.oracle.graal.api.replacements.*;
 import com.oracle.graal.api.runtime.*;
 import com.oracle.graal.compiler.common.*;
+import com.oracle.graal.compiler.common.remote.*;
 import com.oracle.graal.compiler.target.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.graph.*;
@@ -80,10 +81,26 @@
     }
 
     /**
+     * Checks that all accesses to a {@link HotSpotGraalRuntimeProvider} within a replay context are
+     * through references to a captured {@link HotSpotGraalRuntimeProvider}, not through the static
+     * {@link HotSpotGraalRuntimeProvider} instance of the runtime hosting the replay.
+     */
+    private static boolean checkRuntimeAccess() {
+        Context c = Context.getCurrent();
+        if (c != null) {
+            if (!c.inProxyInvocation()) {
+                throw new GraalInternalError("Cannot access HotSpotGraalRuntime statically in replay/remote context");
+            }
+        }
+        return true;
+    }
+
+    /**
      * Gets the singleton {@link HotSpotGraalRuntime} object.
      */
     public static HotSpotGraalRuntime runtime() {
         assert instance != null;
+        assert checkRuntimeAccess();
         return instance;
     }