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

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

author
zgu
date
Fri, 08 Feb 2019 16:34:52 -0500
changeset 9621
c3abd2b71b9a
parent 9620
97d605522fcb
child 9622
1abddcd038df

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

src/share/vm/prims/whitebox.cpp file | annotate | diff | comparison | revisions
src/share/vm/services/memReporter.cpp file | annotate | diff | comparison | revisions
test/runtime/NMT/MallocSiteTypeChange.java file | annotate | diff | comparison | revisions
test/testlibrary/whitebox/sun/hotspot/WhiteBox.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/prims/whitebox.cpp	Mon Feb 25 21:38:45 2019 +0000
     1.2 +++ b/src/share/vm/prims/whitebox.cpp	Fri Feb 08 16:34:52 2019 -0500
     1.3 @@ -371,6 +371,13 @@
     1.4    return (jlong)(uintptr_t)os::malloc(size, mtTest, stack);
     1.5  WB_END
     1.6  
     1.7 +// Alloc memory with pseudo call stack and specific memory type.
     1.8 +WB_ENTRY(jlong, WB_NMTMallocWithPseudoStackAndType(JNIEnv* env, jobject o, jlong size, jint pseudo_stack, jint type))
     1.9 +  address pc = (address)(size_t)pseudo_stack;
    1.10 +  NativeCallStack stack(&pc, 1);
    1.11 +  return (jlong)(uintptr_t)os::malloc(size, (MEMFLAGS)type, stack);
    1.12 +WB_END
    1.13 +
    1.14  // Free the memory allocated by NMTAllocTest
    1.15  WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem))
    1.16    os::free((void*)(uintptr_t)mem, mtTest);
    1.17 @@ -1081,6 +1088,7 @@
    1.18  #if INCLUDE_NMT
    1.19    {CC"NMTMalloc",           CC"(J)J",                 (void*)&WB_NMTMalloc          },
    1.20    {CC"NMTMallocWithPseudoStack", CC"(JI)J",           (void*)&WB_NMTMallocWithPseudoStack},
    1.21 +  {CC"NMTMallocWithPseudoStackAndType", CC"(JII)J",   (void*)&WB_NMTMallocWithPseudoStackAndType},
    1.22    {CC"NMTFree",             CC"(J)V",                 (void*)&WB_NMTFree            },
    1.23    {CC"NMTReserveMemory",    CC"(J)J",                 (void*)&WB_NMTReserveMemory   },
    1.24    {CC"NMTCommitMemory",     CC"(JJ)V",                (void*)&WB_NMTCommitMemory    },
     2.1 --- a/src/share/vm/services/memReporter.cpp	Mon Feb 25 21:38:45 2019 +0000
     2.2 +++ b/src/share/vm/services/memReporter.cpp	Fri Feb 08 16:34:52 2019 -0500
     2.3 @@ -572,9 +572,15 @@
     2.4  
     2.5  void MemDetailDiffReporter::diff_malloc_site(const MallocSite* early,
     2.6    const MallocSite* current)  const {
     2.7 -  assert(early->flags() == current->flags(), "Must be the same memory type");
     2.8 -  diff_malloc_site(current->call_stack(), current->size(), current->count(),
     2.9 -    early->size(), early->count(), early->flags());
    2.10 +  if (early->flags() != current->flags()) {
    2.11 +    // If malloc site type changed, treat it as deallocation of old type and
    2.12 +    // allocation of new type.
    2.13 +    old_malloc_site(early);
    2.14 +    new_malloc_site(current);
    2.15 +  } else {
    2.16 +    diff_malloc_site(current->call_stack(), current->size(), current->count(),
    2.17 +      early->size(), early->count(), early->flags());
    2.18 +  }
    2.19  }
    2.20  
    2.21  void MemDetailDiffReporter::diff_malloc_site(const NativeCallStack* stack, size_t current_size,
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/runtime/NMT/MallocSiteTypeChange.java	Fri Feb 08 16:34:52 2019 -0500
     3.3 @@ -0,0 +1,69 @@
     3.4 +/*
     3.5 + * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + *
    3.26 + */
    3.27 +
    3.28 +/*
    3.29 + * @test MallocSiteTypeChange
    3.30 + * @summary Test a malloc site type change results NMT to report deallocation of old type and allocation of new type
    3.31 + * @bug 8200109
    3.32 + * @key nmt jcmd
    3.33 + * @modules java.base/jdk.internal.misc
    3.34 + * @library /testlibrary /testlibrary/whitebox
    3.35 + * @build sun.hotspot.WhiteBox
    3.36 + * @run driver ClassFileInstaller sun.hotspot.WhiteBox
    3.37 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocSiteTypeChange
    3.38 + */
    3.39 +
    3.40 +import com.oracle.java.testlibrary.*;
    3.41 +import sun.hotspot.WhiteBox;
    3.42 +
    3.43 +public class MallocSiteTypeChange {
    3.44 +    public static void main(String args[]) throws Exception {
    3.45 +        OutputAnalyzer output;
    3.46 +        WhiteBox wb = WhiteBox.getWhiteBox();
    3.47 +
    3.48 +        // Grab my own PID
    3.49 +        String pid = Long.toString(ProcessTools.getProcessId());
    3.50 +        ProcessBuilder pb = new ProcessBuilder();
    3.51 +
    3.52 +        int pc = 1;
    3.53 +        long addr = wb.NMTMallocWithPseudoStack(4 * 1024, pc);
    3.54 +
    3.55 +        // Verify that current tracking level is "detail"
    3.56 +        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"});
    3.57 +        output = new OutputAnalyzer(pb.start());
    3.58 +        output.shouldContain("Test (reserved=4KB, committed=4KB)");
    3.59 +
    3.60 +        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "baseline"});
    3.61 +        output = new OutputAnalyzer(pb.start());
    3.62 +        output.shouldContain("Baseline succeeded");
    3.63 +
    3.64 +        wb.NMTFree(addr);
    3.65 +        addr = wb.NMTMallocWithPseudoStackAndType(2 * 1024, pc, 7 /* mtInternal */ );
    3.66 +        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail.diff"});
    3.67 +        output = new OutputAnalyzer(pb.start());
    3.68 +        output.shouldContain("(malloc=0KB type=Test -4KB)");
    3.69 +        output.shouldContain("(malloc=2KB type=Internal +2KB #1 +1)");
    3.70 +        output.shouldHaveExitValue(0);
    3.71 +  }
    3.72 +}
     4.1 --- a/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java	Mon Feb 25 21:38:45 2019 +0000
     4.2 +++ b/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java	Fri Feb 08 16:34:52 2019 -0500
     4.3 @@ -1,5 +1,5 @@
     4.4  /*
     4.5 - * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
     4.6 + * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     4.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.8   *
     4.9   * This code is free software; you can redistribute it and/or modify it
    4.10 @@ -117,6 +117,7 @@
    4.11    public native void NMTUncommitMemory(long addr, long size);
    4.12    public native void NMTReleaseMemory(long addr, long size);
    4.13    public native long NMTMallocWithPseudoStack(long size, int index);
    4.14 +  public native long NMTMallocWithPseudoStackAndType(long size, int index, int type);
    4.15    public native boolean NMTIsDetailSupported();
    4.16    public native boolean NMTChangeTrackingLevel();
    4.17    public native int NMTGetHashSize();

mercurial