Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/sa/TestG1HeapRegion.java
41149 views
1
/*
2
* Copyright (c) 2018, 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
import java.util.ArrayList;
25
import java.util.List;
26
27
import sun.jvm.hotspot.gc.g1.G1CollectedHeap;
28
import sun.jvm.hotspot.gc.g1.HeapRegion;
29
import sun.jvm.hotspot.HotSpotAgent;
30
import sun.jvm.hotspot.runtime.VM;
31
32
import jdk.test.lib.apps.LingeredApp;
33
import jdk.test.lib.Asserts;
34
import jdk.test.lib.Platform;
35
import jdk.test.lib.process.OutputAnalyzer;
36
import jdk.test.lib.process.ProcessTools;
37
import jdk.test.lib.SA.SATestUtils;
38
import jdk.test.lib.Utils;
39
40
/**
41
* @test
42
* @library /test/lib
43
* @requires vm.hasSA
44
* @requires vm.gc.G1
45
* @modules jdk.hotspot.agent/sun.jvm.hotspot
46
* jdk.hotspot.agent/sun.jvm.hotspot.gc.g1
47
* jdk.hotspot.agent/sun.jvm.hotspot.memory
48
* jdk.hotspot.agent/sun.jvm.hotspot.runtime
49
* @run driver TestG1HeapRegion
50
*/
51
52
public class TestG1HeapRegion {
53
54
private static LingeredApp theApp = null;
55
56
private static void checkHeapRegion(String pid) throws Exception {
57
HotSpotAgent agent = new HotSpotAgent();
58
59
try {
60
agent.attach(Integer.parseInt(pid));
61
G1CollectedHeap heap = (G1CollectedHeap)VM.getVM().getUniverse().heap();
62
HeapRegion hr = heap.hrm().heapRegionIterator().next();
63
HeapRegion hrTop = heap.hrm().getByAddress(hr.top());
64
65
Asserts.assertEquals(hr.top(), hrTop.top(),
66
"Address of HeapRegion does not match.");
67
} finally {
68
agent.detach();
69
}
70
}
71
72
private static void createAnotherToAttach(long lingeredAppPid)
73
throws Exception {
74
// Start a new process to attach to the lingered app
75
ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
76
"--add-modules=jdk.hotspot.agent",
77
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED",
78
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.gc.g1=ALL-UNNAMED",
79
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.memory=ALL-UNNAMED",
80
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.runtime=ALL-UNNAMED",
81
"TestG1HeapRegion",
82
Long.toString(lingeredAppPid));
83
SATestUtils.addPrivilegesIfNeeded(processBuilder);
84
OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);
85
SAOutput.shouldHaveExitValue(0);
86
System.out.println(SAOutput.getOutput());
87
}
88
89
public static void main (String... args) throws Exception {
90
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
91
if (args == null || args.length == 0) {
92
try {
93
theApp = new LingeredApp();
94
LingeredApp.startApp(theApp, "-XX:+UsePerfData", "-XX:+UseG1GC");
95
createAnotherToAttach(theApp.getPid());
96
} finally {
97
LingeredApp.stopApp(theApp);
98
}
99
} else {
100
checkHeapRegion(args[0]);
101
}
102
}
103
}
104
105