From f3eeeeaedcf4a92e9d6890497b25d0233f60a335 Mon Sep 17 00:00:00 2001 From: "erik.corry@gmail.com" Date: Fri, 11 Nov 2011 11:23:39 +0000 Subject: [PATCH] 8-byte align zone allocations of objects that may require it. Review URL: http://codereview.chromium.org/8539008 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9965 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/zone-inl.h | 8 ++++++++ src/zone.h | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/zone-inl.h b/src/zone-inl.h index 4870105..7e506e7 100644 --- a/src/zone-inl.h +++ b/src/zone-inl.h @@ -53,6 +53,14 @@ inline void* Zone::New(int size) { // Round up the requested size to fit the alignment. size = RoundUp(size, kAlignment); + // If the allocation size is divisible by 8 then we return an 8-byte aligned + // address. + if (kPointerSize == 4 && kAlignment == 4) { + position_ += ((~size) & 4) & (reinterpret_cast(position_) & 4); + } else { + ASSERT(kAlignment >= kPointerSize); + } + // Check if the requested size is available without expanding. Address result = position_; diff --git a/src/zone.h b/src/zone.h index f60ac0d..2ca3c4d 100644 --- a/src/zone.h +++ b/src/zone.h @@ -86,7 +86,9 @@ class Zone { friend class Isolate; friend class ZoneScope; - // All pointers returned from New() have this alignment. + // All pointers returned from New() have this alignment. In addition, if the + // object being allocated has a size that is divisible by 8 then its alignment + // will be 8. static const int kAlignment = kPointerSize; // Never allocate segments smaller than this size in bytes. -- 2.7.4