test/runtime/NMT/MallocSiteTypeChange.java

Fri, 08 Feb 2019 16:34:52 -0500

author
zgu
date
Fri, 08 Feb 2019 16:34:52 -0500
changeset 9621
c3abd2b71b9a
permissions
-rw-r--r--

8200109: NMT: diff_malloc_site assert(early->flags() == current->flags(), "Must be the same memory type")
Reviewed-by: shade, coleenp

     1 /*
     2  * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 /*
    26  * @test MallocSiteTypeChange
    27  * @summary Test a malloc site type change results NMT to report deallocation of old type and allocation of new type
    28  * @bug 8200109
    29  * @key nmt jcmd
    30  * @modules java.base/jdk.internal.misc
    31  * @library /testlibrary /testlibrary/whitebox
    32  * @build sun.hotspot.WhiteBox
    33  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
    34  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocSiteTypeChange
    35  */
    37 import com.oracle.java.testlibrary.*;
    38 import sun.hotspot.WhiteBox;
    40 public class MallocSiteTypeChange {
    41     public static void main(String args[]) throws Exception {
    42         OutputAnalyzer output;
    43         WhiteBox wb = WhiteBox.getWhiteBox();
    45         // Grab my own PID
    46         String pid = Long.toString(ProcessTools.getProcessId());
    47         ProcessBuilder pb = new ProcessBuilder();
    49         int pc = 1;
    50         long addr = wb.NMTMallocWithPseudoStack(4 * 1024, pc);
    52         // Verify that current tracking level is "detail"
    53         pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
    54         output = new OutputAnalyzer(pb.start());
    55         output.shouldContain("Test (reserved=4KB, committed=4KB)");
    57         pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "baseline"});
    58         output = new OutputAnalyzer(pb.start());
    59         output.shouldContain("Baseline succeeded");
    61         wb.NMTFree(addr);
    62         addr = wb.NMTMallocWithPseudoStackAndType(2 * 1024, pc, 7 /* mtInternal */ );
    63         pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail.diff"});
    64         output = new OutputAnalyzer(pb.start());
    65         output.shouldContain("(malloc=0KB type=Test -4KB)");
    66         output.shouldContain("(malloc=2KB type=Internal +2KB #1 +1)");
    67         output.shouldHaveExitValue(0);
    68   }
    69 }

mercurial