Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backports release 1.11 #55344

Merged
merged 59 commits into from
Aug 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
50e5fe0
Add timing to precompile trace compile (#54962)
IanButterworth Jul 1, 2024
29f6950
Fix annotated join with non-concrete eltype iters (#54919)
tecosaur Jul 24, 2024
0429e1e
[docs] change docstring to match code (#55013)
araujoms Jul 25, 2024
1f285ec
TOML: Make `Dates` a type parameter (#55017)
topolarity Jul 25, 2024
70af74e
Fix a bug in `stack`'s DimensionMismatch error message (#54033)
mcabbott Jul 25, 2024
bab4ef1
fix at-main docstring to not code quote a compat box (#55242)
KristofferC Jul 25, 2024
e7ddd62
Make `jl_*affinity` tests more portable (#55261)
ararslan Jul 27, 2024
e0b2828
specificity: ensure fast-path in `sub/eq_msp` handle missing `UnionAl…
N5N3 Jul 29, 2024
4381c05
typeintersect: fix bounds merging during inner `intersect_all` (#55299)
N5N3 Jul 30, 2024
b010b97
Add `lbt_forwarded_funcs()` to debug LBT forwarding issues (#55302)
staticfloat Jul 30, 2024
aacb1ca
Random: Mark unexported public symbols as public (#55148)
jakobnissen Jul 30, 2024
b0691b5
avoid overflowing show for OffsetArrays around typemax (#55303)
mbauman Jul 31, 2024
2b31eab
Restrict argument to `isleapyear(::Integer)` (#55317)
jariji Jul 31, 2024
78ed775
Profile: Fix stdlib paths (#55327)
IanButterworth Aug 1, 2024
6a5792d
[libblastrampoline] Bump to v5.11.0 (#55330)
staticfloat Aug 1, 2024
5431961
Preserve structure in scaling triangular matrices by NaN (#55310)
jishnub Aug 1, 2024
eaa792f
Add PGO/LTO Makefile to NEWS.md
giordano Aug 2, 2024
2f46f2b
🤖 [backports-release-1.11] Bump the Pkg stdlib from 8457d3eff to 2ff6…
DilumAluthgeBot Aug 5, 2024
46ed1ba
[build] Some improvements to the LLVM build system (#55354)
giordano Aug 6, 2024
cb7a962
Profile: close files when assembling heap snapshot (#55356)
topolarity Aug 3, 2024
8a4dd86
Fix tr for block SymTridiagonal (#55371)
jishnub Aug 5, 2024
885aeda
Make REPL.TerminalMenus and some if its symbols public (#55307)
GHTaarn Aug 5, 2024
9386218
inference: fix missing LimitedAccuracy markers (#55362)
vtjnash Aug 5, 2024
c802049
AllocOpt: Fix stack lowering where alloca continas boxed and unboxed …
wsmoses Aug 6, 2024
fbcb434
fix #55389: type-unstable `join` (#55395)
simeonschaub Aug 6, 2024
894454c
re-add `unsafe_convert` for Reinterpret and Reshaped array (#55226)
oscardssmith Aug 8, 2024
b7d4aeb
compiler: apply more accurate effects to return_type_tfunc (#55338)
vtjnash Aug 10, 2024
b29b9b5
handle unbound vars in NTuple fields (#55405)
vtjnash Aug 8, 2024
cc694e4
ml-matches: ensure all methods are included (#55365)
vtjnash Aug 8, 2024
d499694
codegen: move undef freeze before promotion point (#55428)
vtjnash Aug 9, 2024
99583cf
`stale_cachefile`: handle if the expected cache file is missing (#55419)
IanButterworth Aug 9, 2024
10b55db
Add push! implementation for AbstractArray depending only on resize! …
mkitti Aug 12, 2024
709d83e
fix hierarchy level of "API reference" in `Dates` documentation (#55483)
matthias314 Aug 13, 2024
403558e
fix a test that does not apply to 1.11 according to Jameson
Aug 14, 2024
86a5aee
simplify complex atanh and remove singularity perturbation (#55268)
oscardssmith Aug 13, 2024
133b83a
Backport https://github.com/JuliaLang/julia/pull/55407 to 1.11 (#55433)
gbaraldi Aug 14, 2024
bcb33ed
[release-1.11] fix GC race bug in pool sweep (#55485)
d-netto Aug 14, 2024
16a7ad9
compress jit debuginfo for easy memory savings (#55180)
vtjnash Jul 23, 2024
89faa35
mapreduce: don't inbounds unknown functions (#55329)
mbauman Aug 2, 2024
63c8445
fix Event to use normal Condition variable (#55441)
vtjnash Aug 14, 2024
b1e0fc4
subtyping: fast path for lhs union and rhs typevar (#55413)
vtjnash Aug 14, 2024
95e255f
build: add missing dependencies for expmap (#55492)
vtjnash Aug 15, 2024
876853b
Fix fast getptls ccall lowering. (#55507)
gbaraldi Aug 16, 2024
7a3e21f
Update symmetric docstring to reflect the type of uplo (#55504)
jishnub Aug 17, 2024
c9d09d6
Ensure bidiagonal setindex! does not read indices in error message (#…
jishnub Aug 3, 2024
07df4bb
Do not load `ScopedValues` with `using` (#55452)
LilithHafner Aug 15, 2024
0ccd4ed
add missing clamp function for IOBuffer (#55424)
KristofferC Aug 9, 2024
00b6831
Vendor the terminfo database for use with base/terminfo.jl (#55411)
ararslan Aug 8, 2024
28fcbff
codgen: make the Memory GEP an inbounds GEP (#55107)
gbaraldi Aug 8, 2024
4e7648f
Backport "Fix (l/r)mul! with Diagonal/Bidiagonal #55052" to v1.11 (#5…
jishnub Aug 19, 2024
44fc535
Restrict binary ops for Diagonal and Symmetric to Number eltypes (#55…
jishnub Jul 28, 2024
b09a4b3
Make `Base.depwarn()` public (#55212)
JamesWrigley Jul 25, 2024
8da6a94
LAPACK: Aggressive constprop to concretely infer syev!/syevd! (#55295)
jishnub Jul 30, 2024
8c60a17
🤖 [master] Bump the StyledStrings stdlib from d7496d2 to f6035eb (#55…
DilumAluthgeBot Aug 12, 2024
9723ff1
atomics: fix setonce runtime intrinsic
vtjnash Aug 19, 2024
7b18f9c
codegen: NFC refactoring to use Align type
vtjnash Aug 3, 2024
e964634
codegen: update type of x after type-assert
vtjnash Aug 3, 2024
8467772
codegen: take gc roots (and alloca alignment) more seriously
vtjnash Aug 1, 2024
13d440d
Backport "Fix tr for Symmetric/Hermitian block matrices #55522" to v1…
jishnub Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
compress jit debuginfo for easy memory savings (#55180)
In some ad-hoc testing, I had JIT about 19 MB of code and data, which
generated about 170 MB of debuginfo alongside it, and that debuginfo
then compressed to about 50 MB with this change, which simply compresses
the ObjectFile until it is actually required (which it very rarely is
needed).

(cherry picked from commit fe597c1)
vtjnash authored and KristofferC committed Aug 19, 2024
commit 16a7ad94dd3576c4d841985db5b484a6a1ee0d7b
22 changes: 15 additions & 7 deletions src/debug-registry.h
Original file line number Diff line number Diff line change
@@ -99,18 +99,26 @@ class JITDebugInfoRegistry
};
private:

struct ObjectInfo {
const llvm::object::ObjectFile *object = nullptr;
size_t SectionSize = 0;
ptrdiff_t slide = 0;
llvm::object::SectionRef Section{};
llvm::DIContext *context = nullptr;
struct LazyObjectInfo {
SmallVector<uint8_t, 0> data;
size_t uncompressedsize;
std::unique_ptr<const llvm::object::ObjectFile> object;
std::unique_ptr<llvm::DIContext> context;
LazyObjectInfo() = delete;
};

struct SectionInfo {
LazyObjectInfo *object;
size_t SectionSize;
ptrdiff_t slide;
uint64_t SectionIndex;
SectionInfo() = delete;
};

template<typename KeyT, typename ValT>
using rev_map = std::map<KeyT, ValT, std::greater<KeyT>>;

typedef rev_map<size_t, ObjectInfo> objectmap_t;
typedef rev_map<size_t, SectionInfo> objectmap_t;
typedef rev_map<uint64_t, objfileentry_t> objfilemap_t;

objectmap_t objectmap{};
57 changes: 42 additions & 15 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
#include <llvm/DebugInfo/DWARF/DWARFContext.h>
#include <llvm/Object/SymbolSize.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/Support/MemoryBufferRef.h>
#include <llvm/IR/Function.h>
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/StringMap.h>
@@ -335,8 +336,12 @@ void JITDebugInfoRegistry::registerJITObject(const object::ObjectFile &Object,
#endif // defined(_OS_X86_64_)
#endif // defined(_OS_WINDOWS_)

SmallVector<uint8_t, 0> packed;
compression::zlib::compress(ArrayRef<uint8_t>((uint8_t*)Object.getData().data(), Object.getData().size()), packed, compression::zlib::DefaultCompression);
jl_jit_add_bytes(packed.size());
auto ObjectCopy = new LazyObjectInfo{packed, Object.getData().size()}; // intentionally leaked so that we don't need to ref-count it, intentionally copied so that we exact-size the allocation (since no shrink_to_fit function)
auto symbols = object::computeSymbolSizes(Object);
bool first = true;
bool hassection = false;
for (const auto &sym_size : symbols) {
const object::SymbolRef &sym_iter = sym_size.first;
object::SymbolRef::Type SymbolType = cantFail(sym_iter.getType());
@@ -385,17 +390,17 @@ void JITDebugInfoRegistry::registerJITObject(const object::ObjectFile &Object,
jl_profile_atomic([&]() JL_NOTSAFEPOINT {
if (mi)
linfomap[Addr] = std::make_pair(Size, mi);
if (first) {
objectmap[SectionLoadAddr] = {&Object,
(size_t)SectionSize,
(ptrdiff_t)(SectionAddr - SectionLoadAddr),
*Section,
nullptr,
};
first = false;
}
hassection = true;
objectmap.insert(std::pair{SectionLoadAddr, SectionInfo{
ObjectCopy,
(size_t)SectionSize,
(ptrdiff_t)(SectionAddr - SectionLoadAddr),
Section->getIndex()
}});
});
}
if (!hassection) // clang-sa demands that we do this to fool cplusplus.NewDeleteLeaks
delete ObjectCopy;
}

void jl_register_jit_object(const object::ObjectFile &Object,
@@ -1213,11 +1218,33 @@ int jl_DI_for_fptr(uint64_t fptr, uint64_t *symsize, int64_t *slide,
auto fit = objmap.lower_bound(fptr);
if (fit != objmap.end() && fptr < fit->first + fit->second.SectionSize) {
*slide = fit->second.slide;
*Section = fit->second.Section;
if (context) {
if (fit->second.context == nullptr)
fit->second.context = DWARFContext::create(*fit->second.object).release();
*context = fit->second.context;
auto lazyobject = fit->second.object;
if (!lazyobject->object && !lazyobject->data.empty()) {
if (lazyobject->uncompressedsize) {
SmallVector<uint8_t, 0> unpacked;
Error E = compression::zlib::decompress(lazyobject->data, unpacked, lazyobject->uncompressedsize);
if (E)
lazyobject->data.clear();
else
lazyobject->data = std::move(unpacked);
jl_jit_add_bytes(lazyobject->data.size() - lazyobject->uncompressedsize);
lazyobject->uncompressedsize = 0;
}
if (!lazyobject->data.empty()) {
auto obj = object::ObjectFile::createObjectFile(MemoryBufferRef(StringRef((const char*)lazyobject->data.data(), lazyobject->data.size()), "jit.o"));
if (obj)
lazyobject->object = std::move(*obj);
else
lazyobject->data.clear();
}
}
if (lazyobject->object) {
*Section = *std::next(lazyobject->object->section_begin(), fit->second.SectionIndex);
if (context) {
if (lazyobject->context == nullptr)
lazyobject->context = DWARFContext::create(*lazyobject->object);
*context = lazyobject->context.get();
}
}
found = 1;
}
1 change: 1 addition & 0 deletions src/debuginfo.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is a part of Julia. License is MIT: https://julialang.org/license

// Declarations for debuginfo.cpp
void jl_jit_add_bytes(size_t bytes) JL_NOTSAFEPOINT;

int jl_DI_for_fptr(uint64_t fptr, uint64_t *symsize, int64_t *slide,
llvm::object::SectionRef *Section, llvm::DIContext **context) JL_NOTSAFEPOINT;
93 changes: 34 additions & 59 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
@@ -800,22 +800,19 @@ struct JITObjectInfo {
class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
std::mutex PluginMutex;
std::map<MaterializationResponsibility *, std::unique_ptr<JITObjectInfo>> PendingObjs;
// Resources from distinct `MaterializationResponsibility`s can get merged
// after emission, so we can have multiple debug objects per resource key.
std::map<ResourceKey, SmallVector<std::unique_ptr<JITObjectInfo>, 0>> RegisteredObjs;

public:
void notifyMaterializing(MaterializationResponsibility &MR, jitlink::LinkGraph &G,
jitlink::JITLinkContext &Ctx,
MemoryBufferRef InputObject) override
{
// Keeping around a full copy of the input object file (and re-parsing it) is
// wasteful, but for now, this lets us reuse the existing debuginfo.cpp code.
// Should look into just directly pulling out all the information required in
// a JITLink pass and just keeping the required tables/DWARF sections around
// (perhaps using the LLVM DebuggerSupportPlugin as a reference).
auto NewBuffer =
MemoryBuffer::getMemBufferCopy(InputObject.getBuffer(), G.getName());
// Re-parsing the InputObject is wasteful, but for now, this lets us
// reuse the existing debuginfo.cpp code. Should look into just
// directly pulling out all the information required in a JITLink pass
// and just keeping the required tables/DWARF sections around (perhaps
// using the LLVM DebuggerSupportPlugin as a reference).
auto NewObj =
cantFail(object::ObjectFile::createObjectFile(NewBuffer->getMemBufferRef()));

@@ -849,13 +846,8 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
};

jl_register_jit_object(*NewInfo->Object, getLoadAddress, nullptr);
}

cantFail(MR.withResourceKeyDo([&](ResourceKey K) {
std::lock_guard<std::mutex> lock(PluginMutex);
RegisteredObjs[K].push_back(std::move(PendingObjs[&MR]));
PendingObjs.erase(&MR);
}));
}

return Error::success();
}
@@ -866,32 +858,23 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
PendingObjs.erase(&MR);
return Error::success();
}

#if JL_LLVM_VERSION >= 160000
Error notifyRemovingResources(JITDylib &JD, orc::ResourceKey K) override
#else
Error notifyRemovingResources(ResourceKey K) override
Error notifyRemovingResources(orc::ResourceKey K) override
#endif
{
std::lock_guard<std::mutex> lock(PluginMutex);
RegisteredObjs.erase(K);
// TODO: If we ever unload code, need to notify debuginfo registry.
return Error::success();
}

#if JL_LLVM_VERSION >= 160000
void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) override
void notifyTransferringResources(JITDylib &JD, orc::ResourceKey DstKey,
orc::ResourceKey SrcKey) override {}
#else
void notifyTransferringResources(ResourceKey DstKey, ResourceKey SrcKey) override
void notifyTransferringResources(orc::ResourceKey DstKey,
orc::ResourceKey SrcKey) override {}
#endif
{
std::lock_guard<std::mutex> lock(PluginMutex);
auto SrcIt = RegisteredObjs.find(SrcKey);
if (SrcIt != RegisteredObjs.end()) {
for (std::unique_ptr<JITObjectInfo> &Info : SrcIt->second)
RegisteredObjs[DstKey].push_back(std::move(Info));
RegisteredObjs.erase(SrcIt);
}
}

void modifyPassConfig(MaterializationResponsibility &MR, jitlink::LinkGraph &,
jitlink::PassConfiguration &PassConfig) override
@@ -931,12 +914,12 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {

class JLMemoryUsagePlugin : public ObjectLinkingLayer::Plugin {
private:
std::atomic<size_t> &total_size;
std::atomic<size_t> &jit_bytes_size;

public:

JLMemoryUsagePlugin(std::atomic<size_t> &total_size)
: total_size(total_size) {}
JLMemoryUsagePlugin(std::atomic<size_t> &jit_bytes_size)
: jit_bytes_size(jit_bytes_size) {}

Error notifyFailed(orc::MaterializationResponsibility &MR) override {
return Error::success();
@@ -985,7 +968,7 @@ class JLMemoryUsagePlugin : public ObjectLinkingLayer::Plugin {
}
(void) code_size;
(void) data_size;
this->total_size.fetch_add(graph_size, std::memory_order_relaxed);
this->jit_bytes_size.fetch_add(graph_size, std::memory_order_relaxed);
jl_timing_counter_inc(JL_TIMING_COUNTER_JITSize, graph_size);
jl_timing_counter_inc(JL_TIMING_COUNTER_JITCodeSize, code_size);
jl_timing_counter_inc(JL_TIMING_COUNTER_JITDataSize, data_size);
@@ -1101,24 +1084,7 @@ void registerRTDyldJITObject(const object::ObjectFile &Object,
const RuntimeDyld::LoadedObjectInfo &L,
const std::shared_ptr<RTDyldMemoryManager> &MemMgr)
{
auto SavedObject = L.getObjectForDebug(Object).takeBinary();
// If the debug object is unavailable, save (a copy of) the original object
// for our backtraces.
// This copy seems unfortunate, but there doesn't seem to be a way to take
// ownership of the original buffer.
if (!SavedObject.first) {
auto NewBuffer =
MemoryBuffer::getMemBufferCopy(Object.getData(), Object.getFileName());
auto NewObj =
cantFail(object::ObjectFile::createObjectFile(NewBuffer->getMemBufferRef()));
SavedObject = std::make_pair(std::move(NewObj), std::move(NewBuffer));
}
const object::ObjectFile *DebugObj = SavedObject.first.release();
SavedObject.second.release();

StringMap<object::SectionRef> loadedSections;
// Use the original Object, not the DebugObject, as this is used for the
// RuntimeDyld::LoadedObjectInfo lookup.
for (const object::SectionRef &lSection : Object.sections()) {
auto sName = lSection.getName();
if (sName) {
@@ -1135,7 +1101,9 @@ void registerRTDyldJITObject(const object::ObjectFile &Object,
return L.getSectionLoadAddress(search->second);
};

jl_register_jit_object(*DebugObj, getLoadAddress,
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.
jl_register_jit_object(DebugObject.getBinary() ? *DebugObject.getBinary() : Object,
getLoadAddress,
#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_)
[MemMgr](void *p) { return lookupWriteAddressFor(MemMgr.get(), p); }
#else
@@ -1737,7 +1705,7 @@ JuliaOJIT::JuliaOJIT()
ES, std::move(ehRegistrar)));

ObjectLayer.addPlugin(std::make_unique<JLDebuginfoPlugin>());
ObjectLayer.addPlugin(std::make_unique<JLMemoryUsagePlugin>(total_size));
ObjectLayer.addPlugin(std::make_unique<JLMemoryUsagePlugin>(jit_bytes_size));
#else
ObjectLayer.setNotifyLoaded(
[this](orc::MaterializationResponsibility &MR,
@@ -2058,19 +2026,20 @@ std::string JuliaOJIT::getMangledName(const GlobalValue *GV)
return getMangledName(GV->getName());
}

#ifdef JL_USE_JITLINK
size_t JuliaOJIT::getTotalBytes() const
{
return total_size.load(std::memory_order_relaxed);
auto bytes = jit_bytes_size.load(std::memory_order_relaxed);
#ifndef JL_USE_JITLINK
size_t getRTDyldMemoryManagerTotalBytes(RTDyldMemoryManager *mm) JL_NOTSAFEPOINT;
bytes += getRTDyldMemoryManagerTotalBytes(MemMgr.get());
#endif
return bytes;
}
#else
size_t getRTDyldMemoryManagerTotalBytes(RTDyldMemoryManager *mm) JL_NOTSAFEPOINT;

size_t JuliaOJIT::getTotalBytes() const
void JuliaOJIT::addBytes(size_t bytes)
{
return getRTDyldMemoryManagerTotalBytes(MemMgr.get());
jit_bytes_size.fetch_add(bytes, std::memory_order_relaxed);
}
#endif

void JuliaOJIT::printTimers()
{
@@ -2348,3 +2317,9 @@ size_t jl_jit_total_bytes_impl(void)
{
return jl_ExecutionEngine->getTotalBytes();
}

// API for adding bytes to record being owned by the JIT
void jl_jit_add_bytes(size_t bytes)
{
jl_ExecutionEngine->addBytes(bytes);
}
3 changes: 2 additions & 1 deletion src/jitlayers.h
Original file line number Diff line number Diff line change
@@ -553,6 +553,7 @@ class JuliaOJIT {
TargetIRAnalysis getTargetIRAnalysis() const JL_NOTSAFEPOINT;

size_t getTotalBytes() const JL_NOTSAFEPOINT;
void addBytes(size_t bytes) JL_NOTSAFEPOINT;
void printTimers() JL_NOTSAFEPOINT;

jl_locked_stream &get_dump_emitted_mi_name_stream() JL_NOTSAFEPOINT {
@@ -597,10 +598,10 @@ class JuliaOJIT {

ResourcePool<orc::ThreadSafeContext, 0, std::queue<orc::ThreadSafeContext>> ContextPool;

std::atomic<size_t> jit_bytes_size{0};
#ifndef JL_USE_JITLINK
const std::shared_ptr<RTDyldMemoryManager> MemMgr;
#else
std::atomic<size_t> total_size{0};
const std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr;
#endif
ObjLayerT ObjectLayer;