提交 58da4ffd 编写于 作者: K kshefov

8067005: Several java/lang/invoke tests fail due to exhausted code cache

Reviewed-by: vlivanov
上级 708c6548
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
package test.java.lang.invoke.MethodHandles; package test.java.lang.invoke.MethodHandles;
import com.oracle.testlibrary.jsr292.Helper; import com.oracle.testlibrary.jsr292.Helper;
import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
import jdk.testlibrary.Asserts; import jdk.testlibrary.Asserts;
import jdk.testlibrary.TimeLimitedRunner; import jdk.testlibrary.TimeLimitedRunner;
import jdk.testlibrary.Utils; import jdk.testlibrary.Utils;
...@@ -35,15 +36,14 @@ import java.util.*; ...@@ -35,15 +36,14 @@ import java.util.*;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.concurrent.TimeUnit;
/* @test /* @test
* @library /lib/testlibrary/jsr292 /lib/testlibrary/ * @library /lib/testlibrary/jsr292 /lib/testlibrary/
* @compile CatchExceptionTest.java * @compile CatchExceptionTest.java
* @build jdk.testlibrary.*
* @run main/othervm -esa test.java.lang.invoke.MethodHandles.CatchExceptionTest * @run main/othervm -esa test.java.lang.invoke.MethodHandles.CatchExceptionTest
*/ */
public class CatchExceptionTest { public class CatchExceptionTest {
private static final List<Class<?>> ARGS_CLASSES; private static final List<Class<?>> ARGS_CLASSES;
protected static final int MAX_ARITY = Helper.MAX_ARITY - 1; protected static final int MAX_ARITY = Helper.MAX_ARITY - 1;
...@@ -91,8 +91,11 @@ public class CatchExceptionTest { ...@@ -91,8 +91,11 @@ public class CatchExceptionTest {
} }
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
System.out.println("classes = " + ARGS_CLASSES); CodeCacheOverflowProcessor.runMHTest(CatchExceptionTest::test);
}
public static void test() throws Throwable {
System.out.println("classes = " + ARGS_CLASSES);
TestFactory factory = new TestFactory(); TestFactory factory = new TestFactory();
long timeout = Helper.IS_THOROUGH ? 0L : Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT); long timeout = Helper.IS_THOROUGH ? 0L : Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT);
// subtract vm init time and reserve time for vm exit // subtract vm init time and reserve time for vm exit
...@@ -116,7 +119,6 @@ public class CatchExceptionTest { ...@@ -116,7 +119,6 @@ public class CatchExceptionTest {
return Helper.getParams(ARGS_CLASSES, isVararg, argsCount); return Helper.getParams(ARGS_CLASSES, isVararg, argsCount);
} }
private List<Class<?>> getCatcherParams() { private List<Class<?>> getCatcherParams() {
int catchArgc = 1 + this.argsCount - dropped; int catchArgc = 1 + this.argsCount - dropped;
List<Class<?>> result = new ArrayList<>( List<Class<?>> result = new ArrayList<>(
...@@ -128,9 +130,10 @@ public class CatchExceptionTest { ...@@ -128,9 +130,10 @@ public class CatchExceptionTest {
private void runTest() { private void runTest() {
if (Helper.IS_VERBOSE) { if (Helper.IS_VERBOSE) {
System.out.printf("CatchException(%s, isVararg=%b argsCount=%d " + System.out.printf("CatchException(%s, isVararg=%b argsCount=%d "
"dropped=%d)%n", + "dropped=%d)%n",
testCase, thrower.isVarargsCollector(), argsCount, dropped); testCase, thrower.isVarargsCollector(),
argsCount, dropped);
} }
Helper.clear(); Helper.clear();
...@@ -186,7 +189,7 @@ class TestFactory { ...@@ -186,7 +189,7 @@ class TestFactory {
{CatchExceptionTest.MAX_ARITY, 0}, {CatchExceptionTest.MAX_ARITY, 0},
{CatchExceptionTest.MAX_ARITY, CatchExceptionTest.MAX_ARITY}, {CatchExceptionTest.MAX_ARITY, CatchExceptionTest.MAX_ARITY},
}) { }) {
MANDATORY_TEST_CASES.addAll(createTests(args[0], args[1])); MANDATORY_TEST_CASES.addAll(createTests(args[0], args[1]));
} }
} }
...@@ -241,8 +244,9 @@ class TestFactory { ...@@ -241,8 +244,9 @@ class TestFactory {
} }
/** /**
* @return next test from test matrix: * @return next test from test matrix: {varArgs, noVarArgs} x
* {varArgs, noVarArgs} x TestCase.rtypes x TestCase.THROWABLES x {1, .., maxArgs } x {0, .., maxDrops} * TestCase.rtypes x TestCase.THROWABLES x {1, .., maxArgs } x
* {0, .., maxDrops}
*/ */
public CatchExceptionTest nextTest() { public CatchExceptionTest nextTest() {
if (constructor < constructorSize) { if (constructor < constructorSize) {
...@@ -285,17 +289,17 @@ class TestFactory { ...@@ -285,17 +289,17 @@ class TestFactory {
TestCase.CONSTRUCTORS.get(constructor++).get(), TestCase.CONSTRUCTORS.get(constructor++).get(),
Helper.RNG.nextBoolean(), args, dropArgs); Helper.RNG.nextBoolean(), args, dropArgs);
} else { } else {
if (isVararg) { if (isVararg) {
isVararg = false; isVararg = false;
return new CatchExceptionTest( return new CatchExceptionTest(
TestCase.CONSTRUCTORS.get(constructor++).get(), TestCase.CONSTRUCTORS.get(constructor++).get(),
isVararg, args, dropArgs); isVararg, args, dropArgs);
} else { } else {
isVararg = true; isVararg = true;
return new CatchExceptionTest( return new CatchExceptionTest(
TestCase.CONSTRUCTORS.get(constructor).get(), TestCase.CONSTRUCTORS.get(constructor).get(),
isVararg, args, dropArgs); isVararg, args, dropArgs);
} }
} }
} }
} }
...@@ -423,7 +427,7 @@ class TestCase<T> { ...@@ -423,7 +427,7 @@ class TestCase<T> {
} }
private static <T extends Throwable> private static <T extends Throwable>
Object throwOrReturn(Object normal, T exception) throws T { Object throwOrReturn(Object normal, T exception) throws T {
if (exception != null) { if (exception != null) {
Helper.called("throwOrReturn/throw", normal, exception); Helper.called("throwOrReturn/throw", normal, exception);
throw exception; throw exception;
...@@ -432,8 +436,7 @@ class TestCase<T> { ...@@ -432,8 +436,7 @@ class TestCase<T> {
return normal; return normal;
} }
private static <T extends Throwable> private static <T extends Throwable> Object catcher(Object o) {
Object catcher(Object o) {
Helper.called("catcher", o); Helper.called("catcher", o);
return o; return o;
} }
...@@ -444,7 +447,7 @@ class TestCase<T> { ...@@ -444,7 +447,7 @@ class TestCase<T> {
public MethodHandle getCatcher(List<Class<?>> classes) { public MethodHandle getCatcher(List<Class<?>> classes) {
return MethodHandles.filterReturnValue(Helper.AS_LIST.asType( return MethodHandles.filterReturnValue(Helper.AS_LIST.asType(
MethodType.methodType(Object.class, classes)), MethodType.methodType(Object.class, classes)),
CATCHER CATCHER
); );
} }
......
/* /*
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
/* @test /* @test
* @summary unit tests for java.lang.invoke.MethodHandles * @summary unit tests for java.lang.invoke.MethodHandles
* @library /lib/testlibrary /lib/testlibrary/jsr292
* @compile MethodHandlesTest.java remote/RemoteExample.java * @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
*/ */
...@@ -36,6 +37,7 @@ import java.lang.reflect.*; ...@@ -36,6 +37,7 @@ import java.lang.reflect.*;
import java.util.*; import java.util.*;
import org.junit.*; import org.junit.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
/** /**
...@@ -499,6 +501,10 @@ public class MethodHandlesTest { ...@@ -499,6 +501,10 @@ public class MethodHandlesTest {
@Test @Test
public void testFindStatic() throws Throwable { public void testFindStatic() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testFindStatic0);
}
public void testFindStatic0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("findStatic"); startTest("findStatic");
testFindStatic(PubExample.class, void.class, "s0"); testFindStatic(PubExample.class, void.class, "s0");
...@@ -586,6 +592,10 @@ public class MethodHandlesTest { ...@@ -586,6 +592,10 @@ public class MethodHandlesTest {
@Test @Test
public void testFindVirtual() throws Throwable { public void testFindVirtual() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testFindVirtual0);
}
public void testFindVirtual0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("findVirtual"); startTest("findVirtual");
testFindVirtual(Example.class, void.class, "v0"); testFindVirtual(Example.class, void.class, "v0");
...@@ -616,6 +626,10 @@ public class MethodHandlesTest { ...@@ -616,6 +626,10 @@ public class MethodHandlesTest {
@Test @Test
public void testFindVirtualClone() throws Throwable { public void testFindVirtualClone() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testFindVirtualClone0);
}
public void testFindVirtualClone0() throws Throwable {
// test some ad hoc system methods // test some ad hoc system methods
testFindVirtual(false, PUBLIC, Object.class, Object.class, "clone"); testFindVirtual(false, PUBLIC, Object.class, Object.class, "clone");
testFindVirtual(true, PUBLIC, Object[].class, Object.class, "clone"); testFindVirtual(true, PUBLIC, Object[].class, Object.class, "clone");
...@@ -699,6 +713,10 @@ public class MethodHandlesTest { ...@@ -699,6 +713,10 @@ public class MethodHandlesTest {
@Test @Test
public void testFindSpecial() throws Throwable { public void testFindSpecial() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testFindSpecial0);
}
public void testFindSpecial0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("findSpecial"); startTest("findSpecial");
testFindSpecial(SubExample.class, Example.class, void.class, "v0"); testFindSpecial(SubExample.class, Example.class, void.class, "v0");
...@@ -775,6 +793,10 @@ public class MethodHandlesTest { ...@@ -775,6 +793,10 @@ public class MethodHandlesTest {
@Test @Test
public void testFindConstructor() throws Throwable { public void testFindConstructor() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testFindConstructor0);
}
public void testFindConstructor0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("findConstructor"); startTest("findConstructor");
testFindConstructor(true, EXAMPLE, Example.class); testFindConstructor(true, EXAMPLE, Example.class);
...@@ -818,6 +840,10 @@ public class MethodHandlesTest { ...@@ -818,6 +840,10 @@ public class MethodHandlesTest {
@Test @Test
public void testBind() throws Throwable { public void testBind() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testBind0);
}
public void testBind0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("bind"); startTest("bind");
testBind(Example.class, void.class, "v0"); testBind(Example.class, void.class, "v0");
...@@ -879,6 +905,10 @@ public class MethodHandlesTest { ...@@ -879,6 +905,10 @@ public class MethodHandlesTest {
@Test @Test
public void testUnreflect() throws Throwable { public void testUnreflect() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testUnreflect0);
}
public void testUnreflect0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("unreflect"); startTest("unreflect");
testUnreflect(Example.class, true, void.class, "s0"); testUnreflect(Example.class, true, void.class, "s0");
...@@ -985,6 +1015,10 @@ public class MethodHandlesTest { ...@@ -985,6 +1015,10 @@ public class MethodHandlesTest {
@Test @Test
public void testUnreflectSpecial() throws Throwable { public void testUnreflectSpecial() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testUnreflectSpecial0);
}
public void testUnreflectSpecial0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("unreflectSpecial"); startTest("unreflectSpecial");
testUnreflectSpecial(Example.class, Example.class, void.class, "v0"); testUnreflectSpecial(Example.class, Example.class, void.class, "v0");
...@@ -1077,23 +1111,38 @@ public class MethodHandlesTest { ...@@ -1077,23 +1111,38 @@ public class MethodHandlesTest {
@Test @Test
public void testUnreflectGetter() throws Throwable { public void testUnreflectGetter() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testUnreflectGetter0);
}
public void testUnreflectGetter0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("unreflectGetter"); startTest("unreflectGetter");
testGetter(TEST_UNREFLECT); testGetter(TEST_UNREFLECT);
} }
@Test @Test
public void testFindGetter() throws Throwable { public void testFindGetter() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testFindGetter0);
}
public void testFindGetter0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("findGetter"); startTest("findGetter");
testGetter(TEST_FIND_FIELD); testGetter(TEST_FIND_FIELD);
testGetter(TEST_FIND_FIELD | TEST_BOUND); testGetter(TEST_FIND_FIELD | TEST_BOUND);
} }
@Test @Test
public void testFindStaticGetter() throws Throwable { public void testFindStaticGetter() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testFindStaticGetter0);
}
public void testFindStaticGetter0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("findStaticGetter"); startTest("findStaticGetter");
testGetter(TEST_FIND_STATIC); testGetter(TEST_FIND_STATIC);
} }
public void testGetter(int testMode) throws Throwable { public void testGetter(int testMode) throws Throwable {
Lookup lookup = PRIVATE; // FIXME: test more lookups than this one Lookup lookup = PRIVATE; // FIXME: test more lookups than this one
for (Object[] c : HasFields.CASES) { for (Object[] c : HasFields.CASES) {
...@@ -1287,26 +1336,40 @@ public class MethodHandlesTest { ...@@ -1287,26 +1336,40 @@ public class MethodHandlesTest {
} }
} }
@Test @Test
public void testUnreflectSetter() throws Throwable { public void testUnreflectSetter() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testUnreflectSetter0);
}
public void testUnreflectSetter0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("unreflectSetter"); startTest("unreflectSetter");
testSetter(TEST_UNREFLECT); testSetter(TEST_UNREFLECT);
} }
@Test @Test
public void testFindSetter() throws Throwable { public void testFindSetter() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testFindSetter0);
}
public void testFindSetter0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("findSetter"); startTest("findSetter");
testSetter(TEST_FIND_FIELD); testSetter(TEST_FIND_FIELD);
testSetter(TEST_FIND_FIELD | TEST_BOUND); testSetter(TEST_FIND_FIELD | TEST_BOUND);
} }
@Test @Test
public void testFindStaticSetter() throws Throwable { public void testFindStaticSetter() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testFindStaticSetter0);
}
public void testFindStaticSetter0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("findStaticSetter"); startTest("findStaticSetter");
testSetter(TEST_FIND_STATIC); testSetter(TEST_FIND_STATIC);
} }
public void testSetter(int testMode) throws Throwable { public void testSetter(int testMode) throws Throwable {
Lookup lookup = PRIVATE; // FIXME: test more lookups than this one Lookup lookup = PRIVATE; // FIXME: test more lookups than this one
startTest("unreflectSetter"); startTest("unreflectSetter");
...@@ -1329,6 +1392,10 @@ public class MethodHandlesTest { ...@@ -1329,6 +1392,10 @@ public class MethodHandlesTest {
@Test @Test
public void testArrayElementGetter() throws Throwable { public void testArrayElementGetter() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testArrayElementGetter0);
}
public void testArrayElementGetter0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("arrayElementGetter"); startTest("arrayElementGetter");
testArrayElementGetterSetter(false); testArrayElementGetterSetter(false);
...@@ -1336,6 +1403,10 @@ public class MethodHandlesTest { ...@@ -1336,6 +1403,10 @@ public class MethodHandlesTest {
@Test @Test
public void testArrayElementSetter() throws Throwable { public void testArrayElementSetter() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testArrayElementSetter0);
}
public void testArrayElementSetter0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("arrayElementSetter"); startTest("arrayElementSetter");
testArrayElementGetterSetter(true); testArrayElementGetterSetter(true);
...@@ -1349,6 +1420,10 @@ public class MethodHandlesTest { ...@@ -1349,6 +1420,10 @@ public class MethodHandlesTest {
@Test @Test
public void testArrayElementErrors() throws Throwable { public void testArrayElementErrors() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testArrayElementErrors0);
}
public void testArrayElementErrors0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("arrayElementErrors"); startTest("arrayElementErrors");
testArrayElementGetterSetter(false, TEST_ARRAY_NPE); testArrayElementGetterSetter(false, TEST_ARRAY_NPE);
...@@ -1528,6 +1603,10 @@ public class MethodHandlesTest { ...@@ -1528,6 +1603,10 @@ public class MethodHandlesTest {
@Test @Test
public void testConvertArguments() throws Throwable { public void testConvertArguments() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testConvertArguments0);
}
public void testConvertArguments0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("convertArguments"); startTest("convertArguments");
testConvert(Callee.ofType(1), null, "id", int.class); testConvert(Callee.ofType(1), null, "id", int.class);
...@@ -1591,6 +1670,10 @@ public class MethodHandlesTest { ...@@ -1591,6 +1670,10 @@ public class MethodHandlesTest {
@Test @Test
public void testVarargsCollector() throws Throwable { public void testVarargsCollector() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testVarargsCollector0);
}
public void testVarargsCollector0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("varargsCollector"); startTest("varargsCollector");
MethodHandle vac0 = PRIVATE.findStatic(MethodHandlesTest.class, "called", MethodHandle vac0 = PRIVATE.findStatic(MethodHandlesTest.class, "called",
...@@ -1605,8 +1688,12 @@ public class MethodHandlesTest { ...@@ -1605,8 +1688,12 @@ public class MethodHandlesTest {
} }
} }
@Test // SLOW @Test // SLOW
public void testPermuteArguments() throws Throwable { public void testPermuteArguments() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testPermuteArguments0);
}
public void testPermuteArguments0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("permuteArguments"); startTest("permuteArguments");
testPermuteArguments(4, Integer.class, 2, long.class, 6); testPermuteArguments(4, Integer.class, 2, long.class, 6);
...@@ -1744,8 +1831,12 @@ public class MethodHandlesTest { ...@@ -1744,8 +1831,12 @@ public class MethodHandlesTest {
} }
@Test // SLOW @Test // SLOW
public void testSpreadArguments() throws Throwable { public void testSpreadArguments() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testSpreadArguments0);
}
public void testSpreadArguments0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("spreadArguments"); startTest("spreadArguments");
for (Class<?> argType : new Class<?>[]{Object.class, Integer.class, int.class}) { for (Class<?> argType : new Class<?>[]{Object.class, Integer.class, int.class}) {
...@@ -1838,8 +1929,12 @@ public class MethodHandlesTest { ...@@ -1838,8 +1929,12 @@ public class MethodHandlesTest {
} }
} }
@Test // SLOW @Test // SLOW
public void testAsCollector() throws Throwable { public void testAsCollector() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testAsCollector0);
}
public void testAsCollector0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("asCollector"); startTest("asCollector");
for (Class<?> argType : new Class<?>[]{Object.class, Integer.class, int.class}) { for (Class<?> argType : new Class<?>[]{Object.class, Integer.class, int.class}) {
...@@ -1880,8 +1975,12 @@ public class MethodHandlesTest { ...@@ -1880,8 +1975,12 @@ public class MethodHandlesTest {
assertArrayEquals(collectedArgs, returnValue); assertArrayEquals(collectedArgs, returnValue);
} }
@Test // SLOW @Test // SLOW
public void testInsertArguments() throws Throwable { public void testInsertArguments() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testInsertArguments0);
}
public void testInsertArguments0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("insertArguments"); startTest("insertArguments");
for (int nargs = 0; nargs < 50; nargs++) { for (int nargs = 0; nargs < 50; nargs++) {
...@@ -1923,6 +2022,10 @@ public class MethodHandlesTest { ...@@ -1923,6 +2022,10 @@ public class MethodHandlesTest {
@Test @Test
public void testFilterReturnValue() throws Throwable { public void testFilterReturnValue() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testFilterReturnValue0);
}
public void testFilterReturnValue0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("filterReturnValue"); startTest("filterReturnValue");
Class<?> classOfVCList = varargsList(1).invokeWithArguments(0).getClass(); Class<?> classOfVCList = varargsList(1).invokeWithArguments(0).getClass();
...@@ -1972,6 +2075,10 @@ public class MethodHandlesTest { ...@@ -1972,6 +2075,10 @@ public class MethodHandlesTest {
@Test @Test
public void testFilterArguments() throws Throwable { public void testFilterArguments() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testFilterArguments0);
}
public void testFilterArguments0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("filterArguments"); startTest("filterArguments");
for (int nargs = 1; nargs <= 6; nargs++) { for (int nargs = 1; nargs <= 6; nargs++) {
...@@ -2004,6 +2111,10 @@ public class MethodHandlesTest { ...@@ -2004,6 +2111,10 @@ public class MethodHandlesTest {
@Test @Test
public void testCollectArguments() throws Throwable { public void testCollectArguments() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testCollectArguments0);
}
public void testCollectArguments0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("collectArguments"); startTest("collectArguments");
testFoldOrCollectArguments(true); testFoldOrCollectArguments(true);
...@@ -2011,6 +2122,10 @@ public class MethodHandlesTest { ...@@ -2011,6 +2122,10 @@ public class MethodHandlesTest {
@Test @Test
public void testFoldArguments() throws Throwable { public void testFoldArguments() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testFoldArguments0);
}
public void testFoldArguments0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("foldArguments"); startTest("foldArguments");
testFoldOrCollectArguments(false); testFoldOrCollectArguments(false);
...@@ -2112,6 +2227,10 @@ public class MethodHandlesTest { ...@@ -2112,6 +2227,10 @@ public class MethodHandlesTest {
@Test @Test
public void testDropArguments() throws Throwable { public void testDropArguments() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testDropArguments0);
}
public void testDropArguments0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("dropArguments"); startTest("dropArguments");
for (int nargs = 0; nargs <= 4; nargs++) { for (int nargs = 0; nargs <= 4; nargs++) {
...@@ -2143,6 +2262,10 @@ public class MethodHandlesTest { ...@@ -2143,6 +2262,10 @@ public class MethodHandlesTest {
@Test // SLOW @Test // SLOW
public void testInvokers() throws Throwable { public void testInvokers() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testInvokers0);
}
public void testInvokers0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("exactInvoker, genericInvoker, varargsInvoker, dynamicInvoker"); startTest("exactInvoker, genericInvoker, varargsInvoker, dynamicInvoker");
// exactInvoker, genericInvoker, varargsInvoker[0..N], dynamicInvoker // exactInvoker, genericInvoker, varargsInvoker[0..N], dynamicInvoker
...@@ -2344,6 +2467,10 @@ public class MethodHandlesTest { ...@@ -2344,6 +2467,10 @@ public class MethodHandlesTest {
@Test @Test
public void testGuardWithTest() throws Throwable { public void testGuardWithTest() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testGuardWithTest0);
}
public void testGuardWithTest0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("guardWithTest"); startTest("guardWithTest");
for (int nargs = 0; nargs <= 50; nargs++) { for (int nargs = 0; nargs <= 50; nargs++) {
...@@ -2415,6 +2542,10 @@ public class MethodHandlesTest { ...@@ -2415,6 +2542,10 @@ public class MethodHandlesTest {
@Test @Test
public void testThrowException() throws Throwable { public void testThrowException() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testThrowException0);
}
public void testThrowException0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("throwException"); startTest("throwException");
testThrowException(int.class, new ClassCastException("testing")); testThrowException(int.class, new ClassCastException("testing"));
...@@ -2446,6 +2577,10 @@ public class MethodHandlesTest { ...@@ -2446,6 +2577,10 @@ public class MethodHandlesTest {
@Test @Test
public void testInterfaceCast() throws Throwable { public void testInterfaceCast() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testInterfaceCast0);
}
public void testInterfaceCast0() throws Throwable {
//if (CAN_SKIP_WORKING) return; //if (CAN_SKIP_WORKING) return;
startTest("interfaceCast"); startTest("interfaceCast");
assert( (((Object)"foo") instanceof CharSequence)); assert( (((Object)"foo") instanceof CharSequence));
...@@ -2543,6 +2678,10 @@ public class MethodHandlesTest { ...@@ -2543,6 +2678,10 @@ public class MethodHandlesTest {
@Test // SLOW @Test // SLOW
public void testCastFailure() throws Throwable { public void testCastFailure() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testCastFailure0);
}
public void testCastFailure0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("testCastFailure"); startTest("testCastFailure");
testCastFailure("cast/argument", 11000); testCastFailure("cast/argument", 11000);
...@@ -2655,6 +2794,10 @@ public class MethodHandlesTest { ...@@ -2655,6 +2794,10 @@ public class MethodHandlesTest {
@Test @Test
public void testUserClassInSignature() throws Throwable { public void testUserClassInSignature() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testUserClassInSignature0);
}
public void testUserClassInSignature0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("testUserClassInSignature"); startTest("testUserClassInSignature");
Lookup lookup = MethodHandles.lookup(); Lookup lookup = MethodHandles.lookup();
...@@ -2706,6 +2849,10 @@ public class MethodHandlesTest { ...@@ -2706,6 +2849,10 @@ public class MethodHandlesTest {
@Test @Test
public void testAsInterfaceInstance() throws Throwable { public void testAsInterfaceInstance() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testAsInterfaceInstance0);
}
public void testAsInterfaceInstance0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("asInterfaceInstance"); startTest("asInterfaceInstance");
Lookup lookup = MethodHandles.lookup(); Lookup lookup = MethodHandles.lookup();
...@@ -2869,6 +3016,10 @@ public class MethodHandlesTest { ...@@ -2869,6 +3016,10 @@ public class MethodHandlesTest {
@Test @Test
public void testRunnableProxy() throws Throwable { public void testRunnableProxy() throws Throwable {
CodeCacheOverflowProcessor.runMHTest(this::testRunnableProxy0);
}
public void testRunnableProxy0() throws Throwable {
if (CAN_SKIP_WORKING) return; if (CAN_SKIP_WORKING) return;
startTest("testRunnableProxy"); startTest("testRunnableProxy");
MethodHandles.Lookup lookup = MethodHandles.lookup(); MethodHandles.Lookup lookup = MethodHandles.lookup();
......
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -24,9 +24,12 @@ ...@@ -24,9 +24,12 @@
/* /*
* @test * @test
* @bug 8019184 * @bug 8019184
* @library /lib/testlibrary /lib/testlibrary/jsr292
* @summary MethodHandles.catchException() fails when methods have 8 args + varargs * @summary MethodHandles.catchException() fails when methods have 8 args + varargs
* @run main TestCatchExceptionWithVarargs
*/ */
import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
import java.util.*; import java.util.*;
import java.lang.invoke.*; import java.lang.invoke.*;
...@@ -68,6 +71,11 @@ public class TestCatchExceptionWithVarargs { ...@@ -68,6 +71,11 @@ public class TestCatchExceptionWithVarargs {
} }
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
CodeCacheOverflowProcessor
.runMHTest(TestCatchExceptionWithVarargs::test);
}
public static void test() throws Throwable {
List<Class<?>> ptypes = new LinkedList<>(); List<Class<?>> ptypes = new LinkedList<>();
ptypes.add(Object[].class); ptypes.add(Object[].class);
......
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -24,14 +24,14 @@ ...@@ -24,14 +24,14 @@
package java.lang.invoke; package java.lang.invoke;
import sun.invoke.util.Wrapper; import sun.invoke.util.Wrapper;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
/* @test /* @test
* @summary unit tests for varargs array methods: MethodHandleInfo.varargsArray(int), * @summary unit tests for varargs array methods: MethodHandleInfo.varargsArray(int),
* MethodHandleInfo.varargsArray(Class,int) & MethodHandleInfo.varargsList(int) * MethodHandleInfo.varargsArray(Class,int) & MethodHandleInfo.varargsList(int)
* * @library /lib/testlibrary /lib/testlibrary/jsr292
* @run main/bootclasspath java.lang.invoke.VarargsArrayTest * @run main/bootclasspath java.lang.invoke.VarargsArrayTest
* @run main/bootclasspath -DVarargsArrayTest.MAX_ARITY=255 -DVarargsArrayTest.START_ARITY=250 * @run main/bootclasspath -DVarargsArrayTest.MAX_ARITY=255 -DVarargsArrayTest.START_ARITY=250
* java.lang.invoke.VarargsArrayTest * java.lang.invoke.VarargsArrayTest
...@@ -47,6 +47,10 @@ public class VarargsArrayTest { ...@@ -47,6 +47,10 @@ public class VarargsArrayTest {
private static final boolean EXHAUSTIVE = Boolean.getBoolean(CLASS.getSimpleName()+".EXHAUSTIVE"); private static final boolean EXHAUSTIVE = Boolean.getBoolean(CLASS.getSimpleName()+".EXHAUSTIVE");
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
CodeCacheOverflowProcessor.runMHTest(VarargsArrayTest::test);
}
public static void test() throws Throwable {
testVarargsArray(); testVarargsArray();
testVarargsReferenceArray(); testVarargsReferenceArray();
testVarargsPrimitiveArray(); testVarargsPrimitiveArray();
......
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -36,6 +36,7 @@ import java.util.Collections; ...@@ -36,6 +36,7 @@ import java.util.Collections;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function;
/** /**
* Common library for various test helper functions. * Common library for various test helper functions.
...@@ -276,4 +277,38 @@ public final class Utils { ...@@ -276,4 +277,38 @@ public final class Utils {
public static long adjustTimeout(long tOut) { public static long adjustTimeout(long tOut) {
return Math.round(tOut * Utils.TIMEOUT_FACTOR); return Math.round(tOut * Utils.TIMEOUT_FACTOR);
} }
/**
* Interface same as java.lang.Runnable but with
* method {@code run()} able to throw any Throwable.
*/
public static interface ThrowingRunnable {
void run() throws Throwable;
}
/**
* Filters out an exception that may be thrown by the given
* test according to the given filter.
*
* @param test - method that is invoked and checked for exception.
* @param filter - function that checks if the thrown exception matches
* criteria given in the filter's implementation.
* @return - exception that matches the filter if it has been thrown or
* {@code null} otherwise.
* @throws Throwable - if test has thrown an exception that does not
* match the filter.
*/
public static Throwable filterException(ThrowingRunnable test,
Function<Throwable, Boolean> filter) throws Throwable {
try {
test.run();
} catch (Throwable t) {
if (filter.apply(t)) {
return t;
} else {
throw t;
}
}
return null;
}
} }
/*
* 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");
t.printStackTrace();
}
return t;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册