changeset 14758:c612c2742a4f

extend graph builder and CompilationResult for substrateVM
author Erik Eckstein <erik.eckstein@oracle.com>
date Wed, 26 Mar 2014 10:15:15 +0100
parents 91c88fc2157c
children 56721cd3f8ba
files graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java graal/com.oracle.graal.java/src/com/oracle/graal/java/FrameStateBuilder.java graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java
diffstat 3 files changed, 44 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java	Wed Mar 26 10:10:12 2014 +0100
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java	Wed Mar 26 10:15:15 2014 +0100
@@ -602,7 +602,15 @@
         addInfopoint(new Infopoint(codePos, debugInfo, reason));
     }
 
-    private void addInfopoint(Infopoint infopoint) {
+    /**
+     * Records a custom infopoint in the code section.
+     * 
+     * Compiler implementations can use this method to record non-standard infopoints, which are not
+     * handled by the dedicated methods like {@link #recordCall}.
+     * 
+     * @param infopoint the infopoint to record, usually a derived class from {@link Infopoint}
+     */
+    public void addInfopoint(Infopoint infopoint) {
         // The infopoints list must always be sorted
         if (!infopoints.isEmpty() && infopoints.get(infopoints.size() - 1).pcOffset >= infopoint.pcOffset) {
             // This re-sorting should be very rare
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/FrameStateBuilder.java	Wed Mar 26 10:10:12 2014 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/FrameStateBuilder.java	Wed Mar 26 10:15:15 2014 +0100
@@ -386,6 +386,10 @@
         return stack[i];
     }
 
+    public final ValueNode lockAt(int i) {
+        return lockedObjects[i];
+    }
+
     /**
      * Adds a locked monitor to this frame state.
      * 
@@ -470,6 +474,11 @@
         stack[i] = x;
     }
 
+    public void storeLock(int i, ValueNode x) {
+        assert x == null || x.isAlive() && (lockedObjects[i] == null || x.getKind() == lockedObjects[i].getKind()) : "unexpected lock value: " + x;
+        lockedObjects[i] = x;
+    }
+
     /**
      * Pushes an instruction onto the stack with the expected type.
      * 
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Wed Mar 26 10:10:12 2014 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Wed Mar 26 10:15:15 2014 +0100
@@ -139,7 +139,7 @@
          * the jump. When the block is seen the second time, a {@link MergeNode} is created to
          * correctly merge the now two different predecessor states.
          */
-        private static class BlockPlaceholderNode extends FixedWithNextNode {
+        protected static class BlockPlaceholderNode extends FixedWithNextNode {
 
             /*
              * Cannot be explicitly declared as a Node type since it is not an input; would cause
@@ -238,6 +238,7 @@
             }
             frameState.clearNonLiveLocals(blockMap.startBlock, liveness, true);
             ((StateSplit) lastInstr).setStateAfter(frameState.create(0));
+            finishPrepare(lastInstr);
 
             if (graphBuilderConfig.eagerInfopointMode()) {
                 InfopointNode ipn = currentGraph.add(new InfopointNode(InfopointReason.METHOD_START, frameState.create(0)));
@@ -285,6 +286,15 @@
             indent.outdent();
         }
 
+        /**
+         * A hook for derived classes to modify the graph start instruction or append new
+         * instructions to it.
+         * 
+         * @param startInstr The start instruction of the graph.
+         */
+        protected void finishPrepare(FixedWithNextNode startInstr) {
+        }
+
         private Block unwindBlock(int bci) {
             if (unwindBlock == null) {
                 unwindBlock = new ExceptionDispatchBlock();
@@ -454,7 +464,7 @@
                 dispatchState.setRethrowException(true);
             }
             FixedNode target = createTarget(dispatchBlock, dispatchState);
-            dispatchBegin.setNext(target);
+            finishInstruction(dispatchBegin, dispatchState).setNext(target);
             return dispatchBegin;
         }
 
@@ -1754,6 +1764,8 @@
             assert lastInstr.next() == null : "instructions already appended at block " + block;
             Debug.log("  frameState: %s", frameState);
 
+            lastInstr = finishInstruction(lastInstr, frameState);
+
             int endBCI = stream.endBCI();
 
             stream.setBCI(block.startBci);
@@ -1803,6 +1815,7 @@
                         }
                     }
                 }
+                lastInstr = finishInstruction(lastInstr, frameState);
                 if (bci < endBCI) {
                     if (bci > block.endBci) {
                         assert !block.successors.get(0).isExceptionEntry;
@@ -1815,6 +1828,17 @@
             }
         }
 
+        /**
+         * A hook for derived classes to modify the last instruction or add other instructions.
+         * 
+         * @param instr The last instruction (= fixed node) which was added.
+         * @param state The current frame state.
+         * @Returns Returns the (new) last instruction.
+         */
+        protected FixedWithNextNode finishInstruction(FixedWithNextNode instr, FrameStateBuilder state) {
+            return instr;
+        }
+
         private final int traceLevel = Options.TraceBytecodeParserLevel.getValue();
 
         private void traceState() {