@@ -684,22 +684,19 @@ struct JITObjectInfo {
684
684
class JLDebuginfoPlugin : public ObjectLinkingLayer ::Plugin {
685
685
std::mutex PluginMutex;
686
686
std::map<MaterializationResponsibility *, std::unique_ptr<JITObjectInfo>> PendingObjs;
687
- // Resources from distinct `MaterializationResponsibility`s can get merged
688
- // after emission, so we can have multiple debug objects per resource key.
689
- std::map<ResourceKey, SmallVector<std::unique_ptr<JITObjectInfo>, 0 >> RegisteredObjs;
690
687
691
688
public:
692
689
void notifyMaterializing (MaterializationResponsibility &MR, jitlink::LinkGraph &G,
693
690
jitlink::JITLinkContext &Ctx,
694
691
MemoryBufferRef InputObject) override
695
692
{
696
- // Keeping around a full copy of the input object file (and re-parsing it) is
697
- // wasteful, but for now, this lets us reuse the existing debuginfo.cpp code.
698
- // Should look into just directly pulling out all the information required in
699
- // a JITLink pass and just keeping the required tables/DWARF sections around
700
- // (perhaps using the LLVM DebuggerSupportPlugin as a reference).
701
693
auto NewBuffer =
702
694
MemoryBuffer::getMemBufferCopy (InputObject.getBuffer (), G.getName ());
695
+ // Re-parsing the InputObject is wasteful, but for now, this lets us
696
+ // reuse the existing debuginfo.cpp code. Should look into just
697
+ // directly pulling out all the information required in a JITLink pass
698
+ // and just keeping the required tables/DWARF sections around (perhaps
699
+ // using the LLVM DebuggerSupportPlugin as a reference).
703
700
auto NewObj =
704
701
cantFail (object::ObjectFile::createObjectFile (NewBuffer->getMemBufferRef ()));
705
702
@@ -733,13 +730,8 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
733
730
};
734
731
735
732
jl_register_jit_object (*NewInfo->Object , getLoadAddress, nullptr );
736
- }
737
-
738
- cantFail (MR.withResourceKeyDo ([&](ResourceKey K) {
739
- std::lock_guard<std::mutex> lock (PluginMutex);
740
- RegisteredObjs[K].push_back (std::move (PendingObjs[&MR]));
741
733
PendingObjs.erase (&MR);
742
- }));
734
+ }
743
735
744
736
return Error::success ();
745
737
}
@@ -750,32 +742,23 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
750
742
PendingObjs.erase (&MR);
751
743
return Error::success ();
752
744
}
745
+
753
746
#if JL_LLVM_VERSION >= 160000
754
747
Error notifyRemovingResources (JITDylib &JD, orc::ResourceKey K) override
755
748
#else
756
- Error notifyRemovingResources (ResourceKey K) override
749
+ Error notifyRemovingResources (orc:: ResourceKey K) override
757
750
#endif
758
751
{
759
- std::lock_guard<std::mutex> lock (PluginMutex);
760
- RegisteredObjs.erase (K);
761
- // TODO: If we ever unload code, need to notify debuginfo registry.
762
752
return Error::success ();
763
753
}
764
754
765
755
#if JL_LLVM_VERSION >= 160000
766
- void notifyTransferringResources (JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) override
756
+ void notifyTransferringResources (JITDylib &JD, orc::ResourceKey DstKey,
757
+ orc::ResourceKey SrcKey) override {}
767
758
#else
768
- void notifyTransferringResources (ResourceKey DstKey, ResourceKey SrcKey) override
759
+ void notifyTransferringResources (orc::ResourceKey DstKey,
760
+ orc::ResourceKey SrcKey) override {}
769
761
#endif
770
- {
771
- std::lock_guard<std::mutex> lock (PluginMutex);
772
- auto SrcIt = RegisteredObjs.find (SrcKey);
773
- if (SrcIt != RegisteredObjs.end ()) {
774
- for (std::unique_ptr<JITObjectInfo> &Info : SrcIt->second )
775
- RegisteredObjs[DstKey].push_back (std::move (Info));
776
- RegisteredObjs.erase (SrcIt);
777
- }
778
- }
779
762
780
763
void modifyPassConfig (MaterializationResponsibility &MR, jitlink::LinkGraph &,
781
764
jitlink::PassConfiguration &PassConfig) override
@@ -815,12 +798,12 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
815
798
816
799
class JLMemoryUsagePlugin : public ObjectLinkingLayer ::Plugin {
817
800
private:
818
- std::atomic<size_t > &total_size ;
801
+ std::atomic<size_t > &jit_bytes_size ;
819
802
820
803
public:
821
804
822
- JLMemoryUsagePlugin (std::atomic<size_t > &total_size )
823
- : total_size(total_size ) {}
805
+ JLMemoryUsagePlugin (std::atomic<size_t > &jit_bytes_size )
806
+ : jit_bytes_size(jit_bytes_size ) {}
824
807
825
808
Error notifyFailed (orc::MaterializationResponsibility &MR) override {
826
809
return Error::success ();
@@ -869,7 +852,7 @@ class JLMemoryUsagePlugin : public ObjectLinkingLayer::Plugin {
869
852
}
870
853
(void ) code_size;
871
854
(void ) data_size;
872
- this ->total_size .fetch_add (graph_size, std::memory_order_relaxed);
855
+ this ->jit_bytes_size .fetch_add (graph_size, std::memory_order_relaxed);
873
856
jl_timing_counter_inc (JL_TIMING_COUNTER_JITSize, graph_size);
874
857
jl_timing_counter_inc (JL_TIMING_COUNTER_JITCodeSize, code_size);
875
858
jl_timing_counter_inc (JL_TIMING_COUNTER_JITDataSize, data_size);
@@ -985,24 +968,7 @@ void registerRTDyldJITObject(const object::ObjectFile &Object,
985
968
const RuntimeDyld::LoadedObjectInfo &L,
986
969
const std::shared_ptr<RTDyldMemoryManager> &MemMgr)
987
970
{
988
- auto SavedObject = L.getObjectForDebug (Object).takeBinary ();
989
- // If the debug object is unavailable, save (a copy of) the original object
990
- // for our backtraces.
991
- // This copy seems unfortunate, but there doesn't seem to be a way to take
992
- // ownership of the original buffer.
993
- if (!SavedObject.first ) {
994
- auto NewBuffer =
995
- MemoryBuffer::getMemBufferCopy (Object.getData (), Object.getFileName ());
996
- auto NewObj =
997
- cantFail (object::ObjectFile::createObjectFile (NewBuffer->getMemBufferRef ()));
998
- SavedObject = std::make_pair (std::move (NewObj), std::move (NewBuffer));
999
- }
1000
- const object::ObjectFile *DebugObj = SavedObject.first .release ();
1001
- SavedObject.second .release ();
1002
-
1003
971
StringMap<object::SectionRef> loadedSections;
1004
- // Use the original Object, not the DebugObject, as this is used for the
1005
- // RuntimeDyld::LoadedObjectInfo lookup.
1006
972
for (const object::SectionRef &lSection : Object.sections ()) {
1007
973
auto sName = lSection.getName ();
1008
974
if (sName ) {
@@ -1019,7 +985,9 @@ void registerRTDyldJITObject(const object::ObjectFile &Object,
1019
985
return L.getSectionLoadAddress (search->second );
1020
986
};
1021
987
1022
- jl_register_jit_object (*DebugObj, getLoadAddress,
988
+ 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.
989
+ jl_register_jit_object (DebugObject.getBinary () ? *DebugObject.getBinary () : Object,
990
+ getLoadAddress,
1023
991
#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_)
1024
992
[MemMgr](void *p) { return lookupWriteAddressFor (MemMgr.get (), p); }
1025
993
#else
@@ -1630,7 +1598,7 @@ JuliaOJIT::JuliaOJIT()
1630
1598
ES, std::move (ehRegistrar)));
1631
1599
1632
1600
ObjectLayer.addPlugin (std::make_unique<JLDebuginfoPlugin>());
1633
- ObjectLayer.addPlugin (std::make_unique<JLMemoryUsagePlugin>(total_size ));
1601
+ ObjectLayer.addPlugin (std::make_unique<JLMemoryUsagePlugin>(jit_bytes_size ));
1634
1602
#else
1635
1603
ObjectLayer.setNotifyLoaded (
1636
1604
[this ](orc::MaterializationResponsibility &MR,
@@ -2042,19 +2010,20 @@ std::string JuliaOJIT::getMangledName(const GlobalValue *GV)
2042
2010
return getMangledName (GV->getName ());
2043
2011
}
2044
2012
2045
- #ifdef JL_USE_JITLINK
2046
2013
size_t JuliaOJIT::getTotalBytes () const
2047
2014
{
2048
- return total_size.load (std::memory_order_relaxed);
2015
+ auto bytes = jit_bytes_size.load (std::memory_order_relaxed);
2016
+ #ifndef JL_USE_JITLINK
2017
+ size_t getRTDyldMemoryManagerTotalBytes (RTDyldMemoryManager *mm) JL_NOTSAFEPOINT;
2018
+ bytes += getRTDyldMemoryManagerTotalBytes (MemMgr.get ());
2019
+ #endif
2020
+ return bytes;
2049
2021
}
2050
- #else
2051
- size_t getRTDyldMemoryManagerTotalBytes (RTDyldMemoryManager *mm) JL_NOTSAFEPOINT;
2052
2022
2053
- size_t JuliaOJIT::getTotalBytes () const
2023
+ void JuliaOJIT::addBytes ( size_t bytes)
2054
2024
{
2055
- return getRTDyldMemoryManagerTotalBytes (MemMgr. get () );
2025
+ jit_bytes_size. fetch_add (bytes, std::memory_order_relaxed );
2056
2026
}
2057
- #endif
2058
2027
2059
2028
void JuliaOJIT::printTimers ()
2060
2029
{
@@ -2339,3 +2308,9 @@ size_t jl_jit_total_bytes_impl(void)
2339
2308
{
2340
2309
return jl_ExecutionEngine->getTotalBytes ();
2341
2310
}
2311
+
2312
+ // API for adding bytes to record being owned by the JIT
2313
+ void jl_jit_add_bytes (size_t bytes)
2314
+ {
2315
+ jl_ExecutionEngine->addBytes (bytes);
2316
+ }
0 commit comments