Thu, 20 Oct 2011 10:32:37 -0700
Added tag jdk8-b10 for changeset d815de2e85e5
kevinw@3025 | 1 | /* |
kevinw@3025 | 2 | * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
kevinw@3025 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
kevinw@3025 | 4 | * |
kevinw@3025 | 5 | * This code is free software; you can redistribute it and/or modify it |
kevinw@3025 | 6 | * under the terms of the GNU General Public License version 2 only, as |
kevinw@3025 | 7 | * published by the Free Software Foundation. |
kevinw@3025 | 8 | * |
kevinw@3025 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
kevinw@3025 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
kevinw@3025 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
kevinw@3025 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
kevinw@3025 | 13 | * accompanied this code). |
kevinw@3025 | 14 | * |
kevinw@3025 | 15 | * You should have received a copy of the GNU General Public License version |
kevinw@3025 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
kevinw@3025 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
kevinw@3025 | 18 | * |
kevinw@3025 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
kevinw@3025 | 20 | * or visit www.oracle.com if you need additional information or have any |
kevinw@3025 | 21 | * questions. |
kevinw@3025 | 22 | */ |
kevinw@3025 | 23 | |
kevinw@3025 | 24 | /* |
kevinw@3025 | 25 | * @test TestFullGCount.java |
kevinw@3025 | 26 | * @bug 7072527 |
kevinw@3025 | 27 | * @summary CMS: JMM GC counters overcount in some cases |
kevinw@3025 | 28 | * @run main/othervm -XX:+UseConcMarkSweepGC TestFullGCCount |
kevinw@3025 | 29 | * |
kevinw@3025 | 30 | */ |
kevinw@3025 | 31 | import java.util.*; |
kevinw@3025 | 32 | import java.lang.management.*; |
kevinw@3025 | 33 | |
kevinw@3025 | 34 | public class TestFullGCCount { |
kevinw@3025 | 35 | |
kevinw@3025 | 36 | public String collectorName = "ConcurrentMarkSweep"; |
kevinw@3025 | 37 | |
kevinw@3025 | 38 | public static void main(String [] args) { |
kevinw@3025 | 39 | |
kevinw@3025 | 40 | TestFullGCCount t = null; |
kevinw@3025 | 41 | if (args.length==2) { |
kevinw@3025 | 42 | t = new TestFullGCCount(args[0], args[1]); |
kevinw@3025 | 43 | } else { |
kevinw@3025 | 44 | t = new TestFullGCCount(); |
kevinw@3025 | 45 | } |
kevinw@3025 | 46 | System.out.println("Monitoring collector: " + t.collectorName); |
kevinw@3025 | 47 | t.run(); |
kevinw@3025 | 48 | } |
kevinw@3025 | 49 | |
kevinw@3025 | 50 | public TestFullGCCount(String pool, String collector) { |
kevinw@3025 | 51 | collectorName = collector; |
kevinw@3025 | 52 | } |
kevinw@3025 | 53 | |
kevinw@3025 | 54 | public TestFullGCCount() { |
kevinw@3025 | 55 | } |
kevinw@3025 | 56 | |
kevinw@3025 | 57 | public void run() { |
kevinw@3025 | 58 | int count = 0; |
kevinw@3025 | 59 | int iterations = 20; |
kevinw@3025 | 60 | long counts[] = new long[iterations]; |
kevinw@3025 | 61 | boolean diffAlways2 = true; // assume we will fail |
kevinw@3025 | 62 | |
kevinw@3025 | 63 | for (int i=0; i<iterations; i++) { |
kevinw@3025 | 64 | System.gc(); |
kevinw@3025 | 65 | counts[i] = getCollectionCount(); |
kevinw@3025 | 66 | if (i>0) { |
kevinw@3025 | 67 | if (counts[i] - counts[i-1] != 2) { |
kevinw@3025 | 68 | diffAlways2 = false; |
kevinw@3025 | 69 | } |
kevinw@3025 | 70 | } |
kevinw@3025 | 71 | } |
kevinw@3025 | 72 | if (diffAlways2) { |
kevinw@3025 | 73 | throw new RuntimeException("FAILED: System.gc must be incrementing count twice."); |
kevinw@3025 | 74 | } |
kevinw@3025 | 75 | System.out.println("Passed."); |
kevinw@3025 | 76 | } |
kevinw@3025 | 77 | |
kevinw@3025 | 78 | private long getCollectionCount() { |
kevinw@3025 | 79 | long count = 0; |
kevinw@3025 | 80 | List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); |
kevinw@3025 | 81 | List<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans(); |
kevinw@3025 | 82 | for (int i=0; i<collectors.size(); i++) { |
kevinw@3025 | 83 | GarbageCollectorMXBean collector = collectors.get(i); |
kevinw@3025 | 84 | String name = collector.getName(); |
kevinw@3025 | 85 | if (name.contains(collectorName)) { |
kevinw@3025 | 86 | System.out.println(name + ": collection count = " |
kevinw@3025 | 87 | + collector.getCollectionCount()); |
kevinw@3025 | 88 | count = collector.getCollectionCount(); |
kevinw@3025 | 89 | } |
kevinw@3025 | 90 | } |
kevinw@3025 | 91 | return count; |
kevinw@3025 | 92 | } |
kevinw@3025 | 93 | |
kevinw@3025 | 94 | } |
kevinw@3025 | 95 |