74 { |
74 { |
75 MethodHandle mh1 = getmh1( boolean.class, boolean.class); |
75 MethodHandle mh1 = getmh1( boolean.class, boolean.class); |
76 MethodHandle mh2 = getmh2(mh1, boolean.class, boolean.class); |
76 MethodHandle mh2 = getmh2(mh1, boolean.class, boolean.class); |
77 // TODO add this for all cases when the bugs are fixed. |
77 // TODO add this for all cases when the bugs are fixed. |
78 //MethodHandle mh3 = getmh3(mh1, boolean.class, boolean.class); |
78 //MethodHandle mh3 = getmh3(mh1, boolean.class, boolean.class); |
79 boolean a = mh1.<boolean>invokeExact((boolean) x); |
79 boolean a = (boolean) mh1.invokeExact((boolean) x); |
80 boolean b = mh2.<boolean>invokeExact(x); |
80 boolean b = (boolean) mh2.invokeExact(x); |
81 //boolean c = mh3.<boolean>invokeExact((boolean) x); |
81 //boolean c = mh3.<boolean>invokeExact((boolean) x); |
82 assert a == b : a + " != " + b; |
82 check(x, a, b); |
83 //assert c == x : c + " != " + x; |
83 //check(x, c, x); |
84 } |
84 } |
85 |
85 |
86 // byte |
86 // byte |
87 { |
87 { |
88 MethodHandle mh1 = getmh1( byte.class, byte.class ); |
88 MethodHandle mh1 = getmh1( byte.class, byte.class ); |
89 MethodHandle mh2 = getmh2(mh1, byte.class, boolean.class); |
89 MethodHandle mh2 = getmh2(mh1, byte.class, boolean.class); |
90 byte a = mh1.<byte>invokeExact((byte) (x ? 1 : 0)); |
90 byte a = (byte) mh1.invokeExact((byte) (x ? 1 : 0)); |
91 byte b = mh2.<byte>invokeExact(x); |
91 byte b = (byte) mh2.invokeExact(x); |
92 assert a == b : a + " != " + b; |
92 check(x, a, b); |
93 } |
93 } |
94 |
94 |
95 // char |
95 // char |
96 { |
96 { |
97 MethodHandle mh1 = getmh1( char.class, char.class); |
97 MethodHandle mh1 = getmh1( char.class, char.class); |
98 MethodHandle mh2 = getmh2(mh1, char.class, boolean.class); |
98 MethodHandle mh2 = getmh2(mh1, char.class, boolean.class); |
99 char a = mh1.<char>invokeExact((char) (x ? 1 : 0)); |
99 char a = (char) mh1.invokeExact((char) (x ? 1 : 0)); |
100 char b = mh2.<char>invokeExact(x); |
100 char b = (char) mh2.invokeExact(x); |
101 assert a == b : a + " != " + b; |
101 check(x, a, b); |
102 } |
102 } |
103 |
103 |
104 // short |
104 // short |
105 { |
105 { |
106 MethodHandle mh1 = getmh1( short.class, short.class); |
106 MethodHandle mh1 = getmh1( short.class, short.class); |
107 MethodHandle mh2 = getmh2(mh1, short.class, boolean.class); |
107 MethodHandle mh2 = getmh2(mh1, short.class, boolean.class); |
108 short a = mh1.<short>invokeExact((short) (x ? 1 : 0)); |
108 short a = (short) mh1.invokeExact((short) (x ? 1 : 0)); |
109 short b = mh2.<short>invokeExact(x); |
109 short b = (short) mh2.invokeExact(x); |
110 assert a == b : a + " != " + b; |
110 check(x, a, b); |
111 } |
111 } |
112 } |
112 } |
113 |
113 |
114 static void testbyte() throws Throwable { |
114 static void testbyte() throws Throwable { |
115 byte[] a = new byte[] { |
115 byte[] a = new byte[] { |
132 |
132 |
133 // boolean |
133 // boolean |
134 { |
134 { |
135 MethodHandle mh1 = getmh1( boolean.class, boolean.class); |
135 MethodHandle mh1 = getmh1( boolean.class, boolean.class); |
136 MethodHandle mh2 = getmh2(mh1, boolean.class, byte.class); |
136 MethodHandle mh2 = getmh2(mh1, boolean.class, byte.class); |
137 boolean a = mh1.<boolean>invokeExact((x & 1) == 1); |
137 boolean a = (boolean) mh1.invokeExact((x & 1) == 1); |
138 boolean b = mh2.<boolean>invokeExact(x); |
138 boolean b = (boolean) mh2.invokeExact(x); |
139 assert a == b : a + " != " + b; |
139 check(x, a, b); |
140 } |
140 } |
141 |
141 |
142 // byte |
142 // byte |
143 { |
143 { |
144 MethodHandle mh1 = getmh1( byte.class, byte.class); |
144 MethodHandle mh1 = getmh1( byte.class, byte.class); |
145 MethodHandle mh2 = getmh2(mh1, byte.class, byte.class); |
145 MethodHandle mh2 = getmh2(mh1, byte.class, byte.class); |
146 byte a = mh1.<byte>invokeExact((byte) x); |
146 byte a = (byte) mh1.invokeExact((byte) x); |
147 byte b = mh2.<byte>invokeExact(x); |
147 byte b = (byte) mh2.invokeExact(x); |
148 assert a == b : a + " != " + b; |
148 check(x, a, b); |
149 } |
149 } |
150 |
150 |
151 // char |
151 // char |
152 { |
152 { |
153 MethodHandle mh1 = getmh1( char.class, char.class); |
153 MethodHandle mh1 = getmh1( char.class, char.class); |
154 MethodHandle mh2 = getmh2(mh1, char.class, byte.class); |
154 MethodHandle mh2 = getmh2(mh1, char.class, byte.class); |
155 char a = mh1.<char>invokeExact((char) x); |
155 char a = (char) mh1.invokeExact((char) x); |
156 char b = mh2.<char>invokeExact(x); |
156 char b = (char) mh2.invokeExact(x); |
157 assert a == b : a + " != " + b; |
157 check(x, a, b); |
158 } |
158 } |
159 |
159 |
160 // short |
160 // short |
161 { |
161 { |
162 MethodHandle mh1 = getmh1( short.class, short.class); |
162 MethodHandle mh1 = getmh1( short.class, short.class); |
163 MethodHandle mh2 = getmh2(mh1, short.class, byte.class); |
163 MethodHandle mh2 = getmh2(mh1, short.class, byte.class); |
164 short a = mh1.<short>invokeExact((short) x); |
164 short a = (short) mh1.invokeExact((short) x); |
165 short b = mh2.<short>invokeExact(x); |
165 short b = (short) mh2.invokeExact(x); |
166 assert a == b : a + " != " + b; |
166 check(x, a, b); |
167 } |
167 } |
168 } |
168 } |
169 |
169 |
170 static void testchar() throws Throwable { |
170 static void testchar() throws Throwable { |
171 char[] a = new char[] { |
171 char[] a = new char[] { |
186 |
186 |
187 // boolean |
187 // boolean |
188 { |
188 { |
189 MethodHandle mh1 = getmh1( boolean.class, boolean.class); |
189 MethodHandle mh1 = getmh1( boolean.class, boolean.class); |
190 MethodHandle mh2 = getmh2(mh1, boolean.class, char.class); |
190 MethodHandle mh2 = getmh2(mh1, boolean.class, char.class); |
191 boolean a = mh1.<boolean>invokeExact((x & 1) == 1); |
191 boolean a = (boolean) mh1.invokeExact((x & 1) == 1); |
192 boolean b = mh2.<boolean>invokeExact(x); |
192 boolean b = (boolean) mh2.invokeExact(x); |
193 assert a == b : a + " != " + b; |
193 check(x, a, b); |
194 } |
194 } |
195 |
195 |
196 // byte |
196 // byte |
197 { |
197 { |
198 MethodHandle mh1 = getmh1( byte.class, byte.class); |
198 MethodHandle mh1 = getmh1( byte.class, byte.class); |
199 MethodHandle mh2 = getmh2(mh1, byte.class, char.class); |
199 MethodHandle mh2 = getmh2(mh1, byte.class, char.class); |
200 byte a = mh1.<byte>invokeExact((byte) x); |
200 byte a = (byte) mh1.invokeExact((byte) x); |
201 byte b = mh2.<byte>invokeExact(x); |
201 byte b = (byte) mh2.invokeExact(x); |
202 assert a == b : a + " != " + b; |
202 check(x, a, b); |
203 } |
203 } |
204 |
204 |
205 // char |
205 // char |
206 { |
206 { |
207 MethodHandle mh1 = getmh1( char.class, char.class); |
207 MethodHandle mh1 = getmh1( char.class, char.class); |
208 MethodHandle mh2 = getmh2(mh1, char.class, char.class); |
208 MethodHandle mh2 = getmh2(mh1, char.class, char.class); |
209 char a = mh1.<char>invokeExact((char) x); |
209 char a = (char) mh1.invokeExact((char) x); |
210 char b = mh2.<char>invokeExact(x); |
210 char b = (char) mh2.invokeExact(x); |
211 assert a == b : a + " != " + b; |
211 check(x, a, b); |
212 } |
212 } |
213 |
213 |
214 // short |
214 // short |
215 { |
215 { |
216 MethodHandle mh1 = getmh1( short.class, short.class); |
216 MethodHandle mh1 = getmh1( short.class, short.class); |
217 MethodHandle mh2 = getmh2(mh1, short.class, char.class); |
217 MethodHandle mh2 = getmh2(mh1, short.class, char.class); |
218 short a = mh1.<short>invokeExact((short) x); |
218 short a = (short) mh1.invokeExact((short) x); |
219 short b = mh2.<short>invokeExact(x); |
219 short b = (short) mh2.invokeExact(x); |
220 assert a == b : a + " != " + b; |
220 check(x, a, b); |
221 } |
221 } |
222 } |
222 } |
223 |
223 |
224 static void testshort() throws Throwable { |
224 static void testshort() throws Throwable { |
225 short[] a = new short[] { |
225 short[] a = new short[] { |
246 |
246 |
247 // boolean |
247 // boolean |
248 { |
248 { |
249 MethodHandle mh1 = getmh1( boolean.class, boolean.class); |
249 MethodHandle mh1 = getmh1( boolean.class, boolean.class); |
250 MethodHandle mh2 = getmh2(mh1, boolean.class, short.class); |
250 MethodHandle mh2 = getmh2(mh1, boolean.class, short.class); |
251 boolean a = mh1.<boolean>invokeExact((x & 1) == 1); |
251 boolean a = (boolean) mh1.invokeExact((x & 1) == 1); |
252 boolean b = mh2.<boolean>invokeExact(x); |
252 boolean b = (boolean) mh2.invokeExact(x); |
253 assert a == b : a + " != " + b; |
253 check(x, a, b); |
254 } |
254 } |
255 |
255 |
256 // byte |
256 // byte |
257 { |
257 { |
258 MethodHandle mh1 = getmh1( byte.class, byte.class); |
258 MethodHandle mh1 = getmh1( byte.class, byte.class); |
259 MethodHandle mh2 = getmh2(mh1, byte.class, short.class); |
259 MethodHandle mh2 = getmh2(mh1, byte.class, short.class); |
260 byte a = mh1.<byte>invokeExact((byte) x); |
260 byte a = (byte) mh1.invokeExact((byte) x); |
261 byte b = mh2.<byte>invokeExact(x); |
261 byte b = (byte) mh2.invokeExact(x); |
262 assert a == b : a + " != " + b; |
262 check(x, a, b); |
263 } |
263 } |
264 |
264 |
265 // char |
265 // char |
266 { |
266 { |
267 MethodHandle mh1 = getmh1( char.class, char.class); |
267 MethodHandle mh1 = getmh1( char.class, char.class); |
268 MethodHandle mh2 = getmh2(mh1, char.class, short.class); |
268 MethodHandle mh2 = getmh2(mh1, char.class, short.class); |
269 char a = mh1.<char>invokeExact((char) x); |
269 char a = (char) mh1.invokeExact((char) x); |
270 char b = mh2.<char>invokeExact(x); |
270 char b = (char) mh2.invokeExact(x); |
271 assert a == b : a + " != " + b; |
271 check(x, a, b); |
272 } |
272 } |
273 |
273 |
274 // short |
274 // short |
275 { |
275 { |
276 MethodHandle mh1 = getmh1( short.class, short.class); |
276 MethodHandle mh1 = getmh1( short.class, short.class); |
277 MethodHandle mh2 = getmh2(mh1, short.class, short.class); |
277 MethodHandle mh2 = getmh2(mh1, short.class, short.class); |
278 short a = mh1.<short>invokeExact((short) x); |
278 short a = (short) mh1.invokeExact((short) x); |
279 short b = mh2.<short>invokeExact(x); |
279 short b = (short) mh2.invokeExact(x); |
280 assert a == b : a + " != " + b; |
280 check(x, a, b); |
281 } |
281 } |
282 } |
282 } |
283 |
283 |
284 static void testint() throws Throwable { |
284 static void testint() throws Throwable { |
285 int[] a = new int[] { |
285 int[] a = new int[] { |
314 |
314 |
315 // boolean |
315 // boolean |
316 { |
316 { |
317 MethodHandle mh1 = getmh1( boolean.class, boolean.class); |
317 MethodHandle mh1 = getmh1( boolean.class, boolean.class); |
318 MethodHandle mh2 = getmh2(mh1, boolean.class, int.class); |
318 MethodHandle mh2 = getmh2(mh1, boolean.class, int.class); |
319 boolean a = mh1.<boolean>invokeExact((x & 1) == 1); |
319 boolean a = (boolean) mh1.invokeExact((x & 1) == 1); |
320 boolean b = mh2.<boolean>invokeExact(x); |
320 boolean b = (boolean) mh2.invokeExact(x); |
321 assert a == b : a + " != " + b; |
321 check(x, a, b); |
322 } |
322 } |
323 |
323 |
324 // byte |
324 // byte |
325 { |
325 { |
326 MethodHandle mh1 = getmh1( byte.class, byte.class); |
326 MethodHandle mh1 = getmh1( byte.class, byte.class); |
327 MethodHandle mh2 = getmh2(mh1, byte.class, int.class); |
327 MethodHandle mh2 = getmh2(mh1, byte.class, int.class); |
328 byte a = mh1.<byte>invokeExact((byte) x); |
328 byte a = (byte) mh1.invokeExact((byte) x); |
329 byte b = mh2.<byte>invokeExact(x); |
329 byte b = (byte) mh2.invokeExact(x); |
|
330 check(x, a, b); |
|
331 } |
|
332 |
|
333 // char |
|
334 { |
|
335 MethodHandle mh1 = getmh1( char.class, char.class); |
|
336 MethodHandle mh2 = getmh2(mh1, char.class, int.class); |
|
337 char a = (char) mh1.invokeExact((char) x); |
|
338 char b = (char) mh2.invokeExact(x); |
|
339 check(x, a, b); |
|
340 } |
|
341 |
|
342 // short |
|
343 { |
|
344 MethodHandle mh1 = getmh1( short.class, short.class); |
|
345 MethodHandle mh2 = getmh2(mh1, short.class, int.class); |
|
346 short a = (short) mh1.invokeExact((short) x); |
|
347 short b = (short) mh2.invokeExact(x); |
330 assert a == b : a + " != " + b; |
348 assert a == b : a + " != " + b; |
331 } |
349 check(x, a, b); |
332 |
|
333 // char |
|
334 { |
|
335 MethodHandle mh1 = getmh1( char.class, char.class); |
|
336 MethodHandle mh2 = getmh2(mh1, char.class, int.class); |
|
337 char a = mh1.<char>invokeExact((char) x); |
|
338 char b = mh2.<char>invokeExact(x); |
|
339 assert a == b : a + " != " + b; |
|
340 } |
|
341 |
|
342 // short |
|
343 { |
|
344 MethodHandle mh1 = getmh1( short.class, short.class); |
|
345 MethodHandle mh2 = getmh2(mh1, short.class, int.class); |
|
346 short a = mh1.<short>invokeExact((short) x); |
|
347 short b = mh2.<short>invokeExact(x); |
|
348 assert a == b : a + " != " + b; |
|
349 } |
350 } |
350 |
351 |
351 // int |
352 // int |
352 { |
353 { |
353 MethodHandle mh1 = getmh1( int.class, int.class); |
354 MethodHandle mh1 = getmh1( int.class, int.class); |
354 MethodHandle mh2 = getmh2(mh1, int.class, int.class); |
355 MethodHandle mh2 = getmh2(mh1, int.class, int.class); |
355 int a = mh1.<int>invokeExact((int) x); |
356 int a = (int) mh1.invokeExact((int) x); |
356 int b = mh2.<int>invokeExact(x); |
357 int b = (int) mh2.invokeExact(x); |
357 assert a == b : a + " != " + b; |
358 check(x, a, b); |
358 } |
359 } |
359 } |
360 } |
360 |
361 |
361 // test adapter_opt_l2i |
362 // test adapter_opt_l2i |
362 static void testlong() throws Throwable { |
363 static void testlong() throws Throwable { |
393 |
394 |
394 // boolean |
395 // boolean |
395 { |
396 { |
396 MethodHandle mh1 = getmh1( boolean.class, boolean.class); |
397 MethodHandle mh1 = getmh1( boolean.class, boolean.class); |
397 MethodHandle mh2 = getmh2(mh1, boolean.class, long.class); |
398 MethodHandle mh2 = getmh2(mh1, boolean.class, long.class); |
398 boolean a = mh1.<boolean>invokeExact((x & 1L) == 1L); |
399 boolean a = (boolean) mh1.invokeExact((x & 1L) == 1L); |
399 boolean b = mh2.<boolean>invokeExact(x); |
400 boolean b = (boolean) mh2.invokeExact(x); |
400 assert a == b : a + " != " + b; |
401 check(x, a, b); |
401 } |
402 } |
402 |
403 |
403 // byte |
404 // byte |
404 { |
405 { |
405 MethodHandle mh1 = getmh1( byte.class, byte.class); |
406 MethodHandle mh1 = getmh1( byte.class, byte.class); |
406 MethodHandle mh2 = getmh2(mh1, byte.class, long.class); |
407 MethodHandle mh2 = getmh2(mh1, byte.class, long.class); |
407 byte a = mh1.<byte>invokeExact((byte) x); |
408 byte a = (byte) mh1.invokeExact((byte) x); |
408 byte b = mh2.<byte>invokeExact(x); |
409 byte b = (byte) mh2.invokeExact(x); |
409 assert a == b : a + " != " + b; |
410 check(x, a, b); |
410 } |
411 } |
411 |
412 |
412 // char |
413 // char |
413 { |
414 { |
414 MethodHandle mh1 = getmh1( char.class, char.class); |
415 MethodHandle mh1 = getmh1( char.class, char.class); |
415 MethodHandle mh2 = getmh2(mh1, char.class, long.class); |
416 MethodHandle mh2 = getmh2(mh1, char.class, long.class); |
416 char a = mh1.<char>invokeExact((char) x); |
417 char a = (char) mh1.invokeExact((char) x); |
417 char b = mh2.<char>invokeExact(x); |
418 char b = (char) mh2.invokeExact(x); |
418 assert a == b : a + " != " + b; |
419 check(x, a, b); |
419 } |
420 } |
420 |
421 |
421 // short |
422 // short |
422 { |
423 { |
423 MethodHandle mh1 = getmh1( short.class, short.class); |
424 MethodHandle mh1 = getmh1( short.class, short.class); |
424 MethodHandle mh2 = getmh2(mh1, short.class, long.class); |
425 MethodHandle mh2 = getmh2(mh1, short.class, long.class); |
425 short a = mh1.<short>invokeExact((short) x); |
426 short a = (short) mh1.invokeExact((short) x); |
426 short b = mh2.<short>invokeExact(x); |
427 short b = (short) mh2.invokeExact(x); |
427 assert a == b : a + " != " + b; |
428 check(x, a, b); |
428 } |
429 } |
429 |
430 |
430 // int |
431 // int |
431 { |
432 { |
432 MethodHandle mh1 = getmh1( int.class, int.class); |
433 MethodHandle mh1 = getmh1( int.class, int.class); |
433 MethodHandle mh2 = getmh2(mh1, int.class, long.class); |
434 MethodHandle mh2 = getmh2(mh1, int.class, long.class); |
434 int a = mh1.<int>invokeExact((int) x); |
435 int a = (int) mh1.invokeExact((int) x); |
435 int b = mh2.<int>invokeExact(x); |
436 int b = (int) mh2.invokeExact(x); |
436 assert a == b : a + " != " + b; |
437 check(x, a, b); |
437 } |
438 } |
438 |
439 } |
439 } |
440 |
|
441 static void check(boolean x, boolean e, boolean a) { p(z2h(x), z2h(e), z2h(a)); assert e == a : z2h(x) + ": " + z2h(e) + " != " + z2h(a); } |
|
442 static void check(boolean x, byte e, byte a) { p(z2h(x), i2h(e), i2h(a)); assert e == a : z2h(x) + ": " + i2h(e) + " != " + i2h(a); } |
|
443 static void check(boolean x, int e, int a) { p(z2h(x), i2h(e), i2h(a)); assert e == a : z2h(x) + ": " + i2h(e) + " != " + i2h(a); } |
|
444 |
|
445 static void check(int x, boolean e, boolean a) { p(i2h(x), z2h(e), z2h(a)); assert e == a : i2h(x) + ": " + z2h(e) + " != " + z2h(a); } |
|
446 static void check(int x, byte e, byte a) { p(i2h(x), i2h(e), i2h(a)); assert e == a : i2h(x) + ": " + i2h(e) + " != " + i2h(a); } |
|
447 static void check(int x, int e, int a) { p(i2h(x), i2h(e), i2h(a)); assert e == a : i2h(x) + ": " + i2h(e) + " != " + i2h(a); } |
|
448 |
|
449 static void check(long x, boolean e, boolean a) { p(l2h(x), z2h(e), z2h(a)); assert e == a : l2h(x) + ": " + z2h(e) + " != " + z2h(a); } |
|
450 static void check(long x, byte e, byte a) { p(l2h(x), i2h(e), i2h(a)); assert e == a : l2h(x) + ": " + i2h(e) + " != " + i2h(a); } |
|
451 static void check(long x, int e, int a) { p(l2h(x), i2h(e), i2h(a)); assert e == a : l2h(x) + ": " + i2h(e) + " != " + i2h(a); } |
|
452 |
|
453 static void p(String x, String e, String a) { if (DEBUG) System.out.println(x + ": expected: " + e + ", actual: " + a); } |
|
454 |
|
455 static String z2h(boolean x) { return x ? "1" : "0"; } |
|
456 static String i2h(int x) { return Integer.toHexString(x); } |
|
457 static String l2h(long x) { return Long.toHexString(x); } |
440 |
458 |
441 // to int |
459 // to int |
442 public static boolean foo(boolean i) { return i; } |
460 public static boolean foo(boolean i) { return i; } |
443 public static byte foo(byte i) { return i; } |
461 public static byte foo(byte i) { return i; } |
444 public static char foo(char i) { return i; } |
462 public static char foo(char i) { return i; } |