Skip to content

Commit 81ab4fc

Browse files
xal-0KristofferC
authored andcommitted
aotcompile: destroy LLVM context after serializing combined module (#59329)
We already save some memory here by deleting the `jl_native_code_desc_t` after we're done serializing the combined module, but some data in the module's `LLVM::Context` lives on until the end of the scope in `jl_dump_native_impl`. Once we're done with the module, move the lock and `ThreadSafeContext` so the reference count drops to zero. A crude measurement shows that when compiling the Base sysimage, about 3 GiB is in use. Deleting the `jl_native_code_desc_t` (as before) saves about 600 MiB, and cleaning up the context saves an additional ~500 MiB. (cherry picked from commit ceeb661)
1 parent 7ea7202 commit 81ab4fc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/aotcompile.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,9 +2169,14 @@ void jl_dump_native_impl(void *native_code,
21692169
auto lock = TSCtx.getLock();
21702170
auto dataM = data->M.getModuleUnlocked();
21712171

2172-
// Delete data when add_output thinks it's done with it
2173-
// Saves memory for use when multithreading
2174-
data_outputs = compile(*dataM, "text", threads, [data](Module &) { delete data; });
2172+
data_outputs = compile(*dataM, "text", threads, [data, &lock, &TSCtx](Module &) {
2173+
// Delete data when add_output thinks it's done with it
2174+
// Saves memory for use when multithreading
2175+
auto lock2 = std::move(lock);
2176+
delete data;
2177+
// Drop last reference to shared LLVM::Context
2178+
auto TSCtx2 = std::move(TSCtx);
2179+
});
21752180
}
21762181

21772182
if (params->emit_metadata) {

0 commit comments

Comments
 (0)