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
This commit is contained in:
dimich@chromium.org 2010-09-24 21:48:44 +00:00
parent c39194e06f
commit 589eb4a861
5 changed files with 17 additions and 11 deletions

View File

@ -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

View File

@ -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<intptr_t>(obj_size), kCodeAlignment));
Object* result;
if (obj_size > MaxObjectSizeInPagedSpace()) {
result = lo_space_->AllocateRawCode(obj_size);

View File

@ -905,7 +905,7 @@ void Code::CodePrint() {
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();

View File

@ -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;

View File

@ -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;