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

Side by Side Diff: third_party/WebKit/Source/web/WebKit.cpp

Issue 1761853002: Shut down all threads before the main thread shuts down (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.cpp ('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) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 static void callOnMainThreadFunction(WTF::MainThreadFunction function, void* con text) 134 static void callOnMainThreadFunction(WTF::MainThreadFunction function, void* con text)
135 { 135 {
136 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, threadSafeBind(function, AllowCrossThreadAccess(context))); 136 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, threadSafeBind(function, AllowCrossThreadAccess(context)));
137 } 137 }
138 138
139 static void adjustAmountOfExternalAllocatedMemory(int size) 139 static void adjustAmountOfExternalAllocatedMemory(int size)
140 { 140 {
141 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(size); 141 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(size);
142 } 142 }
143 143
144 static ModulesInitializer& modulesInitializer()
145 {
146 DEFINE_STATIC_LOCAL(OwnPtr<ModulesInitializer>, initializer, (adoptPtr(new M odulesInitializer)));
147 return *initializer;
148 }
149
144 void initializeWithoutV8(Platform* platform) 150 void initializeWithoutV8(Platform* platform)
145 { 151 {
146 ASSERT(!s_webKitInitialized); 152 ASSERT(!s_webKitInitialized);
147 s_webKitInitialized = true; 153 s_webKitInitialized = true;
148 154
149 WTF::Partitions::initialize(maxObservedSizeFunction); 155 WTF::Partitions::initialize(maxObservedSizeFunction);
150 ASSERT(platform); 156 ASSERT(platform);
151 Platform::initialize(platform); 157 Platform::initialize(platform);
152 158
153 WTF::initialize(adjustAmountOfExternalAllocatedMemory); 159 WTF::initialize(adjustAmountOfExternalAllocatedMemory);
154 WTF::initializeMainThread(callOnMainThreadFunction); 160 WTF::initializeMainThread(callOnMainThreadFunction);
155 Heap::init(); 161 Heap::init();
156 162
157 ThreadState::attachMainThread(); 163 ThreadState::attachMainThread();
158 // currentThread() is null if we are running on a thread without a message l oop. 164 // currentThread() is null if we are running on a thread without a message l oop.
159 if (WebThread* currentThread = platform->currentThread()) { 165 if (WebThread* currentThread = platform->currentThread()) {
160 ASSERT(!s_gcTaskRunner); 166 ASSERT(!s_gcTaskRunner);
161 s_gcTaskRunner = new GCTaskRunner(currentThread); 167 s_gcTaskRunner = new GCTaskRunner(currentThread);
162 } 168 }
163 169
164 DEFINE_STATIC_LOCAL(ModulesInitializer, initializer, ()); 170 modulesInitializer().init();
165 initializer.init();
166 171
167 setIndexedDBClientCreateFunction(IndexedDBClientImpl::create); 172 setIndexedDBClientCreateFunction(IndexedDBClientImpl::create);
168 } 173 }
169 174
170 void shutdown() 175 void shutdown()
171 { 176 {
172 #if defined(LEAK_SANITIZER) 177 #if defined(LEAK_SANITIZER)
173 // If LSan is about to perform leak detection, release all the registered 178 // If LSan is about to perform leak detection, release all the registered
174 // static Persistent<> root references to global caches that Blink keeps, 179 // static Persistent<> root references to global caches that Blink keeps,
175 // followed by GCs to clear out all they referred to. A full v8 GC cycle 180 // followed by GCs to clear out all they referred to. A full v8 GC cycle
(...skipping 11 matching lines...) Expand all
187 // currentThread() is null if we are running on a thread without a message l oop. 192 // currentThread() is null if we are running on a thread without a message l oop.
188 if (Platform::current()->currentThread()) { 193 if (Platform::current()->currentThread()) {
189 Platform::current()->unregisterMemoryDumpProvider(WebCacheMemoryDumpProv ider::instance()); 194 Platform::current()->unregisterMemoryDumpProvider(WebCacheMemoryDumpProv ider::instance());
190 Platform::current()->unregisterMemoryDumpProvider(FontCacheMemoryDumpPro vider::instance()); 195 Platform::current()->unregisterMemoryDumpProvider(FontCacheMemoryDumpPro vider::instance());
191 196
192 // We don't need to (cannot) remove s_endOfTaskRunner from the current 197 // We don't need to (cannot) remove s_endOfTaskRunner from the current
193 // message loop, because the message loop is already destructed before 198 // message loop, because the message loop is already destructed before
194 // the shutdown() is called. 199 // the shutdown() is called.
195 delete s_endOfTaskRunner; 200 delete s_endOfTaskRunner;
196 s_endOfTaskRunner = nullptr; 201 s_endOfTaskRunner = nullptr;
197
198 ASSERT(s_gcTaskRunner);
199 delete s_gcTaskRunner;
200 s_gcTaskRunner = nullptr;
201 } 202 }
202 203
203 // Shutdown V8-related background threads before V8 is ramped down. Note 204 // Shutdown V8-related background threads before V8 is ramped down. Note
204 // that this will wait the thread to stop its operations. 205 // that this will wait the thread to stop its operations.
205 ScriptStreamerThread::shutdown(); 206 ScriptStreamerThread::shutdown();
206 207
208 ThreadState::current()->unregisterTraceDOMWrappers();
209
207 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); 210 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate();
208 V8PerIsolateData::willBeDestroyed(isolate); 211 V8PerIsolateData::willBeDestroyed(isolate);
209 212
210 CoreInitializer::terminateThreads();
211
212 ModulesInitializer::terminateThreads();
213
214 // Detach the main thread before starting the shutdown sequence
215 // so that the main thread won't get involved in a GC during the shutdown.
216 ThreadState::detachMainThread();
217
218 V8PerIsolateData::destroy(isolate); 213 V8PerIsolateData::destroy(isolate);
219 214
220 shutdownWithoutV8(); 215 shutdownWithoutV8();
221 } 216 }
222 217
223 void shutdownWithoutV8() 218 void shutdownWithoutV8()
224 { 219 {
220 ASSERT(isMainThread());
221 modulesInitializer().shutdown();
222
223 // currentThread() is null if we are running on a thread without a message l oop.
224 if (Platform::current()->currentThread()) {
225 ASSERT(s_gcTaskRunner);
226 delete s_gcTaskRunner;
227 s_gcTaskRunner = nullptr;
228 }
229
230 // Detach the main thread before starting the shutdown sequence
231 // so that the main thread won't get involved in a GC during the shutdown.
232 ThreadState::detachMainThread();
233
225 ASSERT(!s_endOfTaskRunner); 234 ASSERT(!s_endOfTaskRunner);
226 CoreInitializer::shutdown();
227 Heap::shutdown(); 235 Heap::shutdown();
228 WTF::shutdown(); 236 WTF::shutdown();
229 Platform::shutdown(); 237 Platform::shutdown();
230 WebPrerenderingSupport::shutdown(); 238 WebPrerenderingSupport::shutdown();
231 WTF::Partitions::shutdown(); 239 WTF::Partitions::shutdown();
232 } 240 }
233 241
234 // TODO(tkent): The following functions to wrap LayoutTestSupport should be 242 // TODO(tkent): The following functions to wrap LayoutTestSupport should be
235 // moved to public/platform/. 243 // moved to public/platform/.
236 244
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 ASSERT(!reloadPages); 291 ASSERT(!reloadPages);
284 Page::refreshPlugins(); 292 Page::refreshPlugins();
285 } 293 }
286 294
287 void decommitFreeableMemory() 295 void decommitFreeableMemory()
288 { 296 {
289 WTF::Partitions::decommitFreeableMemory(); 297 WTF::Partitions::decommitFreeableMemory();
290 } 298 }
291 299
292 } // namespace blink 300 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/ThreadState.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698