Commit ef62cd06 authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[heap] Remove executable_memory_ from release code

The map is only used to check invariants.

Bug: v8:12054
Change-Id: I7d067cca801c9b6104efb22a26cf27f1f62920c5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3268286Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77766}
parent 5bf95ec6
...@@ -800,7 +800,7 @@ CodeSpaceMemoryModificationScope::CodeSpaceMemoryModificationScope(Heap* heap) ...@@ -800,7 +800,7 @@ CodeSpaceMemoryModificationScope::CodeSpaceMemoryModificationScope(Heap* heap)
LargePage* page = heap_->code_lo_space()->first_page(); LargePage* page = heap_->code_lo_space()->first_page();
while (page != nullptr) { while (page != nullptr) {
DCHECK(page->IsFlagSet(MemoryChunk::IS_EXECUTABLE)); DCHECK(page->IsFlagSet(MemoryChunk::IS_EXECUTABLE));
CHECK(heap_->memory_allocator()->IsMemoryChunkExecutable(page)); DCHECK(heap_->memory_allocator()->IsMemoryChunkExecutable(page));
page->SetCodeModificationPermissions(); page->SetCodeModificationPermissions();
page = page->next_page(); page = page->next_page();
} }
...@@ -814,7 +814,7 @@ CodeSpaceMemoryModificationScope::~CodeSpaceMemoryModificationScope() { ...@@ -814,7 +814,7 @@ CodeSpaceMemoryModificationScope::~CodeSpaceMemoryModificationScope() {
LargePage* page = heap_->code_lo_space()->first_page(); LargePage* page = heap_->code_lo_space()->first_page();
while (page != nullptr) { while (page != nullptr) {
DCHECK(page->IsFlagSet(MemoryChunk::IS_EXECUTABLE)); DCHECK(page->IsFlagSet(MemoryChunk::IS_EXECUTABLE));
CHECK(heap_->memory_allocator()->IsMemoryChunkExecutable(page)); DCHECK(heap_->memory_allocator()->IsMemoryChunkExecutable(page));
page->SetDefaultCodePermissions(); page->SetDefaultCodePermissions();
page = page->next_page(); page = page->next_page();
} }
......
...@@ -2674,7 +2674,7 @@ void Heap::ProtectUnprotectedMemoryChunks() { ...@@ -2674,7 +2674,7 @@ void Heap::ProtectUnprotectedMemoryChunks() {
DCHECK_EQ(code_page_collection_memory_modification_scope_depth_, 0); DCHECK_EQ(code_page_collection_memory_modification_scope_depth_, 0);
for (auto chunk = unprotected_memory_chunks_.begin(); for (auto chunk = unprotected_memory_chunks_.begin();
chunk != unprotected_memory_chunks_.end(); chunk++) { chunk != unprotected_memory_chunks_.end(); chunk++) {
CHECK(memory_allocator()->IsMemoryChunkExecutable(*chunk)); DCHECK(memory_allocator()->IsMemoryChunkExecutable(*chunk));
(*chunk)->SetDefaultCodePermissions(); (*chunk)->SetDefaultCodePermissions();
} }
unprotected_memory_chunks_.clear(); unprotected_memory_chunks_.clear();
......
...@@ -409,7 +409,9 @@ MemoryChunk* MemoryAllocator::AllocateChunk(size_t reserve_area_size, ...@@ -409,7 +409,9 @@ MemoryChunk* MemoryAllocator::AllocateChunk(size_t reserve_area_size,
MemoryChunk* chunk = MemoryChunk* chunk =
MemoryChunk::Initialize(basic_chunk, isolate_->heap(), executable); MemoryChunk::Initialize(basic_chunk, isolate_->heap(), executable);
#ifdef DEBUG
if (chunk->executable()) RegisterExecutableMemoryChunk(chunk); if (chunk->executable()) RegisterExecutableMemoryChunk(chunk);
#endif
return chunk; return chunk;
} }
...@@ -458,7 +460,9 @@ void MemoryAllocator::UnregisterMemory(BasicMemoryChunk* chunk, ...@@ -458,7 +460,9 @@ void MemoryAllocator::UnregisterMemory(BasicMemoryChunk* chunk,
if (executable == EXECUTABLE) { if (executable == EXECUTABLE) {
DCHECK_GE(size_executable_, size); DCHECK_GE(size_executable_, size);
size_executable_ -= size; size_executable_ -= size;
#ifdef DEBUG
UnregisterExecutableMemoryChunk(static_cast<MemoryChunk*>(chunk)); UnregisterExecutableMemoryChunk(static_cast<MemoryChunk*>(chunk));
#endif
} }
chunk->SetFlag(MemoryChunk::UNREGISTERED); chunk->SetFlag(MemoryChunk::UNREGISTERED);
} }
......
...@@ -226,11 +226,14 @@ class MemoryAllocator { ...@@ -226,11 +226,14 @@ class MemoryAllocator {
void PartialFreeMemory(BasicMemoryChunk* chunk, Address start_free, void PartialFreeMemory(BasicMemoryChunk* chunk, Address start_free,
size_t bytes_to_free, Address new_area_end); size_t bytes_to_free, Address new_area_end);
#ifdef DEBUG
// Checks if an allocated MemoryChunk was intended to be used for executable // Checks if an allocated MemoryChunk was intended to be used for executable
// memory. // memory.
bool IsMemoryChunkExecutable(MemoryChunk* chunk) { bool IsMemoryChunkExecutable(MemoryChunk* chunk) {
base::MutexGuard guard(&executable_memory_mutex_);
return executable_memory_.find(chunk) != executable_memory_.end(); return executable_memory_.find(chunk) != executable_memory_.end();
} }
#endif
// Commit memory region owned by given reservation object. Returns true if // Commit memory region owned by given reservation object. Returns true if
// it succeeded and false otherwise. // it succeeded and false otherwise.
...@@ -311,6 +314,7 @@ class MemoryAllocator { ...@@ -311,6 +314,7 @@ class MemoryAllocator {
} }
} }
#ifdef DEBUG
void RegisterExecutableMemoryChunk(MemoryChunk* chunk) { void RegisterExecutableMemoryChunk(MemoryChunk* chunk) {
base::MutexGuard guard(&executable_memory_mutex_); base::MutexGuard guard(&executable_memory_mutex_);
DCHECK(chunk->IsFlagSet(MemoryChunk::IS_EXECUTABLE)); DCHECK(chunk->IsFlagSet(MemoryChunk::IS_EXECUTABLE));
...@@ -324,6 +328,7 @@ class MemoryAllocator { ...@@ -324,6 +328,7 @@ class MemoryAllocator {
executable_memory_.erase(chunk); executable_memory_.erase(chunk);
chunk->heap()->UnregisterUnprotectedMemoryChunk(chunk); chunk->heap()->UnregisterUnprotectedMemoryChunk(chunk);
} }
#endif // DEBUG
Isolate* isolate_; Isolate* isolate_;
...@@ -359,9 +364,12 @@ class MemoryAllocator { ...@@ -359,9 +364,12 @@ class MemoryAllocator {
VirtualMemory last_chunk_; VirtualMemory last_chunk_;
Unmapper unmapper_; Unmapper unmapper_;
#ifdef DEBUG
// Data structure to remember allocated executable memory chunks. // Data structure to remember allocated executable memory chunks.
// This data structure is used only in DCHECKs.
std::unordered_set<MemoryChunk*> executable_memory_; std::unordered_set<MemoryChunk*> executable_memory_;
base::Mutex executable_memory_mutex_; base::Mutex executable_memory_mutex_;
#endif
friend class heap::TestCodePageAllocatorScope; friend class heap::TestCodePageAllocatorScope;
friend class heap::TestMemoryAllocatorScope; friend class heap::TestMemoryAllocatorScope;
......
...@@ -499,7 +499,7 @@ void PagedSpace::ReleasePage(Page* page) { ...@@ -499,7 +499,7 @@ void PagedSpace::ReleasePage(Page* page) {
void PagedSpace::SetReadable() { void PagedSpace::SetReadable() {
DCHECK(identity() == CODE_SPACE); DCHECK(identity() == CODE_SPACE);
for (Page* page : *this) { for (Page* page : *this) {
CHECK(heap()->memory_allocator()->IsMemoryChunkExecutable(page)); DCHECK(heap()->memory_allocator()->IsMemoryChunkExecutable(page));
page->SetReadable(); page->SetReadable();
} }
} }
...@@ -507,7 +507,7 @@ void PagedSpace::SetReadable() { ...@@ -507,7 +507,7 @@ void PagedSpace::SetReadable() {
void PagedSpace::SetReadAndExecutable() { void PagedSpace::SetReadAndExecutable() {
DCHECK(identity() == CODE_SPACE); DCHECK(identity() == CODE_SPACE);
for (Page* page : *this) { for (Page* page : *this) {
CHECK(heap()->memory_allocator()->IsMemoryChunkExecutable(page)); DCHECK(heap()->memory_allocator()->IsMemoryChunkExecutable(page));
page->SetReadAndExecutable(); page->SetReadAndExecutable();
} }
} }
...@@ -515,7 +515,7 @@ void PagedSpace::SetReadAndExecutable() { ...@@ -515,7 +515,7 @@ void PagedSpace::SetReadAndExecutable() {
void PagedSpace::SetCodeModificationPermissions() { void PagedSpace::SetCodeModificationPermissions() {
DCHECK(identity() == CODE_SPACE); DCHECK(identity() == CODE_SPACE);
for (Page* page : *this) { for (Page* page : *this) {
CHECK(heap()->memory_allocator()->IsMemoryChunkExecutable(page)); DCHECK(heap()->memory_allocator()->IsMemoryChunkExecutable(page));
page->SetCodeModificationPermissions(); page->SetCodeModificationPermissions();
} }
} }
......
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