| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 // Never allocate segments smaller than this size in bytes. | 79 // Never allocate segments smaller than this size in bytes. |
| 80 static const int kMinimumSegmentSize = 8 * KB; | 80 static const int kMinimumSegmentSize = 8 * KB; |
| 81 | 81 |
| 82 // Never allocate segments larger than this size in bytes. | 82 // Never allocate segments larger than this size in bytes. |
| 83 static const int kMaximumSegmentSize = 1 * MB; | 83 static const int kMaximumSegmentSize = 1 * MB; |
| 84 | 84 |
| 85 // Never keep segments larger than this size in bytes around. | 85 // Never keep segments larger than this size in bytes around. |
| 86 static const int kMaximumKeptSegmentSize = 64 * KB; | 86 static const int kMaximumKeptSegmentSize = 64 * KB; |
| 87 | 87 |
| 88 // Report zone excess when allocation exceeds this limit. | |
| 89 static int zone_excess_limit_; | |
| 90 | |
| 91 // The number of bytes allocated in segments. Note that this number | |
| 92 // includes memory allocated from the OS but not yet allocated from | |
| 93 // the zone. | |
| 94 static int segment_bytes_allocated_; | |
| 95 | |
| 96 // The Zone is intentionally a singleton; you should not try to | 88 // The Zone is intentionally a singleton; you should not try to |
| 97 // allocate instances of the class. | 89 // allocate instances of the class. |
| 98 Zone() { UNREACHABLE(); } | 90 Zone() { UNREACHABLE(); } |
| 99 | 91 |
| 100 | 92 |
| 101 // Expand the Zone to hold at least 'size' more bytes and allocate | 93 // Expand the Zone to hold at least 'size' more bytes and allocate |
| 102 // the bytes. Returns the address of the newly allocated chunk of | 94 // the bytes. Returns the address of the newly allocated chunk of |
| 103 // memory in the Zone. Should only be called if there isn't enough | 95 // memory in the Zone. Should only be called if there isn't enough |
| 104 // room in the Zone already. | 96 // room in the Zone already. |
| 105 static Address NewExpand(int size); | 97 static Address NewExpand(int size); |
| 98 }; |
| 106 | 99 |
| 100 class Segment; |
| 101 class ZoneData { |
| 102 friend class Zone; |
| 103 |
| 104 // Report zone excess when allocation exceeds this limit. |
| 105 int zone_excess_limit_; |
| 106 |
| 107 // The number of bytes allocated in segments. Note that this number |
| 108 // includes memory allocated from the OS but not yet allocated from |
| 109 // the zone. |
| 110 int segment_bytes_allocated_; |
| 107 | 111 |
| 108 // The free region in the current (front) segment is represented as | 112 // The free region in the current (front) segment is represented as |
| 109 // the half-open interval [position, limit). The 'position' variable | 113 // the half-open interval [position, limit). The 'position' variable |
| 110 // is guaranteed to be aligned as dictated by kAlignment. | 114 // is guaranteed to be aligned as dictated by kAlignment. |
| 111 static Address position_; | 115 Address position_; |
| 112 static Address limit_; | 116 Address limit_; |
| 117 |
| 118 Segment* head_; |
| 119 int bytes_allocated_; |
| 120 int nesting_; |
| 121 bool allow_allocation_; |
| 122 |
| 123 ZoneData(); |
| 124 |
| 125 friend class V8Context; |
| 126 friend class ZoneScope; |
| 127 friend class AssertNoZoneAllocation; |
| 128 friend class Zone; |
| 129 friend class Segment; |
| 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(ZoneData); |
| 113 }; | 132 }; |
| 114 | 133 |
| 115 | |
| 116 // ZoneObject is an abstraction that helps define classes of objects | 134 // ZoneObject is an abstraction that helps define classes of objects |
| 117 // allocated in the Zone. Use it as a base class; see ast.h. | 135 // allocated in the Zone. Use it as a base class; see ast.h. |
| 118 class ZoneObject { | 136 class ZoneObject { |
| 119 public: | 137 public: |
| 120 // Allocate a new ZoneObject of 'size' bytes in the Zone. | 138 // Allocate a new ZoneObject of 'size' bytes in the Zone. |
| 121 void* operator new(size_t size) { return Zone::New(static_cast<int>(size)); } | 139 void* operator new(size_t size) { return Zone::New(static_cast<int>(size)); } |
| 122 | 140 |
| 123 // Ideally, the delete operator should be private instead of | 141 // Ideally, the delete operator should be private instead of |
| 124 // public, but unfortunately the compiler sometimes synthesizes | 142 // public, but unfortunately the compiler sometimes synthesizes |
| 125 // (unused) destructors for classes derived from ZoneObject, which | 143 // (unused) destructors for classes derived from ZoneObject, which |
| 126 // require the operator to be visible. MSVC requires the delete | 144 // require the operator to be visible. MSVC requires the delete |
| 127 // operator to be public. | 145 // operator to be public. |
| 128 | 146 |
| 129 // ZoneObjects should never be deleted individually; use | 147 // ZoneObjects should never be deleted individually; use |
| 130 // Zone::DeleteAll() to delete all zone objects in one go. | 148 // Zone::DeleteAll() to delete all zone objects in one go. |
| 131 void operator delete(void*, size_t) { UNREACHABLE(); } | 149 void operator delete(void*, size_t) { UNREACHABLE(); } |
| 132 }; | 150 }; |
| 133 | 151 |
| 134 | 152 |
| 135 class AssertNoZoneAllocation { | 153 class AssertNoZoneAllocation { |
| 136 public: | 154 public: |
| 137 AssertNoZoneAllocation() : prev_(allow_allocation_) { | 155 AssertNoZoneAllocation() { |
| 138 allow_allocation_ = false; | 156 V8Context* const v8context = v8_context(); |
| 157 prev_ = v8context->zone_data_.allow_allocation_; |
| 158 v8context->zone_data_.allow_allocation_ = false; |
| 139 } | 159 } |
| 140 ~AssertNoZoneAllocation() { allow_allocation_ = prev_; } | 160 ~AssertNoZoneAllocation() { |
| 141 static bool allow_allocation() { return allow_allocation_; } | 161 v8_context()->zone_data_.allow_allocation_ = prev_; |
| 162 } |
| 163 static bool allow_allocation(const ZoneData& zone_data) { |
| 164 return zone_data.allow_allocation_; |
| 165 } |
| 142 private: | 166 private: |
| 143 bool prev_; | 167 bool prev_; |
| 144 static bool allow_allocation_; | |
| 145 }; | 168 }; |
| 146 | 169 |
| 147 | |
| 148 // The ZoneListAllocationPolicy is used to specialize the GenericList | 170 // The ZoneListAllocationPolicy is used to specialize the GenericList |
| 149 // implementation to allocate ZoneLists and their elements in the | 171 // implementation to allocate ZoneLists and their elements in the |
| 150 // Zone. | 172 // Zone. |
| 151 class ZoneListAllocationPolicy { | 173 class ZoneListAllocationPolicy { |
| 152 public: | 174 public: |
| 153 // Allocate 'size' bytes of memory in the zone. | 175 // Allocate 'size' bytes of memory in the zone. |
| 154 static void* New(int size) { return Zone::New(size); } | 176 static void* New(int size) { return Zone::New(size); } |
| 155 | 177 |
| 156 // De-allocation attempts are silently ignored. | 178 // De-allocation attempts are silently ignored. |
| 157 static void Delete(void* p) { } | 179 static void Delete(void* p) { } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 171 : List<T, ZoneListAllocationPolicy>(capacity) { } | 193 : List<T, ZoneListAllocationPolicy>(capacity) { } |
| 172 }; | 194 }; |
| 173 | 195 |
| 174 | 196 |
| 175 // ZoneScopes keep track of the current parsing and compilation | 197 // ZoneScopes keep track of the current parsing and compilation |
| 176 // nesting and cleans up generated ASTs in the Zone when exiting the | 198 // nesting and cleans up generated ASTs in the Zone when exiting the |
| 177 // outer-most scope. | 199 // outer-most scope. |
| 178 class ZoneScope BASE_EMBEDDED { | 200 class ZoneScope BASE_EMBEDDED { |
| 179 public: | 201 public: |
| 180 explicit ZoneScope(ZoneScopeMode mode) : mode_(mode) { | 202 explicit ZoneScope(ZoneScopeMode mode) : mode_(mode) { |
| 181 nesting_++; | 203 v8_context()->zone_data_.nesting_++; |
| 182 } | 204 } |
| 183 | 205 |
| 184 virtual ~ZoneScope() { | 206 virtual ~ZoneScope() { |
| 185 if (ShouldDeleteOnExit()) Zone::DeleteAll(); | 207 if (ShouldDeleteOnExit()) Zone::DeleteAll(); |
| 186 --nesting_; | 208 --v8_context()->zone_data_.nesting_; |
| 187 } | 209 } |
| 188 | 210 |
| 189 bool ShouldDeleteOnExit() { | 211 bool ShouldDeleteOnExit() { |
| 190 return nesting_ == 1 && mode_ == DELETE_ON_EXIT; | 212 return v8_context()->zone_data_.nesting_ == 1 && mode_ == DELETE_ON_EXIT; |
| 191 } | 213 } |
| 192 | 214 |
| 193 // For ZoneScopes that do not delete on exit by default, call this | 215 // For ZoneScopes that do not delete on exit by default, call this |
| 194 // method to request deletion on exit. | 216 // method to request deletion on exit. |
| 195 void DeleteOnExit() { | 217 void DeleteOnExit() { |
| 196 mode_ = DELETE_ON_EXIT; | 218 mode_ = DELETE_ON_EXIT; |
| 197 } | 219 } |
| 198 | 220 |
| 199 static int nesting() { return nesting_; } | 221 static int nesting(const ZoneData& zone_data) { return zone_data.nesting_; } |
| 200 | 222 |
| 201 private: | 223 private: |
| 202 ZoneScopeMode mode_; | 224 ZoneScopeMode mode_; |
| 203 static int nesting_; | |
| 204 }; | 225 }; |
| 205 | 226 |
| 206 | 227 |
| 207 // A zone splay tree. The config type parameter encapsulates the | 228 // A zone splay tree. The config type parameter encapsulates the |
| 208 // different configurations of a concrete splay tree: | 229 // different configurations of a concrete splay tree: |
| 209 // | 230 // |
| 210 // typedef Key: the key type | 231 // typedef Key: the key type |
| 211 // typedef Value: the value type | 232 // typedef Value: the value type |
| 212 // static const kNoKey: the dummy key used when no key is set | 233 // static const kNoKey: the dummy key used when no key is set |
| 213 // static const kNoValue: the dummy value used to initialize nodes | 234 // static const kNoValue: the dummy value used to initialize nodes |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 void ForEach(Callback* callback); | 317 void ForEach(Callback* callback); |
| 297 | 318 |
| 298 private: | 319 private: |
| 299 Node* root_; | 320 Node* root_; |
| 300 }; | 321 }; |
| 301 | 322 |
| 302 | 323 |
| 303 } } // namespace v8::internal | 324 } } // namespace v8::internal |
| 304 | 325 |
| 305 #endif // V8_ZONE_H_ | 326 #endif // V8_ZONE_H_ |
| OLD | NEW |