public class DepthSearchAndSizeCounter extends Object
The basic problem when we want to estimate the size is that it is never known whether an object is exclusive for our cache structure, or it is also referenced by some other classes. To do a "perfect" size measurement the whole java heap must be analyzed and it must be decided which object should be counted where. So, anyway, let's try a good guess, and see whether it is of some use.
Heuristics: Top-Level objects are always counted at least once by instance. An identical object that is found via different ways when descending the graph is not counted at all. Object reached via a non-counted object are not counted.
Caveats: If only one object contains a reference to a bigger static data structure that belongs to the system, the size could be totally wrong. Countermeasures: we do measure the size only if more then x objects are in the cache and we limit the depth. If objects have a reference e.g. to some system objects, or maybe the cache, these objects will not be counted, if the reference is appearing more than once. So an problem may still arise if there is one object within the cache that holds such a reference and the others not. Current countermeasures for this: Estimate size only when sufficient objects are in the cache; limit the descending depth.
| Modifier and Type | Class and Description |
|---|---|
static class |
DepthSearchAndSizeCounter.EstimationException |
| Constructor and Description |
|---|
DepthSearchAndSizeCounter() |
| Modifier and Type | Method and Description |
|---|---|
void |
descend() |
int |
getByteCount() |
int |
getCounter() |
int |
getNextCount() |
int |
getObjectCount() |
boolean |
hasCircles() |
boolean |
hasCommonObjects() |
boolean |
hasNext() |
void |
insert(Object o) |
void |
resetCounter()
Reset our counters but keep the lookup set of the objects seen so far.
|
public DepthSearchAndSizeCounter()
public int getNextCount()
public boolean hasNext()
public void descend() throws DepthSearchAndSizeCounter.EstimationException
public void resetCounter()
public int getByteCount()
public int getObjectCount()
public int getCounter()
public boolean hasCommonObjects()
public boolean hasCircles()
cache2k API documentation. Copyright © 2000–2015 headissue GmbH, Munich.