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

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

Issue 1158443008: compositor-worker: Share a thread and an isolate for compositor workers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: tot-merge Created 5 years, 6 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
« no previous file with comments | « Source/core/workers/WorkerThread.h ('k') | Source/modules/InitModules.cpp » ('j') | 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) 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 211
212 // The worker was terminated before the thread had a chance to run. 212 // The worker was terminated before the thread had a chance to run.
213 if (m_terminated) { 213 if (m_terminated) {
214 // Notify the proxy that the WorkerGlobalScope has been disposed of. 214 // Notify the proxy that the WorkerGlobalScope has been disposed of.
215 // This can free this thread object, hence it must not be touched af terwards. 215 // This can free this thread object, hence it must not be touched af terwards.
216 m_workerReportingProxy.workerThreadTerminated(); 216 m_workerReportingProxy.workerThreadTerminated();
217 return; 217 return;
218 } 218 }
219 219
220 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this)); 220 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this));
221 initializeBackingThread();
221 backingThread().addTaskObserver(m_microtaskRunner.get()); 222 backingThread().addTaskObserver(m_microtaskRunner.get());
222 backingThread().initialize();
223 223
224 m_isolate = initializeIsolate(); 224 m_isolate = initializeIsolate();
225 m_workerGlobalScope = createWorkerGlobalScope(startupData); 225 m_workerGlobalScope = createWorkerGlobalScope(startupData);
226 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge t() ? cachedMetaData->size() : 0); 226 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge t() ? cachedMetaData->size() : 0);
227 } 227 }
228 m_webScheduler = backingThread().platformThread().scheduler(); 228 m_webScheduler = backingThread().platformThread().scheduler();
229 229
230 // The corresponding call to stopRunLoop() is in ~WorkerScriptController(). 230 // The corresponding call to stopRunLoop() is in ~WorkerScriptController().
231 didStartRunLoop(); 231 didStartRunLoop();
232 232
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // The below assignment will destroy the context, which will in turn notify messaging proxy. 266 // The below assignment will destroy the context, which will in turn notify messaging proxy.
267 // We cannot let any objects survive past thread exit, because no other thre ad will run GC or otherwise destroy them. 267 // We cannot let any objects survive past thread exit, because no other thre ad will run GC or otherwise destroy them.
268 // If Oilpan is enabled, we detach of the context/global scope, with the fin al heap cleanup below sweeping it out. 268 // If Oilpan is enabled, we detach of the context/global scope, with the fin al heap cleanup below sweeping it out.
269 #if !ENABLE(OILPAN) 269 #if !ENABLE(OILPAN)
270 ASSERT(m_workerGlobalScope->hasOneRef()); 270 ASSERT(m_workerGlobalScope->hasOneRef());
271 #endif 271 #endif
272 m_workerGlobalScope->notifyContextDestroyed(); 272 m_workerGlobalScope->notifyContextDestroyed();
273 m_workerGlobalScope = nullptr; 273 m_workerGlobalScope = nullptr;
274 274
275 backingThread().removeTaskObserver(m_microtaskRunner.get()); 275 backingThread().removeTaskObserver(m_microtaskRunner.get());
276 backingThread().shutdown(); 276 shutdownBackingThread();
277 destroyIsolate(); 277 destroyIsolate();
278 m_isolate = nullptr;
278 279
279 m_microtaskRunner = nullptr; 280 m_microtaskRunner = nullptr;
280 281
281 // Notify the proxy that the WorkerGlobalScope has been disposed of. 282 // Notify the proxy that the WorkerGlobalScope has been disposed of.
282 // This can free this thread object, hence it must not be touched afterwards . 283 // This can free this thread object, hence it must not be touched afterwards .
283 workerReportingProxy().workerThreadTerminated(); 284 workerReportingProxy().workerThreadTerminated();
284 285
285 m_terminationEvent->signal(); 286 m_terminationEvent->signal();
286 } 287 }
287 288
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 if (m_shutdown) 329 if (m_shutdown)
329 return; 330 return;
330 331
331 // If the worker thread was never initialized, complete the termination imme diately. 332 // If the worker thread was never initialized, complete the termination imme diately.
332 if (!m_workerGlobalScope) { 333 if (!m_workerGlobalScope) {
333 m_terminationEvent->signal(); 334 m_terminationEvent->signal();
334 return; 335 return;
335 } 336 }
336 337
337 // Ensure that tasks are being handled by thread event loop. If script execu tion weren't forbidden, a while(1) loop in JS could keep the thread alive foreve r. 338 // Ensure that tasks are being handled by thread event loop. If script execu tion weren't forbidden, a while(1) loop in JS could keep the thread alive foreve r.
339 m_workerGlobalScope->script()->willScheduleExecutionTermination();
338 terminateV8Execution(); 340 terminateV8Execution();
339 341
340 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop e.get()); 342 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop e.get());
341 m_debuggerMessageQueue.kill(); 343 m_debuggerMessageQueue.kill();
342 backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::s hutdown, AllowCrossThreadAccess(this)))); 344 backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::s hutdown, AllowCrossThreadAccess(this))));
343 } 345 }
344 346
345 void WorkerThread::didStartRunLoop() 347 void WorkerThread::didStartRunLoop()
346 { 348 {
347 ASSERT(isCurrentThread()); 349 ASSERT(isCurrentThread());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi onContextTask> task) 399 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi onContextTask> task)
398 { 400 {
399 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru e).leakPtr()); 401 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru e).leakPtr());
400 } 402 }
401 403
402 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr< ExecutionContextTask> task, long long delayMs) 404 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr< ExecutionContextTask> task, long long delayMs)
403 { 405 {
404 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta sk, true).leakPtr(), delayMs); 406 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta sk, true).leakPtr(), delayMs);
405 } 407 }
406 408
409 void WorkerThread::initializeBackingThread()
410 {
411 ASSERT(isCurrentThread());
412 backingThread().initialize();
413 }
414
415 void WorkerThread::shutdownBackingThread()
416 {
417 ASSERT(isCurrentThread());
418 backingThread().shutdown();
419 }
420
407 v8::Isolate* WorkerThread::initializeIsolate() 421 v8::Isolate* WorkerThread::initializeIsolate()
408 { 422 {
409 ASSERT(isCurrentThread()); 423 ASSERT(isCurrentThread());
410 ASSERT(!m_isolate); 424 ASSERT(!m_isolate);
411 v8::Isolate* isolate = V8PerIsolateData::initialize(); 425 v8::Isolate* isolate = V8PerIsolateData::initialize();
412 V8Initializer::initializeWorker(isolate); 426 V8Initializer::initializeWorker(isolate);
413 427
414 m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate)); 428 m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate));
415 ThreadState::current()->addInterruptor(m_interruptor.get()); 429 ThreadState::current()->addInterruptor(m_interruptor.get());
416 ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::tr aceDOMWrappers); 430 ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::tr aceDOMWrappers);
417 431
418 return isolate; 432 return isolate;
419 } 433 }
420 434
421 void WorkerThread::willDestroyIsolate() 435 void WorkerThread::willDestroyIsolate()
422 { 436 {
423 ASSERT(isCurrentThread()); 437 ASSERT(isCurrentThread());
424 ASSERT(m_isolate); 438 ASSERT(m_isolate);
425 V8PerIsolateData::willBeDestroyed(m_isolate); 439 V8PerIsolateData::willBeDestroyed(m_isolate);
426 ThreadState::current()->removeInterruptor(m_interruptor.get()); 440 ThreadState::current()->removeInterruptor(m_interruptor.get());
427 } 441 }
428 442
429 void WorkerThread::destroyIsolate() 443 void WorkerThread::destroyIsolate()
430 { 444 {
431 ASSERT(isCurrentThread()); 445 ASSERT(isCurrentThread());
432 V8PerIsolateData::destroy(m_isolate); 446 V8PerIsolateData::destroy(m_isolate);
433 m_isolate = nullptr;
434 } 447 }
435 448
436 void WorkerThread::terminateV8Execution() 449 void WorkerThread::terminateV8Execution()
437 { 450 {
438 ASSERT(isMainThread()); 451 ASSERT(isMainThread());
439 m_workerGlobalScope->script()->willScheduleExecutionTermination();
440 v8::V8::TerminateExecution(m_isolate); 452 v8::V8::TerminateExecution(m_isolate);
441 } 453 }
442 454
443 void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task) 455 void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task)
444 { 456 {
445 m_debuggerMessageQueue.append(task); 457 m_debuggerMessageQueue.append(task);
446 } 458 }
447 459
448 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) 460 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode)
449 { 461 {
(...skipping 27 matching lines...) Expand all
477 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); 489 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get());
478 } 490 }
479 491
480 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) 492 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController)
481 { 493 {
482 MutexLocker locker(m_workerInspectorControllerMutex); 494 MutexLocker locker(m_workerInspectorControllerMutex);
483 m_workerInspectorController = workerInspectorController; 495 m_workerInspectorController = workerInspectorController;
484 } 496 }
485 497
486 } // namespace blink 498 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/workers/WorkerThread.h ('k') | Source/modules/InitModules.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698