Bug 1406888 - Inline GeckoProfilerEntryMarker ctor/dtor. r=anba
authorJan de Mooij <jdemooij@mozilla.com>
Wed, 11 Oct 2017 10:30:00 +0200
changeset 428087 8940511ffe9e789c8197105fd68f54a6f184ed0b
parent 428086 3029acae6f822f6e148bf8ad64a719513c655883
child 428088 c42f60eda84571f66cf6467822f56df7807fcff8
push id97
push userfmarier@mozilla.com
push dateSat, 14 Oct 2017 01:12:59 +0000
reviewersanba
bugs1406888
milestone58.0a1
Bug 1406888 - Inline GeckoProfilerEntryMarker ctor/dtor. r=anba
js/src/vm/GeckoProfiler-inl.h
js/src/vm/GeckoProfiler.cpp
js/src/vm/GeckoProfiler.h
--- a/js/src/vm/GeckoProfiler-inl.h
+++ b/js/src/vm/GeckoProfiler-inl.h
@@ -43,16 +43,52 @@ class MOZ_RAII AutoSuppressProfilerSampl
   private:
     JSContext* cx_;
     bool previouslyEnabled_;
     JSRuntime::AutoProhibitActiveContextChange prohibitContextChange_;
     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 };
 
 MOZ_ALWAYS_INLINE
+GeckoProfilerEntryMarker::GeckoProfilerEntryMarker(JSContext* cx,
+                                                   JSScript* script
+                                                   MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
+  : profiler_(&cx->geckoProfiler())
+{
+    MOZ_GUARD_OBJECT_NOTIFIER_INIT;
+    if (MOZ_LIKELY(!profiler_->installed())) {
+        profiler_ = nullptr;
+        return;
+    }
+#ifdef DEBUG
+    spBefore_ = profiler_->stackPointer();
+#endif
+
+    // We want to push a CPP frame so the profiler can correctly order JS and native stacks.
+    // Only the sp value is important.
+    profiler_->pseudoStack_->pushCppFrame(
+        /* label = */ "", /* dynamicString = */ nullptr, /* sp = */ this, /* line = */ 0,
+        ProfileEntry::Kind::CPP_MARKER_FOR_JS, ProfileEntry::Category::OTHER);
+
+    profiler_->pseudoStack_->pushJsFrame(
+        "js::RunScript", /* dynamicString = */ nullptr, script, script->code());
+}
+
+MOZ_ALWAYS_INLINE
+GeckoProfilerEntryMarker::~GeckoProfilerEntryMarker()
+{
+    if (MOZ_LIKELY(profiler_ == nullptr))
+        return;
+
+    profiler_->pseudoStack_->pop();    // the JS frame
+    profiler_->pseudoStack_->pop();    // the BEGIN_PSEUDO_JS frame
+    MOZ_ASSERT(spBefore_ == profiler_->stackPointer());
+}
+
+MOZ_ALWAYS_INLINE
 AutoGeckoProfilerEntry::AutoGeckoProfilerEntry(JSContext* cx, const char* label,
                                                ProfileEntry::Category category
                                                MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
   : profiler_(&cx->geckoProfiler())
 {
     MOZ_GUARD_OBJECT_NOTIFIER_INIT;
     if (MOZ_LIKELY(!profiler_->installed())) {
         profiler_ = nullptr;
--- a/js/src/vm/GeckoProfiler.cpp
+++ b/js/src/vm/GeckoProfiler.cpp
@@ -371,48 +371,16 @@ ProfileEntry::trace(JSTracer* trc)
 {
     if (isJs()) {
         JSScript* s = rawScript();
         TraceNullableRoot(trc, &s, "ProfileEntry script");
         spOrScript = s;
     }
 }
 
-GeckoProfilerEntryMarker::GeckoProfilerEntryMarker(JSContext* cx,
-                                                   JSScript* script
-                                                   MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
-    : profiler(&cx->geckoProfiler())
-{
-    MOZ_GUARD_OBJECT_NOTIFIER_INIT;
-    if (!profiler->installed()) {
-        profiler = nullptr;
-        return;
-    }
-    spBefore_ = profiler->stackPointer();
-
-    // We want to push a CPP frame so the profiler can correctly order JS and native stacks.
-    // Only the sp value is important.
-    profiler->pseudoStack_->pushCppFrame(
-        /* label = */ "", /* dynamicString = */ nullptr, /* sp = */ this, /* line = */ 0,
-        ProfileEntry::Kind::CPP_MARKER_FOR_JS, ProfileEntry::Category::OTHER);
-
-    profiler->pseudoStack_->pushJsFrame(
-        "js::RunScript", /* dynamicString = */ nullptr, script, script->code());
-}
-
-GeckoProfilerEntryMarker::~GeckoProfilerEntryMarker()
-{
-    if (profiler == nullptr)
-        return;
-
-    profiler->pseudoStack_->pop();    // the JS frame
-    profiler->pseudoStack_->pop();    // the BEGIN_PSEUDO_JS frame
-    MOZ_ASSERT(spBefore_ == profiler->stackPointer());
-}
-
 GeckoProfilerBaselineOSRMarker::GeckoProfilerBaselineOSRMarker(JSContext* cx, bool hasProfilerFrame
                                                                MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
     : profiler(&cx->geckoProfiler())
 {
     MOZ_GUARD_OBJECT_NOTIFIER_INIT;
     if (!hasProfilerFrame || !cx->runtime()->geckoProfiler().enabled()) {
         profiler = nullptr;
         return;
--- a/js/src/vm/GeckoProfiler.h
+++ b/js/src/vm/GeckoProfiler.h
@@ -204,24 +204,27 @@ GeckoProfilerRuntime::stringsReset()
 /*
  * This class is used in RunScript() to push the marker onto the sampling stack
  * that we're about to enter JS function calls. This is the only time in which a
  * valid stack pointer is pushed to the sampling stack.
  */
 class MOZ_RAII GeckoProfilerEntryMarker
 {
   public:
-    explicit GeckoProfilerEntryMarker(JSContext* cx,
-                                      JSScript* script
-                                      MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
-    ~GeckoProfilerEntryMarker();
+    explicit MOZ_ALWAYS_INLINE
+    GeckoProfilerEntryMarker(JSContext* cx,
+                             JSScript* script
+                             MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
+    MOZ_ALWAYS_INLINE ~GeckoProfilerEntryMarker();
 
   private:
-    GeckoProfilerThread* profiler;
-    mozilla::DebugOnly<uint32_t> spBefore_;
+    GeckoProfilerThread* profiler_;
+#ifdef DEBUG
+    uint32_t spBefore_;
+#endif
     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 };
 
 /*
  * RAII class to automatically add Gecko Profiler pseudo frame entries.
  *
  * NB: The `label` string must be statically allocated.
  */