Revision: 5020
Author: [email protected]
Date: Mon Jul  5 04:45:11 2010
Log: 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
http://code.google.com/p/v8/source/detail?r=5020

Modified:
 /branches/bleeding_edge/src/frames.cc
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/objects-inl.h
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/src/spaces.cc

=======================================
--- /branches/bleeding_edge/src/frames.cc       Tue Apr  6 10:58:28 2010
+++ /branches/bleeding_edge/src/frames.cc       Mon Jul  5 04:45:11 2010
@@ -542,7 +542,7 @@

       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);
=======================================
--- /branches/bleeding_edge/src/heap.cc Fri Jun 25 01:59:52 2010
+++ /branches/bleeding_edge/src/heap.cc Mon Jul  5 04:45:11 2010
@@ -2352,7 +2352,7 @@
                          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);
@@ -2366,12 +2366,15 @@

   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, 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();

@@ -2429,7 +2431,7 @@
   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()) {
@@ -2440,20 +2442,20 @@

   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());

=======================================
--- /branches/bleeding_edge/src/objects-inl.h   Fri Jul  2 07:36:34 2010
+++ /branches/bleeding_edge/src/objects-inl.h   Mon Jul  5 04:45:11 2010
@@ -2807,22 +2807,37 @@


 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_start()  {
   return FIELD_ADDR(this, kHeaderSize);
 }
+
+
+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();
 }


=======================================
--- /branches/bleeding_edge/src/objects.cc      Fri Jul  2 07:36:34 2010
+++ /branches/bleeding_edge/src/objects.cc      Mon Jul  5 04:45:11 2010
@@ -5314,7 +5314,15 @@
                   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);
   }

@@ -5333,14 +5341,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(),
=======================================
--- /branches/bleeding_edge/src/objects.h       Fri Jul  2 07:36:34 2010
+++ /branches/bleeding_edge/src/objects.h       Mon Jul  5 04:45:11 2010
@@ -2736,9 +2736,13 @@
   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 @@
   // 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 @@

   // 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
=======================================
--- /branches/bleeding_edge/src/spaces.cc       Mon Jun  7 01:27:32 2010
+++ /branches/bleeding_edge/src/spaces.cc       Mon Jul  5 04:45:11 2010
@@ -2305,8 +2305,8 @@
       }

       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);
     }
   }

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to