ctornqvi@4518: /* ctornqvi@4518: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. ctornqvi@4518: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ctornqvi@4518: * ctornqvi@4518: * This code is free software; you can redistribute it and/or modify it ctornqvi@4518: * under the terms of the GNU General Public License version 2 only, as ctornqvi@4518: * published by the Free Software Foundation. ctornqvi@4518: * ctornqvi@4518: * This code is distributed in the hope that it will be useful, but WITHOUT ctornqvi@4518: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ctornqvi@4518: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ctornqvi@4518: * version 2 for more details (a copy is included in the LICENSE file that ctornqvi@4518: * accompanied this code). ctornqvi@4518: * ctornqvi@4518: * You should have received a copy of the GNU General Public License version ctornqvi@4518: * 2 along with this work; if not, write to the Free Software Foundation, ctornqvi@4518: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ctornqvi@4518: * ctornqvi@4518: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ctornqvi@4518: * or visit www.oracle.com if you need additional information or have any ctornqvi@4518: * questions. ctornqvi@4518: */ ctornqvi@4518: ctornqvi@4518: /* ctornqvi@4518: * @test ctornqvi@4518: * @summary Test consistency of NMT by leaking a few select allocations of the Test type and then verify visibility with jcmd ctornqvi@4518: * @key nmt jcmd mgerdin@4637: * @library /testlibrary /testlibrary/whitebox ctornqvi@4885: * @build MallocTestType mgerdin@4637: * @run main ClassFileInstaller sun.hotspot.WhiteBox ctornqvi@4885: * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocTestType ctornqvi@4518: */ ctornqvi@4518: ctornqvi@4518: import com.oracle.java.testlibrary.*; ctornqvi@4518: import sun.hotspot.WhiteBox; ctornqvi@4518: ctornqvi@4885: public class MallocTestType { ctornqvi@4518: ctornqvi@4518: public static void main(String args[]) throws Exception { ctornqvi@4518: OutputAnalyzer output; ctornqvi@4885: WhiteBox wb = WhiteBox.getWhiteBox(); ctornqvi@4518: ctornqvi@4518: // Grab my own PID ctornqvi@4518: String pid = Integer.toString(ProcessTools.getProcessId()); ctornqvi@4518: ProcessBuilder pb = new ProcessBuilder(); ctornqvi@4518: ctornqvi@4885: // Use WB API to alloc and free with the mtTest type ctornqvi@4885: long memAlloc3 = wb.NMTMalloc(128 * 1024); ctornqvi@4885: long memAlloc2 = wb.NMTMalloc(256 * 1024); ctornqvi@4885: wb.NMTFree(memAlloc3); ctornqvi@4885: long memAlloc1 = wb.NMTMalloc(512 * 1024); ctornqvi@4885: wb.NMTFree(memAlloc2); ctornqvi@4518: ctornqvi@4518: // Use WB API to ensure that all data has been merged before we continue ctornqvi@4885: if (!wb.NMTWaitForDataMerge()) { ctornqvi@4518: throw new Exception("Call to WB API NMTWaitForDataMerge() failed"); ctornqvi@4518: } ctornqvi@4518: ctornqvi@4518: // Run 'jcmd VM.native_memory summary' ctornqvi@4518: pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"}); ctornqvi@4518: output = new OutputAnalyzer(pb.start()); ctornqvi@4518: output.shouldContain("Test (reserved=512KB, committed=512KB)"); ctornqvi@4518: ctornqvi@4518: // Free the memory allocated by NMTAllocTest ctornqvi@4885: wb.NMTFree(memAlloc1); ctornqvi@4518: ctornqvi@4518: // Use WB API to ensure that all data has been merged before we continue ctornqvi@4885: if (!wb.NMTWaitForDataMerge()) { ctornqvi@4518: throw new Exception("Call to WB API NMTWaitForDataMerge() failed"); ctornqvi@4518: } ctornqvi@4518: output = new OutputAnalyzer(pb.start()); ctornqvi@4518: output.shouldNotContain("Test (reserved="); ctornqvi@4518: } ctornqvi@4518: }