annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java @ 21554:b1530a6cce8c

renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Tue, 26 May 2015 23:21:15 +0200
parents 93c50cefb9e8
children 48c1ebd24120
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
17422
89f801a9b4d4 Truffle: fix headers.
Christian Humer <christian.humer@gmail.com>
parents: 17420
diff changeset
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.truffle;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import static com.oracle.graal.truffle.TruffleCompilerOptions.*;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27 import java.io.*;
17307
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
28 import java.lang.reflect.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 import java.util.*;
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
30 import java.util.concurrent.atomic.*;
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
31 import java.util.stream.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.api.code.*;
18204
a1873eefea65 Truffle: refactor TraceTrufflePerformanceWarnings into separate class.
Christian Humer <christian.humer@gmail.com>
parents: 18200
diff changeset
34 import com.oracle.graal.truffle.debug.*;
21543
93c50cefb9e8 moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21204
diff changeset
35 import com.oracle.jvmci.common.*;
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21543
diff changeset
36 import com.oracle.jvmci.debug.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 import com.oracle.truffle.api.*;
15216
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
38 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 import com.oracle.truffle.api.frame.*;
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
40 import com.oracle.truffle.api.impl.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 import com.oracle.truffle.api.nodes.*;
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
42 import com.oracle.truffle.api.nodes.Node;
17600
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
43 import com.oracle.truffle.api.utilities.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 /**
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 * Call target that is optimized by Graal upon surpassing a specific invocation threshold.
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 */
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
48 public class OptimizedCallTarget extends InstalledCode implements RootCallTarget, LoopCountReceiver, ReplaceObserver {
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
50 protected static final PrintStream OUT = TTY.out().out();
12709
d2d0c44662bb Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents: 12708
diff changeset
51
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
52 protected final GraalTruffleRuntime runtime;
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
53 private SpeculationLog speculationLog;
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
54 protected final CompilationProfile compilationProfile;
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
55 protected final CompilationPolicy compilationPolicy;
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
56 private final OptimizedCallTarget sourceCallTarget;
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
57 private final AtomicInteger callSitesKnown = new AtomicInteger(0);
19743
2a21ea0ec141 Profile exceptions on OptimizeCallTarget#doInvoke.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19703
diff changeset
58 private final ValueProfile exceptionProfile = ValueProfile.createClassProfile();
18276
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents: 18275
diff changeset
59
15231
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
60 @CompilationFinal private Class<?>[] profiledArgumentTypes;
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
61 @CompilationFinal private Assumption profiledArgumentTypesAssumption;
15216
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
62 @CompilationFinal private Class<?> profiledReturnType;
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
63 @CompilationFinal private Assumption profiledReturnTypeAssumption;
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
64
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
65 private final RootNode uninitializedRootNode;
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
66 private final RootNode rootNode;
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
67
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: 17191
diff changeset
68 /* Experimental fields for new splitting. */
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
69 private final Map<TruffleStamp, OptimizedCallTarget> splitVersions = new HashMap<>();
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
70 private TruffleStamp argumentStamp = DefaultTruffleStamp.getInstance();
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
71
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
72 private TruffleInlining inlining;
19759
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
73 private int cachedNonTrivialNodeCount = -1;
20095
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
74 private boolean compiling;
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: 17191
diff changeset
75
17600
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
76 /**
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
77 * When this call target is inlined, the inlining {@link InstalledCode} registers this
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
78 * assumption. It gets invalidated when a node rewriting is performed. This ensures that all
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
79 * compiled methods that have this call target inlined are properly invalidated.
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
80 */
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
81 private final CyclicAssumption nodeRewritingAssumption;
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
82
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
83 public final RootNode getRootNode() {
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
84 return rootNode;
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
85 }
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
86
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
87 public OptimizedCallTarget(OptimizedCallTarget sourceCallTarget, RootNode rootNode, GraalTruffleRuntime runtime, CompilationPolicy compilationPolicy, SpeculationLog speculationLog) {
16401
347915b8cea8 Move name from HotSpotNmethod to InstalledCode to have a name again for truffle nmethods.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16044
diff changeset
88 super(rootNode.toString());
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
89 this.sourceCallTarget = sourceCallTarget;
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
90 this.runtime = runtime;
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
91 this.speculationLog = speculationLog;
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
92 this.rootNode = rootNode;
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
93 this.compilationPolicy = compilationPolicy;
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
94 this.rootNode.adoptChildren();
18485
e3c95cbbb50c Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 18386
diff changeset
95 this.rootNode.applyInstrumentation();
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
96 this.uninitializedRootNode = sourceCallTarget == null ? cloneRootNode(rootNode) : sourceCallTarget.uninitializedRootNode;
10844
3cf5f371dc9f Truffle: print inlined call target and rename profiling option.
Andreas Woess <andreas.woess@jku.at>
parents: 10797
diff changeset
97 if (TruffleCallTargetProfiling.getValue()) {
17420
e98150919577 Truffle: cleanup compilation profile fields.
Christian Humer <christian.humer@gmail.com>
parents: 17404
diff changeset
98 this.compilationProfile = new TraceCompilationProfile();
17404
b725292b8a11 Truffle: updated TruffleCallTargetProfiling
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
99 } else {
17420
e98150919577 Truffle: cleanup compilation profile fields.
Christian Humer <christian.humer@gmail.com>
parents: 17404
diff changeset
100 this.compilationProfile = new CompilationProfile();
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
101 }
17600
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
102 this.nodeRewritingAssumption = new CyclicAssumption("nodeRewritingAssumption of " + rootNode.toString());
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
103 }
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
104
20095
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
105 public final boolean isCompiling() {
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
106 return compiling;
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
107 }
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
108
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
109 private static RootNode cloneRootNode(RootNode root) {
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
110 if (root == null || !root.isCloningAllowed()) {
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
111 return null;
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
112 }
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
113 return NodeUtil.cloneNode(root);
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
114 }
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
115
17600
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
116 public Assumption getNodeRewritingAssumption() {
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
117 return nodeRewritingAssumption.getAssumption();
13984
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
118 }
13703
03b42f0fb635 Truffle: extend inlining interface with custom reprofile counters.
Christian Humer <christian.humer@gmail.com>
parents: 13208
diff changeset
119
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
120 public final void mergeArgumentStamp(TruffleStamp p) {
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
121 this.argumentStamp = this.argumentStamp.join(p);
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
122 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
123
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
124 public final TruffleStamp getArgumentStamp() {
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
125 return argumentStamp;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
126 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
127
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
128 private int cloneIndex;
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
129
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
130 public int getCloneIndex() {
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
131 return cloneIndex;
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
132 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
133
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
134 public OptimizedCallTarget cloneUninitialized() {
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
135 RootNode copiedRoot = cloneRootNode(uninitializedRootNode);
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
136 if (copiedRoot == null) {
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
137 return null;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
138 }
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
139 OptimizedCallTarget splitTarget = (OptimizedCallTarget) runtime.createClonedCallTarget(this, copiedRoot);
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
140 splitTarget.cloneIndex = cloneIndex++;
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
141 return splitTarget;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
142 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
143
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
144 public Map<TruffleStamp, OptimizedCallTarget> getSplitVersions() {
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
145 return splitVersions;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
146 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
147
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
148 public SpeculationLog getSpeculationLog() {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
149 return speculationLog;
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
150 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
151
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
152 @Override
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
153 public Object call(Object... args) {
17404
b725292b8a11 Truffle: updated TruffleCallTargetProfiling
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
154 compilationProfile.reportIndirectCall();
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
155 if (profiledArgumentTypesAssumption != null && profiledArgumentTypesAssumption.isValid()) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
156 CompilerDirectives.transferToInterpreterAndInvalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
157 profiledArgumentTypesAssumption.invalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
158 profiledArgumentTypes = null;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
159 }
17191
be733832464d Allow subclasses to intercept Truffle call boundaries
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17152
diff changeset
160 return doInvoke(args);
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
161 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
162
17307
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
163 public final Object callDirect(Object... args) {
17404
b725292b8a11 Truffle: updated TruffleCallTargetProfiling
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
164 compilationProfile.reportDirectCall();
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
165 profileArguments(args);
20882
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
166 try {
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
167 Object result = doInvoke(args);
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
168 Class<?> klass = profiledReturnType;
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
169 if (klass != null && CompilerDirectives.inCompiledCode() && profiledReturnTypeAssumption.isValid()) {
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
170 result = FrameWithoutBoxing.unsafeCast(result, klass, true, true);
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
171 }
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
172 return result;
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
173 } catch (Throwable t) {
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
174 t = exceptionProfile.profile(t);
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
175 if (t instanceof RuntimeException) {
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
176 throw (RuntimeException) t;
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
177 } else if (t instanceof Error) {
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
178 throw (Error) t;
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
179 } else {
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
180 throw new RuntimeException(t);
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
181 }
15224
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
182 }
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
183 }
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
184
17307
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
185 public final Object callInlined(Object... arguments) {
17404
b725292b8a11 Truffle: updated TruffleCallTargetProfiling
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
186 compilationProfile.reportInlinedCall();
17307
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
187 VirtualFrame frame = createFrame(getRootNode().getFrameDescriptor(), arguments);
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
188 return callProxy(frame);
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
189 }
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
190
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
191 @ExplodeLoop
20095
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
192 void profileArguments(Object[] args) {
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
193 if (profiledArgumentTypesAssumption == null) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
194 CompilerDirectives.transferToInterpreterAndInvalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
195 initializeProfiledArgumentTypes(args);
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
196 } else if (profiledArgumentTypes != null) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
197 if (profiledArgumentTypes.length != args.length) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
198 CompilerDirectives.transferToInterpreterAndInvalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
199 profiledArgumentTypesAssumption.invalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
200 profiledArgumentTypes = null;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
201 } else if (TruffleArgumentTypeSpeculation.getValue() && profiledArgumentTypesAssumption.isValid()) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
202 for (int i = 0; i < profiledArgumentTypes.length; i++) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
203 if (profiledArgumentTypes[i] != null && !profiledArgumentTypes[i].isInstance(args[i])) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
204 CompilerDirectives.transferToInterpreterAndInvalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
205 updateProfiledArgumentTypes(args);
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
206 break;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
207 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
208 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
209 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
210 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
211 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
212
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
213 private void initializeProfiledArgumentTypes(Object[] args) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
214 CompilerAsserts.neverPartOfCompilation();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
215 profiledArgumentTypesAssumption = Truffle.getRuntime().createAssumption("Profiled Argument Types");
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
216 profiledArgumentTypes = new Class<?>[args.length];
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
217 if (TruffleArgumentTypeSpeculation.getValue()) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
218 for (int i = 0; i < args.length; i++) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
219 profiledArgumentTypes[i] = classOf(args[i]);
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
220 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
221 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
222 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
223
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
224 private void updateProfiledArgumentTypes(Object[] args) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
225 CompilerAsserts.neverPartOfCompilation();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
226 profiledArgumentTypesAssumption.invalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
227 for (int j = 0; j < profiledArgumentTypes.length; j++) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
228 profiledArgumentTypes[j] = joinTypes(profiledArgumentTypes[j], classOf(args[j]));
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
229 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
230 profiledArgumentTypesAssumption = Truffle.getRuntime().createAssumption("Profiled Argument Types");
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
231 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
232
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
233 private static Class<?> classOf(Object arg) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
234 return arg != null ? arg.getClass() : null;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
235 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
236
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
237 private static Class<?> joinTypes(Class<?> class1, Class<?> class2) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
238 if (class1 == class2) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
239 return class1;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
240 } else if (class1 == null || class2 == null) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
241 return null;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
242 } else if (class1.isAssignableFrom(class2)) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
243 return class1;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
244 } else if (class2.isAssignableFrom(class1)) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
245 return class2;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
246 } else {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
247 return Object.class;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
248 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
249 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
250
17191
be733832464d Allow subclasses to intercept Truffle call boundaries
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17152
diff changeset
251 protected Object doInvoke(Object[] args) {
20882
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
252 return callBoundary(args);
17191
be733832464d Allow subclasses to intercept Truffle call boundaries
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17152
diff changeset
253 }
be733832464d Allow subclasses to intercept Truffle call boundaries
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17152
diff changeset
254
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
255 @TruffleCallBoundary
17191
be733832464d Allow subclasses to intercept Truffle call boundaries
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17152
diff changeset
256 protected final Object callBoundary(Object[] args) {
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
257 if (CompilerDirectives.inInterpreter()) {
15215
ca250afc78ec Simplification of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15212
diff changeset
258 // We are called and we are still in Truffle interpreter mode.
ca250afc78ec Simplification of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15212
diff changeset
259 interpreterCall();
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
260 } else {
18276
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents: 18275
diff changeset
261 // We come here from compiled code
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
262 }
15216
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
263
17427
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
264 return callRoot(args);
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
265 }
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
266
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
267 public final Object callRoot(Object[] originalArguments) {
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
268 Object[] args = originalArguments;
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: 17191
diff changeset
269 if (this.profiledArgumentTypesAssumption != null && CompilerDirectives.inCompiledCode() && profiledArgumentTypesAssumption.isValid()) {
19452
3e5c4e59c586 Correctly create IsCompilationConstantNode in FastPE mode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19437
diff changeset
270 args = FrameWithoutBoxing.unsafeCast(castArrayFixedLength(args, profiledArgumentTypes.length), Object[].class, true, true);
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: 17191
diff changeset
271 if (TruffleArgumentTypeSpeculation.getValue()) {
17427
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
272 args = castArguments(args);
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: 17191
diff changeset
273 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
274 }
17427
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
275
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
276 VirtualFrame frame = createFrame(getRootNode().getFrameDescriptor(), args);
17307
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
277 Object result = callProxy(frame);
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: 17191
diff changeset
278
20095
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
279 profileReturnType(result);
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
280
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
281 return result;
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
282 }
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
283
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
284 void profileReturnType(Object result) {
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: 17191
diff changeset
285 if (profiledReturnTypeAssumption == null) {
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
286 if (TruffleReturnTypeSpeculation.getValue()) {
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
287 CompilerDirectives.transferToInterpreterAndInvalidate();
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
288 profiledReturnType = (result == null ? null : result.getClass());
17427
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
289 profiledReturnTypeAssumption = Truffle.getRuntime().createAssumption("Profiled Return Type");
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: 17191
diff changeset
290 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
291 } else if (profiledReturnType != null) {
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
292 if (result == null || profiledReturnType != result.getClass()) {
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
293 CompilerDirectives.transferToInterpreterAndInvalidate();
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
294 profiledReturnType = null;
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
295 profiledReturnTypeAssumption.invalidate();
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
296 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
297 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
298 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
299
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
300 @Override
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
301 public void invalidate() {
18199
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
302 invalidate(null, null);
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
303 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
304
18798
f1e7e4f6d833 Truffle: improve invalidation messages for assumptions.
Christian Humer <christian.humer@gmail.com>
parents: 18485
diff changeset
305 protected void invalidate(Object source, CharSequence reason) {
18210
84e270aa1f47 Truffle: fixed invalidations were printed multiple times.
Christian Humer <christian.humer@gmail.com>
parents: 18206
diff changeset
306 if (isValid()) {
84e270aa1f47 Truffle: fixed invalidations were printed multiple times.
Christian Humer <christian.humer@gmail.com>
parents: 18206
diff changeset
307 this.runtime.invalidateInstalledCode(this, source, reason);
84e270aa1f47 Truffle: fixed invalidations were printed multiple times.
Christian Humer <christian.humer@gmail.com>
parents: 18206
diff changeset
308 }
19759
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
309 cachedNonTrivialNodeCount = -1;
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
310 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
311
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
312 public TruffleInlining getInlining() {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
313 return inlining;
16044
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15393
diff changeset
314 }
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15393
diff changeset
315
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
316 public void setInlining(TruffleInlining inliningDecision) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
317 this.inlining = inliningDecision;
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: 17191
diff changeset
318 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
319
18200
62de94d5cf73 Truffle: refactor implementation of TraceTruffleCompilation, TraceTruffleCompilationDetails into separate classes.
Christian Humer <christian.humer@gmail.com>
parents: 18199
diff changeset
320 private boolean cancelInstalledTask(Node source, CharSequence reason) {
62de94d5cf73 Truffle: refactor implementation of TraceTruffleCompilation, TraceTruffleCompilationDetails into separate classes.
Christian Humer <christian.humer@gmail.com>
parents: 18199
diff changeset
321 return this.runtime.cancelInstalledTask(this, source, reason);
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
322 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
323
15215
ca250afc78ec Simplification of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15212
diff changeset
324 private void interpreterCall() {
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
325 if (isValid()) {
15222
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
326 // Stubs were deoptimized => reinstall.
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
327 this.runtime.reinstallStubs();
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
328 } else {
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
329 compilationProfile.reportInterpreterCall();
20095
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
330 if (!isCompiling() && compilationPolicy.shouldCompile(compilationProfile, getCompilerOptions())) {
15222
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
331 compile();
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
332 }
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
333 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
334 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
335
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
336 public void compile() {
20095
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
337 if (!isCompiling()) {
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
338 compiling = true;
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
339 runtime.compile(this, TruffleBackgroundCompilation.getValue() && !TruffleCompilationExceptionsAreThrown.getValue());
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
340 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
341 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
342
18198
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
343 public void notifyCompilationFailed(Throwable t) {
19868
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19759
diff changeset
344 if (t instanceof BailoutException && !((BailoutException) t).isPermanent()) {
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19759
diff changeset
345 /*
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19759
diff changeset
346 * Non permanent bailouts are expected cases. A non permanent bailout would be for
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19759
diff changeset
347 * example class redefinition during code installation. As opposed to permanent
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19759
diff changeset
348 * bailouts, non permanent bailouts will trigger recompilation and are not considered a
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19759
diff changeset
349 * failure state.
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19759
diff changeset
350 */
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19759
diff changeset
351 } else {
18198
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
352 compilationPolicy.recordCompilationFailure(t);
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
353 if (TruffleCompilationExceptionsAreThrown.getValue()) {
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
354 throw new OptimizationFailedException(t, this);
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: 17191
diff changeset
355 }
19868
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19759
diff changeset
356 if (TruffleCompilationExceptionsAreFatal.getValue()) {
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19759
diff changeset
357 t.printStackTrace(OUT);
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19759
diff changeset
358 System.exit(-1);
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19759
diff changeset
359 }
18198
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
360 }
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
361 }
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
362
20095
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
363 public void notifyCompilationFinished(boolean successful) {
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
364 if (successful && inlining != null) {
18198
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
365 dequeueInlinedCallSites(inlining);
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
366 }
20095
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
367 compiling = false;
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
368 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
369
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
370 private void dequeueInlinedCallSites(TruffleInlining parentDecision) {
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
371 for (TruffleInliningDecision decision : parentDecision) {
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: 17191
diff changeset
372 if (decision.isInline()) {
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
373 OptimizedCallTarget target = decision.getTarget();
18200
62de94d5cf73 Truffle: refactor implementation of TraceTruffleCompilation, TraceTruffleCompilationDetails into separate classes.
Christian Humer <christian.humer@gmail.com>
parents: 18199
diff changeset
374 target.cancelInstalledTask(decision.getProfile().getCallNode(), "Inlining caller compiled.");
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: 17191
diff changeset
375 dequeueInlinedCallSites(decision);
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
376 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
377 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
378 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
379
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
380 protected final Object callProxy(VirtualFrame frame) {
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
381 try {
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
382 return getRootNode().execute(frame);
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
383 } finally {
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
384 // this assertion is needed to keep the values from being cleared as non-live locals
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
385 assert frame != null && this != null;
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
386 }
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
387 }
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
388
14984
a5bebb69dc78 Truffle: instead of redirecting the call method. inlining is now performed by ignoring @SlowPath.
Christian Humer <christian.humer@gmail.com>
parents: 14983
diff changeset
389 public final int getKnownCallSiteCount() {
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
390 return callSitesKnown.get();
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
391 }
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
392
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
393 public final void incrementKnownCallSites() {
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
394 callSitesKnown.incrementAndGet();
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
395 }
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
396
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
397 public final void decrementKnownCallSites() {
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
398 callSitesKnown.decrementAndGet();
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
399 }
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
400
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
401 public final OptimizedCallTarget getSourceCallTarget() {
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
402 return sourceCallTarget;
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
403 }
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
404
13984
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
405 @Override
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
406 public String toString() {
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
407 String superString = rootNode.toString();
15168
78530cbd8940 Truffle: Make OptimizedCallTarget itself an InstalledCode object.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15167
diff changeset
408 if (isValid()) {
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
409 superString += " <opt>";
13984
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
410 }
18162
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
411 if (sourceCallTarget != null) {
ab62800259ff Truffle: renamed the splitting to callTargetCloning. Made RootNode cloning an implementation detail of the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 18129
diff changeset
412 superString += " <split-" + cloneIndex + "-" + argumentStamp.toStringShort() + ">";
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
413 }
13984
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
414 return superString;
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
415 }
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
416
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
417 public CompilationProfile getCompilationProfile() {
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
418 return compilationProfile;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
419 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
420
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
421 @ExplodeLoop
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
422 private Object[] castArguments(Object[] originalArguments) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
423 Object[] castArguments = new Object[profiledArgumentTypes.length];
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
424 for (int i = 0; i < profiledArgumentTypes.length; i++) {
19452
3e5c4e59c586 Correctly create IsCompilationConstantNode in FastPE mode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19437
diff changeset
425 castArguments[i] = profiledArgumentTypes[i] != null ? FrameWithoutBoxing.unsafeCast(originalArguments[i], profiledArgumentTypes[i], true, true) : originalArguments[i];
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
426 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
427 return castArguments;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
428 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
429
15231
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
430 private static Object castArrayFixedLength(Object[] args, @SuppressWarnings("unused") int length) {
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
431 return args;
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
432 }
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
433
19437
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18950
diff changeset
434 public static VirtualFrame createFrame(FrameDescriptor descriptor, Object[] args) {
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18950
diff changeset
435 if (TruffleCompilerOptions.TruffleUseFrameWithoutBoxing.getValue()) {
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18950
diff changeset
436 return new FrameWithoutBoxing(descriptor, args);
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18950
diff changeset
437 } else {
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18950
diff changeset
438 return new FrameWithBoxing(descriptor, args);
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18950
diff changeset
439 }
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
440 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
441
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: 17191
diff changeset
442 public List<OptimizedDirectCallNode> getCallNodes() {
20132
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
443 final List<OptimizedDirectCallNode> callNodes = new ArrayList<>();
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
444 getRootNode().accept(new NodeVisitor() {
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
445 public boolean visit(Node node) {
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
446 if (node instanceof OptimizedDirectCallNode) {
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
447 callNodes.add((OptimizedDirectCallNode) node);
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
448 }
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
449 return true;
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
450 }
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
451 });
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
452 return callNodes;
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: 17191
diff changeset
453 }
88d5fd9e1a6c Truffle: implemented context sensitive inlining; implemented basic partial evaluation caching for call targets (disabled by default).
Christian Humer <christian.humer@gmail.com>
parents: 17191
diff changeset
454
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
455 @Override
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
456 public void reportLoopCount(int count) {
12709
d2d0c44662bb Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents: 12708
diff changeset
457 compilationProfile.reportLoopCount(count);
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
458 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
459
10862
8c570011b86f Truffle: when a node is replaced, notify optimized call target and delay compilation.
Andreas Woess <andreas.woess@jku.at>
parents: 10858
diff changeset
460 @Override
21204
4a5df5570b7f Truffle: make ReplaceObserver return a boolean in order to consume replace events. It can be useful for nodes to consume all replace events if they are always executed behind a @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 20882
diff changeset
461 public boolean nodeReplaced(Node oldNode, Node newNode, CharSequence reason) {
18275
ab4284c5b5b0 Truffle: minor cleanup
Christian Humer <christian.humer@gmail.com>
parents: 18210
diff changeset
462 CompilerAsserts.neverPartOfCompilation();
18199
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
463 if (isValid()) {
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
464 invalidate(newNode, reason);
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
465 }
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
466 /* Notify compiled method that have inlined this call target that the tree changed. */
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
467 nodeRewritingAssumption.invalidate();
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
468
12709
d2d0c44662bb Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents: 12708
diff changeset
469 compilationProfile.reportNodeReplaced();
18200
62de94d5cf73 Truffle: refactor implementation of TraceTruffleCompilation, TraceTruffleCompilationDetails into separate classes.
Christian Humer <christian.humer@gmail.com>
parents: 18199
diff changeset
470 if (cancelInstalledTask(newNode, reason)) {
18199
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
471 compilationProfile.reportInvalidated();
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
472 }
21204
4a5df5570b7f Truffle: make ReplaceObserver return a boolean in order to consume replace events. It can be useful for nodes to consume all replace events if they are always executed behind a @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents: 20882
diff changeset
473 return false;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
474 }
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
475
17399
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
476 public void accept(NodeVisitor visitor, boolean includeInlinedNodes) {
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
477 TruffleInlining inliner = getInlining();
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
478 if (includeInlinedNodes && inliner != null) {
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
479 inlining.accept(this, visitor);
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
480 } else {
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
481 getRootNode().accept(visitor);
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
482 }
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
483 }
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
484
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
485 public Stream<Node> nodeStream(boolean includeInlinedNodes) {
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
486 Iterator<Node> iterator;
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
487 TruffleInlining inliner = getInlining();
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
488 if (includeInlinedNodes && inliner != null) {
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
489 iterator = inliner.makeNodeIterator(this);
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
490 } else {
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
491 iterator = NodeUtil.makeRecursiveIterator(this.getRootNode());
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
492 }
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
493 return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0), false);
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
494 }
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
495
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: 19868
diff changeset
496 public final int getNonTrivialNodeCount() {
19759
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
497 if (cachedNonTrivialNodeCount == -1) {
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: 19868
diff changeset
498 cachedNonTrivialNodeCount = calculateNonTrivialNodes(getRootNode());
19759
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
499 }
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
500 return cachedNonTrivialNodeCount;
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
501 }
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
502
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: 19868
diff changeset
503 public static int calculateNonTrivialNodes(Node node) {
19759
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
504 NonTrivialNodeCountVisitor visitor = new NonTrivialNodeCountVisitor();
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: 19868
diff changeset
505 node.accept(visitor);
19759
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
506 return visitor.nodeCount;
18206
35639ec046d7 Truffle: extract methods from OptimizedCallUtils and remove it.
Christian Humer <christian.humer@gmail.com>
parents: 18204
diff changeset
507 }
35639ec046d7 Truffle: extract methods from OptimizedCallUtils and remove it.
Christian Humer <christian.humer@gmail.com>
parents: 18204
diff changeset
508
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
509 public Map<String, Object> getDebugProperties() {
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
510 Map<String, Object> properties = new LinkedHashMap<>();
18204
a1873eefea65 Truffle: refactor TraceTrufflePerformanceWarnings into separate class.
Christian Humer <christian.humer@gmail.com>
parents: 18200
diff changeset
511 AbstractDebugCompilationListener.addASTSizeProperty(this, properties);
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
512 properties.putAll(getCompilationProfile().getDebugProperties());
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
513 return properties;
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
514 }
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
515
17307
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
516 public static Method getCallDirectMethod() {
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
517 try {
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
518 return OptimizedCallTarget.class.getDeclaredMethod("callDirect", Object[].class);
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
519 } catch (NoSuchMethodException | SecurityException e) {
21543
93c50cefb9e8 moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21204
diff changeset
520 throw new JVMCIError(e);
17307
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
521 }
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
522 }
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
523
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
524 public static Method getCallInlinedMethod() {
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
525 try {
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
526 return OptimizedCallTarget.class.getDeclaredMethod("callInlined", Object[].class);
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
527 } catch (NoSuchMethodException | SecurityException e) {
21543
93c50cefb9e8 moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21204
diff changeset
528 throw new JVMCIError(e);
17307
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
529 }
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
530 }
4bea75e99249 Truffle: fixed callsite argument profiling was still done for inlined calls using context sensitive inlining.
Christian Humer <christian.humer@gmail.com>
parents: 17256
diff changeset
531
18386
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
532 private CompilerOptions getCompilerOptions() {
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
533 final ExecutionContext context = rootNode.getExecutionContext();
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
534
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
535 if (context == null) {
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
536 return DefaultCompilerOptions.INSTANCE;
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
537 }
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
538
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
539 return context.getCompilerOptions();
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
540 }
656331a61829 Truffle: add support for setting a couple of compiler options for individual execution contexts.
Chris Seaton <chris.seaton@oracle.com>
parents: 18276
diff changeset
541
19759
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
542 private static final class NonTrivialNodeCountVisitor implements NodeVisitor {
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
543
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
544 public int nodeCount;
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
545
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
546 public boolean visit(Node node) {
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
547 if (!node.getCost().isTrivial()) {
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
548 nodeCount++;
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
549 }
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
550 return true;
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
551 }
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
552
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
553 }
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19744
diff changeset
554
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
555 }