annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ForeignCallStub.java @ 12045:0fc653a9e019

made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
author Doug Simon <doug.simon@oracle.com>
date Thu, 10 Oct 2013 20:50:54 +0200
parents 23ccaa863eda
children 0afe7370260c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.hotspot.stubs;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
25 import static com.oracle.graal.api.code.CallingConvention.Type.*;
9659
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
26 import static com.oracle.graal.api.meta.MetaUtil.*;
9740
c4b1aa93b9af rename: HotSpotRuntimeCallTarget -> HotSpotForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9737
diff changeset
27 import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.RegisterEffect.*;
c4b1aa93b9af rename: HotSpotRuntimeCallTarget -> HotSpotForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9737
diff changeset
28 import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.Transition.*;
9872
4391fd907278 use StubForeignCallNode within stubs, instead of ForeignCallNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 9832
diff changeset
29 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
31 import java.lang.reflect.*;
11700
528ab536b403 changed iteration over InvokeNodes in a graph to avoid Graph.getNodes() (GRAAL-471)
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
32 import java.util.*;
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.api.code.*;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.api.meta.*;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.debug.*;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.hotspot.*;
9743
590e157cf4d4 rename: RuntimeCallStub -> ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9742
diff changeset
38 import com.oracle.graal.hotspot.HotSpotForeignCallLinkage.Transition;
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 import com.oracle.graal.hotspot.meta.*;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 import com.oracle.graal.hotspot.nodes.*;
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
41 import com.oracle.graal.hotspot.replacements.*;
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 import com.oracle.graal.nodes.*;
9690
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
43 import com.oracle.graal.nodes.calc.*;
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 import com.oracle.graal.nodes.java.*;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 import com.oracle.graal.nodes.java.MethodCallTargetNode.InvokeKind;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 import com.oracle.graal.nodes.spi.*;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47 import com.oracle.graal.nodes.type.*;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 import com.oracle.graal.phases.common.*;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49 import com.oracle.graal.replacements.*;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50 import com.oracle.graal.replacements.nodes.*;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51 import com.oracle.graal.word.*;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52 import com.oracle.graal.word.phases.*;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54 /**
9752
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
55 * A {@linkplain #getGraph() generated} stub for a {@link Transition non-leaf} foreign call from
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
56 * compiled code. A stub is required for such calls as the caller may be scheduled for
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
57 * deoptimization while the call is in progress. And since these are foreign/runtime calls on slow
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
58 * paths, we don't want to force the register allocator to spill around the call. As such, this stub
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
59 * saves and restores all allocatable registers. It also
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
60 * {@linkplain StubUtil#handlePendingException(boolean) handles} any exceptions raised during the
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
61 * foreign call.
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 */
9743
590e157cf4d4 rename: RuntimeCallStub -> ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9742
diff changeset
63 public class ForeignCallStub extends Stub {
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
64
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
65 /**
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
66 * The target of the call.
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
67 */
9740
c4b1aa93b9af rename: HotSpotRuntimeCallTarget -> HotSpotForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9737
diff changeset
68 private final HotSpotForeignCallLinkage target;
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70 /**
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 * Specifies if the JavaThread value for the current thread is to be prepended to the arguments
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 * for the call to {@link #target}.
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 */
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 protected final boolean prependThread;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
76 /**
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 * Creates a stub for a call to code at a given address.
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
78 *
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
79 * @param address the address of the code to call
9747
8e5461c4c82e replaced NewMultiArrayStub use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9746
diff changeset
80 * @param descriptor the signature of the call to this stub
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81 * @param prependThread true if the JavaThread value for the current thread is to be prepended
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
82 * to the arguments for the call to {@code address}
9793
b4f12c603be5 added support for the runtime to specify for each foreign call whether it is re-executable and what memory locations it kills
Doug Simon <doug.simon@oracle.com>
parents: 9752
diff changeset
83 * @param reexecutable specifies if the stub call can be re-executed without (meaningful) side
b4f12c603be5 added support for the runtime to specify for each foreign call whether it is re-executable and what memory locations it kills
Doug Simon <doug.simon@oracle.com>
parents: 9752
diff changeset
84 * effects. Deoptimization will not return to a point before a stub call that cannot
b4f12c603be5 added support for the runtime to specify for each foreign call whether it is re-executable and what memory locations it kills
Doug Simon <doug.simon@oracle.com>
parents: 9752
diff changeset
85 * be re-executed.
b4f12c603be5 added support for the runtime to specify for each foreign call whether it is re-executable and what memory locations it kills
Doug Simon <doug.simon@oracle.com>
parents: 9752
diff changeset
86 * @param killedLocations the memory locations killed by the stub call
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
87 */
10666
9808158cfeab Allow foreign call stubs to be declared as leaf methods.
Roland Schatz <roland.schatz@oracle.com>
parents: 9872
diff changeset
88 public ForeignCallStub(HotSpotRuntime runtime, Replacements replacements, long address, ForeignCallDescriptor descriptor, boolean prependThread, Transition transition, boolean reexecutable,
9793
b4f12c603be5 added support for the runtime to specify for each foreign call whether it is re-executable and what memory locations it kills
Doug Simon <doug.simon@oracle.com>
parents: 9752
diff changeset
89 LocationIdentity... killedLocations) {
10870
886c2df7a7e4 Stubs need both an outgoing and incoming calling convention.
twisti
parents: 10666
diff changeset
90 super(runtime, replacements, HotSpotForeignCallLinkage.create(descriptor, 0L, PRESERVES_REGISTERS, JavaCall, JavaCallee, transition, reexecutable, killedLocations));
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
91 this.prependThread = prependThread;
9747
8e5461c4c82e replaced NewMultiArrayStub use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9746
diff changeset
92 Class[] targetParameterTypes = createTargetParameters(descriptor);
8e5461c4c82e replaced NewMultiArrayStub use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9746
diff changeset
93 ForeignCallDescriptor targetSig = new ForeignCallDescriptor(descriptor.getName() + ":C", descriptor.getResultType(), targetParameterTypes);
10870
886c2df7a7e4 Stubs need both an outgoing and incoming calling convention.
twisti
parents: 10666
diff changeset
94 target = HotSpotForeignCallLinkage.create(targetSig, address, DESTROYS_REGISTERS, NativeCall, NativeCall, transition, reexecutable, killedLocations);
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
95 }
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
96
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
97 /**
9743
590e157cf4d4 rename: RuntimeCallStub -> ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9742
diff changeset
98 * Gets the linkage information for the call from this stub.
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
99 */
9740
c4b1aa93b9af rename: HotSpotRuntimeCallTarget -> HotSpotForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9737
diff changeset
100 public HotSpotForeignCallLinkage getTargetLinkage() {
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
101 return target;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
102 }
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
103
9747
8e5461c4c82e replaced NewMultiArrayStub use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9746
diff changeset
104 private Class[] createTargetParameters(ForeignCallDescriptor descriptor) {
8e5461c4c82e replaced NewMultiArrayStub use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9746
diff changeset
105 Class[] parameters = descriptor.getArgumentTypes();
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
106 if (prependThread) {
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
107 Class[] newParameters = new Class[parameters.length + 1];
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
108 System.arraycopy(parameters, 0, newParameters, 1, parameters.length);
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
109 newParameters[0] = Word.class;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
110 return newParameters;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
111 }
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
112 return parameters;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
113 }
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
114
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
115 @Override
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
116 protected ResolvedJavaMethod getInstalledCodeOwner() {
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
117 return null;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
118 }
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
119
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
120 @Override
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
121 protected Object debugScopeContext() {
9659
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
122 return new JavaMethod() {
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
123
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
124 public Signature getSignature() {
9735
2e4f035186cf rename: Descriptor -> ForeignCallDescriptor
Doug Simon <doug.simon@oracle.com>
parents: 9731
diff changeset
125 ForeignCallDescriptor d = linkage.getDescriptor();
9659
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
126 Class<?>[] arguments = d.getArgumentTypes();
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
127 JavaType[] parameters = new JavaType[arguments.length];
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
128 for (int i = 0; i < arguments.length; i++) {
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
129 parameters[i] = runtime.lookupJavaType(arguments[i]);
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
130 }
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
131 return new HotSpotSignature(runtime.lookupJavaType(d.getResultType()), parameters);
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
132 }
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
133
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
134 public String getName() {
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
135 return linkage.getDescriptor().getName();
9659
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
136 }
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
137
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
138 public JavaType getDeclaringClass() {
9743
590e157cf4d4 rename: RuntimeCallStub -> ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9742
diff changeset
139 return runtime.lookupJavaType(ForeignCallStub.class);
9659
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
140 }
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
141
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
142 @Override
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
143 public String toString() {
9752
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
144 return format("ForeignCallStub<%n(%p)>", this);
9659
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
145 }
c5b1b4dcc094 create fake JavaMethod for non-snippet stubs so that -G:MethodFilter can be applied to them
Doug Simon <doug.simon@oracle.com>
parents: 9655
diff changeset
146 };
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
147 }
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
148
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
149 static class GraphBuilder {
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
150
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
151 public GraphBuilder(Stub stub) {
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
152 this.graph = new StructuredGraph(stub.toString(), null);
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
153 graph.replaceFixed(graph.start(), graph.add(new StubStartNode(stub)));
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
154 this.lastFixedNode = graph.start();
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
155 }
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
156
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
157 final StructuredGraph graph;
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
158 private FixedWithNextNode lastFixedNode;
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
159
9690
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
160 <T extends FloatingNode> T add(T node) {
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
161 return graph.unique(node);
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
162 }
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
163
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
164 <T extends FixedNode> T append(T node) {
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
165 T result = graph.add(node);
9690
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
166 assert lastFixedNode != null;
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
167 assert result.predecessor() == null;
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
168 graph.addAfterFixed(lastFixedNode, result);
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
169 if (result instanceof FixedWithNextNode) {
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
170 lastFixedNode = (FixedWithNextNode) result;
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
171 } else {
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
172 lastFixedNode = null;
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
173 }
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
174 return result;
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
175 }
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
176 }
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
177
9752
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
178 /**
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
179 * Creates a graph for this stub.
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
180 * <p>
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
181 * If the stub returns an object, the graph created corresponds to this pseudo code:
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
182 *
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
183 * <pre>
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
184 * Object foreignFunctionStub(args...) {
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
185 * foreignFunction(currentThread, args);
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
186 * if (clearPendingException(thread())) {
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
187 * getAndClearObjectResult(thread());
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
188 * DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint);
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
189 * }
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
190 * return verifyObject(getAndClearObjectResult(thread()));
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
191 * }
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
192 * </pre>
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
193 *
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
194 * If the stub returns a primitive or word, the graph created corresponds to this pseudo code
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
195 * (using {@code int} as the primitive return type):
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
196 *
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
197 * <pre>
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
198 * int foreignFunctionStub(args...) {
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
199 * int result = foreignFunction(currentThread, args);
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
200 * if (clearPendingException(thread())) {
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
201 * DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint);
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
202 * }
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
203 * return result;
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
204 * }
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
205 * </pre>
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
206 *
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
207 * If the stub is void, the graph created corresponds to this pseudo code:
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
208 *
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
209 * <pre>
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
210 * void foreignFunctionStub(args...) {
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
211 * foreignFunction(currentThread, args);
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
212 * if (clearPendingException(thread())) {
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
213 * DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint);
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
214 * }
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
215 * }
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
216 * </pre>
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
217 *
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
218 * In each example above, the {@code currentThread} argument is the C++ JavaThread value (i.e.,
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
219 * %r15 on AMD64) and is only prepended if {@link #prependThread} is true.
82689c1c0dab replaced VMErrorStub with use of ForeignCallStub
Doug Simon <doug.simon@oracle.com>
parents: 9747
diff changeset
220 */
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
221 @Override
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
222 protected StructuredGraph getGraph() {
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
223 Class<?>[] args = linkage.getDescriptor().getArgumentTypes();
10870
886c2df7a7e4 Stubs need both an outgoing and incoming calling convention.
twisti
parents: 10666
diff changeset
224 boolean isObjectResult = linkage.getOutgoingCallingConvention().getReturn().getKind() == Kind.Object;
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
225 GraphBuilder builder = new GraphBuilder(this);
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
226 LocalNode[] locals = createLocals(builder, args);
11700
528ab536b403 changed iteration over InvokeNodes in a graph to avoid Graph.getNodes() (GRAAL-471)
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
227 List<InvokeNode> invokes = new ArrayList<>(3);
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
228
9690
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
229 ReadRegisterNode thread = prependThread || isObjectResult ? builder.append(new ReadRegisterNode(runtime.threadRegister(), true, false)) : null;
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
230 ValueNode result = createTargetCall(builder, locals, thread);
11700
528ab536b403 changed iteration over InvokeNodes in a graph to avoid Graph.getNodes() (GRAAL-471)
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
231 invokes.add(createInvoke(builder, StubUtil.class, "handlePendingException", ConstantNode.forBoolean(isObjectResult, builder.graph)));
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
232 if (isObjectResult) {
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
233 InvokeNode object = createInvoke(builder, HotSpotReplacementsUtil.class, "getAndClearObjectResult", thread);
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
234 result = createInvoke(builder, StubUtil.class, "verifyObject", object);
11700
528ab536b403 changed iteration over InvokeNodes in a graph to avoid Graph.getNodes() (GRAAL-471)
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
235 invokes.add(object);
528ab536b403 changed iteration over InvokeNodes in a graph to avoid Graph.getNodes() (GRAAL-471)
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
236 invokes.add((InvokeNode) result);
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
237 }
9694
Doug Simon <doug.simon@oracle.com>
parents: 9693 9690
diff changeset
238 builder.append(new ReturnNode(linkage.getDescriptor().getResultType() == void.class ? null : result));
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
239
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
240 if (Debug.isDumpEnabled()) {
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
241 Debug.dump(builder.graph, "Initial stub graph");
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
242 }
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
243
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11688
diff changeset
244 /* Rewrite all word types that can come in from the method argument types. */
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11688
diff changeset
245 new WordTypeRewriterPhase(runtime, wordKind()).apply(builder.graph);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11688
diff changeset
246 /* Inline all method calls that are create above. */
11700
528ab536b403 changed iteration over InvokeNodes in a graph to avoid Graph.getNodes() (GRAAL-471)
Doug Simon <doug.simon@oracle.com>
parents: 11698
diff changeset
247 for (InvokeNode invoke : invokes) {
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
248 inline(invoke);
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
249 }
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11688
diff changeset
250 /* Clean up all code that is now dead after inlining. */
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11688
diff changeset
251 new DeadCodeEliminationPhase().apply(builder.graph);
11688
0d3b767e5356 removed the IterableNodeType marker interface from InvokeNode (GRAAL-471)
Doug Simon <doug.simon@oracle.com>
parents: 10870
diff changeset
252 assert builder.graph.getNodes().filter(InvokeNode.class).isEmpty();
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
253
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
254 if (Debug.isDumpEnabled()) {
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
255 Debug.dump(builder.graph, "Stub graph before compilation");
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
256 }
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
257
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
258 return builder.graph;
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
259 }
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
260
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
261 private LocalNode[] createLocals(GraphBuilder builder, Class<?>[] args) {
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
262 LocalNode[] locals = new LocalNode[args.length];
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
263 ResolvedJavaType accessingClass = runtime.lookupJavaType(getClass());
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
264 for (int i = 0; i < args.length; i++) {
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
265 ResolvedJavaType type = runtime.lookupJavaType(args[i]).resolve(accessingClass);
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
266 Kind kind = type.getKind().getStackKind();
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
267 Stamp stamp;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
268 if (kind == Kind.Object) {
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
269 stamp = StampFactory.declared(type);
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
270 } else {
9832
1c4bef4568a8 create correct stamps for LocalNodes
Lukas Stadler <lukas.stadler@jku.at>
parents: 9793
diff changeset
271 stamp = StampFactory.forKind(type.getKind());
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
272 }
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
273 LocalNode local = builder.add(new LocalNode(i, stamp));
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
274 locals[i] = local;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
275 }
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
276 return locals;
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
277 }
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
278
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
279 private InvokeNode createInvoke(GraphBuilder builder, Class<?> declaringClass, String name, ValueNode... hpeArgs) {
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
280 ResolvedJavaMethod method = null;
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
281 for (Method m : declaringClass.getDeclaredMethods()) {
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
282 if (Modifier.isStatic(m.getModifiers()) && m.getName().equals(name)) {
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
283 assert method == null : "found more than one method in " + declaringClass + " named " + name;
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
284 method = runtime.lookupJavaMethod(m);
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
285 }
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
286 }
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
287 assert method != null : "did not find method in " + declaringClass + " named " + name;
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
288 JavaType returnType = method.getSignature().getReturnType(null);
9690
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
289 MethodCallTargetNode callTarget = builder.graph.add(new MethodCallTargetNode(InvokeKind.Static, method, hpeArgs, returnType));
a7f10828c4ff distinguish floating and fixed nodes when building a stub graph
Doug Simon <doug.simon@oracle.com>
parents: 9675
diff changeset
290 InvokeNode invoke = builder.append(new InvokeNode(callTarget, FrameState.UNKNOWN_BCI));
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
291 return invoke;
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
292 }
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
293
9872
4391fd907278 use StubForeignCallNode within stubs, instead of ForeignCallNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 9832
diff changeset
294 private StubForeignCallNode createTargetCall(GraphBuilder builder, LocalNode[] locals, ReadRegisterNode thread) {
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
295 if (prependThread) {
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
296 ValueNode[] targetArguments = new ValueNode[1 + locals.length];
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
297 targetArguments[0] = thread;
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
298 System.arraycopy(locals, 0, targetArguments, 1, locals.length);
9872
4391fd907278 use StubForeignCallNode within stubs, instead of ForeignCallNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 9832
diff changeset
299 return builder.append(new StubForeignCallNode(runtime, target.getDescriptor(), targetArguments));
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
300 } else {
9872
4391fd907278 use StubForeignCallNode within stubs, instead of ForeignCallNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 9832
diff changeset
301 return builder.append(new StubForeignCallNode(runtime, target.getDescriptor(), locals));
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
302 }
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
303 }
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
304
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
305 private void inline(InvokeNode invoke) {
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
306 ResolvedJavaMethod method = ((MethodCallTargetNode) invoke.callTarget()).targetMethod();
12045
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
307 ReplacementsImpl repl = new ReplacementsImpl(runtime, runtime, runtime, new Assumptions(false), runtime.getTarget());
11870
a80d09922fc1 new parameter on Snippet annotation to remove all frame states
Lukas Stadler <lukas.stadler@jku.at>
parents: 11700
diff changeset
308 StructuredGraph calleeGraph = repl.makeGraph(method, null, null, false);
9673
37ec49e1d7e2 extended RuntimeCallStub to support calls returning an Object
Doug Simon <doug.simon@oracle.com>
parents: 9659
diff changeset
309 InliningUtil.inline(invoke, calleeGraph, false);
9655
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
310 }
0a771345825b added RuntimeCallStub for runtime calls that require no extra/special logic in the stub itself
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
311 }