43 : Parent(Parent), G(G), AllocAddr(AllocAddr), Segs(
std::
move(Segs)) {}
47 for (
auto &KV : Segs) {
48 assert(KV.second.ContentSize <= std::numeric_limits<size_t>::max());
52 alignTo(KV.second.ContentSize + KV.second.ZeroFillSize,
53 Parent.EPC.getPageSize()),
54 {KV.second.WorkingMem,
static_cast<size_t>(KV.second.ContentSize)}});
60 Parent.EPC.callSPSWrapperAsync<
62 Parent.SAs.Initialize,
63 [OnFinalize = std::move(OnFinalize), AllocAddr = this->AllocAddr](
64 Error SerializationErr,
67 if (SerializationErr) {
69 OnFinalize(std::move(SerializationErr));
70 }
else if (!InitializeKey)
71 OnFinalize(InitializeKey.takeError());
75 Parent.SAs.Allocator, std::move(FR));
80 Parent.EPC.callSPSWrapperAsync<
83 [OnAbandoned = std::move(OnAbandoned)](
Error SerializationErr,
84 Error DeallocateErr)
mutable {
85 if (SerializationErr) {
87 OnAbandoned(std::move(SerializationErr));
89 OnAbandoned(std::move(DeallocateErr));
116 return std::make_unique<EPCGenericJITLinkMemoryManager>(
117 ES.getExecutorProcessControl(), SAs);
133 return OnAllocated(Pages.takeError());
137 [
this, BL = std::move(BL), OnAllocated = std::move(OnAllocated)](
139 if (SerializationErr) {
141 return OnAllocated(std::move(SerializationErr));
144 return OnAllocated(AllocAddr.takeError());
146 completeAllocation(*AllocAddr, std::move(BL), std::move(OnAllocated));
148 SAs.Allocator, Pages->total());
155 [OnDeallocated = std::move(OnDeallocated)](
Error SerErr,
156 Error DeallocErr)
mutable {
159 OnDeallocated(std::move(SerErr));
161 OnDeallocated(std::move(DeallocErr));
163 SAs.Allocator, Allocs);
164 for (
auto &
A : Allocs)
168void EPCGenericJITLinkMemoryManager::completeAllocation(
175 const auto &AG = KV.first;
176 auto &Seg = KV.second;
178 Seg.Addr = NextSegAddr;
183 auto &SegInfo = SegInfos[AG];
184 SegInfo.ContentSize = Seg.ContentSize;
185 SegInfo.ZeroFillSize = Seg.ZeroFillSize;
186 SegInfo.Addr = Seg.Addr;
187 SegInfo.WorkingMem = Seg.WorkingMem;
190 if (
auto Err = BL.
apply())
191 return OnAllocated(std::move(Err));
193 OnAllocated(std::make_unique<InFlightAlloc>(*
this, BL.
getGraph(), AllocAddr,
194 std::move(SegInfos)));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
BasicLayout simplifies the implementation of JITLinkMemoryManagers.
LinkGraph & getGraph()
Return a reference to the graph this allocation was created from.
LLVM_ABI Error apply()
Apply the layout to the graph.
LLVM_ABI Expected< ContiguousPageBasedLayoutSizes > getContiguousPageBasedLayoutSizes(uint64_t PageSize)
Returns the total number of required to allocate all segments (with each segment padded out to page s...
iterator_range< SegmentMap::iterator > segments()
Returns an iterator over the segments of the layout.
Represents a finalized allocation.
Represents an allocation which has not been finalized yet.
unique_function< void(Error)> OnAbandonedFunction
unique_function< void(Expected< FinalizedAlloc >)> OnFinalizedFunction
unique_function< void(AllocResult)> OnAllocatedFunction
Called when allocation has been completed.
unique_function< void(Error)> OnDeallocatedFunction
Called when deallocation has completed.
MutableArrayRef< char > allocateBuffer(size_t Size)
Allocate a mutable buffer of the given size using the LinkGraph's allocator.
A specialized small-map for AllocGroups.
void finalize(OnFinalizedFunction OnFinalize) override
Called to transfer working memory to the target and apply finalization.
void abandon(OnAbandonedFunction OnAbandoned) override
Called prior to finalization if the allocation should be abandoned.
InFlightAlloc(EPCGenericJITLinkMemoryManager &Parent, LinkGraph &G, ExecutorAddr AllocAddr, SegInfoMap Segs)
AllocGroupSmallMap< SegInfo > SegInfoMap
void deallocate(std::vector< FinalizedAlloc > Allocs, OnDeallocatedFunction OnDeallocated) override
Deallocate a list of allocation objects.
void allocate(const jitlink::JITLinkDylib *JD, jitlink::LinkGraph &G, OnAllocatedFunction OnAllocated) override
Start the allocation process.
static Expected< std::unique_ptr< EPCGenericJITLinkMemoryManager > > Create(JITDylib &JD, rt::SimpleExecutorMemoryManagerSymbolNames SNs=rt::orc_rt_SimpleNativeMemoryMapSPSSymbols)
Create an EPCGenericJITLinkMemoryManager using the given implementation symbol names.
EPCGenericJITLinkMemoryManager(ExecutorProcessControl &EPC, SymbolAddrs SAs)
Create an EPCGenericJITLinkMemoryManager instance from a given set of function addrs.
An ExecutionSession represents a running JIT program.
JITDylib & getBootstrapJITDylib()
Returns a reference to the bootstrap JITDylib.
Represents an address in the executor process.
unsigned getPageSize() const
Get the page size for the target process.
Represents a JIT'd dynamic library.
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
shared::SPSExpected< shared::SPSExecutorAddr >(shared::SPSExecutorAddr, uint64_t) SPSSimpleExecutorMemoryManagerReserveSignature
shared::SPSExpected< shared::SPSExecutorAddr >(shared::SPSExecutorAddr, shared::SPSFinalizeRequest) SPSSimpleExecutorMemoryManagerInitializeSignature
shared::SPSError( shared::SPSExecutorAddr, shared::SPSSequence< shared::SPSExecutorAddr >) SPSSimpleExecutorMemoryManagerReleaseSignature
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
uint64_t ExecutorAddrDiff
LLVM_ABI void lookupAndRecordAddrs(unique_function< void(Error)> OnRecorded, ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder, std::vector< std::pair< SymbolStringPtr, ExecutorAddr * > > Pairs, SymbolLookupFlags LookupFlags=SymbolLookupFlags::RequiredSymbol)
Record addresses of the given symbols in the given ExecutorAddrs.
This is an optimization pass for GlobalISel generic memory operations.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Symbol addresses for memory management implementation.
Symbol names for memory management implementation.
StringRef DeinitializeName
std::vector< SegFinalizeRequest > Segments
shared::AllocActions Actions