# HG changeset patch # User Christian Haeubl # Date 1368446141 -7200 # Node ID 907f1124b4274f17f867f301cef7a28eec4a5c7c # Parent e538498d6eae725b5101059d4018647ad44503c2 Removed memory leak and bugfixes for the InliningPhase. diff -r e538498d6eae -r 907f1124b427 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 May 13 13:14:17 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java Mon May 13 13:55:41 2013 +0200 @@ -43,8 +43,6 @@ public class InliningPhase extends Phase { - private static final HashMap compiledMethodInfo = new HashMap<>(); - private final PhasePlan plan; private final MetaAccessProvider runtime; private final Assumptions compilationAssumptions; @@ -109,7 +107,16 @@ processNextInvoke(data, graphInfo); } else { data.popGraph(); - tryToInlineCurrentInvocation(data); + MethodInvocation currentInvocation = data.currentInvocation(); + if (currentInvocation != null) { + assert currentInvocation.callee().invoke().asNode().isAlive(); + currentInvocation.incrementProcessedGraphs(); + if (currentInvocation.processedAllGraphs()) { + data.popInvocation(); + MethodInvocation parentInvoke = data.currentInvocation(); + tryToInline(data.currentGraph(), currentInvocation, parentInvoke); + } + } } } } @@ -123,8 +130,8 @@ Assumptions parentAssumptions = callerInvocation == null ? compilationAssumptions : callerInvocation.assumptions(); InlineInfo info = InliningUtil.getInlineInfo(data, invoke, maxMethodPerInlining, replacements, parentAssumptions, optimisticOpts); - double invokeProbability = graphInfo.getInvokeProbability(invoke); - double invokeRelevance = graphInfo.getInvokeRelevance(invoke); + double invokeProbability = graphInfo.invokeProbability(invoke); + double invokeRelevance = graphInfo.invokeRelevance(invoke); if (info != null && inliningPolicy.isWorthInlining(info, invokeProbability, invokeRelevance, false)) { MethodInvocation calleeInvocation = data.pushInvocation(info, parentAssumptions, invokeProbability, invokeRelevance); @@ -135,26 +142,12 @@ data.pushGraph((StructuredGraph) elem, invokeProbability * info.probabilityAt(i), invokeRelevance * info.relevanceAt(i)); } else { assert elem instanceof InlineableMacroNode; - // directly mark one callee as done because we do not have a graph to process - calleeInvocation.incrementProcessedGraphs(); + data.pushDummyGraph(); } } } } - private void tryToInlineCurrentInvocation(InliningData data) { - MethodInvocation currentInvocation = data.currentInvocation(); - if (currentInvocation != null) { - assert currentInvocation.callee().invoke().asNode().isAlive(); - currentInvocation.incrementProcessedGraphs(); - if (currentInvocation.processedAllGraphs()) { - data.popInvocation(); - MethodInvocation parentInvoke = data.currentInvocation(); - tryToInline(data.currentGraph(), currentInvocation, parentInvoke); - } - } - } - private void tryToInline(GraphInfo callerGraphInfo, MethodInvocation calleeInfo, MethodInvocation parentInvocation) { InlineInfo callee = calleeInfo.callee(); Assumptions callerAssumptions = parentInvocation == null ? compilationAssumptions : parentInvocation.assumptions(); @@ -307,10 +300,10 @@ } private static synchronized CompiledMethodInfo compiledMethodInfo(ResolvedJavaMethod m) { - CompiledMethodInfo info = compiledMethodInfo.get(m); + CompiledMethodInfo info = (CompiledMethodInfo) m.getCompilerStorage().get(CompiledMethodInfo.class); if (info == null) { info = new CompiledMethodInfo(); - compiledMethodInfo.put(m, info); + m.getCompilerStorage().put(CompiledMethodInfo.class, info); } return info; } @@ -324,54 +317,6 @@ return summedUpProbabilityOfRemainingInvokes; } - private static class GraphInfo { - - private final StructuredGraph graph; - private final Stack remainingInvokes; - private final double probability; - private final double relevance; - private NodesToDoubles nodeProbabilities; - private NodesToDoubles nodeRelevance; - - public GraphInfo(StructuredGraph graph, Stack invokes, double probability, double relevance) { - this.graph = graph; - this.remainingInvokes = invokes; - this.probability = probability; - this.relevance = relevance; - - computeProbabilities(); - } - - public boolean hasRemainingInvokes() { - return !remainingInvokes.isEmpty(); - } - - public StructuredGraph graph() { - return graph; - } - - public Invoke popInvoke() { - return remainingInvokes.pop(); - } - - public void pushInvoke(Invoke invoke) { - remainingInvokes.push(invoke); - } - - public void computeProbabilities() { - nodeProbabilities = new ComputeProbabilityClosure(graph).apply(); - nodeRelevance = new ComputeInliningRelevanceClosure(graph, nodeProbabilities).apply(); - } - - public double getInvokeProbability(Invoke invoke) { - return probability * nodeProbabilities.get(invoke.asNode()); - } - - public double getInvokeRelevance(Invoke invoke) { - return Math.min(relevance, 1.0) * nodeRelevance.get(invoke.asNode()); - } - } - private abstract static class AbstractInliningPolicy implements InliningPolicy { protected final Replacements replacements; @@ -426,7 +371,7 @@ protected static int previousHIRSize(InlineInfo info) { int size = 0; for (int i = 0; i < info.numberOfMethods(); i++) { - size += compiledMethodInfo(info.methodAt(i)).getHighLevelNodes(); + size += compiledMethodInfo(info.methodAt(i)).highLevelNodes(); } return size; } @@ -617,6 +562,8 @@ */ static class InliningData { + private static final GraphInfo DummyGraphInfo = new GraphInfo(null, new Stack(), 1.0, 1.0); + private final ArrayDeque graphQueue; private final ArrayDeque invocationQueue; @@ -636,6 +583,10 @@ assert graphQueue.size() <= maxGraphs; } + public void pushDummyGraph() { + graphQueue.push(DummyGraphInfo); + } + public boolean hasUnprocessedGraphs() { return !graphQueue.isEmpty(); } @@ -670,7 +621,7 @@ public int countRecursiveInlining(ResolvedJavaMethod method) { int count = 0; for (GraphInfo graphInfo : graphQueue) { - if (method.equals(graphInfo.graph().method())) { + if (method.equals(graphInfo.method())) { count++; } } @@ -739,6 +690,7 @@ public void incrementProcessedGraphs() { processedGraphs++; + assert processedGraphs <= callee.numberOfMethods(); } public boolean processedAllGraphs() { @@ -763,6 +715,61 @@ } } + private static class GraphInfo { + + private final StructuredGraph graph; + private final Stack remainingInvokes; + private final double probability; + private final double relevance; + + private NodesToDoubles nodeProbabilities; + private NodesToDoubles nodeRelevance; + + public GraphInfo(StructuredGraph graph, Stack invokes, double probability, double relevance) { + this.graph = graph; + this.remainingInvokes = invokes; + this.probability = probability; + this.relevance = relevance; + + if (graph != null) { + computeProbabilities(); + } + } + + public ResolvedJavaMethod method() { + return graph.method(); + } + + public boolean hasRemainingInvokes() { + return !remainingInvokes.isEmpty(); + } + + public StructuredGraph graph() { + return graph; + } + + public Invoke popInvoke() { + return remainingInvokes.pop(); + } + + public void pushInvoke(Invoke invoke) { + remainingInvokes.push(invoke); + } + + public void computeProbabilities() { + nodeProbabilities = new ComputeProbabilityClosure(graph).apply(); + nodeRelevance = new ComputeInliningRelevanceClosure(graph, nodeProbabilities).apply(); + } + + public double invokeProbability(Invoke invoke) { + return probability * nodeProbabilities.get(invoke.asNode()); + } + + public double invokeRelevance(Invoke invoke) { + return relevance * nodeRelevance.get(invoke.asNode()); + } + } + private static class CompiledMethodInfo { private int highLevelNodes; @@ -771,7 +778,7 @@ public CompiledMethodInfo() { } - public int getHighLevelNodes() { + public int highLevelNodes() { return highLevelNodes; } @@ -779,7 +786,7 @@ this.highLevelNodes = highLevelNodes; } - public double getSummedUpProbabilityOfRemainingInvokes() { + public double summedUpProbabilityOfRemainingInvokes() { return summedUpProbabilityOfRemainingInvokes; }