Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Unified Diff: src/zone.cc

Issue 456663002: Make Zone::New() and Zone::NewArray() usable w/o v8.h. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/zone.h ('k') | src/zone-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/zone.cc
diff --git a/src/zone.cc b/src/zone.cc
index 450e975c9487003365644c31fe46cb0741f81c0f..48d8c7b171d54deaff81a861e48969adf276f786 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<intptr_t>(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<void*>(result);
+}
+
+
void Zone::DeleteAll() {
#ifdef DEBUG
// Constant byte value used for zapping dead memory in debug mode.
« no previous file with comments | « src/zone.h ('k') | src/zone-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698