Revision: 3344
Author: mikhail.naga...@gmail.com
Date: Mon Nov 23 06:43:00 2009
Log: Store API callback entry address prior to entering a callback.

Callback entry address is stored in VMState and is later retrieved by
profiler stack sampler. This makes possible relating API entry to JS
stack, and this is simpler than trying to unwind native stack.

Review URL: http://codereview.chromium.org/437004
http://code.google.com/p/v8/source/detail?r=3344

Modified:
  /branches/bleeding_edge/src/builtins.cc
  /branches/bleeding_edge/src/log-inl.h
  /branches/bleeding_edge/src/log.cc
  /branches/bleeding_edge/src/log.h
  /branches/bleeding_edge/test/cctest/test-log.cc

=======================================
--- /branches/bleeding_edge/src/builtins.cc     Tue Oct 20 08:26:17 2009
+++ /branches/bleeding_edge/src/builtins.cc     Mon Nov 23 06:43:00 2009
@@ -380,6 +380,9 @@
      {
        // Leaving JavaScript.
        VMState state(EXTERNAL);
+#ifdef ENABLE_LOGGING_AND_PROFILING
+      state.set_external_callback(v8::ToCData<Address>(callback_obj));
+#endif
        value = callback(new_args);
      }
      if (value.IsEmpty()) {
@@ -446,6 +449,9 @@
      {
        // Leaving JavaScript.
        VMState state(EXTERNAL);
+#ifdef ENABLE_LOGGING_AND_PROFILING
+      state.set_external_callback(v8::ToCData<Address>(callback_obj));
+#endif
        value = callback(new_args);
      }
      if (value.IsEmpty()) {
=======================================
--- /branches/bleeding_edge/src/log-inl.h       Wed Sep  9 03:49:40 2009
+++ /branches/bleeding_edge/src/log-inl.h       Mon Nov 23 06:43:00 2009
@@ -55,7 +55,7 @@
    }
  }

-VMState::VMState(StateTag state) : disabled_(true) {
+VMState::VMState(StateTag state) : disabled_(true),  
external_callback_(NULL) {
    if (!Logger::is_logging()) {
      return;
    }
=======================================
--- /branches/bleeding_edge/src/log.cc  Mon Nov 23 01:19:24 2009
+++ /branches/bleeding_edge/src/log.cc  Mon Nov 23 06:43:00 2009
@@ -154,13 +154,19 @@
      sample->frames_count = 0;
      return;
    }
+
+  int i = 0;
+  const Address callback = Logger::current_state_ != NULL ?
+      Logger::current_state_->external_callback() : NULL;
+  if (callback != NULL) {
+    sample->stack[i++] = callback;
+  }

    SafeStackTraceFrameIterator it(
        reinterpret_cast<Address>(sample->fp),
        reinterpret_cast<Address>(sample->sp),
        reinterpret_cast<Address>(sample->sp),
        js_entry_sp);
-  int i = 0;
    while (!it.done() && i < TickSample::kMaxFramesCount) {
      sample->stack[i++] = it.frame()->pc();
      it.Advance();
@@ -683,7 +689,7 @@
    msg.AppendAddress(entry_point);
    SmartPointer<char> str =
        name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
-  msg.Append(",0,\"%s\"", *str);
+  msg.Append(",1,\"%s\"", *str);
    if (FLAG_compress_log) {
      ASSERT(compression_helper_ != NULL);
      if (!compression_helper_->HandleMessage(&msg)) return;
=======================================
--- /branches/bleeding_edge/src/log.h   Mon Nov 23 01:19:24 2009
+++ /branches/bleeding_edge/src/log.h   Mon Nov 23 06:43:00 2009
@@ -91,15 +91,20 @@
  class VMState BASE_EMBEDDED {
  #ifdef ENABLE_LOGGING_AND_PROFILING
   public:
-  inline explicit VMState(StateTag state);
+  inline VMState(StateTag state);
    inline ~VMState();

    StateTag state() { return state_; }
+  Address external_callback() { return external_callback_; }
+  void set_external_callback(Address external_callback) {
+    external_callback_ = external_callback;
+  }

   private:
    bool disabled_;
    StateTag state_;
    VMState* previous_;
+  Address external_callback_;
  #else
   public:
    explicit VMState(StateTag state) {}
@@ -333,6 +338,7 @@
    friend class TimeLog;
    friend class Profiler;
    friend class SlidingStateWindow;
+  friend class StackTracer;
    friend class VMState;

    friend class LoggerTestHelper;
=======================================
--- /branches/bleeding_edge/test/cctest/test-log.cc     Mon Nov 23 01:19:24 2009
+++ /branches/bleeding_edge/test/cctest/test-log.cc     Mon Nov 23 06:43:00 2009
@@ -524,7 +524,7 @@
    pos += strlen(callback_rec);
    EmbeddedVector<char, 100> ref_data;
    i::OS::SNPrintF(ref_data,
-                  "0x%" V8PRIxPTR ",0,\"method1\"", ObjMethod1);
+                  "0x%" V8PRIxPTR ",1,\"method1\"", ObjMethod1);
    *(pos + strlen(ref_data.start())) = '\0';
    CHECK_EQ(ref_data.start(), pos);


--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to