diff graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2673:98447ab8bd83

Create less nodes in case of Deopt
author Gilles Duboscq <gilles.duboscq@oracle.com>
date Fri, 13 May 2011 11:19:25 +0200
parents d8601d421b96
children 6ab73784566a
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java	Thu May 12 17:57:58 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java	Fri May 13 11:19:25 2011 +0200
@@ -540,8 +540,14 @@
         RiType type = constantPool().lookupType(cpi, CHECKCAST);
         boolean isInitialized = type.isResolved();
         Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi, frameState.create(bci()));
-        CheckCast c = new CheckCast(type, typeInstruction, frameState.apop(), graph);
-        frameState.apush(append(c));
+        Instruction result;
+        Value object = frameState.apop();
+        if (typeInstruction != null) {
+            result = new CheckCast(type, typeInstruction, object, graph);
+        } else {
+            result = Constant.forObject(null, graph);
+        }
+        frameState.apush(append(result));
     }
 
     private void genInstanceOf() {
@@ -550,8 +556,14 @@
         boolean isInitialized = type.isResolved();
         //System.out.println("instanceof : type.isResolved() = " + type.isResolved() + "; type.isInitialized() = " + type.isInitialized());
         Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi, frameState.create(bci()));
-        InstanceOf i = new InstanceOf(type, typeInstruction, frameState.apop(), graph);
-        frameState.ipush(append(i));
+        Instruction result;
+        Value object = frameState.apop();
+        if (typeInstruction != null) {
+            result = new InstanceOf(type, typeInstruction, object, graph);
+        } else {
+            result = Constant.forInt(0, graph);
+        }
+        frameState.ipush(append(result));
     }
 
     void genNewInstance(int cpi) {
@@ -605,9 +617,8 @@
         if (!field.isResolved()) {
             stateBefore = frameState.create(bci());
         }
-        LoadField load = new LoadField(frameState.apop(), field, graph);
+        LoadField load = new LoadField(frameState.apop(), field, stateBefore, graph);
         appendOptimizedLoadField(field.kind(), load);
-        load.setStateBefore(stateBefore);
     }
 
     private void genPutField(int cpi, RiField field) {
@@ -634,9 +645,11 @@
             frameState.push(constantValue.kind.stackKind(), appendConstant(constantValue));
         } else {
             Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi, stateBefore);
-            LoadField load = new LoadField(container, field, graph);
+            if (container == null) {
+                container = Constant.forObject(null, graph);
+            }
+            LoadField load = new LoadField(container, field, stateBefore, graph);
             appendOptimizedLoadField(field.kind(), load);
-            load.setStateBefore(stateBefore);
         }
     }
 
@@ -645,22 +658,22 @@
         FrameState stateBefore = frameState.create(bci());
         Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, field.isResolved(), cpi, stateBefore);
         Value value = frameState.pop(field.kind().stackKind());
-        StoreField store = new StoreField(container, field, value, graph);
-        appendOptimizedStoreField(store);
-        if (!field.isResolved()) {
-            store.setStateBefore(stateBefore);
+        if (container != null) {
+            StoreField store = new StoreField(container, field, value, graph);
+            appendOptimizedStoreField(store);
+            if (!field.isResolved()) {
+                store.setStateBefore(stateBefore);
+            }
         }
     }
 
     private Value genTypeOrDeopt(RiType.Representation representation, RiType holder, boolean initialized, int cpi, FrameState stateBefore) {
-        Value holderInstr;
         if (initialized) {
-            holderInstr = appendConstant(holder.getEncoding(representation));
+            return appendConstant(holder.getEncoding(representation));
         } else {
             append(new Deoptimize(graph, stateBefore));
-            holderInstr = append(Constant.forObject(null, graph));
+            return null;
         }
-        return holderInstr;
     }
 
     private void appendOptimizedStoreField(StoreField store) {