-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Improved Java phantom references #7131
Merged
NikolajBjorner
merged 7 commits into
Z3Prover:master
from
ThomasHaas:java_phantom_references
Feb 21, 2024
Merged
Improved Java phantom references #7131
NikolajBjorner
merged 7 commits into
Z3Prover:master
from
ThomasHaas:java_phantom_references
Feb 21, 2024
Conversation
This file contains 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
- Replaced IDecRefQueue with a new Z3ReferenceQueue class - Z3ReferenceQueue manages custom subclasses of phantom references in a doubly-linked list - Replaced all subclasses of IDecRefQueue with subclasses of Z3ReferenceQueue.Reference. These custom reference classes are embedded in the class they reference count. - Context now owns a single Z3ReferenceQueue for all types of references.
Do I need to change update the python scripts that build the .jar (I don't know why the CI fails)? |
Need to update CMakeLists.txt for cmake build |
Thanks, I will check with java examples manually around Tuesday. I am not sure they get tested on the build. |
NikolajBjorner
pushed a commit
that referenced
this pull request
Feb 21, 2024
* Reworked phantom reference handling. - Replaced IDecRefQueue with a new Z3ReferenceQueue class - Z3ReferenceQueue manages custom subclasses of phantom references in a doubly-linked list - Replaced all subclasses of IDecRefQueue with subclasses of Z3ReferenceQueue.Reference. These custom reference classes are embedded in the class they reference count. - Context now owns a single Z3ReferenceQueue for all types of references. * Made Statistics.Entry a static subclass * Made Context.close idempotent (as recommended) * Update CMakeLists.txt for building the Java API. * Updated CMakeLists.txt again. * Use correct SuppressWarning annotation to silence the compiler * Formatting
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.
This PR reworks the handling of phantom references in the Z3 API.
The previous implementation used
N
different reference queues, each with aIdentityHashMap
to associate to each phantom reference the native z3 object it reference counts.In some extreme cases, the
IdentityHashMap
's performance could degenerate, for example, if a user propagator creates millions of formulas in a short time (everyfixed
-callback creates at least 2 phantom references right now!)Furthemore, Java's
IdentityHashMap
does not implement shrinking, so that the map can permanently consume a lot of memory even if emptied.The new implementation replaces the hashmap with a doubly-linked list consisting of custom subclasses of phantom references.
Advantages:
long
.O(n)
map enlargements, and no high access times in degenerate cases with high number of hash collisions)N
different reference queues are combined into a single reference queue for all objects (managed byContext
). Instead, there areN
different implementations(*) ofPhantomReference
all of which are directly inlined in the class they reference count (e.g.AST
containsASTRef
). This puts the implementation ofincRef
anddecRef
in the same class for better maintainability.Disadvantages:
(*) There is an even easier implementation that uses a single
PhantomReference
implementation that stores a method reference to thedecRef
implementation (rather than using subclassing). This variant stores an extra pointer per reference which increases memory consumption by ~14%and makes the implementation not strictly more memory efficient than(EDIT: it is still strictly better since it avoids the boxing of aIdentityHashMap
(in most practical cases it will still be better)long
).Disclaimer: I have not yet tested the correctness of this new implementation. However, I have implemented and tested a slightly easier version in JavaSMT (this version reference counts only AST objects). Still, some testing should be done before merging.