Revision: 22988
Author:   [email protected]
Date:     Fri Aug  8 08:13:06 2014 UTC
Log:      Make Zone::New() and Zone::NewArray() usable w/o v8.h.

[email protected]

Review URL: https://codereview.chromium.org/456663002
http://code.google.com/p/v8/source/detail?r=22988

Modified:
 /branches/bleeding_edge/src/zone-inl.h
 /branches/bleeding_edge/src/zone.cc
 /branches/bleeding_edge/src/zone.h

=======================================
--- /branches/bleeding_edge/src/zone-inl.h      Mon Aug  4 11:34:54 2014 UTC
+++ /branches/bleeding_edge/src/zone-inl.h      Fri Aug  8 08:13:06 2014 UTC
@@ -24,54 +24,6 @@
 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<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);
-}
-
-
-template <typename T>
-T* Zone::NewArray(int length) {
- CHECK(std::numeric_limits<int>::max() / static_cast<int>(sizeof(T)) > length);
-  return static_cast<T*>(New(length * sizeof(T)));
-}
-
-
 bool Zone::excess_allocation() {
   return segment_bytes_allocated_ > kExcessLimit;
 }
=======================================
--- /branches/bleeding_edge/src/zone.cc Mon Aug  4 11:34:54 2014 UTC
+++ /branches/bleeding_edge/src/zone.cc Fri Aug  8 08:13:06 2014 UTC
@@ -60,6 +60,47 @@

   DCHECK(segment_bytes_allocated_ == 0);
 }
+
+
+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() {
=======================================
--- /branches/bleeding_edge/src/zone.h  Mon Jun 30 13:25:46 2014 UTC
+++ /branches/bleeding_edge/src/zone.h  Fri Aug  8 08:13:06 2014 UTC
@@ -5,6 +5,8 @@
 #ifndef V8_ZONE_H_
 #define V8_ZONE_H_

+#include <limits>
+
 #include "src/allocation.h"
 #include "src/base/logging.h"
 #include "src/globals.h"
@@ -38,10 +40,14 @@
   ~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 <typename T>
-  inline T* NewArray(int length);
+  T* NewArray(int length) {
+    CHECK(std::numeric_limits<int>::max() / static_cast<int>(sizeof(T)) >
+          length);
+    return static_cast<T*>(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.

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to