author | goetz |
Tue, 30 Aug 2016 16:08:52 +0200 | |
changeset 41086 | 06b10263e509 |
parent 40631 | ed82623d7831 |
permissions | -rw-r--r-- |
26568
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
1 |
/* |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38089
diff
changeset
|
2 |
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
26568
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
4 |
* |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
8 |
* |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
13 |
* accompanied this code). |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
14 |
* |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
18 |
* |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
21 |
* questions. |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
22 |
*/ |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
23 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
24 |
/* |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
25 |
* @test |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
26 |
* @bug 8054836 |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
27 |
* @summary Test to verify correctness of malloc tracking |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
28 |
* @key nmt jcmd |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38089
diff
changeset
|
29 |
* @library /test/lib |
36851 | 30 |
* @modules java.base/jdk.internal.misc |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
28190
diff
changeset
|
31 |
* java.management |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38089
diff
changeset
|
32 |
* @build sun.hotspot.WhiteBox |
26568
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
33 |
* @run main ClassFileInstaller sun.hotspot.WhiteBox |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
34 |
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocTrackingVerify |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
35 |
* |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
36 |
*/ |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
37 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
38 |
import java.util.ArrayList; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
39 |
import java.util.Random; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
40 |
|
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38089
diff
changeset
|
41 |
import jdk.test.lib.process.ProcessTools; |
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38089
diff
changeset
|
42 |
import jdk.test.lib.process.OutputAnalyzer; |
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
38089
diff
changeset
|
43 |
import jdk.test.lib.JDKToolFinder; |
26568
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
44 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
45 |
import sun.hotspot.WhiteBox; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
46 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
47 |
public class MallocTrackingVerify { |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
48 |
private static int MAX_ALLOC = 4 * 1024; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
49 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
50 |
static ArrayList<MallocMemory> mallocd_memory = new ArrayList<MallocMemory>(); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
51 |
static long mallocd_total = 0; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
52 |
public static WhiteBox wb = WhiteBox.getWhiteBox(); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
53 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
54 |
public static void main(String args[]) throws Exception { |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
55 |
OutputAnalyzer output; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
56 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
57 |
// Grab my own PID |
38089
9e58203ef0e2
8153992: Some hotspot tests fail on compact2 due to an unnecessary test library dependency
akulyakh
parents:
36851
diff
changeset
|
58 |
String pid = Long.toString(ProcessTools.getProcessId()); |
26568
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
59 |
ProcessBuilder pb = new ProcessBuilder(); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
60 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
61 |
Random random = new Random(); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
62 |
// Allocate small amounts of memory with random pseudo call stack |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
63 |
while (mallocd_total < MAX_ALLOC) { |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
64 |
int size = random.nextInt(31) + 1; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
65 |
long addr = wb.NMTMallocWithPseudoStack(size, random.nextInt()); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
66 |
if (addr != 0) { |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
67 |
MallocMemory mem = new MallocMemory(addr, size); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
68 |
mallocd_memory.add(mem); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
69 |
mallocd_total += size; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
70 |
} else { |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
71 |
System.out.println("Out of malloc memory"); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
72 |
break; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
73 |
} |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
74 |
} |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
75 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
76 |
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary" }); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
77 |
output = new OutputAnalyzer(pb.start()); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
78 |
output.shouldContain("Test (reserved=4KB, committed=4KB)"); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
79 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
80 |
// Free |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
81 |
for (MallocMemory mem : mallocd_memory) { |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
82 |
wb.NMTFree(mem.addr()); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
83 |
} |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
84 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
85 |
// Run 'jcmd <pid> VM.native_memory summary', check for expected output |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
86 |
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
87 |
"VM.native_memory", "summary" }); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
88 |
output = new OutputAnalyzer(pb.start()); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
89 |
output.shouldNotContain("Test (reserved="); |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
90 |
} |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
91 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
92 |
static class MallocMemory { |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
93 |
private long addr; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
94 |
private int size; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
95 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
96 |
MallocMemory(long addr, int size) { |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
97 |
this.addr = addr; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
98 |
this.size = size; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
99 |
} |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
100 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
101 |
long addr() { |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
102 |
return this.addr; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
103 |
} |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
104 |
|
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
105 |
int size() { |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
106 |
return this.size; |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
107 |
} |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
108 |
} |
65dbacf42e6d
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
109 |
} |