sofya.graphs.cfg
Class CFGCache

java.lang.Object
  extended by sofya.graphs.GraphCache
      extended by sofya.graphs.cfg.CFGCache

public class CFGCache
extends GraphCache

Disk backed soft memory cache for control flow graphs (CFGs) which uses a least recently used (LRU) policy to cache graphs to disk.

This class provides the implementation to serialize CFGs to binary flat files on disk.

Version:
11/16/2004
Author:
Alex Kinneer

Nested Class Summary
 
Nested classes/interfaces inherited from class sofya.graphs.GraphCache
GraphCache.CachedGraph
 
Constructor Summary
CFGCache()
          Creates a new CFG cache with a default minimum memory threshold and disk caching policy.
CFGCache(int initRemoveNum)
          Creates a new CFG cache with a default minimum memory threshold which immediately caches a given number of graphs to disk when the threshold is passed.
CFGCache(int initRemoveNum, float lowMemThreshold)
          Creates a new CFG cache which immediately caches the specified number of graphs when the given minimum memory threshold is passed.
 
Method Summary
static void main(java.lang.String[] argv)
          Simple test driver.
protected  Graph readFromDisk(MethodSignature method)
          Reads a CFG from a cache file.
protected  void writeToDisk(MethodSignature method, Graph g)
          Writes a CFG to a cache file.
 
Methods inherited from class sofya.graphs.GraphCache
clear, containsKey, get, getForClass, iterator, iterator, keySet, keySet, put, remove, size, sortedIterator, sortedIterator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CFGCache

public CFGCache()
Creates a new CFG cache with a default minimum memory threshold and disk caching policy.


CFGCache

public CFGCache(int initRemoveNum)
Creates a new CFG cache with a default minimum memory threshold which immediately caches a given number of graphs to disk when the threshold is passed.

Parameters:
initRemoveNum - Number of graphs to immediately cache to disk when available memory falls below the minimum threshold. Higher values may improve performance by immediately clearing more memory and thus reducing the frequency with which the cache must search for and cache eligible CFGs.

CFGCache

public CFGCache(int initRemoveNum,
                float lowMemThreshold)
Creates a new CFG cache which immediately caches the specified number of graphs when the given minimum memory threshold is passed.

Parameters:
initRemoveNum - Number of graphs to immediately cache to disk when available memory falls below the minimum threshold. Higher values may improve performance by immediately clearing more memory and thus reducing the frequency with which the cache must search for and cache eligible CFGs.
lowMemThreshold - Minimum free memory, as a percentage of total memory, that the cache must attempt to keep free. Setting this value too high may result in disk thrashing.
Method Detail

readFromDisk

protected Graph readFromDisk(MethodSignature method)
                      throws CacheException
Reads a CFG from a cache file.

Specified by:
readFromDisk in class GraphCache
Parameters:
method - Signature of the method for which to retrieve the CFG from the cache file.
Returns:
The CFG for the specified method.
Throws:
CacheException - If reading of the cache file fails, which may occur if no cache file exists for the requested method or if the cache file is unreadable or corrupted in some way.

writeToDisk

protected void writeToDisk(MethodSignature method,
                           Graph g)
                    throws CacheException
Writes a CFG to a cache file.

Specified by:
writeToDisk in class GraphCache
Parameters:
method - Signature of the method being written to file.
g - CFG being written to the cache file.
Throws:
CacheException - If the cache file cannot be created or written.

main

public static void main(java.lang.String[] argv)
Simple test driver.