| OLD | NEW | 
|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef V8_ZONE_H_ | 5 #ifndef V8_ZONE_H_ | 
| 6 #define V8_ZONE_H_ | 6 #define V8_ZONE_H_ | 
| 7 | 7 | 
| 8 #include <limits> | 8 #include <limits> | 
| 9 | 9 | 
| 10 #include "src/allocation.h" | 10 #include "src/allocation.h" | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 29 | 29 | 
| 30 // Note: There is no need to initialize the Zone; the first time an | 30 // Note: There is no need to initialize the Zone; the first time an | 
| 31 // allocation is attempted, a segment of memory will be requested | 31 // allocation is attempted, a segment of memory will be requested | 
| 32 // through a call to malloc(). | 32 // through a call to malloc(). | 
| 33 | 33 | 
| 34 // Note: The implementation is inherently not thread safe. Do not use | 34 // Note: The implementation is inherently not thread safe. Do not use | 
| 35 // from multi-threaded code. | 35 // from multi-threaded code. | 
| 36 | 36 | 
| 37 class Zone { | 37 class Zone { | 
| 38  public: | 38  public: | 
| 39   explicit Zone(Isolate* isolate); | 39   Zone(); | 
| 40   ~Zone(); | 40   ~Zone(); | 
| 41   // Allocate 'size' bytes of memory in the Zone; expands the Zone by | 41   // Allocate 'size' bytes of memory in the Zone; expands the Zone by | 
| 42   // allocating new segments of memory on demand using malloc(). | 42   // allocating new segments of memory on demand using malloc(). | 
| 43   void* New(int size); | 43   void* New(int size); | 
| 44 | 44 | 
| 45   template <typename T> | 45   template <typename T> | 
| 46   T* NewArray(int length) { | 46   T* NewArray(int length) { | 
| 47     CHECK(std::numeric_limits<int>::max() / static_cast<int>(sizeof(T)) > | 47     CHECK(std::numeric_limits<int>::max() / static_cast<int>(sizeof(T)) > | 
| 48           length); | 48           length); | 
| 49     return static_cast<T*>(New(length * sizeof(T))); | 49     return static_cast<T*>(New(length * sizeof(T))); | 
| 50   } | 50   } | 
| 51 | 51 | 
| 52   // Deletes all objects and free all memory allocated in the Zone. Keeps one | 52   // Deletes all objects and free all memory allocated in the Zone. Keeps one | 
| 53   // small (size <= kMaximumKeptSegmentSize) segment around if it finds one. | 53   // small (size <= kMaximumKeptSegmentSize) segment around if it finds one. | 
| 54   void DeleteAll(); | 54   void DeleteAll(); | 
| 55 | 55 | 
| 56   // Deletes the last small segment kept around by DeleteAll(). You | 56   // Deletes the last small segment kept around by DeleteAll(). You | 
| 57   // may no longer allocate in the Zone after a call to this method. | 57   // may no longer allocate in the Zone after a call to this method. | 
| 58   void DeleteKeptSegment(); | 58   void DeleteKeptSegment(); | 
| 59 | 59 | 
| 60   // Returns true if more memory has been allocated in zones than | 60   // Returns true if more memory has been allocated in zones than | 
| 61   // the limit allows. | 61   // the limit allows. | 
| 62   inline bool excess_allocation(); | 62   inline bool excess_allocation(); | 
| 63 | 63 | 
| 64   inline void adjust_segment_bytes_allocated(int delta); | 64   inline void adjust_segment_bytes_allocated(int delta); | 
| 65 | 65 | 
| 66   inline unsigned allocation_size() const { return allocation_size_; } | 66   inline unsigned allocation_size() const { return allocation_size_; } | 
| 67 | 67 | 
| 68   inline Isolate* isolate() const { return isolate_; } |  | 
| 69 |  | 
| 70  private: | 68  private: | 
| 71   friend class Isolate; | 69   friend class Isolate; | 
| 72 | 70 | 
| 73   // All pointers returned from New() have this alignment.  In addition, if the | 71   // All pointers returned from New() have this alignment.  In addition, if the | 
| 74   // object being allocated has a size that is divisible by 8 then its alignment | 72   // object being allocated has a size that is divisible by 8 then its alignment | 
| 75   // will be 8. ASan requires 8-byte alignment. | 73   // will be 8. ASan requires 8-byte alignment. | 
| 76 #ifdef V8_USE_ADDRESS_SANITIZER | 74 #ifdef V8_USE_ADDRESS_SANITIZER | 
| 77   static const int kAlignment = 8; | 75   static const int kAlignment = 8; | 
| 78   STATIC_ASSERT(kPointerSize <= 8); | 76   STATIC_ASSERT(kPointerSize <= 8); | 
| 79 #else | 77 #else | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 113   // Deletes the given segment. Does not touch the segment chain. | 111   // Deletes the given segment. Does not touch the segment chain. | 
| 114   INLINE(void DeleteSegment(Segment* segment, int size)); | 112   INLINE(void DeleteSegment(Segment* segment, int size)); | 
| 115 | 113 | 
| 116   // The free region in the current (front) segment is represented as | 114   // The free region in the current (front) segment is represented as | 
| 117   // the half-open interval [position, limit). The 'position' variable | 115   // the half-open interval [position, limit). The 'position' variable | 
| 118   // is guaranteed to be aligned as dictated by kAlignment. | 116   // is guaranteed to be aligned as dictated by kAlignment. | 
| 119   Address position_; | 117   Address position_; | 
| 120   Address limit_; | 118   Address limit_; | 
| 121 | 119 | 
| 122   Segment* segment_head_; | 120   Segment* segment_head_; | 
| 123   Isolate* isolate_; |  | 
| 124 }; | 121 }; | 
| 125 | 122 | 
| 126 | 123 | 
| 127 // ZoneObject is an abstraction that helps define classes of objects | 124 // ZoneObject is an abstraction that helps define classes of objects | 
| 128 // allocated in the Zone. Use it as a base class; see ast.h. | 125 // allocated in the Zone. Use it as a base class; see ast.h. | 
| 129 class ZoneObject { | 126 class ZoneObject { | 
| 130  public: | 127  public: | 
| 131   // Allocate a new ZoneObject of 'size' bytes in the Zone. | 128   // Allocate a new ZoneObject of 'size' bytes in the Zone. | 
| 132   INLINE(void* operator new(size_t size, Zone* zone)); | 129   INLINE(void* operator new(size_t size, Zone* zone)); | 
| 133 | 130 | 
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 240   void operator delete(void* pointer) { UNREACHABLE(); } | 237   void operator delete(void* pointer) { UNREACHABLE(); } | 
| 241   void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } | 238   void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } | 
| 242 }; | 239 }; | 
| 243 | 240 | 
| 244 | 241 | 
| 245 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; | 242 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; | 
| 246 | 243 | 
| 247 } }  // namespace v8::internal | 244 } }  // namespace v8::internal | 
| 248 | 245 | 
| 249 #endif  // V8_ZONE_H_ | 246 #endif  // V8_ZONE_H_ | 
| OLD | NEW | 
|---|