changeset 8968:7a6239517d46

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 Contributed-by: zhaixiang@loongson.cn
author zgu
date Wed, 19 Sep 2018 19:48:12 -0400
parents 25beb9e0ffa7
children b7f0e16c80dd
files src/share/vm/services/mallocSiteTable.hpp src/share/vm/services/memTracker.hpp src/share/vm/services/virtualMemoryTracker.cpp src/share/vm/services/virtualMemoryTracker.hpp src/share/vm/utilities/nativeCallStack.cpp src/share/vm/utilities/nativeCallStack.hpp
diffstat 6 files changed, 22 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/services/mallocSiteTable.hpp	Wed Sep 19 14:26:01 2018 -0400
+++ b/src/share/vm/services/mallocSiteTable.hpp	Wed Sep 19 19:48:12 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2017, 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
@@ -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/share/vm/services/memTracker.hpp	Wed Sep 19 14:26:01 2018 -0400
+++ b/src/share/vm/services/memTracker.hpp	Wed Sep 19 19:48:12 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -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:
@@ -83,9 +83,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/share/vm/services/virtualMemoryTracker.cpp	Wed Sep 19 14:26:01 2018 -0400
+++ b/src/share/vm/services/virtualMemoryTracker.cpp	Wed Sep 19 19:48:12 2018 -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, NativeCallStack::EMPTY_STACK);
+          CommittedMemoryRegion high_rgn(high_base, high_size, NativeCallStack::empty_stack());
           return add_committed_region(high_rgn);
         } else {
           return false;
--- a/src/share/vm/services/virtualMemoryTracker.hpp	Wed Sep 19 14:26:01 2018 -0400
+++ b/src/share/vm/services/virtualMemoryTracker.hpp	Wed Sep 19 19:48:12 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -305,7 +305,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),
     _all_committed(false) { }
 
   // Copy constructor
--- a/src/share/vm/utilities/nativeCallStack.cpp	Wed Sep 19 14:26:01 2018 -0400
+++ b/src/share/vm/utilities/nativeCallStack.cpp	Wed Sep 19 19:48:12 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
@@ -27,7 +27,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) {
@@ -114,4 +114,3 @@
     }
   }
 }
-
--- a/src/share/vm/utilities/nativeCallStack.hpp	Wed Sep 19 14:26:01 2018 -0400
+++ b/src/share/vm/utilities/nativeCallStack.hpp	Wed Sep 19 19:48:12 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 {