Acquire the lock only when necessary. More precisely, do not acquire

the lock when calling a method which may materialize the llvm::Function.

llvm-svn: 56995
This commit is contained in:
Nicolas Geoffray 2008-10-03 07:27:08 +00:00
parent cb4f156b6b
commit 74056ae3d5
1 changed files with 21 additions and 9 deletions

View File

@ -234,6 +234,13 @@ unsigned JITResolver::getGOTIndexForAddr(void* addr) {
void *JITResolver::JITCompilerFn(void *Stub) {
JITResolver &JR = *TheJITResolver;
Function* F = 0;
void* ActualPtr = 0;
{
// 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
@ -242,7 +249,9 @@ void *JITResolver::JITCompilerFn(void *Stub) {
JR.state.getStubToFunctionMap(locked).upper_bound(Stub);
assert(I != JR.state.getStubToFunctionMap(locked).begin() &&
"This is not a known stub!");
Function *F = (--I)->second;
F = (--I)->second;
ActualPtr = I->first;
}
// If we have already code generated the function, just return the address.
void *Result = TheJIT->getPointerToGlobalIfAvailable(F);
@ -266,11 +275,14 @@ 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);