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