3792N/A/*
3792N/A * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
3792N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3792N/A *
3792N/A * This code is free software; you can redistribute it and/or modify it
3792N/A * under the terms of the GNU General Public License version 2 only, as
3792N/A * published by the Free Software Foundation.
3792N/A *
3792N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3792N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3792N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3792N/A * version 2 for more details (a copy is included in the LICENSE file that
3792N/A * accompanied this code).
3792N/A *
3792N/A * You should have received a copy of the GNU General Public License version
3792N/A * 2 along with this work; if not, write to the Free Software Foundation,
3792N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3792N/A *
3792N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3792N/A * or visit www.oracle.com if you need additional information or have any
3792N/A * questions.
3792N/A *
3792N/A */
3792N/A
3792N/A/**
3792N/A * @test
3792N/A * @bug 6987555
3792N/A * @summary JSR 292 unboxing to a boolean value fails on big-endian SPARC
3792N/A *
3907N/A * @run main/othervm -Xint -ea -XX:+UnlockDiagnosticVMOptions -XX:+VerifyMethodHandles Test6987555
3792N/A */
3792N/A
3793N/Aimport java.lang.invoke.*;
3792N/A
3792N/Apublic class Test6987555 {
3792N/A private static final Class CLASS = Test6987555.class;
3792N/A private static final String NAME = "foo";
3792N/A private static final boolean DEBUG = false;
3792N/A
3792N/A public static void main(String[] args) throws Throwable {
3792N/A testboolean();
3792N/A testbyte();
3792N/A testchar();
3792N/A testshort();
3792N/A testint();
3792N/A }
3792N/A
3792N/A // boolean
3792N/A static void testboolean() throws Throwable {
3792N/A doboolean(false);
3792N/A doboolean(true);
3792N/A }
3792N/A static void doboolean(boolean x) throws Throwable {
3792N/A if (DEBUG) System.out.println("boolean=" + x);
3792N/A MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(boolean.class, boolean.class));
3792N/A MethodHandle mh2 = mh1.asType(MethodType.methodType(boolean.class, Boolean.class));
3792N/A boolean a = (boolean) mh1.invokeExact(x);
3792N/A boolean b = (boolean) mh2.invokeExact(Boolean.valueOf(x));
3792N/A assert a == b : a + " != " + b;
3792N/A }
3792N/A
3792N/A // byte
3792N/A static void testbyte() throws Throwable {
3792N/A byte[] a = new byte[] {
3792N/A Byte.MIN_VALUE,
3792N/A Byte.MIN_VALUE + 1,
3792N/A -0x0F,
3792N/A -1,
3792N/A 0,
3792N/A 1,
3792N/A 0x0F,
3792N/A Byte.MAX_VALUE - 1,
3792N/A Byte.MAX_VALUE
3792N/A };
3792N/A for (int i = 0; i < a.length; i++) {
3792N/A dobyte(a[i]);
3792N/A }
3792N/A }
3792N/A static void dobyte(byte x) throws Throwable {
3792N/A if (DEBUG) System.out.println("byte=" + x);
3792N/A MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(byte.class, byte.class));
3792N/A MethodHandle mh2 = mh1.asType(MethodType.methodType(byte.class, Byte.class));
3792N/A byte a = (byte) mh1.invokeExact(x);
3792N/A byte b = (byte) mh2.invokeExact(Byte.valueOf(x));
3792N/A assert a == b : a + " != " + b;
3792N/A }
3792N/A
3792N/A // char
3792N/A static void testchar() throws Throwable {
3792N/A char[] a = new char[] {
3792N/A Character.MIN_VALUE,
3792N/A Character.MIN_VALUE + 1,
3792N/A 0x000F,
3792N/A 0x00FF,
3792N/A 0x0FFF,
3792N/A Character.MAX_VALUE - 1,
3792N/A Character.MAX_VALUE
3792N/A };
3792N/A for (int i = 0; i < a.length; i++) {
3792N/A dochar(a[i]);
3792N/A }
3792N/A }
3792N/A static void dochar(char x) throws Throwable {
3792N/A if (DEBUG) System.out.println("char=" + x);
3792N/A MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(char.class, char.class));
3792N/A MethodHandle mh2 = mh1.asType(MethodType.methodType(char.class, Character.class));
3792N/A char a = (char) mh1.invokeExact(x);
3792N/A char b = (char) mh2.invokeExact(Character.valueOf(x));
3792N/A assert a == b : a + " != " + b;
3792N/A }
3792N/A
3792N/A // short
3792N/A static void testshort() throws Throwable {
3792N/A short[] a = new short[] {
3792N/A Short.MIN_VALUE,
3792N/A Short.MIN_VALUE + 1,
3792N/A -0x0FFF,
3792N/A -0x00FF,
3792N/A -0x000F,
3792N/A -1,
3792N/A 0,
3792N/A 1,
3792N/A 0x000F,
3792N/A 0x00FF,
3792N/A 0x0FFF,
3792N/A Short.MAX_VALUE - 1,
3792N/A Short.MAX_VALUE
3792N/A };
3792N/A for (int i = 0; i < a.length; i++) {
3792N/A doshort(a[i]);
3792N/A }
3792N/A }
3792N/A static void doshort(short x) throws Throwable {
3792N/A if (DEBUG) System.out.println("short=" + x);
3792N/A MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(short.class, short.class));
3792N/A MethodHandle mh2 = mh1.asType(MethodType.methodType(short.class, Short.class));
3792N/A short a = (short) mh1.invokeExact(x);
3792N/A short b = (short) mh2.invokeExact(Short.valueOf(x));
3792N/A assert a == b : a + " != " + b;
3792N/A }
3792N/A
3792N/A // int
3792N/A static void testint() throws Throwable {
3792N/A int[] a = new int[] {
3792N/A Integer.MIN_VALUE,
3792N/A Integer.MIN_VALUE + 1,
3792N/A -0x00000FFF,
3792N/A -0x000000FF,
3792N/A -0x0000000F,
3792N/A -1,
3792N/A 0,
3792N/A 1,
3792N/A 0x0000000F,
3792N/A 0x000000FF,
3792N/A 0x00000FFF,
3792N/A Integer.MAX_VALUE - 1,
3792N/A Integer.MAX_VALUE
3792N/A };
3792N/A for (int i = 0; i < a.length; i++) {
3792N/A doint(a[i]);
3792N/A }
3792N/A }
3792N/A static void doint(int x) throws Throwable {
3792N/A if (DEBUG) System.out.println("int=" + x);
3792N/A MethodHandle mh1 = MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(int.class, int.class));
3792N/A MethodHandle mh2 = mh1.asType(MethodType.methodType(int.class, Integer.class));
3792N/A int a = (int) mh1.invokeExact(x);
3792N/A int b = (int) mh2.invokeExact(Integer.valueOf(x));
3792N/A assert a == b : a + " != " + b;
3792N/A }
3792N/A
3792N/A public static boolean foo(boolean i) { return i; }
3792N/A public static byte foo(byte i) { return i; }
3792N/A public static char foo(char i) { return i; }
3792N/A public static short foo(short i) { return i; }
3792N/A public static int foo(int i) { return i; }
3792N/A}