28
28
import java .util .Arrays ;
29
29
import java .util .Objects ;
30
30
31
- import com .oracle .svm .core .graal .code .AssignedLocation ;
32
-
33
31
import jdk .internal .foreign .abi .ABIDescriptor ;
34
32
import jdk .internal .foreign .abi .VMStorage ;
35
33
36
34
/**
37
35
* Carries information about an entrypoint for foreign function calls.
38
- * {@link ForeignFunctionsRuntime#getStubPointer } allows getting the associated function pointer at
39
- * runtime (if it exists).
36
+ * {@link ForeignFunctionsRuntime#getDowncallStubPointer } allows getting the associated function
37
+ * pointer at runtime (if it exists).
40
38
* <p>
41
- * {@link NativeEntryPointInfo#linkMethodType } is of the form (<>: argument; []: optional argument)
39
+ * {@link NativeEntryPointInfo#methodType } is of the form (<>: argument; []: optional argument)
42
40
*
43
41
* <pre>
44
42
* {@code
50
48
*/
51
49
public final class NativeEntryPointInfo {
52
50
private final MethodType methodType ;
53
- private final AssignedLocation [] parameterAssignments ;
54
- private final AssignedLocation [] returnBuffering ;
51
+ private final VMStorage [] parameterAssignments ;
52
+ private final VMStorage [] returnBuffering ;
53
+ private final boolean needsReturnBuffer ;
55
54
private final boolean capturesState ;
56
55
private final boolean needsTransition ;
57
56
58
- private NativeEntryPointInfo (MethodType methodType , AssignedLocation [] cc , AssignedLocation [] returnBuffering , boolean capturesState , boolean needsTransition ) {
57
+ private NativeEntryPointInfo (MethodType methodType , VMStorage [] cc , VMStorage [] returnBuffering , boolean needsReturnBuffer , boolean capturesState , boolean needsTransition ) {
58
+ assert methodType .parameterCount () == cc .length ;
59
+ assert needsReturnBuffer == (returnBuffering .length > 1 );
59
60
this .methodType = methodType ;
60
61
this .parameterAssignments = cc ;
61
62
this .returnBuffering = returnBuffering ;
63
+ this .needsReturnBuffer = needsReturnBuffer ;
62
64
this .capturesState = capturesState ;
63
65
this .needsTransition = needsTransition ;
64
66
}
@@ -69,13 +71,10 @@ public static NativeEntryPointInfo make(
69
71
boolean needsReturnBuffer ,
70
72
int capturedStateMask ,
71
73
boolean needsTransition ) {
72
- if (returnMoves .length > 1 != needsReturnBuffer ) {
74
+ if (( returnMoves .length > 1 ) != needsReturnBuffer ) {
73
75
throw new AssertionError ("Multiple register return, but needsReturnBuffer was false" );
74
76
}
75
-
76
- AssignedLocation [] parametersAssignment = AbiUtils .singleton ().toMemoryAssignment (argMoves , false );
77
- AssignedLocation [] returnBuffering = needsReturnBuffer ? AbiUtils .singleton ().toMemoryAssignment (returnMoves , true ) : null ;
78
- return new NativeEntryPointInfo (methodType , parametersAssignment , returnBuffering , capturedStateMask != 0 , needsTransition );
77
+ return new NativeEntryPointInfo (methodType , argMoves , returnMoves , needsReturnBuffer , capturedStateMask != 0 , needsTransition );
79
78
}
80
79
81
80
public static Target_jdk_internal_foreign_abi_NativeEntryPoint makeEntryPoint (
@@ -86,8 +85,8 @@ public static Target_jdk_internal_foreign_abi_NativeEntryPoint makeEntryPoint(
86
85
int capturedStateMask ,
87
86
boolean needsTransition ) {
88
87
var info = make (argMoves , returnMoves , methodType , needsReturnBuffer , capturedStateMask , needsTransition );
89
- long addr = ForeignFunctionsRuntime .singleton ().getStubPointer (info ).rawValue ();
90
- return new Target_jdk_internal_foreign_abi_NativeEntryPoint (info .linkMethodType (), addr , capturedStateMask );
88
+ long addr = ForeignFunctionsRuntime .singleton ().getDowncallStubPointer (info ).rawValue ();
89
+ return new Target_jdk_internal_foreign_abi_NativeEntryPoint (info .methodType (), addr , capturedStateMask );
91
90
}
92
91
93
92
public int callAddressIndex () {
@@ -101,38 +100,23 @@ public int captureAddressIndex() {
101
100
return callAddressIndex () + 1 ;
102
101
}
103
102
104
- /**
105
- * Method type without any of the special arguments.
106
- */
107
- public MethodType nativeMethodType () {
108
- if (capturesCallState ()) {
109
- return this .methodType .dropParameterTypes (0 , captureAddressIndex () + 1 );
110
- } else {
111
- return this .methodType .dropParameterTypes (0 , callAddressIndex () + 1 );
112
- }
113
- }
114
-
115
- /**
116
- * Method type with all special arguments.
117
- */
118
- public MethodType linkMethodType () {
103
+ public MethodType methodType () {
119
104
return this .methodType ;
120
105
}
121
106
122
107
public boolean needsReturnBuffer () {
123
- return this . returnBuffering != null ;
108
+ return needsReturnBuffer ;
124
109
}
125
110
126
111
public boolean capturesCallState () {
127
112
return capturesState ;
128
113
}
129
114
130
- public AssignedLocation [] parametersAssignment () {
131
- assert parameterAssignments .length == this .nativeMethodType ().parameterCount () : Arrays .toString (parameterAssignments ) + " ; " + nativeMethodType ();
115
+ public VMStorage [] parametersAssignment () {
132
116
return parameterAssignments ;
133
117
}
134
118
135
- public AssignedLocation [] returnsAssignment () {
119
+ public VMStorage [] returnsAssignment () {
136
120
return returnBuffering ;
137
121
}
138
122
@@ -149,12 +133,12 @@ public boolean equals(Object o) {
149
133
return false ;
150
134
}
151
135
NativeEntryPointInfo that = (NativeEntryPointInfo ) o ;
152
- return capturesState == that .capturesState && needsTransition == that .needsTransition && Objects .equals (methodType , that .methodType ) &&
136
+ return capturesState == that .capturesState && needsTransition == that .needsTransition && needsReturnBuffer == that . needsReturnBuffer && Objects .equals (methodType , that .methodType ) &&
153
137
Arrays .equals (parameterAssignments , that .parameterAssignments ) && Arrays .equals (returnBuffering , that .returnBuffering );
154
138
}
155
139
156
140
@ Override
157
141
public int hashCode () {
158
- return Objects .hash (methodType , capturesState , needsTransition , Arrays .hashCode (parameterAssignments ), Arrays .hashCode (returnBuffering ));
142
+ return Objects .hash (methodType , needsReturnBuffer , capturesState , needsTransition , Arrays .hashCode (parameterAssignments ), Arrays .hashCode (returnBuffering ));
159
143
}
160
144
}
0 commit comments