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