annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java @ 16711:c68da2397fcb

Truffle: temporarily disable inlining invalidations
author Andreas Woess <andreas.woess@jku.at>
date Wed, 06 Aug 2014 14:52:41 +0200
parents f2a4042d9787
children 81eb0d77e9f9
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 /*
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
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
15090
07e7aae05983 Truffle: context sensitive inlining cleanup
Christian Humer <christian.humer@gmail.com>
parents: 15089
diff changeset
25 import static com.oracle.graal.truffle.OptimizedCallTargetLog.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26 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
27
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28 import java.io.*;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 import java.util.*;
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
30 import java.util.concurrent.atomic.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.api.code.*;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.debug.*;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 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
35 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
36 import com.oracle.truffle.api.frame.*;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 import com.oracle.truffle.api.nodes.*;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 /**
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 * 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
41 */
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
42 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
43
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
44 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
45
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
46 protected final GraalTruffleRuntime runtime;
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
47 private SpeculationLog speculationLog;
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
48 protected int callCount;
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
49 protected boolean inliningPerformed;
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
50 protected final CompilationProfile compilationProfile;
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
51 protected final CompilationPolicy compilationPolicy;
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
52 private OptimizedCallTarget splitSource;
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
53 private final AtomicInteger callSitesKnown = new AtomicInteger(0);
15231
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
54 @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
55 @CompilationFinal private Assumption profiledArgumentTypesAssumption;
15216
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
56 @CompilationFinal private Class<?> profiledReturnType;
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
57 @CompilationFinal private Assumption profiledReturnTypeAssumption;
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
58
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
59 private final RootNode rootNode;
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
60
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
61 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
62 private TruffleStamp argumentStamp = DefaultTruffleStamp.getInstance();
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
63
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
64 public final RootNode getRootNode() {
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
65 return rootNode;
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
66 }
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
67
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
68 public OptimizedCallTarget(RootNode rootNode, GraalTruffleRuntime runtime, int invokeCounter, int compilationThreshold, 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
69 super(rootNode.toString());
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
70 this.runtime = runtime;
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
71 this.speculationLog = speculationLog;
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
72 this.rootNode = rootNode;
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
73 this.rootNode.adoptChildren();
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
74 this.rootNode.setCallTarget(this);
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
75 this.compilationPolicy = compilationPolicy;
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
76 this.compilationProfile = new CompilationProfile(compilationThreshold, invokeCounter);
10844
3cf5f371dc9f Truffle: print inlined call target and rename profiling option.
Andreas Woess <andreas.woess@jku.at>
parents: 10797
diff changeset
77 if (TruffleCallTargetProfiling.getValue()) {
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
78 registerCallTarget(this);
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
79 }
13984
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
80 }
13703
03b42f0fb635 Truffle: extend inlining interface with custom reprofile counters.
Christian Humer <christian.humer@gmail.com>
parents: 13208
diff changeset
81
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
82 public final void mergeArgumentStamp(TruffleStamp p) {
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
83 this.argumentStamp = this.argumentStamp.join(p);
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
84 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
85
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
86 public final TruffleStamp getArgumentStamp() {
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
87 return argumentStamp;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
88 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
89
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
90 private int splitIndex;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
91
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
92 public int getSplitIndex() {
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
93 return splitIndex;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
94 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
95
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
96 public OptimizedCallTarget split() {
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
97 if (!getRootNode().isSplittable()) {
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
98 return null;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
99 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
100 OptimizedCallTarget splitTarget = (OptimizedCallTarget) Truffle.getRuntime().createCallTarget(getRootNode().split());
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
101 splitTarget.splitSource = this;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
102 splitTarget.splitIndex = splitIndex++;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
103 return splitTarget;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
104 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
105
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
106 public Map<TruffleStamp, OptimizedCallTarget> getSplitVersions() {
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
107 return splitVersions;
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
108 }
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
109
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
110 public SpeculationLog getSpeculationLog() {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
111 return speculationLog;
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
112 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
113
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
114 @Override
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
115 public Object call(Object... args) {
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
116 if (profiledArgumentTypesAssumption != null && profiledArgumentTypesAssumption.isValid()) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
117 CompilerDirectives.transferToInterpreterAndInvalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
118 profiledArgumentTypesAssumption.invalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
119 profiledArgumentTypes = null;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
120 }
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
121 return callBoundary(args);
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
122 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
123
15224
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
124 public Object callDirect(Object... args) {
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
125 profileArguments(args);
15224
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
126 Object result = callBoundary(args);
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
127 Class<?> klass = profiledReturnType;
15231
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
128 if (klass != null && CompilerDirectives.inCompiledCode() && profiledReturnTypeAssumption.isValid()) {
15224
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
129 result = CompilerDirectives.unsafeCast(result, klass, true, true);
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
130 }
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
131 return result;
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
132 }
735147ef0176 Truffle: Move direct call logic from call site to optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15222
diff changeset
133
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
134 @ExplodeLoop
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
135 private void profileArguments(Object[] args) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
136 if (profiledArgumentTypesAssumption == null) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
137 CompilerDirectives.transferToInterpreterAndInvalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
138 initializeProfiledArgumentTypes(args);
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
139 } else if (profiledArgumentTypes != null) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
140 if (profiledArgumentTypes.length != args.length) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
141 CompilerDirectives.transferToInterpreterAndInvalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
142 profiledArgumentTypesAssumption.invalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
143 profiledArgumentTypes = null;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
144 } else if (TruffleArgumentTypeSpeculation.getValue() && profiledArgumentTypesAssumption.isValid()) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
145 for (int i = 0; i < profiledArgumentTypes.length; i++) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
146 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
147 CompilerDirectives.transferToInterpreterAndInvalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
148 updateProfiledArgumentTypes(args);
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
149 break;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
150 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
151 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
152 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
153 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
154 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
155
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
156 private void initializeProfiledArgumentTypes(Object[] args) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
157 CompilerAsserts.neverPartOfCompilation();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
158 profiledArgumentTypesAssumption = Truffle.getRuntime().createAssumption("Profiled Argument Types");
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
159 profiledArgumentTypes = new Class<?>[args.length];
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
160 if (TruffleArgumentTypeSpeculation.getValue()) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
161 for (int i = 0; i < args.length; i++) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
162 profiledArgumentTypes[i] = classOf(args[i]);
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
163 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
164 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
165 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
166
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
167 private void updateProfiledArgumentTypes(Object[] args) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
168 CompilerAsserts.neverPartOfCompilation();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
169 profiledArgumentTypesAssumption.invalidate();
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
170 for (int j = 0; j < profiledArgumentTypes.length; j++) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
171 profiledArgumentTypes[j] = joinTypes(profiledArgumentTypes[j], classOf(args[j]));
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
172 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
173 profiledArgumentTypesAssumption = Truffle.getRuntime().createAssumption("Profiled Argument Types");
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
174 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
175
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
176 private static Class<?> classOf(Object arg) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
177 return arg != null ? arg.getClass() : null;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
178 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
179
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
180 private static Class<?> joinTypes(Class<?> class1, Class<?> class2) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
181 if (class1 == class2) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
182 return class1;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
183 } else if (class1 == null || class2 == null) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
184 return null;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
185 } else if (class1.isAssignableFrom(class2)) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
186 return class1;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
187 } else if (class2.isAssignableFrom(class1)) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
188 return class2;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
189 } else {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
190 return Object.class;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
191 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
192 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
193
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
194 @TruffleCallBoundary
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
195 private Object callBoundary(Object[] args) {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
196 if (CompilerDirectives.inInterpreter()) {
15215
ca250afc78ec Simplification of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15212
diff changeset
197 // 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
198 interpreterCall();
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
199 } else {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
200 // We come here from compiled code (i.e., we have been inlined).
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
201 }
15216
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
202
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
203 return callRoot(args);
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
204 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
205
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
206 @Override
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
207 public void invalidate() {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
208 this.runtime.invalidateInstalledCode(this);
16044
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
209 invalidateInlining();
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
210 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
211
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
212 protected void invalidate(Node oldNode, Node newNode, CharSequence reason) {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
213 if (isValid()) {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
214 CompilerAsserts.neverPartOfCompilation();
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
215 invalidate();
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
216 compilationProfile.reportInvalidated();
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
217 logOptimizedInvalidated(this, oldNode, newNode, reason);
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
218 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
219 cancelInstalledTask(oldNode, newNode, reason);
16711
c68da2397fcb Truffle: temporarily disable inlining invalidations
Andreas Woess <andreas.woess@jku.at>
parents: 16558
diff changeset
220 // invalidateInlining();
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
221 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
222
16044
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
223 public void invalidateInlining() {
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
224 if (inliningPerformed) {
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
225 inliningPerformed = false;
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
226 getRootNode().accept(new NodeVisitor() {
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
227 public boolean visit(Node node) {
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
228 if (node instanceof OptimizedDirectCallNode) {
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
229 OptimizedDirectCallNode callNode = (OptimizedDirectCallNode) node;
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
230 if (callNode.isInlined()) {
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
231 callNode.resetInlining();
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
232 }
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
233 }
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
234 return true;
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
235 }
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
236 });
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
237 }
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
238 }
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
239
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
240 private void cancelInstalledTask(Node oldNode, Node newNode, CharSequence reason) {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
241 if (this.runtime.cancelInstalledTask(this)) {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
242 logOptimizingUnqueued(this, oldNode, newNode, reason);
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
243 compilationProfile.reportInvalidated();
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
244 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
245 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
246
15215
ca250afc78ec Simplification of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15212
diff changeset
247 private void interpreterCall() {
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
248 CompilerAsserts.neverPartOfCompilation();
15222
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
249 if (this.isValid()) {
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
250 // Stubs were deoptimized => reinstall.
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
251 this.runtime.reinstallStubs();
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
252 } else {
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
253 compilationProfile.reportInterpreterCall();
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
254 if (TruffleCallTargetProfiling.getValue()) {
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
255 callCount++;
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
256 }
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
257 if (compilationPolicy.shouldCompile(compilationProfile)) {
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
258 compile();
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
259 }
15212
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
260 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
261 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
262
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
263 public void compile() {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
264 if (!runtime.isCompiling(this)) {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
265 performInlining();
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
266 logOptimizingQueued(this);
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
267 runtime.compile(this, TruffleBackgroundCompilation.getValue());
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
268 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
269 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
270
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
271 public void compilationFinished(Throwable t) {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
272 if (t == null) {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
273 // Compilation was successful.
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
274 } else {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
275 compilationPolicy.recordCompilationFailure(t);
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
276 logOptimizingFailed(this, t.getMessage());
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
277 if (t instanceof BailoutException) {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
278 // Bailout => move on.
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
279 } else {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
280 if (TruffleCompilationExceptionsAreFatal.getValue()) {
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
281 t.printStackTrace(OUT);
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
282 System.exit(-1);
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
283 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
284 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
285 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
286 }
ea9d5b6044af Remove runtime-specific optimized call target.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15211
diff changeset
287
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
288 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
289 try {
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
290 return getRootNode().execute(frame);
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
291 } finally {
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
292 // 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
293 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
294 }
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
295 }
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
296
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
297 public final int getKnownCallSiteCount() {
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
298 return callSitesKnown.get();
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
299 }
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
300
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
301 public final void incrementKnownCallSites() {
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
302 callSitesKnown.incrementAndGet();
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
303 }
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
304
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
305 public final void decrementKnownCallSites() {
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
306 callSitesKnown.decrementAndGet();
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
307 }
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
308
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
309 public final OptimizedCallTarget getSplitSource() {
14073
c5411233cdf8 Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
Christian Humer <christian.humer@gmail.com>
parents: 13996
diff changeset
310 return splitSource;
c5411233cdf8 Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
Christian Humer <christian.humer@gmail.com>
parents: 13996
diff changeset
311 }
c5411233cdf8 Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
Christian Humer <christian.humer@gmail.com>
parents: 13996
diff changeset
312
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
313 public final void setSplitSource(OptimizedCallTarget splitSource) {
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
314 this.splitSource = splitSource;
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
315 }
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
316
13984
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
317 @Override
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
318 public String toString() {
15167
258e3e0b5e2e Change RootCallTarget from an abstract class into an interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15162
diff changeset
319 String superString = rootNode.toString();
15168
78530cbd8940 Truffle: Make OptimizedCallTarget itself an InstalledCode object.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15167
diff changeset
320 if (isValid()) {
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
321 superString += " <opt>";
13984
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
322 }
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
323 if (splitSource != null) {
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
324 superString += " <split-" + splitIndex + "-" + argumentStamp.toStringShort() + ">";
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
325 }
13984
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
326 return superString;
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
327 }
1c9dbfc5b510 Truffle: New more reliable inlining strategy for the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
328
14866
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
329 public CompilationProfile getCompilationProfile() {
a0185cd77565 Truffle: refactor ompilation related classes for SubstrateVM
Erik Eckstein <erik.eckstein@oracle.com>
parents: 14715
diff changeset
330 return compilationProfile;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
331 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
332
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14984
diff changeset
333 public final Object callInlined(Object[] arguments) {
14715
4ea4db3f23ba Truffle: fixed call count profile; added leaf check for inlining; inline tracing now shows dispatched calls.
Christian Humer <christian.humer@gmail.com>
parents: 14618
diff changeset
334 if (CompilerDirectives.inInterpreter()) {
4ea4db3f23ba Truffle: fixed call count profile; added leaf check for inlining; inline tracing now shows dispatched calls.
Christian Humer <christian.humer@gmail.com>
parents: 14618
diff changeset
335 compilationProfile.reportInlinedCall();
4ea4db3f23ba Truffle: fixed call count profile; added leaf check for inlining; inline tracing now shows dispatched calls.
Christian Humer <christian.humer@gmail.com>
parents: 14618
diff changeset
336 }
15216
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
337 VirtualFrame frame = createFrame(getRootNode().getFrameDescriptor(), arguments);
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
338 return callProxy(frame);
14715
4ea4db3f23ba Truffle: fixed call count profile; added leaf check for inlining; inline tracing now shows dispatched calls.
Christian Humer <christian.humer@gmail.com>
parents: 14618
diff changeset
339 }
4ea4db3f23ba Truffle: fixed call count profile; added leaf check for inlining; inline tracing now shows dispatched calls.
Christian Humer <christian.humer@gmail.com>
parents: 14618
diff changeset
340
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
341 public final void performInlining() {
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
342 if (!TruffleFunctionInlining.getValue()) {
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
343 return;
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
344 }
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
345 if (inliningPerformed) {
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
346 return;
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
347 }
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
348 TruffleInliningHandler handler = new TruffleInliningHandler(new DefaultInliningPolicy());
16044
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
349 TruffleInliningDecision result = handler.decideInlining(this, 0);
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
350 performInlining(result);
15090
07e7aae05983 Truffle: context sensitive inlining cleanup
Christian Humer <christian.humer@gmail.com>
parents: 15089
diff changeset
351 logInliningDecision(result);
12711
fb4658e16b5d Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents: 12710
diff changeset
352 }
12592
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
353
16044
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
354 private static void performInlining(TruffleInliningDecision result) {
15339
265c47be2308 Truffle: fix inlining recursions
Christian Humer <christian.humer@gmail.com>
parents: 15312
diff changeset
355 if (result.getCallTarget().inliningPerformed) {
265c47be2308 Truffle: fix inlining recursions
Christian Humer <christian.humer@gmail.com>
parents: 15312
diff changeset
356 return;
265c47be2308 Truffle: fix inlining recursions
Christian Humer <christian.humer@gmail.com>
parents: 15312
diff changeset
357 }
265c47be2308 Truffle: fix inlining recursions
Christian Humer <christian.humer@gmail.com>
parents: 15312
diff changeset
358 result.getCallTarget().inliningPerformed = true;
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
359 for (TruffleInliningProfile profile : result) {
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
360 profile.getCallNode().inline();
16044
2662fb9c37e2 Truffle: invalidate inlining decisions on rewrites.
Christian Humer <christian.humer@gmail.com>
parents: 15396
diff changeset
361 TruffleInliningDecision recursiveResult = profile.getRecursiveResult();
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
362 if (recursiveResult != null) {
15312
7f5c9079e24a Truffle: fixes to the inlining heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 15231
diff changeset
363 performInlining(recursiveResult);
14983
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
364 }
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
365 }
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
366 }
a31d807757ee Truffle: made inlining fully context sensitive.
Christian Humer <christian.humer@gmail.com>
parents: 14911
diff changeset
367
15231
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
368 public final Object callRoot(Object[] originalArguments) {
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
369 Object[] args = originalArguments;
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
370 if (this.profiledArgumentTypesAssumption != null && CompilerDirectives.inCompiledCode() && profiledArgumentTypesAssumption.isValid()) {
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
371 args = CompilerDirectives.unsafeCast(castArrayFixedLength(args, profiledArgumentTypes.length), Object[].class, true, true);
16472
83dce5b6cb41 Truffle: remove needless null check
Andreas Woess <andreas.woess@jku.at>
parents: 16470
diff changeset
372 if (TruffleArgumentTypeSpeculation.getValue()) {
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
373 args = castArguments(args);
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
374 }
15231
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
375 }
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
376
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14984
diff changeset
377 VirtualFrame frame = createFrame(getRootNode().getFrameDescriptor(), args);
15216
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
378 Object result = callProxy(frame);
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
379
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
380 // Profile call return type
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
381 if (profiledReturnTypeAssumption == null) {
15222
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
382 if (TruffleReturnTypeSpeculation.getValue()) {
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
383 CompilerDirectives.transferToInterpreterAndInvalidate();
15395
2a8628bc6c10 Truffle: Allow null as a possible return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15231
diff changeset
384 profiledReturnType = (result == null ? null : result.getClass());
15222
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
385 profiledReturnTypeAssumption = Truffle.getRuntime().createAssumption("Profiled Return Type");
58d2c5bdb9cd Truffle: Add option TruffleReturnTypeSpeculation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15216
diff changeset
386 }
15216
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
387 } else if (profiledReturnType != null) {
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
388 if (result == null || profiledReturnType != result.getClass()) {
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
389 CompilerDirectives.transferToInterpreterAndInvalidate();
15216
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
390 profiledReturnType = null;
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
391 profiledReturnTypeAssumption.invalidate();
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
392 }
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
393 }
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
394
d59f48be0ed6 Truffle: Speculate on the return type of calls.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15215
diff changeset
395 return result;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
396 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
397
16470
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
398 @ExplodeLoop
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
399 private Object[] castArguments(Object[] originalArguments) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
400 Object[] castArguments = new Object[profiledArgumentTypes.length];
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
401 for (int i = 0; i < profiledArgumentTypes.length; i++) {
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
402 castArguments[i] = profiledArgumentTypes[i] != null ? CompilerDirectives.unsafeCast(originalArguments[i], profiledArgumentTypes[i], true, true) : originalArguments[i];
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
403 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
404 return castArguments;
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
405 }
efbf9195dfcb Truffle: add argument type speculation
Andreas Woess <andreas.woess@jku.at>
parents: 16410
diff changeset
406
15231
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
407 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
408 return args;
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
409 }
babe13eb6118 Truffle: Speculate on the exact length of the arguments array.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15224
diff changeset
410
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14984
diff changeset
411 public static FrameWithoutBoxing createFrame(FrameDescriptor descriptor, Object[] args) {
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14984
diff changeset
412 return new FrameWithoutBoxing(descriptor, args);
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
413 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
414
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
415 @Override
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
416 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
417 compilationProfile.reportLoopCount(count);
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
418 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
419
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
420 @Override
14584
6189c1983cd3 Truffle: make Node#replace accept any CharSequence as reason
Andreas Woess <andreas.woess@jku.at>
parents: 14569
diff changeset
421 public void nodeReplaced(Node oldNode, Node newNode, CharSequence reason) {
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
422 compilationProfile.reportNodeReplaced();
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
423 invalidate(oldNode, newNode, reason);
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
424 }
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
425
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
426 public Map<String, Object> getDebugProperties() {
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
427 Map<String, Object> properties = new LinkedHashMap<>();
15089
448338c9ce96 Truffle: Made inlining context-insensitive again to reduce complexity.
Christian Humer <christian.humer@gmail.com>
parents: 15064
diff changeset
428 addASTSizeProperty(this, properties);
13996
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
429 properties.putAll(getCompilationProfile().getDebugProperties());
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
430 return properties;
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
431
c7ac129e17e9 Truffle: further tweaks to the inlinig/split heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 13988
diff changeset
432 }
16410
7f862f0ab1bc Truffle: added new experimental splitting heuristic.
Christian Humer <christian.humer@gmail.com>
parents: 16401
diff changeset
433
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
434 }