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 /test/lib |
|
28 * @modules java.base/jdk.internal.misc |
|
29 * java.management |
|
30 * @build sun.hotspot.WhiteBox |
|
31 * @run driver ClassFileInstaller sun.hotspot.WhiteBox |
|
32 * sun.hotspot.WhiteBox$WhiteBoxPermission |
|
33 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail HugeArenaTracking |
|
34 */ |
|
35 |
|
36 import jdk.test.lib.process.ProcessTools; |
|
37 import jdk.test.lib.process.OutputAnalyzer; |
|
38 import jdk.test.lib.JDKToolFinder; |
|
39 import sun.hotspot.WhiteBox; |
|
40 |
|
41 public class HugeArenaTracking { |
|
42 private static final long GB = 1024 * 1024 * 1024; |
|
43 |
|
44 public static void main(String args[]) throws Exception { |
|
45 OutputAnalyzer output; |
|
46 final WhiteBox wb = WhiteBox.getWhiteBox(); |
|
47 |
|
48 // Grab my own PID |
|
49 String pid = Long.toString(ProcessTools.getProcessId()); |
|
50 ProcessBuilder pb = new ProcessBuilder(); |
|
51 |
|
52 long arena1 = wb.NMTNewArena(1024); |
|
53 long arena2 = wb.NMTNewArena(1024); |
|
54 |
|
55 // Run 'jcmd <pid> VM.native_memory summary' |
|
56 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"}); |
|
57 output = new OutputAnalyzer(pb.start()); |
|
58 output.shouldContain("Test (reserved=2KB, committed=2KB)"); |
|
59 |
|
60 // Allocate 2GB+ from arena |
|
61 long total = 0; |
|
62 while (total < 2 * GB) { |
|
63 wb.NMTArenaMalloc(arena1, 4096); |
|
64 total += 4096; |
|
65 } |
|
66 wb.NMTFreeArena(arena1); |
|
67 |
|
68 output = new OutputAnalyzer(pb.start()); |
|
69 output.shouldContain("Test (reserved=1KB, committed=1KB)"); |
|
70 wb.NMTFreeArena(arena2); |
|
71 |
|
72 output = new OutputAnalyzer(pb.start()); |
|
73 output.shouldNotContain("Test (reserved"); |
|
74 } |
|
75 } |
|