Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/NMT/HugeArenaTracking.java
32284 views
1
/*
2
* Copyright (c) 2019, Red Hat, Inc. All rights reserved.
3
*
4
* This code is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 2 only, as
6
* published by the Free Software Foundation.
7
*
8
* This code is distributed in the hope that it will be useful, but WITHOUT
9
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11
* version 2 for more details (a copy is included in the LICENSE file that
12
* accompanied this code).
13
*
14
* You should have received a copy of the GNU General Public License version
15
* 2 along with this work; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
*
18
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19
* or visit www.oracle.com if you need additional information or have any
20
* questions.
21
*
22
*/
23
24
/*
25
* @test
26
* @key nmt jcmd
27
* @library /testlibrary /testlibrary/whitebox
28
* @build HugeArenaTracking
29
* @run main ClassFileInstaller sun.hotspot.WhiteBox
30
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail HugeArenaTracking
31
*/
32
33
import java.util.Random;
34
import com.oracle.java.testlibrary.*;
35
import sun.hotspot.WhiteBox;
36
37
public class HugeArenaTracking {
38
private static final long GB = 1024 * 1024 * 1024;
39
40
public static void main(String args[]) throws Exception {
41
OutputAnalyzer output;
42
final WhiteBox wb = WhiteBox.getWhiteBox();
43
44
// Grab my own PID
45
String pid = Long.toString(ProcessTools.getProcessId());
46
ProcessBuilder pb = new ProcessBuilder();
47
48
long arena1 = wb.NMTNewArena(1024);
49
long arena2 = wb.NMTNewArena(1024);
50
51
// Run 'jcmd <pid> VM.native_memory summary'
52
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
53
output = new OutputAnalyzer(pb.start());
54
output.shouldContain("Test (reserved=2KB, committed=2KB)");
55
56
Random rand = new Random();
57
58
// Allocate 2GB+ from arena
59
long total = 0;
60
while (total < 2 * GB) {
61
// Cap to 10M
62
long inc = rand.nextInt(10 * 1024 * 1024);
63
wb.NMTArenaMalloc(arena1, inc);
64
total += inc;
65
}
66
67
ProcessBuilder pb2 = new ProcessBuilder();
68
// Run 'jcmd <pid> VM.native_memory summary'
69
pb2.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary", "scale=GB"});
70
output = new OutputAnalyzer(pb2.start());
71
output.shouldContain("Test (reserved=2GB, committed=2GB)");
72
73
wb.NMTFreeArena(arena1);
74
75
output = new OutputAnalyzer(pb.start());
76
output.shouldContain("Test (reserved=1KB, committed=1KB)");
77
wb.NMTFreeArena(arena2);
78
79
output = new OutputAnalyzer(pb.start());
80
output.shouldNotContain("Test (reserved");
81
}
82
}
83
84