Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java @ 10484:0097fb11c16f
Add basic version of Graal's Truffle runtime.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 23 Jun 2013 21:44:15 +0200 |
parents | |
children | 77016aeda39a |
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.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.api.code.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.debug.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.api.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.frame.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.impl.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.nodes.*; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 |
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 * 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
|
39 */ |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 public final class OptimizedCallTarget extends DefaultCallTarget implements LoopCountReceiver, FrameFactory { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 private static final PrintStream OUT = TTY.out().out(); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 private final int inliningReprofileCount; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 private final int invalidationReprofileCount; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
46 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 protected OptimizedCallTarget(RootNode rootNode, FrameDescriptor descriptor, TruffleCompiler compiler, int compilationThreshold, int inliningReprofileCount, int invalidationReprofileCount) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 super(rootNode, descriptor); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 this.compiler = compiler; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 this.invokeCounter = compilationThreshold >> 7; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 this.loopAndInvokeCounter = compilationThreshold; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 this.originalInvokeCounter = compilationThreshold; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 this.rootNode.setCallTarget(this); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 this.inliningReprofileCount = inliningReprofileCount; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 this.invalidationReprofileCount = invalidationReprofileCount; |
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 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 private InstalledCode compiledMethod; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 private final TruffleCompiler compiler; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 private int invokeCounter; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 private int originalInvokeCounter; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
62 private int loopAndInvokeCounter; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
63 private boolean disableCompilation; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
64 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
65 long timeCompilationStarted; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 long timePartialEvaluationFinished; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
67 long timeCompilationFinished; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
68 int codeSize; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
69 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
70 @Override |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
71 public Object call(PackedFrame caller, Arguments args) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
72 for (;;) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
73 if (compiledMethod != null) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
74 try { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
75 return compiledMethod.execute(this, caller, args); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 } catch (InvalidInstalledCodeException ex) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
77 compiledMethod = null; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
78 invokeCounter = invalidationReprofileCount; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
79 if (TruffleFunctionInlining.getValue()) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
80 originalInvokeCounter += invalidationReprofileCount; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
81 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
82 if (TraceTruffleCompilation.getValue()) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
83 OUT.printf("[truffle] invalidated %-48s |Alive %4.0fms\n", rootNode, (System.nanoTime() - timeCompilationFinished) / 1e6); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
84 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
85 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
86 } else { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
87 invokeCounter--; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
88 loopAndInvokeCounter--; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
89 if (disableCompilation || loopAndInvokeCounter > 0 || invokeCounter > 0) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
90 return executeHelper(caller, args); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
91 } else { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
92 if (TruffleFunctionInlining.getValue()) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
93 if (inline()) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
94 invokeCounter = 2; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
95 loopAndInvokeCounter = inliningReprofileCount; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
96 originalInvokeCounter = inliningReprofileCount; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
97 } else { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
98 compile(); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
99 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
100 } else { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
101 compile(); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
102 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
103 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
104 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
105 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
106 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
107 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
108 public boolean inline() { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
109 return new InliningHelper(this).inline(); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
110 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
111 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
112 public void compile() { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
113 try { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
114 compiledMethod = compiler.compile(this); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
115 if (compiledMethod == null) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
116 throw new BailoutException(String.format("code installation failed (codeSize=%s)", codeSize)); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
117 } else { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
118 if (TraceTruffleCompilation.getValue()) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
119 OUT.printf("[truffle] optimized %-50s |Total %5.0fms |PE %4.0fms |Graal %4.0fms |CodeSize %d\n", rootNode, (timeCompilationFinished - timeCompilationStarted) / 1e6, |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
120 (timePartialEvaluationFinished - timeCompilationStarted) / 1e6, (timeCompilationFinished - timePartialEvaluationFinished) / 1e6, codeSize); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
121 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
122 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
123 } catch (Throwable e) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
124 invokeCounter = Integer.MAX_VALUE; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
125 loopAndInvokeCounter = Integer.MAX_VALUE; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
126 if (TraceTruffleCompilation.getValue()) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
127 if (e instanceof BailoutException) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
128 disableCompilation = true; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
129 BailoutException bailoutException = (BailoutException) e; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
130 OUT.printf("[truffle] opt bailout %-48s %s\n", rootNode, bailoutException.getMessage()); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
131 } else { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
132 OUT.printf("[truffle] opt failed %-49s %s\n", rootNode, e.toString()); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
133 if (TraceTruffleCompilationExceptions.getValue()) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
134 e.printStackTrace(OUT); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
135 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
136 if (TruffleCompilationExceptionsAreFatal.getValue()) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
137 System.exit(-1); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
138 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
139 } |
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 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
143 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
144 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
|
145 VirtualFrame frame = createFrame(frameDescriptor, caller, args); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
146 return rootNode.execute(frame); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
147 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
148 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
149 private static FrameWithoutBoxing createFrame(FrameDescriptor descriptor, PackedFrame caller, Arguments args) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
150 return new FrameWithoutBoxing(descriptor, caller, args); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
151 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
152 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
153 @Override |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
154 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
|
155 return createFrame(descriptor, caller, args); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
156 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
157 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
158 @Override |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
159 public String toString() { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
160 return "CallTarget " + rootNode; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
161 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
162 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
163 @Override |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
164 public void reportLoopCount(int count) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
165 loopAndInvokeCounter -= count; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
166 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
167 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
168 private class InliningHelper { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
169 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
170 private static final int MAX_SIZE = 300; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
171 private static final int MAX_INLINE_SIZE = 62; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
172 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
173 private final OptimizedCallTarget target; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
174 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
175 public InliningHelper(OptimizedCallTarget target) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
176 this.target = target; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
177 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
178 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
179 public boolean inline() { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
180 CallTargetProfile profile = new CallTargetProfile(target.getRootNode()); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
181 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
182 if (profile.inlinableCallSites.isEmpty()) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
183 return false; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
184 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
185 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
186 if (profile.nodeCount > MAX_SIZE) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
187 return false; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
188 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
189 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
190 double max = 0.0D; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
191 ProfiledInlinableCallSite inliningDecision = null; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
192 for (Node callNode : profile.inlinableCallSites) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
193 InlinableCallSite callSite = (InlinableCallSite) callNode; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
194 Node inlineTree = callSite.getInlineTree(); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
195 if (inlineTree == null) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
196 continue; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
197 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
198 CallTargetProfile inlineProfile = new CallTargetProfile(inlineTree); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
199 if (inlineProfile.nodeCount > MAX_INLINE_SIZE || inlineProfile.nodeCount + profile.nodeCount > MAX_SIZE) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
200 continue; |
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 ProfiledInlinableCallSite inlinable = new ProfiledInlinableCallSite(inlineProfile, callSite); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
204 double metric = (inlinable.callCount / inlineProfile.nodeCount) + ((double) inlinable.callCount / (double) originalInvokeCounter); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
205 if (metric >= max) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
206 inliningDecision = inlinable; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
207 max = metric; |
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 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
211 for (Node callSite : profile.inlinableCallSites) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
212 ((InlinableCallSite) callSite).resetCallCount(); |
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 if (inliningDecision != null) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
216 if (inliningDecision.callSite.inline(target)) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
217 if (TraceTruffleCompilation.getValue()) { |
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 String calls = String.format("%4s/%4s", inliningDecision.callCount, originalInvokeCounter); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
220 String nodes = String.format("%3s/%3s", inliningDecision.profile.nodeCount, profile.nodeCount); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
221 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
222 OUT.printf("[truffle] inlined %-50s |Nodes %6s |Calls %6s |into %s\n", inliningDecision.callSite, nodes, calls, target.getRootNode()); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
223 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
224 return true; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
225 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
226 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
227 return false; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
228 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
229 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
230 private class ProfiledInlinableCallSite { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
231 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
232 final CallTargetProfile profile; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
233 final InlinableCallSite callSite; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
234 final int callCount; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
235 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
236 public ProfiledInlinableCallSite(CallTargetProfile profile, InlinableCallSite callSite) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
237 this.profile = profile; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
238 this.callSite = callSite; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
239 this.callCount = callSite.getCallCount(); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
240 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
241 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
242 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
243 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
244 private class CallTargetProfile { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
245 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
246 final Node root; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
247 final int nodeCount; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
248 final List<Node> inlinableCallSites = new ArrayList<>(); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
249 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
250 public CallTargetProfile(Node rootNode) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
251 root = rootNode; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
252 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
253 VisitorImpl impl = new VisitorImpl(); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
254 root.accept(impl); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
255 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
256 this.nodeCount = impl.visitedCount; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
257 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
258 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
259 private class VisitorImpl implements NodeVisitor { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
260 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
261 int visitedCount; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
262 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
263 @Override |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
264 public boolean visit(Node node) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
265 if (node instanceof RootNode && node != root) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
266 return false; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
267 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
268 |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
269 if (node instanceof InlinableCallSite) { |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
270 inlinableCallSites.add(node); |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
271 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
272 visitedCount++; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
273 return true; |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
274 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
275 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
276 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
277 } |
0097fb11c16f
Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
278 } |