Bug 1064668 - OdinMonkey: Only add AsmJSActivation to profiling stack after it is fully initialized. r=djvj, a=lmandel
authorLuke Wagner <luke@mozilla.com>
Tue, 09 Sep 2014 11:35:07 -0500
changeset 225744 eb43a2c05eb3
parent 225743 452bc7db811e
child 225745 6609fd74488b
push id3999
push userryanvm@gmail.com
push date2014-10-20 16:11 +0000
treeherdermozilla-beta@2418d9e17dd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdjvj, lmandel
bugs1064668
milestone34.0
Bug 1064668 - OdinMonkey: Only add AsmJSActivation to profiling stack after it is fully initialized. r=djvj, a=lmandel
js/src/vm/Stack-inl.h
js/src/vm/Stack.cpp
--- a/js/src/vm/Stack-inl.h
+++ b/js/src/vm/Stack-inl.h
@@ -739,30 +739,24 @@ Activation::Activation(ThreadSafeContext
     compartment_(cx->compartment_),
     prev_(cx->perThreadData->activation_),
     prevProfiling_(prev_ ? prev_->mostRecentProfiling() : nullptr),
     savedFrameChain_(0),
     hideScriptedCallerCount_(0),
     kind_(kind)
 {
     cx->perThreadData->activation_ = this;
-
-    // Link the activation into the list of profiling activations if needed.
-    if (isProfiling())
-        registerProfiling();
 }
 
 Activation::~Activation()
 {
+    JS_ASSERT_IF(isProfiling(), this != cx_->perThreadData->profilingActivation_);
     JS_ASSERT(cx_->perThreadData->activation_ == this);
     JS_ASSERT(hideScriptedCallerCount_ == 0);
     cx_->perThreadData->activation_ = prev_;
-
-    if (isProfiling())
-        unregisterProfiling();
 }
 
 bool
 Activation::isProfiling() const
 {
     if (isInterpreter())
         return asInterpreter()->isProfiling();
 
--- a/js/src/vm/Stack.cpp
+++ b/js/src/vm/Stack.cpp
@@ -1551,38 +1551,45 @@ AsmJSActivation::AsmJSActivation(JSConte
   : Activation(cx, AsmJS),
     module_(module),
     entrySP_(nullptr),
     profiler_(nullptr),
     resumePC_(nullptr),
     fp_(nullptr),
     exitReason_(AsmJSExit::None)
 {
+    (void) entrySP_;  // squelch GCC warning
+
+    // NB: this is a hack and can be removed once Ion switches over to
+    // JS::ProfilingFrameIterator.
     if (cx->runtime()->spsProfiler.enabled()) {
-        // Use a profiler string that matches jsMatch regex in
-        // browser/devtools/profiler/cleopatra/js/parserWorker.js.
-        // (For now use a single static string to avoid further slowing down
-        // calls into asm.js.)
         profiler_ = &cx->runtime()->spsProfiler;
         profiler_->enterAsmJS("asm.js code :0", this);
     }
 
     prevAsmJSForModule_ = module.activation();
     module.activation() = this;
 
     prevAsmJS_ = cx->mainThread().asmJSActivationStack_;
 
-    JSRuntime::AutoLockForInterrupt lock(cx->runtime());
-    cx->mainThread().asmJSActivationStack_ = this;
+    {
+        JSRuntime::AutoLockForInterrupt lock(cx->runtime());
+        cx->mainThread().asmJSActivationStack_ = this;
+    }
 
-    (void) entrySP_;  // squelch GCC warning
+    // Now that the AsmJSActivation is fully initialized, make it visible to
+    // asynchronous profiling.
+    registerProfiling();
 }
 
 AsmJSActivation::~AsmJSActivation()
 {
+    // Hide this activation from the profiler before is is destroyed.
+    unregisterProfiling();
+
     if (profiler_)
         profiler_->exitAsmJS();
 
     JS_ASSERT(fp_ == nullptr);
 
     JS_ASSERT(module_.activation() == this);
     module_.activation() = prevAsmJSForModule_;