3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-25 01:55:32 +00:00

Improved memory use of the Java API. Thanks to Joerg Pfaehler for reporting this issue!

+ formatting

Signed-off-by: Christoph M. Wintersteiger <cwinter@microsoft.com>
This commit is contained in:
Christoph M. Wintersteiger 2015-01-30 21:04:18 -06:00
parent 3b78509d0a
commit d7a62baef4
60 changed files with 3149 additions and 2992 deletions

View file

@ -21,39 +21,49 @@ import java.util.LinkedList;
abstract class IDecRefQueue
{
protected Object m_lock = new Object();
protected LinkedList<Long> m_queue = new LinkedList<Long>();
protected final int m_move_limit = 1024;
protected Object m_lock = new Object();
protected LinkedList<Long> m_queue = new LinkedList<Long>();
protected int m_move_limit;
protected abstract void incRef(Context ctx, long obj);
public IDecRefQueue()
{
m_move_limit = 1024;
}
protected abstract void decRef(Context ctx, long obj);
public IDecRefQueue(int move_limit)
{
m_move_limit = move_limit;
}
protected void incAndClear(Context ctx, long o)
{
incRef(ctx, o);
if (m_queue.size() >= m_move_limit)
clear(ctx);
}
protected abstract void incRef(Context ctx, long obj);
protected void add(long o)
{
if (o == 0)
return;
protected abstract void decRef(Context ctx, long obj);
synchronized (m_lock)
{
m_queue.add(o);
}
}
protected void incAndClear(Context ctx, long o)
{
incRef(ctx, o);
if (m_queue.size() >= m_move_limit)
clear(ctx);
}
protected void clear(Context ctx)
{
synchronized (m_lock)
{
for (Long o : m_queue)
decRef(ctx, o);
m_queue.clear();
}
}
protected void add(long o)
{
if (o == 0)
return;
synchronized (m_lock)
{
m_queue.add(o);
}
}
protected void clear(Context ctx)
{
synchronized (m_lock)
{
for (Long o : m_queue)
decRef(ctx, o);
m_queue.clear();
}
}
}