comparison test/compiler/6991596/Test6991596.java @ 1901:7aff5786cc02

6991596: JSR 292 unimplemented adapter_opt_i2i and adapter_opt_l2i on SPARC Reviewed-by: kvn, jrose, dsamersoff
author twisti
date Mon, 18 Oct 2010 01:54:24 -0700
parents
children b856cd7f4e60
comparison
equal deleted inserted replaced
1900:e5c3d73017ab 1901:7aff5786cc02
1 /*
2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 /**
26 * @test
27 * @bug 6991596
28 * @summary JSR 292 unimplemented adapter_opt_i2i and adapter_opt_l2i on SPARC
29 *
30 * @run main/othervm -ea -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles -XX:+EnableInvokeDynamic -XX:+UnlockDiagnosticVMOptions -XX:+VerifyMethodHandles Test6991596
31 */
32
33 import java.dyn.*;
34
35 public class Test6991596 {
36 private static final Class CLASS = Test6991596.class;
37 private static final String NAME = "foo";
38 private static final boolean DEBUG = false;
39
40 public static void main(String[] args) throws Throwable {
41 testboolean();
42 testbyte();
43 testchar();
44 testshort();
45 testint();
46 testlong();
47 }
48
49 // Helpers to get various methods.
50 static MethodHandle getmh1(Class ret, Class arg) {
51 return MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(ret, arg));
52 }
53 static MethodHandle getmh2(MethodHandle mh1, Class ret, Class arg) {
54 return MethodHandles.convertArguments(mh1, MethodType.methodType(ret, arg));
55 }
56 static MethodHandle getmh3(MethodHandle mh1, Class ret, Class arg) {
57 return MethodHandles.convertArguments(mh1, MethodType.methodType(ret, arg));
58 }
59
60 // test adapter_opt_i2i
61 static void testboolean() throws Throwable {
62 boolean[] a = new boolean[] {
63 true,
64 false
65 };
66 for (int i = 0; i < a.length; i++) {
67 doboolean(a[i]);
68 }
69 }
70 static void doboolean(boolean x) throws Throwable {
71 if (DEBUG) System.out.println("boolean=" + x);
72
73 // boolean
74 {
75 MethodHandle mh1 = getmh1( 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.
78 //MethodHandle mh3 = getmh3(mh1, boolean.class, boolean.class);
79 boolean a = mh1.<boolean>invokeExact((boolean) x);
80 boolean b = mh2.<boolean>invokeExact(x);
81 //boolean c = mh3.<boolean>invokeExact((boolean) x);
82 assert a == b : a + " != " + b;
83 //assert c == x : c + " != " + x;
84 }
85
86 // byte
87 {
88 MethodHandle mh1 = getmh1( byte.class, byte.class );
89 MethodHandle mh2 = getmh2(mh1, byte.class, boolean.class);
90 byte a = mh1.<byte>invokeExact((byte) (x ? 1 : 0));
91 byte b = mh2.<byte>invokeExact(x);
92 assert a == b : a + " != " + b;
93 }
94
95 // char
96 {
97 MethodHandle mh1 = getmh1( char.class, char.class);
98 MethodHandle mh2 = getmh2(mh1, char.class, boolean.class);
99 char a = mh1.<char>invokeExact((char) (x ? 1 : 0));
100 char b = mh2.<char>invokeExact(x);
101 assert a == b : a + " != " + b;
102 }
103
104 // short
105 {
106 MethodHandle mh1 = getmh1( short.class, short.class);
107 MethodHandle mh2 = getmh2(mh1, short.class, boolean.class);
108 short a = mh1.<short>invokeExact((short) (x ? 1 : 0));
109 short b = mh2.<short>invokeExact(x);
110 assert a == b : a + " != " + b;
111 }
112 }
113
114 static void testbyte() throws Throwable {
115 byte[] a = new byte[] {
116 Byte.MIN_VALUE,
117 Byte.MIN_VALUE + 1,
118 -0x0F,
119 -1,
120 0,
121 1,
122 0x0F,
123 Byte.MAX_VALUE - 1,
124 Byte.MAX_VALUE
125 };
126 for (int i = 0; i < a.length; i++) {
127 dobyte(a[i]);
128 }
129 }
130 static void dobyte(byte x) throws Throwable {
131 if (DEBUG) System.out.println("byte=" + x);
132
133 // boolean
134 {
135 MethodHandle mh1 = getmh1( boolean.class, boolean.class);
136 MethodHandle mh2 = getmh2(mh1, boolean.class, byte.class);
137 boolean a = mh1.<boolean>invokeExact((x & 1) == 1);
138 boolean b = mh2.<boolean>invokeExact(x);
139 assert a == b : a + " != " + b;
140 }
141
142 // byte
143 {
144 MethodHandle mh1 = getmh1( byte.class, byte.class);
145 MethodHandle mh2 = getmh2(mh1, byte.class, byte.class);
146 byte a = mh1.<byte>invokeExact((byte) x);
147 byte b = mh2.<byte>invokeExact(x);
148 assert a == b : a + " != " + b;
149 }
150
151 // char
152 {
153 MethodHandle mh1 = getmh1( char.class, char.class);
154 MethodHandle mh2 = getmh2(mh1, char.class, byte.class);
155 char a = mh1.<char>invokeExact((char) x);
156 char b = mh2.<char>invokeExact(x);
157 assert a == b : a + " != " + b;
158 }
159
160 // short
161 {
162 MethodHandle mh1 = getmh1( short.class, short.class);
163 MethodHandle mh2 = getmh2(mh1, short.class, byte.class);
164 short a = mh1.<short>invokeExact((short) x);
165 short b = mh2.<short>invokeExact(x);
166 assert a == b : a + " != " + b;
167 }
168 }
169
170 static void testchar() throws Throwable {
171 char[] a = new char[] {
172 Character.MIN_VALUE,
173 Character.MIN_VALUE + 1,
174 0x000F,
175 0x00FF,
176 0x0FFF,
177 Character.MAX_VALUE - 1,
178 Character.MAX_VALUE
179 };
180 for (int i = 0; i < a.length; i++) {
181 dochar(a[i]);
182 }
183 }
184 static void dochar(char x) throws Throwable {
185 if (DEBUG) System.out.println("char=" + x);
186
187 // boolean
188 {
189 MethodHandle mh1 = getmh1( boolean.class, boolean.class);
190 MethodHandle mh2 = getmh2(mh1, boolean.class, char.class);
191 boolean a = mh1.<boolean>invokeExact((x & 1) == 1);
192 boolean b = mh2.<boolean>invokeExact(x);
193 assert a == b : a + " != " + b;
194 }
195
196 // byte
197 {
198 MethodHandle mh1 = getmh1( byte.class, byte.class);
199 MethodHandle mh2 = getmh2(mh1, byte.class, char.class);
200 byte a = mh1.<byte>invokeExact((byte) x);
201 byte b = mh2.<byte>invokeExact(x);
202 assert a == b : a + " != " + b;
203 }
204
205 // char
206 {
207 MethodHandle mh1 = getmh1( char.class, char.class);
208 MethodHandle mh2 = getmh2(mh1, char.class, char.class);
209 char a = mh1.<char>invokeExact((char) x);
210 char b = mh2.<char>invokeExact(x);
211 assert a == b : a + " != " + b;
212 }
213
214 // short
215 {
216 MethodHandle mh1 = getmh1( short.class, short.class);
217 MethodHandle mh2 = getmh2(mh1, short.class, char.class);
218 short a = mh1.<short>invokeExact((short) x);
219 short b = mh2.<short>invokeExact(x);
220 assert a == b : a + " != " + b;
221 }
222 }
223
224 static void testshort() throws Throwable {
225 short[] a = new short[] {
226 Short.MIN_VALUE,
227 Short.MIN_VALUE + 1,
228 -0x0FFF,
229 -0x00FF,
230 -0x000F,
231 -1,
232 0,
233 1,
234 0x000F,
235 0x00FF,
236 0x0FFF,
237 Short.MAX_VALUE - 1,
238 Short.MAX_VALUE
239 };
240 for (int i = 0; i < a.length; i++) {
241 doshort(a[i]);
242 }
243 }
244 static void doshort(short x) throws Throwable {
245 if (DEBUG) System.out.println("short=" + x);
246
247 // boolean
248 {
249 MethodHandle mh1 = getmh1( boolean.class, boolean.class);
250 MethodHandle mh2 = getmh2(mh1, boolean.class, short.class);
251 boolean a = mh1.<boolean>invokeExact((x & 1) == 1);
252 boolean b = mh2.<boolean>invokeExact(x);
253 assert a == b : a + " != " + b;
254 }
255
256 // byte
257 {
258 MethodHandle mh1 = getmh1( byte.class, byte.class);
259 MethodHandle mh2 = getmh2(mh1, byte.class, short.class);
260 byte a = mh1.<byte>invokeExact((byte) x);
261 byte b = mh2.<byte>invokeExact(x);
262 assert a == b : a + " != " + b;
263 }
264
265 // char
266 {
267 MethodHandle mh1 = getmh1( char.class, char.class);
268 MethodHandle mh2 = getmh2(mh1, char.class, short.class);
269 char a = mh1.<char>invokeExact((char) x);
270 char b = mh2.<char>invokeExact(x);
271 assert a == b : a + " != " + b;
272 }
273
274 // short
275 {
276 MethodHandle mh1 = getmh1( short.class, short.class);
277 MethodHandle mh2 = getmh2(mh1, short.class, short.class);
278 short a = mh1.<short>invokeExact((short) x);
279 short b = mh2.<short>invokeExact(x);
280 assert a == b : a + " != " + b;
281 }
282 }
283
284 static void testint() throws Throwable {
285 int[] a = new int[] {
286 Integer.MIN_VALUE,
287 Integer.MIN_VALUE + 1,
288 -0x0FFFFFFF,
289 -0x00FFFFFF,
290 -0x000FFFFF,
291 -0x0000FFFF,
292 -0x00000FFF,
293 -0x000000FF,
294 -0x0000000F,
295 -1,
296 0,
297 1,
298 0x0000000F,
299 0x000000FF,
300 0x00000FFF,
301 0x0000FFFF,
302 0x000FFFFF,
303 0x00FFFFFF,
304 0x0FFFFFFF,
305 Integer.MAX_VALUE - 1,
306 Integer.MAX_VALUE
307 };
308 for (int i = 0; i < a.length; i++) {
309 doint(a[i]);
310 }
311 }
312 static void doint(int x) throws Throwable {
313 if (DEBUG) System.out.println("int=" + x);
314
315 // boolean
316 {
317 MethodHandle mh1 = getmh1( boolean.class, boolean.class);
318 MethodHandle mh2 = getmh2(mh1, boolean.class, int.class);
319 boolean a = mh1.<boolean>invokeExact((x & 1) == 1);
320 boolean b = mh2.<boolean>invokeExact(x);
321 assert a == b : a + " != " + b;
322 }
323
324 // byte
325 {
326 MethodHandle mh1 = getmh1( byte.class, byte.class);
327 MethodHandle mh2 = getmh2(mh1, byte.class, int.class);
328 byte a = mh1.<byte>invokeExact((byte) x);
329 byte b = mh2.<byte>invokeExact(x);
330 assert a == b : 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 = 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
351 // int
352 {
353 MethodHandle mh1 = getmh1( int.class, int.class);
354 MethodHandle mh2 = getmh2(mh1, int.class, int.class);
355 int a = mh1.<int>invokeExact((int) x);
356 int b = mh2.<int>invokeExact(x);
357 assert a == b : a + " != " + b;
358 }
359 }
360
361 // test adapter_opt_l2i
362 static void testlong() throws Throwable {
363 long[] a = new long[] {
364 Long.MIN_VALUE,
365 Long.MIN_VALUE + 1,
366 -0x000000000FFFFFFFL,
367 -0x0000000000FFFFFFL,
368 -0x00000000000FFFFFL,
369 -0x000000000000FFFFL,
370 -0x0000000000000FFFL,
371 -0x00000000000000FFL,
372 -0x000000000000000FL,
373 -1L,
374 0L,
375 1L,
376 0x000000000000000FL,
377 0x00000000000000FFL,
378 0x0000000000000FFFL,
379 0x0000000000000FFFL,
380 0x000000000000FFFFL,
381 0x00000000000FFFFFL,
382 0x0000000000FFFFFFL,
383 0x000000000FFFFFFFL,
384 Long.MAX_VALUE - 1,
385 Long.MAX_VALUE
386 };
387 for (int i = 0; i < a.length; i++) {
388 dolong(a[i]);
389 }
390 }
391 static void dolong(long x) throws Throwable {
392 if (DEBUG) System.out.println("long=" + x);
393
394 // boolean
395 {
396 MethodHandle mh1 = getmh1( boolean.class, boolean.class);
397 MethodHandle mh2 = getmh2(mh1, boolean.class, long.class);
398 boolean a = mh1.<boolean>invokeExact((x & 1L) == 1L);
399 boolean b = mh2.<boolean>invokeExact(x);
400 assert a == b : a + " != " + b;
401 }
402
403 // byte
404 {
405 MethodHandle mh1 = getmh1( byte.class, byte.class);
406 MethodHandle mh2 = getmh2(mh1, byte.class, long.class);
407 byte a = mh1.<byte>invokeExact((byte) x);
408 byte b = mh2.<byte>invokeExact(x);
409 assert a == b : a + " != " + b;
410 }
411
412 // char
413 {
414 MethodHandle mh1 = getmh1( char.class, char.class);
415 MethodHandle mh2 = getmh2(mh1, char.class, long.class);
416 char a = mh1.<char>invokeExact((char) x);
417 char b = mh2.<char>invokeExact(x);
418 assert a == b : a + " != " + b;
419 }
420
421 // short
422 {
423 MethodHandle mh1 = getmh1( short.class, short.class);
424 MethodHandle mh2 = getmh2(mh1, short.class, long.class);
425 short a = mh1.<short>invokeExact((short) x);
426 short b = mh2.<short>invokeExact(x);
427 assert a == b : a + " != " + b;
428 }
429
430 // int
431 {
432 MethodHandle mh1 = getmh1( int.class, int.class);
433 MethodHandle mh2 = getmh2(mh1, int.class, long.class);
434 int a = mh1.<int>invokeExact((int) x);
435 int b = mh2.<int>invokeExact(x);
436 assert a == b : a + " != " + b;
437 }
438
439 }
440
441 // to int
442 public static boolean foo(boolean i) { return i; }
443 public static byte foo(byte i) { return i; }
444 public static char foo(char i) { return i; }
445 public static short foo(short i) { return i; }
446 public static int foo(int i) { return i; }
447 }