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