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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(); | |
222 backingThread().addTaskObserver(m_microtaskRunner.get()); | 221 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // The below assignment will destroy the context, which will in turn notify
messaging proxy. | 267 // The below assignment will destroy the context, which will in turn notify
messaging proxy. |
268 // We cannot let any objects survive past thread exit, because no other thre
ad will run GC or otherwise destroy them. | 268 // We cannot let any objects survive past thread exit, because no other thre
ad will run GC or otherwise destroy them. |
269 // If Oilpan is enabled, we detach of the context/global scope, with the fin
al heap cleanup below sweeping it out. | 269 // If Oilpan is enabled, we detach of the context/global scope, with the fin
al heap cleanup below sweeping it out. |
270 #if !ENABLE(OILPAN) | 270 #if !ENABLE(OILPAN) |
271 ASSERT(m_workerGlobalScope->hasOneRef()); | 271 ASSERT(m_workerGlobalScope->hasOneRef()); |
272 #endif | 272 #endif |
273 m_workerGlobalScope->notifyContextDestroyed(); | 273 m_workerGlobalScope->notifyContextDestroyed(); |
274 m_workerGlobalScope = nullptr; | 274 m_workerGlobalScope = nullptr; |
275 | 275 |
276 backingThread().removeTaskObserver(m_microtaskRunner.get()); | 276 backingThread().removeTaskObserver(m_microtaskRunner.get()); |
277 shutdownBackingThread(); | 277 backingThread().shutdown(); |
278 destroyIsolate(); | 278 destroyIsolate(); |
279 m_isolate = nullptr; | |
280 | 279 |
281 m_microtaskRunner = nullptr; | 280 m_microtaskRunner = nullptr; |
282 | 281 |
283 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 282 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
284 // 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
. |
285 workerReportingProxy().workerThreadTerminated(); | 284 workerReportingProxy().workerThreadTerminated(); |
286 | 285 |
287 m_terminationEvent->signal(); | 286 m_terminationEvent->signal(); |
288 } | 287 } |
289 | 288 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 if (m_shutdown) | 329 if (m_shutdown) |
331 return; | 330 return; |
332 | 331 |
333 // 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. |
334 if (!m_workerGlobalScope) { | 333 if (!m_workerGlobalScope) { |
335 m_terminationEvent->signal(); | 334 m_terminationEvent->signal(); |
336 return; | 335 return; |
337 } | 336 } |
338 | 337 |
339 // 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. |
340 m_workerGlobalScope->script()->willScheduleExecutionTermination(); | |
341 terminateV8Execution(); | 339 terminateV8Execution(); |
342 | 340 |
343 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop
e.get()); | 341 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop
e.get()); |
344 m_debuggerMessageQueue.kill(); | 342 m_debuggerMessageQueue.kill(); |
345 backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::s
hutdown, AllowCrossThreadAccess(this)))); | 343 backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::s
hutdown, AllowCrossThreadAccess(this)))); |
346 } | 344 } |
347 | 345 |
348 void WorkerThread::didStartRunLoop() | 346 void WorkerThread::didStartRunLoop() |
349 { | 347 { |
350 ASSERT(isCurrentThread()); | 348 ASSERT(isCurrentThread()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi
onContextTask> task) | 398 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi
onContextTask> task) |
401 { | 399 { |
402 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru
e).leakPtr()); | 400 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru
e).leakPtr()); |
403 } | 401 } |
404 | 402 |
405 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<
ExecutionContextTask> task, long long delayMs) | 403 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<
ExecutionContextTask> task, long long delayMs) |
406 { | 404 { |
407 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta
sk, true).leakPtr(), delayMs); | 405 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta
sk, true).leakPtr(), delayMs); |
408 } | 406 } |
409 | 407 |
410 void WorkerThread::initializeBackingThread() | |
411 { | |
412 ASSERT(isCurrentThread()); | |
413 backingThread().initialize(); | |
414 } | |
415 | |
416 void WorkerThread::shutdownBackingThread() | |
417 { | |
418 ASSERT(isCurrentThread()); | |
419 backingThread().shutdown(); | |
420 } | |
421 | |
422 v8::Isolate* WorkerThread::initializeIsolate() | 408 v8::Isolate* WorkerThread::initializeIsolate() |
423 { | 409 { |
424 ASSERT(isCurrentThread()); | 410 ASSERT(isCurrentThread()); |
425 ASSERT(!m_isolate); | 411 ASSERT(!m_isolate); |
426 v8::Isolate* isolate = V8PerIsolateData::initialize(); | 412 v8::Isolate* isolate = V8PerIsolateData::initialize(); |
427 V8Initializer::initializeWorker(isolate); | 413 V8Initializer::initializeWorker(isolate); |
428 | 414 |
429 m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate)); | 415 m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate)); |
430 ThreadState::current()->addInterruptor(m_interruptor.get()); | 416 ThreadState::current()->addInterruptor(m_interruptor.get()); |
431 ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::tr
aceDOMWrappers); | 417 ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::tr
aceDOMWrappers); |
432 | 418 |
433 return isolate; | 419 return isolate; |
434 } | 420 } |
435 | 421 |
436 void WorkerThread::willDestroyIsolate() | 422 void WorkerThread::willDestroyIsolate() |
437 { | 423 { |
438 ASSERT(isCurrentThread()); | 424 ASSERT(isCurrentThread()); |
439 ASSERT(m_isolate); | 425 ASSERT(m_isolate); |
440 V8PerIsolateData::willBeDestroyed(m_isolate); | 426 V8PerIsolateData::willBeDestroyed(m_isolate); |
441 ThreadState::current()->removeInterruptor(m_interruptor.get()); | 427 ThreadState::current()->removeInterruptor(m_interruptor.get()); |
442 } | 428 } |
443 | 429 |
444 void WorkerThread::destroyIsolate() | 430 void WorkerThread::destroyIsolate() |
445 { | 431 { |
446 ASSERT(isCurrentThread()); | 432 ASSERT(isCurrentThread()); |
447 V8PerIsolateData::destroy(m_isolate); | 433 V8PerIsolateData::destroy(m_isolate); |
| 434 m_isolate = nullptr; |
448 } | 435 } |
449 | 436 |
450 void WorkerThread::terminateV8Execution() | 437 void WorkerThread::terminateV8Execution() |
451 { | 438 { |
452 ASSERT(isMainThread()); | 439 ASSERT(isMainThread()); |
| 440 m_workerGlobalScope->script()->willScheduleExecutionTermination(); |
453 v8::V8::TerminateExecution(m_isolate); | 441 v8::V8::TerminateExecution(m_isolate); |
454 } | 442 } |
455 | 443 |
456 void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task) | 444 void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task) |
457 { | 445 { |
458 m_debuggerMessageQueue.append(task); | 446 m_debuggerMessageQueue.append(task); |
459 } | 447 } |
460 | 448 |
461 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) | 449 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) |
462 { | 450 { |
(...skipping 27 matching lines...) Expand all Loading... |
490 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 478 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
491 } | 479 } |
492 | 480 |
493 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) | 481 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) |
494 { | 482 { |
495 MutexLocker locker(m_workerInspectorControllerMutex); | 483 MutexLocker locker(m_workerInspectorControllerMutex); |
496 m_workerInspectorController = workerInspectorController; | 484 m_workerInspectorController = workerInspectorController; |
497 } | 485 } |
498 | 486 |
499 } // namespace blink | 487 } // namespace blink |
OLD | NEW |