8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory
Reviewed-by: rriggs
--- a/jdk/test/java/lang/invoke/ExplicitCastArgumentsTest.java Fri May 26 22:30:19 2017 -0700
+++ b/jdk/test/java/lang/invoke/ExplicitCastArgumentsTest.java Fri May 26 22:53:26 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,9 @@
* questions.
*/
-import com.oracle.testlibrary.jsr292.Helper;
+import sun.invoke.util.Wrapper;
+import test.java.lang.invoke.lib.Helper;
+
import java.io.File;
import java.io.Serializable;
import java.lang.invoke.MethodHandle;
@@ -31,13 +33,12 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
-import sun.invoke.util.Wrapper;
/*
* @test
* @bug 8060483 8066746
* @key randomness
- * @library /lib/testlibrary /lib/testlibrary/jsr292
+ * @library /lib/testlibrary /java/lang/invoke/common
* @modules java.base/sun.invoke.util
* @summary unit tests for MethodHandles.explicitCastArguments()
* @run main ExplicitCastArgumentsTest
@@ -249,21 +250,27 @@
for (Class parent : parents) {
for (int j = 0; j < children.length; j++) {
// Child type to parent type non-null conversion, shoud succeed
- testConversion(mode, children[j], parent, childInst[j], childInst[j], false, null);
+ testConversion(mode, children[j], parent, childInst[j],
+ childInst[j], false, null);
// Child type to parent type null conversion, shoud succeed
- testConversion(mode, children[j], parent, null, null, false, null);
+ testConversion(mode, children[j], parent, null,
+ null, false, null);
// Parent type to child type non-null conversion with parent
// type instance, should fail
- testConversion(mode, parent, children[j], testSuperObj, null, true, ClassCastException.class);
+ testConversion(mode, parent, children[j], testSuperObj,
+ null, true, ClassCastException.class);
// Parent type to child type non-null conversion with child
// type instance, should succeed
- testConversion(mode, parent, children[j], childInst[j], childInst[j], false, null);
+ testConversion(mode, parent, children[j], childInst[j],
+ childInst[j], false, null);
// Parent type to child type null conversion, should succeed
- testConversion(mode, parent, children[j], null, null, false, null);
+ testConversion(mode, parent, children[j], null,
+ null, false, null);
}
// Parent type to child type non-null conversion with sibling
// type instance, should fail
- testConversion(mode, parent, testSubClass1, testObj02, null, true, ClassCastException.class);
+ testConversion(mode, parent, testSubClass1, testObj02,
+ null, true, ClassCastException.class);
}
// Sibling type non-null conversion, should fail
testConversion(mode, testSubClass1,
--- a/jdk/test/java/lang/invoke/LFCaching/LFGarbageCollectedTest.java Fri May 26 22:30:19 2017 -0700
+++ b/jdk/test/java/lang/invoke/LFCaching/LFGarbageCollectedTest.java Fri May 26 22:53:26 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -28,11 +28,15 @@
* @ignore 8078602
* @summary Test verifies that lambda forms are garbage collected
* @author kshefov
- * @library /lib/testlibrary/jsr292 /lib/testlibrary
+ * @library /lib/testlibrary /java/lang/invoke/common
* @build TestMethods
* @build LambdaFormTestCase
* @build LFGarbageCollectedTest
- * @run main/othervm -Xmx64m -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+HeapDumpOnOutOfMemoryError -DHEAP_DUMP=false LFGarbageCollectedTest
+ * @run main/othervm -Xmx64m
+ * -XX:SoftRefLRUPolicyMSPerMB=0
+ * -XX:+HeapDumpOnOutOfMemoryError
+ * -DHEAP_DUMP=false
+ * LFGarbageCollectedTest
*/
import java.lang.invoke.MethodHandle;
--- a/jdk/test/java/lang/invoke/LFCaching/LFMultiThreadCachingTest.java Fri May 26 22:30:19 2017 -0700
+++ b/jdk/test/java/lang/invoke/LFCaching/LFMultiThreadCachingTest.java Fri May 26 22:53:26 2017 -0700
@@ -27,7 +27,7 @@
* @key randomness
* @summary Test verifies that lambda forms are cached when run with multiple threads
* @author kshefov
- * @library /lib/testlibrary/jsr292 /lib/testlibrary
+ * @library /lib/testlibrary /java/lang/invoke/common
* @modules java.base/java.lang.invoke:open
* java.base/java.lang.ref:open
* java.management
@@ -38,16 +38,16 @@
* @run main/othervm LFMultiThreadCachingTest
*/
+import test.java.lang.invoke.lib.CodeCacheOverflowProcessor;
+
import java.lang.invoke.MethodHandle;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
-import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
-import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
/**
* Multiple threaded lambda forms caching test class.
@@ -57,13 +57,16 @@
private static final TestMethods.Kind[] KINDS;
static {
- EnumSet<TestMethods.Kind> set = EnumSet.complementOf(EnumSet.of(TestMethods.Kind.EXCEPT));
+ EnumSet<TestMethods.Kind> set
+ = EnumSet.complementOf(EnumSet.of(TestMethods.Kind.EXCEPT));
KINDS = set.toArray(new TestMethods.Kind[set.size()]);
if (KINDS.length < 2) {
- throw new Error("TESTBUG: KINDS.length[" + KINDS.length + "] should be at least 2");
+ throw new Error("TESTBUG: KINDS.length[" + KINDS.length
+ + "] should be at least 2");
}
}
- private static final int CORES = Math.max(KINDS.length, Runtime.getRuntime().availableProcessors());
+ private static final int CORES
+ = Math.max(KINDS.length, Runtime.getRuntime().availableProcessors());
/**
* Constructor a for multiple threaded lambda forms caching test case.
@@ -144,6 +147,7 @@
* @param args Accepts no arguments.
*/
public static void main(String[] args) {
- LambdaFormTestCase.runTests(LFMultiThreadCachingTest::new, EnumSet.allOf(TestMethods.class));
+ LambdaFormTestCase.runTests(LFMultiThreadCachingTest::new,
+ EnumSet.allOf(TestMethods.class));
}
}
--- a/jdk/test/java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java Fri May 26 22:30:19 2017 -0700
+++ b/jdk/test/java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java Fri May 26 22:53:26 2017 -0700
@@ -27,7 +27,7 @@
* @key randomness
* @summary Test verifies that lambda forms are cached when run with single thread
* @author kshefov
- * @library /lib/testlibrary/jsr292 /lib/testlibrary
+ * @library /lib/testlibrary /java/lang/invoke/common
* @modules java.base/java.lang.ref:open
* java.base/java.lang.invoke:open
* java.management
@@ -77,6 +77,7 @@
* @param args Accepts no arguments.
*/
public static void main(String[] args) {
- LambdaFormTestCase.runTests(LFSingleThreadCachingTest::new, EnumSet.allOf(TestMethods.class));
+ LambdaFormTestCase.runTests(LFSingleThreadCachingTest::new,
+ EnumSet.allOf(TestMethods.class));
}
}
--- a/jdk/test/java/lang/invoke/LFCaching/LambdaFormTestCase.java Fri May 26 22:30:19 2017 -0700
+++ b/jdk/test/java/lang/invoke/LFCaching/LambdaFormTestCase.java Fri May 26 22:53:26 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,8 +21,11 @@
* questions.
*/
-import com.oracle.testlibrary.jsr292.Helper;
-import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
+import jdk.testlibrary.TimeLimitedRunner;
+import jdk.testlibrary.Utils;
+import test.java.lang.invoke.lib.CodeCacheOverflowProcessor;
+import test.java.lang.invoke.lib.Helper;
+
import java.lang.invoke.MethodHandle;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
@@ -32,8 +35,6 @@
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
-import jdk.testlibrary.Utils;
-import jdk.testlibrary.TimeLimitedRunner;
/**
* Lambda forms caching test case class. Contains all necessary test routines to
@@ -44,7 +45,8 @@
*/
public abstract class LambdaFormTestCase {
- private static final long TIMEOUT = Helper.IS_THOROUGH ? 0L : (long) (Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT) * 0.9);
+ private static final long TIMEOUT = Helper.IS_THOROUGH ?
+ 0L : (long) (Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT) * 0.9);
/**
* Reflection link to {@code j.l.i.MethodHandle.internalForm} method. It is
@@ -92,7 +94,8 @@
long failCounter;
boolean passed;
- TestRun(Function<TestMethods, LambdaFormTestCase> ctor, Collection<TestMethods> testMethods) {
+ TestRun(Function<TestMethods, LambdaFormTestCase> ctor,
+ Collection<TestMethods> testMethods) {
this.ctor = ctor;
this.testMethods = testMethods;
long testCaseNum = testMethods.size();
@@ -175,10 +178,12 @@
* object.
* @param testMethods list of test methods
*/
- public static void runTests(Function<TestMethods, LambdaFormTestCase> ctor, Collection<TestMethods> testMethods) {
+ public static void runTests(Function<TestMethods, LambdaFormTestCase> ctor,
+ Collection<TestMethods> testMethods) {
LambdaFormTestCase.TestRun run
= new LambdaFormTestCase.TestRun(ctor, testMethods);
- TimeLimitedRunner runner = new TimeLimitedRunner(TIMEOUT, 4.0d, run::doIteration);
+ TimeLimitedRunner runner
+ = new TimeLimitedRunner(TIMEOUT, 4.0d, run::doIteration);
try {
runner.call();
} catch (Exception ex) {
--- a/jdk/test/java/lang/invoke/LFCaching/TestMethods.java Fri May 26 22:30:19 2017 -0700
+++ b/jdk/test/java/lang/invoke/LFCaching/TestMethods.java Fri May 26 22:53:26 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,8 @@
* questions.
*/
-import com.oracle.testlibrary.jsr292.Helper;
+import test.java.lang.invoke.lib.Helper;
+
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
@@ -41,462 +42,472 @@
public enum TestMethods {
FOLD_ARGUMENTS("foldArguments") {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- // Arity after reducing because of long and double take 2 slots.
- int realArity = mtTarget.parameterCount();
- int modifierMHArgNum = Helper.RNG.nextInt(realArity + 1);
- data.put("modifierMHArgNum", modifierMHArgNum);
- Class<?> combinerReturnType;
- if (realArity == 0) {
- combinerReturnType = void.class;
- } else {
- combinerReturnType = Helper.RNG.nextBoolean() ? void.class : mtTarget.parameterType(0);
- }
- data.put("combinerReturnType", combinerReturnType);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ // Arity after reducing because of long and double take 2 slots.
+ int realArity = mtTarget.parameterCount();
+ int modifierMHArgNum = Helper.RNG.nextInt(realArity + 1);
+ data.put("modifierMHArgNum", modifierMHArgNum);
+ Class<?> combinerReturnType;
+ if (realArity == 0) {
+ combinerReturnType = void.class;
+ } else {
+ combinerReturnType = Helper.RNG.nextBoolean() ?
+ void.class : mtTarget.parameterType(0);
+ }
+ data.put("combinerReturnType", combinerReturnType);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- Class<?> combinerReturnType = (Class) data.get("combinerReturnType");
- int modifierMHArgNum = (int) data.get("modifierMHArgNum");
- MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
- mtTarget.parameterList(), kind);
- Class<?> rType = mtTarget.returnType();
- int combListStart = (combinerReturnType == void.class) ? 0 : 1;
- if (modifierMHArgNum < combListStart) {
- modifierMHArgNum = combListStart;
- }
- MethodHandle combiner = TestMethods.methodHandleGenerator(combinerReturnType,
- mtTarget.parameterList().subList(combListStart,
- modifierMHArgNum), kind);
- return MethodHandles.foldArguments(target, combiner);
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind)
+ throws NoSuchMethodException, IllegalAccessException {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ Class<?> combinerReturnType = (Class) data.get("combinerReturnType");
+ int modifierMHArgNum = (int) data.get("modifierMHArgNum");
+ MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
+ mtTarget.parameterList(), kind);
+ Class<?> rType = mtTarget.returnType();
+ int combListStart = (combinerReturnType == void.class) ? 0 : 1;
+ if (modifierMHArgNum < combListStart) {
+ modifierMHArgNum = combListStart;
+ }
+ MethodHandle combiner = TestMethods.methodHandleGenerator(combinerReturnType,
+ mtTarget.parameterList().subList(combListStart,
+ modifierMHArgNum), kind);
+ return MethodHandles.foldArguments(target, combiner);
+ }
+ },
DROP_ARGUMENTS("dropArguments") {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- // Arity after reducing because of long and double take 2 slots.
- int realArity = mtTarget.parameterCount();
- int dropArgsPos = Helper.RNG.nextInt(realArity + 1);
- data.put("dropArgsPos", dropArgsPos);
- MethodType mtDropArgs = TestMethods.randomMethodTypeGenerator(
- Helper.RNG.nextInt(super.maxArity - realArity));
- data.put("mtDropArgs", mtDropArgs);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ // Arity after reducing because of long and double take 2 slots.
+ int realArity = mtTarget.parameterCount();
+ int dropArgsPos = Helper.RNG.nextInt(realArity + 1);
+ data.put("dropArgsPos", dropArgsPos);
+ MethodType mtDropArgs = TestMethods.randomMethodTypeGenerator(
+ Helper.RNG.nextInt(super.maxArity - realArity));
+ data.put("mtDropArgs", mtDropArgs);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- MethodType mtDropArgs = (MethodType) data.get("mtDropArgs");
- int dropArgsPos = (int) data.get("dropArgsPos");
- MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
- mtTarget.parameterList(), kind);
- int mtTgtSlotsCount = TestMethods.argSlotsCount(mtTarget);
- int mtDASlotsCount = TestMethods.argSlotsCount(mtDropArgs);
- List<Class<?>> fakeParList;
- if (mtTgtSlotsCount + mtDASlotsCount > super.maxArity - 1) {
- fakeParList = TestMethods.reduceArgListToSlotsCount(mtDropArgs.parameterList(),
- super.maxArity - mtTgtSlotsCount - 1);
- } else {
- fakeParList = mtDropArgs.parameterList();
- }
- return MethodHandles.dropArguments(target, dropArgsPos, fakeParList);
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind)
+ throws NoSuchMethodException, IllegalAccessException {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ MethodType mtDropArgs = (MethodType) data.get("mtDropArgs");
+ int dropArgsPos = (int) data.get("dropArgsPos");
+ MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
+ mtTarget.parameterList(), kind);
+ int mtTgtSlotsCount = TestMethods.argSlotsCount(mtTarget);
+ int mtDASlotsCount = TestMethods.argSlotsCount(mtDropArgs);
+ List<Class<?>> fakeParList;
+ if (mtTgtSlotsCount + mtDASlotsCount > super.maxArity - 1) {
+ fakeParList = TestMethods.reduceArgListToSlotsCount(mtDropArgs.parameterList(),
+ super.maxArity - mtTgtSlotsCount - 1);
+ } else {
+ fakeParList = mtDropArgs.parameterList();
+ }
+ return MethodHandles.dropArguments(target, dropArgsPos, fakeParList);
+ }
+ },
EXPLICIT_CAST_ARGUMENTS("explicitCastArguments", Helper.MAX_ARITY / 2) {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- // Arity after reducing because of long and double take 2 slots.
- int realArity = mtTarget.parameterCount();
- MethodType mtExcplCastArgs = TestMethods.randomMethodTypeGenerator(realArity);
- if (mtTarget.returnType() == void.class) {
- mtExcplCastArgs = MethodType.methodType(void.class,
- mtExcplCastArgs.parameterArray());
- }
- if (mtExcplCastArgs.returnType() == void.class) {
- mtExcplCastArgs = MethodType.methodType(mtTarget.returnType(),
- mtExcplCastArgs.parameterArray());
- }
- data.put("mtExcplCastArgs", mtExcplCastArgs);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ // Arity after reducing because of long and double take 2 slots.
+ int realArity = mtTarget.parameterCount();
+ MethodType mtExcplCastArgs = TestMethods.randomMethodTypeGenerator(realArity);
+ if (mtTarget.returnType() == void.class) {
+ mtExcplCastArgs = MethodType.methodType(void.class,
+ mtExcplCastArgs.parameterArray());
+ }
+ if (mtExcplCastArgs.returnType() == void.class) {
+ mtExcplCastArgs = MethodType.methodType(mtTarget.returnType(),
+ mtExcplCastArgs.parameterArray());
+ }
+ data.put("mtExcplCastArgs", mtExcplCastArgs);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- MethodType mtExcplCastArgs = (MethodType) data.get("mtExcplCastArgs");
- MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
- mtTarget.parameterList(), kind);
- return MethodHandles.explicitCastArguments(target, mtExcplCastArgs);
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind)
+ throws NoSuchMethodException, IllegalAccessException {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ MethodType mtExcplCastArgs = (MethodType) data.get("mtExcplCastArgs");
+ MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
+ mtTarget.parameterList(), kind);
+ return MethodHandles.explicitCastArguments(target, mtExcplCastArgs);
+ }
+ },
FILTER_ARGUMENTS("filterArguments", Helper.MAX_ARITY / 2) {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- // Arity after reducing because of long and double take 2 slots.
- int realArity = mtTarget.parameterCount();
- int filterArgsPos = Helper.RNG.nextInt(realArity + 1);
- data.put("filterArgsPos", filterArgsPos);
- int filtersArgsArrayLength = Helper.RNG.nextInt(realArity + 1 - filterArgsPos);
- data.put("filtersArgsArrayLength", filtersArgsArrayLength);
- MethodType mtFilter = TestMethods.randomMethodTypeGenerator(filtersArgsArrayLength);
- data.put("mtFilter", mtFilter);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ // Arity after reducing because of long and double take 2 slots.
+ int realArity = mtTarget.parameterCount();
+ int filterArgsPos = Helper.RNG.nextInt(realArity + 1);
+ data.put("filterArgsPos", filterArgsPos);
+ int filtersArgsArrayLength = Helper.RNG.nextInt(realArity + 1 - filterArgsPos);
+ data.put("filtersArgsArrayLength", filtersArgsArrayLength);
+ MethodType mtFilter = TestMethods.randomMethodTypeGenerator(filtersArgsArrayLength);
+ data.put("mtFilter", mtFilter);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- MethodType mtFilter = (MethodType) data.get("mtFilter");
- int filterArgsPos = (int) data.get("filterArgsPos");
- int filtersArgsArrayLength = (int) data.get("filtersArgsArrayLength");
- MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
- mtTarget.parameterList(), kind);
- MethodHandle[] filters = new MethodHandle[filtersArgsArrayLength];
- for (int i = 0; i < filtersArgsArrayLength; i++) {
- filters[i] = TestMethods.filterGenerator(mtFilter.parameterType(i),
- mtTarget.parameterType(filterArgsPos + i), kind);
- }
- return MethodHandles.filterArguments(target, filterArgsPos, filters);
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind)
+ throws NoSuchMethodException, IllegalAccessException {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ MethodType mtFilter = (MethodType) data.get("mtFilter");
+ int filterArgsPos = (int) data.get("filterArgsPos");
+ int filtersArgsArrayLength = (int) data.get("filtersArgsArrayLength");
+ MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
+ mtTarget.parameterList(), kind);
+ MethodHandle[] filters = new MethodHandle[filtersArgsArrayLength];
+ for (int i = 0; i < filtersArgsArrayLength; i++) {
+ filters[i] = TestMethods.filterGenerator(mtFilter.parameterType(i),
+ mtTarget.parameterType(filterArgsPos + i), kind);
+ }
+ return MethodHandles.filterArguments(target, filterArgsPos, filters);
+ }
+ },
FILTER_RETURN_VALUE("filterReturnValue") {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- // Arity after reducing because of long and double take 2 slots.
- int realArity = mtTarget.parameterCount();
- int filterArgsPos = Helper.RNG.nextInt(realArity + 1);
- int filtersArgsArrayLength = Helper.RNG.nextInt(realArity + 1 - filterArgsPos);
- MethodType mtFilter = TestMethods.randomMethodTypeGenerator(filtersArgsArrayLength);
- data.put("mtFilter", mtFilter);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ // Arity after reducing because of long and double take 2 slots.
+ int realArity = mtTarget.parameterCount();
+ int filterArgsPos = Helper.RNG.nextInt(realArity + 1);
+ int filtersArgsArrayLength = Helper.RNG.nextInt(realArity + 1 - filterArgsPos);
+ MethodType mtFilter = TestMethods.randomMethodTypeGenerator(filtersArgsArrayLength);
+ data.put("mtFilter", mtFilter);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- MethodType mtFilter = (MethodType) data.get("mtFilter");
- MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
- mtTarget.parameterList(), kind);
- MethodHandle filter = TestMethods.filterGenerator(mtTarget.returnType(),
- mtFilter.returnType(), kind);
- return MethodHandles.filterReturnValue(target, filter);
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind)
+ throws NoSuchMethodException, IllegalAccessException {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ MethodType mtFilter = (MethodType) data.get("mtFilter");
+ MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
+ mtTarget.parameterList(), kind);
+ MethodHandle filter = TestMethods.filterGenerator(mtTarget.returnType(),
+ mtFilter.returnType(), kind);
+ return MethodHandles.filterReturnValue(target, filter);
+ }
+ },
INSERT_ARGUMENTS("insertArguments", Helper.MAX_ARITY - 3) {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- // Arity after reducing because of long and double take 2 slots.
- int realArity = mtTarget.parameterCount();
- int insertArgsPos = Helper.RNG.nextInt(realArity + 1);
- data.put("insertArgsPos", insertArgsPos);
- int insertArgsArrayLength = Helper.RNG.nextInt(realArity + 1 - insertArgsPos);
- MethodType mtInsertArgs = MethodType.methodType(void.class, mtTarget.parameterList()
- .subList(insertArgsPos, insertArgsPos + insertArgsArrayLength));
- data.put("mtInsertArgs", mtInsertArgs);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ // Arity after reducing because of long and double take 2 slots.
+ int realArity = mtTarget.parameterCount();
+ int insertArgsPos = Helper.RNG.nextInt(realArity + 1);
+ data.put("insertArgsPos", insertArgsPos);
+ int insertArgsArrayLength = Helper.RNG.nextInt(realArity + 1 - insertArgsPos);
+ MethodType mtInsertArgs = MethodType.methodType(void.class, mtTarget.parameterList()
+ .subList(insertArgsPos, insertArgsPos + insertArgsArrayLength));
+ data.put("mtInsertArgs", mtInsertArgs);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- MethodType mtInsertArgs = (MethodType) data.get("mtInsertArgs");
- int insertArgsPos = (int) data.get("insertArgsPos");
- MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
- mtTarget.parameterList(), kind);
- Object[] insertList = Helper.randomArgs(mtInsertArgs.parameterList());
- return MethodHandles.insertArguments(target, insertArgsPos, insertList);
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind)
+ throws NoSuchMethodException, IllegalAccessException {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ MethodType mtInsertArgs = (MethodType) data.get("mtInsertArgs");
+ int insertArgsPos = (int) data.get("insertArgsPos");
+ MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
+ mtTarget.parameterList(), kind);
+ Object[] insertList = Helper.randomArgs(mtInsertArgs.parameterList());
+ return MethodHandles.insertArguments(target, insertArgsPos, insertList);
+ }
+ },
PERMUTE_ARGUMENTS("permuteArguments", Helper.MAX_ARITY / 2) {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- // Arity after reducing because of long and double take 2 slots.
- int realArity = mtTarget.parameterCount();
- int[] permuteArgsReorderArray = new int[realArity];
- int mtPermuteArgsNum = Helper.RNG.nextInt(Helper.MAX_ARITY);
- mtPermuteArgsNum = mtPermuteArgsNum == 0 ? 1 : mtPermuteArgsNum;
- MethodType mtPermuteArgs = TestMethods.randomMethodTypeGenerator(mtPermuteArgsNum);
- mtTarget = mtTarget.changeReturnType(mtPermuteArgs.returnType());
- for (int i = 0; i < realArity; i++) {
- int mtPermuteArgsParNum = Helper.RNG.nextInt(mtPermuteArgs.parameterCount());
- permuteArgsReorderArray[i] = mtPermuteArgsParNum;
- mtTarget = mtTarget.changeParameterType(
- i, mtPermuteArgs.parameterType(mtPermuteArgsParNum));
- }
- data.put("mtTarget", mtTarget);
- data.put("permuteArgsReorderArray", permuteArgsReorderArray);
- data.put("mtPermuteArgs", mtPermuteArgs);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ // Arity after reducing because of long and double take 2 slots.
+ int realArity = mtTarget.parameterCount();
+ int[] permuteArgsReorderArray = new int[realArity];
+ int mtPermuteArgsNum = Helper.RNG.nextInt(Helper.MAX_ARITY);
+ mtPermuteArgsNum = mtPermuteArgsNum == 0 ? 1 : mtPermuteArgsNum;
+ MethodType mtPermuteArgs = TestMethods.randomMethodTypeGenerator(mtPermuteArgsNum);
+ mtTarget = mtTarget.changeReturnType(mtPermuteArgs.returnType());
+ for (int i = 0; i < realArity; i++) {
+ int mtPermuteArgsParNum = Helper.RNG.nextInt(mtPermuteArgs.parameterCount());
+ permuteArgsReorderArray[i] = mtPermuteArgsParNum;
+ mtTarget = mtTarget.changeParameterType(
+ i, mtPermuteArgs.parameterType(mtPermuteArgsParNum));
+ }
+ data.put("mtTarget", mtTarget);
+ data.put("permuteArgsReorderArray", permuteArgsReorderArray);
+ data.put("mtPermuteArgs", mtPermuteArgs);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- MethodType mtPermuteArgs = (MethodType) data.get("mtPermuteArgs");
- int[] permuteArgsReorderArray = (int[]) data.get("permuteArgsReorderArray");
- MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
- mtTarget.parameterList(), kind);
- return MethodHandles.permuteArguments(target, mtPermuteArgs, permuteArgsReorderArray);
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind)
+ throws NoSuchMethodException, IllegalAccessException {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ MethodType mtPermuteArgs = (MethodType) data.get("mtPermuteArgs");
+ int[] permuteArgsReorderArray = (int[]) data.get("permuteArgsReorderArray");
+ MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
+ mtTarget.parameterList(), kind);
+ return MethodHandles.permuteArguments(target, mtPermuteArgs, permuteArgsReorderArray);
+ }
+ },
THROW_EXCEPTION("throwException") {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- Class<?> rType = mtTarget.returnType();
- return MethodHandles.throwException(rType, Exception.class
- );
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ Class<?> rType = mtTarget.returnType();
+ return MethodHandles.throwException(rType, Exception.class
+ );
+ }
+ },
GUARD_WITH_TEST("guardWithTest") {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- // Arity after reducing because of long and double take 2 slots.
- int realArity = mtTarget.parameterCount();
- int modifierMHArgNum = Helper.RNG.nextInt(realArity + 1);
- data.put("modifierMHArgNum", modifierMHArgNum);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ // Arity after reducing because of long and double take 2 slots.
+ int realArity = mtTarget.parameterCount();
+ int modifierMHArgNum = Helper.RNG.nextInt(realArity + 1);
+ data.put("modifierMHArgNum", modifierMHArgNum);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- int modifierMHArgNum = (int) data.get("modifierMHArgNum");
- TestMethods.Kind targetKind;
- TestMethods.Kind fallbackKind;
- if (kind.equals(TestMethods.Kind.ONE)) {
- targetKind = TestMethods.Kind.ONE;
- fallbackKind = TestMethods.Kind.TWO;
- } else {
- targetKind = TestMethods.Kind.TWO;
- fallbackKind = TestMethods.Kind.ONE;
- }
- MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
- mtTarget.parameterList(), targetKind);
- MethodHandle fallback = TestMethods.methodHandleGenerator(mtTarget.returnType(),
- mtTarget.parameterList(), fallbackKind);
- MethodHandle test = TestMethods.methodHandleGenerator(boolean.class,
- mtTarget.parameterList().subList(0, modifierMHArgNum), kind);
- return MethodHandles.guardWithTest(test, target, fallback);
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind)
+ throws NoSuchMethodException, IllegalAccessException {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ int modifierMHArgNum = (int) data.get("modifierMHArgNum");
+ TestMethods.Kind targetKind;
+ TestMethods.Kind fallbackKind;
+ if (kind.equals(TestMethods.Kind.ONE)) {
+ targetKind = TestMethods.Kind.ONE;
+ fallbackKind = TestMethods.Kind.TWO;
+ } else {
+ targetKind = TestMethods.Kind.TWO;
+ fallbackKind = TestMethods.Kind.ONE;
+ }
+ MethodHandle target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
+ mtTarget.parameterList(), targetKind);
+ MethodHandle fallback = TestMethods.methodHandleGenerator(mtTarget.returnType(),
+ mtTarget.parameterList(), fallbackKind);
+ MethodHandle test = TestMethods.methodHandleGenerator(boolean.class,
+ mtTarget.parameterList().subList(0, modifierMHArgNum), kind);
+ return MethodHandles.guardWithTest(test, target, fallback);
+ }
+ },
CATCH_EXCEPTION("catchException") {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- // Arity after reducing because of long and double take 2 slots.
- int realArity = mtTarget.parameterCount();
- int modifierMHArgNum = Helper.RNG.nextInt(realArity + 1);
- data.put("modifierMHArgNum", modifierMHArgNum);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ // Arity after reducing because of long and double take 2 slots.
+ int realArity = mtTarget.parameterCount();
+ int modifierMHArgNum = Helper.RNG.nextInt(realArity + 1);
+ data.put("modifierMHArgNum", modifierMHArgNum);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- int modifierMHArgNum = (int) data.get("modifierMHArgNum");
- MethodHandle target;
- if (kind.equals(TestMethods.Kind.ONE)) {
- target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
- mtTarget.parameterList(), TestMethods.Kind.ONE);
- } else {
- target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
- mtTarget.parameterList(), TestMethods.Kind.EXCEPT);
- }
- List<Class<?>> handlerParamList = new ArrayList<>(mtTarget.parameterCount() + 1);
- handlerParamList.add(Exception.class);
- handlerParamList.addAll(mtTarget.parameterList().subList(0, modifierMHArgNum));
- MethodHandle handler = TestMethods.methodHandleGenerator(
- mtTarget.returnType(), handlerParamList, TestMethods.Kind.TWO);
- return MethodHandles.catchException(target, Exception.class, handler);
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind)
+ throws NoSuchMethodException, IllegalAccessException {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ int modifierMHArgNum = (int) data.get("modifierMHArgNum");
+ MethodHandle target;
+ if (kind.equals(TestMethods.Kind.ONE)) {
+ target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
+ mtTarget.parameterList(), TestMethods.Kind.ONE);
+ } else {
+ target = TestMethods.methodHandleGenerator(mtTarget.returnType(),
+ mtTarget.parameterList(), TestMethods.Kind.EXCEPT);
+ }
+ List<Class<?>> handlerParamList = new ArrayList<>(mtTarget.parameterCount() + 1);
+ handlerParamList.add(Exception.class);
+ handlerParamList.addAll(mtTarget.parameterList().subList(0, modifierMHArgNum));
+ MethodHandle handler = TestMethods.methodHandleGenerator(
+ mtTarget.returnType(), handlerParamList, TestMethods.Kind.TWO);
+ return MethodHandles.catchException(target, Exception.class, handler);
+ }
+ },
INVOKER("invoker", Helper.MAX_ARITY - 1) {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- return MethodHandles.invoker(mtTarget);
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ return MethodHandles.invoker(mtTarget);
+ }
+ },
EXACT_INVOKER("exactInvoker", Helper.MAX_ARITY - 1) {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- return MethodHandles.exactInvoker(mtTarget);
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ return MethodHandles.exactInvoker(mtTarget);
+ }
+ },
SPREAD_INVOKER("spreadInvoker", Helper.MAX_ARITY - 1) {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- // Arity after reducing because of long and double take 2 slots.
- int realArity = mtTarget.parameterCount();
- int modifierMHArgNum = Helper.RNG.nextInt(realArity + 1);
- data.put("modifierMHArgNum", modifierMHArgNum);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ // Arity after reducing because of long and double take 2 slots.
+ int realArity = mtTarget.parameterCount();
+ int modifierMHArgNum = Helper.RNG.nextInt(realArity + 1);
+ data.put("modifierMHArgNum", modifierMHArgNum);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- int modifierMHArgNum = (int) data.get("modifierMHArgNum");
- return MethodHandles.spreadInvoker(mtTarget, modifierMHArgNum);
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ int modifierMHArgNum = (int) data.get("modifierMHArgNum");
+ return MethodHandles.spreadInvoker(mtTarget, modifierMHArgNum);
+ }
+ },
ARRAY_ELEMENT_GETTER("arrayElementGetter") {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- Class<?> rType = mtTarget.returnType();
- if (rType == void.class) {
- rType = Object.class;
- }
- return MethodHandles.arrayElementGetter(Array.newInstance(rType, 2).getClass());
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ Class<?> rType = mtTarget.returnType();
+ if (rType == void.class) {
+ rType = Object.class;
+ }
+ return MethodHandles.arrayElementGetter(Array.newInstance(rType, 2).getClass());
+ }
+ },
ARRAY_ELEMENT_SETTER("arrayElementSetter") {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- Class<?> rType = mtTarget.returnType();
- if (rType == void.class) {
- rType = Object.class;
- }
- return MethodHandles.arrayElementSetter(Array.newInstance(rType, 2).getClass());
- }
- },
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ Class<?> rType = mtTarget.returnType();
+ if (rType == void.class) {
+ rType = Object.class;
+ }
+ return MethodHandles.arrayElementSetter(Array.newInstance(rType, 2).getClass());
+ }
+ },
CONSTANT("constant") {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- return data;
- }
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- Class<?> rType = mtTarget.returnType();
- if (rType == void.class) {
- rType = Object.class;
- }
- if (rType.equals(boolean.class)) {
- // There should be the same return values because for default values there are special "zero" forms
- return MethodHandles.constant(rType, true);
- } else {
- return MethodHandles.constant(rType, kind.getValue(rType));
- }
- }
- },
- IDENTITY("identity") {
- @Override
- public Map<String, Object> getTestCaseData() {
- Map<String, Object> data = new HashMap<>();
- int desiredArity = Helper.RNG.nextInt(super.maxArity);
- MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
- data.put("mtTarget", mtTarget);
- return data;
- }
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ Class<?> rType = mtTarget.returnType();
+ if (rType == void.class) {
+ rType = Object.class;
+ }
+ if (rType.equals(boolean.class)) {
+ // There should be the same return values because for default values there are special "zero" forms
+ return MethodHandles.constant(rType, true);
+ } else {
+ return MethodHandles.constant(rType, kind.getValue(rType));
+ }
+ }
+ },
+IDENTITY("identity") {
+ @Override
+ public Map<String, Object> getTestCaseData() {
+ Map<String, Object> data = new HashMap<>();
+ int desiredArity = Helper.RNG.nextInt(super.maxArity);
+ MethodType mtTarget = TestMethods.randomMethodTypeGenerator(desiredArity);
+ data.put("mtTarget", mtTarget);
+ return data;
+ }
- @Override
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
- MethodType mtTarget = (MethodType) data.get("mtTarget");
- Class<?> rType = mtTarget.returnType();
- if (rType == void.class) {
- rType = Object.class;
- }
- return MethodHandles.identity(rType);
- }
- };
+ @Override
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) {
+ MethodType mtTarget = (MethodType) data.get("mtTarget");
+ Class<?> rType = mtTarget.returnType();
+ if (rType == void.class) {
+ rType = Object.class;
+ }
+ return MethodHandles.identity(rType);
+ }
+ };
/**
* Test method's name.
@@ -514,8 +525,10 @@
this(name, Helper.MAX_ARITY);
}
- protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
- throw new UnsupportedOperationException("TESTBUG: getMH method is not implemented for test method " + this);
+ protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind)
+ throws NoSuchMethodException, IllegalAccessException {
+ throw new UnsupportedOperationException(
+ "TESTBUG: getMH method is not implemented for test method " + this);
}
/**
@@ -575,13 +588,15 @@
return Helper.castToWrapper(value, cl);
}
- private MethodHandle getBasicMH(Class<?> rType) throws NoSuchMethodException, IllegalAccessException {
+ private MethodHandle getBasicMH(Class<?> rType)
+ throws NoSuchMethodException, IllegalAccessException {
MethodHandle result = null;
switch (this) {
case ONE:
case TWO:
if (rType.equals(void.class)) {
- result = MethodHandles.lookup().findVirtual(Kind.class, "returnVoid", MethodType.methodType(void.class));
+ result = MethodHandles.lookup().findVirtual(Kind.class,
+ "returnVoid", MethodType.methodType(void.class));
result = MethodHandles.insertArguments(result, 0, this);
} else {
result = MethodHandles.constant(rType, getValue(rType));
--- a/jdk/test/java/lang/invoke/MethodHandles/CatchExceptionTest.java Fri May 26 22:30:19 2017 -0700
+++ b/jdk/test/java/lang/invoke/MethodHandles/CatchExceptionTest.java Fri May 26 22:53:26 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -20,25 +20,30 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+
package test.java.lang.invoke.MethodHandles;
-import com.oracle.testlibrary.jsr292.Helper;
-import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
import jdk.testlibrary.Asserts;
import jdk.testlibrary.TimeLimitedRunner;
import jdk.testlibrary.Utils;
+import test.java.lang.invoke.lib.CodeCacheOverflowProcessor;
+import test.java.lang.invoke.lib.Helper;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Array;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
/* @test
- * @library /lib/testlibrary/jsr292 /lib/testlibrary/
+ * @library /lib/testlibrary /java/lang/invoke/common
* @compile CatchExceptionTest.java
* @run main/othervm -esa test.java.lang.invoke.MethodHandles.CatchExceptionTest
* @key intermittent randomness
@@ -68,8 +73,8 @@
private int dropped;
private MethodHandle thrower;
- public CatchExceptionTest(TestCase testCase, final boolean isVararg, final int argsCount,
- final int catchDrops) {
+ public CatchExceptionTest(TestCase testCase, final boolean isVararg,
+ final int argsCount, final int catchDrops) {
this.testCase = testCase;
this.dropped = catchDrops;
MethodHandle thrower = testCase.thrower;
@@ -353,8 +358,8 @@
new ClassCastException("testing"),
new java.io.IOException("testing"),
new LinkageError("testing")};
- List<Supplier<TestCase>> list = new ArrayList<>(constructors.length *
- throwables.length * ThrowMode.values().length);
+ List<Supplier<TestCase>> list = new ArrayList<>(constructors.length
+ * throwables.length * ThrowMode.values().length);
//noinspection unchecked
for (PartialConstructor f : constructors) {
for (ThrowMode mode : ThrowMode.values()) {
--- a/jdk/test/java/lang/invoke/MethodHandlesTest.java Fri May 26 22:30:19 2017 -0700
+++ b/jdk/test/java/lang/invoke/MethodHandlesTest.java Fri May 26 22:53:26 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,23 +23,46 @@
/* @test
* @summary unit tests for java.lang.invoke.MethodHandles
- * @library /lib/testlibrary /lib/testlibrary/jsr292
+ * @library /lib/testlibrary /java/lang/invoke/common
* @compile MethodHandlesTest.java remote/RemoteExample.java
- * @run junit/othervm/timeout=2500 -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies -esa test.java.lang.invoke.MethodHandlesTest
+ * @run junit/othervm/timeout=2500 -XX:+IgnoreUnrecognizedVMOptions
+ * -XX:-VerifyDependencies
+ * -esa
+ * test.java.lang.invoke.MethodHandlesTest
*/
package test.java.lang.invoke;
+import org.junit.*;
+import test.java.lang.invoke.lib.CodeCacheOverflowProcessor;
import test.java.lang.invoke.remote.RemoteExample;
-import java.lang.invoke.*;
-import static java.lang.invoke.MethodType.methodType;
+
+import java.lang.invoke.CallSite;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandleProxies;
+import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
-import java.lang.reflect.*;
-import java.util.*;
-import org.junit.*;
+import java.lang.invoke.MethodType;
+import java.lang.invoke.MutableCallSite;
+import java.lang.invoke.WrongMethodTypeException;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Formatter;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static java.lang.invoke.MethodType.methodType;
import static org.junit.Assert.*;
-import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
-
/**
*
--- a/jdk/test/java/lang/invoke/PermuteArgsTest.java Fri May 26 22:30:19 2017 -0700
+++ b/jdk/test/java/lang/invoke/PermuteArgsTest.java Fri May 26 22:53:26 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,9 +23,10 @@
/* @test
* @summary unit tests for method handles which permute their arguments
- * @library /lib/testlibrary/jsr292 /lib/testlibrary
+ * @library /lib/testlibrary /java/lang/invoke/common
* @run testng/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies -ea -esa -DPermuteArgsTest.MAX_ARITY=8 test.java.lang.invoke.PermuteArgsTest
*/
+
/* Examples of manual runs:
* java -DPermuteArgsTest.{DRY_RUN=true,MAX_ARITY=253} test.java.lang.invoke.PermuteArgsTest
* java -DPermuteArgsTest.{VERBOSE=true,MAX_ARITY=5} test.java.lang.invoke.PermuteArgsTest
@@ -34,17 +35,23 @@
package test.java.lang.invoke;
-import org.testng.*;
-import org.testng.annotations.*;
-
-import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
+import org.testng.annotations.Test;
+import test.java.lang.invoke.lib.CodeCacheOverflowProcessor;
-import java.util.*;
-import java.lang.reflect.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodType;
+import java.lang.invoke.WrongMethodTypeException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
-import java.lang.invoke.*;
-import static java.lang.invoke.MethodHandles.*;
-import static java.lang.invoke.MethodType.*;
+import static java.lang.invoke.MethodHandles.Lookup;
+import static java.lang.invoke.MethodHandles.lookup;
+import static java.lang.invoke.MethodHandles.permuteArguments;
+import static java.lang.invoke.MethodType.methodType;
public class PermuteArgsTest {
private static final Class<?> CLASS = PermuteArgsTest.class;
@@ -205,7 +212,8 @@
throw new IllegalArgumentException("cannot convert to type "+mt1+" from "+mh, ex);
}
}
- static MethodHandle findTestMH(String name, int[] perm) throws ReflectiveOperationException {
+ static MethodHandle findTestMH(String name, int[] perm)
+ throws ReflectiveOperationException {
int arity = perm.length;
Lookup lookup = lookup();
for (Method m : lookup.lookupClass().getDeclaredMethods()) {
@@ -259,7 +267,8 @@
}
}
- static void testPermutations(MethodHandle mh, int[] perm, int start, int end, Set<String> done) throws Throwable {
+ static void testPermutations(MethodHandle mh, int[] perm, int start, int end,
+ Set<String> done) throws Throwable {
if (end - start <= 1) return;
for (int j = 0; j <= 1; j++) {
testRotations(mh, perm, start, end, done);
@@ -283,7 +292,8 @@
}
}
- static void testRotations(MethodHandle mh, int[] perm, int start, int end, Set<String> done) throws Throwable {
+ static void testRotations(MethodHandle mh, int[] perm, int start, int end,
+ Set<String> done) throws Throwable {
Object[] args = junkArgs(mh.type().parameterArray());
for (int i = start; i < end; i++) {
if (done.add(Arrays.toString(perm)))
@@ -292,9 +302,11 @@
}
}
- static void testOnePermutation(MethodHandle mh, int[] perm, Object[] args) throws Throwable {
+ static void testOnePermutation(MethodHandle mh, int[] perm, Object[] args)
+ throws Throwable {
MethodType mt = mh.type();
- MethodType pmt = methodType(mt.returnType(), unpermuteArgs(perm, mt.parameterArray(), Class[].class));
+ MethodType pmt = methodType(mt.returnType(),
+ unpermuteArgs(perm, mt.parameterArray(), Class[].class));
if (VERBOSE)
System.out.println(Arrays.toString(perm));
testCases += 1;
--- a/jdk/test/java/lang/invoke/TestCatchExceptionWithVarargs.java Fri May 26 22:30:19 2017 -0700
+++ b/jdk/test/java/lang/invoke/TestCatchExceptionWithVarargs.java Fri May 26 22:53:26 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -24,14 +24,18 @@
/*
* @test
* @bug 8019184
- * @library /lib/testlibrary /lib/testlibrary/jsr292
+ * @library /lib/testlibrary /java/lang/invoke/common
* @summary MethodHandles.catchException() fails when methods have 8 args + varargs
* @run main TestCatchExceptionWithVarargs
*/
-import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
-import java.util.*;
-import java.lang.invoke.*;
+import test.java.lang.invoke.lib.CodeCacheOverflowProcessor;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.LinkedList;
+import java.util.List;
public class TestCatchExceptionWithVarargs {
@@ -48,14 +52,16 @@
public static Object target(Object... a) throws Exception {
if (a[0] != firstArg) {
- throw new AssertionError("first argument different than expected: " + a[0] + " != " + firstArg);
+ throw new AssertionError("first argument different than expected: "
+ + a[0] + " != " + firstArg);
}
throw new MyException();
}
public static Object handler(Object... a) {
if (a[0] != firstArg) {
- throw new AssertionError("first argument different than expected: " + a[0] + " != " + firstArg);
+ throw new AssertionError("first argument different than expected: "
+ + a[0] + " != " + firstArg);
}
return a[0];
}
@@ -83,20 +89,27 @@
for (int i = 1; i < MAX_MH_ARITY - 1; i++) {
ptypes.add(0, Object.class);
- MethodHandle targetWithArgs = target.asType(MethodType.methodType(Object.class, ptypes));
- MethodHandle handlerWithArgs = handler.asType(MethodType.methodType(Object.class, ptypes));
- handlerWithArgs = MethodHandles.dropArguments(handlerWithArgs, 0, MyException.class);
+ MethodHandle targetWithArgs = target.asType(
+ MethodType.methodType(Object.class, ptypes));
+ MethodHandle handlerWithArgs = handler.asType(
+ MethodType.methodType(Object.class, ptypes));
+ handlerWithArgs = MethodHandles.dropArguments(
+ handlerWithArgs, 0, MyException.class);
- MethodHandle gwc1 = MethodHandles.catchException(targetWithArgs, MyException.class, handlerWithArgs);
+ MethodHandle gwc1 = MethodHandles.catchException(
+ targetWithArgs, MyException.class, handlerWithArgs);
// The next line throws an IllegalArgumentException if there is a bug.
- MethodHandle gwc2 = MethodHandles.catchException(gwc1, MyException.class, handlerWithArgs);
+ MethodHandle gwc2 = MethodHandles.catchException(
+ gwc1, MyException.class, handlerWithArgs);
// This is only to verify that the method handles can actually be invoked and do the right thing.
firstArg = new Object();
- Object o = gwc2.asSpreader(Object[].class, ptypes.size() - 1).invoke(firstArg, new Object[i]);
+ Object o = gwc2.asSpreader(Object[].class, ptypes.size() - 1)
+ .invoke(firstArg, new Object[i]);
if (o != firstArg) {
- throw new AssertionError("return value different than expected: " + o + " != " + firstArg);
+ throw new AssertionError("return value different than expected: "
+ + o + " != " + firstArg);
}
}
}
--- a/jdk/test/java/lang/invoke/VarargsArrayTest.java Fri May 26 22:30:19 2017 -0700
+++ b/jdk/test/java/lang/invoke/VarargsArrayTest.java Fri May 26 22:53:26 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,20 +21,20 @@
* questions.
*/
+import sun.invoke.util.Wrapper;
+import test.java.lang.invoke.lib.CodeCacheOverflowProcessor;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandleHelper;
import java.lang.invoke.MethodType;
-import sun.invoke.util.Wrapper;
import java.util.Arrays;
import java.util.Collections;
-import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
/* @test
* @summary unit tests for varargs array methods: MethodHandleInfo.varargsArray(int),
* MethodHandleInfo.varargsArray(Class,int) & MethodHandleInfo.varargsList(int)
* @modules java.base/sun.invoke.util
- * @library /lib/testlibrary /lib/testlibrary/jsr292
+ * @library /lib/testlibrary /java/lang/invoke/common
* @compile/module=java.base java/lang/invoke/MethodHandleHelper.java
* @run main/bootclasspath VarargsArrayTest
* @run main/bootclasspath/othervm -DVarargsArrayTest.MAX_ARITY=255 -DVarargsArrayTest.START_ARITY=250
@@ -46,9 +46,12 @@
*/
public class VarargsArrayTest {
private static final Class<?> CLASS = VarargsArrayTest.class;
- private static final int MAX_ARITY = Integer.getInteger(CLASS.getSimpleName()+".MAX_ARITY", 40);
- private static final int START_ARITY = Integer.getInteger(CLASS.getSimpleName()+".START_ARITY", 0);
- private static final boolean EXHAUSTIVE = Boolean.getBoolean(CLASS.getSimpleName()+".EXHAUSTIVE");
+ private static final int MAX_ARITY = Integer.getInteger(
+ CLASS.getSimpleName()+".MAX_ARITY", 40);
+ private static final int START_ARITY = Integer.getInteger(
+ CLASS.getSimpleName()+".START_ARITY", 0);
+ private static final boolean EXHAUSTIVE = Boolean.getBoolean(
+ CLASS.getSimpleName()+".EXHAUSTIVE");
public static void main(String[] args) throws Throwable {
CodeCacheOverflowProcessor.runMHTest(VarargsArrayTest::test);
@@ -211,7 +214,8 @@
}
return;
}
- throw new AssertionError(Arrays.deepToString(arr1) + " != " + Arrays.deepToString(arr2));
+ throw new AssertionError(Arrays.deepToString(arr1)
+ + " != " + Arrays.deepToString(arr2));
}
public static void assertEquals(Object o1, Object o2) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/invoke/common/test/java/lang/invoke/lib/CodeCacheOverflowProcessor.java Fri May 26 22:53:26 2017 -0700
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test.java.lang.invoke.lib;
+
+import jdk.testlibrary.Utils;
+
+/**
+ * Helper class used to catch and process VirtualMachineError with message "Out
+ * of space in CodeCache". Some JSR292 tests run out of code cache size, so code
+ * cache overflows and VME is thrown. This VME is considered as non-critical in
+ * some JSR292 tests, so it should be processed to prevent test failure.
+ */
+public class CodeCacheOverflowProcessor {
+
+ /**
+ * Checks if an instance of Throwable is caused by VirtualMachineError with
+ * message "Out of space in CodeCache". May be used as filter in method
+ * {@code jdk.testlibrary.Utils.filterException}.
+ *
+ * @param t - Throwable to check.
+ * @return true if Throwable is caused by VME, false otherwise.
+ */
+ public static Boolean isThrowableCausedByVME(Throwable t) {
+ Throwable causeOfT = t;
+ do {
+ if (causeOfT instanceof VirtualMachineError
+ && causeOfT.getMessage().matches(".*[Oo]ut of space"
+ + " in CodeCache.*")) {
+ return true;
+ }
+ causeOfT = causeOfT != null ? causeOfT.getCause() : null;
+ } while (causeOfT != null && causeOfT != t);
+ return false;
+ }
+
+ /**
+ * Checks if the given test throws an exception caused by
+ * VirtualMachineError with message "Out of space in CodeCache", and, if VME
+ * takes place, processes it so that no exception is thrown, and prints its
+ * stack trace. If test throws exception not caused by VME, this method just
+ * re-throws this exception.
+ *
+ * @param test - test to check for and process VirtualMachineError.
+ * @return - an exception caused by VME or null
+ * if test has thrown no exception.
+ * @throws Throwable - if test has thrown an exception
+ * that is not caused by VME.
+ */
+ public static Throwable runMHTest(Utils.ThrowingRunnable test) throws Throwable {
+ Throwable t = Utils.filterException(test::run,
+ CodeCacheOverflowProcessor::isThrowableCausedByVME);
+ if (t != null) {
+ System.err.printf("%nNon-critical exception caught becuse of"
+ + " code cache size is not enough to run all test cases.%n%n");
+ }
+ return t;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/invoke/common/test/java/lang/invoke/lib/Helper.java Fri May 26 22:53:26 2017 -0700
@@ -0,0 +1,351 @@
+/*
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test.java.lang.invoke.lib;
+
+import jdk.testlibrary.Asserts;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+
+public class Helper {
+ /** Flag for verbose output, true if {@code -Dverbose} specified */
+ public static final boolean IS_VERBOSE
+ = System.getProperty("verbose") != null;
+ /**
+ * Flag for thorough testing -- all test will be executed,
+ * true if {@code -Dthorough} specified. */
+ public static final boolean IS_THOROUGH
+ = System.getProperty("thorough") != null;
+ /** Random number generator w/ initial seed equal to {@code -Dseed} */
+ public static final Random RNG;
+
+ static {
+ String str = System.getProperty("seed");
+ long seed = str != null ? Long.parseLong(str) : new Random().nextLong();
+ RNG = new Random(seed);
+ System.out.printf("-Dseed=%d%n", seed);
+ }
+
+ public static final long TEST_LIMIT;
+ static {
+ String str = System.getProperty("testLimit");
+ TEST_LIMIT = str != null ? Long.parseUnsignedLong(str) : 2000L;
+ System.out.printf("-DtestLimit=%d%n", TEST_LIMIT);
+ }
+
+ public static final int MAX_ARITY = 254;
+ public static final String MISSING_ARG = "missingArg";
+ public static final String MISSING_ARG_2 = "missingArg#2";
+
+ private static final int
+ // first int value
+ ONE_MILLION = (1000 * 1000),
+ // scale factor to reach upper 32 bits
+ TEN_BILLION = (10 * 1000 * 1000 * 1000),
+ // <<1 makes space for sign bit;
+ INITIAL_ARG_VAL = ONE_MILLION << 1;
+
+ public static final MethodHandle AS_LIST;
+
+ static {
+ try {
+ AS_LIST = MethodHandles.lookup().findStatic(
+ Arrays.class, "asList",
+ MethodType.methodType(List.class, Object[].class));
+ } catch (NoSuchMethodException | IllegalAccessException ex) {
+ throw new Error(ex);
+ }
+ }
+
+ public static boolean isDoubleCost(Class<?> aClass) {
+ return aClass == double.class || aClass == long.class;
+ }
+
+ private static List<List<Object>> calledLog = new ArrayList<>();
+ private static long nextArgVal;
+
+ public static void assertCalled(String name, Object... args) {
+ assertCalled(0, name, args);
+ }
+
+ public static void assertCalled(int lag, String name, Object... args) {
+ Object expected = logEntry(name, args);
+ Object actual = getCalled(lag);
+ Asserts.assertEQ(expected, actual, "method call w/ lag = " + lag);
+ }
+
+ public static Object called(String name, Object... args) {
+ List<Object> entry = logEntry(name, args);
+ calledLog.add(entry);
+ return entry;
+ }
+
+ private static List<Object> logEntry(String name, Object... args) {
+ return Arrays.asList(name, Arrays.asList(args));
+ }
+
+ public static void clear() {
+ calledLog.clear();
+ }
+
+ public static List<Object> getCalled(int lag) {
+ int size = calledLog.size();
+ return size <= lag ? null : calledLog.get(size - lag - 1);
+ }
+
+ public static List<Class<?>> randomClasses(Class<?>[] classes, int size) {
+ List<Class<?>> result = new ArrayList<>(size);
+ for (int i = 0; i < size; ++i) {
+ result.add(classes[RNG.nextInt(classes.length)]);
+ }
+ return result;
+ }
+
+ public static List<Class<?>> getParams(List<Class<?>> classes,
+ boolean isVararg, int argsCount) {
+ boolean unmodifiable = true;
+ List<Class<?>> result = classes.subList(0,
+ Math.min(argsCount, (MAX_ARITY / 2) - 1));
+ int extra = 0;
+ if (argsCount >= MAX_ARITY / 2) {
+ result = new ArrayList<>(result);
+ unmodifiable = false;
+ extra = (int) result.stream().filter(Helper::isDoubleCost).count();
+ int i = result.size();
+ while (result.size() + extra < argsCount) {
+ Class<?> aClass = classes.get(i);
+ if (Helper.isDoubleCost(aClass)) {
+ ++extra;
+ if (result.size() + extra >= argsCount) {
+ break;
+ }
+ }
+ result.add(aClass);
+ }
+ }
+ if (isVararg && result.size() > 0) {
+ if (unmodifiable) {
+ result = new ArrayList<>(result);
+ }
+ int last = result.size() - 1;
+ Class<?> aClass = result.get(last);
+ aClass = Array.newInstance(aClass, 2).getClass();
+ result.set(last, aClass);
+ }
+ return result;
+ }
+
+ public static MethodHandle addTrailingArgs(MethodHandle target, int nargs,
+ List<Class<?>> classes) {
+ int targetLen = target.type().parameterCount();
+ int extra = (nargs - targetLen);
+ if (extra <= 0) {
+ return target;
+ }
+ List<Class<?>> fakeArgs = new ArrayList<>(extra);
+ for (int i = 0; i < extra; ++i) {
+ fakeArgs.add(classes.get(i % classes.size()));
+ }
+ return MethodHandles.dropArguments(target, targetLen, fakeArgs);
+ }
+
+ public static MethodHandle varargsList(int arity) {
+ return AS_LIST.asCollector(Object[].class, arity);
+ }
+
+ private static long nextArg(boolean moreBits) {
+ long val = nextArgVal++;
+ long sign = -(val & 1); // alternate signs
+ val >>= 1;
+ if (moreBits)
+ // Guarantee some bits in the high word.
+ // In any case keep the decimal representation simple-looking,
+ // with lots of zeroes, so as not to make the printed decimal
+ // strings unnecessarily noisy.
+ {
+ val += (val % ONE_MILLION) * TEN_BILLION;
+ }
+ return val ^ sign;
+ }
+
+ private static int nextArg() {
+ // Produce a 32-bit result something like ONE_MILLION+(smallint).
+ // Example: 1_000_042.
+ return (int) nextArg(false);
+ }
+
+ private static long nextArg(Class<?> kind) {
+ if (kind == long.class || kind == Long.class ||
+ kind == double.class || kind == Double.class)
+ // produce a 64-bit result something like
+ // ((TEN_BILLION+1) * (ONE_MILLION+(smallint)))
+ // Example: 10_000_420_001_000_042.
+ {
+ return nextArg(true);
+ }
+ return (long) nextArg();
+ }
+
+ private static Object randomArg(Class<?> param) {
+ Object wrap = castToWrapperOrNull(nextArg(param), param);
+ if (wrap != null) {
+ return wrap;
+ }
+
+ if (param.isInterface()) {
+ for (Class<?> c : param.getClasses()) {
+ if (param.isAssignableFrom(c) && !c.isInterface()) {
+ param = c;
+ break;
+ }
+ }
+ }
+ if (param.isArray()) {
+ Class<?> ctype = param.getComponentType();
+ Object arg = Array.newInstance(ctype, 2);
+ Array.set(arg, 0, randomArg(ctype));
+ return arg;
+ }
+ if (param.isInterface() && param.isAssignableFrom(List.class)) {
+ return Arrays.asList("#" + nextArg());
+ }
+ if (param.isInterface() || param.isAssignableFrom(String.class)) {
+ return "#" + nextArg();
+ }
+
+ try {
+ return param.newInstance();
+ } catch (InstantiationException | IllegalAccessException ex) {
+ }
+ return null; // random class not Object, String, Integer, etc.
+ }
+
+ public static Object[] randomArgs(Class<?>... params) {
+ Object[] args = new Object[params.length];
+ for (int i = 0; i < args.length; i++) {
+ args[i] = randomArg(params[i]);
+ }
+ return args;
+ }
+
+ public static Object[] randomArgs(int nargs, Class<?> param) {
+ Object[] args = new Object[nargs];
+ for (int i = 0; i < args.length; i++) {
+ args[i] = randomArg(param);
+ }
+ return args;
+ }
+
+ public static Object[] randomArgs(int nargs, Class<?>... params) {
+ Object[] args = new Object[nargs];
+ for (int i = 0; i < args.length; i++) {
+ Class<?> param = params[i % params.length];
+ args[i] = randomArg(param);
+ }
+ return args;
+ }
+
+ public static Object[] randomArgs(List<Class<?>> params) {
+ return randomArgs(params.toArray(new Class<?>[params.size()]));
+ }
+
+ public static Object castToWrapper(Object value, Class<?> dst) {
+ Object wrap = null;
+ if (value instanceof Number) {
+ wrap = castToWrapperOrNull(((Number) value).longValue(), dst);
+ }
+ if (value instanceof Character) {
+ wrap = castToWrapperOrNull((char) (Character) value, dst);
+ }
+ if (wrap != null) {
+ return wrap;
+ }
+ return dst.cast(value);
+ }
+
+ @SuppressWarnings("cast")
+ // primitive cast to (long) is part of the pattern
+ private static Object castToWrapperOrNull(long value, Class<?> dst) {
+ if (dst == int.class || dst == Integer.class) {
+ return (int) (value);
+ }
+ if (dst == long.class || dst == Long.class) {
+ return (long) (value);
+ }
+ if (dst == char.class || dst == Character.class) {
+ return (char) (value);
+ }
+ if (dst == short.class || dst == Short.class) {
+ return (short) (value);
+ }
+ if (dst == float.class || dst == Float.class) {
+ return (float) (value);
+ }
+ if (dst == double.class || dst == Double.class) {
+ return (double) (value);
+ }
+ if (dst == byte.class || dst == Byte.class) {
+ return (byte) (value);
+ }
+ if (dst == boolean.class || dst == Boolean.class) {
+ return ((value % 29) & 1) == 0;
+ }
+ return null;
+ }
+
+ /**
+ * Routine used to obtain a randomly generated method type.
+ *
+ * @param arity Arity of returned method type.
+ * @return MethodType generated randomly.
+ */
+ public static MethodType randomMethodTypeGenerator(int arity) {
+ final Class<?>[] CLASSES = {
+ Object.class,
+ int.class,
+ boolean.class,
+ byte.class,
+ short.class,
+ char.class,
+ long.class,
+ float.class,
+ double.class
+ };
+ if (arity > MAX_ARITY) {
+ throw new IllegalArgumentException(
+ String.format("Arity should not exceed %d!", MAX_ARITY));
+ }
+ List<Class<?>> list = randomClasses(CLASSES, arity);
+ list = getParams(list, false, arity);
+ int i = RNG.nextInt(CLASSES.length + 1);
+ Class<?> rtype = i == CLASSES.length ? void.class : CLASSES[i];
+ return MethodType.methodType(rtype, list);
+ }
+}
--- a/jdk/test/lib/testlibrary/jsr292/com/oracle/testlibrary/jsr292/CodeCacheOverflowProcessor.java Fri May 26 22:30:19 2017 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.testlibrary.jsr292;
-
-import jdk.testlibrary.Utils;
-
-/**
- * Helper class used to catch and process VirtualMachineError with message "Out
- * of space in CodeCache". Some JSR292 tests run out of code cache size, so code
- * cache overflows and VME is thrown. This VME is considered as non-critical in
- * some JSR292 tests, so it should be processed to prevent test failure.
- */
-public class CodeCacheOverflowProcessor {
-
- /**
- * Checks if an instance of Throwable is caused by VirtualMachineError with
- * message "Out of space in CodeCache". May be used as filter in method
- * {@code jdk.testlibrary.Utils.filterException}.
- *
- * @param t - Throwable to check.
- * @return true if Throwable is caused by VME, false otherwise.
- */
- public static Boolean isThrowableCausedByVME(Throwable t) {
- Throwable causeOfT = t;
- do {
- if (causeOfT instanceof VirtualMachineError
- && causeOfT.getMessage().matches(".*[Oo]ut of space"
- + " in CodeCache.*")) {
- return true;
- }
- causeOfT = causeOfT != null ? causeOfT.getCause() : null;
- } while (causeOfT != null && causeOfT != t);
- return false;
- }
-
- /**
- * Checks if the given test throws an exception caused by
- * VirtualMachineError with message "Out of space in CodeCache", and, if VME
- * takes place, processes it so that no exception is thrown, and prints its
- * stack trace. If test throws exception not caused by VME, this method just
- * re-throws this exception.
- *
- * @param test - test to check for and process VirtualMachineError.
- * @return - an exception caused by VME or null
- * if test has thrown no exception.
- * @throws Throwable - if test has thrown an exception
- * that is not caused by VME.
- */
- public static Throwable runMHTest(Utils.ThrowingRunnable test) throws Throwable {
- Throwable t = Utils.filterException(test::run,
- CodeCacheOverflowProcessor::isThrowableCausedByVME);
- if (t != null) {
- System.err.printf("%nNon-critical exception caught becuse of"
- + " code cache size is not enough to run all test cases.%n%n");
- }
- return t;
- }
-}
--- a/jdk/test/lib/testlibrary/jsr292/com/oracle/testlibrary/jsr292/Helper.java Fri May 26 22:30:19 2017 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,347 +0,0 @@
-/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.testlibrary.jsr292;
-
-import jdk.testlibrary.Asserts;
-
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
-import java.lang.reflect.Array;
-import java.util.*;
-
-public class Helper {
- /** Flag for verbose output, true if {@code -Dverbose} specified */
- public static final boolean IS_VERBOSE
- = System.getProperty("verbose") != null;
- /**
- * Flag for thorough testing -- all test will be executed,
- * true if {@code -Dthorough} specified. */
- public static final boolean IS_THOROUGH
- = System.getProperty("thorough") != null;
- /** Random number generator w/ initial seed equal to {@code -Dseed} */
- public static final Random RNG;
-
- static {
- String str = System.getProperty("seed");
- long seed = str != null ? Long.parseLong(str) : new Random().nextLong();
- RNG = new Random(seed);
- System.out.printf("-Dseed=%d%n", seed);
- }
-
- public static final long TEST_LIMIT;
- static {
- String str = System.getProperty("testLimit");
- TEST_LIMIT = str != null ? Long.parseUnsignedLong(str) : 2000L;
- System.out.printf("-DtestLimit=%d%n", TEST_LIMIT);
- }
-
- public static final int MAX_ARITY = 254;
- public static final String MISSING_ARG = "missingArg";
- public static final String MISSING_ARG_2 = "missingArg#2";
-
- private static final int
- // first int value
- ONE_MILLION = (1000 * 1000),
- // scale factor to reach upper 32 bits
- TEN_BILLION = (10 * 1000 * 1000 * 1000),
- // <<1 makes space for sign bit;
- INITIAL_ARG_VAL = ONE_MILLION << 1;
-
- public static final MethodHandle AS_LIST;
-
- static {
- try {
- AS_LIST = MethodHandles.lookup().findStatic(
- Arrays.class, "asList",
- MethodType.methodType(List.class, Object[].class));
- } catch (NoSuchMethodException | IllegalAccessException ex) {
- throw new Error(ex);
- }
- }
-
- public static boolean isDoubleCost(Class<?> aClass) {
- return aClass == double.class || aClass == long.class;
- }
-
- private static List<List<Object>> calledLog = new ArrayList<>();
- private static long nextArgVal;
-
- public static void assertCalled(String name, Object... args) {
- assertCalled(0, name, args);
- }
-
- public static void assertCalled(int lag, String name, Object... args) {
- Object expected = logEntry(name, args);
- Object actual = getCalled(lag);
- Asserts.assertEQ(expected, actual, "method call w/ lag = " + lag);
- }
-
- public static Object called(String name, Object... args) {
- List<Object> entry = logEntry(name, args);
- calledLog.add(entry);
- return entry;
- }
-
- private static List<Object> logEntry(String name, Object... args) {
- return Arrays.asList(name, Arrays.asList(args));
- }
-
- public static void clear() {
- calledLog.clear();
- }
-
- public static List<Object> getCalled(int lag) {
- int size = calledLog.size();
- return size <= lag ? null : calledLog.get(size - lag - 1);
- }
-
- public static List<Class<?>> randomClasses(Class<?>[] classes, int size) {
- List<Class<?>> result = new ArrayList<>(size);
- for (int i = 0; i < size; ++i) {
- result.add(classes[RNG.nextInt(classes.length)]);
- }
- return result;
- }
-
- public static List<Class<?>> getParams(List<Class<?>> classes,
- boolean isVararg, int argsCount) {
- boolean unmodifiable = true;
- List<Class<?>> result = classes.subList(0,
- Math.min(argsCount, (MAX_ARITY / 2) - 1));
- int extra = 0;
- if (argsCount >= MAX_ARITY / 2) {
- result = new ArrayList<>(result);
- unmodifiable = false;
- extra = (int) result.stream().filter(Helper::isDoubleCost).count();
- int i = result.size();
- while (result.size() + extra < argsCount) {
- Class<?> aClass = classes.get(i);
- if (Helper.isDoubleCost(aClass)) {
- ++extra;
- if (result.size() + extra >= argsCount) {
- break;
- }
- }
- result.add(aClass);
- }
- }
- if (isVararg && result.size() > 0) {
- if (unmodifiable) {
- result = new ArrayList<>(result);
- }
- int last = result.size() - 1;
- Class<?> aClass = result.get(last);
- aClass = Array.newInstance(aClass, 2).getClass();
- result.set(last, aClass);
- }
- return result;
- }
-
- public static MethodHandle addTrailingArgs(MethodHandle target, int nargs,
- List<Class<?>> classes) {
- int targetLen = target.type().parameterCount();
- int extra = (nargs - targetLen);
- if (extra <= 0) {
- return target;
- }
- List<Class<?>> fakeArgs = new ArrayList<>(extra);
- for (int i = 0; i < extra; ++i) {
- fakeArgs.add(classes.get(i % classes.size()));
- }
- return MethodHandles.dropArguments(target, targetLen, fakeArgs);
- }
-
- public static MethodHandle varargsList(int arity) {
- return AS_LIST.asCollector(Object[].class, arity);
- }
-
- private static long nextArg(boolean moreBits) {
- long val = nextArgVal++;
- long sign = -(val & 1); // alternate signs
- val >>= 1;
- if (moreBits)
- // Guarantee some bits in the high word.
- // In any case keep the decimal representation simple-looking,
- // with lots of zeroes, so as not to make the printed decimal
- // strings unnecessarily noisy.
- {
- val += (val % ONE_MILLION) * TEN_BILLION;
- }
- return val ^ sign;
- }
-
- private static int nextArg() {
- // Produce a 32-bit result something like ONE_MILLION+(smallint).
- // Example: 1_000_042.
- return (int) nextArg(false);
- }
-
- private static long nextArg(Class<?> kind) {
- if (kind == long.class || kind == Long.class ||
- kind == double.class || kind == Double.class)
- // produce a 64-bit result something like
- // ((TEN_BILLION+1) * (ONE_MILLION+(smallint)))
- // Example: 10_000_420_001_000_042.
- {
- return nextArg(true);
- }
- return (long) nextArg();
- }
-
- private static Object randomArg(Class<?> param) {
- Object wrap = castToWrapperOrNull(nextArg(param), param);
- if (wrap != null) {
- return wrap;
- }
-
- if (param.isInterface()) {
- for (Class<?> c : param.getClasses()) {
- if (param.isAssignableFrom(c) && !c.isInterface()) {
- param = c;
- break;
- }
- }
- }
- if (param.isArray()) {
- Class<?> ctype = param.getComponentType();
- Object arg = Array.newInstance(ctype, 2);
- Array.set(arg, 0, randomArg(ctype));
- return arg;
- }
- if (param.isInterface() && param.isAssignableFrom(List.class)) {
- return Arrays.asList("#" + nextArg());
- }
- if (param.isInterface() || param.isAssignableFrom(String.class)) {
- return "#" + nextArg();
- }
-
- try {
- return param.newInstance();
- } catch (InstantiationException | IllegalAccessException ex) {
- }
- return null; // random class not Object, String, Integer, etc.
- }
-
- public static Object[] randomArgs(Class<?>... params) {
- Object[] args = new Object[params.length];
- for (int i = 0; i < args.length; i++) {
- args[i] = randomArg(params[i]);
- }
- return args;
- }
-
- public static Object[] randomArgs(int nargs, Class<?> param) {
- Object[] args = new Object[nargs];
- for (int i = 0; i < args.length; i++) {
- args[i] = randomArg(param);
- }
- return args;
- }
-
- public static Object[] randomArgs(int nargs, Class<?>... params) {
- Object[] args = new Object[nargs];
- for (int i = 0; i < args.length; i++) {
- Class<?> param = params[i % params.length];
- args[i] = randomArg(param);
- }
- return args;
- }
-
- public static Object[] randomArgs(List<Class<?>> params) {
- return randomArgs(params.toArray(new Class<?>[params.size()]));
- }
-
- public static Object castToWrapper(Object value, Class<?> dst) {
- Object wrap = null;
- if (value instanceof Number) {
- wrap = castToWrapperOrNull(((Number) value).longValue(), dst);
- }
- if (value instanceof Character) {
- wrap = castToWrapperOrNull((char) (Character) value, dst);
- }
- if (wrap != null) {
- return wrap;
- }
- return dst.cast(value);
- }
-
- @SuppressWarnings("cast")
- // primitive cast to (long) is part of the pattern
- private static Object castToWrapperOrNull(long value, Class<?> dst) {
- if (dst == int.class || dst == Integer.class) {
- return (int) (value);
- }
- if (dst == long.class || dst == Long.class) {
- return (long) (value);
- }
- if (dst == char.class || dst == Character.class) {
- return (char) (value);
- }
- if (dst == short.class || dst == Short.class) {
- return (short) (value);
- }
- if (dst == float.class || dst == Float.class) {
- return (float) (value);
- }
- if (dst == double.class || dst == Double.class) {
- return (double) (value);
- }
- if (dst == byte.class || dst == Byte.class) {
- return (byte) (value);
- }
- if (dst == boolean.class || dst == Boolean.class) {
- return ((value % 29) & 1) == 0;
- }
- return null;
- }
-
- /**
- * Routine used to obtain a randomly generated method type.
- *
- * @param arity Arity of returned method type.
- * @return MethodType generated randomly.
- */
- public static MethodType randomMethodTypeGenerator(int arity) {
- final Class<?>[] CLASSES = {
- Object.class,
- int.class,
- boolean.class,
- byte.class,
- short.class,
- char.class,
- long.class,
- float.class,
- double.class
- };
- if (arity > MAX_ARITY) {
- throw new IllegalArgumentException(
- String.format("Arity should not exceed %d!", MAX_ARITY));
- }
- List<Class<?>> list = randomClasses(CLASSES, arity);
- list = getParams(list, false, arity);
- int i = RNG.nextInt(CLASSES.length + 1);
- Class<?> rtype = i == CLASSES.length ? void.class : CLASSES[i];
- return MethodType.methodType(rtype, list);
- }
-}