| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // traversal through the heap space continues. | 118 // traversal through the heap space continues. |
| 119 // Returns null object if nothing is found. | 119 // Returns null object if nothing is found. |
| 120 RawInstructions* FindObjectInCodeSpace(FindObjectVisitor* visitor) const; | 120 RawInstructions* FindObjectInCodeSpace(FindObjectVisitor* visitor) const; |
| 121 RawObject* FindOldObject(FindObjectVisitor* visitor) const; | 121 RawObject* FindOldObject(FindObjectVisitor* visitor) const; |
| 122 RawObject* FindNewObject(FindObjectVisitor* visitor) const; | 122 RawObject* FindNewObject(FindObjectVisitor* visitor) const; |
| 123 RawObject* FindObject(FindObjectVisitor* visitor) const; | 123 RawObject* FindObject(FindObjectVisitor* visitor) const; |
| 124 | 124 |
| 125 void CollectGarbage(Space space); | 125 void CollectGarbage(Space space); |
| 126 void CollectGarbage(Space space, ApiCallbacks api_callbacks, GCReason reason); | 126 void CollectGarbage(Space space, ApiCallbacks api_callbacks, GCReason reason); |
| 127 void CollectAllGarbage(); | 127 void CollectAllGarbage(); |
| 128 bool NeedsGarbageCollection() const { |
| 129 return old_space_.NeedsGarbageCollection(); |
| 130 } |
| 128 | 131 |
| 129 // Enables growth control on the page space heaps. This should be | 132 // Enables growth control on the page space heaps. This should be |
| 130 // called before any user code is executed. | 133 // called before any user code is executed. |
| 131 void EnableGrowthControl() { SetGrowthControlState(true); } | 134 void EnableGrowthControl() { SetGrowthControlState(true); } |
| 132 void DisableGrowthControl() { SetGrowthControlState(false); } | 135 void DisableGrowthControl() { SetGrowthControlState(false); } |
| 133 void SetGrowthControlState(bool state); | 136 void SetGrowthControlState(bool state); |
| 134 bool GrowthControlState(); | 137 bool GrowthControlState(); |
| 135 | 138 |
| 136 // Protect access to the heap. Note: Code pages are made | 139 // Protect access to the heap. Note: Code pages are made |
| 137 // executable/non-executable when 'read_only' is true/false, respectively. | 140 // executable/non-executable when 'read_only' is true/false, respectively. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 void RecordTime(int id, int64_t micros) { | 227 void RecordTime(int id, int64_t micros) { |
| 225 ASSERT((id >= 0) && (id < GCStats::kDataEntries)); | 228 ASSERT((id >= 0) && (id < GCStats::kDataEntries)); |
| 226 stats_.times_[id] = micros; | 229 stats_.times_[id] = micros; |
| 227 } | 230 } |
| 228 | 231 |
| 229 void RecordData(int id, intptr_t value) { | 232 void RecordData(int id, intptr_t value) { |
| 230 ASSERT((id >= 0) && (id < GCStats::kDataEntries)); | 233 ASSERT((id >= 0) && (id < GCStats::kDataEntries)); |
| 231 stats_.data_[id] = value; | 234 stats_.data_[id] = value; |
| 232 } | 235 } |
| 233 | 236 |
| 234 bool gc_in_progress(); | |
| 235 | |
| 236 void UpdateGlobalMaxUsed(); | 237 void UpdateGlobalMaxUsed(); |
| 237 | 238 |
| 238 static bool IsAllocatableInNewSpace(intptr_t size) { | 239 static bool IsAllocatableInNewSpace(intptr_t size) { |
| 239 return size <= kNewAllocatableSize; | 240 return size <= kNewAllocatableSize; |
| 240 } | 241 } |
| 241 | 242 |
| 242 void PrintToJSONObject(Space space, JSONObject* object) const; | 243 void PrintToJSONObject(Space space, JSONObject* object) const; |
| 243 | 244 |
| 244 // The heap map contains the sizes and class ids for the objects in each page. | 245 // The heap map contains the sizes and class ids for the objects in each page. |
| 245 void PrintHeapMapToJSONStream(Isolate* isolate, JSONStream* stream) { | 246 void PrintHeapMapToJSONStream(Isolate* isolate, JSONStream* stream) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; | 302 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; |
| 302 | 303 |
| 303 // Visit all objects, including FreeListElement "objects". Caller must ensure | 304 // Visit all objects, including FreeListElement "objects". Caller must ensure |
| 304 // concurrent sweeper is not running, and the visitor must not allocate. | 305 // concurrent sweeper is not running, and the visitor must not allocate. |
| 305 void VisitObjects(ObjectVisitor* visitor) const; | 306 void VisitObjects(ObjectVisitor* visitor) const; |
| 306 | 307 |
| 307 // Like Verify, but does not wait for concurrent sweeper, so caller must | 308 // Like Verify, but does not wait for concurrent sweeper, so caller must |
| 308 // ensure thread-safety. | 309 // ensure thread-safety. |
| 309 bool VerifyGC(MarkExpectation mark_expectation = kForbidMarked) const; | 310 bool VerifyGC(MarkExpectation mark_expectation = kForbidMarked) const; |
| 310 | 311 |
| 312 // Helper functions for garbage collection. |
| 313 void CollectNewSpaceGarbage( |
| 314 Thread* thread, ApiCallbacks api_callbacks, GCReason reason); |
| 315 void CollectOldSpaceGarbage( |
| 316 Thread* thread, ApiCallbacks api_callbacks, GCReason reason); |
| 317 |
| 311 // GC stats collection. | 318 // GC stats collection. |
| 312 void RecordBeforeGC(Space space, GCReason reason); | 319 void RecordBeforeGC(Space space, GCReason reason); |
| 313 void RecordAfterGC(); | 320 void RecordAfterGC(Space space); |
| 314 void PrintStats(); | 321 void PrintStats(); |
| 315 void UpdateClassHeapStatsBeforeGC(Heap::Space space); | 322 void UpdateClassHeapStatsBeforeGC(Heap::Space space); |
| 316 void UpdatePretenurePolicy(); | 323 void UpdatePretenurePolicy(); |
| 317 | 324 |
| 318 // Updates gc_in_progress. | 325 // Updates gc in progress flags. |
| 319 void BeginGC(); | 326 bool BeginNewSpaceGC(); |
| 320 void EndGC(); | 327 void EndNewSpaceGC(); |
| 328 bool BeginOldSpaceGC(); |
| 329 void EndOldSpaceGC(); |
| 321 | 330 |
| 322 // If this heap is non-empty, updates start and end to the smallest range that | 331 // If this heap is non-empty, updates start and end to the smallest range that |
| 323 // contains both the original [start, end) and the [lowest, highest) addresses | 332 // contains both the original [start, end) and the [lowest, highest) addresses |
| 324 // of this heap. | 333 // of this heap. |
| 325 void GetMergedAddressRange(uword* start, uword* end) const; | 334 void GetMergedAddressRange(uword* start, uword* end) const; |
| 326 | 335 |
| 327 Isolate* isolate_; | 336 Isolate* isolate_; |
| 328 | 337 |
| 329 // The different spaces used for allocation. | 338 // The different spaces used for allocation. |
| 330 Scavenger new_space_; | 339 Scavenger new_space_; |
| 331 PageSpace old_space_; | 340 PageSpace old_space_; |
| 332 | 341 |
| 333 WeakTable* new_weak_tables_[kNumWeakSelectors]; | 342 WeakTable* new_weak_tables_[kNumWeakSelectors]; |
| 334 WeakTable* old_weak_tables_[kNumWeakSelectors]; | 343 WeakTable* old_weak_tables_[kNumWeakSelectors]; |
| 335 | 344 |
| 336 // GC stats collection. | 345 // GC stats collection. |
| 337 GCStats stats_; | 346 GCStats stats_; |
| 338 | 347 |
| 339 // This heap is in read-only mode: No allocation is allowed. | 348 // This heap is in read-only mode: No allocation is allowed. |
| 340 bool read_only_; | 349 bool read_only_; |
| 341 | 350 |
| 342 // GC on the heap is in progress. | 351 // GC on the heap is in progress. |
| 343 Mutex gc_in_progress_mutex_; | 352 Monitor gc_in_progress_monitor_; |
| 344 bool gc_in_progress_; | 353 bool gc_new_space_in_progress_; |
| 354 bool gc_old_space_in_progress_; |
| 345 | 355 |
| 346 int pretenure_policy_; | 356 int pretenure_policy_; |
| 347 | 357 |
| 348 friend class ServiceEvent; | 358 friend class ServiceEvent; |
| 349 friend class PageSpace; // VerifyGC | 359 friend class PageSpace; // VerifyGC |
| 350 DISALLOW_COPY_AND_ASSIGN(Heap); | 360 DISALLOW_COPY_AND_ASSIGN(Heap); |
| 351 }; | 361 }; |
| 352 | 362 |
| 353 | 363 |
| 354 class HeapIterationScope : public StackResource { | 364 class HeapIterationScope : public StackResource { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 379 explicit WritableVMIsolateScope(Thread* thread, bool include_code_pages); | 389 explicit WritableVMIsolateScope(Thread* thread, bool include_code_pages); |
| 380 ~WritableVMIsolateScope(); | 390 ~WritableVMIsolateScope(); |
| 381 | 391 |
| 382 private: | 392 private: |
| 383 bool include_code_pages_; | 393 bool include_code_pages_; |
| 384 }; | 394 }; |
| 385 | 395 |
| 386 } // namespace dart | 396 } // namespace dart |
| 387 | 397 |
| 388 #endif // VM_HEAP_H_ | 398 #endif // VM_HEAP_H_ |
| OLD | NEW |