test/java/lang/invoke/LFCaching/LambdaFormTestCase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Cdiff test/java/lang/invoke/LFCaching/LambdaFormTestCase.java

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

Print this page
rev 11011 : 8057020: LambdaForm caches should support eviction
Reviewed-by: psandoz, ?

*** 21,33 **** --- 21,36 ---- * questions. */ import com.oracle.testlibrary.jsr292.Helper; import com.sun.management.HotSpotDiagnosticMXBean; + + import java.lang.management.GarbageCollectorMXBean; import java.lang.management.ManagementFactory; import java.lang.reflect.Method; import java.util.Collection; + import java.util.List; import java.util.function.Function; import jdk.testlibrary.Utils; /** * Lambda forms caching test case class. Contains all necessary test routines to
*** 47,84 **** /** * Reflection link to {@code j.l.i.MethodHandle.internalForm} method. It is * used to get a lambda form from a method handle. */ protected final static Method INTERNAL_FORM; static { try { Class mhClass = Class.forName(METHOD_HANDLE_CLASS_NAME); INTERNAL_FORM = mhClass.getDeclaredMethod(INTERNAL_FORM_METHOD_NAME); INTERNAL_FORM.setAccessible(true); } catch (Exception ex) { throw new Error("Unexpected exception: ", ex); } } private final TestMethods testMethod; ! /** * Test case constructor. Generates test cases with random method types for * given methods form {@code j.l.i.MethodHandles} class. * * @param testMethod A method from {@code j.l.i.MethodHandles} class which * returns a {@code j.l.i.MethodHandle}. */ protected LambdaFormTestCase(TestMethods testMethod) { this.testMethod = testMethod; } public TestMethods getTestMethod() { return testMethod; } /** * Routine that executes a test case. */ public abstract void doTest(); --- 50,102 ---- /** * Reflection link to {@code j.l.i.MethodHandle.internalForm} method. It is * used to get a lambda form from a method handle. */ protected final static Method INTERNAL_FORM; + private static final List<GarbageCollectorMXBean> gcInfo; + + private static long gcCount() { + return gcInfo.stream().mapToLong(GarbageCollectorMXBean::getCollectionCount).sum(); + } static { try { Class mhClass = Class.forName(METHOD_HANDLE_CLASS_NAME); INTERNAL_FORM = mhClass.getDeclaredMethod(INTERNAL_FORM_METHOD_NAME); INTERNAL_FORM.setAccessible(true); } catch (Exception ex) { throw new Error("Unexpected exception: ", ex); } + + gcInfo = ManagementFactory.getGarbageCollectorMXBeans(); + if (gcInfo.size() == 0) { + throw new Error("No GarbageCollectorMXBeans found."); + } } private final TestMethods testMethod; ! private long gcCountAtStart; /** * Test case constructor. Generates test cases with random method types for * given methods form {@code j.l.i.MethodHandles} class. * * @param testMethod A method from {@code j.l.i.MethodHandles} class which * returns a {@code j.l.i.MethodHandle}. */ protected LambdaFormTestCase(TestMethods testMethod) { this.testMethod = testMethod; + this.gcCountAtStart = gcCount(); } public TestMethods getTestMethod() { return testMethod; } + protected boolean noGCHappened() { + return gcCount() == gcCountAtStart; + } + /** * Routine that executes a test case. */ public abstract void doTest();
test/java/lang/invoke/LFCaching/LambdaFormTestCase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File