Commit 62542ba1 authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

Ensure MemoryPressureListenerRegistry instance is created on the main thread

MemoryPressureListenerRegistry is a garbage collected object and was
instantiated lazily. This could be a problem when we start a service worker
on the IO thread because blink::scheduler::WorkerThread tries to get the
instance of the registry during worker start up. Since the IO thread runs
without Oilpan and thus can't create garbage collected objects,
MakeGarbageCollected() would fail when the instance hasn't been
instantiated.

This CL ensures the instantiation happens on the main thread. This moves
the instantiation earlier than before but it wouldn't affect overall
performance because it just creates a garbage collected object and
instantiation eventually happens as blink loads resources.

Bug: 988335
Change-Id: I3c2fa3f2be5bd1de913bd916b761548fbff4dda0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1732111Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683478}
parent 7a387c65
......@@ -208,13 +208,14 @@ void Platform::InitializeCommon(Platform* platform,
Thread::SetMainThread(std::move(main_thread));
ProcessHeap::Init();
MemoryPressureListenerRegistry::Initialize();
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
BlinkGCMemoryDumpProvider::Instance(), "BlinkGC",
base::ThreadTaskRunnerHandle::Get());
ThreadState::AttachMainThread();
MemoryPressureListenerRegistry::Initialize();
// font_family_names are used by platform/fonts and are initialized by core.
// In case core is not available (like on PPAPI plugins), we need to init
// them here.
......
......@@ -51,6 +51,10 @@ bool MemoryPressureListenerRegistry::IsCurrentlyLowMemory() {
void MemoryPressureListenerRegistry::Initialize() {
is_low_end_device_ = ::base::SysInfo::IsLowEndDevice();
ApproximatedDeviceMemory::Initialize();
// Make sure the instance of MemoryPressureListenerRegistry is created on
// the main thread. Otherwise we might try to create the instance on a
// thread which doesn't have ThreadState (e.g., the IO thread).
MemoryPressureListenerRegistry::Instance();
}
// static
......
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