Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/g1/TestHumongousCodeCacheRoots.java
40942 views
1
/*
2
* Copyright (c) 2013, 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.g1;
25
26
/*
27
* @test
28
* @bug 8027756
29
* @requires vm.gc.G1
30
* @library /test/lib
31
* @modules java.base/jdk.internal.misc
32
* java.management
33
* @build sun.hotspot.WhiteBox
34
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
35
* @summary Humongous objects may have references from the code cache
36
* @run driver gc.g1.TestHumongousCodeCacheRoots
37
*/
38
39
import jdk.test.lib.process.OutputAnalyzer;
40
import jdk.test.lib.process.ProcessTools;
41
import sun.hotspot.WhiteBox;
42
43
import java.util.ArrayList;
44
import java.util.Arrays;
45
46
class TestHumongousCodeCacheRootsHelper {
47
48
static final int n = 1000000;
49
static final int[] AA = new int[n];
50
static final int[] BB = new int[n];
51
52
public static void main(String args[]) throws Exception {
53
// do some work so that the compiler compiles this method, inlining the
54
// reference to the integer array (which is a humonguous object) into
55
// the code cache.
56
for(int i = 0; i < n; i++) {
57
AA[i] = 0;
58
BB[i] = 0;
59
}
60
// trigger a GC that checks that the verification code allows humongous
61
// objects with code cache roots; objects should be all live here.
62
System.gc();
63
64
// deoptimize everyhing: this should make all compiled code zombies.
65
WhiteBox wb = WhiteBox.getWhiteBox();
66
wb.deoptimizeAll();
67
68
// trigger a GC that checks that the verification code allows humongous
69
// objects with code cache roots; objects should be all live here.
70
System.gc();
71
72
// wait a little for the code cache sweeper to try to clean up zombie nmethods
73
// and unregister the code roots.
74
try { Thread.sleep(5000); } catch (InterruptedException ex) { }
75
76
// do some work on the arrays to make sure that they need to be live after the GCs
77
for(int i = 0; i < n; i++) {
78
AA[i] = 1;
79
BB[i] = 10;
80
}
81
82
System.out.println();
83
}
84
}
85
86
public class TestHumongousCodeCacheRoots {
87
88
/**
89
* Executes a class in a new VM process with the given parameters.
90
* @param vmargs Arguments to the VM to run
91
* @param classname Name of the class to run
92
* @param arguments Arguments to the class
93
* @return The OutputAnalyzer with the results for the invocation.
94
*/
95
public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments) throws Exception {
96
ArrayList<String> finalargs = new ArrayList<String>();
97
98
String[] whiteboxOpts = new String[] {
99
"-Xbootclasspath/a:.",
100
"-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
101
"-cp", System.getProperty("java.class.path"),
102
};
103
104
finalargs.addAll(Arrays.asList(vmargs));
105
finalargs.addAll(Arrays.asList(whiteboxOpts));
106
finalargs.add(classname);
107
finalargs.addAll(Arrays.asList(arguments));
108
109
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs);
110
OutputAnalyzer output = new OutputAnalyzer(pb.start());
111
output.shouldHaveExitValue(0);
112
return output;
113
}
114
115
public static void main(String[] args) throws Exception {
116
final String[] baseArguments = new String[] {
117
"-XX:+UseG1GC", "-XX:G1HeapRegionSize=1M", "-Xmx100M", // make sure we get a humongous region
118
"-XX:+UnlockDiagnosticVMOptions",
119
"-XX:InitiatingHeapOccupancyPercent=1", // strong code root marking
120
"-XX:+G1VerifyHeapRegionCodeRoots", "-XX:+VerifyAfterGC", // make sure that verification is run
121
};
122
123
runWhiteBoxTest(baseArguments, TestHumongousCodeCacheRootsHelper.class.getName(), new String[] { });
124
}
125
}
126
127
128