1 /*
2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.hotspot.meta;
26
27 import static jdk.vm.ci.hotspot.HotSpotCallingConventionType.JavaCall;
28 import static jdk.vm.ci.hotspot.HotSpotCallingConventionType.JavaCallee;
29 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect.PRESERVES_REGISTERS;
30 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.SAFEPOINT;
31
32 import java.util.ArrayList;
33 import java.util.List;
34
35 import jdk.internal.vm.compiler.collections.EconomicMap;
36 import org.graalvm.compiler.core.common.LIRKind;
37 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
38 import org.graalvm.compiler.debug.GraalError;
39 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
40 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Reexecutability;
41 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect;
42 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition;
43 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkageImpl;
44 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
45 import org.graalvm.compiler.hotspot.stubs.ForeignCallStub;
46 import org.graalvm.compiler.hotspot.stubs.Stub;
47 import org.graalvm.compiler.options.OptionValues;
48 import org.graalvm.compiler.word.Word;
49 import org.graalvm.compiler.word.WordTypes;
97 * Return true if the descriptor has already been registered.
98 */
99 public boolean isRegistered(ForeignCallDescriptor descriptor) {
100 return foreignCalls.containsKey(descriptor);
101 }
102
103 /**
104 * Creates and registers the details for linking a foreign call to a {@link Stub}.
105 *
106 * @param descriptor the signature of the call to the stub
107 * @param transition specifies if this is a {@linkplain Transition#LEAF leaf} call
108 * @param reexecutability specifies if the stub call can be re-executed without (meaningful)
109 * side effects. Deoptimization will not return to a point before a stub call that
110 * cannot be re-executed.
111 * @param killedLocations the memory locations killed by the stub call
112 */
113 public HotSpotForeignCallLinkage registerStubCall(
114 ForeignCallDescriptor descriptor,
115 Transition transition,
116 Reexecutability reexecutability,
117 LocationIdentity... killedLocations) {
118 return register(HotSpotForeignCallLinkageImpl.create(metaAccess,
119 codeCache,
120 wordTypes,
121 this,
122 descriptor,
123 0L, PRESERVES_REGISTERS,
124 JavaCall,
125 JavaCallee,
126 transition,
127 reexecutability,
128 killedLocations));
129 }
130
131 /**
132 * Creates and registers the linkage for a foreign call.
133 *
134 * @param descriptor the signature of the foreign call
135 * @param address the address of the code to call (must be non-zero)
136 * @param outgoingCcType outgoing (caller) calling convention type
137 * @param effect specifies if the call destroys or preserves all registers (apart from
138 * temporaries which are always destroyed)
139 * @param transition specifies if this is a {@linkplain Transition#LEAF leaf} call
140 * @param reexecutability specifies if the foreign call can be re-executed without (meaningful)
141 * side effects. Deoptimization will not return to a point before a foreign call that
142 * cannot be re-executed.
143 * @param killedLocations the memory locations killed by the foreign call
144 */
145 public HotSpotForeignCallLinkage registerForeignCall(
146 ForeignCallDescriptor descriptor,
147 long address,
148 CallingConvention.Type outgoingCcType,
149 RegisterEffect effect,
150 Transition transition,
151 Reexecutability reexecutability,
152 LocationIdentity... killedLocations) {
153 Class<?> resultType = descriptor.getResultType();
154 assert address != 0 : descriptor;
155 assert transition != SAFEPOINT || resultType.isPrimitive() || Word.class.isAssignableFrom(resultType) : "non-leaf foreign calls must return objects in thread local storage: " + descriptor;
156 return register(HotSpotForeignCallLinkageImpl.create(metaAccess,
157 codeCache,
158 wordTypes,
159 this,
160 descriptor,
161 address,
162 effect,
163 outgoingCcType,
164 null, // incomingCcType
165 transition,
166 reexecutability,
167 killedLocations));
168 }
169
170 /**
171 * Creates a {@linkplain ForeignCallStub stub} for the foreign call described by
172 * {@code descriptor} if {@code address != 0}.
173 *
174 * @param descriptor the signature of the call to the stub
175 * @param address the address of the foreign code to call
176 * @param prependThread true if the JavaThread value for the current thread is to be prepended
177 * to the arguments for the call to {@code address}
178 * @param transition specifies if this is a {@linkplain Transition#LEAF leaf} call
179 * @param reexecutability specifies if the foreign call can be re-executed without (meaningful)
180 * side effects. Deoptimization will not return to a point before a foreign call that
181 * cannot be re-executed.
182 * @param killedLocations the memory locations killed by the foreign call
|
1 /*
2 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.hotspot.meta;
26
27 import static jdk.vm.ci.hotspot.HotSpotCallingConventionType.JavaCall;
28 import static jdk.vm.ci.hotspot.HotSpotCallingConventionType.JavaCallee;
29 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect.DESTROYS_ALL_CALLER_SAVE_REGISTERS;
30 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.SAFEPOINT;
31
32 import java.util.ArrayList;
33 import java.util.List;
34
35 import jdk.internal.vm.compiler.collections.EconomicMap;
36 import org.graalvm.compiler.core.common.LIRKind;
37 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
38 import org.graalvm.compiler.debug.GraalError;
39 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
40 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Reexecutability;
41 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect;
42 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition;
43 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkageImpl;
44 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
45 import org.graalvm.compiler.hotspot.stubs.ForeignCallStub;
46 import org.graalvm.compiler.hotspot.stubs.Stub;
47 import org.graalvm.compiler.options.OptionValues;
48 import org.graalvm.compiler.word.Word;
49 import org.graalvm.compiler.word.WordTypes;
97 * Return true if the descriptor has already been registered.
98 */
99 public boolean isRegistered(ForeignCallDescriptor descriptor) {
100 return foreignCalls.containsKey(descriptor);
101 }
102
103 /**
104 * Creates and registers the details for linking a foreign call to a {@link Stub}.
105 *
106 * @param descriptor the signature of the call to the stub
107 * @param transition specifies if this is a {@linkplain Transition#LEAF leaf} call
108 * @param reexecutability specifies if the stub call can be re-executed without (meaningful)
109 * side effects. Deoptimization will not return to a point before a stub call that
110 * cannot be re-executed.
111 * @param killedLocations the memory locations killed by the stub call
112 */
113 public HotSpotForeignCallLinkage registerStubCall(
114 ForeignCallDescriptor descriptor,
115 Transition transition,
116 Reexecutability reexecutability,
117 RegisterEffect effect,
118 LocationIdentity... killedLocations) {
119 return register(HotSpotForeignCallLinkageImpl.create(metaAccess,
120 codeCache,
121 wordTypes,
122 this,
123 descriptor,
124 0L, effect,
125 JavaCall,
126 JavaCallee,
127 transition,
128 reexecutability,
129 killedLocations));
130 }
131
132 /**
133 * Creates and registers the linkage for a foreign call. All foreign calls are assumed to have
134 * the effect {@link RegisterEffect#DESTROYS_ALL_CALLER_SAVE_REGISTERS} since they are outside
135 * of Graal's knowledge.
136 *
137 * @param descriptor the signature of the foreign call
138 * @param address the address of the code to call (must be non-zero)
139 * @param outgoingCcType outgoing (caller) calling convention type
140 * @param transition specifies if this is a {@linkplain Transition#LEAF leaf} call
141 * @param reexecutability specifies if the foreign call can be re-executed without (meaningful)
142 * side effects. Deoptimization will not return to a point before a foreign call that
143 * cannot be re-executed.
144 * @param killedLocations the memory locations killed by the foreign call
145 */
146 public HotSpotForeignCallLinkage registerForeignCall(
147 ForeignCallDescriptor descriptor,
148 long address,
149 CallingConvention.Type outgoingCcType,
150 Transition transition,
151 Reexecutability reexecutability,
152 LocationIdentity... killedLocations) {
153 Class<?> resultType = descriptor.getResultType();
154 assert address != 0 : descriptor;
155 assert transition != SAFEPOINT || resultType.isPrimitive() || Word.class.isAssignableFrom(resultType) : "non-leaf foreign calls must return objects in thread local storage: " + descriptor;
156 return register(HotSpotForeignCallLinkageImpl.create(metaAccess,
157 codeCache,
158 wordTypes,
159 this,
160 descriptor,
161 address,
162 DESTROYS_ALL_CALLER_SAVE_REGISTERS,
163 outgoingCcType,
164 null, // incomingCcType
165 transition,
166 reexecutability,
167 killedLocations));
168 }
169
170 /**
171 * Creates a {@linkplain ForeignCallStub stub} for the foreign call described by
172 * {@code descriptor} if {@code address != 0}.
173 *
174 * @param descriptor the signature of the call to the stub
175 * @param address the address of the foreign code to call
176 * @param prependThread true if the JavaThread value for the current thread is to be prepended
177 * to the arguments for the call to {@code address}
178 * @param transition specifies if this is a {@linkplain Transition#LEAF leaf} call
179 * @param reexecutability specifies if the foreign call can be re-executed without (meaningful)
180 * side effects. Deoptimization will not return to a point before a foreign call that
181 * cannot be re-executed.
182 * @param killedLocations the memory locations killed by the foreign call
|