3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-11-25 23:19:32 +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:
Thomas Haas 2024-02-21 17:39:58 +01:00 committed by GitHub
parent f7691d34fd
commit a3d00ce356
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 448 additions and 805 deletions

View file

@ -17,6 +17,8 @@ Notes:
package com.microsoft.z3;
import java.lang.ref.ReferenceQueue;
/**
* Vectors of ASTs.
**/
@ -101,16 +103,6 @@ public class ASTVector extends Z3Object {
super(ctx, Native.mkAstVector(ctx.nCtx()));
}
@Override
void incRef() {
Native.astVectorIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void addToReferenceQueue() {
getContext().getASTVectorDRQ().storeReference(getContext(), this);
}
/**
* Translates the AST vector into an AST[]
* */
@ -241,4 +233,26 @@ public class ASTVector extends Z3Object {
res[i] = (RealExpr)Expr.create(getContext(), get(i).getNativeObject());
return res;
}
@Override
void incRef() {
Native.astVectorIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void addToReferenceQueue() {
getContext().getReferenceQueue().storeReference(this, ASTVectorRef::new);
}
private static class ASTVectorRef extends Z3ReferenceQueue.Reference<ASTVector> {
private ASTVectorRef(ASTVector referent, ReferenceQueue<Z3Object> q) {
super(referent, q);
}
@Override
void decRef(Context ctx, long z3Obj) {
Native.astVectorDecRef(ctx.nCtx(), z3Obj);
}
}
}