From 589eb4a8616ec5ea2dc302900c404631f9bb9a4e Mon Sep 17 00:00:00 2001 From: "dimich@chromium.org" Date: Fri, 24 Sep 2010 21:48:44 +0000 Subject: [PATCH] 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 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5526 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/globals.h | 10 ++++++++++ src/heap.cc | 2 +- src/objects-debug.cc | 2 +- src/objects.h | 8 +------- src/spaces.h | 6 ++++-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/globals.h b/src/globals.h index f168d6eb14..fbc749da85 100644 --- a/src/globals.h +++ b/src/globals.h @@ -214,6 +214,12 @@ const intptr_t kMapAlignmentBits = kObjectAlignmentBits + 3; 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 @@ enum StateTag { #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 diff --git a/src/heap.cc b/src/heap.cc index f61e343f4f..047e331614 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -2444,7 +2444,7 @@ Object* Heap::CreateCode(const CodeDesc& desc, // 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(obj_size), kCodeAlignment)); Object* result; if (obj_size > MaxObjectSizeInPagedSpace()) { result = lo_space_->AllocateRawCode(obj_size); diff --git a/src/objects-debug.cc b/src/objects-debug.cc index 078b23f6b0..ed08468e5c 100644 --- a/src/objects-debug.cc +++ b/src/objects-debug.cc @@ -905,7 +905,7 @@ void Code::CodePrint() { void Code::CodeVerify() { CHECK(IsAligned(reinterpret_cast(instruction_start()), - static_cast(kCodeAlignment))); + kCodeAlignment)); Address last_gc_pc = NULL; for (RelocIterator it(this); !it.done(); it.next()) { it.rinfo()->Verify(); diff --git a/src/objects.h b/src/objects.h index 307f9cdc91..7f301b5c02 100644 --- a/src/objects.h +++ b/src/objects.h @@ -3013,11 +3013,6 @@ class Code: public HeapObject { 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 @@ class Code: public HeapObject { // 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; diff --git a/src/spaces.h b/src/spaces.h index 9ffa940489..94e0cd24f9 100644 --- a/src/spaces.h +++ b/src/spaces.h @@ -243,8 +243,10 @@ class Page { 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;