Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/arguments/TestNewSizeThreadIncrease.java
40943 views
1
/*
2
* Copyright (c) 2015, 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
package gc.arguments;
25
26
/*
27
* @test TestNewSizeThreadIncrease
28
* @bug 8144527
29
* @summary Tests argument processing for NewSizeThreadIncrease
30
* @library /test/lib
31
* @library /
32
* @requires vm.gc.Serial
33
* @modules java.base/jdk.internal.misc
34
* java.management
35
* @run driver gc.arguments.TestNewSizeThreadIncrease
36
*/
37
38
39
import jdk.test.lib.Platform;
40
import jdk.test.lib.process.OutputAnalyzer;
41
import jdk.test.lib.process.ProcessTools;
42
43
44
// Range of NewSizeThreadIncrease is 0 ~ max_uintx.
45
// Total of 5 threads will be created (1 GCTest thread and 4 TestThread).
46
public class TestNewSizeThreadIncrease {
47
static final String VALID_VALUE = "2097152"; // 2MB
48
49
// This value will make an overflow of 'thread count * NewSizeThreadIncrease' at DefNewGeneration::compute_new_size().
50
// = (max_uintx / 5) + 1, = (18446744073709551615 / 5) + 1
51
static String INVALID_VALUE_1 = "3689348814741910324";
52
53
// This string is contained when compute_new_size() expands or shrinks.
54
static final String LOG_NEWSIZE_CHANGED = "New generation size ";
55
56
public static void main(String[] args) throws Exception {
57
if (Platform.is32bit()) {
58
// (max_uintx / 5) + 1, 4294967295/5 + 1
59
INVALID_VALUE_1 = "858993460";
60
}
61
62
// New size will be applied as NewSizeThreadIncrease is small enough to expand.
63
runNewSizeThreadIncreaseTest(VALID_VALUE, true);
64
65
// New size will be ignored as 'thread count * NewSizeThreadIncrease' overflows.
66
runNewSizeThreadIncreaseTest(INVALID_VALUE_1, false);
67
}
68
69
static void runNewSizeThreadIncreaseTest(String expectedValue, boolean isNewsizeChanged) throws Exception {
70
ProcessBuilder pb = GCArguments.createJavaProcessBuilder("-XX:+UseSerialGC",
71
"-Xms96M",
72
"-Xmx128M",
73
"-XX:NewRatio=2",
74
"-Xlog:gc+heap+ergo=debug",
75
"-XX:NewSizeThreadIncrease="+expectedValue,
76
GCTest.class.getName());
77
OutputAnalyzer output = new OutputAnalyzer(pb.start());
78
79
output.shouldHaveExitValue(0);
80
81
if (isNewsizeChanged) {
82
output.shouldContain(LOG_NEWSIZE_CHANGED);
83
} else {
84
output.shouldNotContain(LOG_NEWSIZE_CHANGED);
85
}
86
}
87
88
static class GCTest {
89
90
static final int MAX_THREADS_COUNT = 4;
91
static TestThread threads[] = new TestThread[MAX_THREADS_COUNT];
92
93
public static void main(String[] args) {
94
95
System.out.println("Creating garbage");
96
97
for (int i=0; i<MAX_THREADS_COUNT; i++) {
98
threads[i] = new TestThread();
99
threads[i].start();
100
}
101
102
System.gc();
103
104
for (int i=0; i<MAX_THREADS_COUNT; i++) {
105
threads[i].stopRunning();
106
}
107
108
System.out.println("Done");
109
}
110
111
private static class TestThread extends Thread {
112
113
volatile boolean isRunning = true;
114
115
public void run() {
116
while (isRunning == true) {
117
try {
118
Thread.sleep(10);
119
} catch (Throwable t) {
120
}
121
}
122
}
123
124
public void stopRunning() {
125
isRunning = false;
126
}
127
}
128
}
129
}
130
131