Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/runtime/LoadClass/TestResize.java
40942 views
1
/*
2
* Copyright (c) 2017, 2020, 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
/*
25
* @test
26
* @bug 8184765
27
* @summary make sure the SystemDictionary gets resized when load factor is too high
28
* @requires vm.debug
29
* @library /test/lib
30
* @modules java.base/jdk.internal.misc
31
* java.management
32
* @compile TriggerResize.java
33
* @run driver TestResize
34
*/
35
36
import jdk.test.lib.Platform;
37
import jdk.test.lib.process.OutputAnalyzer;
38
import jdk.test.lib.process.ProcessTools;
39
import java.io.BufferedReader;
40
import java.io.InputStreamReader;
41
import java.lang.Process;
42
import java.lang.ProcessBuilder;
43
import java.util.Scanner;
44
45
public class TestResize {
46
47
static double MAX_LOAD_FACTOR = 5.0; // see _resize_load_trigger in dictionary.cpp
48
49
static int getInt(String string) {
50
int start = 0;
51
for (int i = 0; i < string.length(); i++) {
52
if (!Character.isDigit(string.charAt(i))) {
53
start++;
54
} else {
55
break;
56
}
57
}
58
int end = start;
59
for (int i = end; i < string.length(); i++) {
60
if (Character.isDigit(string.charAt(i))) {
61
end++;
62
} else {
63
break;
64
}
65
}
66
return Integer.parseInt(string.substring(start, end));
67
}
68
69
static void analyzeOutputOn(ProcessBuilder pb) throws Exception {
70
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
71
String output = analyzer.getStdout();
72
analyzer.shouldHaveExitValue(0);
73
74
boolean resized = false;
75
76
// Split string into lines using platform independent end of line marker.
77
String[] lines = output.split("\\R");
78
for (String line : lines) {
79
if (!resized) {
80
// ex. [0.563s][info][safepoint,cleanup] resizing system dictionaries, 0.0000002 secs
81
if (line.contains("resizing system dictionaries")) {
82
resized = true;
83
}
84
} else if (resized && line.startsWith("Java dictionary (")) {
85
// ex. Java dictionary (table_size=10103, classes=5002)
86
Scanner scanner = new Scanner(line);
87
scanner.next(); // skip "Java"
88
scanner.next(); // skip "dictionary"
89
int table_size = getInt(scanner.next()); // process "(table_size=40423"
90
int classes = getInt(scanner.next()); // process ", classes=50002"
91
scanner.close();
92
93
double loadFactor = (double)classes / (double)table_size;
94
if (loadFactor > MAX_LOAD_FACTOR) {
95
96
// We've hit an error, so print all of the output.
97
System.out.println(output);
98
99
throw new RuntimeException("Load factor too high, expected MAX " + MAX_LOAD_FACTOR +
100
", got " + loadFactor + " [table size " + table_size + ", number of clases " + classes + "]");
101
} else {
102
System.out.println("PASS table_size: " + table_size + ", classes: " + classes +
103
", load factor: " + loadFactor + " <= " + MAX_LOAD_FACTOR);
104
// There are more than one system dictionary to check, so keep looking...
105
}
106
}
107
}
108
109
if (!resized) {
110
System.out.println("PASS trivially. No resizing occurred, so did not check the load.");
111
}
112
}
113
114
public static void main(String[] args) throws Exception {
115
// -XX:+PrintSystemDictionaryAtExit will print the details of system dictionary,
116
// that will allow us to calculate the table's load factor.
117
// -Xlog:safepoint+cleanup will print out cleanup details at safepoint
118
// that will allow us to detect if the system dictionary resized.
119
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintSystemDictionaryAtExit",
120
"-Xlog:safepoint+cleanup",
121
"TriggerResize",
122
"50000");
123
analyzeOutputOn(pb);
124
}
125
}
126
127