cros: Remove some dead code.
[chromium-blink-merge.git] / gin / isolate_holder.cc
blob656ce09f51a14330fe46aaabb63b6a7b0b86a7ff
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 } // namespace gin