| OLD | NEW |
| 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 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 * | 24 * |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 | 28 |
| 29 #include "core/workers/WorkerThread.h" | 29 #include "core/workers/WorkerThread.h" |
| 30 | 30 |
| 31 #include "bindings/core/v8/ScriptSourceCode.h" | 31 #include "bindings/core/v8/ScriptSourceCode.h" |
| 32 #include "bindings/core/v8/V8GCController.h" | |
| 33 #include "bindings/core/v8/V8Initializer.h" | |
| 34 #include "core/dom/Microtask.h" | 32 #include "core/dom/Microtask.h" |
| 35 #include "core/inspector/InspectorInstrumentation.h" | 33 #include "core/inspector/InspectorInstrumentation.h" |
| 36 #include "core/inspector/WorkerInspectorController.h" | 34 #include "core/inspector/WorkerInspectorController.h" |
| 37 #include "core/workers/DedicatedWorkerGlobalScope.h" | 35 #include "core/workers/DedicatedWorkerGlobalScope.h" |
| 38 #include "core/workers/WorkerClients.h" | 36 #include "core/workers/WorkerClients.h" |
| 39 #include "core/workers/WorkerReportingProxy.h" | 37 #include "core/workers/WorkerReportingProxy.h" |
| 40 #include "core/workers/WorkerThreadStartupData.h" | 38 #include "core/workers/WorkerThreadStartupData.h" |
| 41 #include "platform/PlatformThreadData.h" | 39 #include "platform/PlatformThreadData.h" |
| 42 #include "platform/Task.h" | 40 #include "platform/Task.h" |
| 43 #include "platform/ThreadSafeFunctional.h" | 41 #include "platform/ThreadSafeFunctional.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // The worker was terminated before the thread had a chance to run. | 307 // The worker was terminated before the thread had a chance to run. |
| 310 if (m_terminated) { | 308 if (m_terminated) { |
| 311 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 309 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
| 312 // This can free this thread object, hence it must not be touched af
terwards. | 310 // This can free this thread object, hence it must not be touched af
terwards. |
| 313 m_workerReportingProxy.workerThreadTerminated(); | 311 m_workerReportingProxy.workerThreadTerminated(); |
| 314 return; | 312 return; |
| 315 } | 313 } |
| 316 | 314 |
| 317 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this)); | 315 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this)); |
| 318 backingThread().addTaskObserver(m_microtaskRunner.get()); | 316 backingThread().addTaskObserver(m_microtaskRunner.get()); |
| 319 backingThread().initialize(); | 317 initializeBackingThread(); |
| 320 | 318 |
| 321 m_isolate = initializeIsolate(); | 319 m_isolate = initializeIsolate(); |
| 322 m_workerGlobalScope = createWorkerGlobalScope(startupData); | 320 m_workerGlobalScope = createWorkerGlobalScope(startupData); |
| 323 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge
t() ? cachedMetaData->size() : 0); | 321 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge
t() ? cachedMetaData->size() : 0); |
| 324 | 322 |
| 325 PlatformThreadData::current().threadTimers().setSharedTimer(adoptPtr(new
WorkerSharedTimer(this))); | 323 PlatformThreadData::current().threadTimers().setSharedTimer(adoptPtr(new
WorkerSharedTimer(this))); |
| 326 } | 324 } |
| 327 | 325 |
| 328 // The corresponding call to stopRunLoop() is in ~WorkerScriptController(). | 326 // The corresponding call to stopRunLoop() is in ~WorkerScriptController(). |
| 329 didStartRunLoop(); | 327 didStartRunLoop(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // The below assignment will destroy the context, which will in turn notify
messaging proxy. | 364 // 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. | 365 // 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. | 366 // 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) | 367 #if !ENABLE(OILPAN) |
| 370 ASSERT(m_workerGlobalScope->hasOneRef()); | 368 ASSERT(m_workerGlobalScope->hasOneRef()); |
| 371 #endif | 369 #endif |
| 372 m_workerGlobalScope->notifyContextDestroyed(); | 370 m_workerGlobalScope->notifyContextDestroyed(); |
| 373 m_workerGlobalScope = nullptr; | 371 m_workerGlobalScope = nullptr; |
| 374 | 372 |
| 375 backingThread().removeTaskObserver(m_microtaskRunner.get()); | 373 backingThread().removeTaskObserver(m_microtaskRunner.get()); |
| 376 backingThread().shutdown(); | 374 shutdownBackingThread(); |
| 377 destroyIsolate(); | 375 destroyIsolate(); |
| 378 | 376 |
| 379 m_microtaskRunner = nullptr; | 377 m_microtaskRunner = nullptr; |
| 380 | 378 |
| 381 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 379 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
| 382 // This can free this thread object, hence it must not be touched afterwards
. | 380 // This can free this thread object, hence it must not be touched afterwards
. |
| 383 workerReportingProxy().workerThreadTerminated(); | 381 workerReportingProxy().workerThreadTerminated(); |
| 384 | 382 |
| 385 m_terminationEvent->signal(); | 383 m_terminationEvent->signal(); |
| 386 | 384 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 ASSERT(isCurrentThread()); | 448 ASSERT(isCurrentThread()); |
| 451 Platform::current()->didStartWorkerRunLoop(); | 449 Platform::current()->didStartWorkerRunLoop(); |
| 452 } | 450 } |
| 453 | 451 |
| 454 void WorkerThread::didStopRunLoop() | 452 void WorkerThread::didStopRunLoop() |
| 455 { | 453 { |
| 456 ASSERT(isCurrentThread()); | 454 ASSERT(isCurrentThread()); |
| 457 Platform::current()->didStopWorkerRunLoop(); | 455 Platform::current()->didStopWorkerRunLoop(); |
| 458 } | 456 } |
| 459 | 457 |
| 458 void WorkerThread::initializeBackingThread() |
| 459 { |
| 460 backingThread().initialize(); |
| 461 } |
| 462 |
| 463 void WorkerThread::shutdownBackingThread() |
| 464 { |
| 465 backingThread().shutdown(); |
| 466 } |
| 467 |
| 460 void WorkerThread::terminateAndWaitForAllWorkers() | 468 void WorkerThread::terminateAndWaitForAllWorkers() |
| 461 { | 469 { |
| 462 // Keep this lock to prevent WorkerThread instances from being destroyed. | 470 // Keep this lock to prevent WorkerThread instances from being destroyed. |
| 463 MutexLocker lock(threadSetMutex()); | 471 MutexLocker lock(threadSetMutex()); |
| 464 HashSet<WorkerThread*> threads = workerThreads(); | 472 HashSet<WorkerThread*> threads = workerThreads(); |
| 465 for (WorkerThread* thread : threads) | 473 for (WorkerThread* thread : threads) |
| 466 thread->stopInShutdownSequence(); | 474 thread->stopInShutdownSequence(); |
| 467 | 475 |
| 468 for (WorkerThread* thread : threads) | 476 for (WorkerThread* thread : threads) |
| 469 thread->terminationEvent()->wait(); | 477 thread->terminationEvent()->wait(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 500 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi
onContextTask> task) | 508 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi
onContextTask> task) |
| 501 { | 509 { |
| 502 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru
e).leakPtr()); | 510 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru
e).leakPtr()); |
| 503 } | 511 } |
| 504 | 512 |
| 505 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<
ExecutionContextTask> task, long long delayMs) | 513 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<
ExecutionContextTask> task, long long delayMs) |
| 506 { | 514 { |
| 507 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta
sk, true).leakPtr(), delayMs); | 515 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta
sk, true).leakPtr(), delayMs); |
| 508 } | 516 } |
| 509 | 517 |
| 510 v8::Isolate* WorkerThread::initializeIsolate() | 518 PassOwnPtr<WorkerV8Isolate> WorkerThread::initializeIsolate() |
| 511 { | 519 { |
| 512 ASSERT(isCurrentThread()); | 520 ASSERT(isCurrentThread()); |
| 513 ASSERT(!m_isolate); | 521 ASSERT(!m_isolate); |
| 514 v8::Isolate* isolate = V8PerIsolateData::initialize(); | 522 return WorkerV8Isolate::createDefault(); |
| 515 V8Initializer::initializeWorker(isolate); | |
| 516 | |
| 517 m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate)); | |
| 518 ThreadState::current()->addInterruptor(m_interruptor.get()); | |
| 519 ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::tr
aceDOMWrappers); | |
| 520 | |
| 521 return isolate; | |
| 522 } | 523 } |
| 523 | 524 |
| 524 void WorkerThread::willDestroyIsolate() | 525 void WorkerThread::willDestroyIsolate() |
| 525 { | 526 { |
| 526 ASSERT(isCurrentThread()); | 527 ASSERT(isCurrentThread()); |
| 527 ASSERT(m_isolate); | 528 ASSERT(m_isolate); |
| 528 V8PerIsolateData::willBeDestroyed(m_isolate); | 529 m_isolate->willDestroy(); |
| 529 ThreadState::current()->removeInterruptor(m_interruptor.get()); | |
| 530 } | 530 } |
| 531 | 531 |
| 532 void WorkerThread::destroyIsolate() | 532 void WorkerThread::destroyIsolate() |
| 533 { | 533 { |
| 534 ASSERT(isCurrentThread()); | 534 ASSERT(isCurrentThread()); |
| 535 V8PerIsolateData::destroy(m_isolate); | 535 m_isolate.clear(); |
| 536 m_isolate = nullptr; | |
| 537 } | 536 } |
| 538 | 537 |
| 539 void WorkerThread::terminateV8Execution() | 538 void WorkerThread::terminateV8Execution() |
| 540 { | 539 { |
| 541 ASSERT(isMainThread()); | 540 ASSERT(isMainThread()); |
| 542 m_workerGlobalScope->script()->willScheduleExecutionTermination(); | 541 m_workerGlobalScope->script()->willScheduleExecutionTermination(); |
| 543 v8::V8::TerminateExecution(m_isolate); | 542 m_isolate->terminateExecution(); |
| 544 } | 543 } |
| 545 | 544 |
| 546 void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task) | 545 void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task) |
| 547 { | 546 { |
| 548 m_debuggerMessageQueue.append(task); | 547 m_debuggerMessageQueue.append(task); |
| 549 } | 548 } |
| 550 | 549 |
| 551 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) | 550 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) |
| 552 { | 551 { |
| 553 ASSERT(isCurrentThread()); | 552 ASSERT(isCurrentThread()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 580 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 579 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
| 581 } | 580 } |
| 582 | 581 |
| 583 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) | 582 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) |
| 584 { | 583 { |
| 585 MutexLocker locker(m_workerInspectorControllerMutex); | 584 MutexLocker locker(m_workerInspectorControllerMutex); |
| 586 m_workerInspectorController = workerInspectorController; | 585 m_workerInspectorController = workerInspectorController; |
| 587 } | 586 } |
| 588 | 587 |
| 589 } // namespace blink | 588 } // namespace blink |
| OLD | NEW |