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

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
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::cleanupMainThread()
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 it is useless. So we forbid GCs.
224 enterGCForbiddenScope();
225 }
226
212 void ThreadState::detachMainThread() 227 void ThreadState::detachMainThread()
213 { 228 {
214 // Enter a safe point before trying to acquire threadAttachMutex 229 // Enter a safe point before trying to acquire threadAttachMutex
215 // to avoid dead lock if another thread is preparing for GC, has acquired 230 // 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 231 // threadAttachMutex and waiting for other threads to pause or reach a
217 // safepoint. 232 // safepoint.
218 ThreadState* state = mainThreadState(); 233 ThreadState* state = mainThreadState();
219 ASSERT(state == ThreadState::current()); 234 ASSERT(state == ThreadState::current());
220 ASSERT(state->checkThread()); 235 ASSERT(state->checkThread());
221 // You must call unregisterTraceDOMWrappers before detaching 236 ASSERT(!state->isSweepingInProgress());
222 // the main thread.
223 ASSERT(!state->m_isolate);
224 237
225 // 1. Finish sweeping. 238 // The main thread must be the last thread that gets detached.
226 state->completeSweep(); 239 RELEASE_ASSERT(ThreadState::attachedThreads().size() == 1);
227 {
228 SafePointAwareMutexLocker locker(threadAttachMutex(), BlinkGC::NoHeapPoi ntersOnStack);
229 240
230 // 2. Add the main thread's heap pages to the orphaned pool. 241 // Add the main thread's heap pages to the orphaned pool.
231 state->cleanupPages(); 242 state->cleanupPages();
232 243
233 // 3. Detach the main thread. 244 // Detach the main thread. We don't need to grab a lock because
234 ASSERT(attachedThreads().contains(state)); 245 // the main thread should be the last thread that gets detached.
235 attachedThreads().remove(state); 246 ASSERT(attachedThreads().contains(state));
236 state->~ThreadState(); 247 attachedThreads().remove(state);
237 } 248 state->~ThreadState();
238 } 249 }
239 250
240 void ThreadState::attach() 251 void ThreadState::attach()
241 { 252 {
242 RELEASE_ASSERT(!Heap::s_shutdownCalled); 253 RELEASE_ASSERT(!Heap::s_shutdownCalled);
243 MutexLocker locker(threadAttachMutex()); 254 MutexLocker locker(threadAttachMutex());
244 ThreadState* state = new ThreadState(); 255 ThreadState* state = new ThreadState();
245 attachedThreads().add(state); 256 attachedThreads().add(state);
246 } 257 }
247 258
(...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 threadDump->addScalar("dead_count", "objects", totalDeadCount); 1549 threadDump->addScalar("dead_count", "objects", totalDeadCount);
1539 threadDump->addScalar("live_size", "bytes", totalLiveSize); 1550 threadDump->addScalar("live_size", "bytes", totalLiveSize);
1540 threadDump->addScalar("dead_size", "bytes", totalDeadSize); 1551 threadDump->addScalar("dead_size", "bytes", totalDeadSize);
1541 1552
1542 WebMemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvider::instance()->c reateMemoryAllocatorDumpForCurrentGC(heapsDumpName); 1553 WebMemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvider::instance()->c reateMemoryAllocatorDumpForCurrentGC(heapsDumpName);
1543 WebMemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvider::instance()- >createMemoryAllocatorDumpForCurrentGC(classesDumpName); 1554 WebMemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvider::instance()- >createMemoryAllocatorDumpForCurrentGC(classesDumpName);
1544 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->addOwners hipEdge(classesDump->guid(), heapsDump->guid()); 1555 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->addOwners hipEdge(classesDump->guid(), heapsDump->guid());
1545 } 1556 }
1546 1557
1547 } // namespace blink 1558 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698