Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1279)

Unified Diff: Source/core/workers/WorkerThread.cpp

Issue 1158443008: compositor-worker: Share a thread and an isolate for compositor workers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/workers/WorkerThread.cpp
diff --git a/Source/core/workers/WorkerThread.cpp b/Source/core/workers/WorkerThread.cpp
index 883944ff2e4caeac2a8c5b0f951d687984b8da7e..261ed3c9bf5d27c41f1e27569bc7e41136f60702 100644
--- a/Source/core/workers/WorkerThread.cpp
+++ b/Source/core/workers/WorkerThread.cpp
@@ -29,8 +29,6 @@
#include "core/workers/WorkerThread.h"
#include "bindings/core/v8/ScriptSourceCode.h"
-#include "bindings/core/v8/V8GCController.h"
-#include "bindings/core/v8/V8Initializer.h"
#include "core/dom/Microtask.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/inspector/WorkerInspectorController.h"
@@ -256,7 +254,6 @@ WorkerThread::WorkerThread(PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, Work
, m_workerLoaderProxy(workerLoaderProxy)
, m_workerReportingProxy(workerReportingProxy)
, m_webScheduler(nullptr)
- , m_isolate(nullptr)
, m_shutdownEvent(adoptPtr(Platform::current()->createWaitableEvent()))
, m_terminationEvent(adoptPtr(Platform::current()->createWaitableEvent()))
{
@@ -316,9 +313,11 @@ void WorkerThread::initialize(PassOwnPtr<WorkerThreadStartupData> startupData)
m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this));
backingThread().addTaskObserver(m_microtaskRunner.get());
- backingThread().initialize();
+ initializeBackingThread();
- m_isolate = initializeIsolate();
+ // Make sure the isolate is intialized correctly.
+ workerIsolate();
+ ASSERT(isolate());
kinuko 2015/05/31 15:18:24 This part is a bit awkward, if we use the WorkerV8
sadrul 2015/06/01 05:24:10 WorkerIsolateWrapper sounds fairly clear. Done.
m_workerGlobalScope = createWorkerGlobalScope(startupData);
m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.get() ? cachedMetaData->size() : 0);
@@ -358,7 +357,7 @@ void WorkerThread::shutdown()
PlatformThreadData::current().threadTimers().setSharedTimer(nullptr);
workerGlobalScope()->dispose();
- willDestroyIsolate();
+ workerIsolate()->willDestroy();
// This should be called before we start the shutdown procedure.
workerReportingProxy().willDestroyWorkerGlobalScope();
@@ -373,8 +372,8 @@ void WorkerThread::shutdown()
m_workerGlobalScope = nullptr;
backingThread().removeTaskObserver(m_microtaskRunner.get());
- backingThread().shutdown();
- destroyIsolate();
+ shutdownBackingThread();
+ workerIsolate().clear();
m_microtaskRunner = nullptr;
@@ -457,6 +456,21 @@ void WorkerThread::didStopRunLoop()
Platform::current()->didStopWorkerRunLoop();
}
+v8::Isolate* WorkerThread::isolate()
+{
+ return m_shutdown ? nullptr : workerIsolate()->isolate();
+}
+
+void WorkerThread::initializeBackingThread()
+{
+ backingThread().initialize();
+}
+
+void WorkerThread::shutdownBackingThread()
+{
+ backingThread().shutdown();
+}
+
void WorkerThread::terminateAndWaitForAllWorkers()
{
// Keep this lock to prevent WorkerThread instances from being destroyed.
@@ -507,40 +521,11 @@ void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<
backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, task, true).leakPtr(), delayMs);
}
-v8::Isolate* WorkerThread::initializeIsolate()
-{
- ASSERT(isCurrentThread());
- ASSERT(!m_isolate);
- v8::Isolate* isolate = V8PerIsolateData::initialize();
- V8Initializer::initializeWorker(isolate);
-
- m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate));
- ThreadState::current()->addInterruptor(m_interruptor.get());
- ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::traceDOMWrappers);
-
- return isolate;
-}
-
-void WorkerThread::willDestroyIsolate()
-{
- ASSERT(isCurrentThread());
- ASSERT(m_isolate);
- V8PerIsolateData::willBeDestroyed(m_isolate);
- ThreadState::current()->removeInterruptor(m_interruptor.get());
-}
-
-void WorkerThread::destroyIsolate()
-{
- ASSERT(isCurrentThread());
- V8PerIsolateData::destroy(m_isolate);
- m_isolate = nullptr;
-}
-
void WorkerThread::terminateV8Execution()
{
ASSERT(isMainThread());
m_workerGlobalScope->script()->willScheduleExecutionTermination();
- v8::V8::TerminateExecution(m_isolate);
+ workerIsolate()->terminateExecution();
}
void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task)

Powered by Google App Engine
This is Rietveld 408576698