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 RUNTIME_VM_HEAP_H_ | 5 #ifndef RUNTIME_VM_HEAP_H_ |
6 #define RUNTIME_VM_HEAP_H_ | 6 #define RUNTIME_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 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 }; | 34 }; |
35 | 35 |
36 enum WeakSelector { | 36 enum WeakSelector { kPeers = 0, kHashes, kObjectIds, kNumWeakSelectors }; |
37 kPeers = 0, | |
38 kHashes, | |
39 kObjectIds, | |
40 kNumWeakSelectors | |
41 }; | |
42 | 37 |
43 enum ApiCallbacks { | 38 enum ApiCallbacks { kIgnoreApiCallbacks, kInvokeApiCallbacks }; |
44 kIgnoreApiCallbacks, | |
45 kInvokeApiCallbacks | |
46 }; | |
47 | 39 |
48 enum GCReason { | 40 enum GCReason { |
49 kNewSpace, | 41 kNewSpace, |
50 kPromotion, | 42 kPromotion, |
51 kOldSpace, | 43 kOldSpace, |
52 kFull, | 44 kFull, |
53 kGCAtAlloc, | 45 kGCAtAlloc, |
54 kGCTestCase, | 46 kGCTestCase, |
55 }; | 47 }; |
56 | 48 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 void ResetObjectIdTable(); | 196 void ResetObjectIdTable(); |
205 | 197 |
206 // Used by the GC algorithms to propagate weak entries. | 198 // Used by the GC algorithms to propagate weak entries. |
207 intptr_t GetWeakEntry(RawObject* raw_obj, WeakSelector sel) const; | 199 intptr_t GetWeakEntry(RawObject* raw_obj, WeakSelector sel) const; |
208 void SetWeakEntry(RawObject* raw_obj, WeakSelector sel, intptr_t val); | 200 void SetWeakEntry(RawObject* raw_obj, WeakSelector sel, intptr_t val); |
209 | 201 |
210 WeakTable* GetWeakTable(Space space, WeakSelector selector) const { | 202 WeakTable* GetWeakTable(Space space, WeakSelector selector) const { |
211 if (space == kNew) { | 203 if (space == kNew) { |
212 return new_weak_tables_[selector]; | 204 return new_weak_tables_[selector]; |
213 } | 205 } |
214 ASSERT(space ==kOld); | 206 ASSERT(space == kOld); |
215 return old_weak_tables_[selector]; | 207 return old_weak_tables_[selector]; |
216 } | 208 } |
217 void SetWeakTable(Space space, WeakSelector selector, WeakTable* value) { | 209 void SetWeakTable(Space space, WeakSelector selector, WeakTable* value) { |
218 if (space == kNew) { | 210 if (space == kNew) { |
219 new_weak_tables_[selector] = value; | 211 new_weak_tables_[selector] = value; |
220 } else { | 212 } else { |
221 ASSERT(space == kOld); | 213 ASSERT(space == kOld); |
222 old_weak_tables_[selector] = value; | 214 old_weak_tables_[selector] = value; |
223 } | 215 } |
224 } | 216 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 intptr_t num_; | 257 intptr_t num_; |
266 Heap::Space space_; | 258 Heap::Space space_; |
267 Heap::GCReason reason_; | 259 Heap::GCReason reason_; |
268 | 260 |
269 class Data : public ValueObject { | 261 class Data : public ValueObject { |
270 public: | 262 public: |
271 Data() {} | 263 Data() {} |
272 int64_t micros_; | 264 int64_t micros_; |
273 SpaceUsage new_; | 265 SpaceUsage new_; |
274 SpaceUsage old_; | 266 SpaceUsage old_; |
| 267 |
275 private: | 268 private: |
276 DISALLOW_COPY_AND_ASSIGN(Data); | 269 DISALLOW_COPY_AND_ASSIGN(Data); |
277 }; | 270 }; |
278 | 271 |
279 enum { | 272 enum { kDataEntries = 4 }; |
280 kDataEntries = 4 | |
281 }; | |
282 | 273 |
283 Data before_; | 274 Data before_; |
284 Data after_; | 275 Data after_; |
285 int64_t times_[kDataEntries]; | 276 int64_t times_[kDataEntries]; |
286 intptr_t data_[kDataEntries]; | 277 intptr_t data_[kDataEntries]; |
287 | 278 |
288 private: | 279 private: |
289 DISALLOW_COPY_AND_ASSIGN(GCStats); | 280 DISALLOW_COPY_AND_ASSIGN(GCStats); |
290 }; | 281 }; |
291 | 282 |
(...skipping 13 matching lines...) Expand all Loading... |
305 | 296 |
306 // Visit all objects, including FreeListElement "objects". Caller must ensure | 297 // Visit all objects, including FreeListElement "objects". Caller must ensure |
307 // concurrent sweeper is not running, and the visitor must not allocate. | 298 // concurrent sweeper is not running, and the visitor must not allocate. |
308 void VisitObjects(ObjectVisitor* visitor) const; | 299 void VisitObjects(ObjectVisitor* visitor) const; |
309 | 300 |
310 // Like Verify, but does not wait for concurrent sweeper, so caller must | 301 // Like Verify, but does not wait for concurrent sweeper, so caller must |
311 // ensure thread-safety. | 302 // ensure thread-safety. |
312 bool VerifyGC(MarkExpectation mark_expectation = kForbidMarked) const; | 303 bool VerifyGC(MarkExpectation mark_expectation = kForbidMarked) const; |
313 | 304 |
314 // Helper functions for garbage collection. | 305 // Helper functions for garbage collection. |
315 void CollectNewSpaceGarbage( | 306 void CollectNewSpaceGarbage(Thread* thread, |
316 Thread* thread, ApiCallbacks api_callbacks, GCReason reason); | 307 ApiCallbacks api_callbacks, |
317 void CollectOldSpaceGarbage( | 308 GCReason reason); |
318 Thread* thread, ApiCallbacks api_callbacks, GCReason reason); | 309 void CollectOldSpaceGarbage(Thread* thread, |
| 310 ApiCallbacks api_callbacks, |
| 311 GCReason reason); |
319 | 312 |
320 // GC stats collection. | 313 // GC stats collection. |
321 void RecordBeforeGC(Space space, GCReason reason); | 314 void RecordBeforeGC(Space space, GCReason reason); |
322 void RecordAfterGC(Space space); | 315 void RecordAfterGC(Space space); |
323 void PrintStats(); | 316 void PrintStats(); |
324 void UpdateClassHeapStatsBeforeGC(Heap::Space space); | 317 void UpdateClassHeapStatsBeforeGC(Heap::Space space); |
325 void PrintStatsToTimeline(TimelineEventScope* event); | 318 void PrintStatsToTimeline(TimelineEventScope* event); |
326 | 319 |
327 // Updates gc in progress flags. | 320 // Updates gc in progress flags. |
328 bool BeginNewSpaceGC(Thread* thread); | 321 bool BeginNewSpaceGC(Thread* thread); |
(...skipping 19 matching lines...) Expand all Loading... |
348 GCStats stats_; | 341 GCStats stats_; |
349 | 342 |
350 // This heap is in read-only mode: No allocation is allowed. | 343 // This heap is in read-only mode: No allocation is allowed. |
351 bool read_only_; | 344 bool read_only_; |
352 | 345 |
353 // GC on the heap is in progress. | 346 // GC on the heap is in progress. |
354 Monitor gc_in_progress_monitor_; | 347 Monitor gc_in_progress_monitor_; |
355 bool gc_new_space_in_progress_; | 348 bool gc_new_space_in_progress_; |
356 bool gc_old_space_in_progress_; | 349 bool gc_old_space_in_progress_; |
357 | 350 |
358 friend class Become; // VisitObjectPointers | 351 friend class Become; // VisitObjectPointers |
359 friend class Precompiler; // VisitObjects | 352 friend class Precompiler; // VisitObjects |
360 friend class ServiceEvent; | 353 friend class ServiceEvent; |
361 friend class PageSpace; // VerifyGC | 354 friend class PageSpace; // VerifyGC |
362 friend class IsolateReloadContext; // VisitObjects | 355 friend class IsolateReloadContext; // VisitObjects |
363 | 356 |
364 DISALLOW_COPY_AND_ASSIGN(Heap); | 357 DISALLOW_COPY_AND_ASSIGN(Heap); |
365 }; | 358 }; |
366 | 359 |
367 | 360 |
368 class HeapIterationScope : public StackResource { | 361 class HeapIterationScope : public StackResource { |
369 public: | 362 public: |
370 HeapIterationScope(); | 363 HeapIterationScope(); |
371 ~HeapIterationScope(); | 364 ~HeapIterationScope(); |
| 365 |
372 private: | 366 private: |
373 NoSafepointScope no_safepoint_scope_; | 367 NoSafepointScope no_safepoint_scope_; |
374 PageSpace* old_space_; | 368 PageSpace* old_space_; |
375 | 369 |
376 DISALLOW_COPY_AND_ASSIGN(HeapIterationScope); | 370 DISALLOW_COPY_AND_ASSIGN(HeapIterationScope); |
377 }; | 371 }; |
378 | 372 |
379 | 373 |
380 class NoHeapGrowthControlScope : public StackResource { | 374 class NoHeapGrowthControlScope : public StackResource { |
381 public: | 375 public: |
382 NoHeapGrowthControlScope(); | 376 NoHeapGrowthControlScope(); |
383 ~NoHeapGrowthControlScope(); | 377 ~NoHeapGrowthControlScope(); |
| 378 |
384 private: | 379 private: |
385 bool current_growth_controller_state_; | 380 bool current_growth_controller_state_; |
386 DISALLOW_COPY_AND_ASSIGN(NoHeapGrowthControlScope); | 381 DISALLOW_COPY_AND_ASSIGN(NoHeapGrowthControlScope); |
387 }; | 382 }; |
388 | 383 |
389 | 384 |
390 // Note: During this scope, the code pages are non-executable. | 385 // Note: During this scope, the code pages are non-executable. |
391 class WritableVMIsolateScope : StackResource { | 386 class WritableVMIsolateScope : StackResource { |
392 public: | 387 public: |
393 explicit WritableVMIsolateScope(Thread* thread); | 388 explicit WritableVMIsolateScope(Thread* thread); |
394 ~WritableVMIsolateScope(); | 389 ~WritableVMIsolateScope(); |
395 }; | 390 }; |
396 | 391 |
397 } // namespace dart | 392 } // namespace dart |
398 | 393 |
399 #endif // RUNTIME_VM_HEAP_H_ | 394 #endif // RUNTIME_VM_HEAP_H_ |
OLD | NEW |