Commit ecc760a0 authored by yangguo's avatar yangguo Committed by Commit bot

[liveedit] simplify source position recalculation.

When updating source positions, we recompute reloc info. Under the
assumption that reloc info is appended to the code, we may or may not
need to allocate a new code object. That assumption is no longer valid
since 2010 (see r5020).

R=mstarzinger@chromium.org

Review-Url: https://codereview.chromium.org/2077363002
Cr-Commit-Position: refs/heads/master@{#37097}
parent 99eb5686
......@@ -1226,18 +1226,13 @@ Handle<Code> PatchPositionsInCode(Handle<Code> code,
}
Vector<byte> buffer = buffer_writer.GetResult();
Handle<ByteArray> reloc_info =
isolate->factory()->NewByteArray(buffer.length(), TENURED);
if (buffer.length() == code->relocation_size()) {
// Simply patch relocation area of code.
MemCopy(code->relocation_start(), buffer.start(), buffer.length());
return code;
} else {
// Relocation info section now has different size. We cannot simply
// rewrite it inside code object. Instead we have to create a new
// code object.
Handle<Code> result(isolate->factory()->CopyCode(code, buffer));
return result;
}
DisallowHeapAllocation no_gc;
code->set_relocation_info(*reloc_info);
CopyBytes(code->relocation_start(), buffer.start(), buffer.length());
return code;
}
void PatchPositionsInBytecodeArray(Handle<BytecodeArray> bytecode,
......
......@@ -1488,12 +1488,6 @@ Handle<Code> Factory::CopyCode(Handle<Code> code) {
}
Handle<Code> Factory::CopyCode(Handle<Code> code, Vector<byte> reloc_info) {
CALL_HEAP_FUNCTION(isolate(),
isolate()->heap()->CopyCode(*code, reloc_info),
Code);
}
Handle<BytecodeArray> Factory::CopyBytecodeArray(
Handle<BytecodeArray> bytecode_array) {
CALL_HEAP_FUNCTION(isolate(),
......
......@@ -3427,59 +3427,6 @@ AllocationResult Heap::CopyBytecodeArray(BytecodeArray* bytecode_array) {
return copy;
}
AllocationResult Heap::CopyCode(Code* code, Vector<byte> reloc_info) {
// Allocate ByteArray before the Code object, so that we do not risk
// leaving uninitialized Code object (and breaking the heap).
ByteArray* reloc_info_array = nullptr;
{
AllocationResult allocation =
AllocateByteArray(reloc_info.length(), TENURED);
if (!allocation.To(&reloc_info_array)) return allocation;
}
int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment);
int new_obj_size = Code::SizeFor(new_body_size);
Address old_addr = code->address();
size_t relocation_offset =
static_cast<size_t>(code->instruction_end() - old_addr);
HeapObject* result = nullptr;
AllocationResult allocation = AllocateRaw(new_obj_size, CODE_SPACE);
if (!allocation.To(&result)) return allocation;
// Copy code object.
Address new_addr = result->address();
// Copy header and instructions.
CopyBytes(new_addr, old_addr, relocation_offset);
Code* new_code = Code::cast(result);
new_code->set_relocation_info(reloc_info_array);
// Copy patched rinfo.
CopyBytes(new_code->relocation_start(), reloc_info.start(),
static_cast<size_t>(reloc_info.length()));
// Relocate the copy.
DCHECK(IsAligned(bit_cast<intptr_t>(new_code->address()), kCodeAlignment));
DCHECK(!memory_allocator()->code_range()->valid() ||
memory_allocator()->code_range()->contains(code->address()) ||
new_obj_size <= code_space()->AreaSize());
new_code->Relocate(new_addr - old_addr);
// We have to iterate over over the object and process its pointers when
// black allocation is on.
incremental_marking()->IterateBlackObject(new_code);
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) code->ObjectVerify();
#endif
return new_code;
}
void Heap::InitializeAllocationMemento(AllocationMemento* memento,
AllocationSite* allocation_site) {
memento->set_map_no_write_barrier(allocation_memento_map());
......
......@@ -1834,11 +1834,6 @@ class Heap {
AllocateBytecodeArray(int length, const byte* raw_bytecodes, int frame_size,
int parameter_count, FixedArray* constant_pool);
// Copy the code and scope info part of the code object, but insert
// the provided data as the relocation information.
MUST_USE_RESULT AllocationResult CopyCode(Code* code,
Vector<byte> reloc_info);
MUST_USE_RESULT AllocationResult CopyCode(Code* code);
MUST_USE_RESULT AllocationResult
......
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