From: bmeurer@chromium.org Date: Fri, 8 Aug 2014 08:13:06 +0000 (+0000) Subject: Make Zone::New() and Zone::NewArray() usable w/o v8.h. X-Git-Tag: upstream/4.7.83~7726 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e3ba1783edfd5a6898d3c47e023dde0e334ea1a;p=platform%2Fupstream%2Fv8.git Make Zone::New() and Zone::NewArray() usable w/o v8.h. R=svenpanne@chromium.org Review URL: https://codereview.chromium.org/456663002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22988 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/zone-inl.h b/src/zone-inl.h index c36bd98..cf037b5 100644 --- a/src/zone-inl.h +++ b/src/zone-inl.h @@ -24,54 +24,6 @@ namespace internal { static const int kASanRedzoneBytes = 24; // Must be a multiple of 8. -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 { - DCHECK(kAlignment >= kPointerSize); - } - - // Check if the requested size is available without expanding. - Address result = position_; - - int size_with_redzone = -#ifdef V8_USE_ADDRESS_SANITIZER - size + kASanRedzoneBytes; -#else - size; -#endif - - if (size_with_redzone > limit_ - position_) { - result = NewExpand(size_with_redzone); - } else { - position_ += size_with_redzone; - } - -#ifdef V8_USE_ADDRESS_SANITIZER - Address redzone_position = result + size; - DCHECK(redzone_position + kASanRedzoneBytes == position_); - ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes); -#endif - - // Check that the result has the proper alignment and return it. - DCHECK(IsAddressAligned(result, kAlignment, 0)); - allocation_size_ += size; - return reinterpret_cast(result); -} - - -template -T* Zone::NewArray(int length) { - CHECK(std::numeric_limits::max() / static_cast(sizeof(T)) > length); - return static_cast(New(length * sizeof(T))); -} - - bool Zone::excess_allocation() { return segment_bytes_allocated_ > kExcessLimit; } diff --git a/src/zone.cc b/src/zone.cc index 450e975..48d8c7b 100644 --- a/src/zone.cc +++ b/src/zone.cc @@ -62,6 +62,47 @@ Zone::~Zone() { } +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 { + DCHECK(kAlignment >= kPointerSize); + } + + // Check if the requested size is available without expanding. + Address result = position_; + + int size_with_redzone = +#ifdef V8_USE_ADDRESS_SANITIZER + size + kASanRedzoneBytes; +#else + size; +#endif + + if (size_with_redzone > limit_ - position_) { + result = NewExpand(size_with_redzone); + } else { + position_ += size_with_redzone; + } + +#ifdef V8_USE_ADDRESS_SANITIZER + Address redzone_position = result + size; + DCHECK(redzone_position + kASanRedzoneBytes == position_); + ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes); +#endif + + // Check that the result has the proper alignment and return it. + DCHECK(IsAddressAligned(result, kAlignment, 0)); + allocation_size_ += size; + return reinterpret_cast(result); +} + + void Zone::DeleteAll() { #ifdef DEBUG // Constant byte value used for zapping dead memory in debug mode. diff --git a/src/zone.h b/src/zone.h index a689f12..a690b8d 100644 --- a/src/zone.h +++ b/src/zone.h @@ -5,6 +5,8 @@ #ifndef V8_ZONE_H_ #define V8_ZONE_H_ +#include + #include "src/allocation.h" #include "src/base/logging.h" #include "src/globals.h" @@ -38,10 +40,14 @@ class Zone { ~Zone(); // Allocate 'size' bytes of memory in the Zone; expands the Zone by // allocating new segments of memory on demand using malloc(). - inline void* New(int size); + void* New(int size); template - inline T* NewArray(int length); + T* NewArray(int length) { + CHECK(std::numeric_limits::max() / static_cast(sizeof(T)) > + length); + return static_cast(New(length * sizeof(T))); + } // Deletes all objects and free all memory allocated in the Zone. Keeps one // small (size <= kMaximumKeptSegmentSize) segment around if it finds one.