Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/invoke/6987555/Test6987555.java
47311 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*22*/2324/**25* @test26* @bug 698755527* @summary JSR 292 unboxing to a boolean value fails on big-endian SPARC28*29* @run main/othervm -Xint -ea -XX:+UnlockDiagnosticVMOptions -XX:+VerifyMethodHandles Test698755530*/3132import java.lang.invoke.*;3334public class Test6987555 {35private static final Class CLASS = Test6987555.class;36private static final String NAME = "foo";37private static final boolean DEBUG = false;3839public static void main(String[] args) throws Throwable {40testboolean();41testbyte();42testchar();43testshort();44testint();45}4647// boolean48static void testboolean() throws Throwable {49doboolean(false);50doboolean(true);51}52static void doboolean(boolean x) throws Throwable {53if (DEBUG) System.out.println("boolean=" + x);54MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(boolean.class, boolean.class));55MethodHandle mh2 = mh1.asType(MethodType.methodType(boolean.class, Boolean.class));56boolean a = (boolean) mh1.invokeExact(x);57boolean b = (boolean) mh2.invokeExact(Boolean.valueOf(x));58assert a == b : a + " != " + b;59}6061// byte62static void testbyte() throws Throwable {63byte[] a = new byte[] {64Byte.MIN_VALUE,65Byte.MIN_VALUE + 1,66-0x0F,67-1,680,691,700x0F,71Byte.MAX_VALUE - 1,72Byte.MAX_VALUE73};74for (int i = 0; i < a.length; i++) {75dobyte(a[i]);76}77}78static void dobyte(byte x) throws Throwable {79if (DEBUG) System.out.println("byte=" + x);80MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(byte.class, byte.class));81MethodHandle mh2 = mh1.asType(MethodType.methodType(byte.class, Byte.class));82byte a = (byte) mh1.invokeExact(x);83byte b = (byte) mh2.invokeExact(Byte.valueOf(x));84assert a == b : a + " != " + b;85}8687// char88static void testchar() throws Throwable {89char[] a = new char[] {90Character.MIN_VALUE,91Character.MIN_VALUE + 1,920x000F,930x00FF,940x0FFF,95Character.MAX_VALUE - 1,96Character.MAX_VALUE97};98for (int i = 0; i < a.length; i++) {99dochar(a[i]);100}101}102static void dochar(char x) throws Throwable {103if (DEBUG) System.out.println("char=" + x);104MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(char.class, char.class));105MethodHandle mh2 = mh1.asType(MethodType.methodType(char.class, Character.class));106char a = (char) mh1.invokeExact(x);107char b = (char) mh2.invokeExact(Character.valueOf(x));108assert a == b : a + " != " + b;109}110111// short112static void testshort() throws Throwable {113short[] a = new short[] {114Short.MIN_VALUE,115Short.MIN_VALUE + 1,116-0x0FFF,117-0x00FF,118-0x000F,119-1,1200,1211,1220x000F,1230x00FF,1240x0FFF,125Short.MAX_VALUE - 1,126Short.MAX_VALUE127};128for (int i = 0; i < a.length; i++) {129doshort(a[i]);130}131}132static void doshort(short x) throws Throwable {133if (DEBUG) System.out.println("short=" + x);134MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(short.class, short.class));135MethodHandle mh2 = mh1.asType(MethodType.methodType(short.class, Short.class));136short a = (short) mh1.invokeExact(x);137short b = (short) mh2.invokeExact(Short.valueOf(x));138assert a == b : a + " != " + b;139}140141// int142static void testint() throws Throwable {143int[] a = new int[] {144Integer.MIN_VALUE,145Integer.MIN_VALUE + 1,146-0x00000FFF,147-0x000000FF,148-0x0000000F,149-1,1500,1511,1520x0000000F,1530x000000FF,1540x00000FFF,155Integer.MAX_VALUE - 1,156Integer.MAX_VALUE157};158for (int i = 0; i < a.length; i++) {159doint(a[i]);160}161}162static void doint(int x) throws Throwable {163if (DEBUG) System.out.println("int=" + x);164MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(int.class, int.class));165MethodHandle mh2 = mh1.asType(MethodType.methodType(int.class, Integer.class));166int a = (int) mh1.invokeExact(x);167int b = (int) mh2.invokeExact(Integer.valueOf(x));168assert a == b : a + " != " + b;169}170171public static boolean foo(boolean i) { return i; }172public static byte foo(byte i) { return i; }173public static char foo(char i) { return i; }174public static short foo(short i) { return i; }175public static int foo(int i) { return i; }176}177178179