annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkage.java @ 9742:cff1e11941c0

moved temporaries from CallingConvention to ForeignCallLinkage
author Doug Simon <doug.simon@oracle.com>
date Thu, 16 May 2013 18:05:30 +0200
parents c4b1aa93b9af
children 590e157cf4d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.hotspot;
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
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: 9617
diff changeset
25 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
9740
c4b1aa93b9af rename: HotSpotRuntimeCallTarget -> HotSpotForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9739
diff changeset
26 import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.RegisterEffect.*;
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
27
9200
9be78aeab2e1 temporaries are recorded for compiled stubs, allowing for better register allocation around calls to such stubs (GRAAL-210)
Doug Simon <doug.simon@oracle.com>
parents: 8969
diff changeset
28 import java.util.*;
9be78aeab2e1 temporaries are recorded for compiled stubs, allowing for better register allocation around calls to such stubs (GRAAL-210)
Doug Simon <doug.simon@oracle.com>
parents: 8969
diff changeset
29
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.api.code.*;
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
31 import com.oracle.graal.api.code.CallingConvention.Type;
7143
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 6534
diff changeset
32 import com.oracle.graal.api.meta.*;
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 7814
diff changeset
33 import com.oracle.graal.compiler.target.*;
9742
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
34 import com.oracle.graal.debug.*;
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
35 import com.oracle.graal.hotspot.meta.*;
7143
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 6534
diff changeset
36 import com.oracle.graal.hotspot.stubs.*;
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
37 import com.oracle.graal.word.*;
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
38
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 /**
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 * The details required to link a HotSpot runtime or stub call.
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41 */
9740
c4b1aa93b9af rename: HotSpotRuntimeCallTarget -> HotSpotForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9739
diff changeset
42 public class HotSpotForeignCallLinkage implements ForeignCallLinkage, InvokeTarget {
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 /**
9742
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
45 * Constants for specifying whether a foreign call destroys or preserves registers. A foreign
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
46 * call will always destroy {@link HotSpotForeignCallLinkage#getCallingConvention() its}
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
47 * {@linkplain ForeignCallLinkage#getTemporaries() temporary} registers.
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
48 */
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
49 public enum RegisterEffect {
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
50 DESTROYS_REGISTERS, PRESERVES_REGISTERS
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
51 }
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
52
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
53 /**
9731
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
54 * Constants for specifying whether a call is a leaf or not. A leaf function does not lock, GC
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
55 * or throw exceptions. That is, the thread's execution state during the call is never inspected
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
56 * by another thread.
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
57 */
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
58 public enum Transition {
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
59 LEAF, NOT_LEAF;
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
60 }
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
61
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
62 /**
9562
99ef9bcb3f32 replaced unwind_exception_call assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 9491
diff changeset
63 * Sentinel marker for a computed jump address.
99ef9bcb3f32 replaced unwind_exception_call assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 9491
diff changeset
64 */
99ef9bcb3f32 replaced unwind_exception_call assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 9491
diff changeset
65 public static final long JUMP_ADDRESS = 0xDEADDEADBEEFBEEFL;
99ef9bcb3f32 replaced unwind_exception_call assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 9491
diff changeset
66
99ef9bcb3f32 replaced unwind_exception_call assembler stub with a compiled stub (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 9491
diff changeset
67 /**
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
68 * The descriptor of the call.
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 */
9735
2e4f035186cf rename: Descriptor -> ForeignCallDescriptor
Doug Simon <doug.simon@oracle.com>
parents: 9731
diff changeset
70 private final ForeignCallDescriptor descriptor;
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 /**
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
73 * The entry point address of this call's target.
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 */
7143
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 6534
diff changeset
75 private long address;
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 6534
diff changeset
76
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 6534
diff changeset
77 /**
9352
d4684b468e93 made NewInstanceStub a RuntimeStub that directly calls the C runtime (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 9296
diff changeset
78 * Non-null (eventually) iff this is a call to a compiled {@linkplain Stub stub}.
7143
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 6534
diff changeset
79 */
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 6534
diff changeset
80 private Stub stub;
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
82 /**
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
83 * The calling convention for this call.
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
84 */
9742
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
85 private final CallingConvention cc;
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
86
9731
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
87 private final RegisterEffect effect;
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
88
9731
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
89 private final Transition transition;
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
90
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
91 /**
9742
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
92 * The locations defined/killed by the call.
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
93 */
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
94 private Value[] temporaries = AllocatableValue.NONE;
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
95
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
96 /**
9740
c4b1aa93b9af rename: HotSpotRuntimeCallTarget -> HotSpotForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9739
diff changeset
97 * Creates a {@link HotSpotForeignCallLinkage}.
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
98 *
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
99 * @param descriptor the descriptor of the call
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
100 * @param address the address of the code to call
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
101 * @param effect specifies if the call destroys or preserves all registers (apart from
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
102 * temporaries which are always destroyed)
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
103 * @param ccType calling convention type
9731
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
104 * @param transition specifies if this is a {@linkplain #isLeaf() leaf} call
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
105 */
9740
c4b1aa93b9af rename: HotSpotRuntimeCallTarget -> HotSpotForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9739
diff changeset
106 public static HotSpotForeignCallLinkage create(ForeignCallDescriptor descriptor, long address, RegisterEffect effect, Type ccType, Transition transition) {
9731
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
107 CallingConvention targetCc = createCallingConvention(descriptor, ccType);
9740
c4b1aa93b9af rename: HotSpotRuntimeCallTarget -> HotSpotForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9739
diff changeset
108 return new HotSpotForeignCallLinkage(descriptor, address, effect, transition, targetCc);
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
109 }
9418
8d3a7fb9eb5f moved binding of parameter locations to runtime call descriptors from platform specific code to shared code for stubs that are now compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9355
diff changeset
110
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
111 /**
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
112 * Gets a calling convention for a given descriptor and call type.
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
113 */
9735
2e4f035186cf rename: Descriptor -> ForeignCallDescriptor
Doug Simon <doug.simon@oracle.com>
parents: 9731
diff changeset
114 public static CallingConvention createCallingConvention(ForeignCallDescriptor descriptor, Type ccType) {
9731
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
115 HotSpotRuntime runtime = graalRuntime().getRuntime();
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
116 Class<?>[] argumentTypes = descriptor.getArgumentTypes();
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
117 JavaType[] parameterTypes = new JavaType[argumentTypes.length];
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
118 for (int i = 0; i < parameterTypes.length; ++i) {
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
119 parameterTypes[i] = asJavaType(argumentTypes[i], runtime);
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
120 }
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
121 TargetDescription target = graalRuntime().getTarget();
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
122 JavaType returnType = asJavaType(descriptor.getResultType(), runtime);
9731
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
123 return runtime.lookupRegisterConfig().getCallingConvention(ccType, returnType, parameterTypes, target, false);
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
124 }
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
125
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
126 private static JavaType asJavaType(Class type, HotSpotRuntime runtime) {
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
127 if (WordBase.class.isAssignableFrom(type)) {
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
128 return runtime.lookupJavaType(wordKind().toJavaClass());
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
129 } else {
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
130 return runtime.lookupJavaType(type);
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
131 }
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
132 }
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
133
9740
c4b1aa93b9af rename: HotSpotRuntimeCallTarget -> HotSpotForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9739
diff changeset
134 public HotSpotForeignCallLinkage(ForeignCallDescriptor descriptor, long address, RegisterEffect effect, Transition transition, CallingConvention cc) {
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
135 this.address = address;
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
136 this.effect = effect;
9731
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
137 this.transition = transition;
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
138 this.descriptor = descriptor;
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
139 this.cc = cc;
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
140 }
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
141
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
142 @Override
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
143 public String toString() {
9742
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
144 StringBuilder sb = new StringBuilder(stub == null ? descriptor.toString() : stub.toString());
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
145 sb.append("@0x").append(Long.toHexString(address)).append(':').append(cc);
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
146 if (temporaries != null && temporaries.length != 0) {
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
147 sb.append("; temps=");
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
148 String sep = "";
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
149 for (Value op : temporaries) {
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
150 sb.append(sep).append(op);
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
151 sep = ",";
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
152 }
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
153 }
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
154 return sb.toString();
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
155 }
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
156
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
157 public CallingConvention getCallingConvention() {
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
158 return cc;
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
159 }
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
160
9742
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
161 public Value[] getTemporaries() {
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
162 if (temporaries.length == 0) {
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
163 return temporaries;
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
164 }
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
165 return temporaries.clone();
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
166 }
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
167
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
168 public long getMaxCallTargetOffset() {
9731
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
169 return graalRuntime().getCompilerToVM().getMaxCallTargetOffset(address);
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
170 }
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
171
9735
2e4f035186cf rename: Descriptor -> ForeignCallDescriptor
Doug Simon <doug.simon@oracle.com>
parents: 9731
diff changeset
172 public ForeignCallDescriptor getDescriptor() {
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
173 return descriptor;
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
174 }
7143
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 6534
diff changeset
175
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
176 public void setCompiledStub(Stub stub) {
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 7814
diff changeset
177 assert address == 0L : "cannot set stub for linkage that already has an address: " + this;
7143
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 6534
diff changeset
178 this.stub = stub;
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 6534
diff changeset
179 }
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 6534
diff changeset
180
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
181 /**
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
182 * Determines if this is a call to a compiled {@linkplain Stub stub}.
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
183 */
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
184 public boolean isCompiledStub() {
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
185 return address == 0L || stub != null;
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
186 }
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
187
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 7814
diff changeset
188 public void finalizeAddress(Backend backend) {
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 7814
diff changeset
189 if (address == 0) {
9418
8d3a7fb9eb5f moved binding of parameter locations to runtime call descriptors from platform specific code to shared code for stubs that are now compiled stubs
Doug Simon <doug.simon@oracle.com>
parents: 9355
diff changeset
190 assert stub != null : "linkage without an address must be a stub - forgot to register a Stub associated with " + descriptor + "?";
9200
9be78aeab2e1 temporaries are recorded for compiled stubs, allowing for better register allocation around calls to such stubs (GRAAL-210)
Doug Simon <doug.simon@oracle.com>
parents: 8969
diff changeset
191 InstalledCode code = stub.getCode(backend);
9be78aeab2e1 temporaries are recorded for compiled stubs, allowing for better register allocation around calls to such stubs (GRAAL-210)
Doug Simon <doug.simon@oracle.com>
parents: 8969
diff changeset
192
9491
789cfd153265 a compiled stub can now specify whether it needs to preserve registers. If a stub does not preserve registers and assertions are enabled, then all non-temporary registers are zapped after a C runtime call from the stub.
Doug Simon <doug.simon@oracle.com>
parents: 9454
diff changeset
193 Set<Register> destroyedRegisters = stub.getDestroyedRegisters();
9742
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
194 if (!destroyedRegisters.isEmpty()) {
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
195 AllocatableValue[] temporaryLocations = new AllocatableValue[destroyedRegisters.size()];
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
196 int i = 0;
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
197 for (Register reg : destroyedRegisters) {
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
198 temporaryLocations[i++] = reg.asValue();
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
199 }
cff1e11941c0 moved temporaries from CallingConvention to ForeignCallLinkage
Doug Simon <doug.simon@oracle.com>
parents: 9740
diff changeset
200 temporaries = temporaryLocations;
9200
9be78aeab2e1 temporaries are recorded for compiled stubs, allowing for better register allocation around calls to such stubs (GRAAL-210)
Doug Simon <doug.simon@oracle.com>
parents: 8969
diff changeset
201 }
9be78aeab2e1 temporaries are recorded for compiled stubs, allowing for better register allocation around calls to such stubs (GRAAL-210)
Doug Simon <doug.simon@oracle.com>
parents: 8969
diff changeset
202 address = code.getStart();
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 7814
diff changeset
203 }
7143
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 6534
diff changeset
204 }
8969
1fa6536416db Runtime calls that do not destroy the caller's registers need no spilling at the call site.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8627
diff changeset
205
9452
c1ba734c1ea0 more extensive checking of compiled stub invariants
Doug Simon <doug.simon@oracle.com>
parents: 9418
diff changeset
206 public long getAddress() {
c1ba734c1ea0 more extensive checking of compiled stub invariants
Doug Simon <doug.simon@oracle.com>
parents: 9418
diff changeset
207 assert address != 0L : "address not yet finalized: " + this;
c1ba734c1ea0 more extensive checking of compiled stub invariants
Doug Simon <doug.simon@oracle.com>
parents: 9418
diff changeset
208 return address;
c1ba734c1ea0 more extensive checking of compiled stub invariants
Doug Simon <doug.simon@oracle.com>
parents: 9418
diff changeset
209 }
c1ba734c1ea0 more extensive checking of compiled stub invariants
Doug Simon <doug.simon@oracle.com>
parents: 9418
diff changeset
210
8969
1fa6536416db Runtime calls that do not destroy the caller's registers need no spilling at the call site.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8627
diff changeset
211 @Override
9454
85a836bcd796 renaming for improved clarity: hasCall -> destroysCallerSavedRegisters
Doug Simon <doug.simon@oracle.com>
parents: 9452
diff changeset
212 public boolean destroysRegisters() {
9693
d04944441454 cleaned up and simplified runtime call mechanisms
Doug Simon <doug.simon@oracle.com>
parents: 9617
diff changeset
213 return effect == DESTROYS_REGISTERS;
9352
d4684b468e93 made NewInstanceStub a RuntimeStub that directly calls the C runtime (GRAAL-81)
Doug Simon <doug.simon@oracle.com>
parents: 9296
diff changeset
214 }
9731
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
215
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
216 /**
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
217 * Determines if this is call to a function that does not lock, GC or throw exceptions. That is,
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
218 * the thread's execution state during the call is never inspected by another thread.
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
219 */
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
220 public boolean isLeaf() {
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
221 return transition == Transition.LEAF;
f7bd4594cbbf added support for declaring a foreign function call to be a leaf
Doug Simon <doug.simon@oracle.com>
parents: 9693
diff changeset
222 }
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
223 }