Repository navigation
Redline native lifetime - #258
Merged
andreaTP merged 20 commits intoOct 30, 2026
Merged
Conversation
andreaTP
force-pushed
the
redline-native-lifetime
branch
from
October 27, 2026 15:26
786d1b9 to
e0cba00
Compare
Contributor
Author
|
I think this is the way to go, I'll close #236 and I'll move on with this design, redline is still experimental, so we can iterate if we find any gap. |
andreaTP
marked this pull request as ready for review
October 28, 2026 12:57
andreaTP
commented
Oct 30, 2026
andreaTP
left a comment
Contributor
Author
There was a problem hiding this comment.
LGTM, ready to merge when CI is green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #203. An alternative to #236: Redline's native state is freed by the garbage collector once nothing references it, like everything else in Endive, instead of being owned and freed by
close().Why
Compiled code reaches imported memories and tables by raw address, so freeing them in
close()needs ownership tracking: ordered closes, refused closes, a call/close handshake. And an instance nobody closes still leaks, which is #203. The JVM already knows who uses what. The only thing stopping the collector was that upcall stubs and closures held their machine strongly.How
Cleaneraction and fences its accesses.close()stops the instance. It never refuses and frees nothing, so held memories, tables and globals keep working.-Dendive.redline.gcThreshold), as the JDK does for direct buffers.Fixed along the way:
CallContextper function per instance.table.growfill left entries unset.mprotect.Behavior changes
close()frees nothing; native memory goes once unreferenced. With-XX:+DisableExplicitGCthat waits for a collection that happens anyway.withMemoryLimitsrejects limits that change whether the memory is shared.Measured
Peak RSS when building 200 Javy instances, about 11.5 MB of native memory each, on JDK 25:
Without
close(), #236 still holds 2.6 GB afterSystem.gc(); here everything is freed. With long-lived instances under G1, Serial and ZGC, native memory stays within about twice the live set, at 0.5 to 2 ms of extra collection time per instance.Testing
Both runners run the Redline tests and the spec suite on JDK 25, and the jffi runner also runs on JDK 21. New lifecycle tests check:
close()works from inside a call and from another thread;