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

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

Powered by Google App Engine
This is Rietveld 408576698