annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInlining.java @ 22572:3a2cab3a1df4

updated imported truffle version
author Doug Simon <doug.simon@oracle.com>
date Wed, 02 Sep 2015 22:40:18 +0200
parents 4cd28f6e3485
children 05183a084a08
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
17422
89f801a9b4d4 Truffle: fix headers.
Christian Humer <christian.humer@gmail.com>
parents: 17410
diff changeset
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.graal.truffle;
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
25 import java.util.*;
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26 import java.util.stream.*;
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
27
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
28 import com.oracle.truffle.api.*;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
29 import com.oracle.truffle.api.nodes.*;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
30 import com.oracle.truffle.api.nodes.Node;
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
32 public class TruffleInlining implements Iterable<TruffleInliningDecision> {
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
34 private final List<TruffleInliningDecision> callSites;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
35
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18211
diff changeset
36 protected TruffleInlining(List<TruffleInliningDecision> callSites) {
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 this.callSites = callSites;
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
40 public TruffleInlining(OptimizedCallTarget sourceTarget, TruffleInliningPolicy policy) {
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18211
diff changeset
41 this(createDecisions(sourceTarget, policy, sourceTarget.getRootNode().getCompilerOptions()));
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18211
diff changeset
42
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18211
diff changeset
45 private static List<TruffleInliningDecision> createDecisions(OptimizedCallTarget sourceTarget, TruffleInliningPolicy policy, CompilerOptions options) {
19978
4cd28f6e3485 Truffle: refactor trivial node count calculation and expose and API that enables to use it for Node subtrees.
Christian Humer <christian.humer@oracle.com>
parents: 19789
diff changeset
46 int nodeCount = sourceTarget.getNonTrivialNodeCount();
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
47 List<TruffleInliningDecision> exploredCallSites = exploreCallSites(new ArrayList<>(Arrays.asList(sourceTarget)), nodeCount, policy);
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18211
diff changeset
48 return decideInlining(exploredCallSites, policy, nodeCount, options);
17332
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
49 }
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
50
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
51 private static List<TruffleInliningDecision> exploreCallSites(List<OptimizedCallTarget> stack, int callStackNodeCount, TruffleInliningPolicy policy) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
52 List<TruffleInliningDecision> exploredCallSites = new ArrayList<>();
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 OptimizedCallTarget parentTarget = stack.get(stack.size() - 1);
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54 for (OptimizedDirectCallNode callNode : parentTarget.getCallNodes()) {
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 OptimizedCallTarget currentTarget = callNode.getCurrentCallTarget();
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56 stack.add(currentTarget); // push
17332
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
57 exploredCallSites.add(exploreCallSite(stack, callStackNodeCount, policy, callNode));
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 stack.remove(stack.size() - 1); // pop
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
60 return exploredCallSites;
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
62
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
63 private static TruffleInliningDecision exploreCallSite(List<OptimizedCallTarget> callStack, int callStackNodeCount, TruffleInliningPolicy policy, OptimizedDirectCallNode callNode) {
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 OptimizedCallTarget parentTarget = callStack.get(callStack.size() - 2);
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 OptimizedCallTarget currentTarget = callStack.get(callStack.size() - 1);
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
67 List<TruffleInliningDecision> childCallSites = Collections.emptyList();
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
68 double frequency = calculateFrequency(parentTarget, callNode);
19978
4cd28f6e3485 Truffle: refactor trivial node count calculation and expose and API that enables to use it for Node subtrees.
Christian Humer <christian.humer@oracle.com>
parents: 19789
diff changeset
69 int nodeCount = callNode.getCurrentCallTarget().getNonTrivialNodeCount();
17332
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
70
19789
e66a6f8d63e3 Truffle: implement recursive inlining and with a maximum depth of 4.
Christian Humer <christian.humer@gmail.com>
parents: 19766
diff changeset
71 int recursions = countRecursions(callStack);
17332
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
72 int deepNodeCount = nodeCount;
19789
e66a6f8d63e3 Truffle: implement recursive inlining and with a maximum depth of 4.
Christian Humer <christian.humer@gmail.com>
parents: 19766
diff changeset
73 if (callStack.size() < 15 && recursions <= TruffleCompilerOptions.TruffleMaximumRecursiveInlining.getValue()) {
17332
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
74 /*
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
75 * We make a preliminary optimistic inlining decision with best possible characteristics
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18211
diff changeset
76 * to avoid the exploration of unnecessary paths in the inlining tree.
17332
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
77 */
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18211
diff changeset
78 final CompilerOptions options = callNode.getRootNode().getCompilerOptions();
19789
e66a6f8d63e3 Truffle: implement recursive inlining and with a maximum depth of 4.
Christian Humer <christian.humer@gmail.com>
parents: 19766
diff changeset
79 if (policy.isAllowed(new TruffleInliningProfile(callNode, nodeCount, nodeCount, frequency, recursions), callStackNodeCount, options)) {
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
80 List<TruffleInliningDecision> exploredCallSites = exploreCallSites(callStack, callStackNodeCount + nodeCount, policy);
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18211
diff changeset
81 childCallSites = decideInlining(exploredCallSites, policy, nodeCount, options);
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
82 for (TruffleInliningDecision childCallSite : childCallSites) {
17332
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
83 if (childCallSite.isInline()) {
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
84 deepNodeCount += childCallSite.getProfile().getDeepNodeCount();
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
85 } else {
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
86 /* we don't need those anymore. */
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
87 childCallSite.getCallSites().clear();
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
88 }
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
92
19789
e66a6f8d63e3 Truffle: implement recursive inlining and with a maximum depth of 4.
Christian Humer <christian.humer@gmail.com>
parents: 19766
diff changeset
93 TruffleInliningProfile profile = new TruffleInliningProfile(callNode, nodeCount, deepNodeCount, frequency, recursions);
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94 profile.setScore(policy.calculateScore(profile));
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
95 return new TruffleInliningDecision(currentTarget, profile, childCallSites);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
96 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
97
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
98 private static double calculateFrequency(OptimizedCallTarget target, OptimizedDirectCallNode ocn) {
17404
b725292b8a11 Truffle: updated TruffleCallTargetProfiling
Christian Humer <christian.humer@gmail.com>
parents: 17401
diff changeset
99 return (double) Math.max(1, ocn.getCallCount()) / (double) Math.max(1, target.getCompilationProfile().getInterpreterCallCount());
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101
19789
e66a6f8d63e3 Truffle: implement recursive inlining and with a maximum depth of 4.
Christian Humer <christian.humer@gmail.com>
parents: 19766
diff changeset
102 private static int countRecursions(List<OptimizedCallTarget> stack) {
e66a6f8d63e3 Truffle: implement recursive inlining and with a maximum depth of 4.
Christian Humer <christian.humer@gmail.com>
parents: 19766
diff changeset
103 int count = 0;
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 OptimizedCallTarget top = stack.get(stack.size() - 1);
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 for (int i = 0; i < stack.size() - 1; i++) {
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
106 if (stack.get(i) == top) {
19789
e66a6f8d63e3 Truffle: implement recursive inlining and with a maximum depth of 4.
Christian Humer <christian.humer@gmail.com>
parents: 19766
diff changeset
107 count++;
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
108 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
109 }
19789
e66a6f8d63e3 Truffle: implement recursive inlining and with a maximum depth of 4.
Christian Humer <christian.humer@gmail.com>
parents: 19766
diff changeset
110
e66a6f8d63e3 Truffle: implement recursive inlining and with a maximum depth of 4.
Christian Humer <christian.humer@gmail.com>
parents: 19766
diff changeset
111 return count;
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
112 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
113
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18211
diff changeset
114 private static List<TruffleInliningDecision> decideInlining(List<TruffleInliningDecision> callSites, TruffleInliningPolicy policy, int nodeCount, CompilerOptions options) {
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
115 int deepNodeCount = nodeCount;
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
116 int index = 0;
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
117 for (TruffleInliningDecision callSite : callSites.stream().sorted().collect(Collectors.toList())) {
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
118 TruffleInliningProfile profile = callSite.getProfile();
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
119 profile.setQueryIndex(index++);
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18211
diff changeset
120 if (policy.isAllowed(profile, deepNodeCount, options)) {
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
121 callSite.setInline(true);
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
122 deepNodeCount += profile.getDeepNodeCount();
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
123 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
124 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
125 return callSites;
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
126 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
127
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
128 public int getInlinedNodeCount() {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
129 return getCallSites().stream().filter(callSite -> callSite.isInline()).mapToInt(callSite -> callSite.getProfile().getDeepNodeCount()).sum();
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
130 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
131
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
132 public int countCalls() {
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
133 return getCallSites().stream().mapToInt(callSite -> callSite.isInline() ? callSite.countCalls() + 1 : 1).sum();
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
134 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
135
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
136 public int countInlinedCalls() {
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
137 return getCallSites().stream().filter(TruffleInliningDecision::isInline).mapToInt(callSite -> callSite.countInlinedCalls() + 1).sum();
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
138 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
139
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
140 public final List<TruffleInliningDecision> getCallSites() {
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
141 return callSites;
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
142 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
143
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
144 public Iterator<TruffleInliningDecision> iterator() {
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
145 return callSites.iterator();
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
146 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
147
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
148 public TruffleInliningDecision findByCall(OptimizedDirectCallNode callNode) {
19075
336adcd0070b Clean ups in partial evaluator. New development-only option FastPE.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18386
diff changeset
149 for (TruffleInliningDecision d : getCallSites()) {
336adcd0070b Clean ups in partial evaluator. New development-only option FastPE.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18386
diff changeset
150 if (d.getProfile().getCallNode() == callNode) {
336adcd0070b Clean ups in partial evaluator. New development-only option FastPE.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18386
diff changeset
151 return d;
336adcd0070b Clean ups in partial evaluator. New development-only option FastPE.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18386
diff changeset
152 }
336adcd0070b Clean ups in partial evaluator. New development-only option FastPE.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18386
diff changeset
153 }
336adcd0070b Clean ups in partial evaluator. New development-only option FastPE.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18386
diff changeset
154 return null;
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
155 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
156
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
157 /**
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
158 * Visits all nodes of the {@link CallTarget} and all of its inlined calls.
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
159 */
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
160 public void accept(OptimizedCallTarget target, NodeVisitor visitor) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
161 target.getRootNode().accept(new CallTreeNodeVisitorImpl(target, visitor));
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
162 }
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
163
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
164 /**
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
165 * Creates an iterator for all nodes of the {@link CallTarget} and all of its inlined calls.
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
166 */
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
167 public Iterator<Node> makeNodeIterator(OptimizedCallTarget target) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
168 return new CallTreeNodeIterator(target);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
169 }
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
170
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
171 /**
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
172 * This visitor extends the {@link NodeVisitor} interface to be usable for traversing the full
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
173 * call tree.
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
174 */
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
175 public interface CallTreeNodeVisitor extends NodeVisitor {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
176
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17422
diff changeset
177 boolean visit(List<TruffleInlining> decisionStack, Node node);
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
178
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17422
diff changeset
179 default boolean visit(Node node) {
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
180 return visit(null, node);
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
181 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
182
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
183 static int getNodeDepth(List<TruffleInlining> decisionStack, Node node) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
184 int depth = calculateNodeDepth(node);
17410
c58171f94377 Truffle: fix potential null dereferences in call tree visitor.
Christian Humer <christian.humer@gmail.com>
parents: 17404
diff changeset
185 if (decisionStack != null) {
c58171f94377 Truffle: fix potential null dereferences in call tree visitor.
Christian Humer <christian.humer@gmail.com>
parents: 17404
diff changeset
186 for (int i = decisionStack.size() - 1; i > 0; i--) {
c58171f94377 Truffle: fix potential null dereferences in call tree visitor.
Christian Humer <christian.humer@gmail.com>
parents: 17404
diff changeset
187 TruffleInliningDecision decision = (TruffleInliningDecision) decisionStack.get(i);
c58171f94377 Truffle: fix potential null dereferences in call tree visitor.
Christian Humer <christian.humer@gmail.com>
parents: 17404
diff changeset
188 depth += calculateNodeDepth(decision.getProfile().getCallNode());
c58171f94377 Truffle: fix potential null dereferences in call tree visitor.
Christian Humer <christian.humer@gmail.com>
parents: 17404
diff changeset
189 }
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
190 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
191 return depth;
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
192 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
193
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
194 static int calculateNodeDepth(Node node) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
195 int depth = 0;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
196 Node traverseNode = node;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
197 while (traverseNode != null) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
198 depth++;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
199 traverseNode = traverseNode.getParent();
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
200 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
201 return depth;
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
202 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
203
17401
c0f71f81708a Truffle: fixes to the call tree logging.
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
204 static TruffleInliningDecision getCurrentInliningDecision(List<TruffleInlining> decisionStack) {
17410
c58171f94377 Truffle: fix potential null dereferences in call tree visitor.
Christian Humer <christian.humer@gmail.com>
parents: 17404
diff changeset
205 if (decisionStack == null || decisionStack.size() <= 1) {
17401
c0f71f81708a Truffle: fixes to the call tree logging.
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
206 return null;
c0f71f81708a Truffle: fixes to the call tree logging.
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
207 }
c0f71f81708a Truffle: fixes to the call tree logging.
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
208 return (TruffleInliningDecision) decisionStack.get(decisionStack.size() - 1);
c0f71f81708a Truffle: fixes to the call tree logging.
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
209 }
c0f71f81708a Truffle: fixes to the call tree logging.
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
210
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
211 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
212
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
213 /**
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
214 * This visitor wraps an existing {@link NodeVisitor} or {@link CallTreeNodeVisitor} and
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
215 * traverses the full Truffle tree including inlined call sites.
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
216 */
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17422
diff changeset
217 private static final class CallTreeNodeVisitorImpl implements NodeVisitor {
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
218
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
219 protected final List<TruffleInlining> stack = new ArrayList<>();
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
220 private final NodeVisitor visitor;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
221 private boolean continueTraverse = true;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
222
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
223 public CallTreeNodeVisitorImpl(OptimizedCallTarget target, NodeVisitor visitor) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
224 stack.add(target.getInlining());
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
225 this.visitor = visitor;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
226 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
227
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17422
diff changeset
228 public boolean visit(Node node) {
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
229 if (node instanceof OptimizedDirectCallNode) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
230 OptimizedDirectCallNode callNode = (OptimizedDirectCallNode) node;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
231 TruffleInlining inlining = stack.get(stack.size() - 1);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
232 if (inlining != null) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
233 TruffleInliningDecision childInlining = inlining.findByCall(callNode);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
234 if (childInlining != null) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
235 stack.add(childInlining);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
236 continueTraverse = visitNode(node);
18211
16757e473b36 Truffle: fixed node visitor was traversing the full call tree.
Christian Humer <christian.humer@gmail.com>
parents: 18206
diff changeset
237 if (continueTraverse && childInlining.isInline()) {
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
238 childInlining.getTarget().getRootNode().accept(this);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
239 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
240 stack.remove(stack.size() - 1);
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
241 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
242 }
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
243 return continueTraverse;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
244 } else {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
245 continueTraverse = visitNode(node);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
246 return continueTraverse;
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
247 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
248 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
249
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
250 private boolean visitNode(Node node) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
251 if (visitor instanceof CallTreeNodeVisitor) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
252 return ((CallTreeNodeVisitor) visitor).visit(stack, node);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
253 } else {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
254 return visitor.visit(node);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
255 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
256 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
257 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
258
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
259 private static final class CallTreeNodeIterator implements Iterator<Node> {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
260
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
261 private List<TruffleInlining> inliningDecisionStack = new ArrayList<>();
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
262 private List<Iterator<Node>> iteratorStack = new ArrayList<>();
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
263
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
264 public CallTreeNodeIterator(OptimizedCallTarget target) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
265 inliningDecisionStack.add(target.getInlining());
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
266 iteratorStack.add(NodeUtil.makeRecursiveIterator(target.getRootNode()));
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
267 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
268
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
269 public boolean hasNext() {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
270 return peekIterator() != null;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
271 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
272
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
273 public Node next() {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
274 Iterator<Node> iterator = peekIterator();
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
275 if (iterator == null) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
276 throw new NoSuchElementException();
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
277 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
278
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
279 Node node = iterator.next();
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
280 if (node instanceof OptimizedDirectCallNode) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
281 visitInlinedCall(node);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
282 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
283 return node;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
284 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
285
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
286 private void visitInlinedCall(Node node) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
287 TruffleInlining currentDecision = inliningDecisionStack.get(inliningDecisionStack.size() - 1);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
288 if (currentDecision == null) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
289 return;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
290 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
291 TruffleInliningDecision decision = currentDecision.findByCall((OptimizedDirectCallNode) node);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
292 if (decision.isInline()) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
293 inliningDecisionStack.add(decision);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
294 iteratorStack.add(NodeUtil.makeRecursiveIterator(decision.getTarget().getRootNode()));
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
295 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
296 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
297
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
298 private Iterator<Node> peekIterator() {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
299 int tos = iteratorStack.size() - 1;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
300 while (tos >= 0) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
301 Iterator<Node> iterable = iteratorStack.get(tos);
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
302 if (iterable.hasNext()) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
303 return iterable;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
304 } else {
17404
b725292b8a11 Truffle: updated TruffleCallTargetProfiling
Christian Humer <christian.humer@gmail.com>
parents: 17401
diff changeset
305 iteratorStack.remove(tos);
b725292b8a11 Truffle: updated TruffleCallTargetProfiling
Christian Humer <christian.humer@gmail.com>
parents: 17401
diff changeset
306 inliningDecisionStack.remove(tos--);
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
307 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
308 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
309 return null;
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
310 }
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
311
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
312 public void remove() {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17332
diff changeset
313 throw new UnsupportedOperationException();
17332
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
314 }
6e590e01ecf9 Truffle: make preliminary inlining decisions with the best possible characteristics to avoid the exploration of unneccessary pathes in the inlining tree for context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
315
17256
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
316 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
317
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
318 }