Bug 956899 - Replace PRLock with Mutex in JitSpewer; r=nbp
authorTerrence Cole <terrence@mozilla.com>
Thu, 03 Mar 2016 10:27:57 -0800
changeset 288598 d91c3bce840acfec1e318d5fd129dfae81293cc0
parent 288597 59abf823d078ac9042baed6bd750de94413a9f43
child 288599 161e40cc86c115090aa9eb4c1516f17fe38b1baf
push id30087
push usercbook@mozilla.com
push dateTue, 15 Mar 2016 09:43:43 +0000
treeherdermozilla-central@5e14887312d4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp
bugs956899
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 956899 - Replace PRLock with Mutex in JitSpewer; r=nbp
js/src/jit/JitSpewer.cpp
--- a/js/src/jit/JitSpewer.cpp
+++ b/js/src/jit/JitSpewer.cpp
@@ -17,16 +17,19 @@
 #endif
 
 #include "jsprf.h"
 
 #include "jit/Ion.h"
 #include "jit/MIR.h"
 #include "jit/MIRGenerator.h"
 
+#include "threading/LockGuard.h"
+#include "threading/Mutex.h"
+
 #include "vm/HelperThreads.h"
 
 #ifndef JIT_SPEW_DIR
 # if defined(_WIN32)
 #  define JIT_SPEW_DIR ""
 # elif defined(__ANDROID__)
 #  define JIT_SPEW_DIR "/data/local/tmp/"
 # else
@@ -35,17 +38,17 @@
 #endif
 
 using namespace js;
 using namespace js::jit;
 
 class IonSpewer
 {
   private:
-    PRLock* outputLock_;
+    Mutex outputLock_;
     Fprinter c1Output_;
     Fprinter jsonOutput_;
     bool firstFunction_;
     bool asyncLogging_;
     bool inited_;
 
     void release();
 
@@ -68,33 +71,16 @@ class IonSpewer
     }
     bool getAsyncLogging() {
         return asyncLogging_;
     }
 
     void beginFunction();
     void spewPass(GraphSpewer* gs);
     void endFunction(GraphSpewer* gs);
-
-    // Lock used to sequentialized asynchronous compilation output.
-    void lockOutput() {
-        PR_Lock(outputLock_);
-    }
-    void unlockOutput() {
-        PR_Unlock(outputLock_);
-    }
-};
-
-class MOZ_RAII AutoLockIonSpewerOutput
-{
-  private:
-    MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
-  public:
-    explicit AutoLockIonSpewerOutput(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
-    ~AutoLockIonSpewerOutput();
 };
 
 // IonSpewer singleton.
 static IonSpewer ionspewer;
 
 static bool LoggingChecked = false;
 static_assert(JitSpew_Terminator <= 64, "Increase the size of the LoggingBits global.");
 static uint64_t LoggingBits = 0;
@@ -163,19 +149,16 @@ jit::EnableIonDebugAsyncLogging()
 
 void
 IonSpewer::release()
 {
     if (c1Output_.isInitialized())
         c1Output_.finish();
     if (jsonOutput_.isInitialized())
         jsonOutput_.finish();
-    if (outputLock_)
-        PR_DestroyLock(outputLock_);
-    outputLock_ = nullptr;
     inited_ = false;
 }
 
 bool
 IonSpewer::init()
 {
     if (inited_)
         return true;
@@ -205,68 +188,55 @@ IonSpewer::init()
         len = JS_snprintf(c1Buffer, bufferLength, JIT_SPEW_DIR "/ion%" PRIuSIZE ".cfg", pid);
         if (bufferLength <= len) {
             fprintf(stderr, "Warning: IonSpewer::init: Cannot serialize file name.");
             return false;
         }
         c1Filename = c1Buffer;
     }
 
-    outputLock_ = PR_NewLock();
-    if (!outputLock_ ||
-        !c1Output_.init(c1Filename) ||
+    if (!c1Output_.init(c1Filename) ||
         !jsonOutput_.init(jsonFilename))
     {
         release();
         return false;
     }
 
     jsonOutput_.printf("{\n  \"functions\": [\n");
     firstFunction_ = true;
 
     inited_ = true;
     return true;
 }
 
-AutoLockIonSpewerOutput::AutoLockIonSpewerOutput(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
-{
-    MOZ_GUARD_OBJECT_NOTIFIER_INIT;
-    ionspewer.lockOutput();
-}
-
-AutoLockIonSpewerOutput::~AutoLockIonSpewerOutput()
-{
-    ionspewer.unlockOutput();
-}
-
 void
 IonSpewer::beginFunction()
 {
     // If we are doing a synchronous logging then we spew everything as we go,
     // as this is useful in case of failure during the compilation. On the other
     // hand, it is recommended to disabled off main thread compilation.
     if (!getAsyncLogging() && !firstFunction_) {
-        AutoLockIonSpewerOutput outputLock;
+        LockGuard<Mutex> guard(outputLock_);
         jsonOutput_.put(","); // separate functions
     }
 }
 
 void
 IonSpewer::spewPass(GraphSpewer* gs)
 {
     if (!getAsyncLogging()) {
-        AutoLockIonSpewerOutput outputLock;
+        LockGuard<Mutex> guard(outputLock_);
         gs->dump(c1Output_, jsonOutput_);
     }
 }
 
 void
 IonSpewer::endFunction(GraphSpewer* gs)
 {
-    AutoLockIonSpewerOutput outputLock;
+    LockGuard<Mutex> guard(outputLock_);
     if (getAsyncLogging() && !firstFunction_)
         jsonOutput_.put(","); // separate functions
 
     gs->dump(c1Output_, jsonOutput_);
     firstFunction_ = false;
 }
 
 IonSpewer::~IonSpewer()