test/java/lang/invoke/LFCaching/LambdaFormTestCase.java

Print this page

        

*** 25,34 **** --- 25,35 ---- 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,48 **** --- 40,50 ---- 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. */
*** 107,117 **** --- 109,122 ---- iterations = iterationsByCodeCacheSize; } System.out.printf("Number of iterations is set to %d (%d cases)%n", iterations, iterations * testCaseNum); System.out.flush(); + long maxIterTime = 0; + long startTime = System.currentTimeMillis(); for (long i = 0; i < iterations; i++) { + long startIterTime = System.currentTimeMillis(); System.err.println(String.format("Iteration %d:", i)); for (TestMethods testMethod : testMethods) { LambdaFormTestCase testCase = ctor.apply(testMethod); try { System.err.printf("Tested LF caching feature with MethodHandles.%s method.%n",
*** 124,133 **** --- 129,147 ---- passed = false; failCounter++; } testCounter++; } + long passedTime = System.currentTimeMillis() - startTime; + long iterTime = System.currentTimeMillis() - startIterTime; + maxIterTime = Math.max(maxIterTime, iterTime); + long remainTime = TIMEOUT - passedTime; + if (4 * maxIterTime > 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));