changeset 3144:1d907446ac7f

removed reference to GraalCompilation from CompilerGraph (i.e. make it more lightweight)
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Mon, 04 Jul 2011 12:03:31 +0200
parents 4b63eb1197ca
children dcf2b46665a0
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/CompilerGraph.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ArrayLength.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Invoke.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LoadField.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/RegisterFinalizer.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DeadCodeEliminationPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DuplicationPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodResolvedImpl.java graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodUnresolved.java graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java
diffstat 13 files changed, 66 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java	Mon Jul 04 12:03:31 2011 +0200
@@ -52,10 +52,9 @@
     public final RiMethod method;
     public final RiRegisterConfig registerConfig;
     public final CiStatistics stats;
-    public final CiAssumptions assumptions = new CiAssumptions();
     public final FrameState placeholderState;
 
-    public CompilerGraph graph = new CompilerGraph(this);
+    public final CompilerGraph graph;
 
     private boolean hasExceptionHandlers;
     private final GraalCompilation parent;
@@ -92,6 +91,7 @@
         this.compiler = compiler;
         this.target = compiler.target;
         this.runtime = compiler.runtime;
+        this.graph = new CompilerGraph(runtime);
         this.method = method;
         this.stats = stats == null ? new CiStatistics() : stats;
         this.registerConfig = method == null ? compiler.globalStubRegisterConfig : runtime.getRegisterConfig(method);
@@ -139,16 +139,6 @@
     }
 
     /**
-     * Records an assumption that the specified type has no finalizable subclasses.
-     *
-     * @param receiverType the type that is assumed to have no finalizable subclasses
-     * @return {@code true} if the assumption was recorded and can be assumed; {@code false} otherwise
-     */
-    public boolean recordNoFinalizableSubclassAssumption(RiType receiverType) {
-        return false;
-    }
-
-    /**
      * Converts this compilation to a string.
      *
      * @return a string representation of this compilation
@@ -285,8 +275,8 @@
             lirAssembler.emitTraps();
 
             CiTargetMethod targetMethod = assembler().finishTargetMethod(method, runtime, lirAssembler.registerRestoreEpilogueOffset, false);
-            if (assumptions.count() > 0) {
-                targetMethod.setAssumptions(assumptions);
+            if (graph.assumptions().count() > 0) {
+                targetMethod.setAssumptions(graph.assumptions());
             }
 
             if (compiler.isObserved()) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Mon Jul 04 12:03:31 2011 +0200
@@ -580,11 +580,7 @@
     }
 
     protected FrameState stateBeforeInvokeWithArguments(Invoke invoke) {
-        Value[] args = new Value[invoke.argumentCount()];
-        for (int i = 0; i < invoke.argumentCount(); i++) {
-            args[i] = invoke.argument(i);
-        }
-        return invoke.stateAfter().duplicateModified(getBeforeInvokeBci(invoke), invoke.stateAfter().rethrowException(), invoke.kind, args);
+        return invoke.stateAfter().duplicateModified(getBeforeInvokeBci(invoke), invoke.stateAfter().rethrowException(), invoke.kind, invoke.arguments().toArray(new Value[0]));
     }
 
     private int getBeforeInvokeBci(Invoke invoke) {
@@ -1676,10 +1672,9 @@
 
     List<CiValue> visitInvokeArguments(CiCallingConvention cc, Invoke x, List<CiValue> pointerSlots) {
         // for each argument, load it into the correct location
-        List<CiValue> argList = new ArrayList<CiValue>(x.argumentCount());
+        List<CiValue> argList = new ArrayList<CiValue>();
         int j = 0;
-        for (int i = 0; i < x.argumentCount(); i++) {
-            Value arg = x.argument(i);
+        for (Value arg : x.arguments()) {
             if (arg != null) {
                 CiValue operand = cc.locations[j++];
                 if (operand.isRegister()) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/CompilerGraph.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/CompilerGraph.java	Mon Jul 04 12:03:31 2011 +0200
@@ -22,21 +22,22 @@
  */
 package com.oracle.max.graal.compiler.graph;
 
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.ir.*;
 import com.oracle.max.graal.graph.*;
+import com.sun.cri.ci.*;
 import com.sun.cri.ri.*;
 
 
 public class CompilerGraph extends Graph {
 
+    private RiRuntime runtime;
     private Return returnSingleton;
     private Unwind unwindSingleton;
-    private GraalCompilation compilation;
+    private CiAssumptions assumptions = new CiAssumptions();
 
 
-    public CompilerGraph(GraalCompilation compilation) {
-        this.compilation = compilation;
+    public CompilerGraph(RiRuntime runtime) {
+        this.runtime = runtime;
     }
 
     public void setReturn(Return returnNode) {
@@ -58,10 +59,10 @@
     }
 
     public RiRuntime runtime() {
-        return compilation.runtime;
+        return runtime;
     }
 
-    public GraalCompilation getCompilation() {
-        return compilation;
+    public CiAssumptions assumptions() {
+        return assumptions;
     }
 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ArrayLength.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ArrayLength.java	Mon Jul 04 12:03:31 2011 +0200
@@ -128,7 +128,7 @@
             if (constantValue != null && constantValue.isNonNull()) {
                 Graph graph = node.graph();
                 if (graph instanceof CompilerGraph) {
-                    RiRuntime runtime = ((CompilerGraph) graph).getCompilation().runtime;
+                    RiRuntime runtime = ((CompilerGraph) graph).runtime();
                     return Constant.forInt(runtime.getArrayLength(constantValue), graph);
                 }
             }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Invoke.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Invoke.java	Mon Jul 04 12:03:31 2011 +0200
@@ -51,21 +51,24 @@
         return super.successorCount() + SUCCESSOR_COUNT;
     }
 
-    /**
-     * The list of instructions that produce input for this instruction.
-     */
-    public Value argument(int index) {
-        assert index >= 0 && index < argumentCount;
-        return (Value) inputs().get(super.inputCount() + index);
-    }
+    public List<Value> arguments() {
+        return new AbstractList<Value>() {
+            @Override
+            public int size() {
+                return argumentCount;
+            }
 
-    public Value setArgument(int index, Value n) {
-        assert index >= 0 && index < argumentCount;
-        return (Value) inputs().set(super.inputCount() + index, n);
-    }
+            @Override
+            public Value get(int index) {
+                return (Value) inputs().get(Invoke.super.inputCount() + index);
+            }
 
-    public int argumentCount() {
-        return argumentCount;
+            @Override
+            public Value set(int index, Value node) {
+                return (Value) inputs().set(Invoke.super.inputCount() + index, node);
+            }
+        };
+
     }
 
     /**
@@ -103,7 +106,7 @@
 
         this.argumentCount = args.length;
         for (int i = 0; i < args.length; i++) {
-            setArgument(i, args[i]);
+            arguments().set(i, args[i]);
         }
     }
 
@@ -135,7 +138,7 @@
      */
     public Value receiver() {
         assert !isStatic();
-        return argument(0);
+        return arguments().get(0);
     }
 
     /**
@@ -179,7 +182,7 @@
             if (i > argStart) {
                 out.print(", ");
             }
-            out.print(argument(i));
+            out.print(arguments().get(i));
         }
         out.print(CiUtil.format(") [method: %H.%n(%p):%r]", target, false));
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LoadField.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LoadField.java	Mon Jul 04 12:03:31 2011 +0200
@@ -23,7 +23,6 @@
 package com.oracle.max.graal.compiler.ir;
 
 import com.oracle.max.graal.compiler.debug.*;
-import com.oracle.max.graal.compiler.graph.*;
 import com.oracle.max.graal.compiler.phases.CanonicalizerPhase.CanonicalizerOp;
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.compiler.phases.LoweringPhase.LoweringOp;
@@ -130,13 +129,9 @@
             LoadField loadField = (LoadField) node;
             Graph graph = node.graph();
             CiConstant constant = null;
-            if (graph instanceof CompilerGraph) {
-                RiMethod method = ((CompilerGraph) graph).getCompilation().method;
-                if (loadField.isStatic() && !method.isClassInitializer()) {
+            if (loadField.isStatic()) {
                     constant = loadField.field().constantValue(null);
-                }
-            }
-            if (!loadField.isStatic()) {
+            } else {
                 Value object = loadField.object();
                 if (object.isConstant()) {
                     constant = loadField.field().constantValue(object.asConstant());
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/RegisterFinalizer.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/RegisterFinalizer.java	Mon Jul 04 12:03:31 2011 +0200
@@ -93,7 +93,6 @@
                 exactType = declaredType.exactType();
             }
 
-            GraalCompilation compilation = ((CompilerGraph) node.graph()).getCompilation();
             boolean needsCheck = true;
             if (exactType != null) {
                 // we have an exact type
@@ -101,7 +100,7 @@
             } else {
                 // if either the declared type of receiver or the holder can be assumed to have no finalizers
                 if (declaredType != null && !declaredType.hasFinalizableSubclass()) {
-                    if (compilation.recordNoFinalizableSubclassAssumption(declaredType)) {
+                    if (((CompilerGraph) node.graph()).assumptions().recordNoFinalizableSubclassAssumption(declaredType)) {
                         needsCheck = false;
                     }
                 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DeadCodeEliminationPhase.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DeadCodeEliminationPhase.java	Mon Jul 04 12:03:31 2011 +0200
@@ -147,17 +147,6 @@
         }
         for (Node node : graph.getNodes()) {
             if (!flood.isMarked(node)) {
-                if (node.predecessors().size() > 0) {
-                    for (Node pred : node.predecessors()) {
-                        TTY.println("!PRED! " + pred + " (" + flood.isMarked(pred) + ")");
-                        for (int i=0; i<pred.successors().size(); i++) {
-                            TTY.println("pred=>succ: " + pred.successors().get(i));
-                        }
-                        for (int i=0; i<pred.usages().size(); i++) {
-                            TTY.println("pred=>usage: " + pred.usages().get(i));
-                        }
-                    }
-                }
                 node.delete();
             }
         }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DuplicationPhase.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DuplicationPhase.java	Mon Jul 04 12:03:31 2011 +0200
@@ -24,7 +24,6 @@
 
 import java.util.*;
 
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.graph.*;
 import com.oracle.max.graal.graph.*;
 
@@ -36,13 +35,8 @@
     @Override
     protected void run(Graph graph) {
 
-        GraalCompilation compilation = null;
-        if (graph instanceof CompilerGraph) {
-            compilation = ((CompilerGraph) graph).getCompilation();
-        }
-
         // Create duplicate graph.
-        CompilerGraph duplicate = new CompilerGraph(compilation);
+        CompilerGraph duplicate = new CompilerGraph(((CompilerGraph) graph).runtime());
         Map<Node, Node> replacements = new HashMap<Node, Node>();
         replacements.put(graph.start(), duplicate.start());
         duplicate.addDuplicate(graph.getNodes(), replacements);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Mon Jul 04 12:03:31 2011 +0200
@@ -54,11 +54,11 @@
     }
 
     private Queue<Invoke> newInvokes = new ArrayDeque<Invoke>();
-    private Graph graph;
+    private CompilerGraph graph;
 
     @Override
     protected void run(Graph graph) {
-        this.graph = graph;
+        this.graph = (CompilerGraph) graph;
 
         float ratio = GraalOptions.MaximumInlineRatio;
         inliningSize = compilation.method.codeSize();
@@ -121,7 +121,7 @@
         if (!checkInvokeConditions(invoke)) {
             return null;
         }
-        if (invoke.target.hasIntrinsicGraph() && GraalOptions.Intrinsify) {
+        if (GraalOptions.Intrinsify && compilation.runtime.intrinsicGraph(invoke.target, invoke.arguments()) != null) {
             // Always intrinsify.
             return invoke.target;
         }
@@ -159,7 +159,7 @@
                     String concreteName = CiUtil.format("%H.%n(%p):%r", concrete, false);
                     TTY.println("recording concrete method assumption: %s -> %s", targetName, concreteName);
                 }
-                compilation.assumptions.recordConcreteMethod(invoke.target, concrete);
+                graph.assumptions().recordConcreteMethod(invoke.target, concrete);
                 return concrete;
             }
             return null;
@@ -330,16 +330,16 @@
         int slot = withReceiver ? 1 : 0;
         int param = withReceiver ? 1 : 0;
         for (int i = 0; i < argumentCount; i++) {
-            parameters[param++] = invoke.argument(slot);
+            parameters[param++] = invoke.arguments().get(slot);
             slot += method.signature().argumentKindAt(i).sizeInSlots();
         }
         if (withReceiver) {
-            parameters[0] = invoke.argument(0);
+            parameters[0] = invoke.arguments().get(0);
         }
 
         CompilerGraph graph = null;
         if (GraalOptions.Intrinsify) {
-            graph = (CompilerGraph) method.intrinsicGraph(parameters);
+            graph = (CompilerGraph) compilation.runtime.intrinsicGraph(method, invoke.arguments());
         }
         if (graph != null) {
             TTY.println("Using intrinsic graph");
--- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodResolvedImpl.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodResolvedImpl.java	Mon Jul 04 12:03:31 2011 +0200
@@ -223,14 +223,4 @@
             }
         }
     }
-
-    @Override
-    public Graph intrinsicGraph(Node[] parameters) {
-        return null;
-    }
-
-    @Override
-    public boolean hasIntrinsicGraph() {
-        return false;
-    }
 }
--- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodUnresolved.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodUnresolved.java	Mon Jul 04 12:03:31 2011 +0200
@@ -177,14 +177,4 @@
     public int branchProbability(int bci) {
         return -1;
     }
-
-    @Override
-    public Graph intrinsicGraph(Node[] parameters) {
-        return null;
-    }
-
-    @Override
-    public boolean hasIntrinsicGraph() {
-        return false;
-    }
 }
--- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java	Sat Jul 02 02:46:04 2011 +0200
+++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java	Mon Jul 04 12:03:31 2011 +0200
@@ -26,6 +26,7 @@
 import java.lang.reflect.*;
 import java.util.*;
 
+import com.oracle.max.graal.compiler.graph.*;
 import com.oracle.max.graal.compiler.ir.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.runtime.nodes.*;
@@ -46,6 +47,7 @@
     final HotSpotRegisterConfig regConfig;
     final HotSpotRegisterConfig globalStubRegConfig;
     private final Compiler compiler;
+    private IdentityHashMap<RiMethod, CompilerGraph> intrinsicGraphs = new IdentityHashMap<RiMethod, CompilerGraph>();
 
 
     public HotSpotRuntime(HotSpotVMConfig config, Compiler compiler) {
@@ -276,4 +278,22 @@
             field.replaceAndDelete(memoryWrite);
         }
     }
+
+    @Override
+    public Graph intrinsicGraph(RiMethod method, List<? extends Node> parameters) {
+        if (!intrinsicGraphs.containsKey(method)) {
+            RiType holder = method.holder();
+            String fullName = method.name() + method.signature().asString();
+            if (holder.name().equals("Ljava/lang/Object;")) {
+                if (fullName.equals("getClass()Ljava/lang/Class;")) {
+
+                }
+            }
+
+            if (!intrinsicGraphs.containsKey(method)) {
+                intrinsicGraphs.put(method, null);
+            }
+        }
+        return intrinsicGraphs.get(method);
+    }
 }