Commit 09658ff7 authored by Hannes Payer's avatar Hannes Payer Committed by Commit Bot

[heap] Initialize the write_unprotect_counter_ of new code pages with the...

[heap] Initialize the write_unprotect_counter_ of new code pages with the number of open CodeSpaceMemoryModificationScopes.

Bug: chromium:774108,v8:6792
Change-Id: Ib5306075aeff61160762c685c343970ceb32b66a
Reviewed-on: https://chromium-review.googlesource.com/779201Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49521}
parent 1cd6fd9f
...@@ -600,6 +600,7 @@ AlwaysAllocateScope::~AlwaysAllocateScope() { ...@@ -600,6 +600,7 @@ AlwaysAllocateScope::~AlwaysAllocateScope() {
CodeSpaceMemoryModificationScope::CodeSpaceMemoryModificationScope(Heap* heap) CodeSpaceMemoryModificationScope::CodeSpaceMemoryModificationScope(Heap* heap)
: heap_(heap) { : heap_(heap) {
if (FLAG_write_protect_code_memory) { if (FLAG_write_protect_code_memory) {
heap_->increment_code_space_memory_modification_scope_depth();
heap_->code_space()->SetReadAndWritable(); heap_->code_space()->SetReadAndWritable();
LargePage* page = heap_->lo_space()->first_page(); LargePage* page = heap_->lo_space()->first_page();
while (page != nullptr) { while (page != nullptr) {
...@@ -613,6 +614,7 @@ CodeSpaceMemoryModificationScope::CodeSpaceMemoryModificationScope(Heap* heap) ...@@ -613,6 +614,7 @@ CodeSpaceMemoryModificationScope::CodeSpaceMemoryModificationScope(Heap* heap)
CodeSpaceMemoryModificationScope::~CodeSpaceMemoryModificationScope() { CodeSpaceMemoryModificationScope::~CodeSpaceMemoryModificationScope() {
if (FLAG_write_protect_code_memory) { if (FLAG_write_protect_code_memory) {
heap_->decrement_code_space_memory_modification_scope_depth();
heap_->code_space()->SetReadAndExecutable(); heap_->code_space()->SetReadAndExecutable();
LargePage* page = heap_->lo_space()->first_page(); LargePage* page = heap_->lo_space()->first_page();
while (page != nullptr) { while (page != nullptr) {
......
...@@ -165,6 +165,7 @@ Heap::Heap() ...@@ -165,6 +165,7 @@ Heap::Heap()
code_space_(nullptr), code_space_(nullptr),
map_space_(nullptr), map_space_(nullptr),
lo_space_(nullptr), lo_space_(nullptr),
code_space_memory_modification_scope_depth_(0),
gc_state_(NOT_IN_GC), gc_state_(NOT_IN_GC),
gc_post_processing_depth_(0), gc_post_processing_depth_(0),
allocations_count_(0), allocations_count_(0),
......
...@@ -808,6 +808,18 @@ class Heap { ...@@ -808,6 +808,18 @@ class Heap {
// Print short heap statistics. // Print short heap statistics.
void PrintShortHeapStatistics(); void PrintShortHeapStatistics();
uintptr_t code_space_memory_modification_scope_depth() {
return code_space_memory_modification_scope_depth_;
}
void increment_code_space_memory_modification_scope_depth() {
code_space_memory_modification_scope_depth_++;
}
void decrement_code_space_memory_modification_scope_depth() {
code_space_memory_modification_scope_depth_--;
}
inline HeapState gc_state() { return gc_state_; } inline HeapState gc_state() { return gc_state_; }
void SetGCState(HeapState state); void SetGCState(HeapState state);
...@@ -2316,6 +2328,10 @@ class Heap { ...@@ -2316,6 +2328,10 @@ class Heap {
LargeObjectSpace* lo_space_; LargeObjectSpace* lo_space_;
// Map from the space id to the space. // Map from the space id to the space.
Space* space_[LAST_SPACE + 1]; Space* space_[LAST_SPACE + 1];
// Holds the number of open CodeSpaceMemoryModificationScopes.
uintptr_t code_space_memory_modification_scope_depth_;
HeapState gc_state_; HeapState gc_state_;
int gc_post_processing_depth_; int gc_post_processing_depth_;
......
...@@ -624,7 +624,8 @@ MemoryChunk* MemoryChunk::Initialize(Heap* heap, Address base, size_t size, ...@@ -624,7 +624,8 @@ MemoryChunk* MemoryChunk::Initialize(Heap* heap, Address base, size_t size,
if (executable == EXECUTABLE) { if (executable == EXECUTABLE) {
chunk->SetFlag(IS_EXECUTABLE); chunk->SetFlag(IS_EXECUTABLE);
if (FLAG_write_protect_code_memory) { if (FLAG_write_protect_code_memory) {
chunk->write_unprotect_counter_ = 1; chunk->write_unprotect_counter_ =
heap->code_space_memory_modification_scope_depth();
} else { } else {
size_t page_size = MemoryAllocator::GetCommitPageSize(); size_t page_size = MemoryAllocator::GetCommitPageSize();
DCHECK(IsAddressAligned(area_start, page_size)); DCHECK(IsAddressAligned(area_start, page_size));
......
...@@ -700,9 +700,10 @@ class MemoryChunk { ...@@ -700,9 +700,10 @@ class MemoryChunk {
// If Value() >= 1 => The Memory is read and writable (and maybe executable). // If Value() >= 1 => The Memory is read and writable (and maybe executable).
// The maximum value can right now only be 3. // The maximum value can right now only be 3.
// All executable MemoryChunks are allocated rw based on the assumption that // All executable MemoryChunks are allocated rw based on the assumption that
// they will be used immediatelly for an allocation. Hence they are // they will be used immediatelly for an allocation. They are initialized
// initialized with 1. The caller that triggers the page allocation is // with the number of open CodeSpaceMemoryModificationScopes. The caller
// responsible to make the MemoryChunk rx. // that triggers the page allocation is responsible for decrementing the
// counter.
uintptr_t write_unprotect_counter_; uintptr_t write_unprotect_counter_;
// Byte allocated on the page, which includes all objects on the page // Byte allocated on the page, which includes all objects on the page
......
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