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);
Code::Flags flags,
Handle<Object> 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);
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
Object* Heap::CopyCode(Code* code, Vector<byte> 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();
Address old_addr = code->address();
size_t relocation_offset =
- static_cast<size_t>(code->relocation_start() - old_addr);
+ static_cast<size_t>(code->instruction_end() - old_addr);
Object* result;
if (new_obj_size > MaxObjectSizeInPagedSpace()) {
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<HeapObject*>(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());
INT_ACCESSORS(Code, instruction_size, kInstructionSizeOffset)
-INT_ACCESSORS(Code, relocation_size, kRelocationSizeOffset)
+ACCESSORS(Code, relocation_info, ByteArray, kRelocationInfoOffset)
INT_ACCESSORS(Code, sinfo_size, kSInfoSizeOffset)
}
+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<ByteArray*>(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();
}
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);
}
// 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,
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();
// 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();
// 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
}
ASSERT(code->instruction_start() <= prev_pc &&
- prev_pc <= code->relocation_start());
- delta += static_cast<int>(code->relocation_start() - prev_pc);
+ prev_pc <= code->instruction_end());
+ delta += static_cast<int>(code->instruction_end() - prev_pc);
EnterComment("NoComment", delta);
}
}