-
Notifications
You must be signed in to change notification settings - Fork 70
Fix JNI caching for native threads #464
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
|
Lgtm, we may want to consider making thr init throwing but that may be annoying for now. Class not found do happen and perhaps should not crash the whole process tbh, depending what were tryint to find |
| self.javaObjectHolder = nil | ||
| } else { | ||
| // Clear any ClassNotFound exceptions from FindClass | ||
| environment.interface.ExceptionClear(environment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right, good catch
| /// An optional reference to a java object holder | ||
| /// if we cached this class through the class loader | ||
| /// This is to make sure that the underlying reference remains valid | ||
| nonisolated(unsafe) private let javaObjectHolder: JavaObjectHolder? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was the nonisolated unsafe necessary actually?
Co-authored-by: pelekon <13712101+pelekon@users.noreply.github.com> Co-authored-by: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Co-authored-by: Bartłomiej Bukowiecki <pelekon@users.noreply.github.com> Fix `allowGlobalAutomatic` mode for interfaces (swiftlang#466) Fix JNI caching for native threads (swiftlang#464) fix extensions (swiftlang#473) fix protocols that return java classes. (swiftlang#479)
* config: log-level should encode as string * Properly handle nested directories of Swift Sources in jextract * wip * fix test and cleanup (#1) Co-authored-by: pelekon <13712101+pelekon@users.noreply.github.com> Co-authored-by: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Co-authored-by: Bartłomiej Bukowiecki <pelekon@users.noreply.github.com> Fix `allowGlobalAutomatic` mode for interfaces (#466) Fix JNI caching for native threads (#464) fix extensions (#473) fix protocols that return java classes. (#479) --------- Co-authored-by: Mads Odgaard <mads@madsodgaard.com> Co-authored-by: pelekon <13712101+pelekon@users.noreply.github.com> Co-authored-by: Bartłomiej Bukowiecki <pelekon@users.noreply.github.com>
environment.FindClassdoes not work when ran on native threads, such as is in the case of when we bridgeasyncfunctions. As that function uses the caller class loader (which of course is not the application loader in native threads)Therefore, we need the application class loader in order to cache non-system classes. As recommended in the Android docs, we store the application class loader on
JNI_OnLoad, and use that to reference any classes. We also need thisJNI_OnLoadin the future to fix #419 - so this is a nice start, but this PR does not fix that issue.This is needed to make #462 work