test/compiler/6991596/Test6991596.java

changeset 2678
b868d9928221
parent 2677
151da0c145a8
parent 2666
0a5d9566b8a4
child 2679
f731b22cd52d
child 2680
322a41ec766c
     1.1 --- a/test/compiler/6991596/Test6991596.java	Thu Mar 24 02:11:50 2011 -0700
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,465 +0,0 @@
     1.4 -/*
     1.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 - *
     1.8 - * This code is free software; you can redistribute it and/or modify it
     1.9 - * under the terms of the GNU General Public License version 2 only, as
    1.10 - * published by the Free Software Foundation.
    1.11 - *
    1.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 - * version 2 for more details (a copy is included in the LICENSE file that
    1.16 - * accompanied this code).
    1.17 - *
    1.18 - * You should have received a copy of the GNU General Public License version
    1.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 - *
    1.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 - * or visit www.oracle.com if you need additional information or have any
    1.24 - * questions.
    1.25 - *
    1.26 - */
    1.27 -
    1.28 -/**
    1.29 - * @test
    1.30 - * @bug 6991596
    1.31 - * @summary JSR 292 unimplemented adapter_opt_i2i and adapter_opt_l2i on SPARC
    1.32 - *
    1.33 - * @run main/othervm -ea -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles -XX:+EnableInvokeDynamic -XX:+UnlockDiagnosticVMOptions -XX:+VerifyMethodHandles Test6991596
    1.34 - */
    1.35 -
    1.36 -import java.dyn.*;
    1.37 -
    1.38 -public class Test6991596 {
    1.39 -    private static final Class   CLASS = Test6991596.class;
    1.40 -    private static final String  NAME  = "foo";
    1.41 -    private static final boolean DEBUG = System.getProperty("DEBUG", "false").equals("true");
    1.42 -
    1.43 -    public static void main(String[] args) throws Throwable {
    1.44 -        testboolean();
    1.45 -        testbyte();
    1.46 -        testchar();
    1.47 -        testshort();
    1.48 -        testint();
    1.49 -        testlong();
    1.50 -    }
    1.51 -
    1.52 -    // Helpers to get various methods.
    1.53 -    static MethodHandle getmh1(Class ret, Class arg) throws NoAccessException {
    1.54 -        return MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(ret, arg));
    1.55 -    }
    1.56 -    static MethodHandle getmh2(MethodHandle mh1, Class ret, Class arg) {
    1.57 -        return MethodHandles.convertArguments(mh1, MethodType.methodType(ret, arg));
    1.58 -    }
    1.59 -    static MethodHandle getmh3(MethodHandle mh1, Class ret, Class arg) {
    1.60 -        return MethodHandles.convertArguments(mh1, MethodType.methodType(ret, arg));
    1.61 -    }
    1.62 -
    1.63 -    // test adapter_opt_i2i
    1.64 -    static void testboolean() throws Throwable {
    1.65 -        boolean[] a = new boolean[] {
    1.66 -            true,
    1.67 -            false
    1.68 -        };
    1.69 -        for (int i = 0; i < a.length; i++) {
    1.70 -            doboolean(a[i]);
    1.71 -        }
    1.72 -    }
    1.73 -    static void doboolean(boolean x) throws Throwable {
    1.74 -        if (DEBUG)  System.out.println("boolean=" + x);
    1.75 -
    1.76 -        // boolean
    1.77 -        {
    1.78 -            MethodHandle mh1 = getmh1(     boolean.class, boolean.class);
    1.79 -            MethodHandle mh2 = getmh2(mh1, boolean.class, boolean.class);
    1.80 -            // TODO add this for all cases when the bugs are fixed.
    1.81 -            //MethodHandle mh3 = getmh3(mh1, boolean.class, boolean.class);
    1.82 -            boolean a = (boolean) mh1.invokeExact((boolean) x);
    1.83 -            boolean b = (boolean) mh2.invokeExact(x);
    1.84 -            //boolean c = mh3.<boolean>invokeExact((boolean) x);
    1.85 -            check(x, a, b);
    1.86 -            //check(x, c, x);
    1.87 -        }
    1.88 -
    1.89 -        // byte
    1.90 -        {
    1.91 -            MethodHandle mh1 = getmh1(     byte.class,    byte.class   );
    1.92 -            MethodHandle mh2 = getmh2(mh1, byte.class,    boolean.class);
    1.93 -            byte a = (byte) mh1.invokeExact((byte) (x ? 1 : 0));
    1.94 -            byte b = (byte) mh2.invokeExact(x);
    1.95 -            check(x, a, b);
    1.96 -        }
    1.97 -
    1.98 -        // char
    1.99 -        {
   1.100 -            MethodHandle mh1 = getmh1(     char.class, char.class);
   1.101 -            MethodHandle mh2 = getmh2(mh1, char.class, boolean.class);
   1.102 -            char a = (char) mh1.invokeExact((char) (x ? 1 : 0));
   1.103 -            char b = (char) mh2.invokeExact(x);
   1.104 -            check(x, a, b);
   1.105 -        }
   1.106 -
   1.107 -        // short
   1.108 -        {
   1.109 -            MethodHandle mh1 = getmh1(     short.class, short.class);
   1.110 -            MethodHandle mh2 = getmh2(mh1, short.class, boolean.class);
   1.111 -            short a = (short) mh1.invokeExact((short) (x ? 1 : 0));
   1.112 -            short b = (short) mh2.invokeExact(x);
   1.113 -            check(x, a, b);
   1.114 -        }
   1.115 -    }
   1.116 -
   1.117 -    static void testbyte() throws Throwable {
   1.118 -        byte[] a = new byte[] {
   1.119 -            Byte.MIN_VALUE,
   1.120 -            Byte.MIN_VALUE + 1,
   1.121 -            -0x0F,
   1.122 -            -1,
   1.123 -            0,
   1.124 -            1,
   1.125 -            0x0F,
   1.126 -            Byte.MAX_VALUE - 1,
   1.127 -            Byte.MAX_VALUE
   1.128 -        };
   1.129 -        for (int i = 0; i < a.length; i++) {
   1.130 -            dobyte(a[i]);
   1.131 -        }
   1.132 -    }
   1.133 -    static void dobyte(byte x) throws Throwable {
   1.134 -        if (DEBUG)  System.out.println("byte=" + x);
   1.135 -
   1.136 -        // boolean
   1.137 -        {
   1.138 -            MethodHandle mh1 = getmh1(     boolean.class, boolean.class);
   1.139 -            MethodHandle mh2 = getmh2(mh1, boolean.class, byte.class);
   1.140 -            boolean a = (boolean) mh1.invokeExact((x & 1) == 1);
   1.141 -            boolean b = (boolean) mh2.invokeExact(x);
   1.142 -            check(x, a, b);
   1.143 -        }
   1.144 -
   1.145 -        // byte
   1.146 -        {
   1.147 -            MethodHandle mh1 = getmh1(     byte.class, byte.class);
   1.148 -            MethodHandle mh2 = getmh2(mh1, byte.class, byte.class);
   1.149 -            byte a = (byte) mh1.invokeExact((byte) x);
   1.150 -            byte b = (byte) mh2.invokeExact(x);
   1.151 -            check(x, a, b);
   1.152 -        }
   1.153 -
   1.154 -        // char
   1.155 -        {
   1.156 -            MethodHandle mh1 = getmh1(     char.class, char.class);
   1.157 -            MethodHandle mh2 = getmh2(mh1, char.class, byte.class);
   1.158 -            char a = (char) mh1.invokeExact((char) x);
   1.159 -            char b = (char) mh2.invokeExact(x);
   1.160 -            check(x, a, b);
   1.161 -        }
   1.162 -
   1.163 -        // short
   1.164 -        {
   1.165 -            MethodHandle mh1 = getmh1(     short.class, short.class);
   1.166 -            MethodHandle mh2 = getmh2(mh1, short.class, byte.class);
   1.167 -            short a = (short) mh1.invokeExact((short) x);
   1.168 -            short b = (short) mh2.invokeExact(x);
   1.169 -            check(x, a, b);
   1.170 -        }
   1.171 -    }
   1.172 -
   1.173 -    static void testchar() throws Throwable {
   1.174 -        char[] a = new char[] {
   1.175 -            Character.MIN_VALUE,
   1.176 -            Character.MIN_VALUE + 1,
   1.177 -            0x000F,
   1.178 -            0x00FF,
   1.179 -            0x0FFF,
   1.180 -            Character.MAX_VALUE - 1,
   1.181 -            Character.MAX_VALUE
   1.182 -        };
   1.183 -        for (int i = 0; i < a.length; i++) {
   1.184 -            dochar(a[i]);
   1.185 -        }
   1.186 -    }
   1.187 -    static void dochar(char x) throws Throwable {
   1.188 -        if (DEBUG)  System.out.println("char=" + x);
   1.189 -
   1.190 -        // boolean
   1.191 -        {
   1.192 -            MethodHandle mh1 = getmh1(     boolean.class, boolean.class);
   1.193 -            MethodHandle mh2 = getmh2(mh1, boolean.class, char.class);
   1.194 -            boolean a = (boolean) mh1.invokeExact((x & 1) == 1);
   1.195 -            boolean b = (boolean) mh2.invokeExact(x);
   1.196 -            check(x, a, b);
   1.197 -        }
   1.198 -
   1.199 -        // byte
   1.200 -        {
   1.201 -            MethodHandle mh1 = getmh1(     byte.class, byte.class);
   1.202 -            MethodHandle mh2 = getmh2(mh1, byte.class, char.class);
   1.203 -            byte a = (byte) mh1.invokeExact((byte) x);
   1.204 -            byte b = (byte) mh2.invokeExact(x);
   1.205 -            check(x, a, b);
   1.206 -        }
   1.207 -
   1.208 -        // char
   1.209 -        {
   1.210 -            MethodHandle mh1 = getmh1(     char.class, char.class);
   1.211 -            MethodHandle mh2 = getmh2(mh1, char.class, char.class);
   1.212 -            char a = (char) mh1.invokeExact((char) x);
   1.213 -            char b = (char) mh2.invokeExact(x);
   1.214 -            check(x, a, b);
   1.215 -        }
   1.216 -
   1.217 -        // short
   1.218 -        {
   1.219 -            MethodHandle mh1 = getmh1(     short.class, short.class);
   1.220 -            MethodHandle mh2 = getmh2(mh1, short.class, char.class);
   1.221 -            short a = (short) mh1.invokeExact((short) x);
   1.222 -            short b = (short) mh2.invokeExact(x);
   1.223 -            check(x, a, b);
   1.224 -        }
   1.225 -    }
   1.226 -
   1.227 -    static void testshort() throws Throwable {
   1.228 -        short[] a = new short[] {
   1.229 -            Short.MIN_VALUE,
   1.230 -            Short.MIN_VALUE + 1,
   1.231 -            -0x0FFF,
   1.232 -            -0x00FF,
   1.233 -            -0x000F,
   1.234 -            -1,
   1.235 -            0,
   1.236 -            1,
   1.237 -            0x000F,
   1.238 -            0x00FF,
   1.239 -            0x0FFF,
   1.240 -            Short.MAX_VALUE - 1,
   1.241 -            Short.MAX_VALUE
   1.242 -        };
   1.243 -        for (int i = 0; i < a.length; i++) {
   1.244 -            doshort(a[i]);
   1.245 -        }
   1.246 -    }
   1.247 -    static void doshort(short x) throws Throwable {
   1.248 -        if (DEBUG)  System.out.println("short=" + x);
   1.249 -
   1.250 -        // boolean
   1.251 -        {
   1.252 -            MethodHandle mh1 = getmh1(     boolean.class, boolean.class);
   1.253 -            MethodHandle mh2 = getmh2(mh1, boolean.class, short.class);
   1.254 -            boolean a = (boolean) mh1.invokeExact((x & 1) == 1);
   1.255 -            boolean b = (boolean) mh2.invokeExact(x);
   1.256 -            check(x, a, b);
   1.257 -        }
   1.258 -
   1.259 -        // byte
   1.260 -        {
   1.261 -            MethodHandle mh1 = getmh1(     byte.class, byte.class);
   1.262 -            MethodHandle mh2 = getmh2(mh1, byte.class, short.class);
   1.263 -            byte a = (byte) mh1.invokeExact((byte) x);
   1.264 -            byte b = (byte) mh2.invokeExact(x);
   1.265 -            check(x, a, b);
   1.266 -        }
   1.267 -
   1.268 -        // char
   1.269 -        {
   1.270 -            MethodHandle mh1 = getmh1(     char.class, char.class);
   1.271 -            MethodHandle mh2 = getmh2(mh1, char.class, short.class);
   1.272 -            char a = (char) mh1.invokeExact((char) x);
   1.273 -            char b = (char) mh2.invokeExact(x);
   1.274 -            check(x, a, b);
   1.275 -        }
   1.276 -
   1.277 -        // short
   1.278 -        {
   1.279 -            MethodHandle mh1 = getmh1(     short.class, short.class);
   1.280 -            MethodHandle mh2 = getmh2(mh1, short.class, short.class);
   1.281 -            short a = (short) mh1.invokeExact((short) x);
   1.282 -            short b = (short) mh2.invokeExact(x);
   1.283 -            check(x, a, b);
   1.284 -        }
   1.285 -    }
   1.286 -
   1.287 -    static void testint() throws Throwable {
   1.288 -        int[] a = new int[] {
   1.289 -            Integer.MIN_VALUE,
   1.290 -            Integer.MIN_VALUE + 1,
   1.291 -            -0x0FFFFFFF,
   1.292 -            -0x00FFFFFF,
   1.293 -            -0x000FFFFF,
   1.294 -            -0x0000FFFF,
   1.295 -            -0x00000FFF,
   1.296 -            -0x000000FF,
   1.297 -            -0x0000000F,
   1.298 -            -1,
   1.299 -            0,
   1.300 -            1,
   1.301 -            0x0000000F,
   1.302 -            0x000000FF,
   1.303 -            0x00000FFF,
   1.304 -            0x0000FFFF,
   1.305 -            0x000FFFFF,
   1.306 -            0x00FFFFFF,
   1.307 -            0x0FFFFFFF,
   1.308 -            Integer.MAX_VALUE - 1,
   1.309 -            Integer.MAX_VALUE
   1.310 -        };
   1.311 -        for (int i = 0; i < a.length; i++) {
   1.312 -            doint(a[i]);
   1.313 -        }
   1.314 -    }
   1.315 -    static void doint(int x) throws Throwable {
   1.316 -        if (DEBUG)  System.out.println("int=" + x);
   1.317 -
   1.318 -        // boolean
   1.319 -        {
   1.320 -            MethodHandle mh1 = getmh1(     boolean.class, boolean.class);
   1.321 -            MethodHandle mh2 = getmh2(mh1, boolean.class, int.class);
   1.322 -            boolean a = (boolean) mh1.invokeExact((x & 1) == 1);
   1.323 -            boolean b = (boolean) mh2.invokeExact(x);
   1.324 -            check(x, a, b);
   1.325 -        }
   1.326 -
   1.327 -        // byte
   1.328 -        {
   1.329 -            MethodHandle mh1 = getmh1(     byte.class, byte.class);
   1.330 -            MethodHandle mh2 = getmh2(mh1, byte.class, int.class);
   1.331 -            byte a = (byte) mh1.invokeExact((byte) x);
   1.332 -            byte b = (byte) mh2.invokeExact(x);
   1.333 -            check(x, a, b);
   1.334 -        }
   1.335 -
   1.336 -        // char
   1.337 -        {
   1.338 -            MethodHandle mh1 = getmh1(     char.class, char.class);
   1.339 -            MethodHandle mh2 = getmh2(mh1, char.class, int.class);
   1.340 -            char a = (char) mh1.invokeExact((char) x);
   1.341 -            char b = (char) mh2.invokeExact(x);
   1.342 -            check(x, a, b);
   1.343 -        }
   1.344 -
   1.345 -        // short
   1.346 -        {
   1.347 -            MethodHandle mh1 = getmh1(     short.class, short.class);
   1.348 -            MethodHandle mh2 = getmh2(mh1, short.class, int.class);
   1.349 -            short a = (short) mh1.invokeExact((short) x);
   1.350 -            short b = (short) mh2.invokeExact(x);
   1.351 -            assert a == b : a + " != " + b;
   1.352 -            check(x, a, b);
   1.353 -        }
   1.354 -
   1.355 -        // int
   1.356 -        {
   1.357 -            MethodHandle mh1 = getmh1(     int.class, int.class);
   1.358 -            MethodHandle mh2 = getmh2(mh1, int.class, int.class);
   1.359 -            int a = (int) mh1.invokeExact((int) x);
   1.360 -            int b = (int) mh2.invokeExact(x);
   1.361 -            check(x, a, b);
   1.362 -        }
   1.363 -    }
   1.364 -
   1.365 -    // test adapter_opt_l2i
   1.366 -    static void testlong() throws Throwable {
   1.367 -        long[] a = new long[] {
   1.368 -            Long.MIN_VALUE,
   1.369 -            Long.MIN_VALUE + 1,
   1.370 -            -0x000000000FFFFFFFL,
   1.371 -            -0x0000000000FFFFFFL,
   1.372 -            -0x00000000000FFFFFL,
   1.373 -            -0x000000000000FFFFL,
   1.374 -            -0x0000000000000FFFL,
   1.375 -            -0x00000000000000FFL,
   1.376 -            -0x000000000000000FL,
   1.377 -            -1L,
   1.378 -            0L,
   1.379 -            1L,
   1.380 -            0x000000000000000FL,
   1.381 -            0x00000000000000FFL,
   1.382 -            0x0000000000000FFFL,
   1.383 -            0x0000000000000FFFL,
   1.384 -            0x000000000000FFFFL,
   1.385 -            0x00000000000FFFFFL,
   1.386 -            0x0000000000FFFFFFL,
   1.387 -            0x000000000FFFFFFFL,
   1.388 -            Long.MAX_VALUE - 1,
   1.389 -            Long.MAX_VALUE
   1.390 -        };
   1.391 -        for (int i = 0; i < a.length; i++) {
   1.392 -            dolong(a[i]);
   1.393 -        }
   1.394 -    }
   1.395 -    static void dolong(long x) throws Throwable {
   1.396 -        if (DEBUG)  System.out.println("long=" + x);
   1.397 -
   1.398 -        // boolean
   1.399 -        {
   1.400 -            MethodHandle mh1 = getmh1(     boolean.class, boolean.class);
   1.401 -            MethodHandle mh2 = getmh2(mh1, boolean.class, long.class);
   1.402 -            boolean a = (boolean) mh1.invokeExact((x & 1L) == 1L);
   1.403 -            boolean b = (boolean) mh2.invokeExact(x);
   1.404 -            check(x, a, b);
   1.405 -        }
   1.406 -
   1.407 -        // byte
   1.408 -        {
   1.409 -            MethodHandle mh1 = getmh1(     byte.class, byte.class);
   1.410 -            MethodHandle mh2 = getmh2(mh1, byte.class, long.class);
   1.411 -            byte a = (byte) mh1.invokeExact((byte) x);
   1.412 -            byte b = (byte) mh2.invokeExact(x);
   1.413 -            check(x, a, b);
   1.414 -        }
   1.415 -
   1.416 -        // char
   1.417 -        {
   1.418 -            MethodHandle mh1 = getmh1(     char.class, char.class);
   1.419 -            MethodHandle mh2 = getmh2(mh1, char.class, long.class);
   1.420 -            char a = (char) mh1.invokeExact((char) x);
   1.421 -            char b = (char) mh2.invokeExact(x);
   1.422 -            check(x, a, b);
   1.423 -        }
   1.424 -
   1.425 -        // short
   1.426 -        {
   1.427 -            MethodHandle mh1 = getmh1(     short.class, short.class);
   1.428 -            MethodHandle mh2 = getmh2(mh1, short.class, long.class);
   1.429 -            short a = (short) mh1.invokeExact((short) x);
   1.430 -            short b = (short) mh2.invokeExact(x);
   1.431 -            check(x, a, b);
   1.432 -        }
   1.433 -
   1.434 -        // int
   1.435 -        {
   1.436 -            MethodHandle mh1 = getmh1(     int.class, int.class);
   1.437 -            MethodHandle mh2 = getmh2(mh1, int.class, long.class);
   1.438 -            int a = (int) mh1.invokeExact((int) x);
   1.439 -            int b = (int) mh2.invokeExact(x);
   1.440 -            check(x, a, b);
   1.441 -        }
   1.442 -    }
   1.443 -
   1.444 -    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); }
   1.445 -    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); }
   1.446 -    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); }
   1.447 -
   1.448 -    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); }
   1.449 -    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); }
   1.450 -    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); }
   1.451 -
   1.452 -    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); }
   1.453 -    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); }
   1.454 -    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); }
   1.455 -
   1.456 -    static void p(String x, String e, String a) { if (DEBUG)  System.out.println(x + ": expected: " + e + ", actual: " + a); }
   1.457 -
   1.458 -    static String z2h(boolean x) { return x ? "1" : "0"; }
   1.459 -    static String i2h(int     x) { return Integer.toHexString(x); }
   1.460 -    static String l2h(long    x) { return Long.toHexString(x); }
   1.461 -
   1.462 -    // to int
   1.463 -    public static boolean foo(boolean i) { return i; }
   1.464 -    public static byte    foo(byte    i) { return i; }
   1.465 -    public static char    foo(char    i) { return i; }
   1.466 -    public static short   foo(short   i) { return i; }
   1.467 -    public static int     foo(int     i) { return i; }
   1.468 -}

mercurial