Commit 02bf53e3 authored by Hitoshi Yoshida's avatar Hitoshi Yoshida Committed by Commit Bot

worker: Remove WorkerBackingThread::CreateForTest()

With works around terminate GC, we no longer need to
run additional GCs at thread termination.
This CL removes such test only behavior and cleans up
code of paths to it.


Bug: 590802
Change-Id: Icf17118744c785a5a6d0f3e8e6101da1cf9ad3bc
Reviewed-on: https://chromium-review.googlesource.com/1088536Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564858}
parent 032a699c
...@@ -32,7 +32,7 @@ class DedicatedWorkerThreadForTest final : public DedicatedWorkerThread { ...@@ -32,7 +32,7 @@ class DedicatedWorkerThreadForTest final : public DedicatedWorkerThread {
DedicatedWorkerThreadForTest(DedicatedWorkerObjectProxy& worker_object_proxy) DedicatedWorkerThreadForTest(DedicatedWorkerObjectProxy& worker_object_proxy)
: DedicatedWorkerThread(nullptr /* ThreadableLoadingContext */, : DedicatedWorkerThread(nullptr /* ThreadableLoadingContext */,
worker_object_proxy) { worker_object_proxy) {
worker_backing_thread_ = WorkerBackingThread::CreateForTest( worker_backing_thread_ = WorkerBackingThread::Create(
WebThreadCreationParams(WebThreadType::kTestThread)); WebThreadCreationParams(WebThreadType::kTestThread));
} }
......
...@@ -23,22 +23,14 @@ ...@@ -23,22 +23,14 @@
namespace blink { namespace blink {
// Wrapper functions defined in WebKit.h namespace {
void MemoryPressureNotificationToWorkerThreadIsolates(
v8::MemoryPressureLevel level) {
WorkerBackingThread::MemoryPressureNotificationToWorkerThreadIsolates(level);
}
void SetRAILModeOnWorkerThreadIsolates(v8::RAILMode rail_mode) {
WorkerBackingThread::SetRAILModeOnWorkerThreadIsolates(rail_mode);
}
static Mutex& IsolatesMutex() { Mutex& IsolatesMutex() {
DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, ()); DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, ());
return mutex; return mutex;
} }
static HashSet<v8::Isolate*>& Isolates() { HashSet<v8::Isolate*>& Isolates() {
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
DCHECK(IsolatesMutex().Locked()); DCHECK(IsolatesMutex().Locked());
#endif #endif
...@@ -46,27 +38,35 @@ static HashSet<v8::Isolate*>& Isolates() { ...@@ -46,27 +38,35 @@ static HashSet<v8::Isolate*>& Isolates() {
return isolates; return isolates;
} }
static void AddWorkerIsolate(v8::Isolate* isolate) { void AddWorkerIsolate(v8::Isolate* isolate) {
MutexLocker lock(IsolatesMutex()); MutexLocker lock(IsolatesMutex());
Isolates().insert(isolate); Isolates().insert(isolate);
} }
static void RemoveWorkerIsolate(v8::Isolate* isolate) { void RemoveWorkerIsolate(v8::Isolate* isolate) {
MutexLocker lock(IsolatesMutex()); MutexLocker lock(IsolatesMutex());
Isolates().erase(isolate); Isolates().erase(isolate);
} }
WorkerBackingThread::WorkerBackingThread(const WebThreadCreationParams& params, } // namespace
bool should_call_gc_on_shutdown)
// Wrapper functions defined in third_party/blink/public/web/blink.h
void MemoryPressureNotificationToWorkerThreadIsolates(
v8::MemoryPressureLevel level) {
WorkerBackingThread::MemoryPressureNotificationToWorkerThreadIsolates(level);
}
void SetRAILModeOnWorkerThreadIsolates(v8::RAILMode rail_mode) {
WorkerBackingThread::SetRAILModeOnWorkerThreadIsolates(rail_mode);
}
WorkerBackingThread::WorkerBackingThread(const WebThreadCreationParams& params)
: backing_thread_(WebThreadSupportingGC::Create(params)), : backing_thread_(WebThreadSupportingGC::Create(params)),
is_owning_thread_(true), is_owning_thread_(true) {}
should_call_gc_on_shutdown_(should_call_gc_on_shutdown) {}
WorkerBackingThread::WorkerBackingThread(WebThread* thread, WorkerBackingThread::WorkerBackingThread(WebThread* thread)
bool should_call_gc_on_shutdown)
: backing_thread_(WebThreadSupportingGC::CreateForThread(thread)), : backing_thread_(WebThreadSupportingGC::CreateForThread(thread)),
is_owning_thread_(false), is_owning_thread_(false) {}
should_call_gc_on_shutdown_(should_call_gc_on_shutdown) {}
WorkerBackingThread::~WorkerBackingThread() = default; WorkerBackingThread::~WorkerBackingThread() = default;
...@@ -116,11 +116,6 @@ void WorkerBackingThread::ShutdownOnBackingThread() { ...@@ -116,11 +116,6 @@ void WorkerBackingThread::ShutdownOnBackingThread() {
V8PerIsolateData::WillBeDestroyed(isolate_); V8PerIsolateData::WillBeDestroyed(isolate_);
V8GCController::ClearDOMWrappers(isolate_); V8GCController::ClearDOMWrappers(isolate_);
// TODO(yhirano): Remove this when https://crbug.com/v8/1428 is fixed.
if (should_call_gc_on_shutdown_) {
// This statement runs only in tests.
V8GCController::CollectAllGarbageForTesting(isolate_);
}
backing_thread_->ShutdownOnThread(); backing_thread_->ShutdownOnThread();
RemoveWorkerIsolate(isolate_); RemoveWorkerIsolate(isolate_);
......
...@@ -28,20 +28,10 @@ class CORE_EXPORT WorkerBackingThread final { ...@@ -28,20 +28,10 @@ class CORE_EXPORT WorkerBackingThread final {
public: public:
static std::unique_ptr<WorkerBackingThread> Create( static std::unique_ptr<WorkerBackingThread> Create(
const WebThreadCreationParams& params) { const WebThreadCreationParams& params) {
return base::WrapUnique(new WorkerBackingThread(params, false)); return base::WrapUnique(new WorkerBackingThread(params));
} }
static std::unique_ptr<WorkerBackingThread> Create(WebThread* thread) { static std::unique_ptr<WorkerBackingThread> Create(WebThread* thread) {
return base::WrapUnique(new WorkerBackingThread(thread, false)); return base::WrapUnique(new WorkerBackingThread(thread));
}
// These are needed to suppress leak reports. See
// https://crbug.com/590802 and https://crbug.com/v8/1428.
static std::unique_ptr<WorkerBackingThread> CreateForTest(
const WebThreadCreationParams& params) {
return base::WrapUnique(new WorkerBackingThread(params, true));
}
static std::unique_ptr<WorkerBackingThread> CreateForTest(WebThread* thread) {
return base::WrapUnique(new WorkerBackingThread(thread, true));
} }
~WorkerBackingThread(); ~WorkerBackingThread();
...@@ -66,14 +56,12 @@ class CORE_EXPORT WorkerBackingThread final { ...@@ -66,14 +56,12 @@ class CORE_EXPORT WorkerBackingThread final {
static void SetRAILModeOnWorkerThreadIsolates(v8::RAILMode); static void SetRAILModeOnWorkerThreadIsolates(v8::RAILMode);
private: private:
WorkerBackingThread(const WebThreadCreationParams&, explicit WorkerBackingThread(const WebThreadCreationParams&);
bool should_call_gc_on_shutdown); explicit WorkerBackingThread(WebThread*);
WorkerBackingThread(WebThread*, bool should_call_gc_on_s_hutdown);
std::unique_ptr<WebThreadSupportingGC> backing_thread_; std::unique_ptr<WebThreadSupportingGC> backing_thread_;
v8::Isolate* isolate_ = nullptr; v8::Isolate* isolate_ = nullptr;
bool is_owning_thread_; bool is_owning_thread_;
bool should_call_gc_on_shutdown_;
}; };
} // namespace blink } // namespace blink
......
...@@ -86,7 +86,7 @@ class WorkerThreadForTest : public WorkerThread { ...@@ -86,7 +86,7 @@ class WorkerThreadForTest : public WorkerThread {
WorkerThreadForTest(ThreadableLoadingContext* loading_context, WorkerThreadForTest(ThreadableLoadingContext* loading_context,
WorkerReportingProxy& mock_worker_reporting_proxy) WorkerReportingProxy& mock_worker_reporting_proxy)
: WorkerThread(loading_context, mock_worker_reporting_proxy), : WorkerThread(loading_context, mock_worker_reporting_proxy),
worker_backing_thread_(WorkerBackingThread::CreateForTest( worker_backing_thread_(WorkerBackingThread::Create(
WebThreadCreationParams(WebThreadType::kTestThread))) {} WebThreadCreationParams(WebThreadType::kTestThread))) {}
~WorkerThreadForTest() override = default; ~WorkerThreadForTest() override = default;
......
...@@ -46,16 +46,14 @@ class WorkletThreadHolder { ...@@ -46,16 +46,14 @@ class WorkletThreadHolder {
MutexLocker locker(HolderInstanceMutex()); MutexLocker locker(HolderInstanceMutex());
DCHECK(!thread_holder_instance_); DCHECK(!thread_holder_instance_);
thread_holder_instance_ = new WorkletThreadHolder<DerivedWorkletThread>; thread_holder_instance_ = new WorkletThreadHolder<DerivedWorkletThread>;
thread_holder_instance_->Initialize( thread_holder_instance_->Initialize(WorkerBackingThread::Create(params));
WorkerBackingThread::CreateForTest(params));
} }
static void CreateForTest(WebThread* thread) { static void CreateForTest(WebThread* thread) {
MutexLocker locker(HolderInstanceMutex()); MutexLocker locker(HolderInstanceMutex());
DCHECK(!thread_holder_instance_); DCHECK(!thread_holder_instance_);
thread_holder_instance_ = new WorkletThreadHolder<DerivedWorkletThread>; thread_holder_instance_ = new WorkletThreadHolder<DerivedWorkletThread>;
thread_holder_instance_->Initialize( thread_holder_instance_->Initialize(WorkerBackingThread::Create(thread));
WorkerBackingThread::CreateForTest(thread));
} }
static void ClearInstance() { static void ClearInstance() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment