changeset 8552:31b7a648b4b3

turn inlining hints into a map
author Lukas Stadler <lukas.stadler@jku.at>
date Mon, 25 Mar 2013 11:06:45 +0100
parents 0f6dd67470d9
children ed38b01ce7bc
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/BoxingEliminationTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IfBoxingEliminationTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InvokeExceptionTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InvokeHintsTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MonitorGraphTest.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java
diffstat 7 files changed, 31 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/BoxingEliminationTest.java	Mon Mar 11 18:41:16 2013 +0100
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/BoxingEliminationTest.java	Mon Mar 25 11:06:45 2013 +0100
@@ -120,9 +120,9 @@
                 PhasePlan phasePlan = getDefaultPhasePlan();
                 phasePlan.addPhase(PhasePosition.AFTER_PARSING, identifyBoxingPhase);
                 identifyBoxingPhase.apply(graph);
-                Collection<Invoke> hints = new ArrayList<>();
+                Map<Invoke, Double> hints = new HashMap<>();
                 for (Invoke invoke : graph.getInvokes()) {
-                    hints.add(invoke);
+                    hints.put(invoke, 1000d);
                 }
 
                 Assumptions assumptions = new Assumptions(false);
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IfBoxingEliminationTest.java	Mon Mar 11 18:41:16 2013 +0100
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IfBoxingEliminationTest.java	Mon Mar 25 11:06:45 2013 +0100
@@ -83,9 +83,9 @@
                 phasePlan.addPhase(PhasePosition.AFTER_PARSING, identifyBoxingPhase);
                 phasePlan.addPhase(PhasePosition.AFTER_PARSING, new PhiStampPhase());
                 identifyBoxingPhase.apply(graph);
-                Collection<Invoke> hints = new ArrayList<>();
+                Map<Invoke, Double> hints = new HashMap<>();
                 for (Invoke invoke : graph.getInvokes()) {
-                    hints.add(invoke);
+                    hints.put(invoke, 1000d);
                 }
 
                 Assumptions assumptions = new Assumptions(false);
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InvokeExceptionTest.java	Mon Mar 11 18:41:16 2013 +0100
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InvokeExceptionTest.java	Mon Mar 25 11:06:45 2013 +0100
@@ -60,9 +60,9 @@
 
     private void test(String snippet) {
         StructuredGraph graph = parseProfiled(snippet);
-        Collection<Invoke> hints = new ArrayList<>();
+        Map<Invoke, Double> hints = new HashMap<>();
         for (Invoke invoke : graph.getInvokes()) {
-            hints.add(invoke);
+            hints.put(invoke, 1000d);
         }
         Assumptions assumptions = new Assumptions(false);
         new InliningPhase(runtime(), hints, assumptions, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(graph);
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InvokeHintsTest.java	Mon Mar 11 18:41:16 2013 +0100
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InvokeHintsTest.java	Mon Mar 25 11:06:45 2013 +0100
@@ -70,9 +70,9 @@
 
     private void test(String snippet) {
         StructuredGraph graph = parse(snippet);
-        Collection<Invoke> hints = new ArrayList<>();
+        Map<Invoke, Double> hints = new HashMap<>();
         for (Invoke invoke : graph.getInvokes()) {
-            hints.add(invoke);
+            hints.put(invoke, 1000d);
         }
 
         Assumptions assumptions = new Assumptions(false);
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MonitorGraphTest.java	Mon Mar 11 18:41:16 2013 +0100
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MonitorGraphTest.java	Mon Mar 25 11:06:45 2013 +0100
@@ -88,9 +88,9 @@
         for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) {
             n.replaceFirstInput(local, constant);
         }
-        Collection<Invoke> hints = new ArrayList<>();
+        Map<Invoke, Double> hints = new HashMap<>();
         for (Invoke invoke : graph.getInvokes()) {
-            hints.add(invoke);
+            hints.put(invoke, 1000d);
         }
         Assumptions assumptions = new Assumptions(false);
         new InliningPhase(runtime(), hints, assumptions, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(graph);
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java	Mon Mar 11 18:41:16 2013 +0100
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java	Mon Mar 25 11:06:45 2013 +0100
@@ -67,7 +67,7 @@
     private static final DebugMetric metricInliningStoppedByMaxDesiredSize = Debug.metric("InliningStoppedByMaxDesiredSize");
     private static final DebugMetric metricInliningRuns = Debug.metric("Runs");
 
-    public InliningPhase(GraalCodeCacheProvider runtime, Collection<Invoke> hints, Assumptions assumptions, GraphCache cache, PhasePlan plan, OptimisticOptimizations optimisticOpts) {
+    public InliningPhase(GraalCodeCacheProvider runtime, Map<Invoke, Double> hints, Assumptions assumptions, GraphCache cache, PhasePlan plan, OptimisticOptimizations optimisticOpts) {
         this(runtime, assumptions, cache, plan, createInliningPolicy(runtime, assumptions, optimisticOpts, hints), optimisticOpts);
     }
 
@@ -178,9 +178,9 @@
     private static class GreedySizeBasedInliningDecision implements InliningDecision {
 
         private final GraalCodeCacheProvider runtime;
-        private final Collection<Invoke> hints;
+        private final Map<Invoke, Double> hints;
 
-        public GreedySizeBasedInliningDecision(GraalCodeCacheProvider runtime, Collection<Invoke> hints) {
+        public GreedySizeBasedInliningDecision(GraalCodeCacheProvider runtime, Map<Invoke, Double> hints) {
             this.runtime = runtime;
             this.hints = hints;
         }
@@ -199,12 +199,14 @@
                 return InliningUtil.logInlinedMethod(info, "intrinsic");
             }
 
-            boolean preferredInvoke = hints != null && hints.contains(info.invoke());
-            int bonus = preferredInvoke ? 2 : 1;
+            double bonus = 1;
+            if (hints != null && hints.containsKey(info.invoke())) {
+                bonus = hints.get(info.invoke());
+            }
 
-            int bytecodeSize = bytecodeCodeSize(info) / bonus;
-            int complexity = compilationComplexity(info) / bonus;
-            int compiledCodeSize = compiledCodeSize(info) / bonus;
+            int bytecodeSize = (int) (bytecodeCodeSize(info) / bonus);
+            int complexity = (int) (compilationComplexity(info) / bonus);
+            int compiledCodeSize = (int) (compiledCodeSize(info) / bonus);
             double relevance = info.invoke().inliningRelevance();
 
             /*
@@ -234,8 +236,8 @@
             // TODO (chaeubl): compute metric that is used to check if this method should be inlined
 
             return InliningUtil.logNotInlinedMethod(info,
-                            "(relevance=%f, bytecodes=%d, complexity=%d, codeSize=%d, probability=%f, transferredValues=%d, invokeUsages=%d, moreSpecificArguments=%d, level=%d, preferred=%b)",
-                            relevance, bytecodeSize, complexity, compiledCodeSize, probability, transferredValues, invokeUsages, moreSpecificArguments, level, preferredInvoke);
+                            "(relevance=%f, bytecodes=%d, complexity=%d, codeSize=%d, probability=%f, transferredValues=%d, invokeUsages=%d, moreSpecificArguments=%d, level=%d, bonus=%f)", relevance,
+                            bytecodeSize, complexity, compiledCodeSize, probability, transferredValues, invokeUsages, moreSpecificArguments, level, bonus);
         }
 
         private static boolean isTrivialInlining(int bytecodeSize, int complexity, int compiledCodeSize) {
@@ -345,16 +347,14 @@
     private static class CFInliningPolicy implements InliningPolicy {
 
         private final InliningDecision inliningDecision;
-        private final Collection<Invoke> hints;
         private final Assumptions assumptions;
         private final OptimisticOptimizations optimisticOpts;
         private final Deque<Invoke> sortedInvokes;
         private NodeBitMap visitedFixedNodes;
         private FixedNode invokePredecessor;
 
-        public CFInliningPolicy(InliningDecision inliningPolicy, Collection<Invoke> hints, Assumptions assumptions, OptimisticOptimizations optimisticOpts) {
+        public CFInliningPolicy(InliningDecision inliningPolicy, Assumptions assumptions, OptimisticOptimizations optimisticOpts) {
             this.inliningDecision = inliningPolicy;
-            this.hints = hints;
             this.assumptions = assumptions;
             this.optimisticOpts = optimisticOpts;
             this.sortedInvokes = new ArrayDeque<>();
@@ -387,9 +387,6 @@
         public void initialize(StructuredGraph graph) {
             visitedFixedNodes = graph.createNodeBitMap(true);
             scanGraphForInvokes(graph.start());
-            if (hints != null) {
-                sortedInvokes.retainAll(hints);
-            }
         }
 
         public void scanInvokes(Iterable<? extends Node> newNodes) {
@@ -516,8 +513,8 @@
         }
     }
 
-    private static InliningPolicy createInliningPolicy(GraalCodeCacheProvider runtime, Assumptions assumptions, OptimisticOptimizations optimisticOpts, Collection<Invoke> hints) {
+    private static InliningPolicy createInliningPolicy(GraalCodeCacheProvider runtime, Assumptions assumptions, OptimisticOptimizations optimisticOpts, Map<Invoke, Double> hints) {
         InliningDecision inliningDecision = new GreedySizeBasedInliningDecision(runtime, hints);
-        return new CFInliningPolicy(inliningDecision, hints, assumptions, optimisticOpts);
+        return new CFInliningPolicy(inliningDecision, assumptions, optimisticOpts);
     }
 }
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java	Mon Mar 11 18:41:16 2013 +0100
+++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java	Mon Mar 25 11:06:45 2013 +0100
@@ -68,7 +68,7 @@
 
     private final VirtualizerToolImpl tool;
 
-    private final List<Invoke> hints = new ArrayList<>();
+    private final Map<Invoke, Double> hints = new IdentityHashMap<>();
 
     public PartialEscapeClosure(NodeBitMap usages, SchedulePhase schedule, MetaAccessProvider metaAccess, Assumptions assumptions) {
         this.usages = usages;
@@ -84,7 +84,7 @@
         return tool.getNewVirtualObjectCount();
     }
 
-    public Collection<Invoke> getHints() {
+    public Map<Invoke, Double> getHints() {
         return hints;
     }
 
@@ -130,7 +130,9 @@
                     } else if (node instanceof MemoryCheckpoint) {
                         METRIC_MEMORYCHECKOINT.increment();
                         MemoryCheckpoint checkpoint = (MemoryCheckpoint) node;
-                        state.killReadCache(checkpoint.getLocationIdentity());
+                        for (Object identity : checkpoint.getLocationIdentities()) {
+                            state.killReadCache(identity);
+                        }
                     }
                 }
             }
@@ -231,7 +233,7 @@
             if (obj != null) {
                 if (obj.isVirtual() && node instanceof MethodCallTargetNode) {
                     Invoke invoke = ((MethodCallTargetNode) node).invoke();
-                    hints.add(invoke);
+                    hints.put(invoke, 5d);
                 }
                 trace("replacing input %s at %s: %s", input, node, obj);
                 replaceWithMaterialized(input, node, insertBefore, state, obj, METRIC_MATERIALIZATIONS_UNHANDLED);