Bug 1283278 - Use js::Mutex instead of PRLock in js/src/jit/arm/Simulator-arm.{h,cpp}; r=terrence
authorNick Fitzgerald <fitzgen@gmail.com>
Thu, 30 Jun 2016 13:13:30 -0700
changeset 303318 73cc7590bc392e657d8a97e937d19859af8e9858
parent 303317 105425978bcce64b8bfe2074b3000353a7c33003
child 303319 8a0a8a185bf8df3a01a0d3976ddd9ba13479de7a
push id19839
push usercbook@mozilla.com
push dateFri, 01 Jul 2016 09:19:59 +0000
treeherderfx-team@499d8875de7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1283278
milestone50.0a1
Bug 1283278 - Use js::Mutex instead of PRLock in js/src/jit/arm/Simulator-arm.{h,cpp}; r=terrence
js/src/jit/arm/Simulator-arm.cpp
js/src/jit/arm/Simulator-arm.h
--- a/js/src/jit/arm/Simulator-arm.cpp
+++ b/js/src/jit/arm/Simulator-arm.cpp
@@ -34,16 +34,17 @@
 #include "mozilla/Likely.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/SizePrintfMacros.h"
 
 #include "asmjs/WasmSignalHandlers.h"
 #include "jit/arm/Assembler-arm.h"
 #include "jit/arm/disasm/Constants-arm.h"
 #include "jit/AtomicOperations.h"
+#include "threading/LockGuard.h"
 #include "vm/Runtime.h"
 #include "vm/SharedMem.h"
 
 extern "C" {
 
 int64_t
 __aeabi_idivmod(int x, int y)
 {
@@ -353,33 +354,36 @@ class CachePage
   private:
     char data_[kPageSize];   // The cached data.
     static const int kValidityMapSize = kPageSize >> kLineShift;
     char validity_map_[kValidityMapSize];  // One byte per line.
 };
 
 // Protects the icache() and redirection() properties of the
 // Simulator.
-class AutoLockSimulatorCache
+class AutoLockSimulatorCache : public LockGuard<Mutex>
 {
+    using Base = LockGuard<Mutex>;
+
   public:
-    explicit AutoLockSimulatorCache(Simulator* sim) : sim_(sim) {
-        PR_Lock(sim_->cacheLock_);
+    explicit AutoLockSimulatorCache(Simulator* sim)
+      : Base(sim->cacheLock_)
+      , sim_(sim)
+    {
         MOZ_ASSERT(!sim_->cacheLockHolder_);
 #ifdef DEBUG
         sim_->cacheLockHolder_ = PR_GetCurrentThread();
 #endif
     }
 
     ~AutoLockSimulatorCache() {
         MOZ_ASSERT(sim_->cacheLockHolder_);
 #ifdef DEBUG
         sim_->cacheLockHolder_ = nullptr;
 #endif
-        PR_Unlock(sim_->cacheLock_);
     }
 
   private:
     Simulator* const sim_;
 };
 
 bool Simulator::ICacheCheckingEnabled = false;
 
@@ -1119,32 +1123,27 @@ Simulator::Simulator()
 
     // The lr and pc are initialized to a known bad value that will cause an
     // access violation if the simulator ever tries to execute it.
     registers_[pc] = bad_lr;
     registers_[lr] = bad_lr;
 
     lastDebuggerInput_ = nullptr;
 
-    cacheLock_ = nullptr;
 #ifdef DEBUG
     cacheLockHolder_ = nullptr;
 #endif
     redirection_ = nullptr;
     exclusiveMonitorHeld_ = false;
     exclusiveMonitor_ = 0;
 }
 
 bool
 Simulator::init()
 {
-    cacheLock_ = PR_NewLock();
-    if (!cacheLock_)
-        return false;
-
     if (!icache_.init())
         return false;
 
     // Allocate 2MB for the stack. Note that we will only use 1MB, see below.
     static const size_t stackSize = 2 * 1024*1024;
     stack_ = reinterpret_cast<char*>(js_malloc(stackSize));
     if (!stack_)
         return false;
@@ -1221,17 +1220,16 @@ class Redirection
     uint32_t swiInstruction_;
     ABIFunctionType type_;
     Redirection* next_;
 };
 
 Simulator::~Simulator()
 {
     js_free(stack_);
-    PR_DestroyLock(cacheLock_);
     Redirection* r = redirection_;
     while (r) {
         Redirection* next = r->next_;
         js_delete(r);
         r = next;
     }
 }
 
--- a/js/src/jit/arm/Simulator-arm.h
+++ b/js/src/jit/arm/Simulator-arm.h
@@ -31,16 +31,17 @@
 
 #ifdef JS_SIMULATOR_ARM
 
 #include "jslock.h"
 
 #include "jit/arm/Architecture-arm.h"
 #include "jit/arm/disasm/Disasm-arm.h"
 #include "jit/IonTypes.h"
+#include "threading/Mutex.h"
 
 namespace js {
 namespace jit {
 
 class Simulator;
 class Redirection;
 class CachePage;
 class AutoLockSimulator;
@@ -413,17 +414,17 @@ class Simulator
 
   public:
     typedef HashMap<void*, CachePage*, ICacheHasher, SystemAllocPolicy> ICacheMap;
 
   private:
     // This lock creates a critical section around 'redirection_' and
     // 'icache_', which are referenced both by the execution engine
     // and by the off-thread compiler (see Redirection::Get in the cpp file).
-    PRLock* cacheLock_;
+    Mutex cacheLock_;
 #ifdef DEBUG
     PRThread* cacheLockHolder_;
 #endif
 
     Redirection* redirection_;
     ICacheMap icache_;
 
   public: