aboutsummaryrefslogtreecommitdiff
path: root/test/java/lang
diff options
context:
space:
mode:
authorvlivanov <none@none>2014-12-04 07:15:37 -0800
committervlivanov <none@none>2014-12-04 07:15:37 -0800
commite7a2ea5c80d41ffb1e135e0c1ec442f750de3590 (patch)
treeec19905bd61177c661ccfb016375b206bc625c09 /test/java/lang
parent970d3f107bfff0d46d0fb4afbd50081dcd4a17bd (diff)
downloadjdk8u_jdk-e7a2ea5c80d41ffb1e135e0c1ec442f750de3590.tar.gz
8057020: LambdaForm caches should support eviction
Reviewed-by: psandoz, jrose, shade
Diffstat (limited to 'test/java/lang')
-rw-r--r--test/java/lang/invoke/LFCaching/LFCachingTestCase.java17
-rw-r--r--test/java/lang/invoke/LFCaching/LambdaFormTestCase.java19
2 files changed, 30 insertions, 6 deletions
diff --git a/test/java/lang/invoke/LFCaching/LFCachingTestCase.java b/test/java/lang/invoke/LFCaching/LFCachingTestCase.java
index 30ba39ac2e..50a57e40c6 100644
--- a/test/java/lang/invoke/LFCaching/LFCachingTestCase.java
+++ b/test/java/lang/invoke/LFCaching/LFCachingTestCase.java
@@ -63,12 +63,17 @@ public abstract class LFCachingTestCase extends LambdaFormTestCase {
}
if (lambdaForm0 != lambdaForm1) {
- System.err.println("Lambda form 0 toString is:");
- System.err.println(lambdaForm0);
- System.err.println("Lambda form 1 toString is:");
- System.err.println(lambdaForm1);
- throw new AssertionError("Error: Lambda forms of the two method handles"
- + " are not the same. LF cahing does not work");
+ // Since LambdaForm caches are based on SoftReferences, GC can cause element eviction.
+ if (noGCHappened()) {
+ System.err.println("Lambda form 0 toString is:");
+ System.err.println(lambdaForm0);
+ System.err.println("Lambda form 1 toString is:");
+ System.err.println(lambdaForm1);
+ throw new AssertionError("Error: Lambda forms of the two method handles"
+ + " are not the same. LF cahing does not work");
+ } else {
+ System.err.println("LambdaForms differ, but there was a GC in between. Ignore the failure.");
+ }
}
} catch (IllegalAccessException | IllegalArgumentException |
SecurityException | InvocationTargetException ex) {
diff --git a/test/java/lang/invoke/LFCaching/LambdaFormTestCase.java b/test/java/lang/invoke/LFCaching/LambdaFormTestCase.java
index 34df1b2dd8..7b6ce2eeff 100644
--- a/test/java/lang/invoke/LFCaching/LambdaFormTestCase.java
+++ b/test/java/lang/invoke/LFCaching/LambdaFormTestCase.java
@@ -23,9 +23,12 @@
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;
import jdk.testlibrary.TimeLimitedRunner;
@@ -50,6 +53,11 @@ public abstract class LambdaFormTestCase {
* 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 {
@@ -59,6 +67,11 @@ public abstract class LambdaFormTestCase {
} 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;
@@ -67,6 +80,7 @@ public abstract class LambdaFormTestCase {
private static boolean passed = true;
private static int testCounter = 0;
private static int failCounter = 0;
+ private long gcCountAtStart;
/**
* Test case constructor. Generates test cases with random method types for
@@ -77,12 +91,17 @@ public abstract class LambdaFormTestCase {
*/
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.
*/