Skip to content

Commit

Permalink
Move setup of code event handlers to gin
Browse files Browse the repository at this point in the history
This will make sure that the handlers are set at the correct point
during v8::Isolate construction

BUG=none
R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/567343002

Cr-Commit-Position: refs/heads/master@{#295066}
  • Loading branch information
jeisinger authored and Commit bot committed Sep 16, 2014
1 parent a45fa21 commit 4879fd2
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 7 deletions.
1 change: 1 addition & 0 deletions chrome/common/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include_rules = [
"+components/signin/core/common",
"+components/translate/core/common",
"+extensions/common",
"+gin/public", # For profiling.cc
"+google_apis/gaia", # For gaia_switches.h
"+grit", # For generated headers. TODO(thestig): Remove.
"+media",
Expand Down
10 changes: 4 additions & 6 deletions chrome/common/profiling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/strings/string_util.h"
#include "base/threading/thread.h"
#include "chrome/common/chrome_switches.h"
#include "gin/public/debug.h"
#include "v8/include/v8.h"

namespace {
Expand Down Expand Up @@ -146,14 +147,11 @@ void Profiling::ProcessStarted() {
add_dynamic_symbol_func = base::debug::GetProfilerAddDynamicSymbolFunc();
move_dynamic_symbol_func = base::debug::GetProfilerMoveDynamicSymbolFunc();

v8::Isolate* isolate = v8::Isolate::GetCurrent();
if (isolate != NULL &&
entry_hook_func != NULL &&
if (entry_hook_func != NULL &&
add_dynamic_symbol_func != NULL &&
move_dynamic_symbol_func != NULL) {
v8::V8::SetFunctionEntryHook(isolate, entry_hook_func);
v8::V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault,
&JitCodeEventHandler);
gin::Debug::SetFunctionEntryHook(entry_hook_func);
gin::Debug::SetJitCodeEventHandler(&JitCodeEventHandler);
}
}

Expand Down
3 changes: 3 additions & 0 deletions gin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ component("gin") {
"context_holder.cc",
"converter.cc",
"converter.h",
"debug_impl.cc",
"debug_impl.h",
"dictionary.cc",
"dictionary.h",
"function_template.cc",
Expand Down Expand Up @@ -38,6 +40,7 @@ component("gin") {
"per_isolate_data.cc",
"per_isolate_data.h",
"public/context_holder.h",
"public/debug.h",
"public/gin_embedders.h",
"public/isolate_holder.h",
"public/v8_platform.h",
Expand Down
34 changes: 34 additions & 0 deletions gin/debug_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gin/debug_impl.h"

namespace gin {

namespace {
v8::FunctionEntryHook g_entry_hook = NULL;
v8::JitCodeEventHandler g_jit_code_event_handler = NULL;
} // namespace

// static
void Debug::SetFunctionEntryHook(v8::FunctionEntryHook entry_hook) {
g_entry_hook = entry_hook;
}

// static
void Debug::SetJitCodeEventHandler(v8::JitCodeEventHandler event_handler) {
g_jit_code_event_handler = event_handler;
}

// static
v8::FunctionEntryHook DebugImpl::GetFunctionEntryHook() {
return g_entry_hook;
}

// static
v8::JitCodeEventHandler DebugImpl::GetJitCodeEventHandler() {
return g_jit_code_event_handler;
}

} // namespace gin
21 changes: 21 additions & 0 deletions gin/debug_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GIN_PUBLIC_DEBUG_IMPL_H_
#define GIN_PUBLIC_DEBUG_IMPL_H_

#include "gin/public/debug.h"
#include "v8/include/v8.h"

namespace gin {

class DebugImpl {
public:
static v8::FunctionEntryHook GetFunctionEntryHook();
static v8::JitCodeEventHandler GetJitCodeEventHandler();
};

} // namespace gin

#endif // GIN_PUBLIC_DEBUG_IMPL_H_
3 changes: 3 additions & 0 deletions gin/gin.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
'context_holder.cc',
'converter.cc',
'converter.h',
'debug_impl.cc',
'debug_impl.h',
'dictionary.cc',
'dictionary.h',
'function_template.cc',
Expand Down Expand Up @@ -58,6 +60,7 @@
'per_isolate_data.cc',
'per_isolate_data.h',
'public/context_holder.h',
'public/debug.h',
'public/gin_embedders.h',
'public/isolate_holder.h',
'public/v8_platform.h',
Expand Down
6 changes: 5 additions & 1 deletion gin/isolate_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/rand_util.h"
#include "base/sys_info.h"
#include "gin/array_buffer.h"
#include "gin/debug_impl.h"
#include "gin/function_template.h"
#include "gin/per_isolate_data.h"
#include "gin/public/v8_platform.h"
Expand All @@ -31,7 +32,10 @@ bool GenerateEntropy(unsigned char* buffer, size_t amount) {
IsolateHolder::IsolateHolder() {
CHECK(g_array_buffer_allocator)
<< "You need to invoke gin::IsolateHolder::Initialize first";
isolate_ = v8::Isolate::New();
v8::Isolate::CreateParams params;
params.entry_hook = DebugImpl::GetFunctionEntryHook();
params.code_event_handler = DebugImpl::GetJitCodeEventHandler();
isolate_ = v8::Isolate::New(params);
v8::ResourceConstraints constraints;
constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
base::SysInfo::AmountOfVirtualMemory(),
Expand Down
34 changes: 34 additions & 0 deletions gin/public/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GIN_PUBLIC_DEBUG_H_
#define GIN_PUBLIC_DEBUG_H_

#include "gin/gin_export.h"
#include "v8/include/v8.h"

namespace gin {

class GIN_EXPORT Debug {
public:
/* Installs a callback that is invoked on entry to every V8-generated
* function.
*
* This only affects IsolateHolder instances created after
* SetFunctionEntryHook was invoked.
*/
static void SetFunctionEntryHook(v8::FunctionEntryHook entry_hook);

/* Installs a callback that is invoked each time jit code is added, moved,
* or removed.
*
* This only affects IsolateHolder instances created after
* SetJitCodeEventHandler was invoked.
*/
static void SetJitCodeEventHandler(v8::JitCodeEventHandler event_handler);
};

} // namespace gin

#endif // GIN_PUBLIC_DEBUG_H_

0 comments on commit 4879fd2

Please sign in to comment.