Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: third_party/WebKit/Source/platform/heap/ThreadState.cpp

Issue 1771353010: Finish completeSweep before shutting down V8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/heap/ThreadState.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 #endif 202 #endif
203 203
204 void ThreadState::attachMainThread() 204 void ThreadState::attachMainThread()
205 { 205 {
206 RELEASE_ASSERT(!Heap::s_shutdownCalled); 206 RELEASE_ASSERT(!Heap::s_shutdownCalled);
207 MutexLocker locker(threadAttachMutex()); 207 MutexLocker locker(threadAttachMutex());
208 ThreadState* state = new (s_mainThreadStateStorage) ThreadState(); 208 ThreadState* state = new (s_mainThreadStateStorage) ThreadState();
209 attachedThreads().add(state); 209 attachedThreads().add(state);
210 } 210 }
211 211
212
213 void ThreadState::stopMainThread()
214 {
215 ASSERT(isMainThread());
216
217 // Finish sweeping before shutting down V8. Otherwise, some destructor
218 // may access V8 and cause crashes.
219 completeSweep();
220
221 // It is unsafe to trigger GCs after this point because some
222 // destructor may access already-detached V8 and cause crashes.
223 // Also there is no benefit in triggering a GC on a detaching thread.
224 // So we forbid GCs.
225 enterGCForbiddenScope();
226 }
227
212 void ThreadState::detachMainThread() 228 void ThreadState::detachMainThread()
213 { 229 {
214 // Enter a safe point before trying to acquire threadAttachMutex 230 // Enter a safe point before trying to acquire threadAttachMutex
215 // to avoid dead lock if another thread is preparing for GC, has acquired 231 // to avoid dead lock if another thread is preparing for GC, has acquired
216 // threadAttachMutex and waiting for other threads to pause or reach a 232 // threadAttachMutex and waiting for other threads to pause or reach a
217 // safepoint. 233 // safepoint.
218 ThreadState* state = mainThreadState(); 234 ThreadState* state = mainThreadState();
219 ASSERT(state == ThreadState::current()); 235 ASSERT(state == ThreadState::current());
220 ASSERT(state->checkThread()); 236 ASSERT(state->checkThread());
221 // You must call unregisterTraceDOMWrappers before detaching 237 ASSERT(!state->isSweepingInProgress());
sof 2016/03/10 07:52:16 nit: add ASSERT(state->isGCForbidden());
222 // the main thread.
223 ASSERT(!state->m_isolate);
224 238
225 // 1. Finish sweeping. 239 // The main thread must be the last thread that gets detached.
226 state->completeSweep(); 240 RELEASE_ASSERT(ThreadState::attachedThreads().size() == 1);
227 {
228 SafePointAwareMutexLocker locker(threadAttachMutex(), BlinkGC::NoHeapPoi ntersOnStack);
229 241
230 // 2. Add the main thread's heap pages to the orphaned pool. 242 // Add the main thread's heap pages to the orphaned pool.
231 state->cleanupPages(); 243 state->cleanupPages();
232 244
233 // 3. Detach the main thread. 245 state->leaveGCForbiddenScope();
234 ASSERT(attachedThreads().contains(state)); 246
235 attachedThreads().remove(state); 247 // Detach the main thread. We don't need to grab a lock because
236 state->~ThreadState(); 248 // the main thread should be the last thread that gets detached.
237 } 249 ASSERT(attachedThreads().contains(state));
250 attachedThreads().remove(state);
251 state->~ThreadState();
238 } 252 }
239 253
240 void ThreadState::attach() 254 void ThreadState::attach()
241 { 255 {
242 RELEASE_ASSERT(!Heap::s_shutdownCalled); 256 RELEASE_ASSERT(!Heap::s_shutdownCalled);
243 MutexLocker locker(threadAttachMutex()); 257 MutexLocker locker(threadAttachMutex());
244 ThreadState* state = new ThreadState(); 258 ThreadState* state = new ThreadState();
245 attachedThreads().add(state); 259 attachedThreads().add(state);
246 } 260 }
247 261
(...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 threadDump->addScalar("dead_count", "objects", totalDeadCount); 1552 threadDump->addScalar("dead_count", "objects", totalDeadCount);
1539 threadDump->addScalar("live_size", "bytes", totalLiveSize); 1553 threadDump->addScalar("live_size", "bytes", totalLiveSize);
1540 threadDump->addScalar("dead_size", "bytes", totalDeadSize); 1554 threadDump->addScalar("dead_size", "bytes", totalDeadSize);
1541 1555
1542 WebMemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvider::instance()->c reateMemoryAllocatorDumpForCurrentGC(heapsDumpName); 1556 WebMemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvider::instance()->c reateMemoryAllocatorDumpForCurrentGC(heapsDumpName);
1543 WebMemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvider::instance()- >createMemoryAllocatorDumpForCurrentGC(classesDumpName); 1557 WebMemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvider::instance()- >createMemoryAllocatorDumpForCurrentGC(classesDumpName);
1544 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->addOwners hipEdge(classesDump->guid(), heapsDump->guid()); 1558 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->addOwners hipEdge(classesDump->guid(), heapsDump->guid());
1545 } 1559 }
1546 1560
1547 } // namespace blink 1561 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/ThreadState.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698