Skip to content

Commit

Permalink
Make IsolateHolder aware of the isolate type.
Browse files Browse the repository at this point in the history
This introduces four isolate types (main, worker, utility, test) and
stores the isolate type in IsolateHolder.

V8's memory dump provider will group memory dumps by the isolate type,
which is necessary for UMA/UKM reporting of V8's memory metrics.

Bug: chromium:852415
Change-Id: Id9a31404e6bc62562545518aaa4e35cae00a97d6
Reviewed-on: https://chromium-review.googlesource.com/1183194
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585480}
  • Loading branch information
ulan authored and Commit Bot committed Aug 23, 2018
1 parent 834a212 commit 51945ab
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 21 deletions.
5 changes: 3 additions & 2 deletions extensions/renderer/bindings/api_binding_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ void APIBindingTest::SetUp() {
gin::IsolateHolder::kStableV8Extras,
gin::ArrayBufferAllocator::SharedInstance());

isolate_holder_ =
std::make_unique<gin::IsolateHolder>(base::ThreadTaskRunnerHandle::Get());
isolate_holder_ = std::make_unique<gin::IsolateHolder>(
base::ThreadTaskRunnerHandle::Get(),
gin::IsolateHolder::IsolateType::kTest);
isolate()->Enter();

v8::HandleScope handle_scope(isolate());
Expand Down
14 changes: 10 additions & 4 deletions gin/isolate_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,29 @@ const intptr_t* g_reference_table = nullptr;
} // namespace

IsolateHolder::IsolateHolder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: IsolateHolder(std::move(task_runner), AccessMode::kSingleThread) {}
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
IsolateType isolate_type)
: IsolateHolder(std::move(task_runner),
AccessMode::kSingleThread,
isolate_type) {}

IsolateHolder::IsolateHolder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
AccessMode access_mode)
AccessMode access_mode,
IsolateType isolate_type)
: IsolateHolder(std::move(task_runner),
access_mode,
kAllowAtomicsWait,
isolate_type,
IsolateCreationMode::kNormal) {}

IsolateHolder::IsolateHolder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
AccessMode access_mode,
AllowAtomicsWaitMode atomics_wait_mode,
IsolateType isolate_type,
IsolateCreationMode isolate_creation_mode)
: access_mode_(access_mode) {
: access_mode_(access_mode), isolate_type_(isolate_type) {
DCHECK(task_runner);
DCHECK(task_runner->BelongsToCurrentThread());

Expand Down
23 changes: 20 additions & 3 deletions gin/public/isolate_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,28 @@ class GIN_EXPORT IsolateHolder {
kCreateSnapshot,
};

explicit IsolateHolder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
// Isolate type used for UMA/UKM reporting:
// - kBlinkMainThread: the main isolate of Blink.
// - kBlinkWorkerThread: the isolate of a Blink worker.
// - kTest: used only in tests.
// - kUtility: the isolate of PDFium and ProxyResolver.
enum class IsolateType {
kBlinkMainThread,
kBlinkWorkerThread,
kTest,
kUtility
};

IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
AccessMode access_mode);
IsolateType isolate_type);
IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
AccessMode access_mode,
IsolateType isolate_type);
IsolateHolder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
AccessMode access_mode,
AllowAtomicsWaitMode atomics_wait_mode,
IsolateType isolate_type,
IsolateCreationMode isolate_creation_mode = IsolateCreationMode::kNormal);
~IsolateHolder();

Expand All @@ -90,6 +104,8 @@ class GIN_EXPORT IsolateHolder {
// This method returns if v8::Locker is needed to access isolate.
AccessMode access_mode() const { return access_mode_; }

IsolateType isolate_type() const { return isolate_type_; }

v8::SnapshotCreator* snapshot_creator() const {
return snapshot_creator_.get();
}
Expand All @@ -111,6 +127,7 @@ class GIN_EXPORT IsolateHolder {
std::unique_ptr<PerIsolateData> isolate_data_;
std::unique_ptr<V8IsolateMemoryDumpProvider> isolate_memory_dump_provider_;
AccessMode access_mode_;
IsolateType isolate_type_;

DISALLOW_COPY_AND_ASSIGN(IsolateHolder);
};
Expand Down
4 changes: 3 additions & 1 deletion gin/shell/gin_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ int main(int argc, char** argv) {
gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode,
gin::IsolateHolder::kStableV8Extras,
gin::ArrayBufferAllocator::SharedInstance());
gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get());
gin::IsolateHolder instance(
base::ThreadTaskRunnerHandle::Get(),
gin::IsolateHolder::IsolateType::kBlinkMainThread);

gin::GinShellRunnerDelegate delegate;
gin::ShellRunner runner(&delegate, instance.isolate());
Expand Down
3 changes: 2 additions & 1 deletion gin/shell_runner_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ TEST(RunnerTest, Run) {
gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode,
gin::IsolateHolder::kStableV8Extras,
gin::ArrayBufferAllocator::SharedInstance());
gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get());
gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get(),
gin::IsolateHolder::IsolateType::kTest);

ShellRunnerDelegate delegate;
Isolate* isolate = instance.isolate();
Expand Down
4 changes: 3 additions & 1 deletion gin/test/v8_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ void V8Test::SetUp() {
gin::IsolateHolder::kStableV8Extras,
gin::ArrayBufferAllocator::SharedInstance());

instance_.reset(new gin::IsolateHolder(base::ThreadTaskRunnerHandle::Get()));
instance_.reset(new gin::IsolateHolder(
base::ThreadTaskRunnerHandle::Get(),
gin::IsolateHolder::IsolateType::kBlinkMainThread));
instance_->isolate()->Enter();
HandleScope handle_scope(instance_->isolate());
context_.Reset(instance_->isolate(), Context::New(instance_->isolate()));
Expand Down
5 changes: 3 additions & 2 deletions net/proxy_resolution/proxy_resolver_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,9 @@ class SharedIsolateFactory {
has_initialized_v8_ = true;
}

holder_.reset(new gin::IsolateHolder(base::ThreadTaskRunnerHandle::Get(),
gin::IsolateHolder::kUseLocker));
holder_.reset(new gin::IsolateHolder(
base::ThreadTaskRunnerHandle::Get(), gin::IsolateHolder::kUseLocker,
gin::IsolateHolder::IsolateType::kUtility));
}

return holder_->isolate();
Expand Down
5 changes: 3 additions & 2 deletions pdf/pdfium/pdfium_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,9 @@ void SetUpV8() {
gin::IsolateHolder::kStableV8Extras,
gin::ArrayBufferAllocator::SharedInstance());
DCHECK(!g_isolate_holder);
g_isolate_holder = new gin::IsolateHolder(base::ThreadTaskRunnerHandle::Get(),
gin::IsolateHolder::kSingleThread);
g_isolate_holder = new gin::IsolateHolder(
base::ThreadTaskRunnerHandle::Get(), gin::IsolateHolder::kSingleThread,
gin::IsolateHolder::IsolateType::kUtility);
g_isolate_holder->isolate()->Enter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ void DataConsumerHandleTestUtil::Thread::Initialize() {
DCHECK(thread_->IsCurrentThread());
if (initialization_policy_ >= kScriptExecution) {
isolate_holder_ = std::make_unique<gin::IsolateHolder>(
scheduler::GetSingleThreadTaskRunnerForTesting());
scheduler::GetSingleThreadTaskRunnerForTesting(),
gin::IsolateHolder::IsolateType::kTest);
GetIsolate()->Enter();
}
thread_->InitializeOnThread();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ V8PerIsolateData::V8PerIsolateData(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
V8ContextSnapshotMode v8_context_snapshot_mode)
: v8_context_snapshot_mode_(v8_context_snapshot_mode),
isolate_holder_(task_runner,
gin::IsolateHolder::kSingleThread,
IsMainThread() ? gin::IsolateHolder::kDisallowAtomicsWait
: gin::IsolateHolder::kAllowAtomicsWait),
isolate_holder_(
task_runner,
gin::IsolateHolder::kSingleThread,
IsMainThread() ? gin::IsolateHolder::kDisallowAtomicsWait
: gin::IsolateHolder::kAllowAtomicsWait,
IsMainThread() ? gin::IsolateHolder::IsolateType::kBlinkMainThread
: gin::IsolateHolder::IsolateType::kBlinkWorkerThread),
interface_template_map_for_v8_context_snapshot_(GetIsolate()),
string_cache_(std::make_unique<StringCache>(GetIsolate())),
private_property_(V8PrivateProperty::Create()),
Expand All @@ -94,6 +97,7 @@ V8PerIsolateData::V8PerIsolateData()
isolate_holder_(Platform::Current()->MainThread()->GetTaskRunner(),
gin::IsolateHolder::kSingleThread,
gin::IsolateHolder::kAllowAtomicsWait,
gin::IsolateHolder::IsolateType::kBlinkMainThread,
gin::IsolateHolder::IsolateCreationMode::kCreateSnapshot),
interface_template_map_for_v8_context_snapshot_(GetIsolate()),
string_cache_(std::make_unique<StringCache>(GetIsolate())),
Expand Down
7 changes: 7 additions & 0 deletions third_party/blink/tools/audit_non_blink_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@
'detail::.+',
],
},
{
'paths': ['third_party/blink/renderer/core/fetch/data_consumer_handle_test_util.cc'],
'allowed': [
# The existing code already contains gin::IsolateHolder.
'gin::IsolateHolder',
],
},
{
'paths': ['third_party/blink/renderer/core/paint'],
'allowed': [
Expand Down

0 comments on commit 51945ab

Please sign in to comment.