Commit cc008653 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[heap] Copy value of --write-protect-code-memory.

This introduces {Heap::write_protect_code_memory} as a race-free copy of
the underlying {FLAG_write_protect_code_memory} flag. Since this flag is
checked from the parallel sweeper, subsequent flag implications might be
racing against the read. This ensures race-free reads.

R=hpayer@chromium.org
BUG=v8:6792,chromium:774108,v8:7106

Change-Id: I1a1073f11e91bebd60f8d5da440845452ec67c50
Reviewed-on: https://chromium-review.googlesource.com/781662Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49535}
parent d43c6e59
......@@ -599,7 +599,7 @@ AlwaysAllocateScope::~AlwaysAllocateScope() {
CodeSpaceMemoryModificationScope::CodeSpaceMemoryModificationScope(Heap* heap)
: heap_(heap) {
if (FLAG_write_protect_code_memory) {
if (heap_->write_protect_code_memory()) {
heap_->increment_code_space_memory_modification_scope_depth();
heap_->code_space()->SetReadAndWritable();
LargePage* page = heap_->lo_space()->first_page();
......@@ -613,7 +613,7 @@ CodeSpaceMemoryModificationScope::CodeSpaceMemoryModificationScope(Heap* heap)
}
CodeSpaceMemoryModificationScope::~CodeSpaceMemoryModificationScope() {
if (FLAG_write_protect_code_memory) {
if (heap_->write_protect_code_memory()) {
heap_->decrement_code_space_memory_modification_scope_depth();
heap_->code_space()->SetReadAndExecutable();
LargePage* page = heap_->lo_space()->first_page();
......@@ -629,7 +629,7 @@ CodeSpaceMemoryModificationScope::~CodeSpaceMemoryModificationScope() {
CodePageMemoryModificationScope::CodePageMemoryModificationScope(
MemoryChunk* chunk, CodePageModificationMode mode)
: chunk_(chunk),
scope_active_(FLAG_write_protect_code_memory &&
scope_active_(chunk_->heap()->write_protect_code_memory() &&
chunk_->IsFlagSet(MemoryChunk::IS_EXECUTABLE)) {
if (scope_active_) {
DCHECK(chunk_->owner()->identity() == CODE_SPACE ||
......
......@@ -165,6 +165,7 @@ Heap::Heap()
code_space_(nullptr),
map_space_(nullptr),
lo_space_(nullptr),
write_protect_code_memory_(false),
code_space_memory_modification_scope_depth_(0),
gc_state_(NOT_IN_GC),
gc_post_processing_depth_(0),
......@@ -5623,6 +5624,8 @@ bool Heap::SetUp() {
stress_marking_percentage_ = NextStressMarkingLimit();
}
write_protect_code_memory_ = FLAG_write_protect_code_memory;
return true;
}
......
......@@ -811,6 +811,8 @@ class Heap {
// Print short heap statistics.
void PrintShortHeapStatistics();
bool write_protect_code_memory() const { return write_protect_code_memory_; }
uintptr_t code_space_memory_modification_scope_depth() {
return code_space_memory_modification_scope_depth_;
}
......@@ -2344,6 +2346,10 @@ class Heap {
// Map from the space id to the space.
Space* space_[LAST_SPACE + 1];
// Determines whether code space is write-protected. This is essentially a
// race-free copy of the {FLAG_write_protect_code_memory} flag.
bool write_protect_code_memory_;
// Holds the number of open CodeSpaceMemoryModificationScopes.
uintptr_t code_space_memory_modification_scope_depth_;
......
......@@ -623,7 +623,7 @@ MemoryChunk* MemoryChunk::Initialize(Heap* heap, Address base, size_t size,
if (executable == EXECUTABLE) {
chunk->SetFlag(IS_EXECUTABLE);
if (FLAG_write_protect_code_memory) {
if (heap->write_protect_code_memory()) {
chunk->write_unprotect_counter_ =
heap->code_space_memory_modification_scope_depth();
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment