# HG changeset patch
# User Miguel Garcia
# Date 1402143790 -7200
# Node ID fa04403d1cb56a78a87ada2a063aa956108de209
# Parent 4291873b259b2854b79b2cf86507f8711f785ccb
[inliner] documentation, more and better
diff -r 4291873b259b -r fa04403d1cb5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningPhase.java
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningPhase.java Fri Jun 06 19:46:16 2014 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningPhase.java Sat Jun 07 14:23:10 2014 +0200
@@ -29,9 +29,7 @@
import com.oracle.graal.phases.common.*;
import com.oracle.graal.phases.common.inlining.policy.GreedyInliningPolicy;
import com.oracle.graal.phases.common.inlining.policy.InliningPolicy;
-import com.oracle.graal.phases.common.inlining.walker.CallsiteHolder;
import com.oracle.graal.phases.common.inlining.walker.InliningData;
-import com.oracle.graal.phases.common.inlining.walker.MethodInvocation;
import com.oracle.graal.phases.tiers.*;
public class InliningPhase extends AbstractInliningPhase {
@@ -72,68 +70,11 @@
}
/**
- *
- * The space of inlining decisions is explored depth-first with the help of a stack realized by
- * {@link com.oracle.graal.phases.common.inlining.walker.InliningData}. At any point in time,
- * its topmost element consist of:
- *
- * -
- * one or more {@link CallsiteHolder}s of inlining candidates, all of them corresponding to a
- * single callsite (details below). For example, "exact inline" leads to a single candidate.
- * -
- * the callsite (for the targets above) is tracked as a {@link MethodInvocation}. The difference
- * between {@link com.oracle.graal.phases.common.inlining.walker.MethodInvocation#totalGraphs()}
- * and {@link MethodInvocation#processedGraphs()} indicates the topmost {@link CallsiteHolder}s
- * that might be delved-into to explore inlining opportunities.
- *
- *
*
- *
- * The bottom-most element in the stack consists of:
- *
- * -
- * a single {@link CallsiteHolder} (the root one, for the method on which inlining was called)
- * -
- * a single {@link MethodInvocation} (the
- * {@link com.oracle.graal.phases.common.inlining.walker.MethodInvocation#isRoot} one, ie the
- * unknown caller of the root graph)
- *
- *
- *
+ * This method sets in motion the inlining machinery.
*
- *
- * The stack grows and shrinks as choices are made among the alternatives below:
- *
- * -
- * not worth inlining: pop any remaining graphs not yet delved into, pop the current invocation.
- *
- * -
- * process next invoke: delve into one of the callsites hosted in the current candidate graph,
- * determine whether any inlining should be performed in it
- * -
- * try to inline: move past the current inlining candidate (remove it from the topmost element).
- * If that was the last one then try to inline the callsite that is (still) in the topmost
- * element of {@link com.oracle.graal.phases.common.inlining.walker.InliningData}, and then
- * remove such callsite.
- *
- *
- *
- *
- * Some facts about the alternatives above:
- *
- * -
- * the first step amounts to backtracking, the 2nd one to delving, and the 3rd one also involves
- * backtracking (however after may-be inlining).
- * -
- * the choice of abandon-and-backtrack or delve-into is depends on
- * {@link InliningPolicy#isWorthInlining} and {@link InliningPolicy#continueInlining}.
- * -
- * the 3rd choice is picked when both of the previous ones aren't picked
- * -
- * as part of trying-to-inline, {@link InliningPolicy#isWorthInlining} again sees use, but
- * that's another story.
- *
- *
+ * @see InliningData
+ * @see InliningData#moveForward()
*
*/
@Override
diff -r 4291873b259b -r fa04403d1cb5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java Fri Jun 06 19:46:16 2014 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java Sat Jun 07 14:23:10 2014 +0200
@@ -37,6 +37,20 @@
import static com.oracle.graal.compiler.common.GraalOptions.OptCanonicalizer;
+/**
+ *
+ * Represents a feasible concrete target for inlining, whose graph has been copied already and thus
+ * can be modified without affecting the original (usually cached) version.
+ *
+ *
+ *
+ * Instances of this class don't make sense in isolation but as part of an
+ * {@link com.oracle.graal.phases.common.inlining.info.InlineInfo InlineInfo}.
+ *
+ *
+ * @see com.oracle.graal.phases.common.inlining.walker.InliningData#moveForward()
+ * @see com.oracle.graal.phases.common.inlining.walker.CallsiteHolderExplorable
+ */
public class InlineableGraph implements Inlineable {
private final StructuredGraph graph;
diff -r 4291873b259b -r fa04403d1cb5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/CallsiteHolderExplorable.java
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/CallsiteHolderExplorable.java Fri Jun 06 19:46:16 2014 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/CallsiteHolderExplorable.java Sat Jun 07 14:23:10 2014 +0200
@@ -36,15 +36,19 @@
/**
*
- * A {@link CallsiteHolder} whose graph has been already copied and thus can be modified without
+ * A {@link CallsiteHolder} whose graph has been copied already and thus can be modified without
* affecting the original (usually cached) version.
*
*
*
- * An instance of this class is "explorable" in that any {@link Invoke} nodes it contains are
- * candidates for depth-first search for further inlining opportunities (as realized by
- * {@link InliningData})
+ * An instance of this class is derived from an
+ * {@link com.oracle.graal.phases.common.inlining.info.elem.InlineableGraph InlineableGraph} and
+ * contains a subset of the information there: just the {@link Invoke} nodes from it. Such nodes are
+ * candidates for depth-first search of further inlining opportunities (thus the adjective
+ * "explorable" given to this class)
*
+ *
+ * @see InliningData#moveForward()
*/
public final class CallsiteHolderExplorable extends CallsiteHolder {
diff -r 4291873b259b -r fa04403d1cb5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/InliningData.java
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/InliningData.java Fri Jun 06 19:46:16 2014 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/InliningData.java Sat Jun 07 14:23:10 2014 +0200
@@ -54,8 +54,31 @@
import static com.oracle.graal.phases.common.inlining.walker.CallsiteHolderDummy.DUMMY_CALLSITE_HOLDER;
/**
- * Holds the data for building the callee graphs recursively: graphs and invocations (each
- * invocation can have multiple graphs).
+ *
+ * The space of inlining decisions is explored depth-first with the help of a stack realized by
+ * {@link InliningData}. At any point in time, the topmost element of that stack consists of:
+ *
+ * - the callsite under consideration is tracked as a {@link MethodInvocation}.
+ * -
+ * one or more {@link CallsiteHolder}s, all of them associated to the callsite above. Why more than
+ * one? Depending on the type-profile for the receiver more than one concrete method may be feasible
+ * target.
+ *
+ *
+ *
+ *
+ * The bottom element in the stack consists of:
+ *
+ * -
+ * a single {@link MethodInvocation} (the
+ * {@link com.oracle.graal.phases.common.inlining.walker.MethodInvocation#isRoot root} one, ie the
+ * unknown caller of the root graph)
+ * -
+ * a single {@link CallsiteHolder} (the root one, for the method on which inlining was called)
+ *
+ *
+ *
+ * @see #moveForward()
*/
public class InliningData {
@@ -376,6 +399,17 @@
}
/**
+ *
+ * This method attempts:
+ *
+ * -
+ * to inline at the callsite given by
calleeInvocation
, where that callsite belongs
+ * to the {@link CallsiteHolderExplorable} at the top of the {@link #graphQueue} maintained in
+ * this class.
+ * -
+ * otherwise, to devirtualize the callsite in question.
+ *
+ *
* @return true iff inlining was actually performed
*/
private boolean tryToInline(MethodInvocation calleeInvocation, MethodInvocation parentInvocation, int inliningDepth) {
@@ -398,7 +432,29 @@
}
/**
- * Process the next invoke and enqueue all its graphs for processing.
+ * This method picks one of the callsites belonging to the current
+ * {@link CallsiteHolderExplorable}. Provided the callsite qualifies to be analyzed for
+ * inlining, this method prepares a new stack top in {@link InliningData} for such callsite,
+ * which comprises:
+ *
+ * - preparing a summary of feasible targets, ie preparing an {@link InlineInfo}
+ * - based on it, preparing the stack top proper which consists of:
+ *
+ * - one {@link MethodInvocation}
+ * - a {@link CallsiteHolder} for each feasible target
+ *
+ *
+ *
+ *
+ * The thus prepared "stack top" is needed by {@link #moveForward()} to explore the space of
+ * inlining decisions (each decision one of: backtracking, delving, inlining).
+ *
+ *
+ *
+ * The {@link InlineInfo} used to get things rolling is kept around in the
+ * {@link MethodInvocation}, it will be needed in case of inlining, see
+ * {@link InlineInfo#inline(Providers, Assumptions)}
+ *
*/
private void processNextInvoke() {
CallsiteHolderExplorable callsiteHolder = (CallsiteHolderExplorable) currentGraph();
@@ -531,6 +587,49 @@
}
/**
+ *
+ * The stack realized by {@link InliningData} grows and shrinks as choices are made among the
+ * alternatives below:
+ *
+ * -
+ * not worth inlining: pop stack top, which comprises:
+ *
+ * - pop any remaining graphs not yet delved into
+ * - pop the current invocation
+ *
+ *
+ * -
+ * {@link #processNextInvoke() delve} into one of the callsites hosted in the current graph,
+ * such callsite is explored next by {@link #moveForward()}
+ * -
+ * {@link #tryToInline(MethodInvocation, MethodInvocation, int) try to inline}: move past the
+ * current graph (remove it from the topmost element).
+ *
+ * -
+ * If that was the last one then {@link #tryToInline(MethodInvocation, MethodInvocation, int)
+ * try to inline} the callsite under consideration (ie, the "current invocation").
+ * -
+ * Whether inlining occurs or not, that callsite is removed from the top of {@link InliningData}
+ * .
+ *
+ *
+ *
+ *
+ *
+ *
+ * Some facts about the alternatives above:
+ *
+ * -
+ * the first step amounts to backtracking, the 2nd one to depth-search, and the 3rd one also
+ * involves backtracking (however possibly after inlining).
+ * -
+ * the choice of abandon-and-backtrack or delve-into depends on
+ * {@link InliningPolicy#isWorthInlining} and {@link InliningPolicy#continueInlining}.
+ * -
+ * the 3rd choice is picked whenever none of the previous choices are made
+ *
+ *
+ *
* @return true iff inlining was actually performed
*/
public boolean moveForward() {
diff -r 4291873b259b -r fa04403d1cb5 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/MethodInvocation.java
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/MethodInvocation.java Fri Jun 06 19:46:16 2014 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/MethodInvocation.java Sat Jun 07 14:23:10 2014 +0200
@@ -29,6 +29,17 @@
import com.oracle.graal.nodes.java.MethodCallTargetNode;
import com.oracle.graal.phases.common.inlining.info.InlineInfo;
+/**
+ *
+ * An instance of this class denotes a callsite being analyzed for inlining.
+ *
+ *
+ * Each element of the {@link InliningData} stack contains one such instance, the accompanying
+ * {@link CallsiteHolder}s in that element represent feasible targets for the callsite in question.
+ *
+ *
+ * @see InliningData#moveForward()
+ */
public class MethodInvocation {
private final InlineInfo callee;