From c96fd46a4c6dfa25b01b971ff8e06d146f9303de Mon Sep 17 00:00:00 2001 From: Mattias Tobiasson Date: Fri, 28 Feb 2014 13:38:51 +0100 Subject: [PATCH] 6625574: java/lang/management/MemoryMXBean/Pending.java fails: "pending finalization = 0 but expected > 0" Move local objs variable to a static public so the the optimizer will not remove it unexpectedly. Reviewed-by: sla --- jdk/test/java/lang/management/MemoryMXBean/Pending.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jdk/test/java/lang/management/MemoryMXBean/Pending.java b/jdk/test/java/lang/management/MemoryMXBean/Pending.java index cc0235f58f7..678bc7e4ca7 100644 --- a/jdk/test/java/lang/management/MemoryMXBean/Pending.java +++ b/jdk/test/java/lang/management/MemoryMXBean/Pending.java @@ -76,6 +76,9 @@ public class Pending { 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 @@ public class Pending { 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(); }