author | gtriantafill |
Mon, 18 Aug 2014 11:56:12 -0700 | |
changeset 26147 | 8f797b3ef01e |
parent 25948 | 9b33776f4f07 |
child 26149 | dd15a4c3746b |
permissions | -rw-r--r-- |
16666 | 1 |
/* |
25948
9b33776f4f07
8044140: Create NMT (Native Memory Tracking) tests for NMT2
zgu
parents:
19554
diff
changeset
|
2 |
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
16666 | 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 |
/* |
|
25 |
* @test |
|
26 |
* @key nmt jcmd |
|
27 |
* @library /testlibrary /testlibrary/whitebox |
|
28 |
* @build ThreadedVirtualAllocTestType |
|
29 |
* @run main ClassFileInstaller sun.hotspot.WhiteBox |
|
30 |
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail ThreadedVirtualAllocTestType |
|
31 |
*/ |
|
32 |
||
33 |
import com.oracle.java.testlibrary.*; |
|
34 |
import sun.hotspot.WhiteBox; |
|
35 |
||
36 |
public class ThreadedVirtualAllocTestType { |
|
37 |
public static long addr; |
|
38 |
public static final WhiteBox wb = WhiteBox.getWhiteBox(); |
|
39 |
public static final long commitSize = 128 * 1024; |
|
40 |
public static final long reserveSize = 512 * 1024; |
|
41 |
||
42 |
public static void main(String args[]) throws Exception { |
|
43 |
OutputAnalyzer output; |
|
44 |
||
45 |
String pid = Integer.toString(ProcessTools.getProcessId()); |
|
46 |
ProcessBuilder pb = new ProcessBuilder(); |
|
47 |
||
19554
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
48 |
boolean has_nmt_detail = wb.NMTIsDetailSupported(); |
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
49 |
if (has_nmt_detail) { |
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
50 |
System.out.println("NMT detail support detected."); |
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
51 |
} else { |
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
52 |
System.out.println("NMT detail support not detected."); |
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
53 |
} |
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
54 |
|
16666 | 55 |
Thread reserveThread = new Thread() { |
56 |
public void run() { |
|
57 |
addr = wb.NMTReserveMemory(reserveSize); |
|
58 |
} |
|
59 |
}; |
|
60 |
reserveThread.start(); |
|
61 |
reserveThread.join(); |
|
62 |
||
63 |
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail"}); |
|
64 |
output = new OutputAnalyzer(pb.start()); |
|
65 |
output.shouldContain("Test (reserved=512KB, committed=0KB)"); |
|
19554
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
66 |
if (has_nmt_detail) { |
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
67 |
output.shouldMatch("\\[0x[0]*" + Long.toHexString(addr) + " - 0x[0]*" + Long.toHexString(addr + reserveSize) + "\\] reserved 512KB for Test"); |
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
68 |
} |
16666 | 69 |
|
70 |
Thread commitThread = new Thread() { |
|
71 |
public void run() { |
|
72 |
wb.NMTCommitMemory(addr, commitSize); |
|
73 |
} |
|
74 |
}; |
|
75 |
commitThread.start(); |
|
76 |
commitThread.join(); |
|
77 |
||
78 |
output = new OutputAnalyzer(pb.start()); |
|
79 |
output.shouldContain("Test (reserved=512KB, committed=128KB)"); |
|
19554
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
80 |
if (has_nmt_detail) { |
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
81 |
output.shouldMatch("\\[0x[0]*" + Long.toHexString(addr) + " - 0x[0]*" + Long.toHexString(addr + commitSize) + "\\] committed 128KB"); |
3f21e829c7de
8020829: JT_HS: 2 runtime NMT tests fail on platforms if NMT detail is not supported
cjplummer
parents:
16666
diff
changeset
|
82 |
} |
16666 | 83 |
|
84 |
Thread uncommitThread = new Thread() { |
|
85 |
public void run() { |
|
86 |
wb.NMTUncommitMemory(addr, commitSize); |
|
87 |
} |
|
88 |
}; |
|
89 |
uncommitThread.start(); |
|
90 |
uncommitThread.join(); |
|
91 |
||
92 |
output = new OutputAnalyzer(pb.start()); |
|
93 |
output.shouldContain("Test (reserved=512KB, committed=0KB)"); |
|
94 |
output.shouldNotMatch("\\[0x[0]*" + Long.toHexString(addr) + " - 0x[0]*" + Long.toHexString(addr + commitSize) + "\\] committed"); |
|
95 |
||
96 |
Thread releaseThread = new Thread() { |
|
97 |
public void run() { |
|
98 |
wb.NMTReleaseMemory(addr, reserveSize); |
|
99 |
} |
|
100 |
}; |
|
101 |
releaseThread.start(); |
|
102 |
releaseThread.join(); |
|
103 |
||
104 |
output = new OutputAnalyzer(pb.start()); |
|
105 |
output.shouldNotContain("Test (reserved="); |
|
106 |
output.shouldNotContain("\\[0x[0]*" + Long.toHexString(addr) + " - 0x[0]*" + Long.toHexString(addr + reserveSize) + "\\] reserved"); |
|
107 |
} |
|
108 |
||
109 |
} |