8205965: SIGSEGV on write to NativeCallStack::EMPTY_STACK
authorzgu
Mon, 02 Jul 2018 16:28:09 -0400
changeset 50904 b9c7eb8d8972
parent 50903 0221f6a72e4b
child 50905 67f6158279d8
8205965: SIGSEGV on write to NativeCallStack::EMPTY_STACK Summary: Made EMPTY_STACK non-const, so it will not be placed in read-only BSS section. Reviewed-by: stuefe, martin
src/hotspot/share/services/mallocSiteTable.hpp
src/hotspot/share/services/memTracker.hpp
src/hotspot/share/services/virtualMemoryTracker.hpp
src/hotspot/share/utilities/nativeCallStack.cpp
src/hotspot/share/utilities/nativeCallStack.hpp
--- a/src/hotspot/share/services/mallocSiteTable.hpp	Mon Jul 02 00:55:24 2018 -0700
+++ b/src/hotspot/share/services/mallocSiteTable.hpp	Mon Jul 02 16:28:09 2018 -0400
@@ -42,7 +42,7 @@
 
  public:
   MallocSite() :
-    AllocationSite<MemoryCounter>(NativeCallStack::EMPTY_STACK), _flags(mtNone) {}
+    AllocationSite<MemoryCounter>(NativeCallStack::empty_stack()), _flags(mtNone) {}
 
   MallocSite(const NativeCallStack& stack, MEMFLAGS flags) :
     AllocationSite<MemoryCounter>(stack), _flags(flags) {}
--- a/src/hotspot/share/services/memTracker.hpp	Mon Jul 02 00:55:24 2018 -0700
+++ b/src/hotspot/share/services/memTracker.hpp	Mon Jul 02 16:28:09 2018 -0400
@@ -31,8 +31,8 @@
 
 #if !INCLUDE_NMT
 
-#define CURRENT_PC   NativeCallStack::EMPTY_STACK
-#define CALLER_PC    NativeCallStack::EMPTY_STACK
+#define CURRENT_PC   NativeCallStack::empty_stack()
+#define CALLER_PC    NativeCallStack::empty_stack()
 
 class Tracker : public StackObj {
  public:
@@ -86,9 +86,9 @@
 extern volatile bool NMT_stack_walkable;
 
 #define CURRENT_PC ((MemTracker::tracking_level() == NMT_detail && NMT_stack_walkable) ? \
-                    NativeCallStack(0, true) : NativeCallStack::EMPTY_STACK)
+                    NativeCallStack(0, true) : NativeCallStack::empty_stack())
 #define CALLER_PC  ((MemTracker::tracking_level() == NMT_detail && NMT_stack_walkable) ?  \
-                    NativeCallStack(1, true) : NativeCallStack::EMPTY_STACK)
+                    NativeCallStack(1, true) : NativeCallStack::empty_stack())
 
 class MemBaseline;
 class Mutex;
--- a/src/hotspot/share/services/virtualMemoryTracker.hpp	Mon Jul 02 00:55:24 2018 -0700
+++ b/src/hotspot/share/services/virtualMemoryTracker.hpp	Mon Jul 02 16:28:09 2018 -0400
@@ -302,7 +302,7 @@
 
 
   ReservedMemoryRegion(address base, size_t size) :
-    VirtualMemoryRegion(base, size), _stack(NativeCallStack::EMPTY_STACK), _flag(mtNone) { }
+    VirtualMemoryRegion(base, size), _stack(NativeCallStack::empty_stack()), _flag(mtNone) { }
 
   // Copy constructor
   ReservedMemoryRegion(const ReservedMemoryRegion& rr) :
--- a/src/hotspot/share/utilities/nativeCallStack.cpp	Mon Jul 02 00:55:24 2018 -0700
+++ b/src/hotspot/share/utilities/nativeCallStack.cpp	Mon Jul 02 16:28:09 2018 -0400
@@ -28,7 +28,7 @@
 #include "utilities/globalDefinitions.hpp"
 #include "utilities/nativeCallStack.hpp"
 
-const NativeCallStack NativeCallStack::EMPTY_STACK(0, false);
+NativeCallStack NativeCallStack::EMPTY_STACK(0, false);
 
 NativeCallStack::NativeCallStack(int toSkip, bool fillStack) :
   _hash_value(0) {
@@ -126,4 +126,3 @@
     }
   }
 }
-
--- a/src/hotspot/share/utilities/nativeCallStack.hpp	Mon Jul 02 00:55:24 2018 -0700
+++ b/src/hotspot/share/utilities/nativeCallStack.hpp	Mon Jul 02 16:28:09 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, 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
@@ -51,18 +51,23 @@
  * 2. The class is strict stack object, no heap or virtual memory can be allocated
  *    from it.
  */
+class MemTracker;
+
 class NativeCallStack : public StackObj {
- public:
-  static const NativeCallStack EMPTY_STACK;
+  friend class MemTracker;
 
- private:
+private:
   address       _stack[NMT_TrackingStackDepth];
   unsigned int  _hash_value;
 
- public:
+  static NativeCallStack EMPTY_STACK;
+public:
   NativeCallStack(int toSkip = 0, bool fillStack = false);
   NativeCallStack(address* pc, int frameCount);
 
+  static inline const NativeCallStack& empty_stack() {
+    return EMPTY_STACK;
+  }
 
   // if it is an empty stack
   inline bool is_empty() const {