jdk/test/java/lang/invoke/PermuteArgsTest.java
changeset 11534 9949ffb8eb3a
parent 9859 47e26ad535c4
child 13610 28122b96858e
equal deleted inserted replaced
11353:75bcd5e48fab 11534:9949ffb8eb3a
    43 import java.lang.invoke.*;
    43 import java.lang.invoke.*;
    44 import static java.lang.invoke.MethodHandles.*;
    44 import static java.lang.invoke.MethodHandles.*;
    45 import static java.lang.invoke.MethodType.*;
    45 import static java.lang.invoke.MethodType.*;
    46 
    46 
    47 public class PermuteArgsTest {
    47 public class PermuteArgsTest {
    48     private static final Class CLASS = PermuteArgsTest.class;
    48     private static final Class<?> CLASS = PermuteArgsTest.class;
    49     private static final int MAX_ARITY = Integer.getInteger(CLASS.getSimpleName()+".MAX_ARITY", 8);
    49     private static final int MAX_ARITY = Integer.getInteger(CLASS.getSimpleName()+".MAX_ARITY", 8);
    50     private static final boolean DRY_RUN = Boolean.getBoolean(CLASS.getSimpleName()+".DRY_RUN");
    50     private static final boolean DRY_RUN = Boolean.getBoolean(CLASS.getSimpleName()+".DRY_RUN");
    51     private static final boolean VERBOSE = Boolean.getBoolean(CLASS.getSimpleName()+".VERBOSE") || DRY_RUN;
    51     private static final boolean VERBOSE = Boolean.getBoolean(CLASS.getSimpleName()+".VERBOSE") || DRY_RUN;
    52 
    52 
    53     static Object list2I(int x, int y) {
    53     static Object list2I(int x, int y) {
    97     }
    97     }
    98     static Object listLJJL(Object w, long x, long y, Object z) {
    98     static Object listLJJL(Object w, long x, long y, Object z) {
    99         return Arrays.asList(w, x, y, z);
    99         return Arrays.asList(w, x, y, z);
   100     }
   100     }
   101     static Object listI_etc(int... va) {
   101     static Object listI_etc(int... va) {
   102         ArrayList<Object> res = new ArrayList<Object>();
   102         ArrayList<Object> res = new ArrayList<>();
   103         for (int x : va)  res.add(x);
   103         for (int x : va)  res.add(x);
   104         return res;
   104         return res;
   105     }
   105     }
   106     static Object listIJL_etc(int x, long y, Object z, Object... va) {
   106     static Object listIJL_etc(int x, long y, Object z, Object... va) {
   107         ArrayList<Object> res = new ArrayList<Object>();
   107         ArrayList<Object> res = new ArrayList<>();
   108         res.addAll(Arrays.asList(x, y, z));
   108         res.addAll(Arrays.asList(x, y, z));
   109         res.addAll(Arrays.asList(va));
   109         res.addAll(Arrays.asList(va));
   110         return res;
   110         return res;
   111     }
   111     }
   112 
   112 
   166                 MethodHandle mh1;
   166                 MethodHandle mh1;
   167                 try {
   167                 try {
   168                     mh1 = adjustArity(mh, arity);
   168                     mh1 = adjustArity(mh, arity);
   169                 } catch (IllegalArgumentException ex) {
   169                 } catch (IllegalArgumentException ex) {
   170                     System.out.println("*** mh = "+name+" : "+mh+"; arity = "+arity+" => "+ex);
   170                     System.out.println("*** mh = "+name+" : "+mh+"; arity = "+arity+" => "+ex);
   171                     ex.printStackTrace();
   171                     ex.printStackTrace(System.out);
   172                     break;  // cannot get this arity for this type
   172                     break;  // cannot get this arity for this type
   173                 }
   173                 }
   174                 test("("+arity+")"+name, mh1);
   174                 test("("+arity+")"+name, mh1);
   175                 arity = jump(arity, arity0*2, MAX_ARITY);
   175                 arity = jump(arity, arity0*2, MAX_ARITY);
   176             }
   176             }
   211         }
   211         }
   212         throw new RuntimeException("no such method for arity "+arity+": "+name);
   212         throw new RuntimeException("no such method for arity "+arity+": "+name);
   213     }
   213     }
   214 
   214 
   215     static void testPermutations(MethodHandle mh) throws Throwable {
   215     static void testPermutations(MethodHandle mh) throws Throwable {
   216         HashSet<String> done = new HashSet<String>();
   216         HashSet<String> done = new HashSet<>();
   217         MethodType mt = mh.type();
   217         MethodType mt = mh.type();
   218         int[] perm = nullPerm(mt.parameterCount());
   218         int[] perm = nullPerm(mt.parameterCount());
   219         final int MARGIN = (perm.length <= 10 ? 2 : 0);
   219         final int MARGIN = (perm.length <= 10 ? 2 : 0);
   220         int testCases0 = testCases;
   220         int testCases0 = testCases;
   221         for (int j = 0; j <= 1; j++) {
   221         for (int j = 0; j <= 1; j++) {
   324         Object[] args = new Object[ptypes.length];
   324         Object[] args = new Object[ptypes.length];
   325         for (int i = 0; i < ptypes.length; i++) {
   325         for (int i = 0; i < ptypes.length; i++) {
   326             Class<?> pt = ptypes[i];
   326             Class<?> pt = ptypes[i];
   327             Object arg;
   327             Object arg;
   328             if (pt == Void.class)       arg = null;
   328             if (pt == Void.class)       arg = null;
   329             else if (pt == int.class)   arg = (int)  i + 101;
   329             else if (pt == int.class)   arg = i + 101;
   330             else if (pt == long.class)  arg = (long) i + 10_000_000_001L;
   330             else if (pt == long.class)  arg = i + 10_000_000_001L;
   331             else                        arg = "#" + (i + 1);
   331             else                        arg = "#" + (i + 1);
   332             args[i] = arg;
   332             args[i] = arg;
   333         }
   333         }
   334         return args;
   334         return args;
   335     }
   335     }