# HG changeset patch # User Doug Simon # Date 1417378453 -3600 # Node ID b76489300efa2287ff1521c1aec3c44e94bcb9ac # Parent 77b55091cca17826905275c23d75e84ef9c6c15a generalized assertion regarding code that can/cannot execute in replay compilation context diff -r 77b55091cca1 -r b76489300efa 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 Sun Nov 30 21:12:06 2014 +0100 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/remote/Context.java Sun Nov 30 21:14:13 2014 +0100 @@ -37,6 +37,10 @@ /** * Manages a context for replay or remote compilation. + * + * With respect to replay or remote compilation, certain objects only exist on the VM side of the + * VM-compiler boundary. These are objects that encapsulate compiler references to user heap objects + * or other VM data such as native VM objects representing Java classes and methods. */ public class Context implements AutoCloseable { @@ -463,6 +467,24 @@ return true; } + /** + * Asserts that the current caller is in code that is on the VM side. + * + * @param errorMessage the error message used for the {@link GraalInternalError} thrown if the + * check fails + * @return true if the check succeeds + * @throw AssertionError if the check fails + */ + public static boolean assertInLocal(String errorMessage) { + Context c = Context.getCurrent(); + if (c != null) { + if (!c.inProxyInvocation()) { + throw new AssertionError(errorMessage); + } + } + return true; + } + private NoContext leave; int activeInvocations; diff -r 77b55091cca1 -r b76489300efa 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 Sun Nov 30 21:12:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Sun Nov 30 21:14:13 2014 +0100 @@ -85,14 +85,8 @@ * 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; + public static boolean checkRuntimeAccess() { + return Context.assertInLocal("Cannot access HotSpotGraalRuntime statically in replay/remote context"); } /** diff -r 77b55091cca1 -r b76489300efa graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMetaspaceConstantImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMetaspaceConstantImpl.java Sun Nov 30 21:12:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMetaspaceConstantImpl.java Sun Nov 30 21:14:13 2014 +0100 @@ -25,6 +25,7 @@ import java.util.*; import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.common.remote.*; import com.oracle.graal.hotspot.HotSpotVMConfig.CompressEncoding; public final class HotSpotMetaspaceConstantImpl extends PrimitiveConstant implements HotSpotMetaspaceConstant, VMConstant, Remote { @@ -46,6 +47,7 @@ super(kind, primitive); this.metaspaceObject = metaspaceObject; this.compressed = compressed; + assert Context.assertInLocal("Should not create metaspace constants here"); } @Override diff -r 77b55091cca1 -r b76489300efa graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotObjectConstantImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotObjectConstantImpl.java Sun Nov 30 21:12:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotObjectConstantImpl.java Sun Nov 30 21:14:13 2014 +0100 @@ -28,6 +28,7 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.common.remote.*; import com.oracle.graal.graph.*; import com.oracle.graal.lir.*; @@ -95,6 +96,7 @@ assert stableDimension == 0 || (object != null && object.getClass().isArray()); assert stableDimension >= 0 && stableDimension <= 255; assert !isDefaultStable || stableDimension > 0; + assert Context.assertInLocal("Should not create object constants here"); } private HotSpotObjectConstantImpl(Object object, boolean compressed) {