Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java @ 12708:85bab2227295
Truffle: refactored inlining to a new class.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Thu, 07 Nov 2013 15:10:09 +0100 |
parents | 48bc171026d1 |
children | d2d0c44662bb |
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 */ |
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
|
41 public final class OptimizedCallTarget extends DefaultCallTarget implements FrameFactory, 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(); |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
44 private static final int MIN_INVOKES_AFTER_INLINING = 2; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 |
11643
2bd626188d31
Introduce TruffleMinInvokeThreshold flag.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10886
diff
changeset
|
46 protected OptimizedCallTarget(RootNode rootNode, FrameDescriptor descriptor, TruffleCompiler compiler, int invokeCounter, int compilationThreshold) { |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 super(rootNode, descriptor); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 this.compiler = compiler; |
12478
b4b7d39cdf73
Truffle: Update for the CompilationPolicy
Christian Wirth <christian.wirth@oracle.com>
parents:
12405
diff
changeset
|
49 this.compilationPolicy = new CompilationPolicy(compilationThreshold, invokeCounter, rootNode.toString()); |
12708
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
50 this.inlining = new TruffleInliningImpl(); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 this.rootNode.setCallTarget(this); |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
52 |
10844
3cf5f371dc9f
Truffle: print inlined call target and rename profiling option.
Andreas Woess <andreas.woess@jku.at>
parents:
10797
diff
changeset
|
53 if (TruffleCallTargetProfiling.getValue()) { |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
54 registerCallTarget(this); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
55 } |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
58 private InstalledCode installedCode; |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
59 private Future<InstalledCode> installedCodeTask; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 private final TruffleCompiler compiler; |
11722
ff05c78a7f64
use time passed to decide what methods to compile or inline
Christian Wirth <christian.wirth@oracle.com>
parents:
11685
diff
changeset
|
61 private final CompilationPolicy compilationPolicy; |
12708
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
62 private final TruffleInlining inlining; |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
63 private boolean disableCompilation; |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
64 private int callCount; |
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
|
65 |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
66 /** |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
67 * Number of times an installed code for this tree was invalidated. |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
68 */ |
10858
f2008a93ad54
Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10857
diff
changeset
|
69 private int invalidationCount; |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
70 |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
71 /** |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
72 * Number of times a node was replaced in this tree. |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
73 */ |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
74 private int nodeReplaceCount; |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
75 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 @Override |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
77 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
|
78 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
|
79 } |
b34114019fd0
Re-add OptimizedCallTarget.callHelper - prevents frequent reinstallation of frame injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12531
diff
changeset
|
80 |
12708
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
81 CompilationPolicy getCompilationPolicy() { |
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
82 return compilationPolicy; |
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
83 } |
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
84 |
12534
b34114019fd0
Re-add OptimizedCallTarget.callHelper - prevents frequent reinstallation of frame injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12531
diff
changeset
|
85 private Object callHelper(PackedFrame caller, Arguments args) { |
12601
48bc171026d1
Merge fixes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12599
diff
changeset
|
86 if (installedCode != null && installedCode.isValid()) { |
12529
23dc5dfdb9c7
Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12488
diff
changeset
|
87 TruffleRuntime runtime = Truffle.getRuntime(); |
23dc5dfdb9c7
Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12488
diff
changeset
|
88 if (runtime instanceof GraalTruffleRuntime) { |
23dc5dfdb9c7
Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12488
diff
changeset
|
89 OUT.printf("[truffle] reinstall OptimizedCallTarget.call code with frame prolog shortcut."); |
23dc5dfdb9c7
Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12488
diff
changeset
|
90 OUT.println(); |
12531
7d5c3ffbee64
Refactoring of the frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12529
diff
changeset
|
91 GraalTruffleRuntime.installOptimizedCallTargetCallMethod(); |
12529
23dc5dfdb9c7
Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12488
diff
changeset
|
92 } |
23dc5dfdb9c7
Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
12488
diff
changeset
|
93 } |
10844
3cf5f371dc9f
Truffle: print inlined call target and rename profiling option.
Andreas Woess <andreas.woess@jku.at>
parents:
10797
diff
changeset
|
94 if (TruffleCallTargetProfiling.getValue()) { |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
95 callCount++; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
96 } |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
97 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
|
98 try { |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
99 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
|
100 } catch (InvalidInstalledCodeException ex) { |
10659
63083745d390
Clean up OptimizedCallTarget and HotSpotNmethod.execute.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10654
diff
changeset
|
101 return compiledCodeInvalidated(caller, args); |
10654
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
102 } |
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
103 } else { |
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
104 return interpreterCall(caller, args); |
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
105 } |
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
106 } |
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
107 |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
108 private Object compiledCodeInvalidated(PackedFrame caller, Arguments args) { |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
109 invalidate(); |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
110 return call(caller, args); |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
111 } |
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 private void invalidate() { |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
114 InstalledCode m = this.installedCode; |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
115 if (m != null) { |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
116 CompilerAsserts.neverPartOfCompilation(); |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
117 installedCode = null; |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
118 invalidationCount++; |
12708
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
119 compilationPolicy.reportCompilationInvalidated(); |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
120 if (TraceTruffleCompilation.getValue()) { |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
121 OUT.printf("[truffle] invalidated %-48s |Inv# %d |Replace# %d\n", rootNode, invalidationCount, nodeReplaceCount); |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
122 } |
10659
63083745d390
Clean up OptimizedCallTarget and HotSpotNmethod.execute.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10654
diff
changeset
|
123 } |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
124 |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
125 Future<InstalledCode> task = this.installedCodeTask; |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
126 if (task != null) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
127 task.cancel(true); |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
128 this.installedCodeTask = null; |
12708
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
129 compilationPolicy.reportCompilationInvalidated(); |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
130 } |
10659
63083745d390
Clean up OptimizedCallTarget and HotSpotNmethod.execute.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10654
diff
changeset
|
131 } |
63083745d390
Clean up OptimizedCallTarget and HotSpotNmethod.execute.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10654
diff
changeset
|
132 |
10654
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
133 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
|
134 CompilerAsserts.neverPartOfCompilation(); |
12708
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
135 compilationPolicy.reportInterpreterCall(); |
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
136 if (disableCompilation || !compilationPolicy.shouldCompileOrInline()) { |
10654
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
137 return executeHelper(caller, args); |
d71c56c67921
Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10643
diff
changeset
|
138 } else { |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
139 return compileOrInline(caller, args); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
140 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
141 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
142 |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
143 private Object compileOrInline(PackedFrame caller, Arguments args) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
144 if (installedCodeTask != null) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
145 // There is already a compilation running. |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
146 if (installedCodeTask.isCancelled()) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
147 installedCodeTask = null; |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
148 } else { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
149 if (installedCodeTask.isDone()) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
150 receiveInstalledCode(); |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
151 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
152 return executeHelper(caller, args); |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
153 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
154 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
155 |
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
|
156 if (TruffleFunctionInlining.getValue() && inline()) { |
12708
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
157 compilationPolicy.reportCallInlined(MIN_INVOKES_AFTER_INLINING); |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
158 return call(caller, args); |
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
|
159 } else { |
8c570011b86f
Truffle: when a node is replaced, notify optimized call target and delay compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10858
diff
changeset
|
160 compile(); |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
161 return executeHelper(caller, args); |
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
|
162 } |
8c570011b86f
Truffle: when a node is replaced, notify optimized call target and delay compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10858
diff
changeset
|
163 } |
8c570011b86f
Truffle: when a node is replaced, notify optimized call target and delay compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10858
diff
changeset
|
164 |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
165 private void receiveInstalledCode() { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
166 try { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
167 this.installedCode = installedCodeTask.get(); |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
168 if (TruffleCallTargetProfiling.getValue()) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
169 resetProfiling(); |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
170 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
171 } catch (InterruptedException | ExecutionException e) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
172 disableCompilation = true; |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
173 OUT.printf("[truffle] opt failed %-48s %s\n", rootNode, e.getMessage()); |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
174 if (e.getCause() instanceof BailoutException) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
175 // Bailout => move on. |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
176 } else { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
177 if (TraceTruffleCompilationExceptions.getValue()) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
178 e.printStackTrace(OUT); |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
179 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
180 if (TruffleCompilationExceptionsAreFatal.getValue()) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
181 System.exit(-1); |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
182 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
183 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
184 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
185 installedCodeTask = null; |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
186 } |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
187 |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
188 public boolean inline() { |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
189 CompilerAsserts.neverPartOfCompilation(); |
12708
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
190 return inlining.performInlining(this); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
191 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
192 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
193 public void compile() { |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
194 CompilerAsserts.neverPartOfCompilation(); |
12592
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
195 this.installedCodeTask = compiler.compile(this); |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
196 if (!TruffleBackgroundCompilation.getValue()) { |
42c8f76a98bf
Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12591
diff
changeset
|
197 receiveInstalledCode(); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
198 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
199 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
200 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
201 public Object executeHelper(PackedFrame caller, Arguments args) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
202 VirtualFrame frame = createFrame(frameDescriptor, caller, args); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
203 return rootNode.execute(frame); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
204 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
205 |
11934
dca16d6f9d65
TruffleRuntime.createVirtualFrame.
Chris Seaton <chris.seaton@oracle.com>
parents:
11722
diff
changeset
|
206 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
|
207 return new FrameWithoutBoxing(descriptor, caller, args); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
208 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
209 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
210 @Override |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
211 public VirtualFrame create(FrameDescriptor descriptor, PackedFrame caller, Arguments args) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
212 return createFrame(descriptor, caller, args); |
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 @Override |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
216 public void reportLoopCount(int count) { |
11722
ff05c78a7f64
use time passed to decide what methods to compile or inline
Christian Wirth <christian.wirth@oracle.com>
parents:
11685
diff
changeset
|
217 compilationPolicy.reportLoopCount(count); |
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 |
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
|
220 @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
|
221 public void nodeReplaced() { |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
222 nodeReplaceCount++; |
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
223 invalidate(); |
12708
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
224 compilationPolicy.notifyNodeReplaced(); |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
225 } |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
226 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
227 private static void resetProfiling() { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
228 for (OptimizedCallTarget callTarget : OptimizedCallTarget.callTargets.keySet()) { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
229 callTarget.callCount = 0; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
230 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
231 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
232 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
233 private static void printProfiling() { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
234 List<OptimizedCallTarget> sortedCallTargets = new ArrayList<>(OptimizedCallTarget.callTargets.keySet()); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
235 Collections.sort(sortedCallTargets, new Comparator<OptimizedCallTarget>() { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
236 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
237 @Override |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
238 public int compare(OptimizedCallTarget o1, OptimizedCallTarget o2) { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
239 return o2.callCount - o1.callCount; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
240 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
241 }); |
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 int totalCallCount = 0; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
244 int totalInlinedCallSiteCount = 0; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
245 int totalNotInlinedCallSiteCount = 0; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
246 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
|
247 int totalInvalidationCount = 0; |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
248 |
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
|
249 OUT.println(); |
10858
f2008a93ad54
Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10857
diff
changeset
|
250 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
|
251 for (OptimizedCallTarget callTarget : sortedCallTargets) { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
252 if (callTarget.callCount == 0) { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
253 continue; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
254 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
255 |
12708
85bab2227295
Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents:
12601
diff
changeset
|
256 int notInlinedCallSiteCount = TruffleInliningImpl.getInlinableCallSites(callTarget).size(); |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
257 int nodeCount = NodeUtil.countNodes(callTarget.rootNode); |
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
|
258 int inlinedCallSiteCount = NodeUtil.countNodes(callTarget.rootNode, InlinedCallSite.class); |
12591
33fe56e68abd
Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12405
diff
changeset
|
259 String comment = callTarget.installedCode == null ? " int" : ""; |
10858
f2008a93ad54
Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10857
diff
changeset
|
260 comment += callTarget.disableCompilation ? " fail" : ""; |
f2008a93ad54
Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10857
diff
changeset
|
261 OUT.printf("%-50s | %10d | %15d | %15d | %10d | %3d%s\n", callTarget.getRootNode(), callTarget.callCount, inlinedCallSiteCount, notInlinedCallSiteCount, nodeCount, |
f2008a93ad54
Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10857
diff
changeset
|
262 callTarget.invalidationCount, comment); |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
263 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
264 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
|
265 totalInlinedCallSiteCount += inlinedCallSiteCount; |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
266 totalNotInlinedCallSiteCount += notInlinedCallSiteCount; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
267 totalNodeCount += nodeCount; |
10858
f2008a93ad54
Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10857
diff
changeset
|
268 totalInvalidationCount += callTarget.invalidationCount; |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
269 } |
10858
f2008a93ad54
Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents:
10857
diff
changeset
|
270 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
|
271 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
272 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
273 private static void registerCallTarget(OptimizedCallTarget callTarget) { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
274 callTargets.put(callTarget, 0); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
275 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
276 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
277 private static Map<OptimizedCallTarget, Integer> callTargets; |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
278 static { |
10844
3cf5f371dc9f
Truffle: print inlined call target and rename profiling option.
Andreas Woess <andreas.woess@jku.at>
parents:
10797
diff
changeset
|
279 if (TruffleCallTargetProfiling.getValue()) { |
10752
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
280 callTargets = new WeakHashMap<>(); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
281 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
282 Runtime.getRuntime().addShutdownHook(new Thread() { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
283 |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
284 @Override |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
285 public void run() { |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
286 printProfiling(); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
287 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
288 }); |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
289 } |
e2f5ae9afdc5
Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents:
10751
diff
changeset
|
290 } |
10484
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
291 } |