Staffan, could you please sponsor this fix? Thanks, Mattias
----- Original Message ----- From: staffan.lar...@oracle.com To: mattias.tobias...@oracle.com Cc: serviceability-dev@openjdk.java.net Sent: Friday, February 28, 2014 1:58:44 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna Subject: Re: RFR(XS) 6625574: MemoryMXBean/Pending.java fails: "pending finalization = 0 but expected > 0" Looks good! Thanks, /Staffan On 28 feb 2014, at 13:56, Mattias Tobiasson <mattias.tobias...@oracle.com> wrote: > Hi, > Could you please review this fix? > > The test often fails when run with command line "-Xcomp" > > The test creates some objects and stores them in a local variable in the > function. The test expects those objects to survive until they are set to > null. The problem seems to be that the optimizer realizes that the objects > are never used and removes them before the test expects it. > > The solution is to move the local variable out to a public static variable. > Then the optimizer will not remove it before expected. > > webrev: > http://cr.openjdk.java.net/~mtobiass/6625574/webrev.00 > > bug: > https://bugs.openjdk.java.net/browse/JDK-6625574 > > Mattias
# HG changeset patch # User mtobiass # Date 1393591131 -3600 # Node ID 511f475aa2c8dbad0f636851fc8c2a032f1d64db # Parent 0731952efb104b783b75a5765a91a91601903a3c 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. diff --git a/test/java/lang/management/MemoryMXBean/Pending.java b/test/java/lang/management/MemoryMXBean/Pending.java --- a/test/java/lang/management/MemoryMXBean/Pending.java +++ b/test/java/lang/management/MemoryMXBean/Pending.java @@ -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(); }