harpoon.Analysis.Transformation
Class MethodSplitter

java.lang.Object
  extended by harpoon.Analysis.Transformation.MethodSplitter
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AllocationHoisting, InitializerTransform, RCTransformer, SyncTransformer

public abstract class MethodSplitter
extends Object
implements Serializable

MethodSplitter makes it easier to implement transformations which specialize methods for one purpose or another. It is meant to be subclassed. In your subclass, you will likely want to create a few static fields of type MethodSplitter.Token to name your specialized versions, override the isValidToken() method to include your new tokens, and override mutateDescriptor() and/or mutateHCode() to effect the specialization.

Note that if you mutate the ORIGINAL version of a method, all split versions will inherit the mutation. Be careful not to introduce cycles because of this ordering.

Version:
$Id: MethodSplitter.java,v 1.7 2004/02/08 01:54:24 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>
See Also:
Serialized Form

Nested Class Summary
protected static class MethodSplitter.Token
          Subclasses of MethodSplitter refer to "versions" of the underlying method which may be named by creating static instances of this MethodSplitter.Token class.
 
Field Summary
static MethodSplitter.Token ORIGINAL
          The ORIGINAL token represents the original pre-split version of a method.
 
Constructor Summary
MethodSplitter(HCodeFactory _parent, ClassHierarchy ch, boolean mutateOriginalBeforeSplit)
          Creates a MethodSplitter, based on the method representations in the parent HCodeFactory.
 
Method Summary
protected  HCodeAndMaps cloneHCode(HCode hc, HMethod newmethod)
          Override this method if you do not want the mutatable HCode to be a straight clone of the original HCode: for example, if the input HCodes were QuadSSI and you wanted to clone them into QuadRSSIs before mutating.
 HCodeFactory codeFactory()
          Returns a HCodeFactory containing representations for the methods split by the MethodSplitter.
protected  boolean isValidToken(MethodSplitter.Token which)
          Check the validity of a given MethodSplitter.Token.
protected  boolean isVirtual(HMethod m)
          Utility method to determine whether a method is inheritable (and thus it's children should be split whenever it is).
protected  String mutateCodeName(String codeName)
          Override this method to change the codename which this MethodMutator's codefactory reports.
protected  String mutateDescriptor(HMethod hm, MethodSplitter.Token which)
          Override this method if you want to create mutated methods with descriptors differing from that of the original method.
protected  HCode mutateHCode(HCodeAndMaps input, MethodSplitter.Token which)
          Override this method to effect transformations on split methods.
 HMethod select(HMethod source, MethodSplitter.Token which)
          Go from a (possibly already split) method to the version of the method named by the token which.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORIGINAL

public static final MethodSplitter.Token ORIGINAL
The ORIGINAL token represents the original pre-split version of a method.

Constructor Detail

MethodSplitter

public MethodSplitter(HCodeFactory _parent,
                      ClassHierarchy ch,
                      boolean mutateOriginalBeforeSplit)
Creates a MethodSplitter, based on the method representations in the parent HCodeFactory.

Parameters:
mutateOriginalBeforeSplit - if true, the mutated version of the original is cloned and given to mutateHCode as source for a split methods; otherwise, the unmutated version of the original is taken as the source for the split method. If it doesn't matter, choose true, as this reduces the memory footprint.
Method Detail

select

public final HMethod select(HMethod source,
                            MethodSplitter.Token which)
Go from a (possibly already split) method to the version of the method named by the token which.


isVirtual

protected boolean isVirtual(HMethod m)
Utility method to determine whether a method is inheritable (and thus it's children should be split whenever it is).


codeFactory

public HCodeFactory codeFactory()
Returns a HCodeFactory containing representations for the methods split by the MethodSplitter.


mutateDescriptor

protected String mutateDescriptor(HMethod hm,
                                  MethodSplitter.Token which)
Override this method if you want to create mutated methods with descriptors differing from that of the original method.


mutateHCode

protected HCode mutateHCode(HCodeAndMaps input,
                            MethodSplitter.Token which)
Override this method to effect transformations on split methods.


mutateCodeName

protected String mutateCodeName(String codeName)
Override this method to change the codename which this MethodMutator's codefactory reports.


cloneHCode

protected HCodeAndMaps cloneHCode(HCode hc,
                                  HMethod newmethod)
                           throws CloneNotSupportedException
Override this method if you do not want the mutatable HCode to be a straight clone of the original HCode: for example, if the input HCodes were QuadSSI and you wanted to clone them into QuadRSSIs before mutating. By default, this method returns hc.clone(newmethod).

Throws:
CloneNotSupportedException

isValidToken

protected boolean isValidToken(MethodSplitter.Token which)
Check the validity of a given MethodSplitter.Token. Override if (when) your subclass defines new tokens.