test/compiler/6991596/Test6991596.java

changeset 2351
b856cd7f4e60
parent 2256
7aff5786cc02
     1.1 --- a/test/compiler/6991596/Test6991596.java	Fri Dec 03 01:34:31 2010 -0800
     1.2 +++ b/test/compiler/6991596/Test6991596.java	Fri Dec 03 06:14:37 2010 -0800
     1.3 @@ -35,7 +35,7 @@
     1.4  public class Test6991596 {
     1.5      private static final Class   CLASS = Test6991596.class;
     1.6      private static final String  NAME  = "foo";
     1.7 -    private static final boolean DEBUG = false;
     1.8 +    private static final boolean DEBUG = System.getProperty("DEBUG", "false").equals("true");
     1.9  
    1.10      public static void main(String[] args) throws Throwable {
    1.11          testboolean();
    1.12 @@ -47,7 +47,7 @@
    1.13      }
    1.14  
    1.15      // Helpers to get various methods.
    1.16 -    static MethodHandle getmh1(Class ret, Class arg) {
    1.17 +    static MethodHandle getmh1(Class ret, Class arg) throws NoAccessException {
    1.18          return MethodHandles.lookup().findStatic(CLASS, NAME, MethodType.methodType(ret, arg));
    1.19      }
    1.20      static MethodHandle getmh2(MethodHandle mh1, Class ret, Class arg) {
    1.21 @@ -76,38 +76,38 @@
    1.22              MethodHandle mh2 = getmh2(mh1, boolean.class, boolean.class);
    1.23              // TODO add this for all cases when the bugs are fixed.
    1.24              //MethodHandle mh3 = getmh3(mh1, boolean.class, boolean.class);
    1.25 -            boolean a = mh1.<boolean>invokeExact((boolean) x);
    1.26 -            boolean b = mh2.<boolean>invokeExact(x);
    1.27 +            boolean a = (boolean) mh1.invokeExact((boolean) x);
    1.28 +            boolean b = (boolean) mh2.invokeExact(x);
    1.29              //boolean c = mh3.<boolean>invokeExact((boolean) x);
    1.30 -            assert a == b : a + " != " + b;
    1.31 -            //assert c == x : c + " != " + x;
    1.32 +            check(x, a, b);
    1.33 +            //check(x, c, x);
    1.34          }
    1.35  
    1.36          // byte
    1.37          {
    1.38              MethodHandle mh1 = getmh1(     byte.class,    byte.class   );
    1.39              MethodHandle mh2 = getmh2(mh1, byte.class,    boolean.class);
    1.40 -            byte    a = mh1.<byte>invokeExact((byte) (x ? 1 : 0));
    1.41 -            byte    b = mh2.<byte>invokeExact(x);
    1.42 -            assert a == b : a + " != " + b;
    1.43 +            byte a = (byte) mh1.invokeExact((byte) (x ? 1 : 0));
    1.44 +            byte b = (byte) mh2.invokeExact(x);
    1.45 +            check(x, a, b);
    1.46          }
    1.47  
    1.48          // char
    1.49          {
    1.50              MethodHandle mh1 = getmh1(     char.class, char.class);
    1.51              MethodHandle mh2 = getmh2(mh1, char.class, boolean.class);
    1.52 -            char a = mh1.<char>invokeExact((char) (x ? 1 : 0));
    1.53 -            char b = mh2.<char>invokeExact(x);
    1.54 -            assert a == b : a + " != " + b;
    1.55 +            char a = (char) mh1.invokeExact((char) (x ? 1 : 0));
    1.56 +            char b = (char) mh2.invokeExact(x);
    1.57 +            check(x, a, b);
    1.58          }
    1.59  
    1.60          // short
    1.61          {
    1.62              MethodHandle mh1 = getmh1(     short.class, short.class);
    1.63              MethodHandle mh2 = getmh2(mh1, short.class, boolean.class);
    1.64 -            short a = mh1.<short>invokeExact((short) (x ? 1 : 0));
    1.65 -            short b = mh2.<short>invokeExact(x);
    1.66 -            assert a == b : a + " != " + b;
    1.67 +            short a = (short) mh1.invokeExact((short) (x ? 1 : 0));
    1.68 +            short b = (short) mh2.invokeExact(x);
    1.69 +            check(x, a, b);
    1.70          }
    1.71      }
    1.72  
    1.73 @@ -134,36 +134,36 @@
    1.74          {
    1.75              MethodHandle mh1 = getmh1(     boolean.class, boolean.class);
    1.76              MethodHandle mh2 = getmh2(mh1, boolean.class, byte.class);
    1.77 -            boolean a = mh1.<boolean>invokeExact((x & 1) == 1);
    1.78 -            boolean b = mh2.<boolean>invokeExact(x);
    1.79 -            assert a == b : a + " != " + b;
    1.80 +            boolean a = (boolean) mh1.invokeExact((x & 1) == 1);
    1.81 +            boolean b = (boolean) mh2.invokeExact(x);
    1.82 +            check(x, a, b);
    1.83          }
    1.84  
    1.85          // byte
    1.86          {
    1.87              MethodHandle mh1 = getmh1(     byte.class, byte.class);
    1.88              MethodHandle mh2 = getmh2(mh1, byte.class, byte.class);
    1.89 -            byte a = mh1.<byte>invokeExact((byte) x);
    1.90 -            byte b = mh2.<byte>invokeExact(x);
    1.91 -            assert a == b : a + " != " + b;
    1.92 +            byte a = (byte) mh1.invokeExact((byte) x);
    1.93 +            byte b = (byte) mh2.invokeExact(x);
    1.94 +            check(x, a, b);
    1.95          }
    1.96  
    1.97          // char
    1.98          {
    1.99              MethodHandle mh1 = getmh1(     char.class, char.class);
   1.100              MethodHandle mh2 = getmh2(mh1, char.class, byte.class);
   1.101 -            char a = mh1.<char>invokeExact((char) x);
   1.102 -            char b = mh2.<char>invokeExact(x);
   1.103 -            assert a == b : a + " != " + b;
   1.104 +            char a = (char) mh1.invokeExact((char) x);
   1.105 +            char b = (char) mh2.invokeExact(x);
   1.106 +            check(x, a, b);
   1.107          }
   1.108  
   1.109          // short
   1.110          {
   1.111              MethodHandle mh1 = getmh1(     short.class, short.class);
   1.112              MethodHandle mh2 = getmh2(mh1, short.class, byte.class);
   1.113 -            short a = mh1.<short>invokeExact((short) x);
   1.114 -            short b = mh2.<short>invokeExact(x);
   1.115 -            assert a == b : a + " != " + b;
   1.116 +            short a = (short) mh1.invokeExact((short) x);
   1.117 +            short b = (short) mh2.invokeExact(x);
   1.118 +            check(x, a, b);
   1.119          }
   1.120      }
   1.121  
   1.122 @@ -188,36 +188,36 @@
   1.123          {
   1.124              MethodHandle mh1 = getmh1(     boolean.class, boolean.class);
   1.125              MethodHandle mh2 = getmh2(mh1, boolean.class, char.class);
   1.126 -            boolean a = mh1.<boolean>invokeExact((x & 1) == 1);
   1.127 -            boolean b = mh2.<boolean>invokeExact(x);
   1.128 -            assert a == b : a + " != " + b;
   1.129 +            boolean a = (boolean) mh1.invokeExact((x & 1) == 1);
   1.130 +            boolean b = (boolean) mh2.invokeExact(x);
   1.131 +            check(x, a, b);
   1.132          }
   1.133  
   1.134          // byte
   1.135          {
   1.136              MethodHandle mh1 = getmh1(     byte.class, byte.class);
   1.137              MethodHandle mh2 = getmh2(mh1, byte.class, char.class);
   1.138 -            byte a = mh1.<byte>invokeExact((byte) x);
   1.139 -            byte b = mh2.<byte>invokeExact(x);
   1.140 -            assert a == b : a + " != " + b;
   1.141 +            byte a = (byte) mh1.invokeExact((byte) x);
   1.142 +            byte b = (byte) mh2.invokeExact(x);
   1.143 +            check(x, a, b);
   1.144          }
   1.145  
   1.146          // char
   1.147          {
   1.148              MethodHandle mh1 = getmh1(     char.class, char.class);
   1.149              MethodHandle mh2 = getmh2(mh1, char.class, char.class);
   1.150 -            char a = mh1.<char>invokeExact((char) x);
   1.151 -            char b = mh2.<char>invokeExact(x);
   1.152 -            assert a == b : a + " != " + b;
   1.153 +            char a = (char) mh1.invokeExact((char) x);
   1.154 +            char b = (char) mh2.invokeExact(x);
   1.155 +            check(x, a, b);
   1.156          }
   1.157  
   1.158          // short
   1.159          {
   1.160              MethodHandle mh1 = getmh1(     short.class, short.class);
   1.161              MethodHandle mh2 = getmh2(mh1, short.class, char.class);
   1.162 -            short a = mh1.<short>invokeExact((short) x);
   1.163 -            short b = mh2.<short>invokeExact(x);
   1.164 -            assert a == b : a + " != " + b;
   1.165 +            short a = (short) mh1.invokeExact((short) x);
   1.166 +            short b = (short) mh2.invokeExact(x);
   1.167 +            check(x, a, b);
   1.168          }
   1.169      }
   1.170  
   1.171 @@ -248,36 +248,36 @@
   1.172          {
   1.173              MethodHandle mh1 = getmh1(     boolean.class, boolean.class);
   1.174              MethodHandle mh2 = getmh2(mh1, boolean.class, short.class);
   1.175 -            boolean a = mh1.<boolean>invokeExact((x & 1) == 1);
   1.176 -            boolean b = mh2.<boolean>invokeExact(x);
   1.177 -            assert a == b : a + " != " + b;
   1.178 +            boolean a = (boolean) mh1.invokeExact((x & 1) == 1);
   1.179 +            boolean b = (boolean) mh2.invokeExact(x);
   1.180 +            check(x, a, b);
   1.181          }
   1.182  
   1.183          // byte
   1.184          {
   1.185              MethodHandle mh1 = getmh1(     byte.class, byte.class);
   1.186              MethodHandle mh2 = getmh2(mh1, byte.class, short.class);
   1.187 -            byte a = mh1.<byte>invokeExact((byte) x);
   1.188 -            byte b = mh2.<byte>invokeExact(x);
   1.189 -            assert a == b : a + " != " + b;
   1.190 +            byte a = (byte) mh1.invokeExact((byte) x);
   1.191 +            byte b = (byte) mh2.invokeExact(x);
   1.192 +            check(x, a, b);
   1.193          }
   1.194  
   1.195          // char
   1.196          {
   1.197              MethodHandle mh1 = getmh1(     char.class, char.class);
   1.198              MethodHandle mh2 = getmh2(mh1, char.class, short.class);
   1.199 -            char a = mh1.<char>invokeExact((char) x);
   1.200 -            char b = mh2.<char>invokeExact(x);
   1.201 -            assert a == b : a + " != " + b;
   1.202 +            char a = (char) mh1.invokeExact((char) x);
   1.203 +            char b = (char) mh2.invokeExact(x);
   1.204 +            check(x, a, b);
   1.205          }
   1.206  
   1.207          // short
   1.208          {
   1.209              MethodHandle mh1 = getmh1(     short.class, short.class);
   1.210              MethodHandle mh2 = getmh2(mh1, short.class, short.class);
   1.211 -            short a = mh1.<short>invokeExact((short) x);
   1.212 -            short b = mh2.<short>invokeExact(x);
   1.213 -            assert a == b : a + " != " + b;
   1.214 +            short a = (short) mh1.invokeExact((short) x);
   1.215 +            short b = (short) mh2.invokeExact(x);
   1.216 +            check(x, a, b);
   1.217          }
   1.218      }
   1.219  
   1.220 @@ -316,45 +316,46 @@
   1.221          {
   1.222              MethodHandle mh1 = getmh1(     boolean.class, boolean.class);
   1.223              MethodHandle mh2 = getmh2(mh1, boolean.class, int.class);
   1.224 -            boolean a = mh1.<boolean>invokeExact((x & 1) == 1);
   1.225 -            boolean b = mh2.<boolean>invokeExact(x);
   1.226 -            assert a == b : a + " != " + b;
   1.227 +            boolean a = (boolean) mh1.invokeExact((x & 1) == 1);
   1.228 +            boolean b = (boolean) mh2.invokeExact(x);
   1.229 +            check(x, a, b);
   1.230          }
   1.231  
   1.232          // byte
   1.233          {
   1.234              MethodHandle mh1 = getmh1(     byte.class, byte.class);
   1.235              MethodHandle mh2 = getmh2(mh1, byte.class, int.class);
   1.236 -            byte a = mh1.<byte>invokeExact((byte) x);
   1.237 -            byte b = mh2.<byte>invokeExact(x);
   1.238 -            assert a == b : a + " != " + b;
   1.239 +            byte a = (byte) mh1.invokeExact((byte) x);
   1.240 +            byte b = (byte) mh2.invokeExact(x);
   1.241 +            check(x, a, b);
   1.242          }
   1.243  
   1.244          // char
   1.245          {
   1.246              MethodHandle mh1 = getmh1(     char.class, char.class);
   1.247              MethodHandle mh2 = getmh2(mh1, char.class, int.class);
   1.248 -            char a = mh1.<char>invokeExact((char) x);
   1.249 -            char b = mh2.<char>invokeExact(x);
   1.250 -            assert a == b : a + " != " + b;
   1.251 +            char a = (char) mh1.invokeExact((char) x);
   1.252 +            char b = (char) mh2.invokeExact(x);
   1.253 +            check(x, a, b);
   1.254          }
   1.255  
   1.256          // short
   1.257          {
   1.258              MethodHandle mh1 = getmh1(     short.class, short.class);
   1.259              MethodHandle mh2 = getmh2(mh1, short.class, int.class);
   1.260 -            short a = mh1.<short>invokeExact((short) x);
   1.261 -            short b = mh2.<short>invokeExact(x);
   1.262 +            short a = (short) mh1.invokeExact((short) x);
   1.263 +            short b = (short) mh2.invokeExact(x);
   1.264              assert a == b : a + " != " + b;
   1.265 +            check(x, a, b);
   1.266          }
   1.267  
   1.268          // int
   1.269          {
   1.270              MethodHandle mh1 = getmh1(     int.class, int.class);
   1.271              MethodHandle mh2 = getmh2(mh1, int.class, int.class);
   1.272 -            int a = mh1.<int>invokeExact((int) x);
   1.273 -            int b = mh2.<int>invokeExact(x);
   1.274 -            assert a == b : a + " != " + b;
   1.275 +            int a = (int) mh1.invokeExact((int) x);
   1.276 +            int b = (int) mh2.invokeExact(x);
   1.277 +            check(x, a, b);
   1.278          }
   1.279      }
   1.280  
   1.281 @@ -395,48 +396,65 @@
   1.282          {
   1.283              MethodHandle mh1 = getmh1(     boolean.class, boolean.class);
   1.284              MethodHandle mh2 = getmh2(mh1, boolean.class, long.class);
   1.285 -            boolean a = mh1.<boolean>invokeExact((x & 1L) == 1L);
   1.286 -            boolean b = mh2.<boolean>invokeExact(x);
   1.287 -            assert a == b : a + " != " + b;
   1.288 +            boolean a = (boolean) mh1.invokeExact((x & 1L) == 1L);
   1.289 +            boolean b = (boolean) mh2.invokeExact(x);
   1.290 +            check(x, a, b);
   1.291          }
   1.292  
   1.293          // byte
   1.294          {
   1.295              MethodHandle mh1 = getmh1(     byte.class, byte.class);
   1.296              MethodHandle mh2 = getmh2(mh1, byte.class, long.class);
   1.297 -            byte a = mh1.<byte>invokeExact((byte) x);
   1.298 -            byte b = mh2.<byte>invokeExact(x);
   1.299 -            assert a == b : a + " != " + b;
   1.300 +            byte a = (byte) mh1.invokeExact((byte) x);
   1.301 +            byte b = (byte) mh2.invokeExact(x);
   1.302 +            check(x, a, b);
   1.303          }
   1.304  
   1.305          // char
   1.306          {
   1.307              MethodHandle mh1 = getmh1(     char.class, char.class);
   1.308              MethodHandle mh2 = getmh2(mh1, char.class, long.class);
   1.309 -            char a = mh1.<char>invokeExact((char) x);
   1.310 -            char b = mh2.<char>invokeExact(x);
   1.311 -            assert a == b : a + " != " + b;
   1.312 +            char a = (char) mh1.invokeExact((char) x);
   1.313 +            char b = (char) mh2.invokeExact(x);
   1.314 +            check(x, a, b);
   1.315          }
   1.316  
   1.317          // short
   1.318          {
   1.319              MethodHandle mh1 = getmh1(     short.class, short.class);
   1.320              MethodHandle mh2 = getmh2(mh1, short.class, long.class);
   1.321 -            short a = mh1.<short>invokeExact((short) x);
   1.322 -            short b = mh2.<short>invokeExact(x);
   1.323 -            assert a == b : a + " != " + b;
   1.324 +            short a = (short) mh1.invokeExact((short) x);
   1.325 +            short b = (short) mh2.invokeExact(x);
   1.326 +            check(x, a, b);
   1.327          }
   1.328  
   1.329          // int
   1.330          {
   1.331              MethodHandle mh1 = getmh1(     int.class, int.class);
   1.332              MethodHandle mh2 = getmh2(mh1, int.class, long.class);
   1.333 -            int a = mh1.<int>invokeExact((int) x);
   1.334 -            int b = mh2.<int>invokeExact(x);
   1.335 -            assert a == b : a + " != " + b;
   1.336 +            int a = (int) mh1.invokeExact((int) x);
   1.337 +            int b = (int) mh2.invokeExact(x);
   1.338 +            check(x, a, b);
   1.339          }
   1.340 +    }
   1.341  
   1.342 -    }
   1.343 +    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.344 +    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.345 +    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.346 +
   1.347 +    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.348 +    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.349 +    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.350 +
   1.351 +    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.352 +    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.353 +    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.354 +
   1.355 +    static void p(String x, String e, String a) { if (DEBUG)  System.out.println(x + ": expected: " + e + ", actual: " + a); }
   1.356 +
   1.357 +    static String z2h(boolean x) { return x ? "1" : "0"; }
   1.358 +    static String i2h(int     x) { return Integer.toHexString(x); }
   1.359 +    static String l2h(long    x) { return Long.toHexString(x); }
   1.360  
   1.361      // to int
   1.362      public static boolean foo(boolean i) { return i; }

mercurial