[llvm-commits] [llvm] r56995 - /llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Fri Oct 3 00:27:09 PDT 2008


Author: geoffray
Date: Fri Oct  3 02:27:08 2008
New Revision: 56995

URL: http://llvm.org/viewvc/llvm-project?rev=56995&view=rev
Log:
Acquire the lock only when necessary. More precisely, do not acquire
the lock when calling a method which may materialize the llvm::Function.


Modified:
    llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp

Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=56995&r1=56994&r2=56995&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp Fri Oct  3 02:27:08 2008
@@ -233,16 +233,25 @@
 /// it if necessary, then returns the resultant function pointer.
 void *JITResolver::JITCompilerFn(void *Stub) {
   JITResolver &JR = *TheJITResolver;
+  
+  Function* F = 0;
+  void* ActualPtr = 0;
 
-  MutexGuard locked(TheJIT->lock);
-
-  // The address given to us for the stub may not be exactly right, it might be
-  // a little bit after the stub.  As such, use upper_bound to find it.
-  std::map<void*, Function*>::iterator I =
-    JR.state.getStubToFunctionMap(locked).upper_bound(Stub);
-  assert(I != JR.state.getStubToFunctionMap(locked).begin() &&
-         "This is not a known stub!");
-  Function *F = (--I)->second;
+  {
+    // Only lock for getting the Function. The call getPointerToFunction made
+    // in this function might trigger function materializing, which requires
+    // JIT lock to be unlocked.
+    MutexGuard locked(TheJIT->lock);
+
+    // The address given to us for the stub may not be exactly right, it might be
+    // a little bit after the stub.  As such, use upper_bound to find it.
+    std::map<void*, Function*>::iterator I =
+      JR.state.getStubToFunctionMap(locked).upper_bound(Stub);
+    assert(I != JR.state.getStubToFunctionMap(locked).begin() &&
+           "This is not a known stub!");
+    F = (--I)->second;
+    ActualPtr = I->first;
+  }
 
   // If we have already code generated the function, just return the address.
   void *Result = TheJIT->getPointerToGlobalIfAvailable(F);
@@ -266,10 +275,13 @@
 
     DOUT << "JIT: Lazily resolving function '" << F->getName()
          << "' In stub ptr = " << Stub << " actual ptr = "
-         << I->first << "\n";
+         << ActualPtr << "\n";
 
     Result = TheJIT->getPointerToFunction(F);
   }
+  
+  // Reacquire the lock to erase the stub in the map.
+  MutexGuard locked(TheJIT->lock);
 
   // We don't need to reuse this stub in the future, as F is now compiled.
   JR.state.getFunctionToStubMap(locked).erase(F);





More information about the llvm-commits mailing list