OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // We don't have any type-based mappings to the CollectionBackingHeap. | 288 // We don't have any type-based mappings to the CollectionBackingHeap. |
289 | 289 |
290 // Each typed-heap maps the respective type to its heap. | 290 // Each typed-heap maps the respective type to its heap. |
291 #define DEFINE_TYPED_HEAP_TRAIT(Type) \ | 291 #define DEFINE_TYPED_HEAP_TRAIT(Type) \ |
292 class Type; \ | 292 class Type; \ |
293 template<> \ | 293 template<> \ |
294 struct HeapTypeTrait<class Type> : public HeapIndexTrait<Type##Heap> { }; | 294 struct HeapTypeTrait<class Type> : public HeapIndexTrait<Type##Heap> { }; |
295 FOR_EACH_TYPED_HEAP(DEFINE_TYPED_HEAP_TRAIT) | 295 FOR_EACH_TYPED_HEAP(DEFINE_TYPED_HEAP_TRAIT) |
296 #undef DEFINE_TYPED_HEAP_TRAIT | 296 #undef DEFINE_TYPED_HEAP_TRAIT |
297 | 297 |
| 298 // A HeapStats structure keeps track of the amount of memory allocated |
| 299 // for a Blink heap and how much of that memory is used for actual |
| 300 // Blink objects. These stats are used in the heuristics to determine |
| 301 // when to perform garbage collections. |
| 302 class HeapStats { |
| 303 public: |
| 304 HeapStats() : m_totalObjectSpace(0), m_totalAllocatedSpace(0) { } |
| 305 |
| 306 size_t totalObjectSpace() const { return m_totalObjectSpace; } |
| 307 size_t totalAllocatedSpace() const { return m_totalAllocatedSpace; } |
| 308 |
| 309 void add(HeapStats* other) |
| 310 { |
| 311 m_totalObjectSpace += other->m_totalObjectSpace; |
| 312 m_totalAllocatedSpace += other->m_totalAllocatedSpace; |
| 313 } |
| 314 |
| 315 void inline increaseObjectSpace(size_t newObjectSpace) |
| 316 { |
| 317 m_totalObjectSpace += newObjectSpace; |
| 318 } |
| 319 |
| 320 void inline decreaseObjectSpace(size_t deadObjectSpace) |
| 321 { |
| 322 m_totalObjectSpace -= deadObjectSpace; |
| 323 } |
| 324 |
| 325 void inline increaseAllocatedSpace(size_t newAllocatedSpace) |
| 326 { |
| 327 m_totalAllocatedSpace += newAllocatedSpace; |
| 328 } |
| 329 |
| 330 void inline decreaseAllocatedSpace(size_t deadAllocatedSpace) |
| 331 { |
| 332 m_totalAllocatedSpace -= deadAllocatedSpace; |
| 333 } |
| 334 |
| 335 void clear() |
| 336 { |
| 337 m_totalObjectSpace = 0; |
| 338 m_totalAllocatedSpace = 0; |
| 339 } |
| 340 |
| 341 bool operator==(const HeapStats& other) |
| 342 { |
| 343 return m_totalAllocatedSpace == other.m_totalAllocatedSpace |
| 344 && m_totalObjectSpace == other.m_totalObjectSpace; |
| 345 } |
| 346 |
| 347 private: |
| 348 size_t m_totalObjectSpace; // Actually contains objects that may be live, no
t including headers. |
| 349 size_t m_totalAllocatedSpace; // Allocated from the OS. |
| 350 |
| 351 friend class HeapTester; |
| 352 }; |
| 353 |
298 class PLATFORM_EXPORT ThreadState { | 354 class PLATFORM_EXPORT ThreadState { |
299 WTF_MAKE_NONCOPYABLE(ThreadState); | 355 WTF_MAKE_NONCOPYABLE(ThreadState); |
300 public: | 356 public: |
301 // When garbage collecting we need to know whether or not there | 357 // When garbage collecting we need to know whether or not there |
302 // can be pointers to Blink GC managed objects on the stack for | 358 // can be pointers to Blink GC managed objects on the stack for |
303 // each thread. When threads reach a safe point they record | 359 // each thread. When threads reach a safe point they record |
304 // whether or not they have pointers on the stack. | 360 // whether or not they have pointers on the stack. |
305 enum StackState { | 361 enum StackState { |
306 NoHeapPointersOnStack, | 362 NoHeapPointersOnStack, |
307 HeapPointersOnStack | 363 HeapPointersOnStack |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage); | 441 return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage); |
386 } | 442 } |
387 | 443 |
388 bool isMainThread() const { return this == mainThreadState(); } | 444 bool isMainThread() const { return this == mainThreadState(); } |
389 inline bool checkThread() const | 445 inline bool checkThread() const |
390 { | 446 { |
391 ASSERT(m_thread == currentThread()); | 447 ASSERT(m_thread == currentThread()); |
392 return true; | 448 return true; |
393 } | 449 } |
394 | 450 |
395 // If gcRequested returns true when a thread returns to its event | |
396 // loop the thread will initiate a garbage collection. | |
397 bool gcRequested(); | |
398 void setGCRequested(); | |
399 void clearGCRequested(); | |
400 | |
401 // shouldGC and shouldForceConservativeGC implement the heuristics | 451 // shouldGC and shouldForceConservativeGC implement the heuristics |
402 // that are used to determine when to collect garbage. If | 452 // that are used to determine when to collect garbage. If |
403 // shouldForceConservativeGC returns true, we force the garbage | 453 // shouldForceConservativeGC returns true, we force the garbage |
404 // collection immediately. Otherwise, if shouldGC returns true, we | 454 // collection immediately. Otherwise, if shouldGC returns true, we |
405 // record that we should garbage collect the next time we return | 455 // record that we should garbage collect the next time we return |
406 // to the event loop. If both return false, we don't need to | 456 // to the event loop. If both return false, we don't need to |
407 // collect garbage at this point. | 457 // collect garbage at this point. |
408 bool shouldGC(); | 458 bool shouldGC(); |
409 bool shouldForceConservativeGC(); | 459 bool shouldForceConservativeGC(); |
| 460 bool increasedEnoughToGC(size_t, size_t); |
| 461 bool increasedEnoughToForceConservativeGC(size_t, size_t); |
| 462 |
| 463 // If gcRequested returns true when a thread returns to its event |
| 464 // loop the thread will initiate a garbage collection. |
| 465 bool gcRequested(); |
| 466 void setGCRequested(); |
| 467 void clearGCRequested(); |
410 | 468 |
411 // Was the last GC forced for testing? This is set when garbage collection | 469 // Was the last GC forced for testing? This is set when garbage collection |
412 // is forced for testing and there are pointers on the stack. It remains | 470 // is forced for testing and there are pointers on the stack. It remains |
413 // set until a garbage collection is triggered with no pointers on the stack
. | 471 // set until a garbage collection is triggered with no pointers on the stack
. |
414 // This is used for layout tests that trigger GCs and check if objects are | 472 // This is used for layout tests that trigger GCs and check if objects are |
415 // dead at a given point in time. That only reliably works when we get | 473 // dead at a given point in time. That only reliably works when we get |
416 // precise GCs with no conservative stack scanning. | 474 // precise GCs with no conservative stack scanning. |
417 void setForcePreciseGCForTesting(bool); | 475 void setForcePreciseGCForTesting(bool); |
418 bool forcePreciseGCForTesting(); | 476 bool forcePreciseGCForTesting(); |
419 | 477 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 | 706 |
649 size_t getClassTag(const GCInfo*); | 707 size_t getClassTag(const GCInfo*); |
650 }; | 708 }; |
651 | 709 |
652 void snapshot(); | 710 void snapshot(); |
653 #endif | 711 #endif |
654 | 712 |
655 void pushWeakObjectPointerCallback(void*, WeakPointerCallback); | 713 void pushWeakObjectPointerCallback(void*, WeakPointerCallback); |
656 bool popAndInvokeWeakPointerCallback(Visitor*); | 714 bool popAndInvokeWeakPointerCallback(Visitor*); |
657 | 715 |
658 size_t objectPayloadSizeForTesting(); | 716 void getStats(HeapStats&); |
| 717 void getStatsForTesting(HeapStats&); |
| 718 HeapStats& stats() { return m_stats; } |
659 | 719 |
660 void setupHeapsForTermination(); | 720 void setupHeapsForTermination(); |
661 | 721 |
662 void registerSweepingTask(); | 722 void registerSweepingTask(); |
663 void unregisterSweepingTask(); | 723 void unregisterSweepingTask(); |
664 | 724 |
665 // Request to call a pref-finalizer of the target object before the object | 725 // Request to call a pref-finalizer of the target object before the object |
666 // is destructed. The class T must have USING_PRE_FINALIZER(). The | 726 // is destructed. The class T must have USING_PRE_FINALIZER(). The |
667 // argument should be |*this|. Registering a lot of objects affects GC | 727 // argument should be |*this|. Registering a lot of objects affects GC |
668 // performance. We should register an object only if the object really | 728 // performance. We should register an object only if the object really |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 // When ThreadState is detaching from non-main thread its | 783 // When ThreadState is detaching from non-main thread its |
724 // heap is expected to be empty (because it is going away). | 784 // heap is expected to be empty (because it is going away). |
725 // Perform registered cleanup tasks and garbage collection | 785 // Perform registered cleanup tasks and garbage collection |
726 // to sweep away any objects that are left on this heap. | 786 // to sweep away any objects that are left on this heap. |
727 // We assert that nothing must remain after this cleanup. | 787 // We assert that nothing must remain after this cleanup. |
728 // If assertion does not hold we crash as we are potentially | 788 // If assertion does not hold we crash as we are potentially |
729 // in the dangling pointer situation. | 789 // in the dangling pointer situation. |
730 void cleanup(); | 790 void cleanup(); |
731 void cleanupPages(); | 791 void cleanupPages(); |
732 | 792 |
| 793 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; } |
| 794 |
733 void performPendingSweepInParallel(); | 795 void performPendingSweepInParallel(); |
734 void waitUntilSweepersDone(); | 796 void waitUntilSweepersDone(); |
735 void unregisterPreFinalizerInternal(void*); | 797 void unregisterPreFinalizerInternal(void*); |
736 void invokePreFinalizers(Visitor&); | 798 void invokePreFinalizers(Visitor&); |
737 | 799 |
738 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; | 800 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; |
739 static uintptr_t s_mainThreadStackStart; | 801 static uintptr_t s_mainThreadStackStart; |
740 static uintptr_t s_mainThreadUnderestimatedStackSize; | 802 static uintptr_t s_mainThreadUnderestimatedStackSize; |
741 static SafePointBarrier* s_safePointBarrier; | 803 static SafePointBarrier* s_safePointBarrier; |
742 | 804 |
(...skipping 19 matching lines...) Expand all Loading... |
762 Vector<Address> m_safePointStackCopy; | 824 Vector<Address> m_safePointStackCopy; |
763 bool m_atSafePoint; | 825 bool m_atSafePoint; |
764 Vector<Interruptor*> m_interruptors; | 826 Vector<Interruptor*> m_interruptors; |
765 bool m_gcRequested; | 827 bool m_gcRequested; |
766 bool m_forcePreciseGCForTesting; | 828 bool m_forcePreciseGCForTesting; |
767 volatile int m_sweepRequested; | 829 volatile int m_sweepRequested; |
768 bool m_sweepInProgress; | 830 bool m_sweepInProgress; |
769 size_t m_noAllocationCount; | 831 size_t m_noAllocationCount; |
770 bool m_inGC; | 832 bool m_inGC; |
771 BaseHeap* m_heaps[NumberOfHeaps]; | 833 BaseHeap* m_heaps[NumberOfHeaps]; |
| 834 HeapStats m_stats; |
| 835 HeapStats m_statsAfterLastGC; |
772 | 836 |
773 Vector<OwnPtr<CleanupTask> > m_cleanupTasks; | 837 Vector<OwnPtr<CleanupTask> > m_cleanupTasks; |
774 bool m_isTerminating; | 838 bool m_isTerminating; |
775 | 839 |
776 bool m_shouldFlushHeapDoesNotContainCache; | 840 bool m_shouldFlushHeapDoesNotContainCache; |
777 bool m_lowCollectionRate; | 841 bool m_lowCollectionRate; |
778 | 842 |
779 OwnPtr<WebThread> m_sweeperThread; | 843 OwnPtr<WebThread> m_sweeperThread; |
780 int m_numberOfSweeperTasks; | 844 int m_numberOfSweeperTasks; |
781 Mutex m_sweepMutex; | 845 Mutex m_sweepMutex; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 // whether the page is part of a terminting thread or | 975 // whether the page is part of a terminting thread or |
912 // if the page is traced after being terminated (orphaned). | 976 // if the page is traced after being terminated (orphaned). |
913 uintptr_t m_terminating : 1; | 977 uintptr_t m_terminating : 1; |
914 uintptr_t m_tracedAfterOrphaned : 1; | 978 uintptr_t m_tracedAfterOrphaned : 1; |
915 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 | 979 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 |
916 }; | 980 }; |
917 | 981 |
918 } // namespace blink | 982 } // namespace blink |
919 | 983 |
920 #endif // ThreadState_h | 984 #endif // ThreadState_h |
OLD | NEW |