changeset 4364:f33f866a12e5

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 24 Jan 2012 20:32:32 +0100
parents 7462c3600c3a (current diff) e3374bccaa5f (diff)
children b2ba03fc66a2
files graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/GraphTest.java
diffstat 6 files changed, 66 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/util/LIRVerifier.java	Tue Jan 24 20:32:23 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/util/LIRVerifier.java	Tue Jan 24 20:32:32 2012 +0100
@@ -147,7 +147,9 @@
     private CiValue use(CiValue value, OperandMode mode, EnumSet<OperandFlag> flags) {
         allowed(curInstruction, value, mode, flags);
 
-        if (beforeRegisterAllocation && isVariable(value)) {
+        if (isVariable(value)) {
+            assert beforeRegisterAllocation;
+
             int variableIdx = asVariable(value).index;
             if (!curVariablesLive.get(variableIdx)) {
                 TTY.println("block %s  instruction %s", curBlock, curInstruction);
@@ -159,9 +161,13 @@
                 throw Util.shouldNotReachHere();
             }
 
-        } else if (beforeRegisterAllocation && isAllocatableRegister(value)) {
+        } else if (isAllocatableRegister(value)) {
             int regNum = asRegister(value).number;
-            if (curRegistersLive[regNum] != value) {
+            if (mode == OperandMode.Alive) {
+                curRegistersDefined.set(regNum);
+            }
+
+            if (beforeRegisterAllocation && curRegistersLive[regNum] != value) {
                 TTY.println("block %s  instruction %s", curBlock, curInstruction);
                 TTY.println("live registers: %s", Arrays.toString(curRegistersLive));
                 TTY.println("ERROR: Use of fixed register %s that is not defined in this block", value);
@@ -174,7 +180,9 @@
     private CiValue def(CiValue value, OperandMode mode, EnumSet<OperandFlag> flags) {
         allowed(curInstruction, value, mode, flags);
 
-        if (beforeRegisterAllocation && isVariable(value)) {
+        if (isVariable(value)) {
+            assert beforeRegisterAllocation;
+
             int variableIdx = asVariable(value).index;
             if (variableDefinitions[variableIdx] != null) {
                 TTY.println("block %s  instruction %s", curBlock, curInstruction);
@@ -190,7 +198,7 @@
                 curVariablesLive.set(variableIdx);
             }
 
-        } else if (beforeRegisterAllocation && isAllocatableRegister(value)) {
+        } else if (isAllocatableRegister(value)) {
             int regNum = asRegister(value).number;
             if (curRegistersDefined.get(regNum)) {
                 TTY.println("block %s  instruction %s", curBlock, curInstruction);
--- a/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderConfiguration.java	Tue Jan 24 20:32:23 2012 +0100
+++ b/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderConfiguration.java	Tue Jan 24 20:32:32 2012 +0100
@@ -26,13 +26,18 @@
 import com.oracle.max.graal.compiler.phases.*;
 
 public class GraphBuilderConfiguration {
+
+    public static enum ResolvePolicy {
+        Default, EagerForSnippets, Eager,
+    }
+
     private final boolean useBranchPrediction;
-    private final boolean eagerResolving;
+    private final ResolvePolicy resolving;
     private final PhasePlan plan;
 
-    public GraphBuilderConfiguration(boolean useBranchPrediction, boolean eagerResolving, PhasePlan plan) {
+    public GraphBuilderConfiguration(boolean useBranchPrediction, ResolvePolicy resolving, PhasePlan plan) {
         this.useBranchPrediction = useBranchPrediction;
-        this.eagerResolving = eagerResolving;
+        this.resolving = resolving;
         this.plan = plan;
     }
 
@@ -40,8 +45,12 @@
         return useBranchPrediction;
     }
 
+    public boolean eagerResolvingForSnippets() {
+        return (resolving == ResolvePolicy.EagerForSnippets || resolving == ResolvePolicy.Eager);
+    }
+
     public boolean eagerResolving() {
-        return eagerResolving;
+        return (resolving == ResolvePolicy.Eager);
     }
 
     public PhasePlan plan() {
@@ -53,14 +62,14 @@
     }
 
     public static GraphBuilderConfiguration getDefault(PhasePlan plan) {
-        return new GraphBuilderConfiguration(GraalOptions.UseBranchPrediction, false, plan);
+        return new GraphBuilderConfiguration(GraalOptions.UseBranchPrediction, ResolvePolicy.Default, plan);
     }
 
-    public static GraphBuilderConfiguration getDeoptFreeDefault() {
-        return getDeoptFreeDefault(null);
+    public static GraphBuilderConfiguration getSnippetDefault() {
+        return getSnippetDefault(null);
     }
 
-    public static GraphBuilderConfiguration getDeoptFreeDefault(PhasePlan plan) {
-        return new GraphBuilderConfiguration(false, true, plan);
+    public static GraphBuilderConfiguration getSnippetDefault(PhasePlan plan) {
+        return new GraphBuilderConfiguration(false, ResolvePolicy.EagerForSnippets, plan);
     }
 }
--- a/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java	Tue Jan 24 20:32:23 2012 +0100
+++ b/graal/com.oracle.max.graal.java/src/com/oracle/max/graal/java/GraphBuilderPhase.java	Tue Jan 24 20:32:32 2012 +0100
@@ -30,7 +30,7 @@
 
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
-import com.oracle.max.cri.ri.RiType.*;
+import com.oracle.max.cri.ri.RiType.Representation;
 import com.oracle.max.criutils.*;
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.phases.*;
@@ -38,11 +38,12 @@
 import com.oracle.max.graal.compiler.util.*;
 import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
-import com.oracle.max.graal.java.BlockMap.*;
+import com.oracle.max.graal.java.BlockMap.Block;
+import com.oracle.max.graal.java.BlockMap.DeoptBlock;
+import com.oracle.max.graal.java.BlockMap.ExceptionBlock;
 import com.oracle.max.graal.nodes.*;
 import com.oracle.max.graal.nodes.DeoptimizeNode.DeoptAction;
 import com.oracle.max.graal.nodes.PhiNode.PhiType;
-import com.oracle.max.graal.java.BlockMap.Block;
 import com.oracle.max.graal.nodes.calc.*;
 import com.oracle.max.graal.nodes.extended.*;
 import com.oracle.max.graal.nodes.java.*;
@@ -380,8 +381,8 @@
         return p;
     }
 
-    private void genLoadConstant(int cpi) {
-        Object con = constantPool.lookupConstant(cpi);
+    private void genLoadConstant(int cpi, int opcode) {
+        Object con = lookupConstant(cpi, opcode);
 
         if (con instanceof RiType) {
             // this is a load of class constant which might be unresolved
@@ -649,23 +650,30 @@
     }
 
     private RiType lookupType(int cpi, int bytecode) {
-        eagerResolving(cpi, bytecode);
+        eagerResolvingForSnippets(cpi, bytecode);
         RiType result = constantPool.lookupType(cpi, bytecode);
-        assert !config.eagerResolving() || result instanceof RiResolvedType;
+        assert !config.eagerResolvingForSnippets() || result instanceof RiResolvedType;
         return result;
     }
 
     private RiMethod lookupMethod(int cpi, int opcode) {
-        eagerResolving(cpi, opcode);
+        eagerResolvingForSnippets(cpi, opcode);
         RiMethod result = constantPool.lookupMethod(cpi, opcode);
-        assert !config.eagerResolving() || ((result instanceof RiResolvedMethod) && ((RiResolvedMethod) result).holder().isInitialized());
+        assert !config.eagerResolvingForSnippets() || ((result instanceof RiResolvedMethod) && ((RiResolvedMethod) result).holder().isInitialized());
         return result;
     }
 
     private RiField lookupField(int cpi, int opcode) {
-        eagerResolving(cpi, opcode);
+        eagerResolvingForSnippets(cpi, opcode);
         RiField result = constantPool.lookupField(cpi, opcode);
-        assert !config.eagerResolving() || (result instanceof RiResolvedField && ((RiResolvedField) result).holder().isInitialized());
+        assert !config.eagerResolvingForSnippets() || (result instanceof RiResolvedField && ((RiResolvedField) result).holder().isInitialized());
+        return result;
+    }
+
+    private Object lookupConstant(int cpi, int opcode) {
+        eagerResolving(cpi, opcode);
+        Object result = constantPool.lookupConstant(cpi);
+        assert !config.eagerResolving() || !(result instanceof RiType) || (result instanceof RiResolvedType);
         return result;
     }
 
@@ -675,6 +683,12 @@
         }
     }
 
+    private void eagerResolvingForSnippets(int cpi, int bytecode) {
+        if (config.eagerResolvingForSnippets()) {
+            constantPool.loadReferencedType(cpi, bytecode);
+        }
+    }
+
     private void genCheckCast() {
         int cpi = stream().readCPI();
         RiType type = lookupType(cpi, CHECKCAST);
@@ -1383,6 +1397,9 @@
             assert frameState.stackSize() == 1 : frameState;
 
             RiType catchType = block.handler.catchType();
+            if (config.eagerResolving()) {
+                catchType = lookupType(block.handler.catchTypeCPI(), INSTANCEOF);
+            }
             ConstantNode typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, catchType, (catchType instanceof RiResolvedType) && ((RiResolvedType) catchType).isInitialized());
             if (typeInstruction != null) {
                 Block nextBlock = block.successors.size() == 1 ? unwindBlock(block.deoptBci) : block.successors.get(1);
@@ -1480,7 +1497,7 @@
             case SIPUSH         : frameState.ipush(appendConstant(CiConstant.forInt(stream.readShort()))); break;
             case LDC            : // fall through
             case LDC_W          : // fall through
-            case LDC2_W         : genLoadConstant(stream.readCPI()); break;
+            case LDC2_W         : genLoadConstant(stream.readCPI(), opcode); break;
             case ILOAD          : loadLocal(stream.readLocalIndex(), CiKind.Int); break;
             case LLOAD          : loadLocal(stream.readLocalIndex(), CiKind.Long); break;
             case FLOAD          : loadLocal(stream.readLocalIndex(), CiKind.Float); break;
--- a/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java	Tue Jan 24 20:32:23 2012 +0100
+++ b/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java	Tue Jan 24 20:32:32 2012 +0100
@@ -88,7 +88,7 @@
 
     private static StructuredGraph buildSnippetGraph(RiResolvedMethod snippetRiMethod, GraalRuntime runtime, CiTarget target, BoxingMethodPool pool, PhasePlan plan) {
 
-        GraphBuilderConfiguration config = GraphBuilderConfiguration.getDeoptFreeDefault();
+        GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault();
         GraphBuilderPhase graphBuilder = new GraphBuilderPhase(runtime, config);
         StructuredGraph graph = new StructuredGraph(snippetRiMethod);
         graphBuilder.apply(graph);
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/GraphTest.java	Tue Jan 24 20:32:23 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/GraphTest.java	Tue Jan 24 20:32:32 2012 +0100
@@ -92,13 +92,13 @@
     protected StructuredGraph parse(Method m) {
         RiResolvedMethod riMethod = runtime.getRiMethod(m);
         StructuredGraph graph = new StructuredGraph(riMethod);
-        new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDeoptFreeDefault()).apply(graph);
+        new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getSnippetDefault()).apply(graph);
         return graph;
     }
 
     protected PhasePlan getDefaultPhasePlan() {
         PhasePlan plan = new PhasePlan();
-        plan.addPhase(PhasePosition.AFTER_PARSING, new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDeoptFreeDefault()));
+        plan.addPhase(PhasePosition.AFTER_PARSING, new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getSnippetDefault()));
         return plan;
     }
 }
--- a/src/share/vm/graal/graalCompilerToVM.cpp	Tue Jan 24 20:32:23 2012 +0100
+++ b/src/share/vm/graal/graalCompilerToVM.cpp	Tue Jan 24 20:32:32 2012 +0100
@@ -506,7 +506,9 @@
   
   constantPoolOop cp = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type)))->constants();
   int byteCode = (op & 0xFF);
-  if (byteCode != Bytecodes::_checkcast && byteCode != Bytecodes::_instanceof && byteCode != Bytecodes::_new && byteCode != Bytecodes::_anewarray && byteCode != Bytecodes::_multianewarray) {
+  if (byteCode != Bytecodes::_checkcast && byteCode != Bytecodes::_instanceof && byteCode != Bytecodes::_new && byteCode != Bytecodes::_anewarray
+      && byteCode != Bytecodes::_multianewarray && byteCode != Bytecodes::_ldc && byteCode != Bytecodes::_ldc_w && byteCode != Bytecodes::_ldc2_w)
+  {
     index = cp->remap_instruction_operand_from_cache(GraalCompiler::to_cp_index_u2(index));
   }
   constantTag tag = cp->tag_at(index);