diff graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2616:3558ca7088c0

FrameState and Graphviz changes: * removed popx, pushx methods from GraphBuilder * FrameState subclass of Value * added String shortName() to Node * added GraphvizPrinter option to use short names * small hack in GraphvizPrinter: omit FrameState->Local connections * added GraalGraphviz to implicit classpatch (read from GRAAL env var)
author Lukas Stadler <lukas.stadler@jku.at>
date Mon, 09 May 2011 17:00:25 +0200
parents 5768534fd4e5
children dd115f80acf8
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java	Mon May 09 14:11:13 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java	Mon May 09 17:00:25 2011 +0200
@@ -182,8 +182,7 @@
             flags |= Flag.HasHandler.mask;
         }
 
-        FrameState initialState = frameState.create(-1);
-        startBlock.mergeOrClone(initialState, rootMethod);
+        startBlock.mergeOrClone(frameState, rootMethod);
         BlockBegin syncHandler = null;
 
         // 3. setup internal state for appending instructions
@@ -193,7 +192,7 @@
 
         if (isSynchronized(rootMethod.accessFlags())) {
             // 4A.1 add a monitor enter to the start block
-            rootMethodSynchronizedObject = synchronizedObject(initialState, compilation.method);
+            rootMethodSynchronizedObject = synchronizedObject(frameState, compilation.method);
             genMonitorEnter(rootMethodSynchronizedObject, Instruction.SYNCHRONIZATION_ENTRY_BCI);
             // 4A.2 finish the start block
             finishStartBlock(startBlock, stdEntry);
@@ -251,84 +250,12 @@
         return stream.nextBCI();
     }
 
-    private void ipush(Value x) {
-        frameState.ipush(x);
-    }
-
-    private void lpush(Value x) {
-        frameState.lpush(x);
-    }
-
-    private void fpush(Value x) {
-        frameState.fpush(x);
-    }
-
-    private void dpush(Value x) {
-        frameState.dpush(x);
-    }
-
-    private void apush(Value x) {
-        frameState.apush(x);
-    }
-
-    private void wpush(Value x) {
-        frameState.wpush(x);
-    }
-
-    private void push(CiKind kind, Value x) {
-        frameState.push(kind, x);
-    }
-
-    private void pushReturn(CiKind kind, Value x) {
-        if (kind != CiKind.Void) {
-            frameState.push(kind.stackKind(), x);
-        }
-    }
-
-    private Value ipop() {
-        return frameState.ipop();
-    }
-
-    private Value lpop() {
-        return frameState.lpop();
-    }
-
-    private Value fpop() {
-        return frameState.fpop();
-    }
-
-    private Value dpop() {
-        return frameState.dpop();
-    }
-
-    private Value apop() {
-        return frameState.apop();
-    }
-
-    private Value wpop() {
-        return frameState.wpop();
-    }
-
-    private Value pop(CiKind kind) {
-        return frameState.pop(kind);
-    }
-
-    private CiKind peekKind() {
-        Value top = frameState.stackAt(frameState.stackSize() - 1);
-        if (top == null) {
-            top = frameState.stackAt(frameState.stackSize() - 2);
-            assert top != null;
-            assert top.kind.isDoubleWord();
-        }
-        return top.kind;
-    }
-
     private void loadLocal(int index, CiKind kind) {
-        push(kind, frameState.loadLocal(index));
+        frameState.push(kind, frameState.loadLocal(index));
     }
 
     private void storeLocal(CiKind kind, int index) {
-        frameState.storeLocal(index, pop(kind));
+        frameState.storeLocal(index, frameState.pop(kind));
     }
 
     List<ExceptionHandler> handleException(Instruction x, int bci) {
@@ -380,7 +307,7 @@
         assert entryState == null || curState.locksSize() == entryState.locksSize() : "locks do not match : cur:" + curState.locksSize() + " entry:" + entryState.locksSize();
 
         // exception handler starts with an empty expression stack
-        curState = curState.copyWithEmptyStack();
+        curState = curState.duplicateWithEmptyStack();
 
         entry.mergeOrClone(curState, method());
 
@@ -422,13 +349,13 @@
             // this is a load of class constant which might be unresolved
             RiType riType = (RiType) con;
             if (!riType.isResolved() || C1XOptions.TestPatching) {
-                push(CiKind.Object, append(new ResolveClass(riType, RiType.Representation.JavaClass, null, graph)));
+                frameState.push(CiKind.Object, append(new ResolveClass(riType, RiType.Representation.JavaClass, null, graph)));
             } else {
-                push(CiKind.Object, append(new Constant(riType.getEncoding(Representation.JavaClass), graph)));
+                frameState.push(CiKind.Object, append(new Constant(riType.getEncoding(Representation.JavaClass), graph)));
             }
         } else if (con instanceof CiConstant) {
             CiConstant constant = (CiConstant) con;
-            push(constant.kind.stackKind(), appendConstant(constant));
+            frameState.push(constant.kind.stackKind(), appendConstant(constant));
         } else {
             throw new Error("lookupConstant returned an object of incorrect type");
         }
@@ -436,21 +363,21 @@
 
     void genLoadIndexed(CiKind kind) {
         FrameState stateBefore = frameState.create(bci());
-        Value index = ipop();
-        Value array = apop();
+        Value index = frameState.ipop();
+        Value array = frameState.apop();
         Value length = null;
         if (cseArrayLength(array)) {
             length = append(new ArrayLength(array, stateBefore, graph));
         }
         Value v = append(new LoadIndexed(array, index, length, kind, stateBefore, graph));
-        push(kind.stackKind(), v);
+        frameState.push(kind.stackKind(), v);
     }
 
     void genStoreIndexed(CiKind kind) {
         FrameState stateBefore = frameState.create(bci());
-        Value value = pop(kind.stackKind());
-        Value index = ipop();
-        Value array = apop();
+        Value value = frameState.pop(kind.stackKind());
+        Value index = frameState.ipop();
+        Value array = frameState.apop();
         Value length = null;
         if (cseArrayLength(array)) {
             length = append(new ArrayLength(array, stateBefore, graph));
@@ -552,41 +479,41 @@
     }
 
     void genArithmeticOp(CiKind result, int opcode, CiKind x, CiKind y, FrameState state) {
-        Value yValue = pop(y);
-        Value xValue = pop(x);
+        Value yValue = frameState.pop(y);
+        Value xValue = frameState.pop(x);
         Value result1 = append(new ArithmeticOp(opcode, result, xValue, yValue, isStrict(method().accessFlags()), state, graph));
-        push(result, result1);
+        frameState.push(result, result1);
     }
 
     void genNegateOp(CiKind kind) {
-        push(kind, append(new NegateOp(pop(kind), graph)));
+        frameState.push(kind, append(new NegateOp(frameState.pop(kind), graph)));
     }
 
     void genShiftOp(CiKind kind, int opcode) {
-        Value s = ipop();
-        Value x = pop(kind);
+        Value s = frameState.ipop();
+        Value x = frameState.pop(kind);
         // note that strength reduction of e << K >>> K is correctly handled in canonicalizer now
-        push(kind, append(new ShiftOp(opcode, x, s, graph)));
+        frameState.push(kind, append(new ShiftOp(opcode, x, s, graph)));
     }
 
     void genLogicOp(CiKind kind, int opcode) {
-        Value y = pop(kind);
-        Value x = pop(kind);
-        push(kind, append(new LogicOp(opcode, x, y, graph)));
+        Value y = frameState.pop(kind);
+        Value x = frameState.pop(kind);
+        frameState.push(kind, append(new LogicOp(opcode, x, y, graph)));
     }
 
     void genCompareOp(CiKind kind, int opcode, CiKind resultKind) {
-        Value y = pop(kind);
-        Value x = pop(kind);
+        Value y = frameState.pop(kind);
+        Value x = frameState.pop(kind);
         Value value = append(new CompareOp(opcode, resultKind, x, y, graph));
         if (!resultKind.isVoid()) {
-            ipush(value);
+            frameState.ipush(value);
         }
     }
 
     void genConvert(int opcode, CiKind from, CiKind to) {
         CiKind tt = to.stackKind();
-        push(tt, append(new Convert(opcode, pop(from.stackKind()), tt, graph)));
+        frameState.push(tt, append(new Convert(opcode, frameState.pop(from.stackKind()), tt, graph)));
     }
 
     void genIncrement() {
@@ -613,27 +540,27 @@
     void genIfZero(Condition cond) {
         Value y = appendConstant(CiConstant.INT_0);
         FrameState stateBefore = frameState.create(bci());
-        Value x = ipop();
+        Value x = frameState.ipop();
         ifNode(x, cond, y, stateBefore);
     }
 
     void genIfNull(Condition cond) {
         FrameState stateBefore = frameState.create(bci());
         Value y = appendConstant(CiConstant.NULL_OBJECT);
-        Value x = apop();
+        Value x = frameState.apop();
         ifNode(x, cond, y, stateBefore);
     }
 
     void genIfSame(CiKind kind, Condition cond) {
         FrameState stateBefore = frameState.create(bci());
-        Value y = pop(kind);
-        Value x = pop(kind);
+        Value y = frameState.pop(kind);
+        Value x = frameState.pop(kind);
         ifNode(x, cond, y, stateBefore);
     }
 
     void genThrow(int bci) {
         FrameState stateBefore = frameState.create(bci());
-        Throw t = new Throw(apop(), stateBefore, !noSafepoints(), graph);
+        Throw t = new Throw(frameState.apop(), stateBefore, !noSafepoints(), graph);
         appendWithoutOptimization(t, bci);
     }
 
@@ -642,8 +569,8 @@
         RiType type = constantPool().lookupType(cpi, CHECKCAST);
         boolean isInitialized = !C1XOptions.TestPatching && type.isResolved() && type.isInitialized();
         Value typeInstruction = genResolveClass(RiType.Representation.ObjectHub, type, isInitialized, cpi);
-        CheckCast c = new CheckCast(type, typeInstruction, apop(), null, graph);
-        apush(append(c));
+        CheckCast c = new CheckCast(type, typeInstruction, frameState.apop(), null, graph);
+        frameState.apush(append(c));
         checkForDirectCompare(c);
     }
 
@@ -652,8 +579,8 @@
         RiType type = constantPool().lookupType(cpi, INSTANCEOF);
         boolean isInitialized = !C1XOptions.TestPatching && type.isResolved() && type.isInitialized();
         Value typeInstruction = genResolveClass(RiType.Representation.ObjectHub, type, isInitialized, cpi);
-        InstanceOf i = new InstanceOf(type, typeInstruction, apop(), null, graph);
-        ipush(append(i));
+        InstanceOf i = new InstanceOf(type, typeInstruction, frameState.apop(), null, graph);
+        frameState.ipush(append(i));
         checkForDirectCompare(i);
     }
 
@@ -671,21 +598,21 @@
         if (memoryMap != null) {
             memoryMap.newInstance(n);
         }
-        apush(append(n));
+        frameState.apush(append(n));
     }
 
     void genNewTypeArray(int typeCode) {
         FrameState stateBefore = frameState.create(bci());
         CiKind kind = CiKind.fromArrayTypeCode(typeCode);
         RiType elementType = compilation.runtime.asRiType(kind);
-        apush(append(new NewTypeArray(ipop(), elementType, stateBefore, graph)));
+        frameState.apush(append(new NewTypeArray(frameState.ipop(), elementType, stateBefore, graph)));
     }
 
     void genNewObjectArray(int cpi) {
         RiType type = constantPool().lookupType(cpi, ANEWARRAY);
         FrameState stateBefore = frameState.create(bci());
-        NewArray n = new NewObjectArray(type, ipop(), stateBefore, graph);
-        apush(append(n));
+        NewArray n = new NewObjectArray(type, frameState.ipop(), stateBefore, graph);
+        frameState.apush(append(n));
     }
 
     void genNewMultiArray(int cpi) {
@@ -694,24 +621,24 @@
         int rank = stream().readUByte(bci() + 3);
         Value[] dims = new Value[rank];
         for (int i = rank - 1; i >= 0; i--) {
-            dims[i] = ipop();
+            dims[i] = frameState.ipop();
         }
         NewArray n = new NewMultiArray(type, dims, stateBefore, cpi, constantPool(), graph);
-        apush(append(n));
+        frameState.apush(append(n));
     }
 
     void genGetField(int cpi, RiField field) {
         // Must copy the state here, because the field holder must still be on the stack.
         FrameState stateBefore = frameState.create(bci());
-        LoadField load = new LoadField(apop(), field, stateBefore, graph);
+        LoadField load = new LoadField(frameState.apop(), field, stateBefore, graph);
         appendOptimizedLoadField(field.kind(), load);
     }
 
     void genPutField(int cpi, RiField field) {
         // Must copy the state here, because the field holder must still be on the stack.
         FrameState stateBefore = frameState.create(bci());
-        Value value = pop(field.kind().stackKind());
-        appendOptimizedStoreField(new StoreField(apop(), field, value, stateBefore, graph));
+        Value value = frameState.pop(field.kind().stackKind());
+        appendOptimizedStoreField(new StoreField(frameState.apop(), field, value, stateBefore, graph));
     }
 
     void genGetStatic(int cpi, RiField field) {
@@ -722,7 +649,7 @@
             constantValue = field.constantValue(null);
         }
         if (constantValue != null) {
-            push(constantValue.kind.stackKind(), appendConstant(constantValue));
+            frameState.push(constantValue.kind.stackKind(), appendConstant(constantValue));
         } else {
             Value container = genResolveClass(RiType.Representation.StaticFields, holder, field.isResolved(), cpi);
             LoadField load = new LoadField(container, field, null, graph);
@@ -733,7 +660,7 @@
     void genPutStatic(int cpi, RiField field) {
         RiType holder = field.holder();
         Value container = genResolveClass(RiType.Representation.StaticFields, holder, field.isResolved(), cpi);
-        Value value = pop(field.kind().stackKind());
+        Value value = frameState.pop(field.kind().stackKind());
         StoreField store = new StoreField(container, field, value, null, graph);
         appendOptimizedStoreField(store);
     }
@@ -764,7 +691,7 @@
             Value replacement = memoryMap.load(load);
             if (replacement != load) {
                 // the memory buffer found a replacement for this load (no need to append)
-                push(kind.stackKind(), replacement);
+                frameState.push(kind.stackKind(), replacement);
                 return;
             }
         }
@@ -774,7 +701,7 @@
             // local optimization happened, replace its value in the memory map
             memoryMap.setResult(load, optimized);
         }
-        push(kind.stackKind(), optimized);
+        frameState.push(kind.stackKind(), optimized);
     }
 
     void genInvokeStatic(RiMethod target, int cpi, RiConstantPool constantPool) {
@@ -904,7 +831,7 @@
     private void appendInvoke(int opcode, RiMethod target, Value[] args, int cpi, RiConstantPool constantPool, FrameState stateBefore) {
         CiKind resultType = returnKind(target);
         Value result = append(new Invoke(opcode, resultType.stackKind(), args, target, target.signature().returnType(compilation.method.holder()), stateBefore, graph));
-        pushReturn(resultType, result);
+        frameState.pushReturn(resultType, result);
     }
 
     private RiType getExactType(RiType staticType, Value receiver) {
@@ -1092,7 +1019,7 @@
         list.add(blockAt(bci + offset));
         boolean isSafepoint = isBackwards && !noSafepoints();
         FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null;
-        append(new TableSwitch(ipop(), list, ts.lowKey(), stateBefore, isSafepoint, graph));
+        append(new TableSwitch(frameState.ipop(), list, ts.lowKey(), stateBefore, isSafepoint, graph));
     }
 
     void genLookupswitch() {
@@ -1114,7 +1041,7 @@
         list.add(blockAt(bci + offset));
         boolean isSafepoint = isBackwards && !noSafepoints();
         FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null;
-        append(new LookupSwitch(ipop(), list, keys, stateBefore, isSafepoint, graph));
+        append(new LookupSwitch(frameState.ipop(), list, keys, stateBefore, isSafepoint, graph));
     }
 
     /**
@@ -1217,7 +1144,7 @@
         return result;
     }
 
-    private Value synchronizedObject(FrameState curState2, RiMethod target) {
+    private Value synchronizedObject(FrameStateAccess curState2, RiMethod target) {
         if (isStatic(target.accessFlags())) {
             Constant classConstant = new Constant(target.holder().getEncoding(Representation.JavaClass), graph);
             return appendWithoutOptimization(classConstant, Instruction.SYNCHRONIZATION_ENTRY_BCI);
@@ -1252,7 +1179,7 @@
         // exit the monitor
         genMonitorExit(lock, Instruction.SYNCHRONIZATION_ENTRY_BCI);
 
-        apush(exception);
+        frameState.apush(exception);
         genThrow(bci);
         BlockEnd end = (BlockEnd) lastInstr;
         curBlock.setEnd(end);
@@ -1260,6 +1187,7 @@
 
         curBlock = origBlock;
         frameState.initializeFrom(origState);
+        origState.delete();
         lastInstr = origLast;
     }
 
@@ -1314,7 +1242,7 @@
             // push an exception object onto the stack if we are parsing an exception handler
             if (pushException) {
                 FrameState stateBefore = frameState.create(bci());
-                apush(append(new ExceptionObject(stateBefore, graph)));
+                frameState.apush(append(new ExceptionObject(stateBefore, graph)));
                 pushException = false;
             }
 
@@ -1382,23 +1310,23 @@
         // Checkstyle: stop
         switch (opcode) {
             case NOP            : /* nothing to do */ break;
-            case ACONST_NULL    : apush(appendConstant(CiConstant.NULL_OBJECT)); break;
-            case ICONST_M1      : ipush(appendConstant(CiConstant.INT_MINUS_1)); break;
-            case ICONST_0       : ipush(appendConstant(CiConstant.INT_0)); break;
-            case ICONST_1       : ipush(appendConstant(CiConstant.INT_1)); break;
-            case ICONST_2       : ipush(appendConstant(CiConstant.INT_2)); break;
-            case ICONST_3       : ipush(appendConstant(CiConstant.INT_3)); break;
-            case ICONST_4       : ipush(appendConstant(CiConstant.INT_4)); break;
-            case ICONST_5       : ipush(appendConstant(CiConstant.INT_5)); break;
-            case LCONST_0       : lpush(appendConstant(CiConstant.LONG_0)); break;
-            case LCONST_1       : lpush(appendConstant(CiConstant.LONG_1)); break;
-            case FCONST_0       : fpush(appendConstant(CiConstant.FLOAT_0)); break;
-            case FCONST_1       : fpush(appendConstant(CiConstant.FLOAT_1)); break;
-            case FCONST_2       : fpush(appendConstant(CiConstant.FLOAT_2)); break;
-            case DCONST_0       : dpush(appendConstant(CiConstant.DOUBLE_0)); break;
-            case DCONST_1       : dpush(appendConstant(CiConstant.DOUBLE_1)); break;
-            case BIPUSH         : ipush(appendConstant(CiConstant.forInt(s.readByte()))); break;
-            case SIPUSH         : ipush(appendConstant(CiConstant.forInt(s.readShort()))); break;
+            case ACONST_NULL    : frameState.apush(appendConstant(CiConstant.NULL_OBJECT)); break;
+            case ICONST_M1      : frameState.ipush(appendConstant(CiConstant.INT_MINUS_1)); break;
+            case ICONST_0       : frameState.ipush(appendConstant(CiConstant.INT_0)); break;
+            case ICONST_1       : frameState.ipush(appendConstant(CiConstant.INT_1)); break;
+            case ICONST_2       : frameState.ipush(appendConstant(CiConstant.INT_2)); break;
+            case ICONST_3       : frameState.ipush(appendConstant(CiConstant.INT_3)); break;
+            case ICONST_4       : frameState.ipush(appendConstant(CiConstant.INT_4)); break;
+            case ICONST_5       : frameState.ipush(appendConstant(CiConstant.INT_5)); break;
+            case LCONST_0       : frameState.lpush(appendConstant(CiConstant.LONG_0)); break;
+            case LCONST_1       : frameState.lpush(appendConstant(CiConstant.LONG_1)); break;
+            case FCONST_0       : frameState.fpush(appendConstant(CiConstant.FLOAT_0)); break;
+            case FCONST_1       : frameState.fpush(appendConstant(CiConstant.FLOAT_1)); break;
+            case FCONST_2       : frameState.fpush(appendConstant(CiConstant.FLOAT_2)); break;
+            case DCONST_0       : frameState.dpush(appendConstant(CiConstant.DOUBLE_0)); break;
+            case DCONST_1       : frameState.dpush(appendConstant(CiConstant.DOUBLE_1)); break;
+            case BIPUSH         : frameState.ipush(appendConstant(CiConstant.forInt(s.readByte()))); break;
+            case SIPUSH         : frameState.ipush(appendConstant(CiConstant.forInt(s.readShort()))); break;
             case LDC            : // fall through
             case LDC_W          : // fall through
             case LDC2_W         : genLoadConstant(s.readCPI()); break;
@@ -1546,18 +1474,18 @@
             case IF_ICMPGE      : genIfSame(CiKind.Int, Condition.GE); break;
             case IF_ICMPGT      : genIfSame(CiKind.Int, Condition.GT); break;
             case IF_ICMPLE      : genIfSame(CiKind.Int, Condition.LE); break;
-            case IF_ACMPEQ      : genIfSame(peekKind(), Condition.EQ); break;
-            case IF_ACMPNE      : genIfSame(peekKind(), Condition.NE); break;
+            case IF_ACMPEQ      : genIfSame(frameState.peekKind(), Condition.EQ); break;
+            case IF_ACMPNE      : genIfSame(frameState.peekKind(), Condition.NE); break;
             case GOTO           : genGoto(s.currentBCI(), s.readBranchDest()); break;
             case JSR            : genJsr(s.readBranchDest()); break;
             case RET            : genRet(s.readLocalIndex()); break;
             case TABLESWITCH    : genTableswitch(); break;
             case LOOKUPSWITCH   : genLookupswitch(); break;
-            case IRETURN        : genReturn(ipop()); break;
-            case LRETURN        : genReturn(lpop()); break;
-            case FRETURN        : genReturn(fpop()); break;
-            case DRETURN        : genReturn(dpop()); break;
-            case ARETURN        : genReturn(apop()); break;
+            case IRETURN        : genReturn(frameState.ipop()); break;
+            case LRETURN        : genReturn(frameState.lpop()); break;
+            case FRETURN        : genReturn(frameState.fpop()); break;
+            case DRETURN        : genReturn(frameState.dpop()); break;
+            case ARETURN        : genReturn(frameState.apop()); break;
             case RETURN         : genReturn(null  ); break;
             case GETSTATIC      : cpi = s.readCPI(); genGetStatic(cpi, constantPool().lookupField(cpi, opcode)); break;
             case PUTSTATIC      : cpi = s.readCPI(); genPutStatic(cpi, constantPool().lookupField(cpi, opcode)); break;
@@ -1574,8 +1502,8 @@
             case ATHROW         : genThrow(s.currentBCI()); break;
             case CHECKCAST      : genCheckCast(); break;
             case INSTANCEOF     : genInstanceOf(); break;
-            case MONITORENTER   : genMonitorEnter(apop(), s.currentBCI()); break;
-            case MONITOREXIT    : genMonitorExit(apop(), s.currentBCI()); break;
+            case MONITORENTER   : genMonitorEnter(frameState.apop(), s.currentBCI()); break;
+            case MONITOREXIT    : genMonitorExit(frameState.apop(), s.currentBCI()); break;
             case MULTIANEWARRAY : genNewMultiArray(s.readCPI()); break;
             case IFNULL         : genIfNull(Condition.EQ); break;
             case IFNONNULL      : genIfNull(Condition.NE); break;
@@ -1608,7 +1536,7 @@
 
     private void genArrayLength() {
         FrameState stateBefore = frameState.create(bci());
-        ipush(append(new ArrayLength(apop(), stateBefore, graph)));
+        frameState.ipush(append(new ArrayLength(frameState.apop(), stateBefore, graph)));
     }
 
     void killMemoryMap() {