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

Side by Side Diff: Source/core/workers/WorkerThread.cpp

Issue 469683002: Implement WebThreadSupportingGC, which wraps a WebThread attached to Oilpan's GC (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 MutexLocker lock(threadSetMutex()); 217 MutexLocker lock(threadSetMutex());
218 ASSERT(workerThreads().contains(this)); 218 ASSERT(workerThreads().contains(this));
219 workerThreads().remove(this); 219 workerThreads().remove(this);
220 } 220 }
221 221
222 void WorkerThread::start() 222 void WorkerThread::start()
223 { 223 {
224 if (m_thread) 224 if (m_thread)
225 return; 225 return;
226 226
227 m_thread = adoptPtr(blink::Platform::current()->createThread("WebCore: Worke r")); 227 m_thread = WebThreadRunner::create("WebCore: Worker");
228 m_thread->postTask(new Task(WTF::bind(&WorkerThread::initialize, this))); 228 m_thread->postTask(new Task(WTF::bind(&WorkerThread::initialize, this)));
229 } 229 }
230 230
231 void WorkerThread::interruptAndDispatchInspectorCommands() 231 void WorkerThread::interruptAndDispatchInspectorCommands()
232 { 232 {
233 MutexLocker locker(m_workerInspectorControllerMutex); 233 MutexLocker locker(m_workerInspectorControllerMutex);
234 if (m_workerInspectorController) 234 if (m_workerInspectorController)
235 m_workerInspectorController->interruptAndDispatchInspectorCommands(); 235 m_workerInspectorController->interruptAndDispatchInspectorCommands();
236 } 236 }
237 237
238 void WorkerThread::initialize() 238 void WorkerThread::initialize()
239 { 239 {
240 KURL scriptURL = m_startupData->m_scriptURL; 240 KURL scriptURL = m_startupData->m_scriptURL;
241 String sourceCode = m_startupData->m_sourceCode; 241 String sourceCode = m_startupData->m_sourceCode;
242 WorkerThreadStartMode startMode = m_startupData->m_startMode; 242 WorkerThreadStartMode startMode = m_startupData->m_startMode;
243 m_microtaskRunner = adoptPtr(new MicrotaskRunner); 243 m_microtaskRunner = adoptPtr(new MicrotaskRunner);
244 m_thread->addTaskObserver(m_microtaskRunner.get()); 244 m_thread->addTaskObserver(m_microtaskRunner.get());
245 245
246 { 246 {
247 MutexLocker lock(m_threadCreationMutex); 247 MutexLocker lock(m_threadCreationMutex);
248 248
249 m_pendingGCRunner = adoptPtr(new PendingGCRunner); 249 m_thread->attachGC();
250 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(m_thread. get()));
251 m_thread->addTaskObserver(m_pendingGCRunner.get());
252 ThreadState::attach();
253 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get());
254 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); 250 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release());
255 251
256 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this)); 252 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this));
257 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime r.get()); 253 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime r.get());
258 254
259 if (m_terminated) { 255 if (m_terminated) {
260 // The worker was terminated before the thread had a chance to run. Since the context didn't exist yet, 256 // The worker was terminated before the thread had a chance to run. Since the context didn't exist yet,
261 // forbidExecution() couldn't be called from stop(). 257 // forbidExecution() couldn't be called from stop().
262 m_workerGlobalScope->script()->forbidExecution(); 258 m_workerGlobalScope->script()->forbidExecution();
263 } 259 }
(...skipping 25 matching lines...) Expand all
289 285
290 // The below assignment will destroy the context, which will in turn notify messaging proxy. 286 // The below assignment will destroy the context, which will in turn notify messaging proxy.
291 // We cannot let any objects survive past thread exit, because no other thre ad will run GC or otherwise destroy them. 287 // We cannot let any objects survive past thread exit, because no other thre ad will run GC or otherwise destroy them.
292 // If Oilpan is enabled, we detach of the context/global scope, with the fin al heap cleanup below sweeping it out. 288 // If Oilpan is enabled, we detach of the context/global scope, with the fin al heap cleanup below sweeping it out.
293 #if !ENABLE(OILPAN) 289 #if !ENABLE(OILPAN)
294 ASSERT(m_workerGlobalScope->hasOneRef()); 290 ASSERT(m_workerGlobalScope->hasOneRef());
295 #endif 291 #endif
296 m_workerGlobalScope->dispose(); 292 m_workerGlobalScope->dispose();
297 m_workerGlobalScope = nullptr; 293 m_workerGlobalScope = nullptr;
298 294
299 ThreadState::current()->removeInterruptor(m_messageLoopInterruptor.get()); 295 m_thread->detachGC();
300
301 // Detach the ThreadState, cleaning out the thread's heap by
302 // performing a final GC. The cleanup operation will at the end
303 // assert that the heap is empty. If the heap does not become
304 // empty, there are still pointers into the heap and those
305 // pointers will be dangling after thread termination because we
306 // are destroying the heap. It is important to detach while the
307 // thread is still valid. In particular, finalizers for objects in
308 // the heap for this thread will need to access thread local data.
309 ThreadState::detach();
310 296
311 m_thread->removeTaskObserver(m_microtaskRunner.get()); 297 m_thread->removeTaskObserver(m_microtaskRunner.get());
312 m_microtaskRunner = nullptr; 298 m_microtaskRunner = nullptr;
313 m_thread->removeTaskObserver(m_pendingGCRunner.get());
314 m_pendingGCRunner = nullptr;
315 m_messageLoopInterruptor = nullptr;
316 299
317 // Notify the proxy that the WorkerGlobalScope has been disposed of. 300 // Notify the proxy that the WorkerGlobalScope has been disposed of.
318 // This can free this thread object, hence it must not be touched afterwards . 301 // This can free this thread object, hence it must not be touched afterwards .
319 workerReportingProxy().workerGlobalScopeDestroyed(); 302 workerReportingProxy().workerGlobalScopeDestroyed();
320 303
321 // Clean up PlatformThreadData before WTF::WTFThreadData goes away! 304 // Clean up PlatformThreadData before WTF::WTFThreadData goes away!
322 PlatformThreadData::current().destroy(); 305 PlatformThreadData::current().destroy();
323 } 306 }
324 307
325 class WorkerThreadShutdownFinishTask : public ExecutionContextTask { 308 class WorkerThreadShutdownFinishTask : public ExecutionContextTask {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); 447 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get());
465 } 448 }
466 449
467 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) 450 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController)
468 { 451 {
469 MutexLocker locker(m_workerInspectorControllerMutex); 452 MutexLocker locker(m_workerInspectorControllerMutex);
470 m_workerInspectorController = workerInspectorController; 453 m_workerInspectorController = workerInspectorController;
471 } 454 }
472 455
473 } // namespace blink 456 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698