Cleanup how we handle local references in JNI interactions#616
Merged
ktoso merged 12 commits intoswiftlang:mainfrom Mar 17, 2026
Merged
Cleanup how we handle local references in JNI interactions#616ktoso merged 12 commits intoswiftlang:mainfrom
ktoso merged 12 commits intoswiftlang:mainfrom
Conversation
ktoso
reviewed
Mar 12, 2026
ktoso
approved these changes
Mar 12, 2026
Collaborator
|
I'll give this a closer look actually tomorrow |
ktoso
reviewed
Mar 16, 2026
Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift
Outdated
Show resolved
Hide resolved
ktoso
reviewed
Mar 16, 2026
Contributor
Author
|
@ktoso I updated to use the new frame helpers when we generate protocol wrappers. On top of that, I actually removed the frame helpers from the method calls. Those should be handled by the other I've tested these changes on our Android devices, and it no longer crashes 👍 |
ktoso
reviewed
Mar 17, 2026
Collaborator
ktoso
left a comment
There was a problem hiding this comment.
Thanks, looks better now 👍 Nice to use the withLocalFrame and friends too :)
I suspect we'll have to investigate these more in the future but this looks like a good first step, thanksyou
ktoso
approved these changes
Mar 17, 2026
Collaborator
|
Renamed the PR for future changelog, sorry :) |
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.
We were hitting "JNI ERROR (app bug): local reference table overflow (max=512)".
In order to improve this, I've added some
DeleteLocalRefsand explicitPush/Popof local frames to SwiftJava where I saw fit.These changes made our app stopping crashing with that error.
This also modifies the "implement Swift protocols in Java" generated wrappers, such that all calls are wrapped in a local frame to ensure that resources are cleaned up, as this might not be called from a JVM thread and be auto-cleaned.