Reviewers: Mads Ager,

Description:
Add global setup for runtime profiler.

Whether it's enabled or not must not change while we're running. Let's
not waste time recomputing it. This also makes the VM state tracking
code slightly more lightweight.

Please review this at http://codereview.chromium.org/6825054/

Affected files:
  M src/runtime-profiler.h
  M src/runtime-profiler.cc
  M src/v8.cc


Index: src/runtime-profiler.cc
diff --git a/src/runtime-profiler.cc b/src/runtime-profiler.cc
index 5b0aa8f72868f9ca8a7bfadf631db9afd6ba299d..97f034169e5677a1b38751a78328760714b4ecdd 100644
--- a/src/runtime-profiler.cc
+++ b/src/runtime-profiler.cc
@@ -114,6 +114,11 @@ Atomic32 RuntimeProfiler::state_ = 0;
 Semaphore* RuntimeProfiler::semaphore_ = OS::CreateSemaphore(0);
 #endif

+#ifdef DEBUG
+bool RuntimeProfiler::has_been_globally_setup_ = false;
+#endif
+bool RuntimeProfiler::enabled_ = false;
+

 RuntimeProfiler::RuntimeProfiler(Isolate* isolate)
     : isolate_(isolate),
@@ -134,8 +139,12 @@ RuntimeProfiler::RuntimeProfiler(Isolate* isolate)
 }


-bool RuntimeProfiler::IsEnabled() {
-  return V8::UseCrankshaft() && FLAG_opt;
+void RuntimeProfiler::GlobalSetup() {
+  ASSERT(!has_been_globally_setup_);
+  enabled_ = V8::UseCrankshaft() && FLAG_opt;
+#ifdef DEBUG
+  has_been_globally_setup_ = true;
+#endif
 }


@@ -363,6 +372,7 @@ void RuntimeProfiler::NotifyTick() {


 void RuntimeProfiler::Setup() {
+  ASSERT(has_been_globally_setup_);
   ClearSampleBuffer();
   // If the ticker hasn't already started, make sure to do so to get
   // the ticks for the runtime profiler.
Index: src/runtime-profiler.h
diff --git a/src/runtime-profiler.h b/src/runtime-profiler.h
index 3656893ae783c556bf1215bba30c4ffc1c057f7d..692b4ffacc29c5e03a7f7f3d312cd641c0d806d0 100644
--- a/src/runtime-profiler.h
+++ b/src/runtime-profiler.h
@@ -44,7 +44,12 @@ class RuntimeProfiler {
  public:
   explicit RuntimeProfiler(Isolate* isolate);

-  static bool IsEnabled();
+  static void GlobalSetup();
+
+  static inline bool IsEnabled() {
+    ASSERT(has_been_globally_setup_);
+    return enabled_;
+  }

   void OptimizeNow();
   void OptimizeSoon(JSFunction* function);
@@ -143,6 +148,11 @@ class RuntimeProfiler {
   //   0 or positive => the number of isolates running JavaScript code.
   static Atomic32 state_;
   static Semaphore* semaphore_;
+
+#ifdef DEBUG
+  static bool has_been_globally_setup_;
+#endif
+  static bool enabled_;
 };


Index: src/v8.cc
diff --git a/src/v8.cc b/src/v8.cc
index 19ed18401181a0d50a96c38f7dd28efe1840b0d7..464d2dd930b3b148f0dc165593b4f28771ecf118 100644
--- a/src/v8.cc
+++ b/src/v8.cc
@@ -204,6 +204,8 @@ void V8::InitializeOncePerProcess() {
     use_crankshaft_ = false;
   }

+  RuntimeProfiler::GlobalSetup();
+
   // Peephole optimization might interfere with deoptimization.
   FLAG_peephole_optimization = !use_crankshaft_;
 }


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

Reply via email to