summaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine
diff options
context:
space:
mode:
authorNicolas Geoffray <nicolas.geoffray@lip6.fr>2008-10-03 07:27:08 +0000
committerNicolas Geoffray <nicolas.geoffray@lip6.fr>2008-10-03 07:27:08 +0000
commitdcb31e179000193c65b3f09b7138ef273dc3ce63 (patch)
tree072f7b08bf3b02fe02c844310e20da8931e3b882 /lib/ExecutionEngine
parenta90793b431458c1bac4c7267946738968c4cdf58 (diff)
downloadexternal_llvm-dcb31e179000193c65b3f09b7138ef273dc3ce63.zip
external_llvm-dcb31e179000193c65b3f09b7138ef273dc3ce63.tar.gz
external_llvm-dcb31e179000193c65b3f09b7138ef273dc3ce63.tar.bz2
Acquire the lock only when necessary. More precisely, do not acquire
the lock when calling a method which may materialize the llvm::Function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56995 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r--lib/ExecutionEngine/JIT/JITEmitter.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp
index 4803fdf..63f3b4e 100644
--- a/lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp
@@ -233,16 +233,25 @@ unsigned JITResolver::getGOTIndexForAddr(void* addr) {
/// 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 @@ void *JITResolver::JITCompilerFn(void *Stub) {
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);