Skip to content

[jnigen] Clean up .reference.pointer pattern#3350

Open
liamappelbe wants to merge 3 commits intomainfrom
jnigen_reference
Open

[jnigen] Clean up .reference.pointer pattern#3350
liamappelbe wants to merge 3 commits intomainfrom
jnigen_reference

Conversation

@liamappelbe
Copy link
Copy Markdown
Contributor

For the most part, JNIgen was already storing all foo.reference.pointers in a local variable. There were just a few remaining cases: the class reference for static methods, the self reference for non-static methods, and one other random case in kotlin suspend functions. Not sure if these cases can hit the same GC issue, but I'm switching them to locals just to be safe.

Fixes #3346

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
jni None 1.0.0 1.0.1-wip 1.0.1-wip ✔️
jni_flutter None 1.0.1 1.0.1 1.0.1 ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ⚠️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources
jni $JIterator core_bindings.dart::JIterator::implementIn::$impl
core_bindings.dart::JIterator::implement::$impl
jni $JCollection core_bindings.dart::JCollection::implementIn::$impl
core_bindings.dart::JCollection::implement::$impl
jni $JList core_bindings.dart::JList::implementIn::$impl
core_bindings.dart::JList::implement::$impl
jni $JMap$JEntry core_bindings.dart::JMap$JEntry::implementIn::$impl
core_bindings.dart::JMap$JEntry::implement::$impl
jni $JMap core_bindings.dart::JMap::implementIn::$impl
core_bindings.dart::JMap::implement::$impl
jni $JSet core_bindings.dart::JSet::implementIn::$impl
core_bindings.dart::JSet::implement::$impl

This check can be disabled by tagging the PR with skip-leaking-check.

@liamappelbe liamappelbe marked this pull request as ready for review May 7, 2026 05:50
@liamappelbe liamappelbe requested review from dcharkes and goderbauer May 7, 2026 05:53
return _new$(_class.reference.pointer, _id_new$.pointer)
.object<Notifications>();
final _$$classRef = _class.reference;
return _new$(_$$classRef.pointer, _id_new$.pointer).object<Notifications>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The before and after code looks semantically identical. Why do we need to rewrite these?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this a work around for a bug that should ideally be fixed in the dart SDK (e.g. what Daco is also saying in #3342 (comment)?)?

If so, do we have an upstream issue that we could link in a TODO in dart_generator.dart to make it more explicit why we pull the reference out into a variable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's a bug in FinalizableTransformer (filed one). We should fix it, but I'm not sure how hard it'll be to fix. In any case we'll need this work around in the short term.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[jnigen] Remove .reference.pointer from all JNIgen codegen

2 participants