test/runtime/NMT/MallocTestType.java

Wed, 03 Apr 2013 21:41:33 +0200

author
ctornqvi
date
Wed, 03 Apr 2013 21:41:33 +0200
changeset 4885
3b890cd4da64
parent 4637
test/runtime/NMT/AllocTestType.java@1b0dc9f87e75
child 6876
710a3c8b516e
child 7075
ac12996df59b
permissions
-rw-r--r--

8009125: Add NMT tests for Virtual Memory operations
Summary: Tests added for Reserve/Commit/Uncommit/Unreserve operations
Reviewed-by: zgu, mgerdin

ctornqvi@4518 1 /*
ctornqvi@4518 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
ctornqvi@4518 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ctornqvi@4518 4 *
ctornqvi@4518 5 * This code is free software; you can redistribute it and/or modify it
ctornqvi@4518 6 * under the terms of the GNU General Public License version 2 only, as
ctornqvi@4518 7 * published by the Free Software Foundation.
ctornqvi@4518 8 *
ctornqvi@4518 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ctornqvi@4518 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ctornqvi@4518 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ctornqvi@4518 12 * version 2 for more details (a copy is included in the LICENSE file that
ctornqvi@4518 13 * accompanied this code).
ctornqvi@4518 14 *
ctornqvi@4518 15 * You should have received a copy of the GNU General Public License version
ctornqvi@4518 16 * 2 along with this work; if not, write to the Free Software Foundation,
ctornqvi@4518 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ctornqvi@4518 18 *
ctornqvi@4518 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ctornqvi@4518 20 * or visit www.oracle.com if you need additional information or have any
ctornqvi@4518 21 * questions.
ctornqvi@4518 22 */
ctornqvi@4518 23
ctornqvi@4518 24 /*
ctornqvi@4518 25 * @test
ctornqvi@4518 26 * @summary Test consistency of NMT by leaking a few select allocations of the Test type and then verify visibility with jcmd
ctornqvi@4518 27 * @key nmt jcmd
mgerdin@4637 28 * @library /testlibrary /testlibrary/whitebox
ctornqvi@4885 29 * @build MallocTestType
mgerdin@4637 30 * @run main ClassFileInstaller sun.hotspot.WhiteBox
ctornqvi@4885 31 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocTestType
ctornqvi@4518 32 */
ctornqvi@4518 33
ctornqvi@4518 34 import com.oracle.java.testlibrary.*;
ctornqvi@4518 35 import sun.hotspot.WhiteBox;
ctornqvi@4518 36
ctornqvi@4885 37 public class MallocTestType {
ctornqvi@4518 38
ctornqvi@4518 39 public static void main(String args[]) throws Exception {
ctornqvi@4518 40 OutputAnalyzer output;
ctornqvi@4885 41 WhiteBox wb = WhiteBox.getWhiteBox();
ctornqvi@4518 42
ctornqvi@4518 43 // Grab my own PID
ctornqvi@4518 44 String pid = Integer.toString(ProcessTools.getProcessId());
ctornqvi@4518 45 ProcessBuilder pb = new ProcessBuilder();
ctornqvi@4518 46
ctornqvi@4885 47 // Use WB API to alloc and free with the mtTest type
ctornqvi@4885 48 long memAlloc3 = wb.NMTMalloc(128 * 1024);
ctornqvi@4885 49 long memAlloc2 = wb.NMTMalloc(256 * 1024);
ctornqvi@4885 50 wb.NMTFree(memAlloc3);
ctornqvi@4885 51 long memAlloc1 = wb.NMTMalloc(512 * 1024);
ctornqvi@4885 52 wb.NMTFree(memAlloc2);
ctornqvi@4518 53
ctornqvi@4518 54 // Use WB API to ensure that all data has been merged before we continue
ctornqvi@4885 55 if (!wb.NMTWaitForDataMerge()) {
ctornqvi@4518 56 throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
ctornqvi@4518 57 }
ctornqvi@4518 58
ctornqvi@4518 59 // Run 'jcmd <pid> VM.native_memory summary'
ctornqvi@4518 60 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
ctornqvi@4518 61 output = new OutputAnalyzer(pb.start());
ctornqvi@4518 62 output.shouldContain("Test (reserved=512KB, committed=512KB)");
ctornqvi@4518 63
ctornqvi@4518 64 // Free the memory allocated by NMTAllocTest
ctornqvi@4885 65 wb.NMTFree(memAlloc1);
ctornqvi@4518 66
ctornqvi@4518 67 // Use WB API to ensure that all data has been merged before we continue
ctornqvi@4885 68 if (!wb.NMTWaitForDataMerge()) {
ctornqvi@4518 69 throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
ctornqvi@4518 70 }
ctornqvi@4518 71 output = new OutputAnalyzer(pb.start());
ctornqvi@4518 72 output.shouldNotContain("Test (reserved=");
ctornqvi@4518 73 }
ctornqvi@4518 74 }

mercurial