Path: blob/master/test/jdk/java/lang/invoke/6987555/Test6987555.java
41153 views
/*1* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 698755526* @summary JSR 292 unboxing to a boolean value fails on big-endian SPARC27*28* @run main/othervm -Xint -ea -XX:+UnlockDiagnosticVMOptions -XX:+VerifyMethodHandles Test698755529*/3031import java.lang.invoke.*;3233public class Test6987555 {34private static final Class CLASS = Test6987555.class;35private static final String NAME = "foo";36private static final boolean DEBUG = false;3738public static void main(String[] args) throws Throwable {39testboolean();40testbyte();41testchar();42testshort();43testint();44}4546// boolean47static void testboolean() throws Throwable {48doboolean(false);49doboolean(true);50}51static void doboolean(boolean x) throws Throwable {52if (DEBUG) System.out.println("boolean=" + x);53MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(boolean.class, boolean.class));54MethodHandle mh2 = mh1.asType(MethodType.methodType(boolean.class, Boolean.class));55boolean a = (boolean) mh1.invokeExact(x);56boolean b = (boolean) mh2.invokeExact(Boolean.valueOf(x));57assert a == b : a + " != " + b;58}5960// byte61static void testbyte() throws Throwable {62byte[] a = new byte[] {63Byte.MIN_VALUE,64Byte.MIN_VALUE + 1,65-0x0F,66-1,670,681,690x0F,70Byte.MAX_VALUE - 1,71Byte.MAX_VALUE72};73for (int i = 0; i < a.length; i++) {74dobyte(a[i]);75}76}77static void dobyte(byte x) throws Throwable {78if (DEBUG) System.out.println("byte=" + x);79MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(byte.class, byte.class));80MethodHandle mh2 = mh1.asType(MethodType.methodType(byte.class, Byte.class));81byte a = (byte) mh1.invokeExact(x);82byte b = (byte) mh2.invokeExact(Byte.valueOf(x));83assert a == b : a + " != " + b;84}8586// char87static void testchar() throws Throwable {88char[] a = new char[] {89Character.MIN_VALUE,90Character.MIN_VALUE + 1,910x000F,920x00FF,930x0FFF,94Character.MAX_VALUE - 1,95Character.MAX_VALUE96};97for (int i = 0; i < a.length; i++) {98dochar(a[i]);99}100}101static void dochar(char x) throws Throwable {102if (DEBUG) System.out.println("char=" + x);103MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(char.class, char.class));104MethodHandle mh2 = mh1.asType(MethodType.methodType(char.class, Character.class));105char a = (char) mh1.invokeExact(x);106char b = (char) mh2.invokeExact(Character.valueOf(x));107assert a == b : a + " != " + b;108}109110// short111static void testshort() throws Throwable {112short[] a = new short[] {113Short.MIN_VALUE,114Short.MIN_VALUE + 1,115-0x0FFF,116-0x00FF,117-0x000F,118-1,1190,1201,1210x000F,1220x00FF,1230x0FFF,124Short.MAX_VALUE - 1,125Short.MAX_VALUE126};127for (int i = 0; i < a.length; i++) {128doshort(a[i]);129}130}131static void doshort(short x) throws Throwable {132if (DEBUG) System.out.println("short=" + x);133MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(short.class, short.class));134MethodHandle mh2 = mh1.asType(MethodType.methodType(short.class, Short.class));135short a = (short) mh1.invokeExact(x);136short b = (short) mh2.invokeExact(Short.valueOf(x));137assert a == b : a + " != " + b;138}139140// int141static void testint() throws Throwable {142int[] a = new int[] {143Integer.MIN_VALUE,144Integer.MIN_VALUE + 1,145-0x00000FFF,146-0x000000FF,147-0x0000000F,148-1,1490,1501,1510x0000000F,1520x000000FF,1530x00000FFF,154Integer.MAX_VALUE - 1,155Integer.MAX_VALUE156};157for (int i = 0; i < a.length; i++) {158doint(a[i]);159}160}161static void doint(int x) throws Throwable {162if (DEBUG) System.out.println("int=" + x);163MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(int.class, int.class));164MethodHandle mh2 = mh1.asType(MethodType.methodType(int.class, Integer.class));165int a = (int) mh1.invokeExact(x);166int b = (int) mh2.invokeExact(Integer.valueOf(x));167assert a == b : a + " != " + b;168}169170public static boolean foo(boolean i) { return i; }171public static byte foo(byte i) { return i; }172public static char foo(char i) { return i; }173public static short foo(short i) { return i; }174public static int foo(int i) { return i; }175}176177178