#include "llvm/IR/ValueHandle.h"
#include "llvm/IR/ValueMap.h"
#include "llvm/Support/Debug.h"
-#include "llvm/Support/Disassembler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Memory.h"
+#include "llvm/Support/MutexGuard.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetJITInfo.h"
#ifndef NDEBUG
#include <iomanip>
#endif
-#include <mutex>
using namespace llvm;
#define DEBUG_TYPE "jit"
std::map<void*, JITResolver*> Map;
/// Guards Map from concurrent accesses.
- mutable std::recursive_mutex Lock;
+ mutable sys::Mutex Lock;
public:
/// Registers a Stub to be resolved by Resolver.
void RegisterStubResolver(void *Stub, JITResolver *Resolver) {
- std::lock_guard<std::recursive_mutex> guard(Lock);
+ MutexGuard guard(Lock);
Map.insert(std::make_pair(Stub, Resolver));
}
/// Unregisters the Stub when it's invalidated.
void UnregisterStubResolver(void *Stub) {
- std::lock_guard<std::recursive_mutex> guard(Lock);
+ MutexGuard guard(Lock);
Map.erase(Stub);
}
/// Returns the JITResolver instance that owns the Stub.
JITResolver *getResolverFromStub(void *Stub) const {
- std::lock_guard<std::recursive_mutex> guard(Lock);
+ MutexGuard guard(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.
// This is the same trick as in LookupFunctionFromCallSite from
/// True if any stubs refer to the given resolver. Only used in an assert().
/// O(N)
bool ResolverHasStubs(JITResolver* Resolver) const {
- std::lock_guard<std::recursive_mutex> guard(Lock);
+ MutexGuard guard(Lock);
for (std::map<void*, JITResolver*>::const_iterator I = Map.begin(),
E = Map.end(); I != E; ++I) {
if (I->second == Resolver)
/// getLazyFunctionStubIfAvailable - This returns a pointer to a function stub
/// if it has already been created.
void *JITResolver::getLazyFunctionStubIfAvailable(Function *F) {
- std::lock_guard<std::recursive_mutex> guard(TheJIT->lock);
+ MutexGuard locked(TheJIT->lock);
// If we already have a stub for this function, recycle it.
return state.getFunctionToLazyStubMap().lookup(F);
/// getFunctionStub - This returns a pointer to a function stub, creating
/// one on demand as needed.
void *JITResolver::getLazyFunctionStub(Function *F) {
- std::lock_guard<std::recursive_mutex> guard(TheJIT->lock);
+ MutexGuard locked(TheJIT->lock);
// If we already have a lazy stub for this function, recycle it.
void *&Stub = state.getFunctionToLazyStubMap()[F];
/// getGlobalValueIndirectSym - Return a lazy pointer containing the specified
/// GV address.
void *JITResolver::getGlobalValueIndirectSym(GlobalValue *GV, void *GVAddress) {
- std::lock_guard<std::recursive_mutex> guard(TheJIT->lock);
+ MutexGuard locked(TheJIT->lock);
// If we already have a stub for this global variable, recycle it.
void *&IndirectSym = state.getGlobalToIndirectSymMap()[GV];
// Only lock for getting the Function. The call getPointerToFunction made
// in this function might trigger function materializing, which requires
// JIT lock to be unlocked.
- std::lock_guard<std::recursive_mutex> guard(JR->TheJIT->lock);
+ MutexGuard locked(JR->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.
}
// Reacquire the lock to update the GOT map.
- std::lock_guard<std::recursive_mutex> locked(JR->TheJIT->lock);
+ MutexGuard locked(JR->TheJIT->lock);
// We might like to remove the call site from the CallSiteToFunction map, but
// we can't do that! Multiple threads could be stuck, waiting to acquire the
MemMgr->setMemoryExecutable();
DEBUG({
- if (sys::hasDisassembler()) {
- dbgs() << "JIT: Disassembled code:\n";
- dbgs() << sys::disassembleBuffer(FnStart, FnEnd-FnStart,
- (uintptr_t)FnStart);
- } else {
dbgs() << "JIT: Binary code:\n";
uint8_t* q = FnStart;
for (int i = 0; q < FnEnd; q += 4, ++i) {
dbgs() << '\n';
}
dbgs()<< '\n';
- }
});
if (MMI)