/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test Test6581734.java * @bug 6581734 * @summary CMS Old Gen's collection usage is zero after GC which is incorrect * @run main/othervm -server -Xmx512m -verbose:gc -XX:+UseConcMarkSweepGC Test6581734 * */ import java.util.*; import java.lang.management.*; // 6581734 states that memory pool usage via the mbean is wrong // for CMS (zero, even after a collection). // // 6580448 states that the collection count similarly is wrong // (stays at zero for CMS collections) // -- closed as dup of 6581734 as the same fix resolves both. public class Test6581734 { private String poolName = "CMS"; private String collectorName = "ConcurrentMarkSweep"; public static void main(String [] args) { Test6581734 t = null; if (args.length==2) { t = new Test6581734(args[0], args[1]); } else { System.out.println("Defaulting to monitor CMS pool and collector."); t = new Test6581734(); } t.run(); } public Test6581734(String pool, String collector) { poolName = pool; collectorName = collector; } public Test6581734() { } public void run() { // Use some memory, enough that we expect collections should // have happened. // Must run with options to ensure no stop the world full GC, // but e.g. at least one CMS cycle. allocationWork(300*1024*1024); System.out.println("Done allocationWork"); // Verify some non-zero results are stored. List pools = ManagementFactory.getMemoryPoolMXBeans(); int poolsFound = 0; int poolsWithStats = 0; for (int i=0; i collectors = ManagementFactory.getGarbageCollectorMXBeans(); int collectorsFound = 0; int collectorsWithTime= 0; for (int i=0; i 0) { collectorsWithTime++; } } } // verify: if (poolsWithStats < poolsFound) { throw new RuntimeException("pools found with zero stats"); } if (collectorsWithTime