jdk/test/java/lang/invoke/MethodHandles/CatchExceptionTest.java
changeset 26599 e82af948593b
parent 23594 505c3a4eb0d6
child 27781 eb64f15b3085
equal deleted inserted replaced
26598:c1d885140938 26599:e82af948593b
    40  * @run main/othervm -esa test.java.lang.invoke.MethodHandles.CatchExceptionTest
    40  * @run main/othervm -esa test.java.lang.invoke.MethodHandles.CatchExceptionTest
    41  */
    41  */
    42 public class CatchExceptionTest {
    42 public class CatchExceptionTest {
    43     private static final List<Class<?>> ARGS_CLASSES;
    43     private static final List<Class<?>> ARGS_CLASSES;
    44     protected static final int MAX_ARITY = Helper.MAX_ARITY - 1;
    44     protected static final int MAX_ARITY = Helper.MAX_ARITY - 1;
       
    45 
    45     static {
    46     static {
    46         Class<?> classes[] = {
    47         Class<?> classes[] = {
    47                 Object.class,
    48                 Object.class,
    48                 long.class,
    49                 long.class,
    49                 int.class,
    50                 int.class,
    50                 byte.class,
    51                 byte.class,
    51                 Integer[].class,
    52                 Integer[].class,
    52                 double[].class,
    53                 double[].class,
    53                 String.class,
    54                 String.class,
    54         };
    55         };
    55         List<Class<?>> list = new ArrayList<>(MAX_ARITY);
    56         ARGS_CLASSES = Collections.unmodifiableList(
    56         for (int i = 0; i < MAX_ARITY; ++i) {
    57                 Helper.randomClasses(classes, MAX_ARITY));
    57             list.add(classes[Helper.RNG.nextInt(classes.length)]);
       
    58         }
       
    59         ARGS_CLASSES = Collections.unmodifiableList(list);
       
    60     }
    58     }
    61 
    59 
    62     private final TestCase testCase;
    60     private final TestCase testCase;
    63     private final int nargs;
    61     private final int nargs;
    64     private final int argsCount;
    62     private final int argsCount;
    65     private final MethodHandle catcher;
    63     private final MethodHandle catcher;
    66     private int dropped;
    64     private int dropped;
    67     private MethodHandle thrower;
    65     private MethodHandle thrower;
    68 
       
    69 
    66 
    70     public CatchExceptionTest(TestCase testCase, final boolean isVararg, final int argsCount,
    67     public CatchExceptionTest(TestCase testCase, final boolean isVararg, final int argsCount,
    71             final int catchDrops) {
    68             final int catchDrops) {
    72         this.testCase = testCase;
    69         this.testCase = testCase;
    73         this.dropped = catchDrops;
    70         this.dropped = catchDrops;
   105             test.runTest();
   102             test.runTest();
   106         }
   103         }
   107     }
   104     }
   108 
   105 
   109     private List<Class<?>> getThrowerParams(boolean isVararg, int argsCount) {
   106     private List<Class<?>> getThrowerParams(boolean isVararg, int argsCount) {
   110         boolean unmodifiable = true;
   107         return Helper.getParams(ARGS_CLASSES, isVararg, argsCount);
   111         List<Class<?>> classes;
       
   112         classes = ARGS_CLASSES.subList(0,
       
   113                 Math.min(argsCount, (MAX_ARITY / 2) - 1));
       
   114         int extra = 0;
       
   115         if (argsCount >= MAX_ARITY / 2) {
       
   116             classes = new ArrayList<>(classes);
       
   117             unmodifiable = false;
       
   118             extra = (int) classes.stream().filter(Helper::isDoubleCost).count();
       
   119             int i = classes.size();
       
   120             while (classes.size() + extra < argsCount) {
       
   121                 Class<?> aClass = ARGS_CLASSES.get(i);
       
   122                 if (Helper.isDoubleCost(aClass)) {
       
   123                     ++extra;
       
   124                     if (classes.size() + extra >= argsCount) {
       
   125                         break;
       
   126                     }
       
   127                 }
       
   128                 classes.add(aClass);
       
   129             }
       
   130         }
       
   131         if (isVararg && classes.size() > 0) {
       
   132             if (unmodifiable) {
       
   133                 classes = new ArrayList<>(classes);
       
   134             }
       
   135             int last = classes.size() - 1;
       
   136             Class<?> aClass = classes.get(classes.size() - 1);
       
   137             aClass = Array.newInstance(aClass, 2).getClass();
       
   138             classes.set(last, aClass);
       
   139         }
       
   140         return classes;
       
   141     }
   108     }
   142 
   109 
   143 
   110 
   144     private List<Class<?>> getCatcherParams() {
   111     private List<Class<?>> getCatcherParams() {
   145         int catchArgc = 1 + this.argsCount - dropped;
   112         int catchArgc = 1 + this.argsCount - dropped;