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

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: . 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
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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 307
308 // The worker was terminated before the thread had a chance to run. 308 // The worker was terminated before the thread had a chance to run.
309 if (m_terminated) { 309 if (m_terminated) {
310 // Notify the proxy that the WorkerGlobalScope has been disposed of. 310 // Notify the proxy that the WorkerGlobalScope has been disposed of.
311 // This can free this thread object, hence it must not be touched af terwards. 311 // This can free this thread object, hence it must not be touched af terwards.
312 m_workerReportingProxy.workerThreadTerminated(); 312 m_workerReportingProxy.workerThreadTerminated();
313 return; 313 return;
314 } 314 }
315 315
316 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this)); 316 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this));
317 initializeBackingThread();
317 backingThread().addTaskObserver(m_microtaskRunner.get()); 318 backingThread().addTaskObserver(m_microtaskRunner.get());
318 backingThread().initialize();
319 319
320 m_isolate = initializeIsolate(); 320 m_isolate = initializeIsolate();
321 m_workerGlobalScope = createWorkerGlobalScope(startupData); 321 m_workerGlobalScope = createWorkerGlobalScope(startupData);
322 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge t() ? cachedMetaData->size() : 0); 322 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge t() ? cachedMetaData->size() : 0);
323 323
324 PlatformThreadData::current().threadTimers().setSharedTimer(adoptPtr(new WorkerSharedTimer(this))); 324 PlatformThreadData::current().threadTimers().setSharedTimer(adoptPtr(new WorkerSharedTimer(this)));
325 } 325 }
326 m_webScheduler = backingThread().platformThread().scheduler(); 326 m_webScheduler = backingThread().platformThread().scheduler();
327 327
328 // The corresponding call to stopRunLoop() is in ~WorkerScriptController(). 328 // The corresponding call to stopRunLoop() is in ~WorkerScriptController().
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // The below assignment will destroy the context, which will in turn notify messaging proxy. 366 // The below assignment will destroy the context, which will in turn notify messaging proxy.
367 // We cannot let any objects survive past thread exit, because no other thre ad will run GC or otherwise destroy them. 367 // We cannot let any objects survive past thread exit, because no other thre ad will run GC or otherwise destroy them.
368 // If Oilpan is enabled, we detach of the context/global scope, with the fin al heap cleanup below sweeping it out. 368 // If Oilpan is enabled, we detach of the context/global scope, with the fin al heap cleanup below sweeping it out.
369 #if !ENABLE(OILPAN) 369 #if !ENABLE(OILPAN)
370 ASSERT(m_workerGlobalScope->hasOneRef()); 370 ASSERT(m_workerGlobalScope->hasOneRef());
371 #endif 371 #endif
372 m_workerGlobalScope->notifyContextDestroyed(); 372 m_workerGlobalScope->notifyContextDestroyed();
373 m_workerGlobalScope = nullptr; 373 m_workerGlobalScope = nullptr;
374 374
375 backingThread().removeTaskObserver(m_microtaskRunner.get()); 375 backingThread().removeTaskObserver(m_microtaskRunner.get());
376 backingThread().shutdown(); 376 shutdownBackingThread();
377 destroyIsolate(); 377 destroyIsolate();
378 378
kinuko 2015/06/03 05:05:03 I feel we should do m_isolate = nullptr here (rath
sadrul 2015/06/03 14:31:38 Good point. Done.
379 m_microtaskRunner = nullptr; 379 m_microtaskRunner = nullptr;
380 380
381 // Notify the proxy that the WorkerGlobalScope has been disposed of. 381 // Notify the proxy that the WorkerGlobalScope has been disposed of.
382 // This can free this thread object, hence it must not be touched afterwards . 382 // This can free this thread object, hence it must not be touched afterwards .
383 workerReportingProxy().workerThreadTerminated(); 383 workerReportingProxy().workerThreadTerminated();
384 384
385 m_terminationEvent->signal(); 385 m_terminationEvent->signal();
386 386
387 // Clean up PlatformThreadData before WTF::WTFThreadData goes away! 387 // Clean up PlatformThreadData before WTF::WTFThreadData goes away!
388 PlatformThreadData::current().destroy(); 388 PlatformThreadData::current().destroy();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 if (m_shutdown) 431 if (m_shutdown)
432 return; 432 return;
433 433
434 // If the worker thread was never initialized, complete the termination imme diately. 434 // If the worker thread was never initialized, complete the termination imme diately.
435 if (!m_workerGlobalScope) { 435 if (!m_workerGlobalScope) {
436 m_terminationEvent->signal(); 436 m_terminationEvent->signal();
437 return; 437 return;
438 } 438 }
439 439
440 // 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. 440 // 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.
441 m_workerGlobalScope->script()->willScheduleExecutionTermination();
441 terminateV8Execution(); 442 terminateV8Execution();
442 443
443 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop e.get()); 444 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop e.get());
444 m_debuggerMessageQueue.kill(); 445 m_debuggerMessageQueue.kill();
445 backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::s hutdown, AllowCrossThreadAccess(this)))); 446 backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::s hutdown, AllowCrossThreadAccess(this))));
446 } 447 }
447 448
448 void WorkerThread::didStartRunLoop() 449 void WorkerThread::didStartRunLoop()
449 { 450 {
450 ASSERT(isCurrentThread()); 451 ASSERT(isCurrentThread());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi onContextTask> task) 501 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi onContextTask> task)
501 { 502 {
502 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru e).leakPtr()); 503 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru e).leakPtr());
503 } 504 }
504 505
505 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr< ExecutionContextTask> task, long long delayMs) 506 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr< ExecutionContextTask> task, long long delayMs)
506 { 507 {
507 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta sk, true).leakPtr(), delayMs); 508 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta sk, true).leakPtr(), delayMs);
508 } 509 }
509 510
511 void WorkerThread::initializeBackingThread()
512 {
513 ASSERT(isCurrentThread());
514 backingThread().initialize();
515 }
516
517 void WorkerThread::shutdownBackingThread()
518 {
519 ASSERT(isCurrentThread());
520 backingThread().shutdown();
521 }
522
510 v8::Isolate* WorkerThread::initializeIsolate() 523 v8::Isolate* WorkerThread::initializeIsolate()
511 { 524 {
512 ASSERT(isCurrentThread()); 525 ASSERT(isCurrentThread());
513 ASSERT(!m_isolate); 526 ASSERT(!m_isolate);
514 v8::Isolate* isolate = V8PerIsolateData::initialize(); 527 v8::Isolate* isolate = V8PerIsolateData::initialize();
515 V8Initializer::initializeWorker(isolate); 528 V8Initializer::initializeWorker(isolate);
516 529
517 m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate)); 530 m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate));
518 ThreadState::current()->addInterruptor(m_interruptor.get()); 531 ThreadState::current()->addInterruptor(m_interruptor.get());
519 ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::tr aceDOMWrappers); 532 ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::tr aceDOMWrappers);
(...skipping 12 matching lines...) Expand all
532 void WorkerThread::destroyIsolate() 545 void WorkerThread::destroyIsolate()
533 { 546 {
534 ASSERT(isCurrentThread()); 547 ASSERT(isCurrentThread());
535 V8PerIsolateData::destroy(m_isolate); 548 V8PerIsolateData::destroy(m_isolate);
536 m_isolate = nullptr; 549 m_isolate = nullptr;
537 } 550 }
538 551
539 void WorkerThread::terminateV8Execution() 552 void WorkerThread::terminateV8Execution()
540 { 553 {
541 ASSERT(isMainThread()); 554 ASSERT(isMainThread());
542 m_workerGlobalScope->script()->willScheduleExecutionTermination();
543 v8::V8::TerminateExecution(m_isolate); 555 v8::V8::TerminateExecution(m_isolate);
544 } 556 }
545 557
546 void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task) 558 void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task)
547 { 559 {
548 m_debuggerMessageQueue.append(task); 560 m_debuggerMessageQueue.append(task);
549 } 561 }
550 562
551 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) 563 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode)
552 { 564 {
(...skipping 27 matching lines...) Expand all
580 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); 592 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get());
581 } 593 }
582 594
583 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) 595 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController)
584 { 596 {
585 MutexLocker locker(m_workerInspectorControllerMutex); 597 MutexLocker locker(m_workerInspectorControllerMutex);
586 m_workerInspectorController = workerInspectorController; 598 m_workerInspectorController = workerInspectorController;
587 } 599 }
588 600
589 } // namespace blink 601 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698