8055007: NMT2: emptyStack missing in minimal build
authorzgu
Tue, 19 Aug 2014 08:34:25 -0400
changeset 26144 35e11b657728
parent 25956 99be217ac88d
child 26145 d25ff5b0a56d
8055007: NMT2: emptyStack missing in minimal build Summary: 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
hotspot/src/share/vm/services/memTracker.cpp
hotspot/src/share/vm/services/memTracker.hpp
hotspot/src/share/vm/services/nmtCommon.hpp
hotspot/src/share/vm/services/virtualMemoryTracker.cpp
hotspot/src/share/vm/services/virtualMemoryTracker.hpp
hotspot/src/share/vm/utilities/nativeCallStack.cpp
hotspot/src/share/vm/utilities/nativeCallStack.hpp
--- a/hotspot/src/share/vm/services/mallocSiteTable.hpp	Tue Aug 12 21:16:05 2014 -0400
+++ b/hotspot/src/share/vm/services/mallocSiteTable.hpp	Tue Aug 19 08:34:25 2014 -0400
@@ -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<MemoryCounter> {
  public:
   MallocSite() :
-    AllocationSite<MemoryCounter>(emptyStack) { }
+    AllocationSite<MemoryCounter>(NativeCallStack::EMPTY_STACK) { }
 
   MallocSite(const NativeCallStack& stack) :
     AllocationSite<MemoryCounter>(stack) { }
--- a/hotspot/src/share/vm/services/memTracker.cpp	Tue Aug 12 21:16:05 2014 -0400
+++ b/hotspot/src/share/vm/services/memTracker.cpp	Tue Aug 19 08:34:25 2014 -0400
@@ -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 @@
     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;
--- a/hotspot/src/share/vm/services/memTracker.hpp	Tue Aug 12 21:16:05 2014 -0400
+++ b/hotspot/src/share/vm/services/memTracker.hpp	Tue Aug 19 08:34:25 2014 -0400
@@ -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 @@
 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;
--- a/hotspot/src/share/vm/services/nmtCommon.hpp	Tue Aug 12 21:16:05 2014 -0400
+++ b/hotspot/src/share/vm/services/nmtCommon.hpp	Tue Aug 19 08:34:25 2014 -0400
@@ -50,9 +50,6 @@
 // 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:
--- a/hotspot/src/share/vm/services/virtualMemoryTracker.cpp	Tue Aug 12 21:16:05 2014 -0400
+++ b/hotspot/src/share/vm/services/virtualMemoryTracker.cpp	Tue Aug 19 08:34:25 2014 -0400
@@ -167,7 +167,7 @@
           // 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;
--- a/hotspot/src/share/vm/services/virtualMemoryTracker.hpp	Tue Aug 12 21:16:05 2014 -0400
+++ b/hotspot/src/share/vm/services/virtualMemoryTracker.hpp	Tue Aug 19 08:34:25 2014 -0400
@@ -320,7 +320,7 @@
 
 
   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
--- a/hotspot/src/share/vm/utilities/nativeCallStack.cpp	Tue Aug 12 21:16:05 2014 -0400
+++ b/hotspot/src/share/vm/utilities/nativeCallStack.cpp	Tue Aug 19 08:34:25 2014 -0400
@@ -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) {
--- a/hotspot/src/share/vm/utilities/nativeCallStack.hpp	Tue Aug 12 21:16:05 2014 -0400
+++ b/hotspot/src/share/vm/utilities/nativeCallStack.hpp	Tue Aug 19 08:34:25 2014 -0400
@@ -52,6 +52,9 @@
  *    from it.
  */
 class NativeCallStack : public StackObj {
+ public:
+  static const NativeCallStack EMPTY_STACK;
+
  private:
   address   _stack[NMT_TrackingStackDepth];
   int       _hash_value;