JITTargetAddress TrampolineAddr,
NotifyLandingResolvedFunction OnLandingResolved) const>;
- virtual ~TrampolinePool() {}
+ virtual ~TrampolinePool();
/// Get an available trampoline address.
/// Returns an error if no trampoline can be created.
- virtual Expected<JITTargetAddress> getTrampoline() = 0;
+ Expected<JITTargetAddress> getTrampoline() {
+ std::lock_guard<std::mutex> Lock(TPMutex);
+ if (AvailableTrampolines.empty()) {
+ if (auto Err = grow())
+ return std::move(Err);
+ }
+ assert(!AvailableTrampolines.empty() && "Failed to grow trampoline pool");
+ auto TrampolineAddr = AvailableTrampolines.back();
+ AvailableTrampolines.pop_back();
+ return TrampolineAddr;
+ }
-private:
- virtual void anchor();
+ /// Returns the given trampoline to the pool for re-use.
+ void releaseTrampoline(JITTargetAddress TrampolineAddr) {
+ std::lock_guard<std::mutex> Lock(TPMutex);
+ AvailableTrampolines.push_back(TrampolineAddr);
+ }
+
+protected:
+ virtual Error grow() = 0;
+
+ std::mutex TPMutex;
+ std::vector<JITTargetAddress> AvailableTrampolines;
};
/// A trampoline pool for trampolines within the current process.
return std::move(LTP);
}
- /// Get a free trampoline. Returns an error if one can not be provided (e.g.
- /// because the pool is empty and can not be grown).
- Expected<JITTargetAddress> getTrampoline() override {
- std::lock_guard<std::mutex> Lock(LTPMutex);
- if (AvailableTrampolines.empty()) {
- if (auto Err = grow())
- return std::move(Err);
- }
- assert(!AvailableTrampolines.empty() && "Failed to grow trampoline pool");
- auto TrampolineAddr = AvailableTrampolines.back();
- AvailableTrampolines.pop_back();
- return TrampolineAddr;
- }
-
- /// Returns the given trampoline to the pool for re-use.
- void releaseTrampoline(JITTargetAddress TrampolineAddr) {
- std::lock_guard<std::mutex> Lock(LTPMutex);
- AvailableTrampolines.push_back(TrampolineAddr);
- }
-
private:
static JITTargetAddress reenter(void *TrampolinePoolPtr, void *TrampolineId) {
LocalTrampolinePool<ORCABI> *TrampolinePool =
}
}
- Error grow() {
- assert(this->AvailableTrampolines.empty() && "Growing prematurely?");
+ Error grow() override {
+ assert(AvailableTrampolines.empty() && "Growing prematurely?");
std::error_code EC;
auto TrampolineBlock =
pointerToJITTargetAddress(ResolverBlock.base()), NumTrampolines);
for (unsigned I = 0; I < NumTrampolines; ++I)
- this->AvailableTrampolines.push_back(pointerToJITTargetAddress(
+ AvailableTrampolines.push_back(pointerToJITTargetAddress(
TrampolineMem + (I * ORCABI::TrampolineSize)));
if (auto EC = sys::Memory::protectMappedMemory(
ResolveLandingFunction ResolveLanding;
- std::mutex LTPMutex;
sys::OwningMemoryBlock ResolverBlock;
std::vector<sys::OwningMemoryBlock> TrampolineBlocks;
- std::vector<JITTargetAddress> AvailableTrampolines;
};
/// Target-independent base class for compile callback management.
public:
RemoteTrampolinePool(OrcRemoteTargetClient &Client) : Client(Client) {}
- Expected<JITTargetAddress> getTrampoline() override {
- std::lock_guard<std::mutex> Lock(RTPMutex);
- if (AvailableTrampolines.empty()) {
- if (auto Err = grow())
- return std::move(Err);
- }
- assert(!AvailableTrampolines.empty() && "Failed to grow trampoline pool");
- auto TrampolineAddr = AvailableTrampolines.back();
- AvailableTrampolines.pop_back();
- return TrampolineAddr;
- }
-
private:
Error grow() {
JITTargetAddress BlockAddr = 0;
uint32_t TrampolineSize = Client.getTrampolineSize();
for (unsigned I = 0; I < NumTrampolines; ++I)
- this->AvailableTrampolines.push_back(BlockAddr + (I * TrampolineSize));
+ AvailableTrampolines.push_back(BlockAddr + (I * TrampolineSize));
return Error::success();
}
- std::mutex RTPMutex;
OrcRemoteTargetClient &Client;
- std::vector<JITTargetAddress> AvailableTrampolines;
};
/// Remote compile callback manager.
/// Return a MemoryAccess object for the target process.
MemoryAccess &getMemoryAccess() const { return *MemAccess; }
+ /// Load the library at the given path.
+
protected:
TargetProcessControl(Triple TT, unsigned PageSize);
namespace llvm {
namespace orc {
+TrampolinePool::~TrampolinePool() {}
void IndirectStubsManager::anchor() {}
-void TrampolinePool::anchor() {}
Expected<JITTargetAddress>
JITCompileCallbackManager::getCompileCallback(CompileFunction Compile) {
public:
TPCTrampolinePool(TPCIndirectionUtils &TPCIU);
Error deallocatePool();
- Expected<JITTargetAddress> getTrampoline() override;
- void releaseTrampoline(JITTargetAddress TrampolineAddr);
protected:
- Error grow();
+ Error grow() override;
using Allocation = jitlink::JITLinkMemoryManager::Allocation;
- std::mutex TPMutex;
TPCIndirectionUtils &TPCIU;
unsigned TrampolineSize = 0;
unsigned TrampolinesPerPage = 0;
std::vector<std::unique_ptr<Allocation>> TrampolineBlocks;
- std::vector<JITTargetAddress> AvailableTrampolines;
};
class TPCIndirectStubsManager : public IndirectStubsManager,
return Err;
}
-Expected<JITTargetAddress> TPCTrampolinePool::getTrampoline() {
- std::lock_guard<std::mutex> Lock(TPMutex);
- if (AvailableTrampolines.empty()) {
- if (auto Err = grow())
- return std::move(Err);
- }
-
- assert(!AvailableTrampolines.empty() && "Failed to grow trampoline pool");
- auto TrampolineAddr = AvailableTrampolines.back();
- AvailableTrampolines.pop_back();
- return TrampolineAddr;
-}
-
-void TPCTrampolinePool::releaseTrampoline(JITTargetAddress TrampolineAddr) {
- std::lock_guard<std::mutex> Lock(TPMutex);
- AvailableTrampolines.push_back(TrampolineAddr);
-}
-
Error TPCTrampolinePool::grow() {
- assert(this->AvailableTrampolines.empty() &&
+ assert(AvailableTrampolines.empty() &&
"Grow called with trampolines still available");
auto ResolverAddress = TPCIU.getResolverBlockAddress();
auto TargetAddr = (*Alloc)->getTargetMemory(TrampolinePagePermissions);
for (unsigned I = 0; I < NumTrampolines; ++I)
- this->AvailableTrampolines.push_back(TargetAddr + (I * TrampolineSize));
+ AvailableTrampolines.push_back(TargetAddr + (I * TrampolineSize));
if (auto Err = (*Alloc)->finalize())
return Err;
namespace {
class DummyTrampolinePool : public orc::TrampolinePool {
-public:
- Expected<JITTargetAddress> getTrampoline() override {
- llvm_unreachable("Unimplemented");
- }
+protected:
+ Error grow() override { llvm_unreachable("Unimplemented"); }
};
class DummyCallbackManager : public JITCompileCallbackManager {