@@ -800,22 +800,19 @@ struct JITObjectInfo {
800
800
class JLDebuginfoPlugin : public ObjectLinkingLayer ::Plugin {
801
801
std::mutex PluginMutex;
802
802
std::map<MaterializationResponsibility *, std::unique_ptr<JITObjectInfo>> PendingObjs;
803
- // Resources from distinct `MaterializationResponsibility`s can get merged
804
- // after emission, so we can have multiple debug objects per resource key.
805
- std::map<ResourceKey, SmallVector<std::unique_ptr<JITObjectInfo>, 0 >> RegisteredObjs;
806
803
807
804
public:
808
805
void notifyMaterializing (MaterializationResponsibility &MR, jitlink::LinkGraph &G,
809
806
jitlink::JITLinkContext &Ctx,
810
807
MemoryBufferRef InputObject) override
811
808
{
812
- // Keeping around a full copy of the input object file (and re-parsing it) is
813
- // wasteful, but for now, this lets us reuse the existing debuginfo.cpp code.
814
- // Should look into just directly pulling out all the information required in
815
- // a JITLink pass and just keeping the required tables/DWARF sections around
816
- // (perhaps using the LLVM DebuggerSupportPlugin as a reference).
817
809
auto NewBuffer =
818
810
MemoryBuffer::getMemBufferCopy (InputObject.getBuffer (), G.getName ());
811
+ // Re-parsing the InputObject is wasteful, but for now, this lets us
812
+ // reuse the existing debuginfo.cpp code. Should look into just
813
+ // directly pulling out all the information required in a JITLink pass
814
+ // and just keeping the required tables/DWARF sections around (perhaps
815
+ // using the LLVM DebuggerSupportPlugin as a reference).
819
816
auto NewObj =
820
817
cantFail (object::ObjectFile::createObjectFile (NewBuffer->getMemBufferRef ()));
821
818
@@ -849,13 +846,8 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
849
846
};
850
847
851
848
jl_register_jit_object (*NewInfo->Object , getLoadAddress, nullptr );
852
- }
853
-
854
- cantFail (MR.withResourceKeyDo ([&](ResourceKey K) {
855
- std::lock_guard<std::mutex> lock (PluginMutex);
856
- RegisteredObjs[K].push_back (std::move (PendingObjs[&MR]));
857
849
PendingObjs.erase (&MR);
858
- }));
850
+ }
859
851
860
852
return Error::success ();
861
853
}
@@ -866,32 +858,23 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
866
858
PendingObjs.erase (&MR);
867
859
return Error::success ();
868
860
}
861
+
869
862
#if JL_LLVM_VERSION >= 160000
870
863
Error notifyRemovingResources (JITDylib &JD, orc::ResourceKey K) override
871
864
#else
872
- Error notifyRemovingResources (ResourceKey K) override
865
+ Error notifyRemovingResources (orc:: ResourceKey K) override
873
866
#endif
874
867
{
875
- std::lock_guard<std::mutex> lock (PluginMutex);
876
- RegisteredObjs.erase (K);
877
- // TODO: If we ever unload code, need to notify debuginfo registry.
878
868
return Error::success ();
879
869
}
880
870
881
871
#if JL_LLVM_VERSION >= 160000
882
- void notifyTransferringResources (JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) override
872
+ void notifyTransferringResources (JITDylib &JD, orc::ResourceKey DstKey,
873
+ orc::ResourceKey SrcKey) override {}
883
874
#else
884
- void notifyTransferringResources (ResourceKey DstKey, ResourceKey SrcKey) override
875
+ void notifyTransferringResources (orc::ResourceKey DstKey,
876
+ orc::ResourceKey SrcKey) override {}
885
877
#endif
886
- {
887
- std::lock_guard<std::mutex> lock (PluginMutex);
888
- auto SrcIt = RegisteredObjs.find (SrcKey);
889
- if (SrcIt != RegisteredObjs.end ()) {
890
- for (std::unique_ptr<JITObjectInfo> &Info : SrcIt->second )
891
- RegisteredObjs[DstKey].push_back (std::move (Info));
892
- RegisteredObjs.erase (SrcIt);
893
- }
894
- }
895
878
896
879
void modifyPassConfig (MaterializationResponsibility &MR, jitlink::LinkGraph &,
897
880
jitlink::PassConfiguration &PassConfig) override
@@ -931,12 +914,12 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
931
914
932
915
class JLMemoryUsagePlugin : public ObjectLinkingLayer ::Plugin {
933
916
private:
934
- std::atomic<size_t > &total_size ;
917
+ std::atomic<size_t > &jit_bytes_size ;
935
918
936
919
public:
937
920
938
- JLMemoryUsagePlugin (std::atomic<size_t > &total_size )
939
- : total_size(total_size ) {}
921
+ JLMemoryUsagePlugin (std::atomic<size_t > &jit_bytes_size )
922
+ : jit_bytes_size(jit_bytes_size ) {}
940
923
941
924
Error notifyFailed (orc::MaterializationResponsibility &MR) override {
942
925
return Error::success ();
@@ -985,7 +968,7 @@ class JLMemoryUsagePlugin : public ObjectLinkingLayer::Plugin {
985
968
}
986
969
(void ) code_size;
987
970
(void ) data_size;
988
- this ->total_size .fetch_add (graph_size, std::memory_order_relaxed);
971
+ this ->jit_bytes_size .fetch_add (graph_size, std::memory_order_relaxed);
989
972
jl_timing_counter_inc (JL_TIMING_COUNTER_JITSize, graph_size);
990
973
jl_timing_counter_inc (JL_TIMING_COUNTER_JITCodeSize, code_size);
991
974
jl_timing_counter_inc (JL_TIMING_COUNTER_JITDataSize, data_size);
@@ -1101,24 +1084,7 @@ void registerRTDyldJITObject(const object::ObjectFile &Object,
1101
1084
const RuntimeDyld::LoadedObjectInfo &L,
1102
1085
const std::shared_ptr<RTDyldMemoryManager> &MemMgr)
1103
1086
{
1104
- auto SavedObject = L.getObjectForDebug (Object).takeBinary ();
1105
- // If the debug object is unavailable, save (a copy of) the original object
1106
- // for our backtraces.
1107
- // This copy seems unfortunate, but there doesn't seem to be a way to take
1108
- // ownership of the original buffer.
1109
- if (!SavedObject.first ) {
1110
- auto NewBuffer =
1111
- MemoryBuffer::getMemBufferCopy (Object.getData (), Object.getFileName ());
1112
- auto NewObj =
1113
- cantFail (object::ObjectFile::createObjectFile (NewBuffer->getMemBufferRef ()));
1114
- SavedObject = std::make_pair (std::move (NewObj), std::move (NewBuffer));
1115
- }
1116
- const object::ObjectFile *DebugObj = SavedObject.first .release ();
1117
- SavedObject.second .release ();
1118
-
1119
1087
StringMap<object::SectionRef> loadedSections;
1120
- // Use the original Object, not the DebugObject, as this is used for the
1121
- // RuntimeDyld::LoadedObjectInfo lookup.
1122
1088
for (const object::SectionRef &lSection : Object.sections ()) {
1123
1089
auto sName = lSection.getName ();
1124
1090
if (sName ) {
@@ -1135,7 +1101,9 @@ void registerRTDyldJITObject(const object::ObjectFile &Object,
1135
1101
return L.getSectionLoadAddress (search->second );
1136
1102
};
1137
1103
1138
- jl_register_jit_object (*DebugObj, getLoadAddress,
1104
+ auto DebugObject = L.getObjectForDebug (Object); // ELF requires us to make a copy to mutate the header with the section load addresses. On other platforms this is a no-op.
1105
+ jl_register_jit_object (DebugObject.getBinary () ? *DebugObject.getBinary () : Object,
1106
+ getLoadAddress,
1139
1107
#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_)
1140
1108
[MemMgr](void *p) { return lookupWriteAddressFor (MemMgr.get (), p); }
1141
1109
#else
@@ -1737,7 +1705,7 @@ JuliaOJIT::JuliaOJIT()
1737
1705
ES, std::move (ehRegistrar)));
1738
1706
1739
1707
ObjectLayer.addPlugin (std::make_unique<JLDebuginfoPlugin>());
1740
- ObjectLayer.addPlugin (std::make_unique<JLMemoryUsagePlugin>(total_size ));
1708
+ ObjectLayer.addPlugin (std::make_unique<JLMemoryUsagePlugin>(jit_bytes_size ));
1741
1709
#else
1742
1710
ObjectLayer.setNotifyLoaded (
1743
1711
[this ](orc::MaterializationResponsibility &MR,
@@ -2058,19 +2026,20 @@ std::string JuliaOJIT::getMangledName(const GlobalValue *GV)
2058
2026
return getMangledName (GV->getName ());
2059
2027
}
2060
2028
2061
- #ifdef JL_USE_JITLINK
2062
2029
size_t JuliaOJIT::getTotalBytes () const
2063
2030
{
2064
- return total_size.load (std::memory_order_relaxed);
2031
+ auto bytes = jit_bytes_size.load (std::memory_order_relaxed);
2032
+ #ifndef JL_USE_JITLINK
2033
+ size_t getRTDyldMemoryManagerTotalBytes (RTDyldMemoryManager *mm) JL_NOTSAFEPOINT;
2034
+ bytes += getRTDyldMemoryManagerTotalBytes (MemMgr.get ());
2035
+ #endif
2036
+ return bytes;
2065
2037
}
2066
- #else
2067
- size_t getRTDyldMemoryManagerTotalBytes (RTDyldMemoryManager *mm) JL_NOTSAFEPOINT;
2068
2038
2069
- size_t JuliaOJIT::getTotalBytes () const
2039
+ void JuliaOJIT::addBytes ( size_t bytes)
2070
2040
{
2071
- return getRTDyldMemoryManagerTotalBytes (MemMgr. get () );
2041
+ jit_bytes_size. fetch_add (bytes, std::memory_order_relaxed );
2072
2042
}
2073
- #endif
2074
2043
2075
2044
void JuliaOJIT::printTimers ()
2076
2045
{
@@ -2348,3 +2317,9 @@ size_t jl_jit_total_bytes_impl(void)
2348
2317
{
2349
2318
return jl_ExecutionEngine->getTotalBytes ();
2350
2319
}
2320
+
2321
+ // API for adding bytes to record being owned by the JIT
2322
+ void jl_jit_add_bytes (size_t bytes)
2323
+ {
2324
+ jl_ExecutionEngine->addBytes (bytes);
2325
+ }
0 commit comments