| 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 13 matching lines...) Expand all Loading... |
| 24 class ServiceEvent; | 24 class ServiceEvent; |
| 25 class TimelineEventScope; | 25 class TimelineEventScope; |
| 26 class VirtualMemory; | 26 class VirtualMemory; |
| 27 | 27 |
| 28 class Heap { | 28 class Heap { |
| 29 public: | 29 public: |
| 30 enum Space { | 30 enum Space { |
| 31 kNew, | 31 kNew, |
| 32 kOld, | 32 kOld, |
| 33 kCode, | 33 kCode, |
| 34 // TODO(koda): Harmonize all old-space allocation and get rid of this. | |
| 35 kPretenured, | |
| 36 }; | 34 }; |
| 37 | 35 |
| 38 enum WeakSelector { | 36 enum WeakSelector { |
| 39 kPeers = 0, | 37 kPeers = 0, |
| 40 kHashes, | 38 kHashes, |
| 41 kObjectIds, | 39 kObjectIds, |
| 42 kNumWeakSelectors | 40 kNumWeakSelectors |
| 43 }; | 41 }; |
| 44 | 42 |
| 45 enum ApiCallbacks { | 43 enum ApiCallbacks { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 74 case kNew: | 72 case kNew: |
| 75 // Do not attempt to allocate very large objects in new space. | 73 // Do not attempt to allocate very large objects in new space. |
| 76 if (!IsAllocatableInNewSpace(size)) { | 74 if (!IsAllocatableInNewSpace(size)) { |
| 77 return AllocateOld(size, HeapPage::kData); | 75 return AllocateOld(size, HeapPage::kData); |
| 78 } | 76 } |
| 79 return AllocateNew(size); | 77 return AllocateNew(size); |
| 80 case kOld: | 78 case kOld: |
| 81 return AllocateOld(size, HeapPage::kData); | 79 return AllocateOld(size, HeapPage::kData); |
| 82 case kCode: | 80 case kCode: |
| 83 return AllocateOld(size, HeapPage::kExecutable); | 81 return AllocateOld(size, HeapPage::kExecutable); |
| 84 case kPretenured: | |
| 85 return AllocatePretenured(size); | |
| 86 default: | 82 default: |
| 87 UNREACHABLE(); | 83 UNREACHABLE(); |
| 88 } | 84 } |
| 89 return 0; | 85 return 0; |
| 90 } | 86 } |
| 91 | 87 |
| 92 // Track external data. | 88 // Track external data. |
| 93 void AllocateExternal(intptr_t size, Space space); | 89 void AllocateExternal(intptr_t size, Space space); |
| 94 void FreeExternal(intptr_t size, Space space); | 90 void FreeExternal(intptr_t size, Space space); |
| 95 // Move external size from new to old space. Does not by itself trigger GC. | 91 // Move external size from new to old space. Does not by itself trigger GC. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // Protect access to the heap. Note: Code pages are made | 137 // Protect access to the heap. Note: Code pages are made |
| 142 // executable/non-executable when 'read_only' is true/false, respectively. | 138 // executable/non-executable when 'read_only' is true/false, respectively. |
| 143 void WriteProtect(bool read_only); | 139 void WriteProtect(bool read_only); |
| 144 void WriteProtectCode(bool read_only) { | 140 void WriteProtectCode(bool read_only) { |
| 145 old_space_.WriteProtectCode(read_only); | 141 old_space_.WriteProtectCode(read_only); |
| 146 } | 142 } |
| 147 | 143 |
| 148 // Accessors for inlined allocation in generated code. | 144 // Accessors for inlined allocation in generated code. |
| 149 static intptr_t TopOffset(Space space); | 145 static intptr_t TopOffset(Space space); |
| 150 static intptr_t EndOffset(Space space); | 146 static intptr_t EndOffset(Space space); |
| 151 static Space SpaceForAllocation(intptr_t class_id); | |
| 152 | 147 |
| 153 // Initialize the heap and register it with the isolate. | 148 // Initialize the heap and register it with the isolate. |
| 154 static void Init(Isolate* isolate, | 149 static void Init(Isolate* isolate, |
| 155 intptr_t max_new_gen_words, | 150 intptr_t max_new_gen_words, |
| 156 intptr_t max_old_gen_words, | 151 intptr_t max_old_gen_words, |
| 157 intptr_t max_external_words); | 152 intptr_t max_external_words); |
| 158 | 153 |
| 159 // Verify that all pointers in the heap point to the heap. | 154 // Verify that all pointers in the heap point to the heap. |
| 160 bool Verify(MarkExpectation mark_expectation = kForbidMarked) const; | 155 bool Verify(MarkExpectation mark_expectation = kForbidMarked) const; |
| 161 | 156 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 248 |
| 254 Isolate* isolate() const { return isolate_; } | 249 Isolate* isolate() const { return isolate_; } |
| 255 | 250 |
| 256 Monitor* barrier() const { return barrier_; } | 251 Monitor* barrier() const { return barrier_; } |
| 257 Monitor* barrier_done() const { return barrier_done_; } | 252 Monitor* barrier_done() const { return barrier_done_; } |
| 258 | 253 |
| 259 Monitor* finalization_tasks_lock() const { return finalization_tasks_lock_; } | 254 Monitor* finalization_tasks_lock() const { return finalization_tasks_lock_; } |
| 260 intptr_t finalization_tasks() const { return finalization_tasks_; } | 255 intptr_t finalization_tasks() const { return finalization_tasks_; } |
| 261 void set_finalization_tasks(intptr_t count) { finalization_tasks_ = count; } | 256 void set_finalization_tasks(intptr_t count) { finalization_tasks_ = count; } |
| 262 | 257 |
| 263 bool ShouldPretenure(intptr_t class_id) const; | |
| 264 | |
| 265 void SetupExternalPage(void* pointer, uword size, bool is_executable) { | 258 void SetupExternalPage(void* pointer, uword size, bool is_executable) { |
| 266 old_space_.SetupExternalPage(pointer, size, is_executable); | 259 old_space_.SetupExternalPage(pointer, size, is_executable); |
| 267 } | 260 } |
| 268 | 261 |
| 269 private: | 262 private: |
| 270 class GCStats : public ValueObject { | 263 class GCStats : public ValueObject { |
| 271 public: | 264 public: |
| 272 GCStats() {} | 265 GCStats() {} |
| 273 intptr_t num_; | 266 intptr_t num_; |
| 274 Heap::Space space_; | 267 Heap::Space space_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 299 | 292 |
| 300 static const intptr_t kNewAllocatableSize = 256 * KB; | 293 static const intptr_t kNewAllocatableSize = 256 * KB; |
| 301 | 294 |
| 302 Heap(Isolate* isolate, | 295 Heap(Isolate* isolate, |
| 303 intptr_t max_new_gen_semi_words, // Max capacity of new semi-space. | 296 intptr_t max_new_gen_semi_words, // Max capacity of new semi-space. |
| 304 intptr_t max_old_gen_words, | 297 intptr_t max_old_gen_words, |
| 305 intptr_t max_external_words); | 298 intptr_t max_external_words); |
| 306 | 299 |
| 307 uword AllocateNew(intptr_t size); | 300 uword AllocateNew(intptr_t size); |
| 308 uword AllocateOld(intptr_t size, HeapPage::PageType type); | 301 uword AllocateOld(intptr_t size, HeapPage::PageType type); |
| 309 uword AllocatePretenured(intptr_t size); | |
| 310 | 302 |
| 311 // Visit all pointers. Caller must ensure concurrent sweeper is not running, | 303 // Visit all pointers. Caller must ensure concurrent sweeper is not running, |
| 312 // and the visitor must not allocate. | 304 // and the visitor must not allocate. |
| 313 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; | 305 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; |
| 314 | 306 |
| 315 // Visit all objects, including FreeListElement "objects". Caller must ensure | 307 // Visit all objects, including FreeListElement "objects". Caller must ensure |
| 316 // concurrent sweeper is not running, and the visitor must not allocate. | 308 // concurrent sweeper is not running, and the visitor must not allocate. |
| 317 void VisitObjects(ObjectVisitor* visitor) const; | 309 void VisitObjects(ObjectVisitor* visitor) const; |
| 318 | 310 |
| 319 // Like Verify, but does not wait for concurrent sweeper, so caller must | 311 // Like Verify, but does not wait for concurrent sweeper, so caller must |
| 320 // ensure thread-safety. | 312 // ensure thread-safety. |
| 321 bool VerifyGC(MarkExpectation mark_expectation = kForbidMarked) const; | 313 bool VerifyGC(MarkExpectation mark_expectation = kForbidMarked) const; |
| 322 | 314 |
| 323 // Helper functions for garbage collection. | 315 // Helper functions for garbage collection. |
| 324 void CollectNewSpaceGarbage( | 316 void CollectNewSpaceGarbage( |
| 325 Thread* thread, ApiCallbacks api_callbacks, GCReason reason); | 317 Thread* thread, ApiCallbacks api_callbacks, GCReason reason); |
| 326 void CollectOldSpaceGarbage( | 318 void CollectOldSpaceGarbage( |
| 327 Thread* thread, ApiCallbacks api_callbacks, GCReason reason); | 319 Thread* thread, ApiCallbacks api_callbacks, GCReason reason); |
| 328 | 320 |
| 329 // GC stats collection. | 321 // GC stats collection. |
| 330 void RecordBeforeGC(Space space, GCReason reason); | 322 void RecordBeforeGC(Space space, GCReason reason); |
| 331 void RecordAfterGC(Space space); | 323 void RecordAfterGC(Space space); |
| 332 void PrintStats(); | 324 void PrintStats(); |
| 333 void UpdateClassHeapStatsBeforeGC(Heap::Space space); | 325 void UpdateClassHeapStatsBeforeGC(Heap::Space space); |
| 334 void UpdatePretenurePolicy(); | |
| 335 void PrintStatsToTimeline(TimelineEventScope* event); | 326 void PrintStatsToTimeline(TimelineEventScope* event); |
| 336 | 327 |
| 337 // Updates gc in progress flags. | 328 // Updates gc in progress flags. |
| 338 bool BeginNewSpaceGC(Thread* thread); | 329 bool BeginNewSpaceGC(Thread* thread); |
| 339 void EndNewSpaceGC(); | 330 void EndNewSpaceGC(); |
| 340 bool BeginOldSpaceGC(Thread* thread); | 331 bool BeginOldSpaceGC(Thread* thread); |
| 341 void EndOldSpaceGC(); | 332 void EndOldSpaceGC(); |
| 342 | 333 |
| 343 // If this heap is non-empty, updates start and end to the smallest range that | 334 // If this heap is non-empty, updates start and end to the smallest range that |
| 344 // contains both the original [start, end) and the [lowest, highest) addresses | 335 // contains both the original [start, end) and the [lowest, highest) addresses |
| (...skipping 19 matching lines...) Expand all Loading... |
| 364 GCStats stats_; | 355 GCStats stats_; |
| 365 | 356 |
| 366 // This heap is in read-only mode: No allocation is allowed. | 357 // This heap is in read-only mode: No allocation is allowed. |
| 367 bool read_only_; | 358 bool read_only_; |
| 368 | 359 |
| 369 // GC on the heap is in progress. | 360 // GC on the heap is in progress. |
| 370 Monitor gc_in_progress_monitor_; | 361 Monitor gc_in_progress_monitor_; |
| 371 bool gc_new_space_in_progress_; | 362 bool gc_new_space_in_progress_; |
| 372 bool gc_old_space_in_progress_; | 363 bool gc_old_space_in_progress_; |
| 373 | 364 |
| 374 int pretenure_policy_; | |
| 375 | |
| 376 friend class Become; // VisitObjectPointers | 365 friend class Become; // VisitObjectPointers |
| 377 friend class ServiceEvent; | 366 friend class ServiceEvent; |
| 378 friend class PageSpace; // VerifyGC | 367 friend class PageSpace; // VerifyGC |
| 379 friend class IsolateReloadContext; // VisitObjects | 368 friend class IsolateReloadContext; // VisitObjects |
| 380 | 369 |
| 381 DISALLOW_COPY_AND_ASSIGN(Heap); | 370 DISALLOW_COPY_AND_ASSIGN(Heap); |
| 382 }; | 371 }; |
| 383 | 372 |
| 384 | 373 |
| 385 class HeapIterationScope : public StackResource { | 374 class HeapIterationScope : public StackResource { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 407 // Note: During this scope, the code pages are non-executable. | 396 // Note: During this scope, the code pages are non-executable. |
| 408 class WritableVMIsolateScope : StackResource { | 397 class WritableVMIsolateScope : StackResource { |
| 409 public: | 398 public: |
| 410 explicit WritableVMIsolateScope(Thread* thread); | 399 explicit WritableVMIsolateScope(Thread* thread); |
| 411 ~WritableVMIsolateScope(); | 400 ~WritableVMIsolateScope(); |
| 412 }; | 401 }; |
| 413 | 402 |
| 414 } // namespace dart | 403 } // namespace dart |
| 415 | 404 |
| 416 #endif // VM_HEAP_H_ | 405 #endif // VM_HEAP_H_ |
| OLD | NEW |