6625574: java/lang/management/MemoryMXBean/Pending.java fails: "pending finalization = 0 but expected > 0"
Summary: Move local objs variable to a static public so the the optimizer will not remove it unexpectedly.
Reviewed-by: sla
--- a/jdk/test/java/lang/management/MemoryMXBean/Pending.java Mon Mar 03 18:17:00 2014 +0400
+++ b/jdk/test/java/lang/management/MemoryMXBean/Pending.java Fri Feb 28 13:38:51 2014 +0100
@@ -76,6 +76,9 @@
System.out.println("Test passed.");
}
+ // Keep objs public so the optimizer will not remove them too early.
+ public static Object[] objs = null;
+
private static void test() throws Exception {
// Clean the memory and remove all objects that are pending
// finalization
@@ -105,7 +108,7 @@
System.out.println(" Afer creating objects with no ref: " + snapshot);
printFinalizerInstanceCount();
- Object[] objs = new Object[REF_COUNT];
+ objs = new Object[REF_COUNT];
for (int i = 0; i < REF_COUNT; i++) {
objs[i] = new MyObject();
}