annotate graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java @ 12529:23dc5dfdb9c7

Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
author Matthias Grimmer <grimmer@ssw.jku.at>
date Tue, 22 Oct 2013 13:25:37 +0200
parents dca16d6f9d65
children 7d5c3ffbee64
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
12529
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
25 import static com.oracle.graal.api.code.CodeUtil.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26 import static com.oracle.graal.truffle.TruffleCompilerOptions.*;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27
12529
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
28 import java.lang.reflect.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 import java.util.*;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30
12529
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
31 import com.oracle.graal.api.code.*;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
32 import com.oracle.graal.api.code.CallingConvention.Type;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
33 import com.oracle.graal.api.meta.*;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
34 import com.oracle.graal.api.runtime.*;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
35 import com.oracle.graal.compiler.*;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
36 import com.oracle.graal.compiler.target.*;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
37 import com.oracle.graal.graph.*;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
38 import com.oracle.graal.java.*;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
39 import com.oracle.graal.nodes.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 import com.oracle.graal.nodes.spi.*;
12529
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
41 import com.oracle.graal.phases.*;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
42 import com.oracle.graal.phases.PhasePlan.PhasePosition;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
43 import com.oracle.graal.phases.common.*;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
44 import com.oracle.graal.phases.tiers.*;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
45 import com.oracle.graal.phases.util.*;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
46 import com.oracle.graal.runtime.*;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 import com.oracle.truffle.api.*;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 import com.oracle.truffle.api.frame.*;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 import com.oracle.truffle.api.impl.*;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 import com.oracle.truffle.api.nodes.*;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 /**
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 * Implementation of the Truffle runtime when running on top of Graal.
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 */
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 public final class GraalTruffleRuntime implements TruffleRuntime {
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 public static GraalTruffleRuntime makeInstance() {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 return new GraalTruffleRuntime();
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 private TruffleCompiler truffleCompiler;
10529
254fab64b343 Separate replacements for Truffle compilation
Andreas Woess <andreas.woess@jku.at>
parents: 10484
diff changeset
62 private Replacements truffleReplacements;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 private ArrayList<String> includes;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 private ArrayList<String> excludes;
12529
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
65 private final CodeCacheProvider codeCacheProvider;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
66 private final ResolvedJavaMethod callMethod;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
67 private final CompilationResult callCompilationResult;
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 private GraalTruffleRuntime() {
12529
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
70 Providers providers = getGraalProviders();
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
71 MetaAccessProvider metaAccess = providers.getMetaAccess();
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
72 codeCacheProvider = providers.getCodeCache();
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
73 callMethod = metaAccess.lookupJavaMethod(getCallMethod());
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
74 callCompilationResult = compileMethod(callMethod, providers);
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
75 installOptimizedCallTargetCallMethod();
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
77
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 public String getName() {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
79 return "Graal Truffle Runtime";
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80 }
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 public CallTarget createCallTarget(RootNode rootNode) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 return createCallTarget(rootNode, new FrameDescriptor());
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 @Override
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 public CallTarget createCallTarget(RootNode rootNode, FrameDescriptor frameDescriptor) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 if (!acceptForCompilation(rootNode)) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 return new DefaultCallTarget(rootNode, frameDescriptor);
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 if (truffleCompiler == null) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92 truffleCompiler = new TruffleCompilerImpl();
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 }
11643
2bd626188d31 Introduce TruffleMinInvokeThreshold flag.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10752
diff changeset
94 return new OptimizedCallTarget(rootNode, frameDescriptor, truffleCompiler, TruffleMinInvokeThreshold.getValue(), TruffleCompilationThreshold.getValue());
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
97 @Override
11934
dca16d6f9d65 TruffleRuntime.createVirtualFrame.
Chris Seaton <chris.seaton@oracle.com>
parents: 11643
diff changeset
98 public VirtualFrame createVirtualFrame(PackedFrame caller, Arguments arguments, FrameDescriptor frameDescriptor) {
dca16d6f9d65 TruffleRuntime.createVirtualFrame.
Chris Seaton <chris.seaton@oracle.com>
parents: 11643
diff changeset
99 return OptimizedCallTarget.createFrame(frameDescriptor, caller, arguments);
dca16d6f9d65 TruffleRuntime.createVirtualFrame.
Chris Seaton <chris.seaton@oracle.com>
parents: 11643
diff changeset
100 }
dca16d6f9d65 TruffleRuntime.createVirtualFrame.
Chris Seaton <chris.seaton@oracle.com>
parents: 11643
diff changeset
101
dca16d6f9d65 TruffleRuntime.createVirtualFrame.
Chris Seaton <chris.seaton@oracle.com>
parents: 11643
diff changeset
102 @Override
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 public MaterializedFrame createMaterializedFrame(Arguments arguments) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104 return createMaterializedFrame(arguments);
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 @Override
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 public MaterializedFrame createMaterializedFrame(Arguments arguments, FrameDescriptor frameDescriptor) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109 return new FrameWithoutBoxing(frameDescriptor, null, arguments);
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 @Override
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
113 public Assumption createAssumption() {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114 return createAssumption(null);
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
116
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
117 @Override
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
118 public Assumption createAssumption(String name) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
119 return new OptimizedAssumption(name);
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
121
10529
254fab64b343 Separate replacements for Truffle compilation
Andreas Woess <andreas.woess@jku.at>
parents: 10484
diff changeset
122 public Replacements getReplacements() {
254fab64b343 Separate replacements for Truffle compilation
Andreas Woess <andreas.woess@jku.at>
parents: 10484
diff changeset
123 if (truffleReplacements == null) {
254fab64b343 Separate replacements for Truffle compilation
Andreas Woess <andreas.woess@jku.at>
parents: 10484
diff changeset
124 truffleReplacements = TruffleReplacements.makeInstance();
254fab64b343 Separate replacements for Truffle compilation
Andreas Woess <andreas.woess@jku.at>
parents: 10484
diff changeset
125 }
254fab64b343 Separate replacements for Truffle compilation
Andreas Woess <andreas.woess@jku.at>
parents: 10484
diff changeset
126 return truffleReplacements;
254fab64b343 Separate replacements for Truffle compilation
Andreas Woess <andreas.woess@jku.at>
parents: 10484
diff changeset
127 }
254fab64b343 Separate replacements for Truffle compilation
Andreas Woess <andreas.woess@jku.at>
parents: 10484
diff changeset
128
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
129 private boolean acceptForCompilation(RootNode rootNode) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130 if (TruffleCompileOnly.getValue() != null) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
131 if (includes == null) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
132 parseCompileOnly();
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
133 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135 String name = rootNode.toString();
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136 boolean included = includes.isEmpty();
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137 for (int i = 0; !included && i < includes.size(); i++) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 if (name.contains(includes.get(i))) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139 included = true;
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 if (!included) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143 return false;
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 for (String exclude : excludes) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
146 if (name.contains(exclude)) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
147 return false;
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 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
150 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
151 return true;
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
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154 private void parseCompileOnly() {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
155 includes = new ArrayList<>();
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156 excludes = new ArrayList<>();
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 String[] items = TruffleCompileOnly.getValue().split(",");
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
159 for (String item : items) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160 if (item.startsWith("~")) {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161 excludes.add(item.substring(1));
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 } else {
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
163 includes.add(item);
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 }
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 }
12529
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
167
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
168 public void installOptimizedCallTargetCallMethod() {
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
169 codeCacheProvider.addDefaultMethod(callMethod, callCompilationResult);
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
170 }
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
171
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
172 private static Method getCallMethod() {
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
173 Method method;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
174 try {
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
175 method = OptimizedCallTarget.class.getDeclaredMethod("call", new Class[]{PackedFrame.class, Arguments.class});
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
176 } catch (NoSuchMethodException | SecurityException e) {
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
177 throw GraalInternalError.shouldNotReachHere();
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
178 }
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
179 return method;
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
180 }
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
181
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
182 private static CompilationResult compileMethod(ResolvedJavaMethod javaMethod, Providers providers) {
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
183 MetaAccessProvider metaAccess = providers.getMetaAccess();
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
184 Suites suites = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getSuites().createSuites();
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
185 suites.getHighTier().findPhase(InliningPhase.class).remove();
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
186 StructuredGraph graph = new StructuredGraph(javaMethod);
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
187 ForeignCallsProvider foreignCalls = providers.getForeignCalls();
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
188 new GraphBuilderPhase(metaAccess, foreignCalls, GraphBuilderConfiguration.getEagerDefault(), OptimisticOptimizations.ALL).apply(graph);
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
189 PhasePlan phasePlan = new PhasePlan();
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
190 GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(metaAccess, foreignCalls, GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.ALL);
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
191 phasePlan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase);
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
192 CallingConvention cc = getCallingConvention(providers.getCodeCache(), Type.JavaCallee, graph.method(), false);
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
193 Backend backend = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend();
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
194 return GraalCompiler.compileGraph(graph, cc, javaMethod, providers, backend, providers.getCodeCache().getTarget(), null, phasePlan, OptimisticOptimizations.ALL, new SpeculationLog(), suites,
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
195 new CompilationResult());
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
196 }
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
197
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
198 private static Providers getGraalProviders() {
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
199 RuntimeProvider runtimeProvider = Graal.getRequiredCapability(RuntimeProvider.class);
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
200 return runtimeProvider.getHostBackend().getProviders();
23dc5dfdb9c7 Add OptimizedCallTarget.call(PackedFrame, Arguments) frame prologue injection
Matthias Grimmer <grimmer@ssw.jku.at>
parents: 11934
diff changeset
201 }
10484
0097fb11c16f Add basic version of Graal's Truffle runtime.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
202 }