test/java/lang/invoke/LFCaching/LambdaFormTestCase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/test/java/lang/invoke/LFCaching/LambdaFormTestCase.java	Tue Dec  2 20:15:07 2014
--- new/test/java/lang/invoke/LFCaching/LambdaFormTestCase.java	Tue Dec  2 20:15:06 2014

*** 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 **** --- 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