# HG changeset patch # User Doug Simon # Date 1417040653 -3600 # Node ID 4f27e4a4b4c594986323f9310fa66da6a01547ef # Parent 84bef219afc7ab09d4c7bb2b4210b9e0ba382ef2 added check that HotSpotGraalRuntimeProvider is accessed correctly within the scope of a replay compilation diff -r 84bef219afc7 -r 4f27e4a4b4c5 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/remote/Context.java --- 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; diff -r 84bef219afc7 -r 4f27e4a4b4c5 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java --- 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 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)); diff -r 84bef219afc7 -r 4f27e4a4b4c5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- 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; }