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,
return;
}
Handle<Code> code;
{
CodeSpaceMemoryModificationScope code_allocation(isolate->heap());
code = isolate->factory()->CopyCode(
BUILTIN_CODE(isolate, InterpreterEntryTrampoline));
}
Handle<Code> code = isolate->factory()->CopyCode(
BUILTIN_CODE(isolate, InterpreterEntryTrampoline));
Handle<InterpreterData> interpreter_data = Handle<InterpreterData>::cast(
isolate->factory()->NewStruct(INTERPRETER_DATA_TYPE, TENURED));
......
......@@ -2735,24 +2735,28 @@ Handle<Code> Factory::CopyCode(Handle<Code> code) {
NewCodeDataContainer(code->code_data_container()->kind_specific_flags());
Heap* heap = isolate()->heap();
int obj_size = code->Size();
HeapObject* result = heap->AllocateRawWithRetryOrFail(obj_size, CODE_SPACE);
// Copy code object.
Address old_addr = code->address();
Address new_addr = result->address();
Heap::CopyBlock(new_addr, old_addr, obj_size);
Handle<Code> new_code(Code::cast(result), isolate());
// Set the {CodeDataContainer}, it cannot be shared.
new_code->set_code_data_container(*data_container);
new_code->Relocate(new_addr - old_addr);
// We have to iterate over the object and process its pointers when black
// allocation is on.
heap->incremental_marking()->ProcessBlackAllocatedObject(*new_code);
// Record all references to embedded objects in the new code object.
WriteBarrierForCode(*new_code);
Handle<Code> new_code;
{
int obj_size = code->Size();
CodePageCollectionMemoryModificationScope code_allocation(heap);
HeapObject* result = heap->AllocateRawWithRetryOrFail(obj_size, CODE_SPACE);
// Copy code object.
Address old_addr = code->address();
Address new_addr = result->address();
Heap::CopyBlock(new_addr, old_addr, obj_size);
new_code = handle(Code::cast(result), isolate());
// Set the {CodeDataContainer}, it cannot be shared.
new_code->set_code_data_container(*data_container);
new_code->Relocate(new_addr - old_addr);
// We have to iterate over the object and process its pointers when black
// allocation is on.
heap->incremental_marking()->ProcessBlackAllocatedObject(*new_code);
// Record all references to embedded objects in the new code object.
WriteBarrierForCode(*new_code);
}
#ifdef VERIFY_HEAP
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