Chromium Code Reviews| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 // and we need to resume the other threads. | 132 // and we need to resume the other threads. |
| 133 if (m_shouldResumeThreads) | 133 if (m_shouldResumeThreads) |
| 134 m_state->heap().resume(); | 134 m_state->heap().resume(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 private: | 137 private: |
| 138 ThreadState* m_state; | 138 ThreadState* m_state; |
| 139 bool m_shouldResumeThreads; | 139 bool m_shouldResumeThreads; |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 ThreadState::ThreadState(BlinkGC::ThreadHeapMode threadHeapMode) | 142 ThreadState::ThreadState() |
| 143 : m_thread(currentThread()), | 143 : m_thread(currentThread()), |
| 144 m_persistentRegion(WTF::makeUnique<PersistentRegion>()), | 144 m_persistentRegion(WTF::makeUnique<PersistentRegion>()), |
| 145 #if OS(WIN) && COMPILER(MSVC) | 145 #if OS(WIN) && COMPILER(MSVC) |
| 146 m_threadStackSize(0), | 146 m_threadStackSize(0), |
| 147 #endif | 147 #endif |
| 148 m_startOfStack( | 148 m_startOfStack( |
| 149 reinterpret_cast<intptr_t*>(StackFrameDepth::getStackStart())), | 149 reinterpret_cast<intptr_t*>(StackFrameDepth::getStackStart())), |
| 150 m_endOfStack( | 150 m_endOfStack( |
| 151 reinterpret_cast<intptr_t*>(StackFrameDepth::getStackStart())), | 151 reinterpret_cast<intptr_t*>(StackFrameDepth::getStackStart())), |
| 152 m_safePointScopeMarker(nullptr), | 152 m_safePointScopeMarker(nullptr), |
| 153 m_atSafePoint(false), | 153 m_atSafePoint(false), |
| 154 m_interruptors(), | 154 m_interruptors(), |
| 155 m_sweepForbidden(false), | 155 m_sweepForbidden(false), |
| 156 m_noAllocationCount(0), | 156 m_noAllocationCount(0), |
| 157 m_gcForbiddenCount(0), | 157 m_gcForbiddenCount(0), |
| 158 m_mixinsBeingConstructedCount(0), | 158 m_mixinsBeingConstructedCount(0), |
| 159 m_accumulatedSweepingTime(0), | 159 m_accumulatedSweepingTime(0), |
| 160 m_vectorBackingArenaIndex(BlinkGC::Vector1ArenaIndex), | 160 m_vectorBackingArenaIndex(BlinkGC::Vector1ArenaIndex), |
| 161 m_currentArenaAges(0), | 161 m_currentArenaAges(0), |
| 162 m_threadHeapMode(threadHeapMode), | |
| 163 m_isTerminating(false), | 162 m_isTerminating(false), |
| 164 m_gcMixinMarker(nullptr), | 163 m_gcMixinMarker(nullptr), |
| 165 m_shouldFlushHeapDoesNotContainCache(false), | 164 m_shouldFlushHeapDoesNotContainCache(false), |
| 166 m_gcState(NoGCScheduled), | 165 m_gcState(NoGCScheduled), |
| 167 m_threadLocalWeakCallbackStack(CallbackStack::create()), | 166 m_threadLocalWeakCallbackStack(CallbackStack::create()), |
| 168 m_isolate(nullptr), | 167 m_isolate(nullptr), |
| 169 m_traceDOMWrappers(nullptr), | 168 m_traceDOMWrappers(nullptr), |
| 170 m_invalidateDeadObjectsInWrappersMarkingDeque(nullptr), | 169 m_invalidateDeadObjectsInWrappersMarkingDeque(nullptr), |
| 171 #if defined(ADDRESS_SANITIZER) | 170 #if defined(ADDRESS_SANITIZER) |
| 172 m_asanFakeStack(__asan_get_current_fake_stack()), | 171 m_asanFakeStack(__asan_get_current_fake_stack()), |
| 173 #endif | 172 #endif |
| 174 #if defined(LEAK_SANITIZER) | 173 #if defined(LEAK_SANITIZER) |
| 175 m_disabledStaticPersistentsRegistration(0), | 174 m_disabledStaticPersistentsRegistration(0), |
| 176 #endif | 175 #endif |
| 177 m_allocatedObjectSize(0), | 176 m_allocatedObjectSize(0), |
| 178 m_markedObjectSize(0), | 177 m_markedObjectSize(0), |
| 179 m_reportedMemoryToV8(0) { | 178 m_reportedMemoryToV8(0) { |
| 180 ASSERT(checkThread()); | 179 ASSERT(checkThread()); |
| 181 ASSERT(!**s_threadSpecific); | 180 ASSERT(!**s_threadSpecific); |
| 182 **s_threadSpecific = this; | 181 **s_threadSpecific = this; |
| 183 | 182 |
| 184 switch (m_threadHeapMode) { | 183 if (isMainThread()) { |
| 185 case BlinkGC::MainThreadHeapMode: | 184 s_mainThreadStackStart = |
| 186 if (isMainThread()) { | 185 reinterpret_cast<uintptr_t>(m_startOfStack) - sizeof(void*); |
| 187 s_mainThreadStackStart = | 186 size_t underestimatedStackSize = |
| 188 reinterpret_cast<uintptr_t>(m_startOfStack) - sizeof(void*); | 187 StackFrameDepth::getUnderestimatedStackSize(); |
| 189 size_t underestimatedStackSize = | 188 if (underestimatedStackSize > sizeof(void*)) { |
| 190 StackFrameDepth::getUnderestimatedStackSize(); | 189 s_mainThreadUnderestimatedStackSize = |
| 191 if (underestimatedStackSize > sizeof(void*)) | 190 underestimatedStackSize - sizeof(void*); |
| 192 s_mainThreadUnderestimatedStackSize = | 191 } |
| 193 underestimatedStackSize - sizeof(void*); | |
| 194 m_heap = new ThreadHeap(); | |
| 195 } else { | |
| 196 m_heap = &ThreadState::mainThreadState()->heap(); | |
| 197 } | |
| 198 break; | |
| 199 case BlinkGC::PerThreadHeapMode: | |
| 200 m_heap = new ThreadHeap(); | |
| 201 break; | |
| 202 } | 192 } |
| 193 m_heap = new ThreadHeap(); | |
| 203 ASSERT(m_heap); | 194 ASSERT(m_heap); |
| 204 m_heap->attach(this); | 195 m_heap->attach(this); |
|
sof
2017/01/12 08:29:30
It is possible to now also consider simplifying Th
keishi
2017/01/12 08:31:40
I am working on that next.
| |
| 205 | 196 |
| 206 for (int arenaIndex = 0; arenaIndex < BlinkGC::LargeObjectArenaIndex; | 197 for (int arenaIndex = 0; arenaIndex < BlinkGC::LargeObjectArenaIndex; |
| 207 arenaIndex++) | 198 arenaIndex++) |
| 208 m_arenas[arenaIndex] = new NormalPageArena(this, arenaIndex); | 199 m_arenas[arenaIndex] = new NormalPageArena(this, arenaIndex); |
| 209 m_arenas[BlinkGC::LargeObjectArenaIndex] = | 200 m_arenas[BlinkGC::LargeObjectArenaIndex] = |
| 210 new LargeObjectArena(this, BlinkGC::LargeObjectArenaIndex); | 201 new LargeObjectArena(this, BlinkGC::LargeObjectArenaIndex); |
| 211 | 202 |
| 212 m_likelyToBePromptlyFreed = | 203 m_likelyToBePromptlyFreed = |
| 213 wrapArrayUnique(new int[likelyToBePromptlyFreedArraySize]); | 204 wrapArrayUnique(new int[likelyToBePromptlyFreedArraySize]); |
| 214 clearArenaAges(); | 205 clearArenaAges(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 // explains the details. | 249 // explains the details. |
| 259 RELEASE_ASSERT(m_threadStackSize > 4 * 0x1000); | 250 RELEASE_ASSERT(m_threadStackSize > 4 * 0x1000); |
| 260 m_threadStackSize -= 4 * 0x1000; | 251 m_threadStackSize -= 4 * 0x1000; |
| 261 return m_threadStackSize; | 252 return m_threadStackSize; |
| 262 } | 253 } |
| 263 #endif | 254 #endif |
| 264 | 255 |
| 265 void ThreadState::attachMainThread() { | 256 void ThreadState::attachMainThread() { |
| 266 RELEASE_ASSERT(!ProcessHeap::s_shutdownComplete); | 257 RELEASE_ASSERT(!ProcessHeap::s_shutdownComplete); |
| 267 s_threadSpecific = new WTF::ThreadSpecific<ThreadState*>(); | 258 s_threadSpecific = new WTF::ThreadSpecific<ThreadState*>(); |
| 268 new (s_mainThreadStateStorage) ThreadState(BlinkGC::MainThreadHeapMode); | 259 new (s_mainThreadStateStorage) ThreadState(); |
| 269 } | 260 } |
| 270 | 261 |
| 271 void ThreadState::attachCurrentThread(BlinkGC::ThreadHeapMode threadHeapMode) { | 262 void ThreadState::attachCurrentThread() { |
| 272 RELEASE_ASSERT(!ProcessHeap::s_shutdownComplete); | 263 RELEASE_ASSERT(!ProcessHeap::s_shutdownComplete); |
| 273 new ThreadState(threadHeapMode); | 264 new ThreadState(); |
| 274 } | 265 } |
| 275 | 266 |
| 276 void ThreadState::cleanupPages() { | 267 void ThreadState::cleanupPages() { |
| 277 ASSERT(checkThread()); | 268 ASSERT(checkThread()); |
| 278 for (int i = 0; i < BlinkGC::NumberOfArenas; ++i) | 269 for (int i = 0; i < BlinkGC::NumberOfArenas; ++i) |
| 279 m_arenas[i]->cleanupPages(); | 270 m_arenas[i]->cleanupPages(); |
| 280 } | 271 } |
| 281 | 272 |
| 282 void ThreadState::runTerminationGC() { | 273 void ThreadState::runTerminationGC() { |
| 283 if (isMainThread()) { | 274 if (isMainThread()) { |
| (...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1858 collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, | 1849 collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, |
| 1859 BlinkGC::ForcedGC); | 1850 BlinkGC::ForcedGC); |
| 1860 size_t liveObjects = heap().heapStats().markedObjectSize(); | 1851 size_t liveObjects = heap().heapStats().markedObjectSize(); |
| 1861 if (liveObjects == previousLiveObjects) | 1852 if (liveObjects == previousLiveObjects) |
| 1862 break; | 1853 break; |
| 1863 previousLiveObjects = liveObjects; | 1854 previousLiveObjects = liveObjects; |
| 1864 } | 1855 } |
| 1865 } | 1856 } |
| 1866 | 1857 |
| 1867 } // namespace blink | 1858 } // namespace blink |
| OLD | NEW |