Commit 04a44287 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

Avoid passing a SingleThreadTaskRunner to V8SharedMemoryDumpProvider

Instead of passing a using base::ThreadTaskRunnerHandle::Get(), which can
fail if it's not set up yet, pass nullptr, which causes it to just run on
a background thread. This is fine for the shared memory API as it is not
tied to any particular Isolate.

Additionally this moves registration into the V8SharedMemoryDumpProvider
constructor which itself is created as a Singleton after the first V8
Isolate is created. This ensures that the shared memory is actually set up
before the first dump is provided.

Bug: v8:7464, 1023644
Change-Id: I18fde2c388c3b4c01191b00b4ec441d6964b473b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1912205
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: default avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715661}
parent ac994c78
......@@ -22,6 +22,7 @@
#include "gin/per_isolate_data.h"
#include "gin/v8_initializer.h"
#include "gin/v8_isolate_memory_dump_provider.h"
#include "gin/v8_shared_memory_dump_provider.h"
namespace gin {
......@@ -84,6 +85,10 @@ IsolateHolder::IsolateHolder(
v8::Isolate::Initialize(isolate_, params);
}
// This will attempt register the shared memory dump provider for every
// IsolateHolder, but only the first registration will have any effect.
gin::V8SharedMemoryDumpProvider::Register();
isolate_memory_dump_provider_.reset(
new V8IsolateMemoryDumpProvider(this, task_runner));
}
......
......@@ -23,12 +23,9 @@
#include "base/strings/sys_string_conversions.h"
#include "base/system/sys_info.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "base/trace_event/memory_dump_manager.h"
#include "build/build_config.h"
#include "gin/gin_features.h"
#include "gin/v8_shared_memory_dump_provider.h"
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
#if defined(OS_ANDROID)
......@@ -273,10 +270,6 @@ void V8Initializer::Initialize(IsolateHolder::ScriptMode mode) {
v8::V8::SetEntropySource(&GenerateEntropy);
v8::V8::Initialize();
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
gin::V8SharedMemoryDumpProvider::Instance(), "V8SharedMemory",
base::ThreadTaskRunnerHandle::Get());
v8_is_initialized = true;
}
......
......@@ -13,11 +13,16 @@
namespace gin {
V8SharedMemoryDumpProvider::V8SharedMemoryDumpProvider() {}
V8SharedMemoryDumpProvider::V8SharedMemoryDumpProvider() {
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
this, "V8SharedMemory", nullptr);
}
// static
V8SharedMemoryDumpProvider* V8SharedMemoryDumpProvider::Instance() {
return base::Singleton<
void V8SharedMemoryDumpProvider::Register() {
// The provider is registered as part of the constructor, so all this does is
// access the singleton causing it to be constructed on the first access.
base::Singleton<
V8SharedMemoryDumpProvider,
base::LeakySingletonTraits<V8SharedMemoryDumpProvider>>::get();
}
......
......@@ -26,7 +26,7 @@ class GIN_EXPORT V8SharedMemoryDumpProvider
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* process_memory_dump) override;
static V8SharedMemoryDumpProvider* Instance();
static void Register();
private:
DISALLOW_COPY_AND_ASSIGN(V8SharedMemoryDumpProvider);
......
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