3792N/A/*
3793N/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 6991596
3792N/A * @summary JSR 292 unimplemented adapter_opt_i2i and adapter_opt_l2i on SPARC
3792N/A *
3907N/A * @run main/othervm -ea -XX:+UnlockDiagnosticVMOptions -XX:+VerifyMethodHandles Test6991596
3792N/A */
3792N/A
3793N/Aimport java.lang.invoke.*;
3792N/A
3792N/Apublic class Test6991596 {
3792N/A private static final Class CLASS = Test6991596.class;
3792N/A private static final String NAME = "foo";
3792N/A private static final boolean DEBUG = System.getProperty("DEBUG", "false").equals("true");
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 testlong();
3792N/A }
3792N/A
3792N/A // Helpers to get various methods.
3792N/A static MethodHandle getmh1(Class ret, Class arg) throws ReflectiveOperationException {
3792N/A return MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(ret, arg));
3792N/A }
3792N/A static MethodHandle getmh2(MethodHandle mh1, Class ret, Class arg) {
4244N/A return MethodHandles.explicitCastArguments(mh1, MethodType.methodType(ret, arg));
3792N/A }
3792N/A static MethodHandle getmh3(MethodHandle mh1, Class ret, Class arg) {
4244N/A return MethodHandles.explicitCastArguments(mh1, MethodType.methodType(ret, arg));
3792N/A }
3792N/A
3792N/A // test adapter_opt_i2i
3792N/A static void testboolean() throws Throwable {
3792N/A boolean[] a = new boolean[] {
3792N/A true,
3792N/A false
3792N/A };
3792N/A for (int i = 0; i < a.length; i++) {
3792N/A doboolean(a[i]);
3792N/A }
3792N/A }
3792N/A static void doboolean(boolean x) throws Throwable {
3792N/A if (DEBUG) System.out.println("boolean=" + x);
3792N/A
3792N/A // boolean
3792N/A {
3792N/A MethodHandle mh1 = getmh1( boolean.class, boolean.class);
3792N/A MethodHandle mh2 = getmh2(mh1, boolean.class, boolean.class);
3792N/A // TODO add this for all cases when the bugs are fixed.
3792N/A //MethodHandle mh3 = getmh3(mh1, boolean.class, boolean.class);
3792N/A boolean a = (boolean) mh1.invokeExact((boolean) x);
3792N/A boolean b = (boolean) mh2.invokeExact(x);
3792N/A //boolean c = mh3.<boolean>invokeExact((boolean) x);
3792N/A check(x, a, b);
3792N/A //check(x, c, x);
3792N/A }
3792N/A
3792N/A // byte
3792N/A {
3792N/A MethodHandle mh1 = getmh1( byte.class, byte.class );
3792N/A MethodHandle mh2 = getmh2(mh1, byte.class, boolean.class);
3792N/A byte a = (byte) mh1.invokeExact((byte) (x ? 1 : 0));
3792N/A byte b = (byte) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // char
3792N/A {
3792N/A MethodHandle mh1 = getmh1( char.class, char.class);
3792N/A MethodHandle mh2 = getmh2(mh1, char.class, boolean.class);
3792N/A char a = (char) mh1.invokeExact((char) (x ? 1 : 0));
3792N/A char b = (char) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // short
3792N/A {
3792N/A MethodHandle mh1 = getmh1( short.class, short.class);
3792N/A MethodHandle mh2 = getmh2(mh1, short.class, boolean.class);
3792N/A short a = (short) mh1.invokeExact((short) (x ? 1 : 0));
3792N/A short b = (short) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A }
3792N/A
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
3792N/A // boolean
3792N/A {
3792N/A MethodHandle mh1 = getmh1( boolean.class, boolean.class);
3792N/A MethodHandle mh2 = getmh2(mh1, boolean.class, byte.class);
3792N/A boolean a = (boolean) mh1.invokeExact((x & 1) == 1);
3792N/A boolean b = (boolean) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // byte
3792N/A {
3792N/A MethodHandle mh1 = getmh1( byte.class, byte.class);
3792N/A MethodHandle mh2 = getmh2(mh1, byte.class, byte.class);
3792N/A byte a = (byte) mh1.invokeExact((byte) x);
3792N/A byte b = (byte) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // char
3792N/A {
3792N/A MethodHandle mh1 = getmh1( char.class, char.class);
3792N/A MethodHandle mh2 = getmh2(mh1, char.class, byte.class);
3792N/A char a = (char) mh1.invokeExact((char) x);
3792N/A char b = (char) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // short
3792N/A {
3792N/A MethodHandle mh1 = getmh1( short.class, short.class);
3792N/A MethodHandle mh2 = getmh2(mh1, short.class, byte.class);
3792N/A short a = (short) mh1.invokeExact((short) x);
3792N/A short b = (short) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A }
3792N/A
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
3792N/A // boolean
3792N/A {
3792N/A MethodHandle mh1 = getmh1( boolean.class, boolean.class);
3792N/A MethodHandle mh2 = getmh2(mh1, boolean.class, char.class);
3792N/A boolean a = (boolean) mh1.invokeExact((x & 1) == 1);
3792N/A boolean b = (boolean) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // byte
3792N/A {
3792N/A MethodHandle mh1 = getmh1( byte.class, byte.class);
3792N/A MethodHandle mh2 = getmh2(mh1, byte.class, char.class);
3792N/A byte a = (byte) mh1.invokeExact((byte) x);
3792N/A byte b = (byte) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // char
3792N/A {
3792N/A MethodHandle mh1 = getmh1( char.class, char.class);
3792N/A MethodHandle mh2 = getmh2(mh1, char.class, char.class);
3792N/A char a = (char) mh1.invokeExact((char) x);
3792N/A char b = (char) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // short
3792N/A {
3792N/A MethodHandle mh1 = getmh1( short.class, short.class);
3792N/A MethodHandle mh2 = getmh2(mh1, short.class, char.class);
3792N/A short a = (short) mh1.invokeExact((short) x);
3792N/A short b = (short) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A }
3792N/A
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
3792N/A // boolean
3792N/A {
3792N/A MethodHandle mh1 = getmh1( boolean.class, boolean.class);
3792N/A MethodHandle mh2 = getmh2(mh1, boolean.class, short.class);
3792N/A boolean a = (boolean) mh1.invokeExact((x & 1) == 1);
3792N/A boolean b = (boolean) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // byte
3792N/A {
3792N/A MethodHandle mh1 = getmh1( byte.class, byte.class);
3792N/A MethodHandle mh2 = getmh2(mh1, byte.class, short.class);
3792N/A byte a = (byte) mh1.invokeExact((byte) x);
3792N/A byte b = (byte) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // char
3792N/A {
3792N/A MethodHandle mh1 = getmh1( char.class, char.class);
3792N/A MethodHandle mh2 = getmh2(mh1, char.class, short.class);
3792N/A char a = (char) mh1.invokeExact((char) x);
3792N/A char b = (char) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // short
3792N/A {
3792N/A MethodHandle mh1 = getmh1( short.class, short.class);
3792N/A MethodHandle mh2 = getmh2(mh1, short.class, short.class);
3792N/A short a = (short) mh1.invokeExact((short) x);
3792N/A short b = (short) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A }
3792N/A
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 -0x0FFFFFFF,
3792N/A -0x00FFFFFF,
3792N/A -0x000FFFFF,
3792N/A -0x0000FFFF,
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 0x0000FFFF,
3792N/A 0x000FFFFF,
3792N/A 0x00FFFFFF,
3792N/A 0x0FFFFFFF,
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
3792N/A // boolean
3792N/A {
3792N/A MethodHandle mh1 = getmh1( boolean.class, boolean.class);
3792N/A MethodHandle mh2 = getmh2(mh1, boolean.class, int.class);
3792N/A boolean a = (boolean) mh1.invokeExact((x & 1) == 1);
3792N/A boolean b = (boolean) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // byte
3792N/A {
3792N/A MethodHandle mh1 = getmh1( byte.class, byte.class);
3792N/A MethodHandle mh2 = getmh2(mh1, byte.class, int.class);
3792N/A byte a = (byte) mh1.invokeExact((byte) x);
3792N/A byte b = (byte) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // char
3792N/A {
3792N/A MethodHandle mh1 = getmh1( char.class, char.class);
3792N/A MethodHandle mh2 = getmh2(mh1, char.class, int.class);
3792N/A char a = (char) mh1.invokeExact((char) x);
3792N/A char b = (char) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // short
3792N/A {
3792N/A MethodHandle mh1 = getmh1( short.class, short.class);
3792N/A MethodHandle mh2 = getmh2(mh1, short.class, int.class);
3792N/A short a = (short) mh1.invokeExact((short) x);
3792N/A short b = (short) mh2.invokeExact(x);
3792N/A assert a == b : a + " != " + b;
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // int
3792N/A {
3792N/A MethodHandle mh1 = getmh1( int.class, int.class);
3792N/A MethodHandle mh2 = getmh2(mh1, int.class, int.class);
3792N/A int a = (int) mh1.invokeExact((int) x);
3792N/A int b = (int) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A }
3792N/A
3792N/A // test adapter_opt_l2i
3792N/A static void testlong() throws Throwable {
3792N/A long[] a = new long[] {
3792N/A Long.MIN_VALUE,
3792N/A Long.MIN_VALUE + 1,
3792N/A -0x000000000FFFFFFFL,
3792N/A -0x0000000000FFFFFFL,
3792N/A -0x00000000000FFFFFL,
3792N/A -0x000000000000FFFFL,
3792N/A -0x0000000000000FFFL,
3792N/A -0x00000000000000FFL,
3792N/A -0x000000000000000FL,
3792N/A -1L,
3792N/A 0L,
3792N/A 1L,
3792N/A 0x000000000000000FL,
3792N/A 0x00000000000000FFL,
3792N/A 0x0000000000000FFFL,
3792N/A 0x0000000000000FFFL,
3792N/A 0x000000000000FFFFL,
3792N/A 0x00000000000FFFFFL,
3792N/A 0x0000000000FFFFFFL,
3792N/A 0x000000000FFFFFFFL,
3792N/A Long.MAX_VALUE - 1,
3792N/A Long.MAX_VALUE
3792N/A };
3792N/A for (int i = 0; i < a.length; i++) {
3792N/A dolong(a[i]);
3792N/A }
3792N/A }
3792N/A static void dolong(long x) throws Throwable {
3792N/A if (DEBUG) System.out.println("long=" + x);
3792N/A
3792N/A // boolean
3792N/A {
3792N/A MethodHandle mh1 = getmh1( boolean.class, boolean.class);
3792N/A MethodHandle mh2 = getmh2(mh1, boolean.class, long.class);
3792N/A boolean a = (boolean) mh1.invokeExact((x & 1L) == 1L);
3792N/A boolean b = (boolean) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // byte
3792N/A {
3792N/A MethodHandle mh1 = getmh1( byte.class, byte.class);
3792N/A MethodHandle mh2 = getmh2(mh1, byte.class, long.class);
3792N/A byte a = (byte) mh1.invokeExact((byte) x);
3792N/A byte b = (byte) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // char
3792N/A {
3792N/A MethodHandle mh1 = getmh1( char.class, char.class);
3792N/A MethodHandle mh2 = getmh2(mh1, char.class, long.class);
3792N/A char a = (char) mh1.invokeExact((char) x);
3792N/A char b = (char) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // short
3792N/A {
3792N/A MethodHandle mh1 = getmh1( short.class, short.class);
3792N/A MethodHandle mh2 = getmh2(mh1, short.class, long.class);
3792N/A short a = (short) mh1.invokeExact((short) x);
3792N/A short b = (short) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A
3792N/A // int
3792N/A {
3792N/A MethodHandle mh1 = getmh1( int.class, int.class);
3792N/A MethodHandle mh2 = getmh2(mh1, int.class, long.class);
3792N/A int a = (int) mh1.invokeExact((int) x);
3792N/A int b = (int) mh2.invokeExact(x);
3792N/A check(x, a, b);
3792N/A }
3792N/A }
3792N/A
3792N/A 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); }
3792N/A 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); }
3792N/A 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); }
3792N/A
3792N/A 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); }
3792N/A 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); }
3792N/A 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); }
3792N/A
3792N/A 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); }
3792N/A 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); }
3792N/A 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); }
3792N/A
3792N/A static void p(String x, String e, String a) { if (DEBUG) System.out.println(x + ": expected: " + e + ", actual: " + a); }
3792N/A
3792N/A static String z2h(boolean x) { return x ? "1" : "0"; }
3792N/A static String i2h(int x) { return Integer.toHexString(x); }
3792N/A static String l2h(long x) { return Long.toHexString(x); }
3792N/A
3792N/A // to int
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}