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