test/gc/7072527/TestFullGCCount.java

Fri, 27 Jun 2014 11:07:23 +0100

author
coffeys
date
Fri, 27 Jun 2014 11:07:23 +0100
changeset 6899
b67a3f81b630
parent 5008
bfe3be9ebd6c
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added tag jdk8u40-b00 for changeset 4828415ebbf1

kevinw@3025 1 /*
kevinw@5008 2 * Copyright (c) 2011, 2013, 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@5008 28 * @run main/othervm -XX:+PrintGC TestFullGCCount
kevinw@3025 29 */
kevinw@3025 30 import java.util.*;
kevinw@3025 31 import java.lang.management.*;
kevinw@3025 32
kevinw@5008 33 /*
kevinw@5008 34 * Originally for a specific failure in CMS, this test now monitors all
kevinw@5008 35 * collectors for double-counting of collections.
kevinw@5008 36 */
kevinw@3025 37 public class TestFullGCCount {
kevinw@3025 38
kevinw@5008 39 static List<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans();
kevinw@3025 40
kevinw@5008 41 public static void main(String[] args) {
kevinw@5008 42 int iterations = 20;
kevinw@5008 43 boolean failed = false;
kevinw@5008 44 String errorMessage = "";
kevinw@5008 45 HashMap<String, List> counts = new HashMap<String, List>();
kevinw@3025 46
kevinw@5008 47 // Prime the collection of count lists for all collectors.
kevinw@5008 48 for (int i = 0; i < collectors.size(); i++) {
kevinw@5008 49 GarbageCollectorMXBean collector = collectors.get(i);
kevinw@5008 50 counts.put(collector.getName(), new ArrayList<Long>(iterations));
kevinw@3025 51 }
kevinw@3025 52
kevinw@5008 53 // Perform some gc, record collector counts.
kevinw@5008 54 for (int i = 0; i < iterations; i++) {
kevinw@5008 55 System.gc();
kevinw@5008 56 addCollectionCount(counts, i);
kevinw@5008 57 }
kevinw@3025 58
kevinw@5008 59 // Check the increments:
kevinw@5008 60 // Old gen collectors should increase by one,
kevinw@5008 61 // New collectors may or may not increase.
kevinw@5008 62 // Any increase >=2 is unexpected.
kevinw@5008 63 for (String collector : counts.keySet()) {
kevinw@5008 64 System.out.println("Checking: " + collector);
kevinw@3025 65
kevinw@5008 66 for (int i = 0; i < iterations - 1; i++) {
kevinw@5008 67 List<Long> theseCounts = counts.get(collector);
kevinw@5008 68 long a = theseCounts.get(i);
kevinw@5008 69 long b = theseCounts.get(i + 1);
kevinw@5008 70 if (b - a >= 2) {
kevinw@5008 71 failed = true;
kevinw@5008 72 errorMessage += "Collector '" + collector + "' has increment " + (b - a) +
kevinw@5008 73 " at iteration " + i + "\n";
kevinw@3025 74 }
kevinw@3025 75 }
kevinw@3025 76 }
kevinw@5008 77 if (failed) {
kevinw@5008 78 System.err.println(errorMessage);
kevinw@5008 79 throw new RuntimeException("FAILED: System.gc collections miscounted.");
kevinw@3025 80 }
kevinw@3025 81 System.out.println("Passed.");
kevinw@3025 82 }
kevinw@3025 83
kevinw@5008 84 private static void addCollectionCount(HashMap<String, List> counts, int iteration) {
kevinw@5008 85 for (int i = 0; i < collectors.size(); i++) {
kevinw@3025 86 GarbageCollectorMXBean collector = collectors.get(i);
kevinw@5008 87 List thisList = counts.get(collector.getName());
kevinw@5008 88 thisList.add(collector.getCollectionCount());
kevinw@3025 89 }
kevinw@3025 90 }
kevinw@3025 91 }

mercurial