8205965: SIGSEGV on write to NativeCallStack::EMPTY_STACK

Made EMPTY_STACK non-const, so it will not be placed in read-only BSS section.

Reviewed-by: stuefe, martin
This commit is contained in:
Zhengyu Gu 2018-07-02 16:28:09 -04:00
parent 7d7184e505
commit 1a566d4510
5 changed files with 18 additions and 14 deletions

View File

@ -42,7 +42,7 @@ class MallocSite : public AllocationSite<MemoryCounter> {
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) {}

View File

@ -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 @@ class MemTracker : AllStatic {
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;

View File

@ -302,7 +302,7 @@ class ReservedMemoryRegion : public VirtualMemoryRegion {
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) :

View File

@ -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 @@ void NativeCallStack::print_on(outputStream* out, int indent) const {
}
}
}

View File

@ -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 NativeCallStack : public StackObj {
public:
static const NativeCallStack EMPTY_STACK;
class MemTracker;
private:
class NativeCallStack : public StackObj {
friend class MemTracker;
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 {