changeset 9605:1a87230c775d

removed embedding of compiler creating objects into installed code (HotSpot cannot support this)
author Doug Simon <doug.simon@oracle.com>
date Tue, 07 May 2013 22:42:46 +0200
parents 8fe7e6e7b443
children 0f7bd899a1a8 66db0353f55a
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/VMErrorNode.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MonitorSnippets.java
diffstat 3 files changed, 18 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Tue May 07 21:51:18 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Tue May 07 22:42:46 2013 +0200
@@ -126,13 +126,6 @@
     private final Map<ResolvedJavaMethod, Stub> stubs = new HashMap<>();
 
     /**
-     * Holds onto objects that will be embedded in compiled code. HotSpot treats oops embedded in
-     * code as weak references so without an external strong root, such an embedded oop will quickly
-     * die. This in turn will cause the nmethod to be unloaded.
-     */
-    private final Map<Object, Object> gcRoots = new HashMap<>();
-
-    /**
      * The offset from the origin of an array to the first element.
      * 
      * @return the offset in bytes
@@ -1262,20 +1255,6 @@
         return constant.getPrimitiveAnnotation() != null;
     }
 
-    /**
-     * Registers an object created by the compiler and referenced by some generated code. HotSpot
-     * treats oops embedded in code as weak references so without an external strong root, such an
-     * embedded oop will quickly die. This in turn will cause the nmethod to be unloaded.
-     */
-    public synchronized Object registerGCRoot(Object object) {
-        Object existing = gcRoots.get(object);
-        if (existing != null) {
-            return existing;
-        }
-        gcRoots.put(object, object);
-        return object;
-    }
-
     @Override
     public Constant readUnsafeConstant(Kind kind, Object base, long displacement) {
         switch (kind) {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/VMErrorNode.java	Tue May 07 21:51:18 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/VMErrorNode.java	Tue May 07 22:42:46 2013 +0200
@@ -27,7 +27,6 @@
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.gen.*;
 import com.oracle.graal.compiler.target.*;
-import com.oracle.graal.hotspot.meta.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.type.*;
 import com.oracle.graal.replacements.*;
@@ -38,11 +37,11 @@
  */
 public final class VMErrorNode extends DeoptimizingStubCall implements LIRGenLowerable {
 
-    @Input private ValueNode format;
+    private final String format;
     @Input private ValueNode value;
     public static final Descriptor VM_ERROR = new Descriptor("vm_error", false, void.class, Object.class, Object.class, long.class);
 
-    public VMErrorNode(ValueNode format, ValueNode value) {
+    private VMErrorNode(String format, ValueNode value) {
         super(StampFactory.forVoid());
         this.format = format;
         this.value = value;
@@ -50,21 +49,19 @@
 
     @Override
     public void generate(LIRGenerator gen) {
-        String where = "in compiled code for " + MetaUtil.format("%H.%n(%p)", gen.method());
+        String whereString = "in compiled code for " + MetaUtil.format("%H.%n(%p)", gen.method());
 
-        HotSpotRuntime runtime = (HotSpotRuntime) gen.getRuntime();
-        Constant whereArg = Constant.forObject(runtime.registerGCRoot(where));
-        Value formatArg;
-        if (format.isConstant() && format.kind() == Kind.Object) {
-            formatArg = Constant.forObject(runtime.registerGCRoot(format.asConstant().asObject()));
-        } else {
-            formatArg = gen.operand(format);
-        }
+        // As these strings will end up embedded as oops in the code, they
+        // must be interned or else they will cause the nmethod to be unloaded
+        // (nmethods are a) weak GC roots and b) unloaded if any of their
+        // embedded oops become unreachable).
+        Constant whereArg = Constant.forObject(whereString.intern());
+        Constant formatArg = Constant.forObject(format.intern());
 
         RuntimeCallTarget stub = gen.getRuntime().lookupRuntimeCall(VMErrorNode.VM_ERROR);
         gen.emitCall(stub, stub.getCallingConvention(), null, whereArg, formatArg, gen.operand(value));
     }
 
     @NodeIntrinsic
-    public static native void vmError(String format, long value);
+    public static native void vmError(@ConstantNodeParameter String format, long value);
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MonitorSnippets.java	Tue May 07 21:51:18 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MonitorSnippets.java	Tue May 07 22:42:46 2013 +0200
@@ -37,7 +37,6 @@
 import com.oracle.graal.graph.*;
 import com.oracle.graal.graph.Node.NodeIntrinsic;
 import com.oracle.graal.graph.iterators.*;
-import com.oracle.graal.hotspot.meta.*;
 import com.oracle.graal.hotspot.nodes.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.extended.*;
@@ -373,7 +372,7 @@
     }
 
     @Snippet
-    private static void checkCounter(String errMsg) {
+    private static void checkCounter(@ConstantParameter String errMsg) {
         final Word counter = MonitorCounterNode.counter();
         final int count = counter.readInt(0, MONITOR_COUNTER_LOCATION);
         if (count != 0) {
@@ -498,7 +497,7 @@
                     List<ReturnNode> rets = graph.getNodes().filter(ReturnNode.class).snapshot();
                     for (ReturnNode ret : rets) {
                         returnType = checkCounter.getMethod().getSignature().getReturnType(checkCounter.getMethod().getDeclaringClass());
-                        Object msg = ((HotSpotRuntime) runtime).registerGCRoot("unbalanced monitors in " + MetaUtil.format("%H.%n(%p)", graph.method()) + ", count = %d");
+                        String msg = "unbalanced monitors in " + MetaUtil.format("%H.%n(%p)", graph.method()) + ", count = %d";
                         ConstantNode errMsg = ConstantNode.forObject(msg, runtime, graph);
                         callTarget = graph.add(new MethodCallTargetNode(InvokeKind.Static, checkCounter.getMethod(), new ValueNode[]{errMsg}, returnType));
                         invoke = graph.add(new InvokeNode(callTarget, 0));
@@ -506,7 +505,12 @@
                         FrameState stateAfter = new FrameState(graph.method(), FrameState.AFTER_BCI, new ValueNode[0], stack, new ValueNode[0], false, false);
                         invoke.setStateAfter(graph.add(stateAfter));
                         graph.addBeforeFixed(ret, invoke);
-                        inlineeGraph = replacements.getSnippet(checkCounter.getMethod());
+
+                        Arguments args = new Arguments(checkCounter);
+                        args.addConst("errMsg", msg);
+                        inlineeGraph = template(args).copySpecializedGraph();
+
+                        // inlineeGraph = replacements.getSnippet(checkCounter.getMethod());
                         InliningUtil.inline(invoke, inlineeGraph, false);
                     }
                 }