From: kaznacheev@chromium.org Date: Mon, 5 Jul 2010 11:45:11 +0000 (+0000) Subject: Extracting relocation info from the code object. X-Git-Tag: upstream/4.7.83~21531 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8a4463306dd0ca2d181cf0578af7434cc3d06c29;p=platform%2Fupstream%2Fv8.git Extracting relocation info from the code object. It is now stored in a ByteArray referenced from the code object header. Review URL: http://codereview.chromium.org/2812041 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5020 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/frames.cc b/src/frames.cc index 9cf83c9..67a20d3 100644 --- a/src/frames.cc +++ b/src/frames.cc @@ -542,7 +542,7 @@ void JavaScriptFrame::Print(StringStream* accumulator, Address pc = this->pc(); if (code != NULL && code->kind() == Code::FUNCTION && - pc >= code->instruction_start() && pc < code->relocation_start()) { + pc >= code->instruction_start() && pc < code->instruction_end()) { int source_pos = code->SourcePosition(pc); int line = GetScriptLineNumberSafe(script, source_pos) + 1; accumulator->Add(":%d", line); diff --git a/src/heap.cc b/src/heap.cc index 6ae46f2..3c79d0d 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -2352,7 +2352,7 @@ Object* Heap::CreateCode(const CodeDesc& desc, Code::Flags flags, Handle self_reference) { // Compute size - int body_size = RoundUp(desc.instr_size + desc.reloc_size, kObjectAlignment); + int body_size = RoundUp(desc.instr_size, kObjectAlignment); int sinfo_size = 0; if (sinfo != NULL) sinfo_size = sinfo->Serialize(NULL); int obj_size = Code::SizeFor(body_size, sinfo_size); @@ -2366,12 +2366,15 @@ Object* Heap::CreateCode(const CodeDesc& desc, if (result->IsFailure()) return result; + Object* reloc_info = AllocateByteArray(desc.reloc_size, TENURED); + if (reloc_info->IsFailure()) return reloc_info; + // Initialize the object HeapObject::cast(result)->set_map(code_map()); Code* code = Code::cast(result); ASSERT(!CodeRange::exists() || CodeRange::contains(code->address())); code->set_instruction_size(desc.instr_size); - code->set_relocation_size(desc.reloc_size); + code->set_relocation_info(ByteArray::cast(reloc_info)); code->set_sinfo_size(sinfo_size); code->set_flags(flags); // Allow self references to created code object by patching the handle to @@ -2419,8 +2422,7 @@ Object* Heap::CopyCode(Code* code) { Object* Heap::CopyCode(Code* code, Vector reloc_info) { - int new_body_size = RoundUp(code->instruction_size() + reloc_info.length(), - kObjectAlignment); + int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment); int sinfo_size = code->sinfo_size(); @@ -2429,7 +2431,7 @@ Object* Heap::CopyCode(Code* code, Vector reloc_info) { Address old_addr = code->address(); size_t relocation_offset = - static_cast(code->relocation_start() - old_addr); + static_cast(code->instruction_end() - old_addr); Object* result; if (new_obj_size > MaxObjectSizeInPagedSpace()) { @@ -2440,20 +2442,20 @@ Object* Heap::CopyCode(Code* code, Vector reloc_info) { if (result->IsFailure()) return result; + Object* reloc_info_array = AllocateByteArray(reloc_info.length(), TENURED); + if (reloc_info_array->IsFailure()) return reloc_info_array; + // Copy code object. Address new_addr = reinterpret_cast(result)->address(); // Copy header and instructions. memcpy(new_addr, old_addr, relocation_offset); - // Copy patched rinfo. - memcpy(new_addr + relocation_offset, - reloc_info.start(), - reloc_info.length()); - Code* new_code = Code::cast(result); - new_code->set_relocation_size(reloc_info.length()); + new_code->set_relocation_info(ByteArray::cast(reloc_info_array)); + // Copy patched rinfo. + memcpy(new_code->relocation_start(), reloc_info.start(), reloc_info.length()); // Copy sinfo. memcpy(new_code->sinfo_start(), code->sinfo_start(), code->sinfo_size()); diff --git a/src/objects-inl.h b/src/objects-inl.h index 79f2c97..0e45550 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -2807,7 +2807,7 @@ JSValue* JSValue::cast(Object* obj) { INT_ACCESSORS(Code, instruction_size, kInstructionSizeOffset) -INT_ACCESSORS(Code, relocation_size, kRelocationSizeOffset) +ACCESSORS(Code, relocation_info, ByteArray, kRelocationInfoOffset) INT_ACCESSORS(Code, sinfo_size, kSInfoSizeOffset) @@ -2816,13 +2816,28 @@ byte* Code::instruction_start() { } +byte* Code::instruction_end() { + return instruction_start() + instruction_size(); +} + + int Code::body_size() { - return RoundUp(instruction_size() + relocation_size(), kObjectAlignment); + return RoundUp(instruction_size(), kObjectAlignment); +} + + +ByteArray* Code::unchecked_relocation_info() { + return reinterpret_cast(READ_FIELD(this, kRelocationInfoOffset)); } byte* Code::relocation_start() { - return FIELD_ADDR(this, kHeaderSize + instruction_size()); + return unchecked_relocation_info()->GetDataStartAddress(); +} + + +int Code::relocation_size() { + return unchecked_relocation_info()->length(); } diff --git a/src/objects.cc b/src/objects.cc index 8288f63..e79a550 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -5314,7 +5314,15 @@ void Code::CodeIterateBody(ObjectVisitor* v) { RelocInfo::ModeMask(RelocInfo::DEBUG_BREAK_SLOT) | RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY); - for (RelocIterator it(this, mode_mask); !it.done(); it.next()) { + // Use the relocation info pointer before it is visited by + // the heap compaction in the next statement. + RelocIterator it(this, mode_mask); + + IteratePointers(v, + kRelocationInfoOffset, + kRelocationInfoOffset + kPointerSize); + + for (; !it.done(); it.next()) { it.rinfo()->Visit(v); } @@ -5334,14 +5342,6 @@ void Code::CopyFrom(const CodeDesc& desc) { // copy code memmove(instruction_start(), desc.buffer, desc.instr_size); - // fill gap with zero bytes - { byte* p = instruction_start() + desc.instr_size; - byte* q = relocation_start(); - while (p < q) { - *p++ = 0; - } - } - // copy reloc info memmove(relocation_start(), desc.buffer + desc.buffer_size - desc.reloc_size, diff --git a/src/objects.h b/src/objects.h index 15cfd5c..dc59d57 100644 --- a/src/objects.h +++ b/src/objects.h @@ -2736,9 +2736,13 @@ class Code: public HeapObject { inline int instruction_size(); inline void set_instruction_size(int value); - // [relocation_size]: Size of relocation information. + // [relocation_info]: Code relocation information + DECL_ACCESSORS(relocation_info, ByteArray) + + // Unchecked accessor to be used during GC. + inline ByteArray* unchecked_relocation_info(); + inline int relocation_size(); - inline void set_relocation_size(int value); // [sinfo_size]: Size of scope information. inline int sinfo_size(); @@ -2797,6 +2801,9 @@ class Code: public HeapObject { // Returns the address of the first instruction. inline byte* instruction_start(); + // Returns the address right after the last instruction. + inline byte* instruction_end(); + // Returns the size of the instructions, padding, and relocation information. inline int body_size(); @@ -2857,8 +2864,8 @@ class Code: public HeapObject { // Layout description. static const int kInstructionSizeOffset = HeapObject::kHeaderSize; - static const int kRelocationSizeOffset = kInstructionSizeOffset + kIntSize; - static const int kSInfoSizeOffset = kRelocationSizeOffset + kIntSize; + static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize; + static const int kSInfoSizeOffset = kRelocationInfoOffset + kPointerSize; static const int kFlagsOffset = kSInfoSizeOffset + kIntSize; static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize; // Add padding to align the instruction start following right after diff --git a/src/spaces.cc b/src/spaces.cc index 3c495ba..ca4b66a 100644 --- a/src/spaces.cc +++ b/src/spaces.cc @@ -2305,8 +2305,8 @@ void PagedSpace::CollectCodeStatistics() { } ASSERT(code->instruction_start() <= prev_pc && - prev_pc <= code->relocation_start()); - delta += static_cast(code->relocation_start() - prev_pc); + prev_pc <= code->instruction_end()); + delta += static_cast(code->instruction_end() - prev_pc); EnterComment("NoComment", delta); } }