annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java @ 21556:48c1ebd24120

renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Wed, 27 May 2015 00:36:16 +0200
parents b1530a6cce8c
children 36cf15e3219e
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
21556
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21554
diff changeset
25 import com.oracle.jvmci.code.InstalledCode;
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21554
diff changeset
26 import com.oracle.jvmci.code.SpeculationLog;
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21554
diff changeset
27 import com.oracle.jvmci.code.BailoutException;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28 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
29
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 import java.io.*;
17310
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
31 import java.lang.reflect.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 import java.util.*;
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
33 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
34 import java.util.stream.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35
18204
a1873eefea65 Truffle: refactor TraceTrufflePerformanceWarnings into separate class.
Christian Humer <christian.humer@gmail.com>
parents: 18200
diff changeset
36 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
37 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
38 import com.oracle.jvmci.debug.*;
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.*;
15216
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
40 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
41 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
42 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
43 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
44 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
45 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
46
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 /**
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 * 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
49 */
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
50 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
51
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
52 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
53
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
54 protected final GraalTruffleRuntime runtime;
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
55 private SpeculationLog speculationLog;
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
56 protected final CompilationProfile compilationProfile;
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
57 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
58 private final OptimizedCallTarget sourceCallTarget;
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
59 private final AtomicInteger callSitesKnown = new AtomicInteger(0);
19750
2a21ea0ec141 Profile exceptions on OptimizeCallTarget#doInvoke.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19710
diff changeset
60 private final ValueProfile exceptionProfile = ValueProfile.createClassProfile();
18276
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents: 18275
diff changeset
61
15231
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
62 @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
63 @CompilationFinal private Assumption profiledArgumentTypesAssumption;
15216
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
64 @CompilationFinal private Class<?> profiledReturnType;
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
65 @CompilationFinal private Assumption profiledReturnTypeAssumption;
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
66
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
67 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
68 private final RootNode rootNode;
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
69
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
70 /* Experimental fields for new splitting. */
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
71 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
72 private TruffleStamp argumentStamp = DefaultTruffleStamp.getInstance();
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
73
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
74 private TruffleInlining inlining;
19766
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
75 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
76 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
77
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
78 /**
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 * 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
80 * 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
81 * 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
82 */
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
83 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
84
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
85 public final RootNode getRootNode() {
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
86 return rootNode;
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
87 }
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
88
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 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
90 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
91 this.sourceCallTarget = sourceCallTarget;
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
92 this.runtime = runtime;
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
93 this.speculationLog = speculationLog;
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
94 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
95 this.compilationPolicy = compilationPolicy;
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
96 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
97 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
98 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
99 if (TruffleCallTargetProfiling.getValue()) {
17420
e98150919577 Truffle: cleanup compilation profile fields.
Christian Humer <christian.humer@gmail.com>
parents: 17404
diff changeset
100 this.compilationProfile = new TraceCompilationProfile();
17404
b725292b8a11 Truffle: updated TruffleCallTargetProfiling
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
101 } else {
17420
e98150919577 Truffle: cleanup compilation profile fields.
Christian Humer <christian.humer@gmail.com>
parents: 17404
diff changeset
102 this.compilationProfile = new CompilationProfile();
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
103 }
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
104 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
105 }
6388d789b1d0 Invalidate all compiled methods that have a call target inlined on tree rewriting.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17598
diff changeset
106
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
107 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
108 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
109 }
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
110
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
111 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
112 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
113 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
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 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
116 }
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
117
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
118 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
119 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
120 }
13703
03b42f0fb635 Truffle: extend inlining interface with custom reprofile counters.
Christian Humer <christian.humer@gmail.com>
parents: 13208
diff changeset
121
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
122 public final void mergeArgumentStamp(TruffleStamp p) {
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
123 this.argumentStamp = this.argumentStamp.join(p);
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
124 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
125
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
126 public final TruffleStamp getArgumentStamp() {
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
127 return argumentStamp;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
128 }
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 private int cloneIndex;
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
131
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
132 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
133 return cloneIndex;
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
134 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
135
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
136 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
137 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
138 if (copiedRoot == null) {
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
139 return null;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
140 }
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
141 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
142 splitTarget.cloneIndex = cloneIndex++;
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
143 return splitTarget;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
144 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
145
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
146 public Map<TruffleStamp, OptimizedCallTarget> getSplitVersions() {
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
147 return splitVersions;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
148 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
149
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
150 public SpeculationLog getSpeculationLog() {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
151 return speculationLog;
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
152 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
153
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
154 @Override
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
155 public Object call(Object... args) {
17404
b725292b8a11 Truffle: updated TruffleCallTargetProfiling
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
156 compilationProfile.reportIndirectCall();
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
157 if (profiledArgumentTypesAssumption != null && profiledArgumentTypesAssumption.isValid()) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
158 CompilerDirectives.transferToInterpreterAndInvalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
159 profiledArgumentTypesAssumption.invalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
160 profiledArgumentTypes = null;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
161 }
17191
be733832464d Allow subclasses to intercept Truffle call boundaries
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17152
diff changeset
162 return doInvoke(args);
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
163 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
164
17310
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
165 public final Object callDirect(Object... args) {
17404
b725292b8a11 Truffle: updated TruffleCallTargetProfiling
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
166 compilationProfile.reportDirectCall();
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
167 profileArguments(args);
20882
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
168 try {
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
169 Object result = doInvoke(args);
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
170 Class<?> klass = profiledReturnType;
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
171 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
172 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
173 }
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
174 return result;
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
175 } catch (Throwable t) {
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
176 t = exceptionProfile.profile(t);
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
177 if (t instanceof RuntimeException) {
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
178 throw (RuntimeException) t;
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
179 } else if (t instanceof Error) {
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
180 throw (Error) t;
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
181 } else {
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
182 throw new RuntimeException(t);
e0b3dc6b025c Truffle: profile exception type only for direct calls
Andreas Woess <andreas.woess@oracle.com>
parents: 20132
diff changeset
183 }
15224
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
184 }
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
185 }
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
186
17310
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 public final Object callInlined(Object... arguments) {
17404
b725292b8a11 Truffle: updated TruffleCallTargetProfiling
Christian Humer <christian.humer@gmail.com>
parents: 17400
diff changeset
188 compilationProfile.reportInlinedCall();
17310
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 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
190 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
191 }
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
192
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
193 @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
194 void profileArguments(Object[] args) {
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
195 if (profiledArgumentTypesAssumption == null) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
196 CompilerDirectives.transferToInterpreterAndInvalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
197 initializeProfiledArgumentTypes(args);
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
198 } else if (profiledArgumentTypes != null) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
199 if (profiledArgumentTypes.length != args.length) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
200 CompilerDirectives.transferToInterpreterAndInvalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
201 profiledArgumentTypesAssumption.invalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
202 profiledArgumentTypes = null;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
203 } else if (TruffleArgumentTypeSpeculation.getValue() && profiledArgumentTypesAssumption.isValid()) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
204 for (int i = 0; i < profiledArgumentTypes.length; i++) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
205 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
206 CompilerDirectives.transferToInterpreterAndInvalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
207 updateProfiledArgumentTypes(args);
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
208 break;
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 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
214
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
215 private void initializeProfiledArgumentTypes(Object[] args) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
216 CompilerAsserts.neverPartOfCompilation();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
217 profiledArgumentTypesAssumption = Truffle.getRuntime().createAssumption("Profiled Argument Types");
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
218 profiledArgumentTypes = new Class<?>[args.length];
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
219 if (TruffleArgumentTypeSpeculation.getValue()) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
220 for (int i = 0; i < args.length; i++) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
221 profiledArgumentTypes[i] = classOf(args[i]);
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 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
225
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
226 private void updateProfiledArgumentTypes(Object[] args) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
227 CompilerAsserts.neverPartOfCompilation();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
228 profiledArgumentTypesAssumption.invalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
229 for (int j = 0; j < profiledArgumentTypes.length; j++) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
230 profiledArgumentTypes[j] = joinTypes(profiledArgumentTypes[j], classOf(args[j]));
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 profiledArgumentTypesAssumption = Truffle.getRuntime().createAssumption("Profiled Argument Types");
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
233 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
234
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
235 private static Class<?> classOf(Object arg) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
236 return arg != null ? arg.getClass() : null;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
237 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
238
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
239 private static Class<?> joinTypes(Class<?> class1, Class<?> class2) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
240 if (class1 == class2) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
241 return class1;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
242 } else if (class1 == null || class2 == null) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
243 return null;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
244 } else if (class1.isAssignableFrom(class2)) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
245 return class1;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
246 } else if (class2.isAssignableFrom(class1)) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
247 return class2;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
248 } else {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
249 return Object.class;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
250 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
251 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
252
17191
be733832464d Allow subclasses to intercept Truffle call boundaries
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17152
diff changeset
253 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
254 return callBoundary(args);
17191
be733832464d Allow subclasses to intercept Truffle call boundaries
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17152
diff changeset
255 }
be733832464d Allow subclasses to intercept Truffle call boundaries
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17152
diff changeset
256
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
257 @TruffleCallBoundary
17191
be733832464d Allow subclasses to intercept Truffle call boundaries
Christian Wimmer <christian.wimmer@oracle.com>
parents: 17152
diff changeset
258 protected final Object callBoundary(Object[] args) {
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
259 if (CompilerDirectives.inInterpreter()) {
15215
ca250afc78ec Simplification of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15212
diff changeset
260 // 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
261 interpreterCall();
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
262 } else {
18276
1f3ab088d958 Truffle: implemented defer compilation.
Christian Humer <christian.humer@gmail.com>
parents: 18275
diff changeset
263 // We come here from compiled code
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
264 }
15216
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
265
17427
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
266 return callRoot(args);
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
267 }
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
268
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
269 public final Object callRoot(Object[] originalArguments) {
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
270 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
271 if (this.profiledArgumentTypesAssumption != null && CompilerDirectives.inCompiledCode() && profiledArgumentTypesAssumption.isValid()) {
19456
3e5c4e59c586 Correctly create IsCompilationConstantNode in FastPE mode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19441
diff changeset
272 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
273 if (TruffleArgumentTypeSpeculation.getValue()) {
17427
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
274 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
275 }
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
276 }
17427
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
277
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
278 VirtualFrame frame = createFrame(getRootNode().getFrameDescriptor(), args);
17310
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
279 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
280
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
281 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
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 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
284 }
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
285
c7c799f40c1e Truffle: cache compiling flag in OptimizedCallTarget to speed up check in the interpreter;
Christian Humer <christian.humer@gmail.com>
parents: 19978
diff changeset
286 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
287 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
288 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
289 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
290 profiledReturnType = (result == null ? null : result.getClass());
17427
307b26f8b5d1 Truffle: fixed inlining performance regression.
Christian Humer <christian.humer@gmail.com>
parents: 17426
diff changeset
291 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
292 }
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 } 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
294 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
295 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
296 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
297 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
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 }
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
300 }
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
301
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
302 @Override
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
303 public void invalidate() {
18199
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
304 invalidate(null, null);
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
305 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
306
18798
f1e7e4f6d833 Truffle: improve invalidation messages for assumptions.
Christian Humer <christian.humer@gmail.com>
parents: 18485
diff changeset
307 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
308 if (isValid()) {
84e270aa1f47 Truffle: fixed invalidations were printed multiple times.
Christian Humer <christian.humer@gmail.com>
parents: 18206
diff changeset
309 this.runtime.invalidateInstalledCode(this, source, reason);
84e270aa1f47 Truffle: fixed invalidations were printed multiple times.
Christian Humer <christian.humer@gmail.com>
parents: 18206
diff changeset
310 }
19766
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
311 cachedNonTrivialNodeCount = -1;
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
312 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
313
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
314 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
315 return inlining;
16044
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
316 }
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
317
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
318 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
319 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
320 }
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
321
18200
62de94d5cf73 Truffle: refactor implementation of TraceTruffleCompilation, TraceTruffleCompilationDetails into separate classes.
Christian Humer <christian.humer@gmail.com>
parents: 18199
diff changeset
322 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
323 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
324 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
325
15215
ca250afc78ec Simplification of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15212
diff changeset
326 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
327 if (isValid()) {
15222
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
328 // Stubs were deoptimized => reinstall.
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
329 this.runtime.reinstallStubs();
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
330 } else {
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
331 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
332 if (!isCompiling() && compilationPolicy.shouldCompile(compilationProfile, getCompilerOptions())) {
15222
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
333 compile();
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
334 }
15212
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 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
337
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
338 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
339 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
340 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
341 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
342 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
343 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
344
18198
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
345 public void notifyCompilationFailed(Throwable t) {
19875
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19766
diff changeset
346 if (t instanceof BailoutException && !((BailoutException) t).isPermanent()) {
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19766
diff changeset
347 /*
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19766
diff changeset
348 * 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: 19766
diff changeset
349 * 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: 19766
diff changeset
350 * 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: 19766
diff changeset
351 * failure state.
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19766
diff changeset
352 */
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19766
diff changeset
353 } else {
18198
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
354 compilationPolicy.recordCompilationFailure(t);
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
355 if (TruffleCompilationExceptionsAreThrown.getValue()) {
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
356 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
357 }
19875
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19766
diff changeset
358 if (TruffleCompilationExceptionsAreFatal.getValue()) {
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19766
diff changeset
359 t.printStackTrace(OUT);
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19766
diff changeset
360 System.exit(-1);
f803f49c9ec4 Truffle: fixed TruffleCompilationExceptionsAreThrown was ignored for non permanent bailouts.
Christian Humer <christian.humer@oracle.com>
parents: 19766
diff changeset
361 }
18198
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
362 }
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
363 }
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
364
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
365 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
366 if (successful && inlining != null) {
18198
d7e40b20b030 Truffle: refactor notifications in OptimizedCallTarget.
Christian Humer <christian.humer@gmail.com>
parents: 18162
diff changeset
367 dequeueInlinedCallSites(inlining);
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
368 }
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
369 compiling = false;
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
370 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
371
17400
e3dd05527c2f Truffle: enabled context sensitive inlining by default. removed old inlining structures.
Christian Humer <christian.humer@gmail.com>
parents: 17399
diff changeset
372 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
373 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
374 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
375 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
376 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
377 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
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 }
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
380 }
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
381
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
382 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
383 try {
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
384 return getRootNode().execute(frame);
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
385 } finally {
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
386 // 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
387 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
388 }
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
389 }
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
390
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
391 public final int getKnownCallSiteCount() {
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
392 return callSitesKnown.get();
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
393 }
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
394
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
395 public final void incrementKnownCallSites() {
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
396 callSitesKnown.incrementAndGet();
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
397 }
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
398
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
399 public final void decrementKnownCallSites() {
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
400 callSitesKnown.decrementAndGet();
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
401 }
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
402
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
403 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
404 return sourceCallTarget;
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
405 }
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
406
13984
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
407 @Override
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
408 public String toString() {
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
409 String superString = rootNode.toString();
15168
78530cbd8940 Truffle: Make OptimizedCallTarget itself an InstalledCode object.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15167
diff changeset
410 if (isValid()) {
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
411 superString += " <opt>";
13984
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
412 }
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
413 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
414 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
415 }
13984
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
416 return superString;
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
417 }
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
418
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
419 public CompilationProfile getCompilationProfile() {
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
420 return compilationProfile;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
421 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
422
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
423 @ExplodeLoop
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
424 private Object[] castArguments(Object[] originalArguments) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
425 Object[] castArguments = new Object[profiledArgumentTypes.length];
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
426 for (int i = 0; i < profiledArgumentTypes.length; i++) {
19456
3e5c4e59c586 Correctly create IsCompilationConstantNode in FastPE mode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19441
diff changeset
427 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
428 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
429 return castArguments;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
430 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
431
15231
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
432 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
433 return args;
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
434 }
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
435
19441
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18950
diff changeset
436 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
437 if (TruffleCompilerOptions.TruffleUseFrameWithoutBoxing.getValue()) {
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18950
diff changeset
438 return new FrameWithoutBoxing(descriptor, args);
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18950
diff changeset
439 } else {
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18950
diff changeset
440 return new FrameWithBoxing(descriptor, args);
2e91c189b0d8 Introduce option TruffleUseFrameWithoutBoxing, default to true.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18950
diff changeset
441 }
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
442 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
443
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
444 public List<OptimizedDirectCallNode> getCallNodes() {
20132
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
445 final List<OptimizedDirectCallNode> callNodes = new ArrayList<>();
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
446 getRootNode().accept(new NodeVisitor() {
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
447 public boolean visit(Node node) {
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
448 if (node instanceof OptimizedDirectCallNode) {
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
449 callNodes.add((OptimizedDirectCallNode) node);
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 return true;
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
452 }
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
453 });
b91ba8932cb6 Truffle: use visitor for getCallNodes.
Christian Humer <christian.humer@gmail.com>
parents: 20095
diff changeset
454 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
455 }
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
456
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
457 @Override
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
458 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
459 compilationProfile.reportLoopCount(count);
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
460 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
461
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
462 @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
463 public boolean nodeReplaced(Node oldNode, Node newNode, CharSequence reason) {
18275
ab4284c5b5b0 Truffle: minor cleanup
Christian Humer <christian.humer@gmail.com>
parents: 18210
diff changeset
464 CompilerAsserts.neverPartOfCompilation();
18199
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
465 if (isValid()) {
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
466 invalidate(newNode, reason);
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
467 }
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
468 /* 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
469 nodeRewritingAssumption.invalidate();
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
470
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
471 compilationProfile.reportNodeReplaced();
18200
62de94d5cf73 Truffle: refactor implementation of TraceTruffleCompilation, TraceTruffleCompilationDetails into separate classes.
Christian Humer <christian.humer@gmail.com>
parents: 18199
diff changeset
472 if (cancelInstalledTask(newNode, reason)) {
18199
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
473 compilationProfile.reportInvalidated();
c5c80abc3fc6 Truffle: add support for a CompilationListener in GraalTruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents: 18198
diff changeset
474 }
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
475 return false;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
476 }
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
477
17399
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
478 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
479 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
480 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
481 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
482 } else {
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
483 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
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 }
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
486
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
487 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
488 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
489 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
490 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
491 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
492 } else {
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
493 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
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 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
496 }
5787218bad91 Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents: 17341
diff changeset
497
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: 19875
diff changeset
498 public final int getNonTrivialNodeCount() {
19766
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
499 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: 19875
diff changeset
500 cachedNonTrivialNodeCount = calculateNonTrivialNodes(getRootNode());
19766
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
501 }
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
502 return cachedNonTrivialNodeCount;
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
503 }
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
504
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: 19875
diff changeset
505 public static int calculateNonTrivialNodes(Node node) {
19766
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
506 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: 19875
diff changeset
507 node.accept(visitor);
19766
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
508 return visitor.nodeCount;
18206
35639ec046d7 Truffle: extract methods from OptimizedCallUtils and remove it.
Christian Humer <christian.humer@gmail.com>
parents: 18204
diff changeset
509 }
35639ec046d7 Truffle: extract methods from OptimizedCallUtils and remove it.
Christian Humer <christian.humer@gmail.com>
parents: 18204
diff changeset
510
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
511 public Map<String, Object> getDebugProperties() {
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
512 Map<String, Object> properties = new LinkedHashMap<>();
18204
a1873eefea65 Truffle: refactor TraceTrufflePerformanceWarnings into separate class.
Christian Humer <christian.humer@gmail.com>
parents: 18200
diff changeset
513 AbstractDebugCompilationListener.addASTSizeProperty(this, properties);
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
514 properties.putAll(getCompilationProfile().getDebugProperties());
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
515 return properties;
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
516 }
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
517
17310
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 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
519 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
520 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
521 } 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
522 throw new JVMCIError(e);
17310
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 }
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
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 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
527 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
528 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
529 } 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
530 throw new JVMCIError(e);
17310
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 }
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
532 }
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
533
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
534 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
535 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
536
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 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
538 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
539 }
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 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
542 }
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
543
19766
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
544 private static final class NonTrivialNodeCountVisitor implements NodeVisitor {
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
545
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
546 public int nodeCount;
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
547
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
548 public boolean visit(Node node) {
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
549 if (!node.getCost().isTrivial()) {
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
550 nodeCount++;
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
551 }
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
552 return true;
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
553 }
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
554
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
555 }
39315508f1b6 Truffle: cache trivial node counts per call target.
Christian Humer <christian.humer@gmail.com>
parents: 19751
diff changeset
556
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
557 }