[JExtract/JNI] Add auto arena to SwiftKitCore and add memory management options#353
Merged
Merged
Conversation
ktoso
reviewed
Aug 7, 2025
ktoso
reviewed
Aug 7, 2025
ktoso
reviewed
Aug 7, 2025
ktoso
reviewed
Aug 7, 2025
ktoso
reviewed
Aug 7, 2025
ktoso
reviewed
Aug 7, 2025
ktoso
reviewed
Aug 7, 2025
ktoso
reviewed
Aug 7, 2025
Collaborator
|
Pretty good, I think that'd be okey -- some comments inline. I remain unclear about which android versions don't / do have this, so that may be worth double checking before we commit our own cleaner like things but we could do this if we need to. |
auto arena to SwiftKitCore and add memory management optionsauto arena to SwiftKitCore and add memory management options
Contributor
Author
|
@ktoso It was first added in API level 33: https://developer.android.com/reference/java/lang/ref/Cleaner |
Collaborator
|
I see, and we're trying to support 28/29+ I guess... Let's take this then |
ktoso
approved these changes
Aug 7, 2025
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.
Since
java.lang.ref.Cleaneris not available in Android (before API 33), we introduce our ownCleanerwhich is very similar to the original JDK implementation, but a few simplications for our use case. This allows us to introduce theAutoarena to the JNI mode throughSwiftArena.ofAuto().Note: The
SwiftKitFFMstill uses the JDKCleaner, this is only for the JNI/SwiftKitCore library.In an ideal world we would somehow differentiate between users needing to support Android (use our own) and people just running on regular JVM (then we use the original
Cleaner) - perhaps that is something we could look into in the future, by providing an Android "compatibility" library ofSwiftKitCore.On top of that we introduce a new "memory management mode". This mode can be specified using
--memory-management-modeand has the following options:explicit(default): Generates only wrappers that require explicit passing ofSwifttArenaallow-global-automatic: Generates wrappers that use a default global auto arena, but also explicit APIs.This option is only supported in JNI for now.
Resolves #318