-
Notifications
You must be signed in to change notification settings - Fork 30
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
Getting the GC to work #81
Comments
Not sure how to do this, but seems like progress! |
Any progress here? Compiling an executable from arbitrary Julia code that uses libjulia / gc would be a game changer for portability. I love the idea of using Julia for compiled use cases, I think it opens so many doors for the language. |
This is about getting "the GC" to work, but I realized there's LLVM GC. There's also MMTK standalone project, and also there work to get it into Julia as an alternative. https://www.llvm.org/docs/GarbageCollection.html To quote @jpsamaroo
I think he's right, and we have, and need non-moving only (because of ccall), but it doesn't need to be Julia's implementation. I think it might be easy, even trivial(?) to use some others, e.g. from LLVM. I'm not pushing for it, and I understand if you do not want a 3rd option. I'm just thinking, while the Julia implementation is devorsable from the runtime, maybe not easily. And Julia doesn't simply use Libc.malloc, i.e. from libc, but rather all (regular) allocations go though Julia now. That's something I would want to change too, so that some other better allocators can be used as drop-in replacements. I think that might be already possible with your project. Since GC runs (potentially) when allocation is done (and never otherwise, except in specialized real-time implementations; threading may also be an issue, but you don't support anyway, yet), I think it's trivial to add GC into it, i.e. rather call something that does both GC if needed, and calls libc. Ideally it will just call malloc in libc (dynamically), i.e. not try to implement its own pool, then the alternative malloc would still work I believe with the GC. |
GC might work already for your project without any changes to it:
I.e it just needs to be used, and as I explained, I think it just needs, and can, take over malloc (and makes free a noop): Otherwise from the page:
I got too exited and carried away thinking LLVM provides an implementation. What they have seems/ed redundant, and I think it is if you do not have threads and only need Boehm. Probably in some other situations you need what it provides. E.g for reference counting, that we wouldn't want to use, it can't be transparent I think, nor is it always faster. We would want "generational" and/or incremental. Possibly concurrent (later?) and I'm not sure what they have in mind with "cooperative collectors". Except there's MemBalance, quite exiting from a year ago, already implemented in Julia, but with a bug, so it will be reverted for 1.10. It's unclear the bug will be fixed in time. The woman behind it offered to help. |
Julia's codegen is tightly coupled to Julia precise GC implementation. I see no reason why you wouldn't just use the Julia GC... You could implement your own final-lower pass, but YMMV |
So currently we aren't able to do GC allocations outside of
compile
which requires a running julia session. Ideally we should be able to link a binary tolibjulia
or some version of it, instead of having the whole runtime i.ePackageCompiler
.As a hack me and @brenhinkeller managed to link to it and call
jl_init
, and when calling some functions from the runtime we fail with some stacktraces deep inlibjulia
which is promising.Together with JuliaGPU/GPUCompiler.jl#348, the code actually gets into the GC functions and somewhere inside it finally segfaults.
Some of these segfaults are because some global variables like types get initialized as
null
, and when the sysimg is being processed their actual values are substituted in. In GPUCompiler that doesn't happen so we gt IR withnull
where it shouldn't be a null.That leads to a segfault, we need to find a way to turn that
null
into a pointer to the correctjl_value_t
, which should beArray(Int64,1}
The IR before removing the globals looks like:
The text was updated successfully, but these errors were encountered: