Skip to content

Moving GC Extensions to Julia's FFI#95

Merged
d-netto merged 1 commit intommtk-support-moving-upstreamfrom
dcn-ffi-extensions
Aug 21, 2025
Merged

Moving GC Extensions to Julia's FFI#95
d-netto merged 1 commit intommtk-support-moving-upstreamfrom
dcn-ffi-extensions

Conversation

@d-netto
Copy link
Collaborator

@d-netto d-netto commented Aug 19, 2025

This PR implements the APIs proposed in our Julep.

In the next few days, I plan to start using these APIs to fix a few JuliaLang tests (e.g. Downloads.jl) that are failing due to incorrect memory management in foreign function calls.

The initial implementation of these APIs is fairly simple: it uses two global maps to store objects and their pinning/transitive pinning counts. It's probably not the most performant implementation, but should be good enough for us to start fixing a few tests.

For now, the APIs are only available in our fork, so we have some flexibility to adjust function names, semantics, etc. before committing to a final version.

@d-netto d-netto requested review from qinsoon and udesou August 19, 2025 22:20
@d-netto
Copy link
Collaborator Author

d-netto commented Aug 20, 2025

@qinsoon, @udesou: could you folks please review this PR?

Would be great if we could merge in the next few days, since we'll need these extensions to fix tests that are failing in the FFI.

@qinsoon
Copy link
Member

qinsoon commented Aug 20, 2025

Possibly in the future, the pin count could be directly stored with MMTk for each object, and we don't need a table for it. The API seems to allow this as well, which is good.

@qinsoon
Copy link
Member

qinsoon commented Aug 20, 2025

I think we can merge this.

@d-netto
Copy link
Collaborator Author

d-netto commented Aug 20, 2025

I think we can merge this.

Perfect. Thanks, @qinsoon.

Any thoughts @udesou?

@udesou
Copy link

udesou commented Aug 20, 2025

I think we can merge this.

Perfect. Thanks, @qinsoon.

Any thoughts @udesou?

LGTM too. As Yi said, we might want to implement this on the binding side of things, but it doesn't matter for now.

@d-netto d-netto merged commit d2f7ee7 into mmtk-support-moving-upstream Aug 21, 2025
4 checks passed
Comment on lines +54 to +56
function decrement_pin_count!(obj)
ccall(:jl_decrement_pin_count, Cvoid, (Any,), obj)
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should throw if you try to dec something that's not pinned.

Otherwise it will be easy to accidentally increment_pin but decrement_tpin

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'd probs change the c function to return the new count or -1 if not foudn)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants