author | alanb |
Tue, 03 May 2016 09:11:31 +0100 | |
changeset 37827 | 09fa0c82a5f7 |
parent 35504 | aabd81013e37 |
child 42572 | faf8f5152129 |
permissions | -rw-r--r-- |
35504
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
1 |
/* |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
2 |
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
4 |
* |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
8 |
* |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
13 |
* accompanied this code). |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
14 |
* |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
18 |
* |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
21 |
* questions. |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
22 |
*/ |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
23 |
|
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
24 |
/* |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
25 |
* @test TestFullGCCount.java |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
26 |
* @bug 7072527 |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
27 |
* @summary CMS: JMM GC counters overcount in some cases |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
28 |
* @modules java.management |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
29 |
* @run main/othervm -Xlog:gc TestFullGCCount |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
30 |
*/ |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
31 |
|
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
32 |
import java.lang.management.GarbageCollectorMXBean; |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
33 |
import java.lang.management.ManagementFactory; |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
34 |
import java.util.ArrayList; |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
35 |
import java.util.HashMap; |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
36 |
import java.util.List; |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
37 |
|
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
38 |
/* |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
39 |
* Originally for a specific failure in CMS, this test now monitors all |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
40 |
* collectors for double-counting of collections. |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
41 |
*/ |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
42 |
public class TestFullGCCount { |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
43 |
|
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
44 |
static List<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans(); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
45 |
|
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
46 |
public static void main(String[] args) { |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
47 |
int iterations = 20; |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
48 |
boolean failed = false; |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
49 |
String errorMessage = ""; |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
50 |
HashMap<String, List> counts = new HashMap<>(); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
51 |
|
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
52 |
// Prime the collection of count lists for all collectors. |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
53 |
for (int i = 0; i < collectors.size(); i++) { |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
54 |
GarbageCollectorMXBean collector = collectors.get(i); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
55 |
counts.put(collector.getName(), new ArrayList<>(iterations)); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
56 |
} |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
57 |
|
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
58 |
// Perform some gc, record collector counts. |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
59 |
for (int i = 0; i < iterations; i++) { |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
60 |
System.gc(); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
61 |
addCollectionCount(counts, i); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
62 |
} |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
63 |
|
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
64 |
// Check the increments: |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
65 |
// Old gen collectors should increase by one, |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
66 |
// New collectors may or may not increase. |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
67 |
// Any increase >=2 is unexpected. |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
68 |
for (String collector : counts.keySet()) { |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
69 |
System.out.println("Checking: " + collector); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
70 |
|
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
71 |
for (int i = 0; i < iterations - 1; i++) { |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
72 |
List<Long> theseCounts = counts.get(collector); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
73 |
long a = theseCounts.get(i); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
74 |
long b = theseCounts.get(i + 1); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
75 |
if (b - a >= 2) { |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
76 |
failed = true; |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
77 |
errorMessage += "Collector '" + collector + "' has increment " + (b - a) + |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
78 |
" at iteration " + i + "\n"; |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
79 |
} |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
80 |
} |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
81 |
} |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
82 |
if (failed) { |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
83 |
System.err.println(errorMessage); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
84 |
throw new RuntimeException("FAILED: System.gc collections miscounted."); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
85 |
} |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
86 |
System.out.println("Passed."); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
87 |
} |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
88 |
|
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
89 |
private static void addCollectionCount(HashMap<String, List> counts, int iteration) { |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
90 |
for (int i = 0; i < collectors.size(); i++) { |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
91 |
GarbageCollectorMXBean collector = collectors.get(i); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
92 |
List thisList = counts.get(collector.getName()); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
93 |
thisList.add(collector.getCollectionCount()); |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
94 |
} |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
95 |
} |
aabd81013e37
8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff
changeset
|
96 |
} |