Replace ThreadLocal stack with ScopedValue #336
No reviewers
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
java
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
java-gi/java-gi!336
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "scoped-value"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is a small optimization in the InstanceCache. There is no functional impact.
When a new GObject subclass is constructed from Java, the Java object exists before the native instance. The native instance is then created by
g_object_new, which calls back into the JVM for theinstace_init_func. That causes an automatic type lookup in the Java-GI InstanceCache class. At that point we've lost track of the original Java instance, causing all sorts of trouble.To solve this, I previously used a stack of "objects under construction" in a ThreadLocal field. Since the upgrade to JDK 25, we can instead use a ScopedValue. The ThreadLocal stack implementation has been removed because ScopedValues can be safely nested.