From 7bce3150597db69dfe520ef039307cdeb5de9160 Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Tue, 19 Aug 2014 09:05:55 -0400 Subject: [PATCH 1/5] 8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests Handled CDS mapping region and added test for the scenario Reviewed-by: coleenp, ctornqvi --- .../vm/services/virtualMemoryTracker.cpp | 14 ++++- hotspot/test/runtime/NMT/NMTWithCDS.java | 55 +++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 hotspot/test/runtime/NMT/NMTWithCDS.java diff --git a/hotspot/src/share/vm/services/virtualMemoryTracker.cpp b/hotspot/src/share/vm/services/virtualMemoryTracker.cpp index 4a6e20ab646..52e2f583b02 100644 --- a/hotspot/src/share/vm/services/virtualMemoryTracker.cpp +++ b/hotspot/src/share/vm/services/virtualMemoryTracker.cpp @@ -337,10 +337,18 @@ bool VirtualMemoryTracker::add_reserved_region(address base_addr, size_t size, *reserved_rgn = rgn; return true; - } else { - ShouldNotReachHere(); - return false; } + + // CDS mapping region. + // CDS reserves the whole region for mapping CDS archive, then maps each section into the region. + // NMT reports CDS as a whole. + if (reserved_rgn->flag() == mtClassShared) { + assert(reserved_rgn->contain_region(base_addr, size), "Reserved CDS region should contain this mapping region"); + return true; + } + + ShouldNotReachHere(); + return false; } } } diff --git a/hotspot/test/runtime/NMT/NMTWithCDS.java b/hotspot/test/runtime/NMT/NMTWithCDS.java new file mode 100644 index 00000000000..4672d3d5f75 --- /dev/null +++ b/hotspot/test/runtime/NMT/NMTWithCDS.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8055061 + * @key nmt + * @library /testlibrary + * @run main NMTWithCDS + */ +import com.oracle.java.testlibrary.*; + +public class NMTWithCDS { + + public static void main(String[] args) throws Exception { + ProcessBuilder pb; + pb = ProcessTools.createJavaProcessBuilder("-XX:SharedArchiveFile=./sample.jsa", "-Xshare:dump"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + try { + output.shouldContain("Loading classes to share"); + output.shouldHaveExitValue(0); + + pb = ProcessTools.createJavaProcessBuilder( + "-XX:NativeMemoryTracking=detail", "-XX:SharedArchiveFile=./sample.jsa", "-Xshare:on", "-version"); + output = new OutputAnalyzer(pb.start()); + output.shouldContain("sharing"); + output.shouldHaveExitValue(0); + + } catch (RuntimeException e) { + // Report 'passed' if CDS was turned off. + output.shouldContain("Unable to use shared archive"); + output.shouldHaveExitValue(1); + } + } +} From 8fe87f3da726108478b64c47ec28b9c986479267 Mon Sep 17 00:00:00 2001 From: George Triantafillou Date: Mon, 18 Aug 2014 11:56:12 -0700 Subject: [PATCH 2/5] 8054711: [TESTBUG] Enable NMT2 tests after NMT2 is integrated Enable tests for NMT2 Reviewed-by: ctornqvi, zgu --- hotspot/test/runtime/NMT/AutoshutdownNMT.java | 1 - hotspot/test/runtime/NMT/BaselineWithParameter.java | 1 - hotspot/test/runtime/NMT/CommandLineDetail.java | 1 - hotspot/test/runtime/NMT/CommandLineEmptyArgument.java | 1 - hotspot/test/runtime/NMT/CommandLineInvalidArgument.java | 1 - hotspot/test/runtime/NMT/CommandLineSummary.java | 1 - hotspot/test/runtime/NMT/CommandLineTurnOffNMT.java | 1 - hotspot/test/runtime/NMT/JcmdBaselineDetail.java | 1 - hotspot/test/runtime/NMT/JcmdScale.java | 1 - hotspot/test/runtime/NMT/JcmdScaleDetail.java | 1 - hotspot/test/runtime/NMT/JcmdSummaryDiff.java | 1 - hotspot/test/runtime/NMT/JcmdWithNMTDisabled.java | 1 - hotspot/test/runtime/NMT/MallocRoundingReportTest.java | 1 - hotspot/test/runtime/NMT/MallocTestType.java | 1 - hotspot/test/runtime/NMT/PrintNMTStatistics.java | 1 - hotspot/test/runtime/NMT/PrintNMTStatisticsWithNMTDisabled.java | 1 - hotspot/test/runtime/NMT/ReleaseCommittedMemory.java | 1 - hotspot/test/runtime/NMT/ReleaseNoCommit.java | 1 - hotspot/test/runtime/NMT/ShutdownTwice.java | 1 - hotspot/test/runtime/NMT/SummaryAfterShutdown.java | 1 - hotspot/test/runtime/NMT/SummarySanityCheck.java | 1 - hotspot/test/runtime/NMT/ThreadedMallocTestType.java | 1 - hotspot/test/runtime/NMT/ThreadedVirtualAllocTestType.java | 1 - hotspot/test/runtime/NMT/VirtualAllocTestType.java | 1 - 24 files changed, 24 deletions(-) diff --git a/hotspot/test/runtime/NMT/AutoshutdownNMT.java b/hotspot/test/runtime/NMT/AutoshutdownNMT.java index afb1df8a247..8739dc8d99f 100644 --- a/hotspot/test/runtime/NMT/AutoshutdownNMT.java +++ b/hotspot/test/runtime/NMT/AutoshutdownNMT.java @@ -26,7 +26,6 @@ * @key nmt * @summary Test for deprecated message if -XX:-AutoShutdownNMT is specified * @library /testlibrary - * @ignore */ import com.oracle.java.testlibrary.*; diff --git a/hotspot/test/runtime/NMT/BaselineWithParameter.java b/hotspot/test/runtime/NMT/BaselineWithParameter.java index ef34a11a416..ff10b28a060 100644 --- a/hotspot/test/runtime/NMT/BaselineWithParameter.java +++ b/hotspot/test/runtime/NMT/BaselineWithParameter.java @@ -27,7 +27,6 @@ * @key nmt jcmd regression * @summary Regression test for invoking a jcmd with baseline=false, result was that the target VM crashed * @library /testlibrary - * @ignore * @run main/othervm -XX:NativeMemoryTracking=detail BaselineWithParameter */ diff --git a/hotspot/test/runtime/NMT/CommandLineDetail.java b/hotspot/test/runtime/NMT/CommandLineDetail.java index b3ff104207f..01b0d0d3fae 100644 --- a/hotspot/test/runtime/NMT/CommandLineDetail.java +++ b/hotspot/test/runtime/NMT/CommandLineDetail.java @@ -26,7 +26,6 @@ * @key nmt * @summary Running with NMT detail should not result in an error * @library /testlibrary - * @ignore */ import com.oracle.java.testlibrary.*; diff --git a/hotspot/test/runtime/NMT/CommandLineEmptyArgument.java b/hotspot/test/runtime/NMT/CommandLineEmptyArgument.java index 1c05a195d44..956cdd26006 100644 --- a/hotspot/test/runtime/NMT/CommandLineEmptyArgument.java +++ b/hotspot/test/runtime/NMT/CommandLineEmptyArgument.java @@ -26,7 +26,6 @@ * @key nmt * @summary Empty argument to NMT should result in an informative error message * @library /testlibrary - * @ignore */ import com.oracle.java.testlibrary.*; diff --git a/hotspot/test/runtime/NMT/CommandLineInvalidArgument.java b/hotspot/test/runtime/NMT/CommandLineInvalidArgument.java index 6cc45102397..79cc2de9442 100644 --- a/hotspot/test/runtime/NMT/CommandLineInvalidArgument.java +++ b/hotspot/test/runtime/NMT/CommandLineInvalidArgument.java @@ -26,7 +26,6 @@ * @key nmt * @summary Invalid argument to NMT should result in an informative error message * @library /testlibrary - * @ignore */ import com.oracle.java.testlibrary.*; diff --git a/hotspot/test/runtime/NMT/CommandLineSummary.java b/hotspot/test/runtime/NMT/CommandLineSummary.java index bef1ab9cb38..d07bc7eae63 100644 --- a/hotspot/test/runtime/NMT/CommandLineSummary.java +++ b/hotspot/test/runtime/NMT/CommandLineSummary.java @@ -26,7 +26,6 @@ * @key nmt * @summary Running with NMT summary should not result in an error * @library /testlibrary - * @ignore */ import com.oracle.java.testlibrary.*; diff --git a/hotspot/test/runtime/NMT/CommandLineTurnOffNMT.java b/hotspot/test/runtime/NMT/CommandLineTurnOffNMT.java index a33e2ca4aa3..4193c9775d4 100644 --- a/hotspot/test/runtime/NMT/CommandLineTurnOffNMT.java +++ b/hotspot/test/runtime/NMT/CommandLineTurnOffNMT.java @@ -26,7 +26,6 @@ * @key nmt * @summary Turning off NMT should not result in an error * @library /testlibrary - * @ignore */ import com.oracle.java.testlibrary.*; diff --git a/hotspot/test/runtime/NMT/JcmdBaselineDetail.java b/hotspot/test/runtime/NMT/JcmdBaselineDetail.java index dc802f2be0e..501b860f8bc 100644 --- a/hotspot/test/runtime/NMT/JcmdBaselineDetail.java +++ b/hotspot/test/runtime/NMT/JcmdBaselineDetail.java @@ -26,7 +26,6 @@ * @key nmt jcmd * @summary Verify that jcmd correctly reports that baseline succeeds with NMT enabled with detailed tracking. * @library /testlibrary - * @ignore * @run main/othervm -XX:NativeMemoryTracking=detail JcmdBaselineDetail */ diff --git a/hotspot/test/runtime/NMT/JcmdScale.java b/hotspot/test/runtime/NMT/JcmdScale.java index 42b7393df62..3d8a9518760 100644 --- a/hotspot/test/runtime/NMT/JcmdScale.java +++ b/hotspot/test/runtime/NMT/JcmdScale.java @@ -26,7 +26,6 @@ * @key nmt jcmd * @summary Test the NMT scale parameter * @library /testlibrary - * @ignore * @run main/othervm -XX:NativeMemoryTracking=summary JcmdScale */ diff --git a/hotspot/test/runtime/NMT/JcmdScaleDetail.java b/hotspot/test/runtime/NMT/JcmdScaleDetail.java index 9e2430ba1d9..97c809dc0a0 100644 --- a/hotspot/test/runtime/NMT/JcmdScaleDetail.java +++ b/hotspot/test/runtime/NMT/JcmdScaleDetail.java @@ -26,7 +26,6 @@ * @key nmt jcmd * @summary Test the NMT scale parameter with detail tracking level * @library /testlibrary - * @ignore * @run main/othervm -XX:NativeMemoryTracking=detail JcmdScaleDetail */ diff --git a/hotspot/test/runtime/NMT/JcmdSummaryDiff.java b/hotspot/test/runtime/NMT/JcmdSummaryDiff.java index 7ee6c9f8e47..93c13d7aa3c 100644 --- a/hotspot/test/runtime/NMT/JcmdSummaryDiff.java +++ b/hotspot/test/runtime/NMT/JcmdSummaryDiff.java @@ -27,7 +27,6 @@ * @key nmt jcmd * @library /testlibrary /testlibrary/whitebox * @build JcmdSummaryDiff - * @ignore * @run main ClassFileInstaller sun.hotspot.WhiteBox * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=summary JcmdSummaryDiff */ diff --git a/hotspot/test/runtime/NMT/JcmdWithNMTDisabled.java b/hotspot/test/runtime/NMT/JcmdWithNMTDisabled.java index 086038eb233..9ef37434937 100644 --- a/hotspot/test/runtime/NMT/JcmdWithNMTDisabled.java +++ b/hotspot/test/runtime/NMT/JcmdWithNMTDisabled.java @@ -26,7 +26,6 @@ * @key nmt jcmd * @summary Verify that jcmd correctly reports that NMT is not enabled * @library /testlibrary - * @ignore * @run main JcmdWithNMTDisabled 1 */ diff --git a/hotspot/test/runtime/NMT/MallocRoundingReportTest.java b/hotspot/test/runtime/NMT/MallocRoundingReportTest.java index 2cf43bca8f4..f0a838a3200 100644 --- a/hotspot/test/runtime/NMT/MallocRoundingReportTest.java +++ b/hotspot/test/runtime/NMT/MallocRoundingReportTest.java @@ -27,7 +27,6 @@ * @key nmt jcmd * @library /testlibrary /testlibrary/whitebox * @build MallocRoundingReportTest - * @ignore * @run main ClassFileInstaller sun.hotspot.WhiteBox * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocRoundingReportTest * diff --git a/hotspot/test/runtime/NMT/MallocTestType.java b/hotspot/test/runtime/NMT/MallocTestType.java index 444dfda646f..18d6269a276 100644 --- a/hotspot/test/runtime/NMT/MallocTestType.java +++ b/hotspot/test/runtime/NMT/MallocTestType.java @@ -27,7 +27,6 @@ * @key nmt jcmd * @library /testlibrary /testlibrary/whitebox * @build MallocTestType - * @ignore * @run main ClassFileInstaller sun.hotspot.WhiteBox * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocTestType */ diff --git a/hotspot/test/runtime/NMT/PrintNMTStatistics.java b/hotspot/test/runtime/NMT/PrintNMTStatistics.java index a09007b366d..fa4fb77cb21 100644 --- a/hotspot/test/runtime/NMT/PrintNMTStatistics.java +++ b/hotspot/test/runtime/NMT/PrintNMTStatistics.java @@ -28,7 +28,6 @@ * @summary Make sure PrintNMTStatistics works on normal JVM exit * @library /testlibrary /testlibrary/whitebox * @build PrintNMTStatistics - * @ignore * @run main ClassFileInstaller sun.hotspot.WhiteBox * @run main PrintNMTStatistics */ diff --git a/hotspot/test/runtime/NMT/PrintNMTStatisticsWithNMTDisabled.java b/hotspot/test/runtime/NMT/PrintNMTStatisticsWithNMTDisabled.java index cdc3ded942a..1c25f284d4b 100644 --- a/hotspot/test/runtime/NMT/PrintNMTStatisticsWithNMTDisabled.java +++ b/hotspot/test/runtime/NMT/PrintNMTStatisticsWithNMTDisabled.java @@ -26,7 +26,6 @@ * @key nmt * @summary Trying to enable PrintNMTStatistics should result in a warning * @library /testlibrary - * @ignore */ import com.oracle.java.testlibrary.*; diff --git a/hotspot/test/runtime/NMT/ReleaseCommittedMemory.java b/hotspot/test/runtime/NMT/ReleaseCommittedMemory.java index 1f8592a3605..d6bf8d41bd7 100644 --- a/hotspot/test/runtime/NMT/ReleaseCommittedMemory.java +++ b/hotspot/test/runtime/NMT/ReleaseCommittedMemory.java @@ -28,7 +28,6 @@ * @key nmt regression * @library /testlibrary /testlibrary/whitebox * @build ReleaseCommittedMemory - * @ignore * @run main ClassFileInstaller sun.hotspot.WhiteBox * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail ReleaseCommittedMemory */ diff --git a/hotspot/test/runtime/NMT/ReleaseNoCommit.java b/hotspot/test/runtime/NMT/ReleaseNoCommit.java index b7c2ea950b1..94fba371df6 100644 --- a/hotspot/test/runtime/NMT/ReleaseNoCommit.java +++ b/hotspot/test/runtime/NMT/ReleaseNoCommit.java @@ -27,7 +27,6 @@ * @key nmt regression * @library /testlibrary /testlibrary/whitebox * @build ReleaseNoCommit - * @ignore * @run main ClassFileInstaller sun.hotspot.WhiteBox * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=summary ReleaseNoCommit */ diff --git a/hotspot/test/runtime/NMT/ShutdownTwice.java b/hotspot/test/runtime/NMT/ShutdownTwice.java index d6dcf8013e9..436e0c2c643 100644 --- a/hotspot/test/runtime/NMT/ShutdownTwice.java +++ b/hotspot/test/runtime/NMT/ShutdownTwice.java @@ -26,7 +26,6 @@ * @key nmt jcmd * @summary Run shutdown twice * @library /testlibrary - * @ignore * @run main/othervm -XX:NativeMemoryTracking=detail ShutdownTwice */ diff --git a/hotspot/test/runtime/NMT/SummaryAfterShutdown.java b/hotspot/test/runtime/NMT/SummaryAfterShutdown.java index 1baa484aa25..ea1f3a60737 100644 --- a/hotspot/test/runtime/NMT/SummaryAfterShutdown.java +++ b/hotspot/test/runtime/NMT/SummaryAfterShutdown.java @@ -26,7 +26,6 @@ * @key nmt jcmd * @summary Verify that jcmd correctly reports that NMT is not enabled after a shutdown * @library /testlibrary - * @ignore * @run main/othervm -XX:NativeMemoryTracking=detail SummaryAfterShutdown */ diff --git a/hotspot/test/runtime/NMT/SummarySanityCheck.java b/hotspot/test/runtime/NMT/SummarySanityCheck.java index 1f37e470749..509db8d2eaa 100644 --- a/hotspot/test/runtime/NMT/SummarySanityCheck.java +++ b/hotspot/test/runtime/NMT/SummarySanityCheck.java @@ -27,7 +27,6 @@ * @summary Sanity check the output of NMT * @library /testlibrary /testlibrary/whitebox * @build SummarySanityCheck - * @ignore * @run main ClassFileInstaller sun.hotspot.WhiteBox * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+WhiteBoxAPI SummarySanityCheck */ diff --git a/hotspot/test/runtime/NMT/ThreadedMallocTestType.java b/hotspot/test/runtime/NMT/ThreadedMallocTestType.java index 82d98c523b3..ec0cdd58c72 100644 --- a/hotspot/test/runtime/NMT/ThreadedMallocTestType.java +++ b/hotspot/test/runtime/NMT/ThreadedMallocTestType.java @@ -26,7 +26,6 @@ * @key nmt jcmd * @library /testlibrary /testlibrary/whitebox * @build ThreadedMallocTestType - * @ignore * @run main ClassFileInstaller sun.hotspot.WhiteBox * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail ThreadedMallocTestType */ diff --git a/hotspot/test/runtime/NMT/ThreadedVirtualAllocTestType.java b/hotspot/test/runtime/NMT/ThreadedVirtualAllocTestType.java index 3f9ab7ce98d..2aa6fedf582 100644 --- a/hotspot/test/runtime/NMT/ThreadedVirtualAllocTestType.java +++ b/hotspot/test/runtime/NMT/ThreadedVirtualAllocTestType.java @@ -26,7 +26,6 @@ * @key nmt jcmd * @library /testlibrary /testlibrary/whitebox * @build ThreadedVirtualAllocTestType - * @ignore * @run main ClassFileInstaller sun.hotspot.WhiteBox * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail ThreadedVirtualAllocTestType */ diff --git a/hotspot/test/runtime/NMT/VirtualAllocTestType.java b/hotspot/test/runtime/NMT/VirtualAllocTestType.java index f69f5ba6d9b..054a010daae 100644 --- a/hotspot/test/runtime/NMT/VirtualAllocTestType.java +++ b/hotspot/test/runtime/NMT/VirtualAllocTestType.java @@ -26,7 +26,6 @@ * @summary Test Reserve/Commit/Uncommit/Release of virtual memory and that we track it correctly * @key nmt jcmd * @library /testlibrary /testlibrary/whitebox - * @ignore * @build VirtualAllocTestType * @run main ClassFileInstaller sun.hotspot.WhiteBox * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail VirtualAllocTestType From e6720872341ab1ce7ccb92d20f5cbabd6c9ff6df Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Tue, 19 Aug 2014 08:34:25 -0400 Subject: [PATCH 3/5] 8055007: NMT2: emptyStack missing in minimal build Refactored emptyStack to a static member of NativeCallStack, which is accessible in minimal build. Reviewed-by: coleenp, dholmes --- hotspot/src/share/vm/services/mallocSiteTable.hpp | 3 ++- hotspot/src/share/vm/services/memTracker.cpp | 6 ++++-- hotspot/src/share/vm/services/memTracker.hpp | 11 +++++------ hotspot/src/share/vm/services/nmtCommon.hpp | 3 --- .../src/share/vm/services/virtualMemoryTracker.cpp | 2 +- .../src/share/vm/services/virtualMemoryTracker.hpp | 2 +- hotspot/src/share/vm/utilities/nativeCallStack.cpp | 1 + hotspot/src/share/vm/utilities/nativeCallStack.hpp | 3 +++ 8 files changed, 17 insertions(+), 14 deletions(-) diff --git a/hotspot/src/share/vm/services/mallocSiteTable.hpp b/hotspot/src/share/vm/services/mallocSiteTable.hpp index e291211cac8..cff98161449 100644 --- a/hotspot/src/share/vm/services/mallocSiteTable.hpp +++ b/hotspot/src/share/vm/services/mallocSiteTable.hpp @@ -32,13 +32,14 @@ #include "services/allocationSite.hpp" #include "services/mallocTracker.hpp" #include "services/nmtCommon.hpp" +#include "utilities/nativeCallStack.hpp" // MallocSite represents a code path that eventually calls // os::malloc() to allocate memory class MallocSite : public AllocationSite { public: MallocSite() : - AllocationSite(emptyStack) { } + AllocationSite(NativeCallStack::EMPTY_STACK) { } MallocSite(const NativeCallStack& stack) : AllocationSite(stack) { } diff --git a/hotspot/src/share/vm/services/memTracker.cpp b/hotspot/src/share/vm/services/memTracker.cpp index e66d6fe6be6..9c4bcb30768 100644 --- a/hotspot/src/share/vm/services/memTracker.cpp +++ b/hotspot/src/share/vm/services/memTracker.cpp @@ -39,8 +39,6 @@ volatile NMT_TrackingLevel MemTracker::_tracking_level = NMT_unknown; NMT_TrackingLevel MemTracker::_cmdline_tracking_level = NMT_unknown; -NativeCallStack emptyStack(0, false); - MemBaseline MemTracker::_baseline; Mutex* MemTracker::_query_lock = NULL; bool MemTracker::_is_nmt_env_valid = true; @@ -69,6 +67,10 @@ NMT_TrackingLevel MemTracker::init_tracking_level() { os::unsetenv(buf); } + // Construct NativeCallStack::EMPTY_STACK. It may get constructed twice, + // but it is benign, the results are the same. + ::new ((void*)&NativeCallStack::EMPTY_STACK) NativeCallStack(0, false); + if (!MallocTracker::initialize(level) || !VirtualMemoryTracker::initialize(level)) { level = NMT_off; diff --git a/hotspot/src/share/vm/services/memTracker.hpp b/hotspot/src/share/vm/services/memTracker.hpp index c256c3e1042..de43b9f2b0e 100644 --- a/hotspot/src/share/vm/services/memTracker.hpp +++ b/hotspot/src/share/vm/services/memTracker.hpp @@ -26,14 +26,13 @@ #define SHARE_VM_SERVICES_MEM_TRACKER_HPP #include "services/nmtCommon.hpp" +#include "utilities/nativeCallStack.hpp" -class NativeCallStack; -extern NativeCallStack emptyStack; #if !INCLUDE_NMT -#define CURRENT_PC emptyStack -#define CALLER_PC emptyStack +#define CURRENT_PC NativeCallStack::EMPTY_STACK +#define CALLER_PC NativeCallStack::EMPTY_STACK class Tracker : public StackObj { public: @@ -83,9 +82,9 @@ class MemTracker : AllStatic { extern volatile bool NMT_stack_walkable; #define CURRENT_PC ((MemTracker::tracking_level() == NMT_detail && NMT_stack_walkable) ? \ - NativeCallStack(0, true) : emptyStack) + NativeCallStack(0, true) : NativeCallStack::EMPTY_STACK) #define CALLER_PC ((MemTracker::tracking_level() == NMT_detail && NMT_stack_walkable) ? \ - NativeCallStack(1, true) : emptyStack) + NativeCallStack(1, true) : NativeCallStack::EMPTY_STACK) class MemBaseline; class Mutex; diff --git a/hotspot/src/share/vm/services/nmtCommon.hpp b/hotspot/src/share/vm/services/nmtCommon.hpp index 78139411981..f057484074f 100644 --- a/hotspot/src/share/vm/services/nmtCommon.hpp +++ b/hotspot/src/share/vm/services/nmtCommon.hpp @@ -50,9 +50,6 @@ enum NMT_TrackingLevel { // build time decision. const int NMT_TrackingStackDepth = 4; -class NativeCallStack; -extern NativeCallStack emptyStack; - // A few common utilities for native memory tracking class NMTUtil : AllStatic { public: diff --git a/hotspot/src/share/vm/services/virtualMemoryTracker.cpp b/hotspot/src/share/vm/services/virtualMemoryTracker.cpp index 4e0476f9085..95f13779bba 100644 --- a/hotspot/src/share/vm/services/virtualMemoryTracker.cpp +++ b/hotspot/src/share/vm/services/virtualMemoryTracker.cpp @@ -167,7 +167,7 @@ bool ReservedMemoryRegion::remove_uncommitted_region(address addr, size_t sz) { // higher part address high_base = addr + sz; size_t high_size = top - high_base; - CommittedMemoryRegion high_rgn(high_base, high_size, emptyStack); + CommittedMemoryRegion high_rgn(high_base, high_size, NativeCallStack::EMPTY_STACK); return add_committed_region(high_rgn); } else { return false; diff --git a/hotspot/src/share/vm/services/virtualMemoryTracker.hpp b/hotspot/src/share/vm/services/virtualMemoryTracker.hpp index 982b1531fc9..cf83d86e410 100644 --- a/hotspot/src/share/vm/services/virtualMemoryTracker.hpp +++ b/hotspot/src/share/vm/services/virtualMemoryTracker.hpp @@ -320,7 +320,7 @@ class ReservedMemoryRegion : public VirtualMemoryRegion { ReservedMemoryRegion(address base, size_t size) : - VirtualMemoryRegion(base, size), _stack(emptyStack), _flag(mtNone), + VirtualMemoryRegion(base, size), _stack(NativeCallStack::EMPTY_STACK), _flag(mtNone), _all_committed(false) { } // Copy constructor diff --git a/hotspot/src/share/vm/utilities/nativeCallStack.cpp b/hotspot/src/share/vm/utilities/nativeCallStack.cpp index c50ff410921..aa3a1e67a5d 100644 --- a/hotspot/src/share/vm/utilities/nativeCallStack.cpp +++ b/hotspot/src/share/vm/utilities/nativeCallStack.cpp @@ -27,6 +27,7 @@ #include "utilities/globalDefinitions.hpp" #include "utilities/nativeCallStack.hpp" +const NativeCallStack NativeCallStack::EMPTY_STACK(0, false); NativeCallStack::NativeCallStack(int toSkip, bool fillStack) : _hash_value(0) { diff --git a/hotspot/src/share/vm/utilities/nativeCallStack.hpp b/hotspot/src/share/vm/utilities/nativeCallStack.hpp index 957090b61c7..b6d6a35303e 100644 --- a/hotspot/src/share/vm/utilities/nativeCallStack.hpp +++ b/hotspot/src/share/vm/utilities/nativeCallStack.hpp @@ -52,6 +52,9 @@ * from it. */ class NativeCallStack : public StackObj { + public: + static const NativeCallStack EMPTY_STACK; + private: address _stack[NMT_TrackingStackDepth]; int _hash_value; From 1a1ce4534ef15b3b0aef4b954888e77a08f67a21 Mon Sep 17 00:00:00 2001 From: George Triantafillou Date: Tue, 19 Aug 2014 06:47:28 -0700 Subject: [PATCH 4/5] 8055051: runtime/NMT/CommandLineEmptyArgument.java fails Disable failing test Reviewed-by: ctornqvi, zgu --- hotspot/test/runtime/NMT/CommandLineEmptyArgument.java | 1 + 1 file changed, 1 insertion(+) diff --git a/hotspot/test/runtime/NMT/CommandLineEmptyArgument.java b/hotspot/test/runtime/NMT/CommandLineEmptyArgument.java index 956cdd26006..fcfa18ab6f2 100644 --- a/hotspot/test/runtime/NMT/CommandLineEmptyArgument.java +++ b/hotspot/test/runtime/NMT/CommandLineEmptyArgument.java @@ -26,6 +26,7 @@ * @key nmt * @summary Empty argument to NMT should result in an informative error message * @library /testlibrary + * @ignore 8055051 */ import com.oracle.java.testlibrary.*; From 92679c02266feb2ac58c35bef6f1bb092aefa637 Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Wed, 20 Aug 2014 08:41:15 -0400 Subject: [PATCH 5/5] 8054546: NMT2 leaks memory Fixed memory leak in NMT by baselining memory in c heap instead of an arena. Reviewed-by: coleenp, minqi --- .../src/share/vm/services/mallocTracker.hpp | 5 +- hotspot/src/share/vm/services/memBaseline.cpp | 60 +++++--------- hotspot/src/share/vm/services/memBaseline.hpp | 82 +++++++------------ 3 files changed, 51 insertions(+), 96 deletions(-) diff --git a/hotspot/src/share/vm/services/mallocTracker.hpp b/hotspot/src/share/vm/services/mallocTracker.hpp index 3b84270477b..17c58529482 100644 --- a/hotspot/src/share/vm/services/mallocTracker.hpp +++ b/hotspot/src/share/vm/services/mallocTracker.hpp @@ -171,8 +171,9 @@ class MallocMemorySnapshot : public ResourceObj { // Total malloc'd memory used by arenas size_t total_arena() const; - inline size_t thread_count() { - return by_type(mtThreadStack)->malloc_count(); + inline size_t thread_count() const { + MallocMemorySnapshot* s = const_cast(this); + return s->by_type(mtThreadStack)->malloc_count(); } void reset(); diff --git a/hotspot/src/share/vm/services/memBaseline.cpp b/hotspot/src/share/vm/services/memBaseline.cpp index 26cef4ceebb..02b4924760b 100644 --- a/hotspot/src/share/vm/services/memBaseline.cpp +++ b/hotspot/src/share/vm/services/memBaseline.cpp @@ -70,15 +70,13 @@ int compare_virtual_memory_site(const VirtualMemoryAllocationSite& s1, */ class MallocAllocationSiteWalker : public MallocSiteWalker { private: - SortedLinkedList - _malloc_sites; + SortedLinkedList _malloc_sites; size_t _count; // Entries in MallocSiteTable with size = 0 and count = 0, // when the malloc site is not longer there. public: - MallocAllocationSiteWalker(Arena* arena) : _count(0), _malloc_sites(arena) { - } + MallocAllocationSiteWalker() : _count(0) { } inline size_t count() const { return _count; } @@ -109,13 +107,12 @@ int compare_virtual_memory_base(const ReservedMemoryRegion& r1, const ReservedMe // Walk all virtual memory regions for baselining class VirtualMemoryAllocationWalker : public VirtualMemoryWalker { private: - SortedLinkedList + SortedLinkedList _virtual_memory_regions; size_t _count; public: - VirtualMemoryAllocationWalker(Arena* a) : _count(0), _virtual_memory_regions(a) { - } + VirtualMemoryAllocationWalker() : _count(0) { } bool do_allocation_site(const ReservedMemoryRegion* rgn) { if (rgn->size() >= MemBaseline::SIZE_THRESHOLD) { @@ -136,39 +133,30 @@ class VirtualMemoryAllocationWalker : public VirtualMemoryWalker { bool MemBaseline::baseline_summary() { - assert(_malloc_memory_snapshot == NULL, "Malloc baseline not yet reset"); - assert(_virtual_memory_snapshot == NULL, "Virtual baseline not yet reset"); - - _malloc_memory_snapshot = new (arena()) MallocMemorySnapshot(); - _virtual_memory_snapshot = new (arena()) VirtualMemorySnapshot(); - if (_malloc_memory_snapshot == NULL || _virtual_memory_snapshot == NULL) { - return false; - } - MallocMemorySummary::snapshot(_malloc_memory_snapshot); - VirtualMemorySummary::snapshot(_virtual_memory_snapshot); + MallocMemorySummary::snapshot(&_malloc_memory_snapshot); + VirtualMemorySummary::snapshot(&_virtual_memory_snapshot); return true; } bool MemBaseline::baseline_allocation_sites() { - assert(arena() != NULL, "Just check"); // Malloc allocation sites - MallocAllocationSiteWalker malloc_walker(arena()); + MallocAllocationSiteWalker malloc_walker; if (!MallocSiteTable::walk_malloc_site(&malloc_walker)) { return false; } - _malloc_sites.set_head(malloc_walker.malloc_sites()->head()); + _malloc_sites.move(malloc_walker.malloc_sites()); // The malloc sites are collected in size order _malloc_sites_order = by_size; // Virtual memory allocation sites - VirtualMemoryAllocationWalker virtual_memory_walker(arena()); + VirtualMemoryAllocationWalker virtual_memory_walker; if (!VirtualMemoryTracker::walk_virtual_memory(&virtual_memory_walker)) { return false; } // Virtual memory allocations are collected in call stack order - _virtual_memory_allocations.set_head(virtual_memory_walker.virtual_memory_allocations()->head()); + _virtual_memory_allocations.move(virtual_memory_walker.virtual_memory_allocations()); if (!aggregate_virtual_memory_allocation_sites()) { return false; @@ -180,11 +168,6 @@ bool MemBaseline::baseline_allocation_sites() { } bool MemBaseline::baseline(bool summaryOnly) { - if (arena() == NULL) { - _arena = new (std::nothrow, mtNMT) Arena(mtNMT); - if (arena() == NULL) return false; - } - reset(); _class_count = InstanceKlass::number_of_instance_classes(); @@ -211,8 +194,7 @@ int compare_allocation_site(const VirtualMemoryAllocationSite& s1, } bool MemBaseline::aggregate_virtual_memory_allocation_sites() { - SortedLinkedList - allocation_sites(arena()); + SortedLinkedList allocation_sites; VirtualMemoryAllocationIterator itr = virtual_memory_allocations(); const ReservedMemoryRegion* rgn; @@ -230,12 +212,12 @@ bool MemBaseline::aggregate_virtual_memory_allocation_sites() { site->commit_memory(rgn->committed_size()); } - _virtual_memory_sites.set_head(allocation_sites.head()); + _virtual_memory_sites.move(&allocation_sites); return true; } MallocSiteIterator MemBaseline::malloc_sites(SortingOrder order) { - assert(!_malloc_sites.is_empty(), "Detail baseline?"); + assert(!_malloc_sites.is_empty(), "Not detail baseline"); switch(order) { case by_size: malloc_sites_to_size_order(); @@ -251,7 +233,7 @@ MallocSiteIterator MemBaseline::malloc_sites(SortingOrder order) { } VirtualMemorySiteIterator MemBaseline::virtual_memory_sites(SortingOrder order) { - assert(!_virtual_memory_sites.is_empty(), "Detail baseline?"); + assert(!_virtual_memory_sites.is_empty(), "Not detail baseline"); switch(order) { case by_size: virtual_memory_sites_to_size_order(); @@ -270,8 +252,7 @@ VirtualMemorySiteIterator MemBaseline::virtual_memory_sites(SortingOrder order) // Sorting allocations sites in different orders void MemBaseline::malloc_sites_to_size_order() { if (_malloc_sites_order != by_size) { - SortedLinkedList - tmp(arena()); + SortedLinkedList tmp; // Add malloc sites to sorted linked list to sort into size order tmp.move(&_malloc_sites); @@ -283,8 +264,7 @@ void MemBaseline::malloc_sites_to_size_order() { void MemBaseline::malloc_sites_to_allocation_site_order() { if (_malloc_sites_order != by_site) { - SortedLinkedList - tmp(arena()); + SortedLinkedList tmp; // Add malloc sites to sorted linked list to sort into site (address) order tmp.move(&_malloc_sites); _malloc_sites.set_head(tmp.head()); @@ -295,8 +275,7 @@ void MemBaseline::malloc_sites_to_allocation_site_order() { void MemBaseline::virtual_memory_sites_to_size_order() { if (_virtual_memory_sites_order != by_size) { - SortedLinkedList - tmp(arena()); + SortedLinkedList tmp; tmp.move(&_virtual_memory_sites); @@ -308,10 +287,9 @@ void MemBaseline::virtual_memory_sites_to_size_order() { void MemBaseline::virtual_memory_sites_to_reservation_site_order() { if (_virtual_memory_sites_order != by_size) { - SortedLinkedList - tmp(arena()); + SortedLinkedList tmp; - tmp.add(&_virtual_memory_sites); + tmp.move(&_virtual_memory_sites); _virtual_memory_sites.set_head(tmp.head()); tmp.set_head(NULL); diff --git a/hotspot/src/share/vm/services/memBaseline.hpp b/hotspot/src/share/vm/services/memBaseline.hpp index bf742f8d56a..8272da49646 100644 --- a/hotspot/src/share/vm/services/memBaseline.hpp +++ b/hotspot/src/share/vm/services/memBaseline.hpp @@ -61,28 +61,22 @@ class MemBaseline VALUE_OBJ_CLASS_SPEC { }; private: - // All baseline data is stored in this arena - Arena* _arena; - // Summary information - MallocMemorySnapshot* _malloc_memory_snapshot; - VirtualMemorySnapshot* _virtual_memory_snapshot; + MallocMemorySnapshot _malloc_memory_snapshot; + VirtualMemorySnapshot _virtual_memory_snapshot; size_t _class_count; // Allocation sites information // Malloc allocation sites - LinkedListImpl - _malloc_sites; + LinkedListImpl _malloc_sites; // All virtual memory allocations - LinkedListImpl - _virtual_memory_allocations; + LinkedListImpl _virtual_memory_allocations; // Virtual memory allocations by allocation sites, always in by_address // order - LinkedListImpl - _virtual_memory_sites; + LinkedListImpl _virtual_memory_sites; SortingOrder _malloc_sites_order; SortingOrder _virtual_memory_sites_order; @@ -93,30 +87,23 @@ class MemBaseline VALUE_OBJ_CLASS_SPEC { // create a memory baseline MemBaseline(): _baseline_type(Not_baselined), - _class_count(0), - _arena(NULL), - _malloc_memory_snapshot(NULL), - _virtual_memory_snapshot(NULL), - _malloc_sites(NULL) { + _class_count(0) { } ~MemBaseline() { reset(); - if (_arena != NULL) { - delete _arena; - } } bool baseline(bool summaryOnly = true); BaselineType baseline_type() const { return _baseline_type; } - MallocMemorySnapshot* malloc_memory_snapshot() const { - return _malloc_memory_snapshot; + MallocMemorySnapshot* malloc_memory_snapshot() { + return &_malloc_memory_snapshot; } - VirtualMemorySnapshot* virtual_memory_snapshot() const { - return _virtual_memory_snapshot; + VirtualMemorySnapshot* virtual_memory_snapshot() { + return &_virtual_memory_snapshot; } MallocSiteIterator malloc_sites(SortingOrder order); @@ -133,10 +120,8 @@ class MemBaseline VALUE_OBJ_CLASS_SPEC { // memory size_t total_reserved_memory() const { assert(baseline_type() != Not_baselined, "Not yet baselined"); - assert(_virtual_memory_snapshot != NULL, "No virtual memory snapshot"); - assert(_malloc_memory_snapshot != NULL, "No malloc memory snapshot"); - size_t amount = _malloc_memory_snapshot->total() + - _virtual_memory_snapshot->total_reserved(); + size_t amount = _malloc_memory_snapshot.total() + + _virtual_memory_snapshot.total_reserved(); return amount; } @@ -144,32 +129,30 @@ class MemBaseline VALUE_OBJ_CLASS_SPEC { // virtual memory size_t total_committed_memory() const { assert(baseline_type() != Not_baselined, "Not yet baselined"); - assert(_virtual_memory_snapshot != NULL, - "Not a snapshot"); - size_t amount = _malloc_memory_snapshot->total() + - _virtual_memory_snapshot->total_committed(); + size_t amount = _malloc_memory_snapshot.total() + + _virtual_memory_snapshot.total_committed(); return amount; } size_t total_arena_memory() const { assert(baseline_type() != Not_baselined, "Not yet baselined"); - assert(_malloc_memory_snapshot != NULL, "Not yet baselined"); - return _malloc_memory_snapshot->total_arena(); + return _malloc_memory_snapshot.total_arena(); } size_t malloc_tracking_overhead() const { assert(baseline_type() != Not_baselined, "Not yet baselined"); - return _malloc_memory_snapshot->malloc_overhead()->size(); + MemBaseline* bl = const_cast(this); + return bl->_malloc_memory_snapshot.malloc_overhead()->size(); } - const MallocMemory* malloc_memory(MEMFLAGS flag) const { - assert(_malloc_memory_snapshot != NULL, "Not a snapshot"); - return _malloc_memory_snapshot->by_type(flag); + MallocMemory* malloc_memory(MEMFLAGS flag) { + assert(baseline_type() != Not_baselined, "Not yet baselined"); + return _malloc_memory_snapshot.by_type(flag); } - const VirtualMemory* virtual_memory(MEMFLAGS flag) const { - assert(_virtual_memory_snapshot != NULL, "Not a snapshot"); - return _virtual_memory_snapshot->by_type(flag); + VirtualMemory* virtual_memory(MEMFLAGS flag) { + assert(baseline_type() != Not_baselined, "Not yet baselined"); + return _virtual_memory_snapshot.by_type(flag); } @@ -180,24 +163,19 @@ class MemBaseline VALUE_OBJ_CLASS_SPEC { size_t thread_count() const { assert(baseline_type() != Not_baselined, "Not yet baselined"); - assert(_malloc_memory_snapshot != NULL, "Baselined?"); - return _malloc_memory_snapshot->thread_count(); + return _malloc_memory_snapshot.thread_count(); } // reset the baseline for reuse void reset() { _baseline_type = Not_baselined; - _malloc_memory_snapshot = NULL; - _virtual_memory_snapshot = NULL; + _malloc_memory_snapshot.reset(); + _virtual_memory_snapshot.reset(); _class_count = 0; - _malloc_sites = NULL; - _virtual_memory_sites = NULL; - _virtual_memory_allocations = NULL; - - if (_arena != NULL) { - _arena->destruct_contents(); - } + _malloc_sites.clear(); + _virtual_memory_sites.clear(); + _virtual_memory_allocations.clear(); } private: @@ -210,8 +188,6 @@ class MemBaseline VALUE_OBJ_CLASS_SPEC { // Aggregate virtual memory allocation by allocation sites bool aggregate_virtual_memory_allocation_sites(); - Arena* arena() { return _arena; } - // Sorting allocation sites in different orders // Sort allocation sites in size order void malloc_sites_to_size_order();