Reviewers: Benedikt Meurer,

Message:
Please revel in the stunning beauty of this patch.

Description:
Temporarily allow HistogramTimerScopes to be nested

Please review this at https://codereview.chromium.org/47513015/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+34, -3 lines):
  M src/counters.h
  M src/parser.cc


Index: src/counters.h
diff --git a/src/counters.h b/src/counters.h
index 93911d721615dfd81e3198cd70074927a4cfa01f..821c25f8cec1c2a3391ddcc297a22e731b6552fb 100644
--- a/src/counters.h
+++ b/src/counters.h
@@ -259,22 +259,51 @@ class HistogramTimer : public Histogram {
     return Enabled() && timer_.IsStarted();
   }

+  // TODO(bmeurer): Remove this when HistogramTimerScope is fixed.
+#ifdef DEBUG
+  ElapsedTimer* timer() { return &timer_; }
+#endif
+
  private:
   ElapsedTimer timer_;
 };

 // Helper class for scoping a HistogramTimer.
+// TODO(bmeurer): The ifdeffery is an ugly hack around the fact that the
+// Parser is currently reentrant (when it throws an error, we call back
+// into JavaScript and all bets are off), but ElapsedTimer is not
+// reentry-safe. Fix this properly and remove |allow_nesting|.
 class HistogramTimerScope BASE_EMBEDDED {
  public:
-  explicit HistogramTimerScope(HistogramTimer* timer) :
-  timer_(timer) {
+  explicit HistogramTimerScope(HistogramTimer* timer,
+                               bool allow_nesting = false)
+#ifdef DEBUG
+      : timer_(timer),
+        skipped_timer_start_(false) {
+    if (timer_->timer()->IsStarted() && allow_nesting) {
+      skipped_timer_start_ = true;
+    } else {
+      timer_->Start();
+    }
+#else
+      : timer_(timer) {
     timer_->Start();
+#endif
   }
   ~HistogramTimerScope() {
+#ifdef DEBUG
+    if (!skipped_timer_start_) {
+      timer_->Stop();
+    }
+#else
     timer_->Stop();
+#endif
   }
  private:
   HistogramTimer* timer_;
+#ifdef DEBUG
+  bool skipped_timer_start_;
+#endif
 };


Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index a17883fd456182865a90a1b76225ff02ae826ddb..d84649d86b268cb224d28c0a0115f2638f99582b 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -565,7 +565,9 @@ Parser::Parser(CompilationInfo* info)


 FunctionLiteral* Parser::ParseProgram() {
-  HistogramTimerScope timer_scope(isolate()->counters()->parse());
+  // TODO(bmeurer): We temporarily need to pass allow_nesting = true here,
+  // see comment for HistogramTimerScope class.
+  HistogramTimerScope timer_scope(isolate()->counters()->parse(), true);
   Handle<String> source(String::cast(script_->source()));
   isolate()->counters()->total_parse_size()->Increment(source->length());
   ElapsedTimer timer;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to