diff --git a/src/api/java/AST.java b/src/api/java/AST.java index 4b5b37d46..e1cde837f 100644 --- a/src/api/java/AST.java +++ b/src/api/java/AST.java @@ -192,9 +192,12 @@ public class AST extends Z3Object implements Comparable } @Override - void incRef(long o) - { - Native.incRef(getContext().nCtx(), o); + void incRef() { + Native.incRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getASTDRQ().storeReference(getContext(), this); } diff --git a/src/api/java/ASTMap.java b/src/api/java/ASTMap.java index b4ae7102a..916811cec 100644 --- a/src/api/java/ASTMap.java +++ b/src/api/java/ASTMap.java @@ -20,8 +20,7 @@ package com.microsoft.z3; /** * Map from AST to AST **/ -class ASTMap extends Z3Object -{ +class ASTMap extends Z3Object { /** * Checks whether the map contains the key {@code k}. * @param k An AST @@ -118,9 +117,12 @@ class ASTMap extends Z3Object } @Override - void incRef(long o) - { - Native.astMapIncRef(getContext().nCtx(), o); + void incRef() { + Native.astMapIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getASTMapDRQ().storeReference(getContext(), this); } } diff --git a/src/api/java/ASTVector.java b/src/api/java/ASTVector.java index 7c5ca1067..4d9ab291a 100644 --- a/src/api/java/ASTVector.java +++ b/src/api/java/ASTVector.java @@ -20,8 +20,7 @@ package com.microsoft.z3; /** * Vectors of ASTs. **/ -public class ASTVector extends Z3Object -{ +public class ASTVector extends Z3Object { /** * The size of the vector **/ @@ -103,9 +102,12 @@ public class ASTVector extends Z3Object } @Override - void incRef(long o) - { - Native.astVectorIncRef(getContext().nCtx(), o); + void incRef() { + Native.astVectorIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getASTVectorDRQ().storeReference(getContext(), this); } diff --git a/src/api/java/ApplyResult.java b/src/api/java/ApplyResult.java index 8b3c1daf6..6fafbd888 100644 --- a/src/api/java/ApplyResult.java +++ b/src/api/java/ApplyResult.java @@ -21,8 +21,7 @@ package com.microsoft.z3; * ApplyResult objects represent the result of an application of a tactic to a * goal. It contains the subgoals that were produced. **/ -public class ApplyResult extends Z3Object -{ +public class ApplyResult extends Z3Object { /** * The number of Subgoals. **/ @@ -74,8 +73,12 @@ public class ApplyResult extends Z3Object } @Override - void incRef(long o) { - Native.applyResultIncRef(getContext().nCtx(), o); + void incRef() { + Native.applyResultIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getApplyResultDRQ().storeReference(getContext(), this); } } diff --git a/src/api/java/Constructor.java b/src/api/java/Constructor.java index 28558b15a..87ab86c3f 100644 --- a/src/api/java/Constructor.java +++ b/src/api/java/Constructor.java @@ -85,9 +85,12 @@ public class Constructor extends Z3Object { } @Override - void incRef(long o) { - + void incRef() { // Datatype constructors are not reference counted. + } + + @Override + void addToReferenceQueue() { getContext().getConstructorDRQ().storeReference(getContext(), this); } diff --git a/src/api/java/ConstructorList.java b/src/api/java/ConstructorList.java index 3f1835082..c79e08d9e 100644 --- a/src/api/java/ConstructorList.java +++ b/src/api/java/ConstructorList.java @@ -28,7 +28,12 @@ public class ConstructorList extends Z3Object { } @Override - void incRef(long o) { + void incRef() { + // Constructor lists are not reference counted. + } + + @Override + void addToReferenceQueue() { getContext().getConstructorListDRQ().storeReference(getContext(), this); } diff --git a/src/api/java/Fixedpoint.java b/src/api/java/Fixedpoint.java index 5a7958364..876345f1e 100644 --- a/src/api/java/Fixedpoint.java +++ b/src/api/java/Fixedpoint.java @@ -349,8 +349,12 @@ public class Fixedpoint extends Z3Object } @Override - void incRef(long o) { - Native.fixedpointIncRef(getContext().nCtx(), o); + void incRef() { + Native.fixedpointIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getFixedpointDRQ().storeReference(getContext(), this); } diff --git a/src/api/java/FixedpointDecRefQueue.java b/src/api/java/FixedpointDecRefQueue.java index d5ae79a2b..3cba67ced 100644 --- a/src/api/java/FixedpointDecRefQueue.java +++ b/src/api/java/FixedpointDecRefQueue.java @@ -17,8 +17,7 @@ Notes: package com.microsoft.z3; -class FixedpointDecRefQueue extends IDecRefQueue -{ +class FixedpointDecRefQueue extends IDecRefQueue { public FixedpointDecRefQueue() { super(); @@ -29,7 +28,6 @@ class FixedpointDecRefQueue extends IDecRefQueue super(move_limit); } - @Override protected void decRef(Context ctx, long obj) { diff --git a/src/api/java/FuncInterp.java b/src/api/java/FuncInterp.java index 52f09c5a4..b5873d98e 100644 --- a/src/api/java/FuncInterp.java +++ b/src/api/java/FuncInterp.java @@ -22,8 +22,8 @@ package com.microsoft.z3; * Each entry in the finite map represents the value of a function given a set * of arguments. **/ -public class FuncInterp extends Z3Object -{ +public class FuncInterp extends Z3Object { + /** * An Entry object represents an element in the finite map used to encode a * function interpretation. @@ -32,10 +32,10 @@ public class FuncInterp extends Z3Object /** * Return the (symbolic) value of this entry. - * + * * @throws Z3Exception * @throws Z3Exception on error - **/ + **/ public Expr getValue() { return Expr.create(getContext(), @@ -45,7 +45,7 @@ public class FuncInterp extends Z3Object /** * The number of arguments of the entry. * @throws Z3Exception on error - **/ + **/ public int getNumArgs() { return Native.funcEntryGetNumArgs(getContext().nCtx(), getNativeObject()); @@ -53,10 +53,10 @@ public class FuncInterp extends Z3Object /** * The arguments of the function entry. - * + * * @throws Z3Exception * @throws Z3Exception on error - **/ + **/ public Expr[] getArgs() { int n = getNumArgs(); @@ -81,14 +81,17 @@ public class FuncInterp extends Z3Object return res + getValue() + "]"; } - Entry(Context ctx, long obj) - { + Entry(Context ctx, long obj) { super(ctx, obj); } @Override - void incRef(long o) { - Native.funcEntryIncRef(getContext().nCtx(), o);; + void incRef() { + Native.funcEntryIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getFuncEntryDRQ().storeReference(getContext(), this); } } @@ -176,8 +179,12 @@ public class FuncInterp extends Z3Object } @Override - void incRef(long o) { - Native.funcInterpIncRef(getContext().nCtx(), o); + void incRef() { + Native.funcInterpIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getFuncInterpDRQ().storeReference(getContext(), this); } } diff --git a/src/api/java/Goal.java b/src/api/java/Goal.java index a6d41ccd2..25b1fe511 100644 --- a/src/api/java/Goal.java +++ b/src/api/java/Goal.java @@ -23,8 +23,7 @@ import com.microsoft.z3.enumerations.Z3_goal_prec; * A goal (aka problem). A goal is essentially a set of formulas, that can be * solved and/or transformed using tactics and solvers. **/ -public class Goal extends Z3Object -{ +public class Goal extends Z3Object { /** * The precision of the goal. * Remarks: Goals can be transformed using over @@ -242,8 +241,12 @@ public class Goal extends Z3Object } @Override - void incRef(long o) { - Native.goalIncRef(getContext().nCtx(), o); + void incRef() { + Native.goalIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getGoalDRQ().storeReference(getContext(), this); } } diff --git a/src/api/java/Model.java b/src/api/java/Model.java index fc6c6046b..60abb001d 100644 --- a/src/api/java/Model.java +++ b/src/api/java/Model.java @@ -22,8 +22,7 @@ import com.microsoft.z3.enumerations.Z3_sort_kind; /** * A Model contains interpretations (assignments) of constants and functions. **/ -public class Model extends Z3Object -{ +public class Model extends Z3Object { /** * Retrieves the interpretation (the assignment) of {@code a} in * the model. @@ -293,8 +292,12 @@ public class Model extends Z3Object } @Override - void incRef(long o) { - Native.modelIncRef(getContext().nCtx(), o); + void incRef() { + Native.modelIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getModelDRQ().storeReference(getContext(), this); } } diff --git a/src/api/java/Optimize.java b/src/api/java/Optimize.java index a5705a388..ea100d1ca 100644 --- a/src/api/java/Optimize.java +++ b/src/api/java/Optimize.java @@ -266,8 +266,12 @@ public class Optimize extends Z3Object } @Override - void incRef(long o) { - Native.optimizeIncRef(getContext().nCtx(), o); + void incRef() { + Native.optimizeIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getOptimizeDRQ().storeReference(getContext(), this); } } diff --git a/src/api/java/ParamDescrs.java b/src/api/java/ParamDescrs.java index f90e4dd99..0008515e3 100644 --- a/src/api/java/ParamDescrs.java +++ b/src/api/java/ParamDescrs.java @@ -22,8 +22,7 @@ import com.microsoft.z3.enumerations.Z3_param_kind; /** * A ParamDescrs describes a set of parameters. **/ -public class ParamDescrs extends Z3Object -{ +public class ParamDescrs extends Z3Object { /** * validate a set of parameters. **/ @@ -92,8 +91,12 @@ public class ParamDescrs extends Z3Object } @Override - void incRef(long o) { - Native.paramDescrsIncRef(getContext().nCtx(), o); + void incRef() { + Native.paramDescrsIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getParamDescrsDRQ().storeReference(getContext(), this); } } diff --git a/src/api/java/Params.java b/src/api/java/Params.java index e3b143371..a76dd3cab 100644 --- a/src/api/java/Params.java +++ b/src/api/java/Params.java @@ -21,8 +21,7 @@ package com.microsoft.z3; /** * A ParameterSet represents a configuration in the form of Symbol/value pairs. **/ -public class Params extends Z3Object -{ +public class Params extends Z3Object { /** * Adds a parameter setting. **/ @@ -123,9 +122,14 @@ public class Params extends Z3Object super(ctx, Native.mkParams(ctx.nCtx())); } + @Override - void incRef(long o) { - Native.paramsIncRef(getContext().nCtx(), o); + void incRef() { + Native.paramsIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getParamsDRQ().storeReference(getContext(), this); } } diff --git a/src/api/java/Probe.java b/src/api/java/Probe.java index 6983613c1..a36f3b64b 100644 --- a/src/api/java/Probe.java +++ b/src/api/java/Probe.java @@ -25,8 +25,7 @@ package com.microsoft.z3; * also be obtained using the command {@code (help-tactic)} in the SMT 2.0 * front-end. **/ -public class Probe extends Z3Object -{ +public class Probe extends Z3Object { /** * Execute the probe over the goal. * @@ -46,15 +45,17 @@ public class Probe extends Z3Object super(ctx, obj); } - Probe(Context ctx, String name) - { + Probe(Context ctx, String name) { super(ctx, Native.mkProbe(ctx.nCtx(), name)); } @Override - void incRef(long o) - { - Native.probeIncRef(getContext().nCtx(), o); + void incRef() { + Native.probeIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getProbeDRQ().storeReference(getContext(), this); } } diff --git a/src/api/java/Solver.java b/src/api/java/Solver.java index 5d538b2f3..a98fcbf94 100644 --- a/src/api/java/Solver.java +++ b/src/api/java/Solver.java @@ -22,8 +22,7 @@ import com.microsoft.z3.enumerations.Z3_lbool; /** * Solvers. **/ -public class Solver extends Z3Object -{ +public class Solver extends Z3Object { /** * A string that describes all available solver parameters. **/ @@ -154,13 +153,13 @@ public class Solver extends Z3Object * using the Boolean constant p. * * Remarks: - * This API is an alternative to {@link check} with assumptions for + * This API is an alternative to {@link #check} with assumptions for * extracting unsat cores. * Both APIs can be used in the same solver. The unsat core will contain a * combination - * of the Boolean variables provided using {@link assertAndTrack} + * of the Boolean variables provided using {@link #assertAndTrack} * and the Boolean literals - * provided using {@link check} with assumptions. + * provided using {@link #check} with assumptions. */ public void assertAndTrack(BoolExpr constraint, BoolExpr p) { @@ -333,8 +332,12 @@ public class Solver extends Z3Object } @Override - void incRef(long o) { - Native.solverIncRef(getContext().nCtx(), o); + void incRef() { + Native.solverIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getSolverDRQ().storeReference(getContext(), this); } } diff --git a/src/api/java/Statistics.java b/src/api/java/Statistics.java index d2ba2bbd3..356cbeadb 100644 --- a/src/api/java/Statistics.java +++ b/src/api/java/Statistics.java @@ -20,8 +20,7 @@ package com.microsoft.z3; /** * Objects of this class track statistical information about solvers. **/ -public class Statistics extends Z3Object -{ +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} @@ -191,8 +190,12 @@ public class Statistics extends Z3Object } @Override - void incRef(long o) { - Native.statsIncRef(getContext().nCtx(), o); + void incRef() { getContext().getStatisticsDRQ().storeReference(getContext(), this); } + + @Override + void addToReferenceQueue() { + Native.statsIncRef(getContext().nCtx(), getNativeObject()); + } } diff --git a/src/api/java/Symbol.java b/src/api/java/Symbol.java index 21925b099..139894be1 100644 --- a/src/api/java/Symbol.java +++ b/src/api/java/Symbol.java @@ -22,8 +22,7 @@ import com.microsoft.z3.enumerations.Z3_symbol_kind; /** * Symbols are used to name several term and type constructors. **/ -public class Symbol extends Z3Object -{ +public class Symbol extends Z3Object { /** * The kind of the symbol (int or string) **/ @@ -81,7 +80,13 @@ public class Symbol extends Z3Object } @Override - void incRef(long o) { + void incRef() { + // Symbol does not require tracking. + } + + @Override + void addToReferenceQueue() { + // Symbol does not require tracking. } diff --git a/src/api/java/Tactic.java b/src/api/java/Tactic.java index f7e030f04..11d02ca73 100644 --- a/src/api/java/Tactic.java +++ b/src/api/java/Tactic.java @@ -24,8 +24,7 @@ package com.microsoft.z3; * also be obtained using the command {@code (help-tactic)} in the SMT 2.0 * front-end. **/ -public class Tactic extends Z3Object -{ +public class Tactic extends Z3Object { /** * A string containing a description of parameters accepted by the tactic. **/ @@ -93,9 +92,12 @@ public class Tactic extends Z3Object } @Override - void incRef(long o) - { - Native.tacticIncRef(getContext().nCtx(), o); + void incRef() { + Native.tacticIncRef(getContext().nCtx(), getNativeObject()); + } + + @Override + void addToReferenceQueue() { getContext().getTacticDRQ().storeReference(getContext(), this); } } diff --git a/src/api/java/Z3Object.java b/src/api/java/Z3Object.java index f982bba1c..7c5f606d9 100644 --- a/src/api/java/Z3Object.java +++ b/src/api/java/Z3Object.java @@ -30,15 +30,20 @@ public abstract class Z3Object { m_ctx = ctx; checkNativeObject(obj); m_n_obj = obj; - incRef(obj); + incRef(); + addToReferenceQueue(); } /** - * Increment reference count on {@code o}. - * - * @param o Z3 object. + * Add to ReferenceQueue for tracking reachability on the object and + * decreasing the reference count when the object is no longer reachable. */ - abstract void incRef(long o); + abstract void addToReferenceQueue(); + + /** + * Increment reference count on {@code this}. + */ + abstract void incRef(); /** * This function is provided for overriding, and a child class