test/java/lang/invoke/LFCaching/LambdaFormTestCase.java
Print this page
@@ -25,10 +25,11 @@
import com.sun.management.HotSpotDiagnosticMXBean;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.function.Function;
+import jdk.testlibrary.Utils;
/**
* Lambda forms caching test case class. Contains all necessary test routines to
* test lambda forms caching in method handles returned by methods of
* MethodHandles class.
@@ -39,10 +40,11 @@
private final static String METHOD_HANDLE_CLASS_NAME = "java.lang.invoke.MethodHandle";
private final static String INTERNAL_FORM_METHOD_NAME = "internalForm";
private static final double ITERATIONS_TO_CODE_CACHE_SIZE_RATIO
= 45 / (128.0 * 1024 * 1024);
+ private static final long TIMEOUT = Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT);
/**
* Reflection link to {@code j.l.i.MethodHandle.internalForm} method. It is
* used to get a lambda form from a method handle.
*/
@@ -118,10 +120,11 @@
iterations = 1;
}
System.out.printf("Number of iterations is set to %d (%d cases)%n",
iterations, iterations * testCaseNum);
System.out.flush();
+ long startTime = System.currentTimeMillis();
for (long i = 0; i < iterations; i++) {
System.err.println(String.format("Iteration %d:", i));
for (TestMethods testMethod : testMethods) {
LambdaFormTestCase testCase = ctor.apply(testMethod);
try {
@@ -135,10 +138,18 @@
passed = false;
failCounter++;
}
testCounter++;
}
+ long passedTime = System.currentTimeMillis() - startTime;
+ long avgIterTime = passedTime / (i + 1);
+ long remainTime = TIMEOUT - passedTime;
+ if (avgIterTime > 2 * remainTime) {
+ System.err.printf("Stopping iterations because of lack of time.%n"
+ + "Increase timeout factor for more iterations.%n");
+ break;
+ }
}
if (!passed) {
throw new Error(String.format("%d of %d test cases FAILED! %n"
+ "Rerun the test with the same \"-Dseed=\" option as in the log file!",
failCounter, testCounter));