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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 static bool invokePreFinalizer(void* object) \ | 109 static bool invokePreFinalizer(void* object) \ |
110 { \ | 110 { \ |
111 Class* self = reinterpret_cast<Class*>(object); \ | 111 Class* self = reinterpret_cast<Class*>(object); \ |
112 if (ThreadHeap::isHeapObjectAlive(self)) \ | 112 if (ThreadHeap::isHeapObjectAlive(self)) \ |
113 return false; \ | 113 return false; \ |
114 self->Class::preFinalizer(); \ | 114 self->Class::preFinalizer(); \ |
115 return true; \ | 115 return true; \ |
116 } \ | 116 } \ |
117 using UsingPreFinalizerMacroNeedsTrailingSemiColon = char | 117 using UsingPreFinalizerMacroNeedsTrailingSemiColon = char |
118 | 118 |
119 enum ThreadHeapMode { | |
haraken
2016/09/21 04:56:42
Move this to BlinkGC.h.
keishi
2016/09/21 07:06:37
Done.
| |
120 MainThreadHeapMode, | |
121 PerThreadHeapMode, | |
122 }; | |
123 | |
119 class PLATFORM_EXPORT ThreadState { | 124 class PLATFORM_EXPORT ThreadState { |
120 USING_FAST_MALLOC(ThreadState); | 125 USING_FAST_MALLOC(ThreadState); |
121 WTF_MAKE_NONCOPYABLE(ThreadState); | 126 WTF_MAKE_NONCOPYABLE(ThreadState); |
122 public: | 127 public: |
123 typedef std::pair<void*, PreFinalizerCallback> PreFinalizer; | 128 typedef std::pair<void*, PreFinalizerCallback> PreFinalizer; |
124 | 129 |
125 // See setGCState() for possible state transitions. | 130 // See setGCState() for possible state transitions. |
126 enum GCState { | 131 enum GCState { |
127 NoGCScheduled, | 132 NoGCScheduled, |
128 IdleGCScheduled, | 133 IdleGCScheduled, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 ASSERT(m_state->m_sweepForbidden); | 172 ASSERT(m_state->m_sweepForbidden); |
168 m_state->m_sweepForbidden = false; | 173 m_state->m_sweepForbidden = false; |
169 } | 174 } |
170 private: | 175 private: |
171 ThreadState* m_state; | 176 ThreadState* m_state; |
172 }; | 177 }; |
173 | 178 |
174 void lockThreadAttachMutex(); | 179 void lockThreadAttachMutex(); |
175 void unlockThreadAttachMutex(); | 180 void unlockThreadAttachMutex(); |
176 | 181 |
177 bool perThreadHeapEnabled() const { return m_perThreadHeapEnabled; } | 182 ThreadHeapMode threadHeapMode() const { return m_threadHeapMode; } |
178 | 183 |
179 bool isTerminating() { return m_isTerminating; } | 184 bool isTerminating() { return m_isTerminating; } |
180 | 185 |
181 static void attachMainThread(); | 186 static void attachMainThread(); |
182 static void detachMainThread(); | 187 static void detachMainThread(); |
183 void cleanupMainThread(); | 188 void cleanupMainThread(); |
184 | 189 |
185 // Associate ThreadState object with the current thread. After this | 190 // Associate ThreadState object with the current thread. After this |
186 // call thread can start using the garbage collected heap infrastructure. | 191 // call thread can start using the garbage collected heap infrastructure. |
187 // It also has to periodically check for safepoints. | 192 // It also has to periodically check for safepoints. |
188 static void attachCurrentThread(bool perThreadHeapEnabled); | 193 static void attachCurrentThread(ThreadHeapMode); |
189 | 194 |
190 // Disassociate attached ThreadState from the current thread. The thread | 195 // Disassociate attached ThreadState from the current thread. The thread |
191 // can no longer use the garbage collected heap after this call. | 196 // can no longer use the garbage collected heap after this call. |
192 static void detachCurrentThread(); | 197 static void detachCurrentThread(); |
193 | 198 |
194 static ThreadState* current() | 199 static ThreadState* current() |
195 { | 200 { |
196 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) | 201 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) |
197 // TLS lookup is fast in these platforms. | 202 // TLS lookup is fast in these platforms. |
198 return **s_threadSpecific; | 203 return **s_threadSpecific; |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 void collectGarbage(BlinkGC::StackState, BlinkGC::GCType, BlinkGC::GCReason) ; | 538 void collectGarbage(BlinkGC::StackState, BlinkGC::GCType, BlinkGC::GCReason) ; |
534 void collectGarbageForTerminatingThread(); | 539 void collectGarbageForTerminatingThread(); |
535 void collectAllGarbage(); | 540 void collectAllGarbage(); |
536 | 541 |
537 private: | 542 private: |
538 enum SnapshotType { | 543 enum SnapshotType { |
539 HeapSnapshot, | 544 HeapSnapshot, |
540 FreelistSnapshot | 545 FreelistSnapshot |
541 }; | 546 }; |
542 | 547 |
543 ThreadState(bool perThreadHeapEnabled); | 548 ThreadState(ThreadHeapMode); |
nhiroki
2016/09/21 05:15:26
explicit
keishi
2016/09/21 07:06:37
Done.
| |
544 ~ThreadState(); | 549 ~ThreadState(); |
545 | 550 |
546 NO_SANITIZE_ADDRESS void copyStackUntilSafePointScope(); | 551 NO_SANITIZE_ADDRESS void copyStackUntilSafePointScope(); |
547 void clearSafePointScopeMarker() | 552 void clearSafePointScopeMarker() |
548 { | 553 { |
549 m_safePointStackCopy.clear(); | 554 m_safePointStackCopy.clear(); |
550 m_safePointScopeMarker = nullptr; | 555 m_safePointScopeMarker = nullptr; |
551 } | 556 } |
552 | 557 |
553 // shouldSchedule{Precise,Idle}GC and shouldForceConservativeGC | 558 // shouldSchedule{Precise,Idle}GC and shouldForceConservativeGC |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 bool m_sweepForbidden; | 648 bool m_sweepForbidden; |
644 size_t m_noAllocationCount; | 649 size_t m_noAllocationCount; |
645 size_t m_gcForbiddenCount; | 650 size_t m_gcForbiddenCount; |
646 double m_accumulatedSweepingTime; | 651 double m_accumulatedSweepingTime; |
647 | 652 |
648 BaseArena* m_arenas[BlinkGC::NumberOfArenas]; | 653 BaseArena* m_arenas[BlinkGC::NumberOfArenas]; |
649 int m_vectorBackingArenaIndex; | 654 int m_vectorBackingArenaIndex; |
650 size_t m_arenaAges[BlinkGC::NumberOfArenas]; | 655 size_t m_arenaAges[BlinkGC::NumberOfArenas]; |
651 size_t m_currentArenaAges; | 656 size_t m_currentArenaAges; |
652 | 657 |
653 bool m_perThreadHeapEnabled; | 658 ThreadHeapMode m_threadHeapMode; |
nhiroki
2016/09/21 05:15:26
const?
keishi
2016/09/21 07:06:37
Done.
| |
654 bool m_isTerminating; | 659 bool m_isTerminating; |
655 GarbageCollectedMixinConstructorMarker* m_gcMixinMarker; | 660 GarbageCollectedMixinConstructorMarker* m_gcMixinMarker; |
656 | 661 |
657 bool m_shouldFlushHeapDoesNotContainCache; | 662 bool m_shouldFlushHeapDoesNotContainCache; |
658 GCState m_gcState; | 663 GCState m_gcState; |
659 | 664 |
660 std::unique_ptr<CallbackStack> m_threadLocalWeakCallbackStack; | 665 std::unique_ptr<CallbackStack> m_threadLocalWeakCallbackStack; |
661 | 666 |
662 // Pre-finalizers are called in the reverse order in which they are | 667 // Pre-finalizers are called in the reverse order in which they are |
663 // registered by the constructors (including constructors of Mixin objects) | 668 // registered by the constructors (including constructors of Mixin objects) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 | 718 |
714 template<> class ThreadStateFor<AnyThread> { | 719 template<> class ThreadStateFor<AnyThread> { |
715 STATIC_ONLY(ThreadStateFor); | 720 STATIC_ONLY(ThreadStateFor); |
716 public: | 721 public: |
717 static ThreadState* state() { return ThreadState::current(); } | 722 static ThreadState* state() { return ThreadState::current(); } |
718 }; | 723 }; |
719 | 724 |
720 } // namespace blink | 725 } // namespace blink |
721 | 726 |
722 #endif // ThreadState_h | 727 #endif // ThreadState_h |
OLD | NEW |