Mercurial > hg > truffle
annotate test/runtime/NMT/MallocTrackingVerify.java @ 21864:e44b10693a44
Added tag jdk8u45-b11 for changeset f4822d122041
author | asaha |
---|---|
date | Mon, 09 Mar 2015 12:35:33 -0700 |
parents | 4edd7572c235 |
children |
rev | line source |
---|---|
20442
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
1 /* |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
4edd7572c235
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. |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
4 * |
4edd7572c235
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 |
4edd7572c235
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 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
8 * |
4edd7572c235
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 |
4edd7572c235
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 |
4edd7572c235
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 |
4edd7572c235
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 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
13 * accompanied this code). |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
14 * |
4edd7572c235
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 |
4edd7572c235
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, |
4edd7572c235
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. |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
18 * |
4edd7572c235
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 |
4edd7572c235
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 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
21 * questions. |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
22 */ |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
23 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
24 /* |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
25 * @test |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
26 * @bug 8054836 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
27 * @summary Test to verify correctness of malloc tracking |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
28 * @key nmt jcmd |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
29 * @library /testlibrary /testlibrary/whitebox |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
30 * @build MallocTrackingVerify |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
31 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
32 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocTrackingVerify |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
33 * |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
34 */ |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
35 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
36 import java.util.ArrayList; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
37 import java.util.Random; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
38 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
39 import com.oracle.java.testlibrary.*; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
40 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
41 import sun.hotspot.WhiteBox; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
42 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
43 public class MallocTrackingVerify { |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
44 private static int MAX_ALLOC = 4 * 1024; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
45 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
46 static ArrayList<MallocMemory> mallocd_memory = new ArrayList<MallocMemory>(); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
47 static long mallocd_total = 0; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
48 public static WhiteBox wb = WhiteBox.getWhiteBox(); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
49 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
50 public static void main(String args[]) throws Exception { |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
51 OutputAnalyzer output; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
52 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
53 // Grab my own PID |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
54 String pid = Integer.toString(ProcessTools.getProcessId()); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
55 ProcessBuilder pb = new ProcessBuilder(); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
56 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
57 Random random = new Random(); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
58 // Allocate small amounts of memory with random pseudo call stack |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
59 while (mallocd_total < MAX_ALLOC) { |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
60 int size = random.nextInt(31) + 1; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
61 long addr = wb.NMTMallocWithPseudoStack(size, random.nextInt()); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
62 if (addr != 0) { |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
63 MallocMemory mem = new MallocMemory(addr, size); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
64 mallocd_memory.add(mem); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
65 mallocd_total += size; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
66 } else { |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
67 System.out.println("Out of malloc memory"); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
68 break; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
69 } |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
70 } |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
71 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
72 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary" }); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
73 output = new OutputAnalyzer(pb.start()); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
74 output.shouldContain("Test (reserved=4KB, committed=4KB)"); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
75 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
76 // Free |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
77 for (MallocMemory mem : mallocd_memory) { |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
78 wb.NMTFree(mem.addr()); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
79 } |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
80 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
81 // Run 'jcmd <pid> VM.native_memory summary', check for expected output |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
82 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
83 "VM.native_memory", "summary" }); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
84 output = new OutputAnalyzer(pb.start()); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
85 output.shouldNotContain("Test (reserved="); |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
86 } |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
87 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
88 static class MallocMemory { |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
89 private long addr; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
90 private int size; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
91 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
92 MallocMemory(long addr, int size) { |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
93 this.addr = addr; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
94 this.size = size; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
95 } |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
96 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
97 long addr() { |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
98 return this.addr; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
99 } |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
100 |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
101 int size() { |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
102 return this.size; |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
103 } |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
104 } |
4edd7572c235
8054836: [TESTBUG] Test is needed to verify correctness of malloc tracking
gtriantafill
parents:
diff
changeset
|
105 } |