kevinw@3025: /* kevinw@3025: * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. kevinw@3025: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. kevinw@3025: * kevinw@3025: * This code is free software; you can redistribute it and/or modify it kevinw@3025: * under the terms of the GNU General Public License version 2 only, as kevinw@3025: * published by the Free Software Foundation. kevinw@3025: * kevinw@3025: * This code is distributed in the hope that it will be useful, but WITHOUT kevinw@3025: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or kevinw@3025: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License kevinw@3025: * version 2 for more details (a copy is included in the LICENSE file that kevinw@3025: * accompanied this code). kevinw@3025: * kevinw@3025: * You should have received a copy of the GNU General Public License version kevinw@3025: * 2 along with this work; if not, write to the Free Software Foundation, kevinw@3025: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. kevinw@3025: * kevinw@3025: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA kevinw@3025: * or visit www.oracle.com if you need additional information or have any kevinw@3025: * questions. kevinw@3025: */ kevinw@3025: kevinw@3025: /* kevinw@3025: * @test TestFullGCount.java kevinw@3025: * @bug 7072527 kevinw@3025: * @summary CMS: JMM GC counters overcount in some cases kevinw@3025: * @run main/othervm -XX:+UseConcMarkSweepGC TestFullGCCount kevinw@3025: * kevinw@3025: */ kevinw@3025: import java.util.*; kevinw@3025: import java.lang.management.*; kevinw@3025: kevinw@3025: public class TestFullGCCount { kevinw@3025: kevinw@3025: public String collectorName = "ConcurrentMarkSweep"; kevinw@3025: kevinw@3025: public static void main(String [] args) { kevinw@3025: kevinw@3025: TestFullGCCount t = null; kevinw@3025: if (args.length==2) { kevinw@3025: t = new TestFullGCCount(args[0], args[1]); kevinw@3025: } else { kevinw@3025: t = new TestFullGCCount(); kevinw@3025: } kevinw@3025: System.out.println("Monitoring collector: " + t.collectorName); kevinw@3025: t.run(); kevinw@3025: } kevinw@3025: kevinw@3025: public TestFullGCCount(String pool, String collector) { kevinw@3025: collectorName = collector; kevinw@3025: } kevinw@3025: kevinw@3025: public TestFullGCCount() { kevinw@3025: } kevinw@3025: kevinw@3025: public void run() { kevinw@3025: int count = 0; kevinw@3025: int iterations = 20; kevinw@3025: long counts[] = new long[iterations]; kevinw@3025: boolean diffAlways2 = true; // assume we will fail kevinw@3025: kevinw@3025: for (int i=0; i0) { kevinw@3025: if (counts[i] - counts[i-1] != 2) { kevinw@3025: diffAlways2 = false; kevinw@3025: } kevinw@3025: } kevinw@3025: } kevinw@3025: if (diffAlways2) { kevinw@3025: throw new RuntimeException("FAILED: System.gc must be incrementing count twice."); kevinw@3025: } kevinw@3025: System.out.println("Passed."); kevinw@3025: } kevinw@3025: kevinw@3025: private long getCollectionCount() { kevinw@3025: long count = 0; kevinw@3025: List pools = ManagementFactory.getMemoryPoolMXBeans(); kevinw@3025: List collectors = ManagementFactory.getGarbageCollectorMXBeans(); kevinw@3025: for (int i=0; i