Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_PAGES_H_ | 5 #ifndef VM_PAGES_H_ |
| 6 #define VM_PAGES_H_ | 6 #define VM_PAGES_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "vm/freelist.h" | 10 #include "vm/freelist.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 HeapPage* next() const { return next_; } | 24 HeapPage* next() const { return next_; } |
| 25 void set_next(HeapPage* next) { next_ = next; } | 25 void set_next(HeapPage* next) { next_ = next; } |
| 26 | 26 |
| 27 bool Contains(uword addr) { | 27 bool Contains(uword addr) { |
| 28 return memory_->Contains(addr); | 28 return memory_->Contains(addr); |
| 29 } | 29 } |
| 30 | 30 |
| 31 uword start() const { return reinterpret_cast<uword>(this); } | 31 uword start() const { return reinterpret_cast<uword>(this); } |
| 32 uword end() const { return memory_->end(); } | 32 uword end() const { return memory_->end(); } |
| 33 | 33 |
| 34 uword top() const { return top_; } | |
| 35 void set_top(uword top) { top_ = top; } | |
| 36 | |
| 37 uword first_object_start() const { | 34 uword first_object_start() const { |
| 38 return (reinterpret_cast<uword>(this) + sizeof(HeapPage)); | 35 return (reinterpret_cast<uword>(this) + sizeof(HeapPage)); |
| 39 } | 36 } |
| 40 | 37 |
| 41 void set_used(uword used) { used_ = used; } | 38 void set_used(uword used) { used_ = used; } |
| 42 uword used() const { return used_; } | 39 uword used() const { return used_; } |
| 43 void AddUsed(uword size) { | 40 void AddUsed(uword size) { |
| 44 used_ += size; | 41 used_ += size; |
| 45 } | 42 } |
| 46 | 43 |
| 47 uword TryBumpAllocate(intptr_t size) { | |
| 48 uword result = top(); | |
| 49 intptr_t remaining_space = end() - result; | |
| 50 if (remaining_space < size) { | |
| 51 return 0; | |
| 52 } | |
| 53 set_top(result + size); | |
| 54 return result; | |
| 55 } | |
| 56 | |
| 57 void VisitObjects(ObjectVisitor* visitor) const; | 44 void VisitObjects(ObjectVisitor* visitor) const; |
| 58 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; | 45 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; |
| 59 | 46 |
| 60 RawObject* FindObject(FindObjectVisitor* visitor) const; | 47 RawObject* FindObject(FindObjectVisitor* visitor) const; |
| 61 | 48 |
| 62 void WriteProtect(bool read_only); | 49 void WriteProtect(bool read_only); |
| 63 | 50 |
| 64 private: | 51 private: |
| 65 static HeapPage* Initialize(VirtualMemory* memory, bool is_executable); | 52 static HeapPage* Initialize(VirtualMemory* memory, bool is_executable); |
| 66 static HeapPage* Allocate(intptr_t size, bool is_executable); | 53 static HeapPage* Allocate(intptr_t size, bool is_executable); |
| 67 | 54 |
| 68 // Deallocate the virtual memory backing this page. The page pointer to this | 55 // Deallocate the virtual memory backing this page. The page pointer to this |
| 69 // page becomes immediately inaccessible. | 56 // page becomes immediately inaccessible. |
| 70 void Deallocate(); | 57 void Deallocate(); |
| 71 | 58 |
| 72 VirtualMemory* memory_; | 59 VirtualMemory* memory_; |
| 73 HeapPage* next_; | 60 HeapPage* next_; |
| 74 uword used_; | 61 uword used_; |
| 75 uword top_; | 62 uword alignment_; // Needed to allocate old objects with kOldObjectAlignment. |
|
cshapiro
2012/10/17 02:53:22
This is a bit confusing. Is this member reference
Ivan Posva
2012/10/18 17:34:21
It is padding, which I tried to convey with the na
| |
| 76 | 63 |
| 77 friend class PageSpace; | 64 friend class PageSpace; |
| 78 | 65 |
| 79 DISALLOW_ALLOCATION(); | 66 DISALLOW_ALLOCATION(); |
| 80 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapPage); | 67 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapPage); |
| 81 }; | 68 }; |
| 82 | 69 |
| 83 | 70 |
| 84 // The history holds the timing information of the last garbage collection | 71 // The history holds the timing information of the last garbage collection |
| 85 // runs. | 72 // runs. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 | 196 |
| 210 void* GetPeer(RawObject* raw_obj); | 197 void* GetPeer(RawObject* raw_obj); |
| 211 | 198 |
| 212 int64_t PeerCount() const; | 199 int64_t PeerCount() const; |
| 213 | 200 |
| 214 PeerTable* GetPeerTable() { return &peer_table_; } | 201 PeerTable* GetPeerTable() { return &peer_table_; } |
| 215 | 202 |
| 216 private: | 203 private: |
| 217 static const intptr_t kAllocatablePageSize = kPageSize - sizeof(HeapPage); | 204 static const intptr_t kAllocatablePageSize = kPageSize - sizeof(HeapPage); |
| 218 | 205 |
| 219 void AllocatePage(); | 206 HeapPage* AllocatePage(); |
| 220 void FreePage(HeapPage* page, HeapPage* previous_page); | 207 void FreePage(HeapPage* page, HeapPage* previous_page); |
| 221 HeapPage* AllocateLargePage(intptr_t size); | 208 HeapPage* AllocateLargePage(intptr_t size); |
| 222 void FreeLargePage(HeapPage* page, HeapPage* previous_page); | 209 void FreeLargePage(HeapPage* page, HeapPage* previous_page); |
| 223 void FreePages(HeapPage* pages); | 210 void FreePages(HeapPage* pages); |
| 224 | 211 |
| 225 static intptr_t LargePageSizeFor(intptr_t size); | 212 static intptr_t LargePageSizeFor(intptr_t size); |
| 226 | 213 |
| 227 bool CanIncreaseCapacity(intptr_t increase) { | 214 bool CanIncreaseCapacity(intptr_t increase) { |
| 228 ASSERT(capacity_ <= max_capacity_); | 215 ASSERT(capacity_ <= max_capacity_); |
| 229 return increase <= (max_capacity_ - capacity_); | 216 return increase <= (max_capacity_ - capacity_); |
| 230 } | 217 } |
| 231 | 218 |
| 232 uword TryBumpAllocate(intptr_t size); | |
| 233 | |
| 234 FreeList freelist_; | 219 FreeList freelist_; |
| 235 | 220 |
| 236 Heap* heap_; | 221 Heap* heap_; |
| 237 | 222 |
| 238 HeapPage* pages_; | 223 HeapPage* pages_; |
| 239 HeapPage* pages_tail_; | 224 HeapPage* pages_tail_; |
| 240 HeapPage* large_pages_; | 225 HeapPage* large_pages_; |
| 241 | 226 |
| 242 PeerTable peer_table_; | 227 PeerTable peer_table_; |
| 243 | 228 |
| 244 // Page being used for bump allocation. | |
| 245 // The value has different meanings: | |
| 246 // NULL: Still bump allocating from last allocated fresh page. | |
| 247 // !NULL: Last page that had enough room to bump allocate, when we reach the | |
| 248 // tail page, we give up bump allocating. | |
| 249 HeapPage* bump_page_; | |
| 250 | |
| 251 // Various sizes being tracked for this generation. | 229 // Various sizes being tracked for this generation. |
| 252 intptr_t max_capacity_; | 230 intptr_t max_capacity_; |
| 253 intptr_t capacity_; | 231 intptr_t capacity_; |
| 254 intptr_t in_use_; | 232 intptr_t in_use_; |
| 255 | 233 |
| 256 // Old-gen GC cycle count. | 234 // Old-gen GC cycle count. |
| 257 int count_; | 235 int count_; |
| 258 | 236 |
| 259 bool is_executable_; | 237 bool is_executable_; |
| 260 | 238 |
| 261 // Keep track whether a MarkSweep is currently running. | 239 // Keep track whether a MarkSweep is currently running. |
| 262 bool sweeping_; | 240 bool sweeping_; |
| 263 | 241 |
| 264 PageSpaceController page_space_controller_; | 242 PageSpaceController page_space_controller_; |
| 265 | 243 |
| 266 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace); | 244 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace); |
| 267 }; | 245 }; |
| 268 | 246 |
| 269 } // namespace dart | 247 } // namespace dart |
| 270 | 248 |
| 271 #endif // VM_PAGES_H_ | 249 #endif // VM_PAGES_H_ |
| OLD | NEW |