Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/invoke/6991596/Test6991596.java
48230 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 699159627* @summary JSR 292 unimplemented adapter_opt_i2i and adapter_opt_l2i on SPARC28*29* @run main/othervm -ea -XX:+UnlockDiagnosticVMOptions -XX:+VerifyMethodHandles Test699159630*/3132import java.lang.invoke.*;3334public class Test6991596 {35private static final Class CLASS = Test6991596.class;36private static final String NAME = "foo";37private static final boolean DEBUG = System.getProperty("DEBUG", "false").equals("true");3839public static void main(String[] args) throws Throwable {40testboolean();41testbyte();42testchar();43testshort();44testint();45testlong();46}4748// Helpers to get various methods.49static MethodHandle getmh1(Class ret, Class arg) throws ReflectiveOperationException {50return MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(ret, arg));51}52static MethodHandle getmh2(MethodHandle mh1, Class ret, Class arg) {53return MethodHandles.explicitCastArguments(mh1, MethodType.methodType(ret, arg));54}55static MethodHandle getmh3(MethodHandle mh1, Class ret, Class arg) {56return MethodHandles.explicitCastArguments(mh1, MethodType.methodType(ret, arg));57}5859// test adapter_opt_i2i60static void testboolean() throws Throwable {61boolean[] a = new boolean[] {62true,63false64};65for (int i = 0; i < a.length; i++) {66doboolean(a[i]);67}68}69static void doboolean(boolean x) throws Throwable {70if (DEBUG) System.out.println("boolean=" + x);7172// boolean73{74MethodHandle mh1 = getmh1( boolean.class, boolean.class);75MethodHandle mh2 = getmh2(mh1, boolean.class, boolean.class);76// TODO add this for all cases when the bugs are fixed.77//MethodHandle mh3 = getmh3(mh1, boolean.class, boolean.class);78boolean a = (boolean) mh1.invokeExact((boolean) x);79boolean b = (boolean) mh2.invokeExact(x);80//boolean c = mh3.<boolean>invokeExact((boolean) x);81check(x, a, b);82//check(x, c, x);83}8485// byte86{87MethodHandle mh1 = getmh1( byte.class, byte.class );88MethodHandle mh2 = getmh2(mh1, byte.class, boolean.class);89byte a = (byte) mh1.invokeExact((byte) (x ? 1 : 0));90byte b = (byte) mh2.invokeExact(x);91check(x, a, b);92}9394// char95{96MethodHandle mh1 = getmh1( char.class, char.class);97MethodHandle mh2 = getmh2(mh1, char.class, boolean.class);98char a = (char) mh1.invokeExact((char) (x ? 1 : 0));99char b = (char) mh2.invokeExact(x);100check(x, a, b);101}102103// short104{105MethodHandle mh1 = getmh1( short.class, short.class);106MethodHandle mh2 = getmh2(mh1, short.class, boolean.class);107short a = (short) mh1.invokeExact((short) (x ? 1 : 0));108short b = (short) mh2.invokeExact(x);109check(x, a, b);110}111}112113static void testbyte() throws Throwable {114byte[] a = new byte[] {115Byte.MIN_VALUE,116Byte.MIN_VALUE + 1,117-0x0F,118-1,1190,1201,1210x0F,122Byte.MAX_VALUE - 1,123Byte.MAX_VALUE124};125for (int i = 0; i < a.length; i++) {126dobyte(a[i]);127}128}129static void dobyte(byte x) throws Throwable {130if (DEBUG) System.out.println("byte=" + x);131132// boolean133{134MethodHandle mh1 = getmh1( boolean.class, boolean.class);135MethodHandle mh2 = getmh2(mh1, boolean.class, byte.class);136boolean a = (boolean) mh1.invokeExact((x & 1) == 1);137boolean b = (boolean) mh2.invokeExact(x);138check(x, a, b);139}140141// byte142{143MethodHandle mh1 = getmh1( byte.class, byte.class);144MethodHandle mh2 = getmh2(mh1, byte.class, byte.class);145byte a = (byte) mh1.invokeExact((byte) x);146byte b = (byte) mh2.invokeExact(x);147check(x, a, b);148}149150// char151{152MethodHandle mh1 = getmh1( char.class, char.class);153MethodHandle mh2 = getmh2(mh1, char.class, byte.class);154char a = (char) mh1.invokeExact((char) x);155char b = (char) mh2.invokeExact(x);156check(x, a, b);157}158159// short160{161MethodHandle mh1 = getmh1( short.class, short.class);162MethodHandle mh2 = getmh2(mh1, short.class, byte.class);163short a = (short) mh1.invokeExact((short) x);164short b = (short) mh2.invokeExact(x);165check(x, a, b);166}167}168169static void testchar() throws Throwable {170char[] a = new char[] {171Character.MIN_VALUE,172Character.MIN_VALUE + 1,1730x000F,1740x00FF,1750x0FFF,176Character.MAX_VALUE - 1,177Character.MAX_VALUE178};179for (int i = 0; i < a.length; i++) {180dochar(a[i]);181}182}183static void dochar(char x) throws Throwable {184if (DEBUG) System.out.println("char=" + x);185186// boolean187{188MethodHandle mh1 = getmh1( boolean.class, boolean.class);189MethodHandle mh2 = getmh2(mh1, boolean.class, char.class);190boolean a = (boolean) mh1.invokeExact((x & 1) == 1);191boolean b = (boolean) mh2.invokeExact(x);192check(x, a, b);193}194195// byte196{197MethodHandle mh1 = getmh1( byte.class, byte.class);198MethodHandle mh2 = getmh2(mh1, byte.class, char.class);199byte a = (byte) mh1.invokeExact((byte) x);200byte b = (byte) mh2.invokeExact(x);201check(x, a, b);202}203204// char205{206MethodHandle mh1 = getmh1( char.class, char.class);207MethodHandle mh2 = getmh2(mh1, char.class, char.class);208char a = (char) mh1.invokeExact((char) x);209char b = (char) mh2.invokeExact(x);210check(x, a, b);211}212213// short214{215MethodHandle mh1 = getmh1( short.class, short.class);216MethodHandle mh2 = getmh2(mh1, short.class, char.class);217short a = (short) mh1.invokeExact((short) x);218short b = (short) mh2.invokeExact(x);219check(x, a, b);220}221}222223static void testshort() throws Throwable {224short[] a = new short[] {225Short.MIN_VALUE,226Short.MIN_VALUE + 1,227-0x0FFF,228-0x00FF,229-0x000F,230-1,2310,2321,2330x000F,2340x00FF,2350x0FFF,236Short.MAX_VALUE - 1,237Short.MAX_VALUE238};239for (int i = 0; i < a.length; i++) {240doshort(a[i]);241}242}243static void doshort(short x) throws Throwable {244if (DEBUG) System.out.println("short=" + x);245246// boolean247{248MethodHandle mh1 = getmh1( boolean.class, boolean.class);249MethodHandle mh2 = getmh2(mh1, boolean.class, short.class);250boolean a = (boolean) mh1.invokeExact((x & 1) == 1);251boolean b = (boolean) mh2.invokeExact(x);252check(x, a, b);253}254255// byte256{257MethodHandle mh1 = getmh1( byte.class, byte.class);258MethodHandle mh2 = getmh2(mh1, byte.class, short.class);259byte a = (byte) mh1.invokeExact((byte) x);260byte b = (byte) mh2.invokeExact(x);261check(x, a, b);262}263264// char265{266MethodHandle mh1 = getmh1( char.class, char.class);267MethodHandle mh2 = getmh2(mh1, char.class, short.class);268char a = (char) mh1.invokeExact((char) x);269char b = (char) mh2.invokeExact(x);270check(x, a, b);271}272273// short274{275MethodHandle mh1 = getmh1( short.class, short.class);276MethodHandle mh2 = getmh2(mh1, short.class, short.class);277short a = (short) mh1.invokeExact((short) x);278short b = (short) mh2.invokeExact(x);279check(x, a, b);280}281}282283static void testint() throws Throwable {284int[] a = new int[] {285Integer.MIN_VALUE,286Integer.MIN_VALUE + 1,287-0x0FFFFFFF,288-0x00FFFFFF,289-0x000FFFFF,290-0x0000FFFF,291-0x00000FFF,292-0x000000FF,293-0x0000000F,294-1,2950,2961,2970x0000000F,2980x000000FF,2990x00000FFF,3000x0000FFFF,3010x000FFFFF,3020x00FFFFFF,3030x0FFFFFFF,304Integer.MAX_VALUE - 1,305Integer.MAX_VALUE306};307for (int i = 0; i < a.length; i++) {308doint(a[i]);309}310}311static void doint(int x) throws Throwable {312if (DEBUG) System.out.println("int=" + x);313314// boolean315{316MethodHandle mh1 = getmh1( boolean.class, boolean.class);317MethodHandle mh2 = getmh2(mh1, boolean.class, int.class);318boolean a = (boolean) mh1.invokeExact((x & 1) == 1);319boolean b = (boolean) mh2.invokeExact(x);320check(x, a, b);321}322323// byte324{325MethodHandle mh1 = getmh1( byte.class, byte.class);326MethodHandle mh2 = getmh2(mh1, byte.class, int.class);327byte a = (byte) mh1.invokeExact((byte) x);328byte b = (byte) mh2.invokeExact(x);329check(x, a, b);330}331332// char333{334MethodHandle mh1 = getmh1( char.class, char.class);335MethodHandle mh2 = getmh2(mh1, char.class, int.class);336char a = (char) mh1.invokeExact((char) x);337char b = (char) mh2.invokeExact(x);338check(x, a, b);339}340341// short342{343MethodHandle mh1 = getmh1( short.class, short.class);344MethodHandle mh2 = getmh2(mh1, short.class, int.class);345short a = (short) mh1.invokeExact((short) x);346short b = (short) mh2.invokeExact(x);347assert a == b : a + " != " + b;348check(x, a, b);349}350351// int352{353MethodHandle mh1 = getmh1( int.class, int.class);354MethodHandle mh2 = getmh2(mh1, int.class, int.class);355int a = (int) mh1.invokeExact((int) x);356int b = (int) mh2.invokeExact(x);357check(x, a, b);358}359}360361// test adapter_opt_l2i362static void testlong() throws Throwable {363long[] a = new long[] {364Long.MIN_VALUE,365Long.MIN_VALUE + 1,366-0x000000000FFFFFFFL,367-0x0000000000FFFFFFL,368-0x00000000000FFFFFL,369-0x000000000000FFFFL,370-0x0000000000000FFFL,371-0x00000000000000FFL,372-0x000000000000000FL,373-1L,3740L,3751L,3760x000000000000000FL,3770x00000000000000FFL,3780x0000000000000FFFL,3790x0000000000000FFFL,3800x000000000000FFFFL,3810x00000000000FFFFFL,3820x0000000000FFFFFFL,3830x000000000FFFFFFFL,384Long.MAX_VALUE - 1,385Long.MAX_VALUE386};387for (int i = 0; i < a.length; i++) {388dolong(a[i]);389}390}391static void dolong(long x) throws Throwable {392if (DEBUG) System.out.println("long=" + x);393394// boolean395{396MethodHandle mh1 = getmh1( boolean.class, boolean.class);397MethodHandle mh2 = getmh2(mh1, boolean.class, long.class);398boolean a = (boolean) mh1.invokeExact((x & 1L) == 1L);399boolean b = (boolean) mh2.invokeExact(x);400check(x, a, b);401}402403// byte404{405MethodHandle mh1 = getmh1( byte.class, byte.class);406MethodHandle mh2 = getmh2(mh1, byte.class, long.class);407byte a = (byte) mh1.invokeExact((byte) x);408byte b = (byte) mh2.invokeExact(x);409check(x, a, b);410}411412// char413{414MethodHandle mh1 = getmh1( char.class, char.class);415MethodHandle mh2 = getmh2(mh1, char.class, long.class);416char a = (char) mh1.invokeExact((char) x);417char b = (char) mh2.invokeExact(x);418check(x, a, b);419}420421// short422{423MethodHandle mh1 = getmh1( short.class, short.class);424MethodHandle mh2 = getmh2(mh1, short.class, long.class);425short a = (short) mh1.invokeExact((short) x);426short b = (short) mh2.invokeExact(x);427check(x, a, b);428}429430// int431{432MethodHandle mh1 = getmh1( int.class, int.class);433MethodHandle mh2 = getmh2(mh1, int.class, long.class);434int a = (int) mh1.invokeExact((int) x);435int b = (int) mh2.invokeExact(x);436check(x, a, b);437}438}439440static void check(boolean x, boolean e, boolean a) { p(z2h(x), z2h(e), z2h(a)); assert e == a : z2h(x) + ": " + z2h(e) + " != " + z2h(a); }441static void check(boolean x, byte e, byte a) { p(z2h(x), i2h(e), i2h(a)); assert e == a : z2h(x) + ": " + i2h(e) + " != " + i2h(a); }442static void check(boolean x, int e, int a) { p(z2h(x), i2h(e), i2h(a)); assert e == a : z2h(x) + ": " + i2h(e) + " != " + i2h(a); }443444static void check(int x, boolean e, boolean a) { p(i2h(x), z2h(e), z2h(a)); assert e == a : i2h(x) + ": " + z2h(e) + " != " + z2h(a); }445static void check(int x, byte e, byte a) { p(i2h(x), i2h(e), i2h(a)); assert e == a : i2h(x) + ": " + i2h(e) + " != " + i2h(a); }446static void check(int x, int e, int a) { p(i2h(x), i2h(e), i2h(a)); assert e == a : i2h(x) + ": " + i2h(e) + " != " + i2h(a); }447448static void check(long x, boolean e, boolean a) { p(l2h(x), z2h(e), z2h(a)); assert e == a : l2h(x) + ": " + z2h(e) + " != " + z2h(a); }449static void check(long x, byte e, byte a) { p(l2h(x), i2h(e), i2h(a)); assert e == a : l2h(x) + ": " + i2h(e) + " != " + i2h(a); }450static void check(long x, int e, int a) { p(l2h(x), i2h(e), i2h(a)); assert e == a : l2h(x) + ": " + i2h(e) + " != " + i2h(a); }451452static void p(String x, String e, String a) { if (DEBUG) System.out.println(x + ": expected: " + e + ", actual: " + a); }453454static String z2h(boolean x) { return x ? "1" : "0"; }455static String i2h(int x) { return Integer.toHexString(x); }456static String l2h(long x) { return Long.toHexString(x); }457458// to int459public static boolean foo(boolean i) { return i; }460public static byte foo(byte i) { return i; }461public static char foo(char i) { return i; }462public static short foo(short i) { return i; }463public static int foo(int i) { return i; }464}465466467