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:
parent
f7691d34fd
commit
a3d00ce356
41 changed files with 448 additions and 805 deletions
|
|
@ -17,6 +17,8 @@ Notes:
|
|||
|
||||
package com.microsoft.z3;
|
||||
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
|
||||
/**
|
||||
* Objects of this class track statistical information about solvers.
|
||||
**/
|
||||
|
|
@ -25,7 +27,7 @@ public class Statistics extends Z3Object {
|
|||
* Statistical data is organized into pairs of [Key, Entry], where every
|
||||
* Entry is either a {@code DoubleEntry} or a {@code UIntEntry}
|
||||
**/
|
||||
public class Entry
|
||||
public static class Entry
|
||||
{
|
||||
/**
|
||||
* The key of the entry.
|
||||
|
|
@ -191,11 +193,23 @@ public class Statistics extends Z3Object {
|
|||
|
||||
@Override
|
||||
void incRef() {
|
||||
getContext().getStatisticsDRQ().storeReference(getContext(), this);
|
||||
Native.statsIncRef(getContext().nCtx(), getNativeObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
void addToReferenceQueue() {
|
||||
Native.statsIncRef(getContext().nCtx(), getNativeObject());
|
||||
getContext().getReferenceQueue().storeReference(this, StatisticsRef::new);
|
||||
}
|
||||
|
||||
private static class StatisticsRef extends Z3ReferenceQueue.Reference<Statistics> {
|
||||
|
||||
private StatisticsRef(Statistics referent, ReferenceQueue<Z3Object> q) {
|
||||
super(referent, q);
|
||||
}
|
||||
|
||||
@Override
|
||||
void decRef(Context ctx, long z3Obj) {
|
||||
Native.statsDecRef(ctx.nCtx(), z3Obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue