# HG changeset patch # User Lukas Stadler # Date 1364206005 -3600 # Node ID 31b7a648b4b3ed59ec265b86dda22cbeaf35487c # Parent 0f6dd67470d97d2dd5771fa80a0a9f813585c6b7 turn inlining hints into a map diff -r 0f6dd67470d9 -r 31b7a648b4b3 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/BoxingEliminationTest.java --- 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 hints = new ArrayList<>(); + Map hints = new HashMap<>(); for (Invoke invoke : graph.getInvokes()) { - hints.add(invoke); + hints.put(invoke, 1000d); } Assumptions assumptions = new Assumptions(false); diff -r 0f6dd67470d9 -r 31b7a648b4b3 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IfBoxingEliminationTest.java --- 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 hints = new ArrayList<>(); + Map hints = new HashMap<>(); for (Invoke invoke : graph.getInvokes()) { - hints.add(invoke); + hints.put(invoke, 1000d); } Assumptions assumptions = new Assumptions(false); diff -r 0f6dd67470d9 -r 31b7a648b4b3 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InvokeExceptionTest.java --- 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 hints = new ArrayList<>(); + Map 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); diff -r 0f6dd67470d9 -r 31b7a648b4b3 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InvokeHintsTest.java --- 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 hints = new ArrayList<>(); + Map hints = new HashMap<>(); for (Invoke invoke : graph.getInvokes()) { - hints.add(invoke); + hints.put(invoke, 1000d); } Assumptions assumptions = new Assumptions(false); diff -r 0f6dd67470d9 -r 31b7a648b4b3 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MonitorGraphTest.java --- 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 hints = new ArrayList<>(); + Map 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); diff -r 0f6dd67470d9 -r 31b7a648b4b3 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java --- 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 hints, Assumptions assumptions, GraphCache cache, PhasePlan plan, OptimisticOptimizations optimisticOpts) { + public InliningPhase(GraalCodeCacheProvider runtime, Map 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 hints; + private final Map hints; - public GreedySizeBasedInliningDecision(GraalCodeCacheProvider runtime, Collection hints) { + public GreedySizeBasedInliningDecision(GraalCodeCacheProvider runtime, Map 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 hints; private final Assumptions assumptions; private final OptimisticOptimizations optimisticOpts; private final Deque sortedInvokes; private NodeBitMap visitedFixedNodes; private FixedNode invokePredecessor; - public CFInliningPolicy(InliningDecision inliningPolicy, Collection 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 newNodes) { @@ -516,8 +513,8 @@ } } - private static InliningPolicy createInliningPolicy(GraalCodeCacheProvider runtime, Assumptions assumptions, OptimisticOptimizations optimisticOpts, Collection hints) { + private static InliningPolicy createInliningPolicy(GraalCodeCacheProvider runtime, Assumptions assumptions, OptimisticOptimizations optimisticOpts, Map hints) { InliningDecision inliningDecision = new GreedySizeBasedInliningDecision(runtime, hints); - return new CFInliningPolicy(inliningDecision, hints, assumptions, optimisticOpts); + return new CFInliningPolicy(inliningDecision, assumptions, optimisticOpts); } } diff -r 0f6dd67470d9 -r 31b7a648b4b3 graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java --- 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 hints = new ArrayList<>(); + private final Map 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 getHints() { + public Map 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);