test/java/lang/invoke/LFCaching/LambdaFormTestCase.java
Print this page
*** 20,32 ****
--- 20,36 ----
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.oracle.testlibrary.jsr292.Helper;
+ import com.sun.management.HotSpotDiagnosticMXBean;
+ import java.io.IOException;
+ import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.function.Function;
+ import javax.management.MBeanServer;
/**
* 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.
*** 35,44 ****
--- 39,52 ----
*/
public abstract class LambdaFormTestCase {
private final static String METHOD_HANDLE_CLASS_NAME = "java.lang.invoke.MethodHandle";
private final static String INTERNAL_FORM_METHOD_NAME = "internalForm";
+ private static final String HOTSPOT_BEAN_NAME
+ = "com.sun.management:type=HotSpotDiagnostic";
+ private static final double ITERATIONS_TO_CODE_CACHE_SIZE_RATIO
+ = 45 / (128.0 * 1024 * 1024);
/**
* Reflection link to {@code j.l.i.MethodHandle.internalForm} method. It is
* used to get a lambda form from a method handle.
*/
*** 85,95 ****
*/
public static void runTests(Function<TestMethods, LambdaFormTestCase> ctor, Collection<TestMethods> testMethods) {
boolean passed = true;
int testCounter = 0;
int failCounter = 0;
! long iterations = Math.max(1, Helper.TEST_LIMIT / testMethods.size());
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 {
--- 93,127 ----
*/
public static void runTests(Function<TestMethods, LambdaFormTestCase> ctor, Collection<TestMethods> testMethods) {
boolean passed = true;
int testCounter = 0;
int failCounter = 0;
! long testCaseNum = testMethods.size();
! long iterations = Math.max(1, Helper.TEST_LIMIT / testCaseNum);
! System.out.printf("Number of iterations according to -DtestLimit is %d (%d cases)%n",
! iterations, iterations * testCaseNum);
! MBeanServer server = ManagementFactory.getPlatformMBeanServer();
! HotSpotDiagnosticMXBean hsDiagBean;
! try {
! hsDiagBean = ManagementFactory.newPlatformMXBeanProxy(server,
! HOTSPOT_BEAN_NAME, HotSpotDiagnosticMXBean.class);
! } catch (IOException ex) {
! throw new Error("TESTBUG: ", ex);
! }
! long codeCacheSize = Long.parseLong(
! hsDiagBean.getVMOption("ReservedCodeCacheSize").getValue());
! System.out.printf("Code Cache Size is %d bytes%n", codeCacheSize);
! long iterationsByCodeCacheSize = (long) (codeCacheSize
! * ITERATIONS_TO_CODE_CACHE_SIZE_RATIO);
! System.out.printf("Number of iterations limited by code cache size is %d (%d cases)%n",
! iterationsByCodeCacheSize, iterationsByCodeCacheSize * testCaseNum);
! if (iterations > iterationsByCodeCacheSize) {
! iterations = iterationsByCodeCacheSize;
! }
! System.out.printf("Number of iterations is set to %d (%d cases)%n",
! iterations, iterations * testCaseNum);
! System.out.flush();
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 {
*** 113,117 ****
--- 145,150 ----
} else {
System.err.println(String.format("All %d test cases PASSED!", testCounter));
}
}
}
+