Revision: 5526
Author: [email protected]
Date: Fri Sep 24 14:48:44 2010
Log: Add CODE_POINTER_ALIGN, use it in Page to align generated code.

The object's space in Page starts after Page header and is aligned to kMapAlignment which is 32 bytes on 32-bit and 8 bytes on 64-bit.

In case of 64-bit target, the current page header size is exactly 32 bytes so we get the code magically aligned at 32 bytes but it is better to have a separate CODE_POINTER_ALIGN macro to make sure the object space in Page is aligned properly for both maps and code.

There could be a small waste of bytes sometimes (since both Page header and Code header sizes are aligned separately) but it seems the optimal one would involve cross-dependencies between .h files and not clear if it's worth it.

This is a back-port from Isolates branch.

Review URL: http://codereview.chromium.org/3461021
http://code.google.com/p/v8/source/detail?r=5526

Modified:
 /branches/bleeding_edge/src/globals.h
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/objects-debug.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/src/spaces.h

=======================================
--- /branches/bleeding_edge/src/globals.h       Tue Aug 31 01:05:42 2010
+++ /branches/bleeding_edge/src/globals.h       Fri Sep 24 14:48:44 2010
@@ -214,6 +214,12 @@
 const intptr_t kMapAlignment = (1 << kMapAlignmentBits);
 const intptr_t kMapAlignmentMask = kMapAlignment - 1;

+// Desired alignment for generated code is 32 bytes (to improve cache line
+// utilization).
+const int kCodeAlignmentBits = 5;
+const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
+const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
+
 // Tag information for Failure.
 const int kFailureTag = 3;
 const int kFailureTagSize = 2;
@@ -588,6 +594,10 @@
 #define MAP_POINTER_ALIGN(value)                                \
   (((value) + kMapAlignmentMask) & ~kMapAlignmentMask)

+// CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
+#define CODE_POINTER_ALIGN(value)                               \
+  (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
+
 // The expression OFFSET_OF(type, field) computes the byte-offset
 // of the specified field relative to the containing type. This
 // corresponds to 'offsetof' (in stddef.h), except that it doesn't
=======================================
--- /branches/bleeding_edge/src/heap.cc Fri Sep 24 04:45:12 2010
+++ /branches/bleeding_edge/src/heap.cc Fri Sep 24 14:48:44 2010
@@ -2444,7 +2444,7 @@
   // Compute size
   int body_size = RoundUp(desc.instr_size, kObjectAlignment);
   int obj_size = Code::SizeFor(body_size);
-  ASSERT(IsAligned(obj_size, Code::kCodeAlignment));
+  ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment));
   Object* result;
   if (obj_size > MaxObjectSizeInPagedSpace()) {
     result = lo_space_->AllocateRawCode(obj_size);
=======================================
--- /branches/bleeding_edge/src/objects-debug.cc        Fri Sep 24 01:18:33 2010
+++ /branches/bleeding_edge/src/objects-debug.cc        Fri Sep 24 14:48:44 2010
@@ -905,7 +905,7 @@

 void Code::CodeVerify() {
   CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()),
-                  static_cast<intptr_t>(kCodeAlignment)));
+                  kCodeAlignment));
   Address last_gc_pc = NULL;
   for (RelocIterator it(this); !it.done(); it.next()) {
     it.rinfo()->Verify();
=======================================
--- /branches/bleeding_edge/src/objects.h       Fri Sep 24 01:18:33 2010
+++ /branches/bleeding_edge/src/objects.h       Fri Sep 24 14:48:44 2010
@@ -3013,11 +3013,6 @@
   void CodePrint();
   void CodeVerify();
 #endif
-  // Code entry points are aligned to 32 bytes.
-  static const int kCodeAlignmentBits = 5;
-  static const int kCodeAlignment = 1 << kCodeAlignmentBits;
-  static const int kCodeAlignmentMask = kCodeAlignment - 1;
-
   // Layout description.
   static const int kInstructionSizeOffset = HeapObject::kHeaderSize;
static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize;
@@ -3026,8 +3021,7 @@
   // Add padding to align the instruction start following right after
   // the Code object header.
   static const int kHeaderSize =
-      (kKindSpecificFlagsOffset + kIntSize + kCodeAlignmentMask) &
-          ~kCodeAlignmentMask;
+      CODE_POINTER_ALIGN(kKindSpecificFlagsOffset + kIntSize);

   // Byte offsets within kKindSpecificFlagsOffset.
   static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset + 1;
=======================================
--- /branches/bleeding_edge/src/spaces.h        Fri Sep  3 05:00:05 2010
+++ /branches/bleeding_edge/src/spaces.h        Fri Sep 24 14:48:44 2010
@@ -243,8 +243,10 @@
static const int kPageHeaderSize = kPointerSize + kPointerSize + kIntSize +
     kIntSize + kPointerSize;

-  // The start offset of the object area in a page.
-  static const int kObjectStartOffset = MAP_POINTER_ALIGN(kPageHeaderSize);
+ // The start offset of the object area in a page. Aligned to both maps and
+  // code alignment to be suitable for both.
+  static const int kObjectStartOffset =
+      CODE_POINTER_ALIGN(MAP_POINTER_ALIGN(kPageHeaderSize));

   // Object area size in bytes.
   static const int kObjectAreaSize = kPageSize - kObjectStartOffset;

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

Reply via email to