Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / gin / isolate_holder.cc
blob3defd7ce9b5d080855302e3a1356b91f6049e521
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gin/public/isolate_holder.h"
7 #include <stdlib.h>
8 #include <string.h>
10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/sys_info.h"
13 #include "gin/debug_impl.h"
14 #include "gin/function_template.h"
15 #include "gin/per_isolate_data.h"
16 #include "gin/run_microtasks_observer.h"
17 #include "gin/v8_initializer.h"
18 #include "gin/v8_isolate_memory_dump_provider.h"
20 namespace gin {
22 namespace {
23 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = nullptr;
24 } // namespace
26 IsolateHolder::IsolateHolder() : IsolateHolder(AccessMode::kSingleThread) {
29 IsolateHolder::IsolateHolder(AccessMode access_mode)
30 : access_mode_(access_mode) {
31 v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
32 CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first";
33 v8::Isolate::CreateParams params;
34 params.entry_hook = DebugImpl::GetFunctionEntryHook();
35 params.code_event_handler = DebugImpl::GetJitCodeEventHandler();
36 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
37 base::SysInfo::AmountOfVirtualMemory());
38 params.array_buffer_allocator = allocator;
39 isolate_ = v8::Isolate::New(params);
40 isolate_data_.reset(new PerIsolateData(isolate_, allocator));
41 isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this));
42 #if defined(OS_WIN)
44 void* code_range;
45 size_t size;
46 isolate_->GetCodeRange(&code_range, &size);
47 Debug::CodeRangeCreatedCallback callback =
48 DebugImpl::GetCodeRangeCreatedCallback();
49 if (code_range && size && callback)
50 callback(code_range, size);
52 #endif
55 IsolateHolder::~IsolateHolder() {
56 if (task_observer_.get())
57 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get());
58 #if defined(OS_WIN)
60 void* code_range;
61 size_t size;
62 isolate_->GetCodeRange(&code_range, &size);
63 Debug::CodeRangeDeletedCallback callback =
64 DebugImpl::GetCodeRangeDeletedCallback();
65 if (code_range && callback)
66 callback(code_range);
68 #endif
69 isolate_memory_dump_provider_.reset();
70 isolate_data_.reset();
71 isolate_->Dispose();
72 isolate_ = NULL;
75 // static
76 void IsolateHolder::Initialize(ScriptMode mode,
77 v8::ArrayBuffer::Allocator* allocator) {
78 CHECK(allocator);
79 V8Initializer::Initialize(mode);
80 g_array_buffer_allocator = allocator;
83 void IsolateHolder::AddRunMicrotasksObserver() {
84 DCHECK(!task_observer_.get());
85 task_observer_.reset(new RunMicrotasksObserver(isolate_));;
86 base::MessageLoop::current()->AddTaskObserver(task_observer_.get());
89 void IsolateHolder::RemoveRunMicrotasksObserver() {
90 DCHECK(task_observer_.get());
91 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get());
92 task_observer_.reset();
95 void IsolateHolder::EnableIdleTasks(
96 scoped_ptr<V8IdleTaskRunner> idle_task_runner) {
97 DCHECK(isolate_data_.get());
98 isolate_data_->EnableIdleTasks(idle_task_runner.Pass());
101 } // namespace gin