test/java/lang/invoke/MethodHandles/CatchExceptionTest.java

Print this page
rev 10362 : 8057707: TEST library enhancement: copy sun.hotspot.whitebox classes from hotspot repo and enhance lib/testlibrary/jsr292/com/oracle/testlibrary/jsr292/Helper.java
Reviewed-by: iignatyev

@@ -40,35 +40,32 @@
  * @run main/othervm -esa test.java.lang.invoke.MethodHandles.CatchExceptionTest
  */
 public class CatchExceptionTest {
     private static final List<Class<?>> ARGS_CLASSES;
     protected static final int MAX_ARITY = Helper.MAX_ARITY - 1;
+
     static {
         Class<?> classes[] = {
                 Object.class,
                 long.class,
                 int.class,
                 byte.class,
                 Integer[].class,
                 double[].class,
                 String.class,
         };
-        List<Class<?>> list = new ArrayList<>(MAX_ARITY);
-        for (int i = 0; i < MAX_ARITY; ++i) {
-            list.add(classes[Helper.RNG.nextInt(classes.length)]);
-        }
-        ARGS_CLASSES = Collections.unmodifiableList(list);
+        ARGS_CLASSES = Collections.unmodifiableList(
+                Helper.randomClasses(classes, MAX_ARITY));
     }
 
     private final TestCase testCase;
     private final int nargs;
     private final int argsCount;
     private final MethodHandle catcher;
     private int dropped;
     private MethodHandle thrower;
 
-
     public CatchExceptionTest(TestCase testCase, final boolean isVararg, final int argsCount,
             final int catchDrops) {
         this.testCase = testCase;
         this.dropped = catchDrops;
         if (Helper.IS_VERBOSE) {

@@ -105,41 +102,11 @@
             test.runTest();
         }
     }
 
     private List<Class<?>> getThrowerParams(boolean isVararg, int argsCount) {
-        boolean unmodifiable = true;
-        List<Class<?>> classes;
-        classes = ARGS_CLASSES.subList(0,
-                Math.min(argsCount, (MAX_ARITY / 2) - 1));
-        int extra = 0;
-        if (argsCount >= MAX_ARITY / 2) {
-            classes = new ArrayList<>(classes);
-            unmodifiable = false;
-            extra = (int) classes.stream().filter(Helper::isDoubleCost).count();
-            int i = classes.size();
-            while (classes.size() + extra < argsCount) {
-                Class<?> aClass = ARGS_CLASSES.get(i);
-                if (Helper.isDoubleCost(aClass)) {
-                    ++extra;
-                    if (classes.size() + extra >= argsCount) {
-                        break;
-                    }
-                }
-                classes.add(aClass);
-            }
-        }
-        if (isVararg && classes.size() > 0) {
-            if (unmodifiable) {
-                classes = new ArrayList<>(classes);
-            }
-            int last = classes.size() - 1;
-            Class<?> aClass = classes.get(classes.size() - 1);
-            aClass = Array.newInstance(aClass, 2).getClass();
-            classes.set(last, aClass);
-        }
-        return classes;
+        return Helper.getParams(ARGS_CLASSES, isVararg, argsCount);
     }
 
 
     private List<Class<?>> getCatcherParams() {
         int catchArgc = 1 + this.argsCount - dropped;