-
Notifications
You must be signed in to change notification settings - Fork 50
[JExtract/JNI] Add auto
arena to SwiftKitCore and add memory management options
#353
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
Conversation
Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift
Outdated
Show resolved
Hide resolved
Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+JavaBindingsPrinting.swift
Outdated
Show resolved
Hide resolved
SwiftKitCore/src/main/java/org/swift/swiftkit/core/ref/Cleaner.java
Outdated
Show resolved
Hide resolved
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
@ktoso It was first added in API level 33: https://developer.android.com/reference/java/lang/ref/Cleaner |
I see, and we're trying to support 28/29+ I guess... Let's take this then |
Since
java.lang.ref.Cleaner
is not available in Android (before API 33), we introduce our ownCleaner
which is very similar to the original JDK implementation, but a few simplications for our use case. This allows us to introduce theAuto
arena to the JNI mode throughSwiftArena.ofAuto()
.Note: The
SwiftKitFFM
still 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-mode
and has the following options:explicit
(default): Generates only wrappers that require explicit passing ofSwifttArena
allow-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