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(); | |
318 backingThread().addTaskObserver(m_microtaskRunner.get()); | 317 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 shutdownBackingThread(); | 376 backingThread().shutdown(); |
377 destroyIsolate(); | 377 destroyIsolate(); |
378 m_isolate = nullptr; | |
379 | 378 |
380 m_microtaskRunner = nullptr; | 379 m_microtaskRunner = nullptr; |
381 | 380 |
382 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 381 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
383 // 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
. |
384 workerReportingProxy().workerThreadTerminated(); | 383 workerReportingProxy().workerThreadTerminated(); |
385 | 384 |
386 m_terminationEvent->signal(); | 385 m_terminationEvent->signal(); |
387 | 386 |
388 // Clean up PlatformThreadData before WTF::WTFThreadData goes away! | 387 // Clean up PlatformThreadData before WTF::WTFThreadData goes away! |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 if (m_shutdown) | 431 if (m_shutdown) |
433 return; | 432 return; |
434 | 433 |
435 // 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. |
436 if (!m_workerGlobalScope) { | 435 if (!m_workerGlobalScope) { |
437 m_terminationEvent->signal(); | 436 m_terminationEvent->signal(); |
438 return; | 437 return; |
439 } | 438 } |
440 | 439 |
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. | 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. |
442 m_workerGlobalScope->script()->willScheduleExecutionTermination(); | |
443 terminateV8Execution(); | 441 terminateV8Execution(); |
444 | 442 |
445 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop
e.get()); | 443 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop
e.get()); |
446 m_debuggerMessageQueue.kill(); | 444 m_debuggerMessageQueue.kill(); |
447 backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::s
hutdown, AllowCrossThreadAccess(this)))); | 445 backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::s
hutdown, AllowCrossThreadAccess(this)))); |
448 } | 446 } |
449 | 447 |
450 void WorkerThread::didStartRunLoop() | 448 void WorkerThread::didStartRunLoop() |
451 { | 449 { |
452 ASSERT(isCurrentThread()); | 450 ASSERT(isCurrentThread()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi
onContextTask> task) | 500 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi
onContextTask> task) |
503 { | 501 { |
504 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru
e).leakPtr()); | 502 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru
e).leakPtr()); |
505 } | 503 } |
506 | 504 |
507 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<
ExecutionContextTask> task, long long delayMs) | 505 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<
ExecutionContextTask> task, long long delayMs) |
508 { | 506 { |
509 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta
sk, true).leakPtr(), delayMs); | 507 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta
sk, true).leakPtr(), delayMs); |
510 } | 508 } |
511 | 509 |
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 | |
524 v8::Isolate* WorkerThread::initializeIsolate() | 510 v8::Isolate* WorkerThread::initializeIsolate() |
525 { | 511 { |
526 ASSERT(isCurrentThread()); | 512 ASSERT(isCurrentThread()); |
527 ASSERT(!m_isolate); | 513 ASSERT(!m_isolate); |
528 v8::Isolate* isolate = V8PerIsolateData::initialize(); | 514 v8::Isolate* isolate = V8PerIsolateData::initialize(); |
529 V8Initializer::initializeWorker(isolate); | 515 V8Initializer::initializeWorker(isolate); |
530 | 516 |
531 m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate)); | 517 m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate)); |
532 ThreadState::current()->addInterruptor(m_interruptor.get()); | 518 ThreadState::current()->addInterruptor(m_interruptor.get()); |
533 ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::tr
aceDOMWrappers); | 519 ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::tr
aceDOMWrappers); |
534 | 520 |
535 return isolate; | 521 return isolate; |
536 } | 522 } |
537 | 523 |
538 void WorkerThread::willDestroyIsolate() | 524 void WorkerThread::willDestroyIsolate() |
539 { | 525 { |
540 ASSERT(isCurrentThread()); | 526 ASSERT(isCurrentThread()); |
541 ASSERT(m_isolate); | 527 ASSERT(m_isolate); |
542 V8PerIsolateData::willBeDestroyed(m_isolate); | 528 V8PerIsolateData::willBeDestroyed(m_isolate); |
543 ThreadState::current()->removeInterruptor(m_interruptor.get()); | 529 ThreadState::current()->removeInterruptor(m_interruptor.get()); |
544 } | 530 } |
545 | 531 |
546 void WorkerThread::destroyIsolate() | 532 void WorkerThread::destroyIsolate() |
547 { | 533 { |
548 ASSERT(isCurrentThread()); | 534 ASSERT(isCurrentThread()); |
549 V8PerIsolateData::destroy(m_isolate); | 535 V8PerIsolateData::destroy(m_isolate); |
| 536 m_isolate = nullptr; |
550 } | 537 } |
551 | 538 |
552 void WorkerThread::terminateV8Execution() | 539 void WorkerThread::terminateV8Execution() |
553 { | 540 { |
554 ASSERT(isMainThread()); | 541 ASSERT(isMainThread()); |
| 542 m_workerGlobalScope->script()->willScheduleExecutionTermination(); |
555 v8::V8::TerminateExecution(m_isolate); | 543 v8::V8::TerminateExecution(m_isolate); |
556 } | 544 } |
557 | 545 |
558 void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task) | 546 void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task) |
559 { | 547 { |
560 m_debuggerMessageQueue.append(task); | 548 m_debuggerMessageQueue.append(task); |
561 } | 549 } |
562 | 550 |
563 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) | 551 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) |
564 { | 552 { |
(...skipping 27 matching lines...) Expand all Loading... |
592 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 580 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
593 } | 581 } |
594 | 582 |
595 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) | 583 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) |
596 { | 584 { |
597 MutexLocker locker(m_workerInspectorControllerMutex); | 585 MutexLocker locker(m_workerInspectorControllerMutex); |
598 m_workerInspectorController = workerInspectorController; | 586 m_workerInspectorController = workerInspectorController; |
599 } | 587 } |
600 | 588 |
601 } // namespace blink | 589 } // namespace blink |
OLD | NEW |