From 4879fd2c9e48ddadd001fed382163c26586476ce Mon Sep 17 00:00:00 2001
From: jochen <jochen@chromium.org>
Date: Tue, 16 Sep 2014 08:04:29 -0700
Subject: Move setup of code event handlers to gin

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}
---
 gin/BUILD.gn          |  3 +++
 gin/debug_impl.cc     | 34 ++++++++++++++++++++++++++++++++++
 gin/debug_impl.h      | 21 +++++++++++++++++++++
 gin/gin.gyp           |  3 +++
 gin/isolate_holder.cc |  6 +++++-
 gin/public/debug.h    | 34 ++++++++++++++++++++++++++++++++++
 6 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100644 gin/debug_impl.cc
 create mode 100644 gin/debug_impl.h
 create mode 100644 gin/public/debug.h

(limited to 'gin')

diff --git a/gin/BUILD.gn b/gin/BUILD.gn
index 1baa592..22f631f 100644
--- a/gin/BUILD.gn
+++ b/gin/BUILD.gn
@@ -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",
@@ -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",
diff --git a/gin/debug_impl.cc b/gin/debug_impl.cc
new file mode 100644
index 0000000..87a95fb
--- /dev/null
+++ b/gin/debug_impl.cc
@@ -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
diff --git a/gin/debug_impl.h b/gin/debug_impl.h
new file mode 100644
index 0000000..1fc5e4d
--- /dev/null
+++ b/gin/debug_impl.h
@@ -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_
diff --git a/gin/gin.gyp b/gin/gin.gyp
index 8b716fc..caa2ba4 100644
--- a/gin/gin.gyp
+++ b/gin/gin.gyp
@@ -31,6 +31,8 @@
         'context_holder.cc',
         'converter.cc',
         'converter.h',
+        'debug_impl.cc',
+        'debug_impl.h',
         'dictionary.cc',
         'dictionary.h',
         'function_template.cc',
@@ -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',
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc
index b3d1673..afcb109 100644
--- a/gin/isolate_holder.cc
+++ b/gin/isolate_holder.cc
@@ -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"
@@ -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(),
diff --git a/gin/public/debug.h b/gin/public/debug.h
new file mode 100644
index 0000000..f668b82
--- /dev/null
+++ b/gin/public/debug.h
@@ -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_
-- 
cgit v1.1