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/Task.h" | 39 #include "platform/Task.h" |
42 #include "platform/ThreadSafeFunctional.h" | 40 #include "platform/ThreadSafeFunctional.h" |
43 #include "platform/heap/SafePoint.h" | 41 #include "platform/heap/SafePoint.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 // The worker was terminated before the thread had a chance to run. | 211 // The worker was terminated before the thread had a chance to run. |
214 if (m_terminated) { | 212 if (m_terminated) { |
215 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 213 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
216 // This can free this thread object, hence it must not be touched af terwards. | 214 // This can free this thread object, hence it must not be touched af terwards. |
217 m_workerReportingProxy.workerThreadTerminated(); | 215 m_workerReportingProxy.workerThreadTerminated(); |
218 return; | 216 return; |
219 } | 217 } |
220 | 218 |
221 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this)); | 219 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this)); |
222 backingThread().addTaskObserver(m_microtaskRunner.get()); | 220 backingThread().addTaskObserver(m_microtaskRunner.get()); |
223 backingThread().initialize(); | 221 initializeBackingThread(); |
224 | 222 |
225 m_isolate = initializeIsolate(); | 223 m_isolate = initializeIsolate(); |
226 m_workerGlobalScope = createWorkerGlobalScope(startupData); | 224 m_workerGlobalScope = createWorkerGlobalScope(startupData); |
227 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge t() ? cachedMetaData->size() : 0); | 225 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge t() ? cachedMetaData->size() : 0); |
228 } | 226 } |
229 | 227 |
230 // The corresponding call to stopRunLoop() is in ~WorkerScriptController(). | 228 // The corresponding call to stopRunLoop() is in ~WorkerScriptController(). |
231 didStartRunLoop(); | 229 didStartRunLoop(); |
232 | 230 |
233 // Notify proxy that a new WorkerGlobalScope has been created and started. | 231 // Notify proxy that a new WorkerGlobalScope has been created and started. |
(...skipping 33 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. | 265 // 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. | 266 // 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. | 267 // 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) | 268 #if !ENABLE(OILPAN) |
271 ASSERT(m_workerGlobalScope->hasOneRef()); | 269 ASSERT(m_workerGlobalScope->hasOneRef()); |
272 #endif | 270 #endif |
273 m_workerGlobalScope->notifyContextDestroyed(); | 271 m_workerGlobalScope->notifyContextDestroyed(); |
274 m_workerGlobalScope = nullptr; | 272 m_workerGlobalScope = nullptr; |
275 | 273 |
276 backingThread().removeTaskObserver(m_microtaskRunner.get()); | 274 backingThread().removeTaskObserver(m_microtaskRunner.get()); |
277 backingThread().shutdown(); | 275 shutdownBackingThread(); |
278 destroyIsolate(); | 276 destroyIsolate(); |
279 | 277 |
280 m_microtaskRunner = nullptr; | 278 m_microtaskRunner = nullptr; |
281 | 279 |
282 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 280 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
283 // This can free this thread object, hence it must not be touched afterwards . | 281 // This can free this thread object, hence it must not be touched afterwards . |
284 workerReportingProxy().workerThreadTerminated(); | 282 workerReportingProxy().workerThreadTerminated(); |
285 | 283 |
286 m_terminationEvent->signal(); | 284 m_terminationEvent->signal(); |
287 } | 285 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 ASSERT(isCurrentThread()); | 346 ASSERT(isCurrentThread()); |
349 Platform::current()->didStartWorkerRunLoop(); | 347 Platform::current()->didStartWorkerRunLoop(); |
350 } | 348 } |
351 | 349 |
352 void WorkerThread::didStopRunLoop() | 350 void WorkerThread::didStopRunLoop() |
353 { | 351 { |
354 ASSERT(isCurrentThread()); | 352 ASSERT(isCurrentThread()); |
355 Platform::current()->didStopWorkerRunLoop(); | 353 Platform::current()->didStopWorkerRunLoop(); |
356 } | 354 } |
357 | 355 |
356 void WorkerThread::initializeBackingThread() | |
357 { | |
358 backingThread().initialize(); | |
359 } | |
360 | |
361 void WorkerThread::shutdownBackingThread() | |
362 { | |
363 backingThread().shutdown(); | |
364 } | |
365 | |
358 void WorkerThread::terminateAndWaitForAllWorkers() | 366 void WorkerThread::terminateAndWaitForAllWorkers() |
359 { | 367 { |
360 // Keep this lock to prevent WorkerThread instances from being destroyed. | 368 // Keep this lock to prevent WorkerThread instances from being destroyed. |
361 MutexLocker lock(threadSetMutex()); | 369 MutexLocker lock(threadSetMutex()); |
362 HashSet<WorkerThread*> threads = workerThreads(); | 370 HashSet<WorkerThread*> threads = workerThreads(); |
363 for (WorkerThread* thread : threads) | 371 for (WorkerThread* thread : threads) |
364 thread->stopInShutdownSequence(); | 372 thread->stopInShutdownSequence(); |
365 | 373 |
366 for (WorkerThread* thread : threads) | 374 for (WorkerThread* thread : threads) |
367 thread->terminationEvent()->wait(); | 375 thread->terminationEvent()->wait(); |
(...skipping 30 matching lines...) Expand all Loading... | |
398 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi onContextTask> task) | 406 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi onContextTask> task) |
399 { | 407 { |
400 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru e).leakPtr()); | 408 backingThread().postTask(location, WorkerThreadTask::create(*this, task, tru e).leakPtr()); |
401 } | 409 } |
402 | 410 |
403 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr< ExecutionContextTask> task, long long delayMs) | 411 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr< ExecutionContextTask> task, long long delayMs) |
404 { | 412 { |
405 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta sk, true).leakPtr(), delayMs); | 413 backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, ta sk, true).leakPtr(), delayMs); |
406 } | 414 } |
407 | 415 |
408 v8::Isolate* WorkerThread::initializeIsolate() | 416 PassOwnPtr<WorkerV8Isolate> WorkerThread::initializeIsolate() |
409 { | 417 { |
410 ASSERT(isCurrentThread()); | 418 ASSERT(isCurrentThread()); |
411 ASSERT(!m_isolate); | 419 ASSERT(!m_isolate); |
412 v8::Isolate* isolate = V8PerIsolateData::initialize(); | 420 return WorkerV8Isolate::createDefault(); |
413 V8Initializer::initializeWorker(isolate); | |
414 | |
415 m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate)); | |
416 ThreadState::current()->addInterruptor(m_interruptor.get()); | |
417 ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::tr aceDOMWrappers); | |
418 | |
419 return isolate; | |
420 } | 421 } |
421 | 422 |
422 void WorkerThread::willDestroyIsolate() | 423 void WorkerThread::willDestroyIsolate() |
423 { | 424 { |
424 ASSERT(isCurrentThread()); | 425 ASSERT(isCurrentThread()); |
425 ASSERT(m_isolate); | 426 ASSERT(m_isolate); |
426 V8PerIsolateData::willBeDestroyed(m_isolate); | 427 m_isolate->willDestroy(); |
427 ThreadState::current()->removeInterruptor(m_interruptor.get()); | |
428 } | 428 } |
429 | 429 |
430 void WorkerThread::destroyIsolate() | 430 void WorkerThread::destroyIsolate() |
431 { | 431 { |
432 ASSERT(isCurrentThread()); | 432 ASSERT(isCurrentThread()); |
433 V8PerIsolateData::destroy(m_isolate); | |
434 m_isolate = nullptr; | 433 m_isolate = nullptr; |
kinuko
2015/05/26 14:41:25
nit: m_isolate is now OwnPtr, m_isolate.clear() mi
sadrul
2015/05/27 01:28:00
Done.
| |
435 } | 434 } |
436 | 435 |
437 void WorkerThread::terminateV8Execution() | 436 void WorkerThread::terminateV8Execution() |
438 { | 437 { |
439 ASSERT(isMainThread()); | 438 ASSERT(isMainThread()); |
440 m_workerGlobalScope->script()->willScheduleExecutionTermination(); | 439 m_workerGlobalScope->script()->willScheduleExecutionTermination(); |
441 v8::V8::TerminateExecution(m_isolate); | 440 m_isolate->terminateExecution(); |
442 } | 441 } |
443 | 442 |
444 void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task) | 443 void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task) |
445 { | 444 { |
446 m_debuggerMessageQueue.append(task); | 445 m_debuggerMessageQueue.append(task); |
447 } | 446 } |
448 | 447 |
449 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) | 448 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) |
450 { | 449 { |
451 ASSERT(isCurrentThread()); | 450 ASSERT(isCurrentThread()); |
(...skipping 26 matching lines...) Expand all Loading... | |
478 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 477 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
479 } | 478 } |
480 | 479 |
481 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) | 480 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) |
482 { | 481 { |
483 MutexLocker locker(m_workerInspectorControllerMutex); | 482 MutexLocker locker(m_workerInspectorControllerMutex); |
484 m_workerInspectorController = workerInspectorController; | 483 m_workerInspectorController = workerInspectorController; |
485 } | 484 } |
486 | 485 |
487 } // namespace blink | 486 } // namespace blink |
OLD | NEW |