Z3 |

IDecRefQueue.java
Go to the documentation of this file.
1
18 package com.microsoft.z3;
19
20 import java.lang.ref.PhantomReference;
21 import java.lang.ref.Reference;
22 import java.lang.ref.ReferenceQueue;
23 import java.util.IdentityHashMap;
24 import java.util.Map;
25
39 public abstract class IDecRefQueue<T extends Z3Object> {
40 private final ReferenceQueue<T> referenceQueue = new ReferenceQueue<>();
41 private final Map<PhantomReference<T>, Long> referenceMap =
42 new IdentityHashMap<>();
43
44 protected IDecRefQueue() {}
45
54 protected abstract void decRef(Context ctx, long obj);
55
56 public void storeReference(Context ctx, T obj) {
57 PhantomReference<T> ref = new PhantomReference<>(obj, referenceQueue);
58 referenceMap.put(ref, obj.getNativeObject());
59 clear(ctx);
60 }
61
65 protected void clear(Context ctx)
66 {
67 Reference<? extends T> ref;
68 while ((ref = referenceQueue.poll()) != null) {
69 long z3ast = referenceMap.remove(ref);
70 decRef(ctx, z3ast);
71 }
72 }
73
78 public void forceClear(Context ctx) {
79 for (long ref : referenceMap.values()) {
80 decRef(ctx, ref);
81 }
82 }
83}
com.microsoft.z3.Context
Definition: Context.java:36
com.microsoft.z3.IDecRefQueue
Definition: IDecRefQueue.java:39
com.microsoft.z3.IDecRefQueue.forceClear
void forceClear(Context ctx)
Definition: IDecRefQueue.java:78
com.microsoft.z3.IDecRefQueue.storeReference
void storeReference(Context ctx, T obj)
Definition: IDecRefQueue.java:56
com.microsoft.z3.IDecRefQueue.decRef
abstract void decRef(Context ctx, long obj)
com.microsoft.z3.IDecRefQueue.clear
void clear(Context ctx)
Definition: IDecRefQueue.java:65
com.microsoft.z3.IDecRefQueue.IDecRefQueue
IDecRefQueue()
Definition: IDecRefQueue.java:44
com.microsoft.z3.Z3Object
Definition: Z3Object.java:24