| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_HEAP_H_ | 5 #ifndef VM_HEAP_H_ |
| 6 #define VM_HEAP_H_ | 6 #define VM_HEAP_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 DECLARE_FLAG(bool, verify_before_gc); | 26 DECLARE_FLAG(bool, verify_before_gc); |
| 27 DECLARE_FLAG(bool, verify_after_gc); | 27 DECLARE_FLAG(bool, verify_after_gc); |
| 28 DECLARE_FLAG(bool, gc_at_alloc); | 28 DECLARE_FLAG(bool, gc_at_alloc); |
| 29 | 29 |
| 30 class Heap { | 30 class Heap { |
| 31 public: | 31 public: |
| 32 enum Space { | 32 enum Space { |
| 33 kNew, | 33 kNew, |
| 34 kOld, | 34 kOld, |
| 35 kCode, | 35 kCode, |
| 36 kPretenured, |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 enum WeakSelector { | 39 enum WeakSelector { |
| 39 kPeers = 0, | 40 kPeers = 0, |
| 40 kHashes, | 41 kHashes, |
| 41 kNumWeakSelectors | 42 kNumWeakSelectors |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 enum ApiCallbacks { | 45 enum ApiCallbacks { |
| 45 kIgnoreApiCallbacks, | 46 kIgnoreApiCallbacks, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 71 case kNew: | 72 case kNew: |
| 72 // Do not attempt to allocate very large objects in new space. | 73 // Do not attempt to allocate very large objects in new space. |
| 73 if (!IsAllocatableInNewSpace(size)) { | 74 if (!IsAllocatableInNewSpace(size)) { |
| 74 return AllocateOld(size, HeapPage::kData); | 75 return AllocateOld(size, HeapPage::kData); |
| 75 } | 76 } |
| 76 return AllocateNew(size); | 77 return AllocateNew(size); |
| 77 case kOld: | 78 case kOld: |
| 78 return AllocateOld(size, HeapPage::kData); | 79 return AllocateOld(size, HeapPage::kData); |
| 79 case kCode: | 80 case kCode: |
| 80 return AllocateOld(size, HeapPage::kExecutable); | 81 return AllocateOld(size, HeapPage::kExecutable); |
| 82 case kPretenured: |
| 83 return AllocatePretenured(size); |
| 81 default: | 84 default: |
| 82 UNREACHABLE(); | 85 UNREACHABLE(); |
| 83 } | 86 } |
| 84 return 0; | 87 return 0; |
| 85 } | 88 } |
| 86 | 89 |
| 87 // Track external data. | 90 // Track external data. |
| 88 void AllocateExternal(intptr_t size, Space space); | 91 void AllocateExternal(intptr_t size, Space space); |
| 89 void FreeExternal(intptr_t size, Space space); | 92 void FreeExternal(intptr_t size, Space space); |
| 90 // Move external size from new to old space. Does not by itself trigger GC. | 93 // Move external size from new to old space. Does not by itself trigger GC. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 232 |
| 230 void PrintToJSONObject(Space space, JSONObject* object) const; | 233 void PrintToJSONObject(Space space, JSONObject* object) const; |
| 231 | 234 |
| 232 // The heap map contains the sizes and class ids for the objects in each page. | 235 // The heap map contains the sizes and class ids for the objects in each page. |
| 233 void PrintHeapMapToJSONStream(Isolate* isolate, JSONStream* stream) const { | 236 void PrintHeapMapToJSONStream(Isolate* isolate, JSONStream* stream) const { |
| 234 return old_space_->PrintHeapMapToJSONStream(isolate, stream); | 237 return old_space_->PrintHeapMapToJSONStream(isolate, stream); |
| 235 } | 238 } |
| 236 | 239 |
| 237 Isolate* isolate() const { return isolate_; } | 240 Isolate* isolate() const { return isolate_; } |
| 238 | 241 |
| 242 bool ShouldPretenure(intptr_t class_id) const; |
| 243 |
| 239 private: | 244 private: |
| 240 class GCStats : public ValueObject { | 245 class GCStats : public ValueObject { |
| 241 public: | 246 public: |
| 242 GCStats() {} | 247 GCStats() {} |
| 243 intptr_t num_; | 248 intptr_t num_; |
| 244 Heap::Space space_; | 249 Heap::Space space_; |
| 245 Heap::GCReason reason_; | 250 Heap::GCReason reason_; |
| 246 | 251 |
| 247 class Data : public ValueObject { | 252 class Data : public ValueObject { |
| 248 public: | 253 public: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 268 }; | 273 }; |
| 269 | 274 |
| 270 static const intptr_t kNewAllocatableSize = 256 * KB; | 275 static const intptr_t kNewAllocatableSize = 256 * KB; |
| 271 | 276 |
| 272 Heap(Isolate* isolate, | 277 Heap(Isolate* isolate, |
| 273 intptr_t max_new_gen_semi_words, // Max capacity of new semi-space. | 278 intptr_t max_new_gen_semi_words, // Max capacity of new semi-space. |
| 274 intptr_t max_old_gen_words); | 279 intptr_t max_old_gen_words); |
| 275 | 280 |
| 276 uword AllocateNew(intptr_t size); | 281 uword AllocateNew(intptr_t size); |
| 277 uword AllocateOld(intptr_t size, HeapPage::PageType type); | 282 uword AllocateOld(intptr_t size, HeapPage::PageType type); |
| 283 uword AllocatePretenured(intptr_t size); |
| 278 | 284 |
| 279 // GC stats collection. | 285 // GC stats collection. |
| 280 void RecordBeforeGC(Space space, GCReason reason); | 286 void RecordBeforeGC(Space space, GCReason reason); |
| 281 void RecordAfterGC(); | 287 void RecordAfterGC(); |
| 282 void PrintStats(); | 288 void PrintStats(); |
| 283 void UpdateClassHeapStatsBeforeGC(Heap::Space space); | 289 void UpdateClassHeapStatsBeforeGC(Heap::Space space); |
| 290 void UpdatePretenurePolicy(); |
| 284 | 291 |
| 285 // If this heap is non-empty, updates start and end to the smallest range that | 292 // If this heap is non-empty, updates start and end to the smallest range that |
| 286 // contains both the original [start, end) and the [lowest, highest) addresses | 293 // contains both the original [start, end) and the [lowest, highest) addresses |
| 287 // of this heap. | 294 // of this heap. |
| 288 void GetMergedAddressRange(uword* start, uword* end) const; | 295 void GetMergedAddressRange(uword* start, uword* end) const; |
| 289 | 296 |
| 290 Isolate* isolate_; | 297 Isolate* isolate_; |
| 291 | 298 |
| 292 // The different spaces used for allocation. | 299 // The different spaces used for allocation. |
| 293 Scavenger* new_space_; | 300 Scavenger* new_space_; |
| 294 PageSpace* old_space_; | 301 PageSpace* old_space_; |
| 295 | 302 |
| 296 WeakTable* new_weak_tables_[kNumWeakSelectors]; | 303 WeakTable* new_weak_tables_[kNumWeakSelectors]; |
| 297 WeakTable* old_weak_tables_[kNumWeakSelectors]; | 304 WeakTable* old_weak_tables_[kNumWeakSelectors]; |
| 298 | 305 |
| 299 // GC stats collection. | 306 // GC stats collection. |
| 300 GCStats stats_; | 307 GCStats stats_; |
| 301 | 308 |
| 302 // This heap is in read-only mode: No allocation is allowed. | 309 // This heap is in read-only mode: No allocation is allowed. |
| 303 bool read_only_; | 310 bool read_only_; |
| 304 | 311 |
| 305 // GC on the heap is in progress. | 312 // GC on the heap is in progress. |
| 306 bool gc_in_progress_; | 313 bool gc_in_progress_; |
| 307 | 314 |
| 315 int pretenure_policy_; |
| 316 |
| 308 friend class GCEvent; | 317 friend class GCEvent; |
| 309 friend class GCTestHelper; | 318 friend class GCTestHelper; |
| 310 DISALLOW_COPY_AND_ASSIGN(Heap); | 319 DISALLOW_COPY_AND_ASSIGN(Heap); |
| 311 }; | 320 }; |
| 312 | 321 |
| 313 | 322 |
| 314 class GCEvent { | 323 class GCEvent { |
| 315 public: | 324 public: |
| 316 explicit GCEvent(const Heap::GCStats& stats) | 325 explicit GCEvent(const Heap::GCStats& stats) |
| 317 : stats_(stats) {} | 326 : stats_(stats) {} |
| (...skipping 26 matching lines...) Expand all Loading... |
| 344 NoHeapGrowthControlScope(); | 353 NoHeapGrowthControlScope(); |
| 345 ~NoHeapGrowthControlScope(); | 354 ~NoHeapGrowthControlScope(); |
| 346 private: | 355 private: |
| 347 bool current_growth_controller_state_; | 356 bool current_growth_controller_state_; |
| 348 DISALLOW_COPY_AND_ASSIGN(NoHeapGrowthControlScope); | 357 DISALLOW_COPY_AND_ASSIGN(NoHeapGrowthControlScope); |
| 349 }; | 358 }; |
| 350 | 359 |
| 351 } // namespace dart | 360 } // namespace dart |
| 352 | 361 |
| 353 #endif // VM_HEAP_H_ | 362 #endif // VM_HEAP_H_ |
| OLD | NEW |