Commit 717584e9 authored by keishi's avatar keishi Committed by Commit bot

LeakDetector should run a GC on the compositor thread

Compositor workers do not own the compositor thread so they do not do a cleanup gc on termination. This means objects will be left uncollected once per thread heap is enabled for compositor workers. To make up for that, the LeakDetector should run a GC on the compositor thread explicitly.

BUG=

Review-Url: https://codereview.chromium.org/2304073002
Cr-Commit-Position: refs/heads/master@{#417574}
parent 3fbddcd5
...@@ -24,10 +24,10 @@ namespace { ...@@ -24,10 +24,10 @@ namespace {
// case. // case.
class BackingThreadHolder { class BackingThreadHolder {
public: public:
static BackingThreadHolder& instance() static BackingThreadHolder* instance()
{ {
MutexLocker locker(holderInstanceMutex()); MutexLocker locker(holderInstanceMutex());
return *s_instance; return s_instance;
} }
static void ensureInstance() static void ensureInstance()
...@@ -112,7 +112,24 @@ AbstractAnimationWorkletThread::~AbstractAnimationWorkletThread() ...@@ -112,7 +112,24 @@ AbstractAnimationWorkletThread::~AbstractAnimationWorkletThread()
WorkerBackingThread& AbstractAnimationWorkletThread::workerBackingThread() WorkerBackingThread& AbstractAnimationWorkletThread::workerBackingThread()
{ {
return *BackingThreadHolder::instance().thread(); return *BackingThreadHolder::instance()->thread();
}
void collectAllGarbageOnThread(WaitableEvent* doneEvent)
{
blink::ThreadState::current()->collectAllGarbage();
doneEvent->signal();
}
void AbstractAnimationWorkletThread::collectAllGarbage()
{
DCHECK(isMainThread());
WaitableEvent doneEvent;
BackingThreadHolder* instance = BackingThreadHolder::instance();
if (!instance)
return;
instance->thread()->backingThread().postTask(BLINK_FROM_HERE, crossThreadBind(&collectAllGarbageOnThread, crossThreadUnretained(&doneEvent)));
doneEvent.wait();
} }
void AbstractAnimationWorkletThread::ensureSharedBackingThread() void AbstractAnimationWorkletThread::ensureSharedBackingThread()
......
...@@ -29,6 +29,8 @@ public: ...@@ -29,6 +29,8 @@ public:
bool shouldAttachThreadDebugger() const override { return false; } bool shouldAttachThreadDebugger() const override { return false; }
static void collectAllGarbage();
static void ensureSharedBackingThread(); static void ensureSharedBackingThread();
static void createSharedBackingThreadForTest(); static void createSharedBackingThreadForTest();
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "core/inspector/InstanceCounters.h" #include "core/inspector/InstanceCounters.h"
#include "core/workers/InProcessWorkerMessagingProxy.h" #include "core/workers/InProcessWorkerMessagingProxy.h"
#include "core/workers/WorkerThread.h" #include "core/workers/WorkerThread.h"
#include "modules/compositorworker/AbstractAnimationWorkletThread.h"
#include "platform/Timer.h" #include "platform/Timer.h"
#include "public/web/WebFrame.h" #include "public/web/WebFrame.h"
#include "web/WebLocalFrameImpl.h" #include "web/WebLocalFrameImpl.h"
...@@ -105,6 +106,7 @@ void WebLeakDetectorImpl::prepareForLeakDetection(WebFrame* frame) ...@@ -105,6 +106,7 @@ void WebLeakDetectorImpl::prepareForLeakDetection(WebFrame* frame)
void WebLeakDetectorImpl::collectGarbageAndReport() void WebLeakDetectorImpl::collectGarbageAndReport()
{ {
V8GCController::collectAllGarbageForTesting(V8PerIsolateData::mainThreadIsolate()); V8GCController::collectAllGarbageForTesting(V8PerIsolateData::mainThreadIsolate());
AbstractAnimationWorkletThread::collectAllGarbage();
// Note: Oilpan precise GC is scheduled at the end of the event loop. // Note: Oilpan precise GC is scheduled at the end of the event loop.
// Task queue may contain delayed object destruction tasks. // Task queue may contain delayed object destruction tasks.
...@@ -122,6 +124,7 @@ void WebLeakDetectorImpl::delayedGCAndReport(TimerBase*) ...@@ -122,6 +124,7 @@ void WebLeakDetectorImpl::delayedGCAndReport(TimerBase*)
// The third GC is necessary for cleaning up Document after worker object died. // The third GC is necessary for cleaning up Document after worker object died.
V8GCController::collectAllGarbageForTesting(V8PerIsolateData::mainThreadIsolate()); V8GCController::collectAllGarbageForTesting(V8PerIsolateData::mainThreadIsolate());
AbstractAnimationWorkletThread::collectAllGarbage();
// Note: Oilpan precise GC is scheduled at the end of the event loop. // Note: Oilpan precise GC is scheduled at the end of the event loop.
// Inspect counters on the next event loop. // Inspect counters on the next event loop.
......
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