2424 */
2525package jdk .graal .compiler .hotspot .test ;
2626
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+
2733import jdk .graal .compiler .hotspot .meta .HotSpotForeignCallDescriptor ;
2834import jdk .graal .compiler .hotspot .meta .HotSpotHostForeignCallsProvider .TestForeignCalls ;
35+ import jdk .graal .compiler .nodes .ConstantNode ;
2936import jdk .graal .compiler .nodes .ValueNode ;
3037import jdk .graal .compiler .nodes .extended .ForeignCallNode ;
3138import jdk .graal .compiler .nodes .graphbuilderconf .GraphBuilderContext ;
3239import jdk .graal .compiler .nodes .graphbuilderconf .InvocationPlugin ;
3340import jdk .graal .compiler .nodes .graphbuilderconf .InvocationPlugins ;
34- import org .junit .Assume ;
35- import org .junit .Before ;
36- import org .junit .Test ;
37-
3841import jdk .vm .ci .meta .JavaKind ;
3942import jdk .vm .ci .meta .ResolvedJavaMethod ;
4043
@@ -45,12 +48,14 @@ protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
4548 for (JavaKind kind : TestForeignCalls .KINDS ) {
4649 HotSpotForeignCallDescriptor desc = TestForeignCalls .createStubCallDescriptor (kind );
4750 String name = desc .getName ();
48- Class <?> argType = desc .getSignature ().getArgumentTypes ()[0 ];
51+ Class <?> argType = desc .getSignature ().getArgumentTypes ()[1 ];
4952 invocationPlugins .register (HotSpotInvokeJavaMethodTest .class , new InvocationPlugin (name , argType ) {
5053 @ Override
5154 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 );
5459 return true ;
5560 }
5661 });
@@ -63,132 +68,137 @@ public void before() {
6368 Assume .assumeTrue ("Invoke stub helper is missing" , runtime ().getVMConfig ().invokeJavaMethodAddress != 0 );
6469 }
6570
71+ static Object passedArg ;
72+
6673 static boolean [] booleanValues = new boolean []{Boolean .TRUE , Boolean .FALSE };
6774
68- static boolean booleanReturnsBoolean (boolean arg ) {
69- return arg ;
75+ static void passingBoolean (boolean arg ) {
76+ passedArg = arg ;
7077 }
7178
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 ;
7483 }
7584
7685 @ Test
77- public void testBooleanReturnsBoolean () {
86+ public void testPassingBoolean () {
7887 for (boolean value : booleanValues ) {
79- test ("booleanReturnsBooleanSnippet " , value );
88+ test ("passingBooleanSnippet " , value );
8089 }
8190 }
8291
8392 static byte [] byteValues = new byte []{Byte .MAX_VALUE , -1 , 0 , 1 , Byte .MIN_VALUE };
8493
85- static byte byteReturnsByte (byte arg ) {
86- return arg ;
94+ static void passingByte (byte arg ) {
95+ passedArg = arg ;
8796 }
8897
89- public static byte byteReturnsByteSnippet (byte arg ) {
90- return byteReturnsByte (arg );
98+ public static void passingByteSnippet (byte arg ) {
99+ passedArg = null ;
100+ passingByte (arg );
91101 }
92102
93103 @ Test
94- public void testByteReturnsByte () {
104+ public void testPassingByte () {
95105 for (byte value : byteValues ) {
96- test ("byteReturnsByteSnippet " , value );
106+ test ("passingByteSnippet " , value );
97107 }
98108 }
99109
100110 static short [] shortValues = new short []{Short .MAX_VALUE , -1 , 0 , 1 , Short .MIN_VALUE };
101111
102- static short shortReturnsShort (short arg ) {
103- return arg ;
112+ static void passingShort (short arg ) {
113+ passedArg = arg ;
104114 }
105115
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 ;
108120 }
109121
110122 @ Test
111- public void testShortReturnsShort () {
123+ public void testPassingShort () {
112124 for (short value : shortValues ) {
113- test ("shortReturnsShortSnippet " , value );
125+ test ("passingShortSnippet " , value );
114126 }
115127 }
116128
117129 static char [] charValues = new char []{Character .MAX_VALUE , 1 , Character .MIN_VALUE };
118130
119- static char charReturnsChar (char arg ) {
120- return arg ;
131+ static void passingChar (char arg ) {
132+ passedArg = arg ;
121133 }
122134
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 ;
125139 }
126140
127141 @ Test
128- public void testCharReturnsChar () {
142+ public void testPassingChar () {
129143 for (char value : charValues ) {
130- test ("charReturnsCharSnippet " , value );
144+ test ("passingCharSnippet " , value );
131145 }
132146 }
133147
134148 static int [] intValues = new int []{Integer .MAX_VALUE , -1 , 0 , 1 , Integer .MIN_VALUE };
135149
136- static int intReturnsInt (int arg ) {
137- return arg ;
150+ static void passingInt (int arg ) {
151+ passedArg = arg ;
138152 }
139153
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 ;
142158 }
143159
144160 @ Test
145- public void testIntReturnsInt () {
161+ public void testPassingInt () {
146162 for (int value : intValues ) {
147- test ("intReturnsIntSnippet " , value );
163+ test ("passingIntSnippet " , value );
148164 }
149165 }
150166
151167 static long [] longValues = new long []{Long .MAX_VALUE , -1 , 0 , 1 , Long .MIN_VALUE };
152168
153- static long longReturnsLong (long arg ) {
154- return arg ;
169+ static void passingLong (long arg ) {
170+ passedArg = arg ;
155171 }
156172
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 ;
159177 }
160178
161179 @ Test
162- public void testLongReturnsLong () {
180+ public void testPassingLong () {
163181 for (long value : longValues ) {
164- test ("longReturnsLongSnippet " , value );
182+ test ("passingLongSnippet " , value );
165183 }
166184 }
167185
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-
178186 static Object [] objectValues = new Object []{null , "String" , Integer .valueOf (-1 )};
179187
180- static Object objectReturnsObject (Object arg ) {
181- return arg ;
188+ static void passingObject (Object arg ) {
189+ passedArg = arg ;
182190 }
183191
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 ;
186196 }
187197
188198 @ Test
189- public void testObjectReturnsObject () {
199+ public void testPassingObject () {
190200 for (Object value : objectValues ) {
191- test ("objectReturnsObjectSnippet " , value );
201+ test ("passingObjectSnippet " , value );
192202 }
193203 }
194204}
0 commit comments