| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 m_isolate = nullptr; |
| 378 | 379 |
| 379 m_microtaskRunner = nullptr; | 380 m_microtaskRunner = nullptr; |
| 380 | 381 |
| 381 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 382 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
| 382 // This can free this thread object, hence it must not be touched afterwards
. | 383 // This can free this thread object, hence it must not be touched afterwards
. |
| 383 workerReportingProxy().workerThreadTerminated(); | 384 workerReportingProxy().workerThreadTerminated(); |
| 384 | 385 |
| 385 m_terminationEvent->signal(); | 386 m_terminationEvent->signal(); |
| 386 | 387 |
| 387 // Clean up PlatformThreadData before WTF::WTFThreadData goes away! | 388 // Clean up PlatformThreadData before WTF::WTFThreadData goes away! |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 if (m_shutdown) | 432 if (m_shutdown) |
| 432 return; | 433 return; |
| 433 | 434 |
| 434 // If the worker thread was never initialized, complete the termination imme
diately. | 435 // If the worker thread was never initialized, complete the termination imme
diately. |
| 435 if (!m_workerGlobalScope) { | 436 if (!m_workerGlobalScope) { |
| 436 m_terminationEvent->signal(); | 437 m_terminationEvent->signal(); |
| 437 return; | 438 return; |
| 438 } | 439 } |
| 439 | 440 |
| 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 // 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. |
| 442 m_workerGlobalScope->script()->willScheduleExecutionTermination(); |
| 441 terminateV8Execution(); | 443 terminateV8Execution(); |
| 442 | 444 |
| 443 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop
e.get()); | 445 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop
e.get()); |
| 444 m_debuggerMessageQueue.kill(); | 446 m_debuggerMessageQueue.kill(); |
| 445 backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::s
hutdown, AllowCrossThreadAccess(this)))); | 447 backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::s
hutdown, AllowCrossThreadAccess(this)))); |
| 446 } | 448 } |
| 447 | 449 |
| 448 void WorkerThread::didStartRunLoop() | 450 void WorkerThread::didStartRunLoop() |
| 449 { | 451 { |
| 450 ASSERT(isCurrentThread()); | 452 ASSERT(isCurrentThread()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi
onContextTask> task) | 502 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi
onContextTask> task) |
| 501 { | 503 { |
| 502 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru
e).leakPtr()); | 504 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru
e).leakPtr()); |
| 503 } | 505 } |
| 504 | 506 |
| 505 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<
ExecutionContextTask> task, long long delayMs) | 507 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<
ExecutionContextTask> task, long long delayMs) |
| 506 { | 508 { |
| 507 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta
sk, true).leakPtr(), delayMs); | 509 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta
sk, true).leakPtr(), delayMs); |
| 508 } | 510 } |
| 509 | 511 |
| 512 void WorkerThread::initializeBackingThread() |
| 513 { |
| 514 ASSERT(isCurrentThread()); |
| 515 backingThread().initialize(); |
| 516 } |
| 517 |
| 518 void WorkerThread::shutdownBackingThread() |
| 519 { |
| 520 ASSERT(isCurrentThread()); |
| 521 backingThread().shutdown(); |
| 522 } |
| 523 |
| 510 v8::Isolate* WorkerThread::initializeIsolate() | 524 v8::Isolate* WorkerThread::initializeIsolate() |
| 511 { | 525 { |
| 512 ASSERT(isCurrentThread()); | 526 ASSERT(isCurrentThread()); |
| 513 ASSERT(!m_isolate); | 527 ASSERT(!m_isolate); |
| 514 v8::Isolate* isolate = V8PerIsolateData::initialize(); | 528 v8::Isolate* isolate = V8PerIsolateData::initialize(); |
| 515 V8Initializer::initializeWorker(isolate); | 529 V8Initializer::initializeWorker(isolate); |
| 516 | 530 |
| 517 m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate)); | 531 m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate)); |
| 518 ThreadState::current()->addInterruptor(m_interruptor.get()); | 532 ThreadState::current()->addInterruptor(m_interruptor.get()); |
| 519 ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::tr
aceDOMWrappers); | 533 ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::tr
aceDOMWrappers); |
| 520 | 534 |
| 521 return isolate; | 535 return isolate; |
| 522 } | 536 } |
| 523 | 537 |
| 524 void WorkerThread::willDestroyIsolate() | 538 void WorkerThread::willDestroyIsolate() |
| 525 { | 539 { |
| 526 ASSERT(isCurrentThread()); | 540 ASSERT(isCurrentThread()); |
| 527 ASSERT(m_isolate); | 541 ASSERT(m_isolate); |
| 528 V8PerIsolateData::willBeDestroyed(m_isolate); | 542 V8PerIsolateData::willBeDestroyed(m_isolate); |
| 529 ThreadState::current()->removeInterruptor(m_interruptor.get()); | 543 ThreadState::current()->removeInterruptor(m_interruptor.get()); |
| 530 } | 544 } |
| 531 | 545 |
| 532 void WorkerThread::destroyIsolate() | 546 void WorkerThread::destroyIsolate() |
| 533 { | 547 { |
| 534 ASSERT(isCurrentThread()); | 548 ASSERT(isCurrentThread()); |
| 535 V8PerIsolateData::destroy(m_isolate); | 549 V8PerIsolateData::destroy(m_isolate); |
| 536 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 Loading... |
| 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 |
| OLD | NEW |