Wed, 10 Sep 2014 19:05:54 +0000
Merge
1.1 --- a/test/TEST.groups Tue Sep 09 15:47:18 2014 -0700 1.2 +++ b/test/TEST.groups Wed Sep 10 19:05:54 2014 +0000 1.3 @@ -82,6 +82,7 @@ 1.4 runtime/NMT/MallocSiteHashOverflow.java \ 1.5 runtime/NMT/MallocStressTest.java \ 1.6 runtime/NMT/MallocTestType.java \ 1.7 + runtime/NMT/MallocTrackingVerify.java \ 1.8 runtime/NMT/ReleaseCommittedMemory.java \ 1.9 runtime/NMT/ReleaseNoCommit.java \ 1.10 runtime/NMT/ShutdownTwice.java \
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/runtime/NMT/MallocTrackingVerify.java Wed Sep 10 19:05:54 2014 +0000 2.3 @@ -0,0 +1,105 @@ 2.4 +/* 2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 8054836 2.30 + * @summary Test to verify correctness of malloc tracking 2.31 + * @key nmt jcmd 2.32 + * @library /testlibrary /testlibrary/whitebox 2.33 + * @build MallocTrackingVerify 2.34 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 2.35 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocTrackingVerify 2.36 + * 2.37 + */ 2.38 + 2.39 +import java.util.ArrayList; 2.40 +import java.util.Random; 2.41 + 2.42 +import com.oracle.java.testlibrary.*; 2.43 + 2.44 +import sun.hotspot.WhiteBox; 2.45 + 2.46 +public class MallocTrackingVerify { 2.47 + private static int MAX_ALLOC = 4 * 1024; 2.48 + 2.49 + static ArrayList<MallocMemory> mallocd_memory = new ArrayList<MallocMemory>(); 2.50 + static long mallocd_total = 0; 2.51 + public static WhiteBox wb = WhiteBox.getWhiteBox(); 2.52 + 2.53 + public static void main(String args[]) throws Exception { 2.54 + OutputAnalyzer output; 2.55 + 2.56 + // Grab my own PID 2.57 + String pid = Integer.toString(ProcessTools.getProcessId()); 2.58 + ProcessBuilder pb = new ProcessBuilder(); 2.59 + 2.60 + Random random = new Random(); 2.61 + // Allocate small amounts of memory with random pseudo call stack 2.62 + while (mallocd_total < MAX_ALLOC) { 2.63 + int size = random.nextInt(31) + 1; 2.64 + long addr = wb.NMTMallocWithPseudoStack(size, random.nextInt()); 2.65 + if (addr != 0) { 2.66 + MallocMemory mem = new MallocMemory(addr, size); 2.67 + mallocd_memory.add(mem); 2.68 + mallocd_total += size; 2.69 + } else { 2.70 + System.out.println("Out of malloc memory"); 2.71 + break; 2.72 + } 2.73 + } 2.74 + 2.75 + pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary" }); 2.76 + output = new OutputAnalyzer(pb.start()); 2.77 + output.shouldContain("Test (reserved=4KB, committed=4KB)"); 2.78 + 2.79 + // Free 2.80 + for (MallocMemory mem : mallocd_memory) { 2.81 + wb.NMTFree(mem.addr()); 2.82 + } 2.83 + 2.84 + // Run 'jcmd <pid> VM.native_memory summary', check for expected output 2.85 + pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, 2.86 + "VM.native_memory", "summary" }); 2.87 + output = new OutputAnalyzer(pb.start()); 2.88 + output.shouldNotContain("Test (reserved="); 2.89 + } 2.90 + 2.91 + static class MallocMemory { 2.92 + private long addr; 2.93 + private int size; 2.94 + 2.95 + MallocMemory(long addr, int size) { 2.96 + this.addr = addr; 2.97 + this.size = size; 2.98 + } 2.99 + 2.100 + long addr() { 2.101 + return this.addr; 2.102 + } 2.103 + 2.104 + int size() { 2.105 + return this.size; 2.106 + } 2.107 + } 2.108 +}