Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java @ 13915:d6b340b757a2
Truffle: refactorings
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Sat, 08 Feb 2014 06:33:29 +0100 |
parents | e86d32f4803f |
children | 1c9dbfc5b510 |
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 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
25 import static com.oracle.graal.truffle.TruffleCompilerOptions.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
27 import java.io.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
28 import java.util.*; |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
29 import java.util.concurrent.*; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.api.code.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.debug.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.frame.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.impl.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 import com.oracle.truffle.api.nodes.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 |
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 * 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
|
40 */ |
13915
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
41 public final class OptimizedCallTarget extends DefaultCallTarget implements LoopCountReceiver, ReplaceObserver { |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 private 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
|
44 |
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 private InstalledCode installedCode; |
d2d0c44662bb
Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents:
12708
diff
changeset
|
46 private Future<InstalledCode> installedCodeTask; |
d2d0c44662bb
Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents:
12708
diff
changeset
|
47 private final TruffleCompiler compiler; |
d2d0c44662bb
Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents:
12708
diff
changeset
|
48 private final CompilationProfile compilationProfile; |
d2d0c44662bb
Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents:
12708
diff
changeset
|
49 private final CompilationPolicy compilationPolicy; |
d2d0c44662bb
Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents:
12708
diff
changeset
|
50 private final TruffleInlining inlining; |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
51 private boolean compilationEnabled; |
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
|
52 private int callCount; |
13774
dbd670294770
Use a OptimizedCallTarget-bound SpeculationLog for Truffle compilations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
13760
diff
changeset
|
53 private SpeculationLog speculationLog = new SpeculationLog(); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 |
13915
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
55 OptimizedCallTarget(RootNode rootNode, TruffleCompiler compiler, int invokeCounter, int compilationThreshold, boolean compilationEnabled) { |
13705
ac5b0f31f7a2
Truffle API-change: FrameDescriptors are now stored in the RootNode in a final field instead of the CallTarget.
Christian Humer <christian.humer@gmail.com>
parents:
13703
diff
changeset
|
56 super(rootNode); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 this.compiler = compiler; |
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
|
58 this.compilationProfile = new CompilationProfile(compilationThreshold, invokeCounter, rootNode.toString()); |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
59 |
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
|
60 if (TruffleUseTimeForCompilationDecision.getValue()) { |
d2d0c44662bb
Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents:
12708
diff
changeset
|
61 compilationPolicy = new TimedCompilationPolicy(); |
d2d0c44662bb
Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents:
12708
diff
changeset
|
62 } else { |
d2d0c44662bb
Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents:
12708
diff
changeset
|
63 compilationPolicy = new DefaultCompilationPolicy(); |
d2d0c44662bb
Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents:
12708
diff
changeset
|
64 } |
13915
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
65 this.compilationEnabled = compilationEnabled; |
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
|
66 |
10844
3cf5f371dc9f
Truffle: print inlined call target and rename profiling option.
Andreas Woess <andreas.woess@jku.at>
parents:
10797
diff
changeset
|
67 if (TruffleCallTargetProfiling.getValue()) { |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
68 registerCallTarget(this); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
69 } |
13703
03b42f0fb635
Truffle: extend inlining interface with custom reprofile counters.
Christian Humer <christian.humer@gmail.com>
parents:
13208
diff
changeset
|
70 this.inlining = new TruffleInliningImpl(); |
03b42f0fb635
Truffle: extend inlining interface with custom reprofile counters.
Christian Humer <christian.humer@gmail.com>
parents:
13208
diff
changeset
|
71 |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
72 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
73 |
13720
4281521dc39a
Truffle: fix non-local control flow using exceptions
Andreas Woess <andreas.woess@jku.at>
parents:
13705
diff
changeset
|
74 @CompilerDirectives.SlowPath |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
75 @Override |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 public Object call(PackedFrame caller, Arguments args) { |
12534
b34114019fd0
Re-add OptimizedCallTarget.callHelper - prevents frequent reinstallation of frame injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12531
diff
changeset
|
77 return callHelper(caller, args); |
b34114019fd0
Re-add OptimizedCallTarget.callHelper - prevents frequent reinstallation of frame injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12531
diff
changeset
|
78 } |
b34114019fd0
Re-add OptimizedCallTarget.callHelper - prevents frequent reinstallation of frame injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12531
diff
changeset
|
79 |
b34114019fd0
Re-add OptimizedCallTarget.callHelper - prevents frequent reinstallation of frame injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12531
diff
changeset
|
80 private Object callHelper(PackedFrame caller, Arguments args) { |
12601
48bc171026d1
Merge fixes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12599
diff
changeset
|
81 if (installedCode != null && installedCode.isValid()) { |
13915
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
82 reinstallCallMethodShortcut(); |
12529
23dc5dfdb9c7
Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12488
diff
changeset
|
83 } |
10844
3cf5f371dc9f
Truffle: print inlined call target and rename profiling option.
Andreas Woess <andreas.woess@jku.at>
parents:
10797
diff
changeset
|
84 if (TruffleCallTargetProfiling.getValue()) { |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
85 callCount++; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
86 } |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
87 if (CompilerDirectives.injectBranchProbability(CompilerDirectives.FASTPATH_PROBABILITY, installedCode != null)) { |
10654
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
88 try { |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
89 return installedCode.execute(this, caller, args); |
10654
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
90 } catch (InvalidInstalledCodeException ex) { |
10659
63083745d390
Clean up OptimizedCallTarget and HotSpotNmethod.execute.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10654
diff
changeset
|
91 return compiledCodeInvalidated(caller, args); |
10654
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
92 } |
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
93 } else { |
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
94 return interpreterCall(caller, args); |
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
95 } |
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
96 } |
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
97 |
13915
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
98 private static void reinstallCallMethodShortcut() { |
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
99 if (TraceTruffleCompilation.getValue()) { |
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
100 OUT.println("[truffle] reinstall OptimizedCallTarget.call code with frame prolog shortcut."); |
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
101 } |
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
102 GraalTruffleRuntime.installOptimizedCallTargetCallMethod(); |
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
103 } |
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
104 |
12711
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
105 public CompilationProfile getCompilationProfile() { |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
106 return compilationProfile; |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
107 } |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
108 |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
109 private Object compiledCodeInvalidated(PackedFrame caller, Arguments args) { |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
110 invalidate(); |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
111 return call(caller, args); |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
112 } |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
113 |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
114 private void invalidate() { |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
115 InstalledCode m = this.installedCode; |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
116 if (m != null) { |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
117 CompilerAsserts.neverPartOfCompilation(); |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
118 installedCode = null; |
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
|
119 compilationProfile.reportInvalidated(); |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
120 if (TraceTruffleCompilation.getValue()) { |
13915
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
121 OUT.printf("[truffle] invalidated %-48s %08x |InvalidationCount %2d |ReplaceCount %3d\n", getRootNode(), getRootNode().hashCode(), compilationProfile.getInvalidationCount(), |
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
|
122 compilationProfile.getNodeReplaceCount()); |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
123 } |
10659
63083745d390
Clean up OptimizedCallTarget and HotSpotNmethod.execute.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10654
diff
changeset
|
124 } |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
125 |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
126 Future<InstalledCode> task = this.installedCodeTask; |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
127 if (task != null) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
128 task.cancel(true); |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
129 this.installedCodeTask = null; |
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
|
130 compilationProfile.reportInvalidated(); |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
131 } |
10659
63083745d390
Clean up OptimizedCallTarget and HotSpotNmethod.execute.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10654
diff
changeset
|
132 } |
63083745d390
Clean up OptimizedCallTarget and HotSpotNmethod.execute.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10654
diff
changeset
|
133 |
10654
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
134 private Object interpreterCall(PackedFrame caller, Arguments args) { |
10857
94cf5df0727f
Backout changeset 4c12d3756015; ensure compiledCodeInvalidated() is never inlined.
Andreas Woess <andreas.woess@jku.at>
parents:
10844
diff
changeset
|
135 CompilerAsserts.neverPartOfCompilation(); |
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
|
136 compilationProfile.reportInterpreterCall(); |
12711
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
137 if (compilationEnabled && shouldCompile()) { |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
138 if (isCompiling()) { |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
139 return waitForCompilation(caller, args); |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
140 } |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
141 boolean inlined = shouldInline() && inline(); |
12711
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
142 if (!inlined) { |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
143 compile(); |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
144 } |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
145 } |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
146 return executeHelper(caller, args); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
147 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
148 |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
149 private boolean shouldCompile() { |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
150 return compilationPolicy.shouldCompile(compilationProfile); |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
151 } |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
152 |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
153 private static boolean shouldInline() { |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
154 return TruffleFunctionInlining.getValue(); |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
155 } |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
156 |
12711
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
157 private boolean isCompiling() { |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
158 if (installedCodeTask != null) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
159 if (installedCodeTask.isCancelled()) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
160 installedCodeTask = null; |
12711
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
161 return false; |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
162 } |
12711
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
163 return true; |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
164 } |
12711
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
165 return false; |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
166 } |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
167 |
12711
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
168 public void compile() { |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
169 this.installedCodeTask = compiler.compile(this); |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
170 if (!TruffleBackgroundCompilation.getValue()) { |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
171 installedCode = receiveInstalledCode(); |
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
|
172 } |
8c570011b86f
Truffle: when a node is replaced, notify optimized call target and delay compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10858
diff
changeset
|
173 } |
8c570011b86f
Truffle: when a node is replaced, notify optimized call target and delay compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10858
diff
changeset
|
174 |
12711
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
175 private Object waitForCompilation(PackedFrame caller, Arguments args) { |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
176 if (installedCodeTask.isDone()) { |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
177 installedCode = receiveInstalledCode(); |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
178 } |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
179 return executeHelper(caller, args); |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
180 } |
fb4658e16b5d
Truffle: some regression fixes to previous cleanup
Christian Humer <christian.humer@gmail.com>
parents:
12710
diff
changeset
|
181 |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
182 private InstalledCode receiveInstalledCode() { |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
183 try { |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
184 return installedCodeTask.get(); |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
185 } catch (InterruptedException | ExecutionException e) { |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
186 compilationEnabled = false; |
13760
a12017c18d5d
Truffle API cleanup: Reduce the visibility of classes and constructors that are not intended to be instantiated by guest language implementations; provide abstract class RootCallTarget as a CallTarget to a RootNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13720
diff
changeset
|
187 OUT.printf("[truffle] opt failed %-48s %s\n", getRootNode(), e.getMessage()); |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
188 if (e.getCause() instanceof BailoutException) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
189 // Bailout => move on. |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
190 } else { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
191 if (TraceTruffleCompilationExceptions.getValue()) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
192 e.printStackTrace(OUT); |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
193 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
194 if (TruffleCompilationExceptionsAreFatal.getValue()) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
195 System.exit(-1); |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
196 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
197 } |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
198 return null; |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
199 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
200 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
201 |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
202 /** |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
203 * Forces inlining whether or not function inlining is enabled. |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
204 * |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
205 * @return true if an inlining was performed |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
206 */ |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
207 public boolean inline() { |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
208 boolean result = inlining.performInlining(this); |
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
209 if (result) { |
13703
03b42f0fb635
Truffle: extend inlining interface with custom reprofile counters.
Christian Humer <christian.humer@gmail.com>
parents:
13208
diff
changeset
|
210 compilationProfile.reportInliningPerformed(inlining); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
211 } |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
212 return result; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
213 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
214 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
215 public Object executeHelper(PackedFrame caller, Arguments args) { |
13760
a12017c18d5d
Truffle API cleanup: Reduce the visibility of classes and constructors that are not intended to be instantiated by guest language implementations; provide abstract class RootCallTarget as a CallTarget to a RootNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13720
diff
changeset
|
216 VirtualFrame frame = createFrame(getRootNode().getFrameDescriptor(), caller, args); |
a12017c18d5d
Truffle API cleanup: Reduce the visibility of classes and constructors that are not intended to be instantiated by guest language implementations; provide abstract class RootCallTarget as a CallTarget to a RootNode
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13720
diff
changeset
|
217 return getRootNode().execute(frame); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
218 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
219 |
11934
dca16d6f9d65
TruffleRuntime.createVirtualFrame.
Chris Seaton <chris.seaton@oracle.com>
parents:
11722
diff
changeset
|
220 protected static FrameWithoutBoxing createFrame(FrameDescriptor descriptor, PackedFrame caller, Arguments args) { |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
221 return new FrameWithoutBoxing(descriptor, caller, args); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
222 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
223 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
224 @Override |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
225 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
|
226 compilationProfile.reportLoopCount(count); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
227 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
228 |
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
|
229 @Override |
8c570011b86f
Truffle: when a node is replaced, notify optimized call target and delay compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10858
diff
changeset
|
230 public void nodeReplaced() { |
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
|
231 compilationProfile.reportNodeReplaced(); |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
232 invalidate(); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
233 } |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
234 |
13915
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
235 public SpeculationLog getSpeculationLog() { |
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
236 return speculationLog; |
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
237 } |
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13851
diff
changeset
|
238 |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
239 private static void printProfiling() { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
240 List<OptimizedCallTarget> sortedCallTargets = new ArrayList<>(OptimizedCallTarget.callTargets.keySet()); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
241 Collections.sort(sortedCallTargets, new Comparator<OptimizedCallTarget>() { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
242 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
243 @Override |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
244 public int compare(OptimizedCallTarget o1, OptimizedCallTarget o2) { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
245 return o2.callCount - o1.callCount; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
246 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
247 }); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
248 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
249 int totalCallCount = 0; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
250 int totalInlinedCallSiteCount = 0; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
251 int totalNotInlinedCallSiteCount = 0; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
252 int totalNodeCount = 0; |
10858
f2008a93ad54
Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10857
diff
changeset
|
253 int totalInvalidationCount = 0; |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
254 |
10794
3fe325c3f31c
Truffle: add InlinedCallSite interface and an InlinableCallSite method to query the inlined call target
Andreas Woess <andreas.woess@jku.at>
parents:
10752
diff
changeset
|
255 OUT.println(); |
10858
f2008a93ad54
Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10857
diff
changeset
|
256 OUT.printf("%-50s | %-10s | %s / %s | %s | %s\n", "Call Target", "Call Count", "Calls Sites Inlined", "Not Inlined", "Node Count", "Inv"); |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
257 for (OptimizedCallTarget callTarget : sortedCallTargets) { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
258 if (callTarget.callCount == 0) { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
259 continue; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
260 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
261 |
13851
e86d32f4803f
Truffle: Implement cache for truffle inlining heuristic.
Christian Humer <christian.humer@gmail.com>
parents:
13811
diff
changeset
|
262 int notInlinedCallSiteCount = TruffleInliningImpl.getInlinableCallSites(callTarget, callTarget).size(); |
13811
641f22b1c6b8
Truffle: further fixes to the new CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13806
diff
changeset
|
263 int nodeCount = NodeUtil.countNodes(callTarget.getRootNode(), null, true); |
13806 | 264 int inlinedCallSiteCount = countInlinedNodes(callTarget.getRootNode()); |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
265 String comment = callTarget.installedCode == null ? " int" : ""; |
12710
60142b15ed42
Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
Christian Humer <christian.humer@gmail.com>
parents:
12709
diff
changeset
|
266 comment += callTarget.compilationEnabled ? "" : " fail"; |
10858
f2008a93ad54
Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10857
diff
changeset
|
267 OUT.printf("%-50s | %10d | %15d | %15d | %10d | %3d%s\n", callTarget.getRootNode(), callTarget.callCount, inlinedCallSiteCount, notInlinedCallSiteCount, nodeCount, |
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
|
268 callTarget.getCompilationProfile().getInvalidationCount(), comment); |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
269 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
270 totalCallCount += callTarget.callCount; |
10794
3fe325c3f31c
Truffle: add InlinedCallSite interface and an InlinableCallSite method to query the inlined call target
Andreas Woess <andreas.woess@jku.at>
parents:
10752
diff
changeset
|
271 totalInlinedCallSiteCount += inlinedCallSiteCount; |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
272 totalNotInlinedCallSiteCount += notInlinedCallSiteCount; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
273 totalNodeCount += nodeCount; |
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
|
274 totalInvalidationCount += callTarget.getCompilationProfile().getInvalidationCount(); |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
275 } |
10858
f2008a93ad54
Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10857
diff
changeset
|
276 OUT.printf("%-50s | %10d | %15d | %15d | %10d | %3d\n", "Total", totalCallCount, totalInlinedCallSiteCount, totalNotInlinedCallSiteCount, totalNodeCount, totalInvalidationCount); |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
277 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
278 |
13803
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13720
diff
changeset
|
279 private static int countInlinedNodes(Node rootNode) { |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13720
diff
changeset
|
280 List<CallNode> callers = NodeUtil.findAllNodeInstances(rootNode, CallNode.class); |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13720
diff
changeset
|
281 int count = 0; |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13720
diff
changeset
|
282 for (CallNode callNode : callers) { |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13720
diff
changeset
|
283 if (callNode.isInlined()) { |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13720
diff
changeset
|
284 count++; |
13811
641f22b1c6b8
Truffle: further fixes to the new CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13806
diff
changeset
|
285 count += countInlinedNodes(callNode.getInlinedRoot()); |
13803
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13720
diff
changeset
|
286 } |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13720
diff
changeset
|
287 } |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13720
diff
changeset
|
288 return count; |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13720
diff
changeset
|
289 } |
e076c87ab175
Truffle: refactored inlining interfaces to a more compact CallNode.
Christian Humer <christian.humer@gmail.com>
parents:
13720
diff
changeset
|
290 |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
291 private static void registerCallTarget(OptimizedCallTarget callTarget) { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
292 callTargets.put(callTarget, 0); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
293 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
294 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
295 private static Map<OptimizedCallTarget, Integer> callTargets; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
296 static { |
10844
3cf5f371dc9f
Truffle: print inlined call target and rename profiling option.
Andreas Woess <andreas.woess@jku.at>
parents:
10797
diff
changeset
|
297 if (TruffleCallTargetProfiling.getValue()) { |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
298 callTargets = new WeakHashMap<>(); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
299 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
300 Runtime.getRuntime().addShutdownHook(new Thread() { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
301 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
302 @Override |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
303 public void run() { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
304 printProfiling(); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
305 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
306 }); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
307 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
308 } |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
309 } |