# 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: - *

- *

* - *

- * The bottom-most element in the stack consists of: - *

- * - *

+ * This method sets in motion the inlining machinery. * - *

- * The stack grows and shrinks as choices are made among the alternatives below: - *

    - *
  1. - * not worth inlining: pop any remaining graphs not yet delved into, pop the current invocation. - *
  2. - *
  3. - * process next invoke: delve into one of the callsites hosted in the current candidate graph, - * determine whether any inlining should be performed in it
  4. - *
  5. - * 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.
  6. - *
- *

- * - *

- * Some facts about the alternatives above: - *

- *

+ * @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 bottom element in the stack consists of: + *

+ *

+ * + * @see #moveForward() */ public class InliningData { @@ -376,6 +399,17 @@ } /** + * + * This method attempts: + *
    + *
  1. + * 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.
  2. + *
  3. + * otherwise, to devirtualize the callsite in question.
  4. + *
+ * * @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: + * + * + *

+ * 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: + *

    + *
  1. + * not worth inlining: pop stack top, which comprises: + *
      + *
    • pop any remaining graphs not yet delved into
    • + *
    • pop the current invocation
    • + *
    + *
  2. + *
  3. + * {@link #processNextInvoke() delve} into one of the callsites hosted in the current graph, + * such callsite is explored next by {@link #moveForward()}
  4. + *
  5. + * {@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} + * .
    • + *
    + *
  6. + *
+ *

+ * + *

+ * Some facts about the alternatives above: + *

+ *

+ * * @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;