Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: gin/isolate_holder.cc

Issue 1088683003: Adding v8_isolate_memory_dump_provider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving test fixes to different CL, removing unnecessary casts. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gin/public/isolate_holder.h" 5 #include "gin/public/isolate_holder.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/sys_info.h" 12 #include "base/sys_info.h"
13 #include "gin/debug_impl.h" 13 #include "gin/debug_impl.h"
14 #include "gin/function_template.h" 14 #include "gin/function_template.h"
15 #include "gin/per_isolate_data.h" 15 #include "gin/per_isolate_data.h"
16 #include "gin/run_microtasks_observer.h" 16 #include "gin/run_microtasks_observer.h"
17 #include "gin/v8_initializer.h" 17 #include "gin/v8_initializer.h"
18 #include "gin/v8_isolate_memory_dump_provider.h"
18 19
19 namespace gin { 20 namespace gin {
20 21
21 namespace { 22 namespace {
22 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = nullptr; 23 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = nullptr;
23 } // namespace 24 } // namespace
24 25
25 IsolateHolder::IsolateHolder() : IsolateHolder(AccessMode::kSingleThread) { 26 IsolateHolder::IsolateHolder() : IsolateHolder(AccessMode::kSingleThread) {
26 } 27 }
27 28
28 IsolateHolder::IsolateHolder(AccessMode access_mode) 29 IsolateHolder::IsolateHolder(AccessMode access_mode)
29 : access_mode_(access_mode) { 30 : access_mode_(access_mode) {
30 v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator; 31 v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
31 CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first"; 32 CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first";
32 v8::Isolate::CreateParams params; 33 v8::Isolate::CreateParams params;
33 params.entry_hook = DebugImpl::GetFunctionEntryHook(); 34 params.entry_hook = DebugImpl::GetFunctionEntryHook();
34 params.code_event_handler = DebugImpl::GetJitCodeEventHandler(); 35 params.code_event_handler = DebugImpl::GetJitCodeEventHandler();
35 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(), 36 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
36 base::SysInfo::AmountOfVirtualMemory()); 37 base::SysInfo::AmountOfVirtualMemory());
37 params.array_buffer_allocator = allocator; 38 params.array_buffer_allocator = allocator;
38 isolate_ = v8::Isolate::New(params); 39 isolate_ = v8::Isolate::New(params);
39 isolate_data_.reset(new PerIsolateData(isolate_, allocator)); 40 isolate_data_.reset(new PerIsolateData(isolate_, allocator));
41 isolate_memory_dump_provider_.reset(new V8IsolateMemoryDumpProvider(this));
40 #if defined(OS_WIN) 42 #if defined(OS_WIN)
41 { 43 {
42 void* code_range; 44 void* code_range;
43 size_t size; 45 size_t size;
44 isolate_->GetCodeRange(&code_range, &size); 46 isolate_->GetCodeRange(&code_range, &size);
45 Debug::CodeRangeCreatedCallback callback = 47 Debug::CodeRangeCreatedCallback callback =
46 DebugImpl::GetCodeRangeCreatedCallback(); 48 DebugImpl::GetCodeRangeCreatedCallback();
47 if (code_range && size && callback) 49 if (code_range && size && callback)
48 callback(code_range, size); 50 callback(code_range, size);
49 } 51 }
50 #endif 52 #endif
51 } 53 }
52 54
53 IsolateHolder::~IsolateHolder() { 55 IsolateHolder::~IsolateHolder() {
54 if (task_observer_.get()) 56 if (task_observer_.get())
55 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get()); 57 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get());
56 #if defined(OS_WIN) 58 #if defined(OS_WIN)
57 { 59 {
58 void* code_range; 60 void* code_range;
59 size_t size; 61 size_t size;
60 isolate_->GetCodeRange(&code_range, &size); 62 isolate_->GetCodeRange(&code_range, &size);
61 Debug::CodeRangeDeletedCallback callback = 63 Debug::CodeRangeDeletedCallback callback =
62 DebugImpl::GetCodeRangeDeletedCallback(); 64 DebugImpl::GetCodeRangeDeletedCallback();
63 if (code_range && callback) 65 if (code_range && callback)
64 callback(code_range); 66 callback(code_range);
65 } 67 }
66 #endif 68 #endif
69 isolate_memory_dump_provider_.reset();
67 isolate_data_.reset(); 70 isolate_data_.reset();
68 isolate_->Dispose(); 71 isolate_->Dispose();
69 isolate_ = NULL; 72 isolate_ = NULL;
70 } 73 }
71 74
72 // static 75 // static
73 void IsolateHolder::Initialize(ScriptMode mode, 76 void IsolateHolder::Initialize(ScriptMode mode,
74 v8::ArrayBuffer::Allocator* allocator) { 77 v8::ArrayBuffer::Allocator* allocator) {
75 CHECK(allocator); 78 CHECK(allocator);
76 V8Initializer::Initialize(mode); 79 V8Initializer::Initialize(mode);
77 g_array_buffer_allocator = allocator; 80 g_array_buffer_allocator = allocator;
78 } 81 }
79 82
80 void IsolateHolder::AddRunMicrotasksObserver() { 83 void IsolateHolder::AddRunMicrotasksObserver() {
81 DCHECK(!task_observer_.get()); 84 DCHECK(!task_observer_.get());
82 task_observer_.reset(new RunMicrotasksObserver(isolate_));; 85 task_observer_.reset(new RunMicrotasksObserver(isolate_));;
83 base::MessageLoop::current()->AddTaskObserver(task_observer_.get()); 86 base::MessageLoop::current()->AddTaskObserver(task_observer_.get());
84 } 87 }
85 88
86 void IsolateHolder::RemoveRunMicrotasksObserver() { 89 void IsolateHolder::RemoveRunMicrotasksObserver() {
87 DCHECK(task_observer_.get()); 90 DCHECK(task_observer_.get());
88 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get()); 91 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get());
89 task_observer_.reset(); 92 task_observer_.reset();
90 } 93 }
91 94
92 } // namespace gin 95 } // namespace gin
OLDNEW
« no previous file with comments | « gin/gin.gyp ('k') | gin/public/isolate_holder.h » ('j') | gin/v8_isolate_memory_dump_provider.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698