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 {
DedicatedWorkerThreadForTest(DedicatedWorkerObjectProxy& worker_object_proxy)
: DedicatedWorkerThread(nullptr /* ThreadableLoadingContext */,
worker_object_proxy) {
worker_backing_thread_ = WorkerBackingThread::CreateForTest(
worker_backing_thread_ = WorkerBackingThread::Create(
WebThreadCreationParams(WebThreadType::kTestThread));
}
......
......@@ -23,22 +23,14 @@
namespace blink {
// Wrapper functions defined in WebKit.h
void MemoryPressureNotificationToWorkerThreadIsolates(
v8::MemoryPressureLevel level) {
WorkerBackingThread::MemoryPressureNotificationToWorkerThreadIsolates(level);
}
void SetRAILModeOnWorkerThreadIsolates(v8::RAILMode rail_mode) {
WorkerBackingThread::SetRAILModeOnWorkerThreadIsolates(rail_mode);
}
namespace {
static Mutex& IsolatesMutex() {
Mutex& IsolatesMutex() {
DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, ());
return mutex;
}
static HashSet<v8::Isolate*>& Isolates() {
HashSet<v8::Isolate*>& Isolates() {
#if DCHECK_IS_ON()
DCHECK(IsolatesMutex().Locked());
#endif
......@@ -46,27 +38,35 @@ static HashSet<v8::Isolate*>& Isolates() {
return isolates;
}
static void AddWorkerIsolate(v8::Isolate* isolate) {
void AddWorkerIsolate(v8::Isolate* isolate) {
MutexLocker lock(IsolatesMutex());
Isolates().insert(isolate);
}
static void RemoveWorkerIsolate(v8::Isolate* isolate) {
void RemoveWorkerIsolate(v8::Isolate* isolate) {
MutexLocker lock(IsolatesMutex());
Isolates().erase(isolate);
}
WorkerBackingThread::WorkerBackingThread(const WebThreadCreationParams& params,
bool should_call_gc_on_shutdown)
} // namespace
// 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)),
is_owning_thread_(true),
should_call_gc_on_shutdown_(should_call_gc_on_shutdown) {}
is_owning_thread_(true) {}
WorkerBackingThread::WorkerBackingThread(WebThread* thread,
bool should_call_gc_on_shutdown)
WorkerBackingThread::WorkerBackingThread(WebThread* thread)
: backing_thread_(WebThreadSupportingGC::CreateForThread(thread)),
is_owning_thread_(false),
should_call_gc_on_shutdown_(should_call_gc_on_shutdown) {}
is_owning_thread_(false) {}
WorkerBackingThread::~WorkerBackingThread() = default;
......@@ -116,11 +116,6 @@ void WorkerBackingThread::ShutdownOnBackingThread() {
V8PerIsolateData::WillBeDestroyed(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();
RemoveWorkerIsolate(isolate_);
......
......@@ -28,20 +28,10 @@ class CORE_EXPORT WorkerBackingThread final {
public:
static std::unique_ptr<WorkerBackingThread> Create(
const WebThreadCreationParams& params) {
return base::WrapUnique(new WorkerBackingThread(params, false));
return base::WrapUnique(new WorkerBackingThread(params));
}
static std::unique_ptr<WorkerBackingThread> Create(WebThread* thread) {
return base::WrapUnique(new WorkerBackingThread(thread, false));
}
// 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));
return base::WrapUnique(new WorkerBackingThread(thread));
}
~WorkerBackingThread();
......@@ -66,14 +56,12 @@ class CORE_EXPORT WorkerBackingThread final {
static void SetRAILModeOnWorkerThreadIsolates(v8::RAILMode);
private:
WorkerBackingThread(const WebThreadCreationParams&,
bool should_call_gc_on_shutdown);
WorkerBackingThread(WebThread*, bool should_call_gc_on_s_hutdown);
explicit WorkerBackingThread(const WebThreadCreationParams&);
explicit WorkerBackingThread(WebThread*);
std::unique_ptr<WebThreadSupportingGC> backing_thread_;
v8::Isolate* isolate_ = nullptr;
bool is_owning_thread_;
bool should_call_gc_on_shutdown_;
};
} // namespace blink
......
......@@ -86,7 +86,7 @@ class WorkerThreadForTest : public WorkerThread {
WorkerThreadForTest(ThreadableLoadingContext* loading_context,
WorkerReportingProxy& mock_worker_reporting_proxy)
: WorkerThread(loading_context, mock_worker_reporting_proxy),
worker_backing_thread_(WorkerBackingThread::CreateForTest(
worker_backing_thread_(WorkerBackingThread::Create(
WebThreadCreationParams(WebThreadType::kTestThread))) {}
~WorkerThreadForTest() override = default;
......
......@@ -46,16 +46,14 @@ class WorkletThreadHolder {
MutexLocker locker(HolderInstanceMutex());
DCHECK(!thread_holder_instance_);
thread_holder_instance_ = new WorkletThreadHolder<DerivedWorkletThread>;
thread_holder_instance_->Initialize(
WorkerBackingThread::CreateForTest(params));
thread_holder_instance_->Initialize(WorkerBackingThread::Create(params));
}
static void CreateForTest(WebThread* thread) {
MutexLocker locker(HolderInstanceMutex());
DCHECK(!thread_holder_instance_);
thread_holder_instance_ = new WorkletThreadHolder<DerivedWorkletThread>;
thread_holder_instance_->Initialize(
WorkerBackingThread::CreateForTest(thread));
thread_holder_instance_->Initialize(WorkerBackingThread::Create(thread));
}
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