24
24
*/
25
25
package jdk .graal .compiler .hotspot .test ;
26
26
27
+ import static jdk .graal .compiler .replacements .SnippetTemplate .AbstractTemplates .findMethod ;
28
+
29
+ import org .junit .Assume ;
30
+ import org .junit .Before ;
31
+ import org .junit .Test ;
32
+
27
33
import jdk .graal .compiler .hotspot .meta .HotSpotForeignCallDescriptor ;
28
34
import jdk .graal .compiler .hotspot .meta .HotSpotHostForeignCallsProvider .TestForeignCalls ;
35
+ import jdk .graal .compiler .nodes .ConstantNode ;
29
36
import jdk .graal .compiler .nodes .ValueNode ;
30
37
import jdk .graal .compiler .nodes .extended .ForeignCallNode ;
31
38
import jdk .graal .compiler .nodes .graphbuilderconf .GraphBuilderContext ;
32
39
import jdk .graal .compiler .nodes .graphbuilderconf .InvocationPlugin ;
33
40
import jdk .graal .compiler .nodes .graphbuilderconf .InvocationPlugins ;
34
- import org .junit .Assume ;
35
- import org .junit .Before ;
36
- import org .junit .Test ;
37
-
38
41
import jdk .vm .ci .meta .JavaKind ;
39
42
import jdk .vm .ci .meta .ResolvedJavaMethod ;
40
43
@@ -45,12 +48,14 @@ protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
45
48
for (JavaKind kind : TestForeignCalls .KINDS ) {
46
49
HotSpotForeignCallDescriptor desc = TestForeignCalls .createStubCallDescriptor (kind );
47
50
String name = desc .getName ();
48
- Class <?> argType = desc .getSignature ().getArgumentTypes ()[0 ];
51
+ Class <?> argType = desc .getSignature ().getArgumentTypes ()[1 ];
49
52
invocationPlugins .register (HotSpotInvokeJavaMethodTest .class , new InvocationPlugin (name , argType ) {
50
53
@ Override
51
54
public boolean apply (GraphBuilderContext b , ResolvedJavaMethod targetMethod , InvocationPlugin .Receiver receiver , ValueNode arg ) {
52
- ForeignCallNode node = new ForeignCallNode (desc , arg );
53
- b .addPush (kind , node );
55
+ ResolvedJavaMethod javaMethod = findMethod (b .getMetaAccess (), HotSpotInvokeJavaMethodTest .class , desc .getName ());
56
+ ValueNode method = ConstantNode .forConstant (b .getStampProvider ().createMethodStamp (), javaMethod .getEncoding (), b .getMetaAccess (), b .getGraph ());
57
+ ForeignCallNode node = new ForeignCallNode (desc , method , arg );
58
+ b .add (node );
54
59
return true ;
55
60
}
56
61
});
@@ -63,132 +68,137 @@ public void before() {
63
68
Assume .assumeTrue ("Invoke stub helper is missing" , runtime ().getVMConfig ().invokeJavaMethodAddress != 0 );
64
69
}
65
70
71
+ static Object passedArg ;
72
+
66
73
static boolean [] booleanValues = new boolean []{Boolean .TRUE , Boolean .FALSE };
67
74
68
- static boolean booleanReturnsBoolean (boolean arg ) {
69
- return arg ;
75
+ static void passingBoolean (boolean arg ) {
76
+ passedArg = arg ;
70
77
}
71
78
72
- public static boolean booleanReturnsBooleanSnippet (boolean arg ) {
73
- return booleanReturnsBoolean (arg );
79
+ public static boolean passingBooleanSnippet (boolean arg ) {
80
+ passedArg = null ;
81
+ passingBoolean (arg );
82
+ return (boolean ) passedArg ;
74
83
}
75
84
76
85
@ Test
77
- public void testBooleanReturnsBoolean () {
86
+ public void testPassingBoolean () {
78
87
for (boolean value : booleanValues ) {
79
- test ("booleanReturnsBooleanSnippet " , value );
88
+ test ("passingBooleanSnippet " , value );
80
89
}
81
90
}
82
91
83
92
static byte [] byteValues = new byte []{Byte .MAX_VALUE , -1 , 0 , 1 , Byte .MIN_VALUE };
84
93
85
- static byte byteReturnsByte (byte arg ) {
86
- return arg ;
94
+ static void passingByte (byte arg ) {
95
+ passedArg = arg ;
87
96
}
88
97
89
- public static byte byteReturnsByteSnippet (byte arg ) {
90
- return byteReturnsByte (arg );
98
+ public static void passingByteSnippet (byte arg ) {
99
+ passedArg = null ;
100
+ passingByte (arg );
91
101
}
92
102
93
103
@ Test
94
- public void testByteReturnsByte () {
104
+ public void testPassingByte () {
95
105
for (byte value : byteValues ) {
96
- test ("byteReturnsByteSnippet " , value );
106
+ test ("passingByteSnippet " , value );
97
107
}
98
108
}
99
109
100
110
static short [] shortValues = new short []{Short .MAX_VALUE , -1 , 0 , 1 , Short .MIN_VALUE };
101
111
102
- static short shortReturnsShort (short arg ) {
103
- return arg ;
112
+ static void passingShort (short arg ) {
113
+ passedArg = arg ;
104
114
}
105
115
106
- public static short shortReturnsShortSnippet (short arg ) {
107
- return shortReturnsShort (arg );
116
+ public static short passingShortSnippet (short arg ) {
117
+ passedArg = null ;
118
+ passingShort (arg );
119
+ return (short ) passedArg ;
108
120
}
109
121
110
122
@ Test
111
- public void testShortReturnsShort () {
123
+ public void testPassingShort () {
112
124
for (short value : shortValues ) {
113
- test ("shortReturnsShortSnippet " , value );
125
+ test ("passingShortSnippet " , value );
114
126
}
115
127
}
116
128
117
129
static char [] charValues = new char []{Character .MAX_VALUE , 1 , Character .MIN_VALUE };
118
130
119
- static char charReturnsChar (char arg ) {
120
- return arg ;
131
+ static void passingChar (char arg ) {
132
+ passedArg = arg ;
121
133
}
122
134
123
- public static char charReturnsCharSnippet (char arg ) {
124
- return charReturnsChar (arg );
135
+ public static char passingCharSnippet (char arg ) {
136
+ passedArg = null ;
137
+ passingChar (arg );
138
+ return (char ) passedArg ;
125
139
}
126
140
127
141
@ Test
128
- public void testCharReturnsChar () {
142
+ public void testPassingChar () {
129
143
for (char value : charValues ) {
130
- test ("charReturnsCharSnippet " , value );
144
+ test ("passingCharSnippet " , value );
131
145
}
132
146
}
133
147
134
148
static int [] intValues = new int []{Integer .MAX_VALUE , -1 , 0 , 1 , Integer .MIN_VALUE };
135
149
136
- static int intReturnsInt (int arg ) {
137
- return arg ;
150
+ static void passingInt (int arg ) {
151
+ passedArg = arg ;
138
152
}
139
153
140
- public static int intReturnsIntSnippet (int arg ) {
141
- return intReturnsInt (arg );
154
+ public static int passingIntSnippet (int arg ) {
155
+ passedArg = null ;
156
+ passingInt (arg );
157
+ return (int ) passedArg ;
142
158
}
143
159
144
160
@ Test
145
- public void testIntReturnsInt () {
161
+ public void testPassingInt () {
146
162
for (int value : intValues ) {
147
- test ("intReturnsIntSnippet " , value );
163
+ test ("passingIntSnippet " , value );
148
164
}
149
165
}
150
166
151
167
static long [] longValues = new long []{Long .MAX_VALUE , -1 , 0 , 1 , Long .MIN_VALUE };
152
168
153
- static long longReturnsLong (long arg ) {
154
- return arg ;
169
+ static void passingLong (long arg ) {
170
+ passedArg = arg ;
155
171
}
156
172
157
- public static long longReturnsLongSnippet (long arg ) {
158
- return longReturnsLong (arg );
173
+ public static long passingLongSnippet (long arg ) {
174
+ passedArg = null ;
175
+ passingLong (arg );
176
+ return (long ) passedArg ;
159
177
}
160
178
161
179
@ Test
162
- public void testLongReturnsLong () {
180
+ public void testPassingLong () {
163
181
for (long value : longValues ) {
164
- test ("longReturnsLongSnippet " , value );
182
+ test ("passingLongSnippet " , value );
165
183
}
166
184
}
167
185
168
- static float [] floatValues = new float []{Float .MAX_VALUE , -1 , 0 , 1 , Float .MIN_VALUE };
169
-
170
- static float floatReturnsFloat (float arg ) {
171
- return arg ;
172
- }
173
-
174
- public static float floatReturnsFloatSnippet (float arg ) {
175
- return floatReturnsFloat (arg );
176
- }
177
-
178
186
static Object [] objectValues = new Object []{null , "String" , Integer .valueOf (-1 )};
179
187
180
- static Object objectReturnsObject (Object arg ) {
181
- return arg ;
188
+ static void passingObject (Object arg ) {
189
+ passedArg = arg ;
182
190
}
183
191
184
- public static Object objectReturnsObjectSnippet (Object arg ) {
185
- return objectReturnsObject (arg );
192
+ public static Object passingObjectSnippet (Object arg ) {
193
+ passedArg = null ;
194
+ passingObject (arg );
195
+ return passedArg ;
186
196
}
187
197
188
198
@ Test
189
- public void testObjectReturnsObject () {
199
+ public void testPassingObject () {
190
200
for (Object value : objectValues ) {
191
- test ("objectReturnsObjectSnippet " , value );
201
+ test ("passingObjectSnippet " , value );
192
202
}
193
203
}
194
204
}
0 commit comments