Repository navigation
Release discarded library class loaders retained by cached options - #1743
Open
curforever wants to merge 1 commit into
Open
curforever wants to merge 1 commit into
curforever wants to merge 1 commit into
Conversation
Generated-by: OpenAI Codex
Member
Does this mean the code was generated from Codex and not test/reviewed by you? |
| Bug Fixes | ||
| --------- | ||
|
|
||
| * Allow discarded library class loaders to be collected on JVMs by associating cached options with their classes. Android retains the existing cache for compatibility with runtimes without `ClassValue`. See [#1742](https://github.com/java-native-access/jna/issues/1742). |
Member
There was a problem hiding this comment.
Please follow the established format you can see in the entry directly below this entry.
This branch has not been deployed
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.
Closes #1742.
Native.typeOptionshas weak Class keys but strong option-map values. Itsenclosing-libraryvalue references the library Class; a child-loaded TypeMapper or an explicit CLASSLOADER option can also retain the loader. Consequently discarded library class loaders remain reachable through the static cache.Associate cached options with their Class using
ClassValue<AtomicReference<Map<String,Object>>>on JVMs. The reference preserves get/put visibility and the existing shared options-map identity, including nested classes. Public APIs, JNI and other caches remain unchanged.Older Android runtimes lack ClassValue. They retain the existing weak-map implementation in a separate backend; this change does not fix the Android cache leak. Include a narrowly scoped
-dontwarn java.lang.ClassValueconsumer rule in JARs and the AAR, since the unused JVM backend otherwise causes R8 to reject an old Android boot class path. Three build.xml resource-packaging lines implement that compatibility requirement.Validation on Windows:
abscall through an isolated loader: default options, child-loaded mapper, explicit loader option, and live-class options retention. Same final tests: 3 failures before / 4 passing after; all four also pass on Java8 and Java21. GC collection checks use bounded waits.ant -D-native=true distsucceeds, including platform compilation and Javadoc. Java release8 remains unchanged; Java-only changes use the upstream JNI binary, as allowed by CONTRIBUTING. Unchanged testlib sources were compiled locally for native tests.Implementation and validation were assisted by OpenAI Codex. No human review or full platform/native/Android matrix pass is claimed.