annotate test/gc/7072527/TestFullGCCount.java @ 6004:0f701f572aed

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