harpoon.ClassFile
Class CachingCodeFactory

java.lang.Object
  extended by harpoon.ClassFile.CachingCodeFactory
All Implemented Interfaces:
HCodeFactory, SerializableCodeFactory, Serializable
Direct Known Subclasses:
ArrayCopyImplementer, PreallocOpt.SafeCachingCodeFactory

public class CachingCodeFactory
extends Object
implements SerializableCodeFactory

A CachingCodeFactory caches the conversions performed by a parent HCodeFactory; the cache can also be directly modified in order to add or replace method implementations.

Version:
$Id: CachingCodeFactory.java,v 1.5 2005/09/30 19:01:47 salcianu Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>
See Also:
Serialized Form

Field Summary
 HCodeFactory parent
          Parent code factory.
 
Constructor Summary
CachingCodeFactory(HCodeFactory parent)
          Creates a CachingCodeFactory using the conversions performed by parent.
CachingCodeFactory(HCodeFactory parent, boolean saveCode)
          Creates a CachingCodeFactory using the conversions performed by parent.
 
Method Summary
 void clear(HMethod m)
          Remove the cached representation of m from this CachingCodeFactory and its parent.
 HCode convert(HMethod m)
          Convert a method to an HCode, caching the result.
 String getCodeName()
          Returns the name of the HCodes generated by this CachingCodeFactory.
 void put(HMethod m, HCode hc)
          Add or replace a representation for m to this CachingCodeFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

public final HCodeFactory parent
Parent code factory. Creates the representations this CachingCodeFactory caches.

Constructor Detail

CachingCodeFactory

public CachingCodeFactory(HCodeFactory parent)
Creates a CachingCodeFactory using the conversions performed by parent. Cached HCodes will be flushed before this code factory is serialized.


CachingCodeFactory

public CachingCodeFactory(HCodeFactory parent,
                          boolean saveCode)
Creates a CachingCodeFactory using the conversions performed by parent. If saveCode is true, cached HCodes will *not* be flushed before serialization.

Method Detail

getCodeName

public String getCodeName()
Returns the name of the HCodes generated by this CachingCodeFactory. Returns the same name as parent does.

Specified by:
getCodeName in interface HCodeFactory

convert

public HCode convert(HMethod m)
Convert a method to an HCode, caching the result. Cached representations of m in parent are cleared when this CachingCodeFactory adds the converted representation of m to its cache.

Specified by:
convert in interface HCodeFactory

clear

public void clear(HMethod m)
Remove the cached representation of m from this CachingCodeFactory and its parent.

Specified by:
clear in interface HCodeFactory

put

public void put(HMethod m,
                HCode hc)
Add or replace a representation for m to this CachingCodeFactory. This can be used to update the representation of a method with an optimized or otherwise modified version. As a side-effect, clears any cached representations of m from parent.