annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java @ 12710:60142b15ed42

Truffle: fixed bug where invocation counter was decremented twice after inlining; cleanup of optimized call target and profile.
author Christian Humer <christian.humer@gmail.com>
date Thu, 07 Nov 2013 19:07:41 +0100
parents d2d0c44662bb
children fb4658e16b5d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.truffle;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
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();
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;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53
11643
2bd626188d31 Introduce TruffleMinInvokeThreshold flag.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10886
diff changeset
54 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
55 super(rootNode, descriptor);
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 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
57 this.compilationProfile = new CompilationProfile(compilationThreshold, invokeCounter, rootNode.toString());
12708
85bab2227295 Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents: 12601
diff changeset
58 this.inlining = new TruffleInliningImpl();
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 this.rootNode.setCallTarget(this);
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
60
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
61 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
62 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
63 } 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
64 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
65 }
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
66 this.compilationEnabled = true;
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
67
10844
3cf5f371dc9f Truffle: print inlined call target and rename profiling option.
Andreas Woess <andreas.woess@jku.at>
parents: 10797
diff changeset
68 if (TruffleCallTargetProfiling.getValue()) {
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
69 registerCallTarget(this);
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
70 }
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 }
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 @Override
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 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
75 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
76 }
b34114019fd0 Re-add OptimizedCallTarget.callHelper - prevents frequent reinstallation of frame injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 12531
diff changeset
77
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
78 public CompilationProfile getCompilationProfile() {
d2d0c44662bb Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents: 12708
diff changeset
79 return compilationProfile;
12708
85bab2227295 Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents: 12601
diff changeset
80 }
85bab2227295 Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents: 12601
diff changeset
81
12534
b34114019fd0 Re-add OptimizedCallTarget.callHelper - prevents frequent reinstallation of frame injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 12531
diff changeset
82 private Object callHelper(PackedFrame caller, Arguments args) {
12601
48bc171026d1 Merge fixes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12599
diff changeset
83 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
84 TruffleRuntime runtime = Truffle.getRuntime();
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 12488
diff changeset
85 if (runtime instanceof GraalTruffleRuntime) {
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 12488
diff changeset
86 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
87 OUT.println();
12531
7d5c3ffbee64 Refactoring of the frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 12529
diff changeset
88 GraalTruffleRuntime.installOptimizedCallTargetCallMethod();
12529
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 12488
diff changeset
89 }
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 12488
diff changeset
90 }
10844
3cf5f371dc9f Truffle: print inlined call target and rename profiling option.
Andreas Woess <andreas.woess@jku.at>
parents: 10797
diff changeset
91 if (TruffleCallTargetProfiling.getValue()) {
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
92 callCount++;
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
93 }
12591
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
94 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
95 try {
12591
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
96 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
97 } catch (InvalidInstalledCodeException ex) {
10659
63083745d390 Clean up OptimizedCallTarget and HotSpotNmethod.execute.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10654
diff changeset
98 return compiledCodeInvalidated(caller, args);
10654
d71c56c67921 Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10643
diff changeset
99 }
d71c56c67921 Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10643
diff changeset
100 } else {
d71c56c67921 Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10643
diff changeset
101 return interpreterCall(caller, args);
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 }
d71c56c67921 Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10643
diff changeset
104
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
105 private Object compiledCodeInvalidated(PackedFrame caller, Arguments args) {
12591
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
106 invalidate();
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
107 return call(caller, args);
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
108 }
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
109
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
110 private void invalidate() {
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
111 InstalledCode m = this.installedCode;
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
112 if (m != null) {
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
113 CompilerAsserts.neverPartOfCompilation();
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
114 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
115 compilationProfile.reportInvalidated();
12591
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
116 if (TraceTruffleCompilation.getValue()) {
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
117 OUT.printf("[truffle] invalidated %-48s |Inv# %d |Replace# %d\n", rootNode, compilationProfile.getInvalidationCount(),
d2d0c44662bb Truffle: refactored CompilationProfile to separate the profile and the policy in separate classes.
Christian Humer <christian.humer@gmail.com>
parents: 12708
diff changeset
118 compilationProfile.getNodeReplaceCount());
12591
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
119 }
10659
63083745d390 Clean up OptimizedCallTarget and HotSpotNmethod.execute.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10654
diff changeset
120 }
12592
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
121
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
122 Future<InstalledCode> task = this.installedCodeTask;
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
123 if (task != null) {
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
124 task.cancel(true);
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
125 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
126 compilationProfile.reportInvalidated();
12592
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
127 }
10659
63083745d390 Clean up OptimizedCallTarget and HotSpotNmethod.execute.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10654
diff changeset
128 }
63083745d390 Clean up OptimizedCallTarget and HotSpotNmethod.execute.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10654
diff changeset
129
10654
d71c56c67921 Improve performance of calling Truffle call targets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10643
diff changeset
130 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
131 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
132 compilationProfile.reportInterpreterCall();
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
133 if (compilationEnabled) {
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
134 boolean inlined = shouldInline() && inline();
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
135 if (!inlined && 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
136 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
137 }
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 }
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
139 return executeHelper(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
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
142 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
143 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
144 }
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
145
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 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
147 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
148 }
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
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 public void 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
151 CompilerAsserts.neverPartOfCompilation();
12592
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
152 if (installedCodeTask != null) {
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
153 // There is already a compilation running.
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
154 if (installedCodeTask.isCancelled()) {
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
155 installedCodeTask = null;
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
156 } else {
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
157 if (installedCodeTask.isDone()) {
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
158 installedCode = receiveInstalledCode();
12592
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
159 }
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
160 return;
12592
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
161 }
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
162 }
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
163
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
164 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
165 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
166 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
167 }
8c570011b86f Truffle: when a node is replaced, notify optimized call target and delay compilation.
Andreas Woess <andreas.woess@jku.at>
parents: 10858
diff changeset
168 }
8c570011b86f Truffle: when a node is replaced, notify optimized call target and delay compilation.
Andreas Woess <andreas.woess@jku.at>
parents: 10858
diff changeset
169
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
170 private InstalledCode receiveInstalledCode() {
12592
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
171 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
172 return installedCodeTask.get();
12592
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
173 } 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
174 compilationEnabled = false;
12592
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
175 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
176 if (e.getCause() instanceof BailoutException) {
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
177 // Bailout => move on.
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
178 } else {
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
179 if (TraceTruffleCompilationExceptions.getValue()) {
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
180 e.printStackTrace(OUT);
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
181 }
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
182 if (TruffleCompilationExceptionsAreFatal.getValue()) {
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
183 System.exit(-1);
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 }
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 return null;
12592
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
187 }
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
188 }
42c8f76a98bf Move Truffle compilations to background compilation thread.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12591
diff changeset
189
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
190 /**
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
191 * 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
192 *
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
193 * @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
194 */
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
195 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
196 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
197 if (result) {
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 compilationProfile.reportInliningPerformed();
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
199 }
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
200 return result;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
201 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
202
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
203 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
204 VirtualFrame frame = createFrame(frameDescriptor, caller, args);
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
205 return rootNode.execute(frame);
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
206 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
207
11934
dca16d6f9d65 TruffleRuntime.createVirtualFrame.
Chris Seaton <chris.seaton@oracle.com>
parents: 11722
diff changeset
208 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
209 return new FrameWithoutBoxing(descriptor, caller, args);
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
210 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
211
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
212 @Override
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
213 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
214 return createFrame(descriptor, caller, args);
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
215 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
216
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
217 @Override
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
218 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
219 compilationProfile.reportLoopCount(count);
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
220 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
221
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
222 @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
223 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
224 compilationProfile.reportNodeReplaced();
12591
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
225 invalidate();
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
226 }
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
227
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
228 private static void printProfiling() {
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
229 List<OptimizedCallTarget> sortedCallTargets = new ArrayList<>(OptimizedCallTarget.callTargets.keySet());
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
230 Collections.sort(sortedCallTargets, new Comparator<OptimizedCallTarget>() {
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 @Override
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
233 public int compare(OptimizedCallTarget o1, OptimizedCallTarget o2) {
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
234 return o2.callCount - o1.callCount;
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
235 }
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
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
238 int totalCallCount = 0;
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
239 int totalInlinedCallSiteCount = 0;
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
240 int totalNotInlinedCallSiteCount = 0;
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
241 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
242 int totalInvalidationCount = 0;
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
243
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
244 OUT.println();
10858
f2008a93ad54 Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents: 10857
diff changeset
245 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
246 for (OptimizedCallTarget callTarget : sortedCallTargets) {
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
247 if (callTarget.callCount == 0) {
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
248 continue;
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
249 }
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
250
12708
85bab2227295 Truffle: refactored inlining to a new class.
Christian Humer <christian.humer@gmail.com>
parents: 12601
diff changeset
251 int notInlinedCallSiteCount = TruffleInliningImpl.getInlinableCallSites(callTarget).size();
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
252 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
253 int inlinedCallSiteCount = NodeUtil.countNodes(callTarget.rootNode, InlinedCallSite.class);
12591
33fe56e68abd Simplifications of OptimizedCallTarget.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 12405
diff changeset
254 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
255 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
256 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
257 callTarget.getCompilationProfile().getInvalidationCount(), comment);
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
258
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
259 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
260 totalInlinedCallSiteCount += inlinedCallSiteCount;
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
261 totalNotInlinedCallSiteCount += notInlinedCallSiteCount;
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
262 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
263 totalInvalidationCount += callTarget.getCompilationProfile().getInvalidationCount();
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
264 }
10858
f2008a93ad54 Truffle: add invalidation count to call target profiling / trace compilation.
Andreas Woess <andreas.woess@jku.at>
parents: 10857
diff changeset
265 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
266 }
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
267
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
268 private static void registerCallTarget(OptimizedCallTarget callTarget) {
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
269 callTargets.put(callTarget, 0);
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
270 }
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 private static Map<OptimizedCallTarget, Integer> callTargets;
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
273 static {
10844
3cf5f371dc9f Truffle: print inlined call target and rename profiling option.
Andreas Woess <andreas.woess@jku.at>
parents: 10797
diff changeset
274 if (TruffleCallTargetProfiling.getValue()) {
10752
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
275 callTargets = new WeakHashMap<>();
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 Runtime.getRuntime().addShutdownHook(new Thread() {
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
278
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
279 @Override
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
280 public void run() {
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
281 printProfiling();
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
282 }
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 }
e2f5ae9afdc5 Truffle: introduce profiling option
Andreas Woess <andreas.woess@jku.at>
parents: 10751
diff changeset
285 }
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
286 }