8180890: move c.o.testlibrary.jsr292 classes to jdk/test/java/lang/invoke directory

Reviewed-by: rriggs
This commit is contained in:
Igor Ignatyev 2017-05-26 22:53:26 -07:00
parent da6d0e38ee
commit 2bed581331
13 changed files with 622 additions and 524 deletions

View file

@ -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.lang.invoke.WrongMethodTypeException;
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 @@ public class ExplicitCastArgumentsTest {
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,

View file

@ -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;

View file

@ -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 @@ public final class LFMultiThreadCachingTest extends LFCachingTestCase {
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 @@ public final class LFMultiThreadCachingTest extends LFCachingTestCase {
* @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));
}
}

View file

@ -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 @@ public final class LFSingleThreadCachingTest extends LFCachingTestCase {
* @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));
}
}

View file

@ -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.lang.reflect.Method;
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 @@ import jdk.testlibrary.TimeLimitedRunner;
*/
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 @@ public abstract class LambdaFormTestCase {
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 @@ public abstract class LambdaFormTestCase {
* 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) {

View file

@ -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;
@ -55,14 +56,16 @@ public enum TestMethods {
if (realArity == 0) {
combinerReturnType = void.class;
} else {
combinerReturnType = Helper.RNG.nextBoolean() ? void.class : mtTarget.parameterType(0);
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 {
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");
@ -97,7 +100,8 @@ public enum TestMethods {
}
@Override
protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
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");
@ -138,7 +142,8 @@ public enum TestMethods {
}
@Override
protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
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(),
@ -165,7 +170,8 @@ public enum TestMethods {
}
@Override
protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
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");
@ -197,7 +203,8 @@ public enum TestMethods {
}
@Override
protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
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(),
@ -226,7 +233,8 @@ public enum TestMethods {
}
@Override
protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
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");
@ -262,7 +270,8 @@ public enum TestMethods {
}
@Override
protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
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");
@ -304,7 +313,8 @@ public enum TestMethods {
}
@Override
protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
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;
@ -340,7 +350,8 @@ public enum TestMethods {
}
@Override
protected MethodHandle getMH(Map<String, Object> data, TestMethods.Kind kind) throws NoSuchMethodException, IllegalAccessException {
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;
@ -477,7 +488,7 @@ public enum TestMethods {
}
}
},
IDENTITY("identity") {
IDENTITY("identity") {
@Override
public Map<String, Object> getTestCaseData() {
Map<String, Object> data = new HashMap<>();
@ -514,8 +525,10 @@ public enum TestMethods {
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 @@ public enum TestMethods {
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));

View file

@ -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 @@ public class CatchExceptionTest {
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 @@ class TestCase<T> {
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()) {

View file

@ -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 test.java.lang.invoke.remote.RemoteExample;
import java.lang.invoke.*;
import static java.lang.invoke.MethodType.methodType;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.reflect.*;
import java.util.*;
import org.junit.*;
import static org.junit.Assert.*;
import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
import test.java.lang.invoke.lib.CodeCacheOverflowProcessor;
import test.java.lang.invoke.remote.RemoteExample;
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.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.*;
/**
*

View file

@ -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 org.testng.annotations.Test;
import test.java.lang.invoke.lib.CodeCacheOverflowProcessor;
import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
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.util.*;
import java.lang.reflect.*;
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 @@ public class PermuteArgsTest {
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 @@ public class PermuteArgsTest {
}
}
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 @@ public class PermuteArgsTest {
}
}
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 @@ public class PermuteArgsTest {
}
}
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;

View file

@ -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 class TestCatchExceptionWithVarargs {
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 @@ public class TestCatchExceptionWithVarargs {
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);
}
}
}

View file

@ -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 @@ import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
*/
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 @@ public class VarargsArrayTest {
}
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) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* 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
@ -20,7 +20,8 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.testlibrary.jsr292;
package test.java.lang.invoke.lib;
import jdk.testlibrary.Utils;

View file

@ -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,7 +20,8 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.testlibrary.jsr292;
package test.java.lang.invoke.lib;
import jdk.testlibrary.Asserts;
@ -28,7 +29,10 @@ 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.List;
import java.util.Random;
public class Helper {
/** Flag for verbose output, true if {@code -Dverbose} specified */