mirror of
https://github.com/Z3Prover/z3
synced 2026-02-22 16:27:37 +00:00
Improved Java phantom references (#7131)
* 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
This commit is contained in:
parent
f7691d34fd
commit
a3d00ce356
41 changed files with 448 additions and 805 deletions
|
|
@ -19,6 +19,8 @@ package com.microsoft.z3;
|
|||
|
||||
import com.microsoft.z3.enumerations.Z3_ast_kind;
|
||||
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
|
||||
/**
|
||||
* The abstract syntax tree (AST) class.
|
||||
**/
|
||||
|
|
@ -196,7 +198,7 @@ public class AST extends Z3Object implements Comparable<AST>
|
|||
|
||||
@Override
|
||||
void addToReferenceQueue() {
|
||||
getContext().getASTDRQ().storeReference(getContext(), this);
|
||||
getContext().getReferenceQueue().storeReference(this, ASTRef::new);
|
||||
}
|
||||
|
||||
static AST create(Context ctx, long obj)
|
||||
|
|
@ -217,4 +219,16 @@ public class AST extends Z3Object implements Comparable<AST>
|
|||
throw new Z3Exception("Unknown AST kind");
|
||||
}
|
||||
}
|
||||
|
||||
private static class ASTRef extends Z3ReferenceQueue.Reference<AST> {
|
||||
|
||||
private ASTRef(AST referent, ReferenceQueue<Z3Object> q) {
|
||||
super(referent, q);
|
||||
}
|
||||
|
||||
@Override
|
||||
void decRef(Context ctx, long z3Obj) {
|
||||
Native.decRef(ctx.nCtx(), z3Obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue