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

[heap] Make {Factory::CopyCode} use finer scope.

This makes the above factory function use a fine-grained scope when
unlocking code space for modification. It now uses a cumulative per-page
scope that collects only those memory chunks that needed to be touched
during allocation.

R=ulan@chromium.org

Change-Id: I22de0fae8be507ba9d51868f668b902b3bae3d6a
Reviewed-on: https://chromium-review.googlesource.com/c/1335558Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57503}
parent 4e5883c5
...@@ -315,13 +315,8 @@ void InstallBytecodeArray(Handle<BytecodeArray> bytecode_array, ...@@ -315,13 +315,8 @@ void InstallBytecodeArray(Handle<BytecodeArray> bytecode_array,
return; return;
} }
Handle<Code> code; Handle<Code> code = isolate->factory()->CopyCode(
{
CodeSpaceMemoryModificationScope code_allocation(isolate->heap());
code = isolate->factory()->CopyCode(
BUILTIN_CODE(isolate, InterpreterEntryTrampoline)); BUILTIN_CODE(isolate, InterpreterEntryTrampoline));
}
Handle<InterpreterData> interpreter_data = Handle<InterpreterData>::cast( Handle<InterpreterData> interpreter_data = Handle<InterpreterData>::cast(
isolate->factory()->NewStruct(INTERPRETER_DATA_TYPE, TENURED)); isolate->factory()->NewStruct(INTERPRETER_DATA_TYPE, TENURED));
......
...@@ -2735,14 +2735,17 @@ Handle<Code> Factory::CopyCode(Handle<Code> code) { ...@@ -2735,14 +2735,17 @@ Handle<Code> Factory::CopyCode(Handle<Code> code) {
NewCodeDataContainer(code->code_data_container()->kind_specific_flags()); NewCodeDataContainer(code->code_data_container()->kind_specific_flags());
Heap* heap = isolate()->heap(); Heap* heap = isolate()->heap();
Handle<Code> new_code;
{
int obj_size = code->Size(); int obj_size = code->Size();
CodePageCollectionMemoryModificationScope code_allocation(heap);
HeapObject* result = heap->AllocateRawWithRetryOrFail(obj_size, CODE_SPACE); HeapObject* result = heap->AllocateRawWithRetryOrFail(obj_size, CODE_SPACE);
// Copy code object. // Copy code object.
Address old_addr = code->address(); Address old_addr = code->address();
Address new_addr = result->address(); Address new_addr = result->address();
Heap::CopyBlock(new_addr, old_addr, obj_size); Heap::CopyBlock(new_addr, old_addr, obj_size);
Handle<Code> new_code(Code::cast(result), isolate()); new_code = handle(Code::cast(result), isolate());
// Set the {CodeDataContainer}, it cannot be shared. // Set the {CodeDataContainer}, it cannot be shared.
new_code->set_code_data_container(*data_container); new_code->set_code_data_container(*data_container);
...@@ -2753,6 +2756,7 @@ Handle<Code> Factory::CopyCode(Handle<Code> code) { ...@@ -2753,6 +2756,7 @@ Handle<Code> Factory::CopyCode(Handle<Code> code) {
heap->incremental_marking()->ProcessBlackAllocatedObject(*new_code); heap->incremental_marking()->ProcessBlackAllocatedObject(*new_code);
// Record all references to embedded objects in the new code object. // Record all references to embedded objects in the new code object.
WriteBarrierForCode(*new_code); WriteBarrierForCode(*new_code);
}
#ifdef VERIFY_HEAP #ifdef VERIFY_HEAP
if (FLAG_verify_heap) new_code->ObjectVerify(isolate()); if (FLAG_verify_heap) new_code->ObjectVerify(isolate());
......
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