Make VM state tracking to be independent of logging and profiling.
authormikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 8 Apr 2010 13:37:39 +0000 (13:37 +0000)
committermikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 8 Apr 2010 13:37:39 +0000 (13:37 +0000)
Also pull out VMState into its own set of source files.

Review URL: http://codereview.chromium.org/1519027

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4361 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

22 files changed:
SConstruct
src/SConscript
src/api.cc
src/log-inl.h
src/log.cc
src/log.h
src/platform-freebsd.cc
src/platform-linux.cc
src/platform-macos.cc
src/platform-openbsd.cc
src/platform-solaris.cc
src/platform-win32.cc
src/spaces.h
src/v8.h
src/vm-state-inl.h [new file with mode: 0644]
src/vm-state.cc [new file with mode: 0644]
src/vm-state.h [new file with mode: 0644]
tools/gyp/v8.gyp
tools/v8.xcodeproj/project.pbxproj
tools/visual_studio/v8_base.vcproj
tools/visual_studio/v8_base_arm.vcproj
tools/visual_studio/v8_base_x64.vcproj

index 14f2cc4f7ffa22098dfd0248cb0226d317c452de..b81efcb4b3dd5d6049f97c134d272b353d6413c2 100644 (file)
@@ -102,8 +102,14 @@ LIBRARY_FLAGS = {
     'mode:debug': {
       'CPPDEFINES': ['V8_ENABLE_CHECKS']
     },
+    'vmstate:on': {
+      'CPPDEFINES':   ['ENABLE_VMSTATE_TRACKING'],
+    },
+    'protectheap:on': {
+      'CPPDEFINES':   ['ENABLE_VMSTATE_TRACKING', 'ENABLE_HEAP_PROTECTION'],
+    },
     'profilingsupport:on': {
-      'CPPDEFINES':   ['ENABLE_LOGGING_AND_PROFILING'],
+      'CPPDEFINES':   ['ENABLE_VMSTATE_TRACKING', 'ENABLE_LOGGING_AND_PROFILING'],
     },
     'cppprofilesprocessor:on': {
       'CPPDEFINES':   ['ENABLE_CPP_PROFILES_PROCESSOR'],
@@ -672,6 +678,16 @@ SIMPLE_OPTIONS = {
     'default': 'static',
     'help': 'the type of library to produce'
   },
+  'vmstate': {
+    'values': ['on', 'off'],
+    'default': 'off',
+    'help': 'enable VM state tracking'
+  },
+  'protectheap': {
+    'values': ['on', 'off'],
+    'default': 'off',
+    'help': 'enable heap protection'
+  },
   'profilingsupport': {
     'values': ['on', 'off'],
     'default': 'on',
index 1f1c1c183399c4e0f11675aeec6da8fcc4a51245..3eaa6cb456b0a90aaa7b017221488bfd539eb5c3 100755 (executable)
@@ -111,6 +111,7 @@ SOURCES = {
     variables.cc
     version.cc
     virtual-frame.cc
+    vm-state.cc
     zone.cc
     """),
   'arch:arm': Split("""
index 0c1861f7fda4ba0d64703be8bc79e94f7c95d0d5..0145db67b5e0852132bf3bc5dfcefed3476bbf40 100644 (file)
@@ -2861,6 +2861,7 @@ void v8::Object::SetInternalField(int index, v8::Handle<Value> value) {
 
 
 void v8::Object::SetPointerInInternalField(int index, void* value) {
+  ENTER_V8;
   i::Object* as_object = reinterpret_cast<i::Object*>(value);
   if (as_object->IsSmi()) {
     Utils::OpenHandle(this)->SetInternalField(index, as_object);
@@ -3425,6 +3426,7 @@ Local<Object> Array::CloneElementAt(uint32_t index) {
   }
   i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon));
   EXCEPTION_PREAMBLE();
+  ENTER_V8;
   i::Handle<i::JSObject> result = i::Copy(paragon_handle);
   has_pending_exception = result.is_null();
   EXCEPTION_BAILOUT_CHECK(Local<Object>());
index e71b667d16087d21d5c77f4a0140d24973cf7ff4..f8242e1382d480a689e5100699bbf839051c43e6 100644 (file)
 namespace v8 {
 namespace internal {
 
-//
-// VMState class implementation.  A simple stack of VM states held by the
-// logger and partially threaded through the call stack.  States are pushed by
-// VMState construction and popped by destruction.
-//
 #ifdef ENABLE_LOGGING_AND_PROFILING
-inline const char* StateToString(StateTag state) {
-  switch (state) {
-    case JS:
-      return "JS";
-    case GC:
-      return "GC";
-    case COMPILER:
-      return "COMPILER";
-    case OTHER:
-      return "OTHER";
-    default:
-      UNREACHABLE();
-      return NULL;
-  }
-}
-
-VMState::VMState(StateTag state)
-    : disabled_(true),
-      state_(OTHER),
-      external_callback_(NULL) {
-  if (!Logger::is_logging() && !CpuProfiler::is_profiling()) {
-    return;
-}
-
-  disabled_ = false;
-#if !defined(ENABLE_HEAP_PROTECTION)
-  // When not protecting the heap, there is no difference between
-  // EXTERNAL and OTHER.  As an optimization in that case, we will not
-  // perform EXTERNAL->OTHER transitions through the API.  We thus
-  // compress the two states into one.
-  if (state == EXTERNAL) state = OTHER;
-#endif
-  state_ = state;
-  previous_ = Logger::current_state_;
-  Logger::current_state_ = this;
-
-  if (FLAG_log_state_changes) {
-    LOG(UncheckedStringEvent("Entering", StateToString(state_)));
-    if (previous_ != NULL) {
-      LOG(UncheckedStringEvent("From", StateToString(previous_->state_)));
-    }
-  }
-
-#ifdef ENABLE_HEAP_PROTECTION
-  if (FLAG_protect_heap && previous_ != NULL) {
-    if (state_ == EXTERNAL) {
-      // We are leaving V8.
-      ASSERT(previous_->state_ != EXTERNAL);
-      Heap::Protect();
-    } else if (previous_->state_ == EXTERNAL) {
-      // We are entering V8.
-      Heap::Unprotect();
-    }
-  }
-#endif
-}
-
-
-VMState::~VMState() {
-  if (disabled_) return;
-  Logger::current_state_ = previous_;
-
-  if (FLAG_log_state_changes) {
-    LOG(UncheckedStringEvent("Leaving", StateToString(state_)));
-    if (previous_ != NULL) {
-      LOG(UncheckedStringEvent("To", StateToString(previous_->state_)));
-    }
-  }
-
-#ifdef ENABLE_HEAP_PROTECTION
-  if (FLAG_protect_heap && previous_ != NULL) {
-    if (state_ == EXTERNAL) {
-      // We are reentering V8.
-      ASSERT(previous_->state_ != EXTERNAL);
-      Heap::Unprotect();
-    } else if (previous_->state_ == EXTERNAL) {
-      // We are leaving V8.
-      Heap::Protect();
-    }
-  }
-#endif
-}
 
 Logger::LogEventsAndTags Logger::ToNativeByScript(Logger::LogEventsAndTags tag,
                                                   Script* script) {
@@ -139,10 +52,10 @@ Logger::LogEventsAndTags Logger::ToNativeByScript(Logger::LogEventsAndTags tag,
   }
 #else
   return tag;
-#endif
+#endif  // ENABLE_CPP_PROFILES_PROCESSOR
 }
 
-#endif
+#endif  // ENABLE_LOGGING_AND_PROFILING
 
 
 } }  // namespace v8::internal
index 2d16044e9d7156bde50ec25fa98a76d7acb4ecd8..8aefe989573fa325d7178afbf1a2aa69ab0ba7b4 100644 (file)
@@ -162,8 +162,7 @@ void StackTracer::Trace(TickSample* sample) {
   }
 
   int i = 0;
-  const Address callback = Logger::current_state_ != NULL ?
-      Logger::current_state_->external_callback() : NULL;
+  const Address callback = VMState::external_callback();
   if (callback != NULL) {
     sample->stack[i++] = callback;
   }
@@ -327,8 +326,6 @@ void Profiler::Run() {
 //
 Ticker* Logger::ticker_ = NULL;
 Profiler* Logger::profiler_ = NULL;
-VMState* Logger::current_state_ = NULL;
-VMState Logger::bottom_state_(EXTERNAL);
 SlidingStateWindow* Logger::sliding_state_window_ = NULL;
 const char** Logger::log_events_ = NULL;
 CompressionHelper* Logger::compression_helper_ = NULL;
@@ -1481,7 +1478,7 @@ bool Logger::Setup() {
     }
   }
 
-  current_state_ = &bottom_state_;
+  ASSERT(VMState::current_state_ == NULL);  // NULL implies outermost external.
 
   ticker_ = new Ticker(kSamplingIntervalMs);
 
index 846ab67ded081c2ba4e565c7c919b3d5a5612383..fb934038b251cf437f27b20a790b3d212027ef35 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -87,30 +87,6 @@ class CompressionHelper;
 #define LOG(Call) ((void) 0)
 #endif
 
-class VMState BASE_EMBEDDED {
-#ifdef ENABLE_LOGGING_AND_PROFILING
- public:
-  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) {}
-#endif
-};
-
-
 #define LOG_EVENTS_AND_TAGS_LIST(V) \
   V(CODE_CREATION_EVENT,            "code-creation",          "cc")       \
   V(CODE_MOVE_EVENT,                "code-move",              "cm")       \
@@ -264,10 +240,6 @@ class Logger {
   static void LogRuntime(Vector<const char> format, JSArray* args);
 
 #ifdef ENABLE_LOGGING_AND_PROFILING
-  static StateTag state() {
-    return current_state_ ? current_state_->state() : OTHER;
-  }
-
   static bool is_logging() {
     return logging_nesting_ > 0;
   }
@@ -354,12 +326,6 @@ class Logger {
   // of samples.
   static Profiler* profiler_;
 
-  // A stack of VM states.
-  static VMState* current_state_;
-
-  // Singleton bottom or default vm state.
-  static VMState bottom_state_;
-
   // SlidingStateWindow instance keeping a sliding window of the most
   // recent VM states.
   static SlidingStateWindow* sliding_state_window_;
index e5cdd2ee38216951c25052d4b1de660f789c3e2c..67e52ce9479cabd209e347c04cca680299641e28 100644 (file)
@@ -569,7 +569,7 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
   TickSample sample;
 
   // We always sample the VM state.
-  sample.state = Logger::state();
+  sample.state = VMState::current_state();
 
   // If profiling, we extract the current pc and sp.
   if (active_sampler_->IsProfiling()) {
index 78b6eb689e4a1ba7bc40102d227f225c8485dc0f..9bba93b8665c35a26fc6b1b82f54da6323c0bb9c 100644 (file)
@@ -738,7 +738,7 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
 #endif
 
   // We always sample the VM state.
-  sample->state = Logger::state();
+  sample->state = VMState::current_state();
   // If profiling, we extract the current pc and sp.
   if (active_sampler_->IsProfiling()) {
     // Extracting the sample from the context is extremely machine dependent.
index 75e7e830afe9f7fc6eb68c13471b1bac48268f42..b3ee49e2c9968c6c8b0fd7c9eadfdd96595f4ae4 100644 (file)
@@ -557,7 +557,7 @@ class Sampler::PlatformData : public Malloced {
 #endif  // ENABLE_CPP_PROFILES_PROCESSOR
 
       // We always sample the VM state.
-      sample->state = Logger::state();
+      sample->state = VMState::current_state();
       // If profiling, we record the pc and sp of the profiled thread.
       if (sampler_->IsProfiling()
           && KERN_SUCCESS == thread_suspend(profiled_thread_)) {
index f96e769ca206b53c444cc78582f90508f3c7d7d9..e3ae867e1ad75cdfa3e6a881aab1e15c58046945 100644 (file)
@@ -542,7 +542,7 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
   TickSample sample;
 
   // We always sample the VM state.
-  sample.state = Logger::state();
+  sample.state = VMState::current_state();
 
   active_sampler_->Tick(&sample);
 }
index 85c2c54cf1b2e5b5d2c5a61fe5524aea4c89651b..1fa652d9ee957b15256d2f01ac84dd02937b87c5 100644 (file)
@@ -533,7 +533,7 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
   sample.fp = 0;
 
   // We always sample the VM state.
-  sample.state = Logger::state();
+  sample.state = VMState::current_state();
 
   active_sampler_->Tick(&sample);
 }
index 54eed4a3b54a142590ddf5f06587f22de4890b7e..fcf1f8f18b360ffe451243ea1dddc6b3457937d0 100644 (file)
@@ -1816,7 +1816,7 @@ class Sampler::PlatformData : public Malloced {
 #endif  // ENABLE_CPP_PROFILES_PROCESSOR
 
       // We always sample the VM state.
-      sample->state = Logger::state();
+      sample->state = VMState::current_state();
       // If profiling, we record the pc and sp of the profiled thread.
       if (sampler_->IsProfiling()
           && SuspendThread(profiled_thread_) != (DWORD)-1) {
index 850a723666e8973e73b9b01f73e4c861d477884f..1237bdf8883134f1aa40ca6d69a4e81a5c0c22f6 100644 (file)
@@ -301,6 +301,12 @@ class Space : public Malloced {
 
   virtual int Size() = 0;
 
+#ifdef ENABLE_HEAP_PROTECTION
+  // Protect/unprotect the space by marking it read-only/writable.
+  virtual void Protect() = 0;
+  virtual void Unprotect() = 0;
+#endif
+
 #ifdef DEBUG
   virtual void Print() = 0;
 #endif
@@ -1169,6 +1175,12 @@ class SemiSpace : public Space {
   bool Commit();
   bool Uncommit();
 
+#ifdef ENABLE_HEAP_PROTECTION
+  // Protect/unprotect the space by marking it read-only/writable.
+  virtual void Protect() {}
+  virtual void Unprotect() {}
+#endif
+
 #ifdef DEBUG
   virtual void Print();
   virtual void Verify();
index cf660a2680b6a876618c78010a1669ba413df406..966d5a9d2fdd5f3baae240c2440fc95fcda886fa 100644 (file)
--- a/src/v8.h
+++ b/src/v8.h
@@ -69,6 +69,7 @@
 #include "log-inl.h"
 #include "cpu-profiler-inl.h"
 #include "handles-inl.h"
+#include "vm-state-inl.h"
 
 namespace v8 {
 namespace internal {
diff --git a/src/vm-state-inl.h b/src/vm-state-inl.h
new file mode 100644 (file)
index 0000000..4df2cfd
--- /dev/null
@@ -0,0 +1,134 @@
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_VM_STATE_INL_H_
+#define V8_VM_STATE_INL_H_
+
+#include "vm-state.h"
+
+namespace v8 {
+namespace internal {
+
+//
+// VMState class implementation.  A simple stack of VM states held by the
+// logger and partially threaded through the call stack.  States are pushed by
+// VMState construction and popped by destruction.
+//
+#ifdef ENABLE_VMSTATE_TRACKING
+inline const char* StateToString(StateTag state) {
+  switch (state) {
+    case JS:
+      return "JS";
+    case GC:
+      return "GC";
+    case COMPILER:
+      return "COMPILER";
+    case OTHER:
+      return "OTHER";
+    default:
+      UNREACHABLE();
+      return NULL;
+  }
+}
+
+VMState::VMState(StateTag state)
+    : disabled_(true),
+      state_(OTHER),
+      external_callback_(NULL) {
+#ifdef ENABLE_LOGGING_AND_PROFILING
+  if (!Logger::is_logging() && !CpuProfiler::is_profiling()) {
+    return;
+  }
+#endif
+
+  disabled_ = false;
+#if !defined(ENABLE_HEAP_PROTECTION)
+  // When not protecting the heap, there is no difference between
+  // EXTERNAL and OTHER.  As an optimization in that case, we will not
+  // perform EXTERNAL->OTHER transitions through the API.  We thus
+  // compress the two states into one.
+  if (state == EXTERNAL) state = OTHER;
+#endif
+  state_ = state;
+  previous_ = current_state_;  // Save the previous state.
+  current_state_ = this;       // Install the new state.
+
+#ifdef ENABLE_LOGGING_AND_PROFILING
+  if (FLAG_log_state_changes) {
+    LOG(UncheckedStringEvent("Entering", StateToString(state_)));
+    if (previous_ != NULL) {
+      LOG(UncheckedStringEvent("From", StateToString(previous_->state_)));
+    }
+  }
+#endif
+
+#ifdef ENABLE_HEAP_PROTECTION
+  if (FLAG_protect_heap) {
+    if (state_ == EXTERNAL) {
+      // We are leaving V8.
+      ASSERT((previous_ != NULL) && (previous_->state_ != EXTERNAL));
+      Heap::Protect();
+    } else if ((previous_ == NULL) || (previous_->state_ == EXTERNAL)) {
+      // We are entering V8.
+      Heap::Unprotect();
+    }
+  }
+#endif
+}
+
+
+VMState::~VMState() {
+  if (disabled_) return;
+  current_state_ = previous_;  // Return to the previous state.
+
+#ifdef ENABLE_LOGGING_AND_PROFILING
+  if (FLAG_log_state_changes) {
+    LOG(UncheckedStringEvent("Leaving", StateToString(state_)));
+    if (previous_ != NULL) {
+      LOG(UncheckedStringEvent("To", StateToString(previous_->state_)));
+    }
+  }
+#endif  // ENABLE_LOGGING_AND_PROFILING
+
+#ifdef ENABLE_HEAP_PROTECTION
+  if (FLAG_protect_heap) {
+    if (state_ == EXTERNAL) {
+      // We are reentering V8.
+      ASSERT((previous_ != NULL) && (previous_->state_ != EXTERNAL));
+      Heap::Unprotect();
+    } else if ((previous_ == NULL) || (previous_->state_ == EXTERNAL)) {
+      // We are leaving V8.
+      Heap::Protect();
+    }
+  }
+#endif  // ENABLE_HEAP_PROTECTION
+}
+#endif  // ENABLE_VMSTATE_TRACKING
+
+} }  // namespace v8::internal
+
+#endif  // V8_VM_STATE_INL_H_
diff --git a/src/vm-state.cc b/src/vm-state.cc
new file mode 100644 (file)
index 0000000..3859efb
--- /dev/null
@@ -0,0 +1,39 @@
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "v8.h"
+
+#include "vm-state.h"
+
+namespace v8 {
+namespace internal {
+
+#ifdef ENABLE_VMSTATE_TRACKING
+VMState* VMState::current_state_ = NULL;
+#endif
+
+} }  // namespace v8::internal
diff --git a/src/vm-state.h b/src/vm-state.h
new file mode 100644 (file)
index 0000000..a188c5d
--- /dev/null
@@ -0,0 +1,70 @@
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_VM_STATE_H_
+#define V8_VM_STATE_H_
+
+namespace v8 {
+namespace internal {
+
+class VMState BASE_EMBEDDED {
+#ifdef ENABLE_VMSTATE_TRACKING
+ public:
+  inline VMState(StateTag state);
+  inline ~VMState();
+
+  StateTag state() { return state_; }
+  void set_external_callback(Address external_callback) {
+    external_callback_ = external_callback;
+  }
+
+  static StateTag current_state() {
+    return current_state_ ? current_state_->state() : EXTERNAL;
+  }
+
+  static Address external_callback() {
+    return current_state_ ? current_state_->external_callback_ : NULL;
+  }
+
+ private:
+  bool disabled_;
+  StateTag state_;
+  VMState* previous_;
+  Address external_callback_;
+
+  // A stack of VM states.
+  static VMState* current_state_;
+#else
+ public:
+  explicit VMState(StateTag state) {}
+#endif
+};
+
+} }  // namespace v8::internal
+
+
+#endif  // V8_VM_STATE_H_
index dbc004396c0bcc156c22c81cf251cbdc4ee2c78b..e526ff763cc6823bb5046bed3aad4b435f1b7759 100644 (file)
         '../../src/virtual-frame-inl.h',
         '../../src/virtual-frame.cc',
         '../../src/virtual-frame.h',
+        '../../src/vm-state-inl.h',
+        '../../src/vm-state.cc',
+        '../../src/vm-state.h',
         '../../src/zone-inl.h',
         '../../src/zone.cc',
         '../../src/zone.h',
index bc7763804a401d7cf0836c72fef18da3bce95aec..bc795f321ff30dafa0f926cc8ba74153ce440942 100644 (file)
                9F73E3B2114E61A100F84A5A /* profile-generator.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9F73E3AF114E61A100F84A5A /* profile-generator.cc */; };
                9F92FAA90F8F28AD0089F02C /* func-name-inferrer.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9F92FAA70F8F28AD0089F02C /* func-name-inferrer.cc */; };
                9F92FAAA0F8F28AD0089F02C /* func-name-inferrer.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9F92FAA70F8F28AD0089F02C /* func-name-inferrer.cc */; };
+               9FA37335116DD9F000C4CD55 /* vm-state.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9FA37333116DD9F000C4CD55 /* vm-state.cc */; };
+               9FA37336116DD9F000C4CD55 /* vm-state.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9FA37333116DD9F000C4CD55 /* vm-state.cc */; };
                9FBE03DE10BD409900F8BFBA /* fast-codegen.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9FBE03DC10BD409900F8BFBA /* fast-codegen.cc */; };
                9FBE03DF10BD409900F8BFBA /* fast-codegen.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9FBE03DC10BD409900F8BFBA /* fast-codegen.cc */; };
                9FBE03E210BD40EA00F8BFBA /* fast-codegen-ia32.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9FBE03E110BD40EA00F8BFBA /* fast-codegen-ia32.cc */; };
                9F92FAA70F8F28AD0089F02C /* func-name-inferrer.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "func-name-inferrer.cc"; sourceTree = "<group>"; };
                9F92FAA80F8F28AD0089F02C /* func-name-inferrer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "func-name-inferrer.h"; sourceTree = "<group>"; };
                9FA36F62116BA26500C4CD55 /* v8-profiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "v8-profiler.h"; sourceTree = "<group>"; };
+               9FA37332116DD9F000C4CD55 /* vm-state-inl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "vm-state-inl.h"; sourceTree = "<group>"; };
+               9FA37333116DD9F000C4CD55 /* vm-state.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "vm-state.cc"; sourceTree = "<group>"; };
+               9FA37334116DD9F000C4CD55 /* vm-state.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "vm-state.h"; sourceTree = "<group>"; };
                9FBE03DC10BD409900F8BFBA /* fast-codegen.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "fast-codegen.cc"; sourceTree = "<group>"; };
                9FBE03DD10BD409900F8BFBA /* fast-codegen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "fast-codegen.h"; sourceTree = "<group>"; };
                9FBE03E110BD40EA00F8BFBA /* fast-codegen-ia32.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "fast-codegen-ia32.cc"; path = "ia32/fast-codegen-ia32.cc"; sourceTree = "<group>"; };
                                58950D590F55514900F3E8BA /* virtual-frame-ia32.h */,
                                58950D5A0F55514900F3E8BA /* virtual-frame.cc */,
                                58950D5B0F55514900F3E8BA /* virtual-frame.h */,
+                               9FA37332116DD9F000C4CD55 /* vm-state-inl.h */,
+                               9FA37333116DD9F000C4CD55 /* vm-state.cc */,
+                               9FA37334116DD9F000C4CD55 /* vm-state.h */,
                                897FF1A10E719B8F00D62E90 /* zone-inl.h */,
                                897FF1A20E719B8F00D62E90 /* zone.cc */,
                                897FF1A30E719B8F00D62E90 /* zone.h */,
                                9F73E3B2114E61A100F84A5A /* profile-generator.cc in Sources */,
                                9F2B3712114FF62D007CDAF4 /* circular-queue.cc in Sources */,
                                9F2B37271152CEA0007CDAF4 /* cpu-profiler.cc in Sources */,
+                               9FA37336116DD9F000C4CD55 /* vm-state.cc in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                9F73E3B1114E61A100F84A5A /* profile-generator.cc in Sources */,
                                9F2B3711114FF62D007CDAF4 /* circular-queue.cc in Sources */,
                                9F2B37261152CEA0007CDAF4 /* cpu-profiler.cc in Sources */,
+                               9FA37335116DD9F000C4CD55 /* vm-state.cc in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index da3a9f99d2f78eaf6068263c36230eea028af54a..e0845276c89c256575156779d4ab482927d183e0 100644 (file)
                                RelativePath="..\..\src\virtual-frame-heavy.cc"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\src\vm-state.cc"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\src\vm-state-inl.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\src\vm-state.h"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\src\zone-inl.h"
                                >
index 234cd1cff2122a12a24e656c4b18798230adafad..e035392cf2d118165deb1a8468e60bc3c9dd4ed0 100644 (file)
                                RelativePath="..\..\src\virtual-frame-light.cc"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\src\vm-state.cc"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\src\vm-state-inl.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\src\vm-state.h"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\src\zone-inl.h"
                                >
index 4543b19f5a5fa73f3d17c85bd86a22ff02d08ab9..25cac8ed9e613add6e2f743af02c6fb860f87702 100644 (file)
                                RelativePath="..\..\src\virtual-frame-heavy.cc"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\src\vm-state.cc"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\src\vm-state-inl.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\src\vm-state.h"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\src\zone-inl.h"
                                >