# HG changeset patch # User Doug Simon # Date 1372943023 -7200 # Node ID dd5a042811f64613b1c8e6888a540e15b21f809a # Parent a6c0ae38e05e113cfb0fe0cd11b8d874f7fcbb6a enhanced debug context for inlining so that inlining hierarchy is correctly shown in IGV added documentation and toString() implementation for inlining utility classes diff -r a6c0ae38e05e -r dd5a042811f6 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 Thu Jul 04 14:53:28 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java Thu Jul 04 15:03:43 2013 +0200 @@ -33,6 +33,7 @@ import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.java.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; import com.oracle.graal.nodes.util.*; @@ -123,10 +124,10 @@ @Override protected void run(final StructuredGraph graph) { - InliningData data = new InliningData(graph, compilationAssumptions); + final InliningData data = new InliningData(graph, compilationAssumptions); while (data.hasUnprocessedGraphs()) { - MethodInvocation currentInvocation = data.currentInvocation(); + final MethodInvocation currentInvocation = data.currentInvocation(); GraphInfo graphInfo = data.currentGraph(); if (!currentInvocation.isRoot() && !inliningPolicy.isWorthInlining(currentInvocation.callee(), data.inliningDepth(), currentInvocation.probability(), currentInvocation.relevance(), false)) { int remainingGraphs = currentInvocation.totalGraphs() - currentInvocation.processedGraphs(); @@ -142,8 +143,15 @@ currentInvocation.incrementProcessedGraphs(); if (currentInvocation.processedGraphs() == currentInvocation.totalGraphs()) { data.popInvocation(); - MethodInvocation parentInvoke = data.currentInvocation(); - tryToInline(data.currentGraph(), currentInvocation, parentInvoke, data.inliningDepth() + 1); + final MethodInvocation parentInvoke = data.currentInvocation(); + Debug.scope("Inlining", data.inliningContext(), new Runnable() { + + @Override + public void run() { + tryToInline(data.currentGraph(), currentInvocation, parentInvoke, data.inliningDepth() + 1); + } + }); + } } } @@ -581,6 +589,9 @@ private static final GraphInfo DummyGraphInfo = new GraphInfo(null, new LinkedList(), 1.0, 1.0); + /** + * Call hierarchy from outer most call (i.e., compilation unit) to inner most callee. + */ private final ArrayDeque graphQueue; private final ArrayDeque invocationQueue; @@ -632,6 +643,18 @@ } } + /** + * Gets the call hierarchy of this inling from outer most call to inner most callee. + */ + public Object[] inliningContext() { + Object[] result = new Object[graphQueue.size()]; + int i = 0; + for (GraphInfo g : graphQueue) { + result[i++] = g.graph.method(); + } + return result; + } + public MethodInvocation currentInvocation() { return invocationQueue.peek(); } @@ -670,10 +693,12 @@ StringBuilder result = new StringBuilder("Invocations: "); for (MethodInvocation invocation : invocationQueue) { - result.append(invocation.callee().numberOfMethods()); - result.append("x "); - result.append(invocation.callee().invoke()); - result.append("; "); + if (invocation.callee() != null) { + result.append(invocation.callee().numberOfMethods()); + result.append("x "); + result.append(invocation.callee().invoke()); + result.append("; "); + } } result.append("\nGraphs: "); @@ -754,8 +779,26 @@ public boolean isRoot() { return callee == null; } + + @Override + public String toString() { + if (isRoot()) { + return ""; + } + CallTargetNode callTarget = callee.invoke().callTarget(); + if (callTarget instanceof MethodCallTargetNode) { + ResolvedJavaMethod calleeMethod = ((MethodCallTargetNode) callTarget).targetMethod(); + return MetaUtil.format("Invoke#%H.%n(%p)", calleeMethod); + } else { + return "Invoke#" + callTarget.targetName(); + } + } } + /** + * Information about a graph that will potentially be inlined. This includes tracking the + * invocations in graph that will subject to inlining themselves. + */ private static class GraphInfo { private final StructuredGraph graph; @@ -777,6 +820,10 @@ } } + /** + * Gets the method associated with the {@linkplain #graph() graph} represented by this + * object. + */ public ResolvedJavaMethod method() { return graph.method(); } @@ -785,6 +832,9 @@ return !remainingInvokes.isEmpty(); } + /** + * The graph about which this object contains inlining information. + */ public StructuredGraph graph() { return graph; } @@ -809,6 +859,11 @@ public double invokeRelevance(Invoke invoke) { return Math.min(CapInheritedRelevance.getValue(), relevance) * nodeRelevance.get(invoke.asNode()); } + + @Override + public String toString() { + return MetaUtil.format("%H.%n(%p)", method()) + remainingInvokes; + } } private static class CompiledMethodInfo {