jist.runtime
Class Rewriter

java.lang.Object
  extended by java.lang.ClassLoader
      extended by jist.runtime.Rewriter

public final class Rewriter
extends java.lang.ClassLoader

A custom class loader used by the JIST system to modify standard Java applications at load-time to run under "Simulation Time". This implementation uses the Apache Byte-Code Engineering Library (BCEL).

Since:
JIST1.0
Version:
$Id: Rewriter.java,v 1.117 2005/03/13 16:11:54 barr Exp $
Author:
Rimon Barr <barr+jist@cs.cornell.edu>

Field Summary
private  java.util.HashSet blocking
          Methods that are blocking.
static java.lang.Class[] blockingClass
          List of methods that are pre-defined to have every method blocking.
static java.lang.reflect.Member[] blockingMethod
          List of methods that are pre-defined to be blocking.
static java.lang.String CACHE_PREFIX
          Class cache prefix.
private  java.lang.String cacheDir
          Class disk-based cache directory.
private  java.util.HashMap calledBy
          Regular method call graph: (methodsig mapped to hashset(methodsig)).
private  java.util.HashSet continuable
          Methods should be rewritten to be Continuable.
static java.lang.reflect.Member[] continuableMethod
          List of methods that are pre-defined to be continuable.
private static java.lang.String[] ignoredPackages
          Class beginning with these strings are ignored, (used only when processedPackages is null).
static java.lang.String JAVA_MAIN_NAME
          Name of the Java initialization method.
static java.lang.String JIST_CONTINUATION_STATE_PREFIX
          Prefix for all classes to capture continuation state.
static java.lang.String JIST_ENTITYREF
          Name of the entity self reference field.
static java.lang.String JIST_FIELD_PREFIX
          Prefix of automatically generated fields.
static java.lang.String JIST_METHOD_GET
          Prefix of generated field get accessor method.
static java.lang.String JIST_METHOD_PREFIX
          Prefix of automatically generated methods.
static java.lang.String JIST_METHOD_SET
          Prefix of generated field set accessor method.
static java.lang.String JIST_METHODSTUB_PREFIX
          Prefix of generated method stub fields.
static java.lang.String JIST_REF_SUFFIX
          Suffix of the entity self reference field.
static java.lang.String JIST_STATIC_TRIGGER
          Name of the field used to trigger static initialization.
static java.lang.String JIST_STATIC_TRIGGER_SUFFIX
          Suffix of the field used to trigger static intialization.
private  org.apache.bcel.util.Repository jistRepository
          (Possibly remote) Jist repository.
static org.apache.log4j.Logger log
          Logger instance.
private  java.util.HashMap lookupCache
          Classpath lookup cache: (string to JavaClass).
static java.lang.reflect.Method method_initializeMethodStubs
          Method stub of the generic static method initializer method.
private  java.lang.String[] processedPackages
          Classes beginning with these strings are processed and all others are ignored; or, if this variable is null, then ignore packages in ignoredPackages and process all others.
private static java.lang.Object repositoryLock
          Mutex access to BCEL repository object.
private  RemoteJist.ResourceFinderRemote resources
          Resource locator (possibly remote).
private  java.util.Vector rewriters
          Installed rewrite traversal visitors.
private  long rewriterTime
          Time that the rewriter class was compiled.
private  java.util.HashMap rewritten
          Rewrite cache.
static java.lang.String[] timeless
          List of objects that are pre-defined to be timeless.
private static java.util.Hashtable timelessHash
          Hashtable containing the timeless list for rapid lookup.
 
Constructor Summary
Rewriter(java.lang.String[] processedPackages, java.lang.String cacheDir, RemoteJist.ResourceFinderRemote resources, java.io.PrintStream serverOut)
          Initialize an Rewriter instance, with a list of packages to be processed (others are ignored).
 
Method Summary
 boolean addContinuable(java.lang.String sig)
          Add signature to list of continables.
static java.lang.String classToFileName(java.lang.String classname)
          Convert class name into a filename.
 void clearLookupCache()
          Reset the JavaClass lookup cache.
 void computeContinuableFixedPoint()
          Compute continuable fixed-point using call-graph.
static boolean containsMethod(org.apache.bcel.classfile.JavaClass jcl, java.lang.String methodname, org.apache.bcel.generic.Type methodreturn, org.apache.bcel.generic.Type[] methodargs)
          Return whether method contained (declared) within class.
 java.lang.Class define(org.apache.bcel.classfile.JavaClass jcl)
          Load a given BCEL class into the JVM.
protected  java.lang.Class findClass(java.lang.String name)
          Called by loadClass and actually does all the rewriting work, but checks in caches first.
 java.lang.String[] getAllClassReferences(java.lang.String classname)
          Return all the classes that are statically, directly referenced by this classes.
 java.lang.String[] getAllClassReferencesRecursively(java.lang.String classname)
          Return all the classes that are statically, recursively (directly and indirectly) referenced by this class.
static int getConstantPoolSize(org.apache.bcel.classfile.JavaClass jcl)
          Return the (byte) size of the constant pool.
static java.lang.String getContinutationClassName(org.apache.bcel.generic.MethodGen mg, int pc)
          Return the name of the class used to store the continuation of a method at a given "program counter" point.
 java.lang.String getDeclaringClass(java.lang.String classname, java.lang.String methodname, org.apache.bcel.generic.Type methodreturn, org.apache.bcel.generic.Type[] methodargs)
          Find class that declares a method, or null otherwise.
protected  java.lang.Class getDiskRewrittenClass(java.lang.String name)
          Read a cached rewritten class file from disk.
 java.lang.String[] getInterfaceNames(org.apache.bcel.classfile.JavaClass jcl)
          Return an array of the names of all interfaces implemented by a given class.
static java.lang.String getMethodStubFieldName(java.lang.reflect.Method m)
          Return the name of the method stub field for a given method.
 java.lang.String getMethodStubFieldName(org.apache.bcel.generic.MethodGen mg)
          Return the name of the method stub field for a given method.
static java.lang.String getMethodStubFieldName(java.lang.String methodName, java.lang.String sig)
          Return the name of the method stub field for a method with given name and signature (argument and return types).
static java.lang.String getPrimitiveObjectConversionMethod(org.apache.bcel.generic.BasicType t)
          Return name of method used to convert a primitive type wrapper object to a primitive.
static java.lang.Class getPrimitiveObjectType(org.apache.bcel.generic.BasicType t)
          Return a Class object for a given primitive Java Type.
 org.apache.bcel.generic.Type getRefType(org.apache.bcel.generic.Type t)
          Return the reference type of given type.
 org.apache.bcel.generic.Type[] getRefTypes(org.apache.bcel.generic.Type[] t)
          Return an array of reference types for a given array of types.
static java.lang.String getSignature(java.lang.Class c)
          Return the internal Java signature string of a given class.
static java.lang.String getSignature(java.lang.Class[] args, java.lang.Class ret)
          Return the internal Java signature string of a method.
static java.lang.String getSignature(org.apache.bcel.generic.InvokeInstruction ii, org.apache.bcel.generic.ConstantPoolGen cpg)
          Return a method signature from an invocation instruction.
static java.lang.String getSignature(java.lang.reflect.Member m)
          Return a method signature for given Java reflection method object.
static java.lang.String getSignature(org.apache.bcel.generic.MethodGen mg)
          Return a method signature for given BCEL methodgen object.
static java.lang.String getSignature(java.lang.String classname, java.lang.String methodname, org.apache.bcel.generic.Type methodreturn, org.apache.bcel.generic.Type[] methodargs)
          Return a method signature for the given information.
static org.apache.bcel.generic.Type getType(java.lang.Class c)
          Return the BCEL Type object for a corresponding Java Class object.
static java.lang.String getTypeClassname(org.apache.bcel.generic.Type t)
          Return the class name of the given Type or array type, or null for primitive types, or arrays of primitives.
static org.apache.bcel.generic.Type[] getTypes(java.lang.Class[] c)
          Return a BCEL Type object array corresponding to Java Class object array.
static void initializeMethodStubs(java.lang.String classname)
          Generic method for initializing method stubs of entities at runtime.
 void installPreRewriteTraversal(ClassTraversal.Visitor rewrite)
          Install a new rewrite traversal handler.
static boolean isBlocking(org.apache.bcel.generic.MethodGen mg)
          Whether a given method has blocking semantics (whether the caller needs to call with continuation).
 boolean isBlocking(java.lang.String classname, java.lang.String methodname, org.apache.bcel.generic.Type methodreturn, org.apache.bcel.generic.Type[] methodargs)
          Whether a specified method has blocking semantics (whether the caller needs to call with continuation).
static boolean isBlockingRuntime(java.lang.reflect.Method m)
          Whether a given regular entity method has blocking semantics (whether the caller needs to call with continuation).
static boolean isBlockingRuntimeProxy(java.lang.reflect.Method m)
          Whether a given proxy entity method has blocking semantics (whether the caller needs to call with continuation).
 boolean isContinuable(org.apache.bcel.generic.InvokeInstruction ii, org.apache.bcel.generic.ConstantPoolGen cpg)
          Whether a given invocation target is "continuable".
 boolean isContinuable(org.apache.bcel.generic.MethodGen mg)
          Whether a given method is marked as "continuable".
 boolean isDoNotRewrite(org.apache.bcel.classfile.JavaClass c)
          Determine whether given class should not be rewritten.
 boolean isEntity(org.apache.bcel.classfile.JavaClass c)
          Determine whether given class is an entity.
 boolean isEntity(java.lang.String name)
          Determine whether given class is an entity.
static boolean isEntityRuntime(java.lang.Class c)
          Determine whether given class is an entity.
 boolean isIgnored(java.lang.String classname)
          Determine whether a class should be rewritten or left alone.
static boolean isIgnoredStatic(java.lang.String classname)
          Determine whether a class should be rewritten or left alone.
 boolean isProxiable(org.apache.bcel.classfile.JavaClass c)
          Determine whether given class is an entity.
 boolean isProxiable(java.lang.String name)
          Determine whether given class is proxiable.
 boolean isRefType(org.apache.bcel.generic.Type t)
          Return whether this type is a non-entity.
 boolean isRefTypes(org.apache.bcel.generic.Type[] t)
          Return whether all types in array are non-entities.
 boolean isTimeless(org.apache.bcel.classfile.JavaClass c)
          Determine whether given class is timeless.
 boolean isTimeless(java.lang.String name)
          Determine whether given class is timeless.
 boolean isTimeless(org.apache.bcel.generic.Type type)
          Determine whether given type is timeclass.
static boolean isTimelessRuntime(java.lang.Class c)
          Determine whether given class is timeless.
 java.lang.Class loadClass(java.lang.String name, boolean resolve)
          Find and load class.
static void logAccessFlags(org.apache.bcel.classfile.AccessFlags a)
          Emit the access flags to Rewriter log.
 org.apache.bcel.classfile.JavaClass lookupJavaClass(java.lang.String name)
          Search the class path and return requested BCEL JavaClass object.
 int prime(java.lang.String classname)
          Prime the rewriter doing a breadth-first search loading (and rewrite) of all classes transitively statically referenced.
protected  void putDiskRewrittenClass(java.lang.String name, byte[] b)
          Write a rewritten class file to the disk cache.
protected  org.apache.bcel.classfile.JavaClass rewriteClass(org.apache.bcel.classfile.JavaClass jcl)
          Performs JiST rewriting of given JavaClass file.
static void setClassName(org.apache.bcel.classfile.JavaClass jcl, java.lang.String name)
          Modify the name of a class.
 void updateCallGraphAndContinuable(org.apache.bcel.classfile.JavaClass jcl)
          Update call-graph with methods of a new class.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JAVA_MAIN_NAME

public static final java.lang.String JAVA_MAIN_NAME
Name of the Java initialization method.

See Also:
Constant Field Values

JIST_METHOD_PREFIX

public static final java.lang.String JIST_METHOD_PREFIX
Prefix of automatically generated methods.

See Also:
Constant Field Values

JIST_FIELD_PREFIX

public static final java.lang.String JIST_FIELD_PREFIX
Prefix of automatically generated fields.

See Also:
Constant Field Values

JIST_METHODSTUB_PREFIX

public static final java.lang.String JIST_METHODSTUB_PREFIX
Prefix of generated method stub fields.

See Also:
Constant Field Values

JIST_METHOD_SET

public static final java.lang.String JIST_METHOD_SET
Prefix of generated field set accessor method.

See Also:
Constant Field Values

JIST_METHOD_GET

public static final java.lang.String JIST_METHOD_GET
Prefix of generated field get accessor method.

See Also:
Constant Field Values

JIST_REF_SUFFIX

public static final java.lang.String JIST_REF_SUFFIX
Suffix of the entity self reference field.

See Also:
Constant Field Values

JIST_ENTITYREF

public static final java.lang.String JIST_ENTITYREF
Name of the entity self reference field.

See Also:
Constant Field Values

JIST_STATIC_TRIGGER_SUFFIX

public static final java.lang.String JIST_STATIC_TRIGGER_SUFFIX
Suffix of the field used to trigger static intialization.

See Also:
Constant Field Values

JIST_STATIC_TRIGGER

public static final java.lang.String JIST_STATIC_TRIGGER
Name of the field used to trigger static initialization.

See Also:
Constant Field Values

JIST_CONTINUATION_STATE_PREFIX

public static final java.lang.String JIST_CONTINUATION_STATE_PREFIX
Prefix for all classes to capture continuation state.

See Also:
Constant Field Values

log

public static final org.apache.log4j.Logger log
Logger instance.


CACHE_PREFIX

public static final java.lang.String CACHE_PREFIX
Class cache prefix.

See Also:
Constant Field Values

timeless

public static final java.lang.String[] timeless
List of objects that are pre-defined to be timeless.


timelessHash

private static java.util.Hashtable timelessHash
Hashtable containing the timeless list for rapid lookup.


blockingMethod

public static java.lang.reflect.Member[] blockingMethod
List of methods that are pre-defined to be blocking.


continuableMethod

public static java.lang.reflect.Member[] continuableMethod
List of methods that are pre-defined to be continuable.


blockingClass

public static final java.lang.Class[] blockingClass
List of methods that are pre-defined to have every method blocking.


ignoredPackages

private static final java.lang.String[] ignoredPackages
Class beginning with these strings are ignored, (used only when processedPackages is null).


repositoryLock

private static java.lang.Object repositoryLock
Mutex access to BCEL repository object.


processedPackages

private java.lang.String[] processedPackages
Classes beginning with these strings are processed and all others are ignored; or, if this variable is null, then ignore packages in ignoredPackages and process all others.


rewritten

private java.util.HashMap rewritten
Rewrite cache. This is not just for performance... Must have for type-safety.


cacheDir

private java.lang.String cacheDir
Class disk-based cache directory.


resources

private RemoteJist.ResourceFinderRemote resources
Resource locator (possibly remote).


jistRepository

private org.apache.bcel.util.Repository jistRepository
(Possibly remote) Jist repository.


rewriterTime

private long rewriterTime
Time that the rewriter class was compiled.


continuable

private java.util.HashSet continuable
Methods should be rewritten to be Continuable.


blocking

private java.util.HashSet blocking
Methods that are blocking.


rewriters

private java.util.Vector rewriters
Installed rewrite traversal visitors.


lookupCache

private java.util.HashMap lookupCache
Classpath lookup cache: (string to JavaClass).


calledBy

private java.util.HashMap calledBy
Regular method call graph: (methodsig mapped to hashset(methodsig)).


method_initializeMethodStubs

public static java.lang.reflect.Method method_initializeMethodStubs
Method stub of the generic static method initializer method.

Constructor Detail

Rewriter

public Rewriter(java.lang.String[] processedPackages,
                java.lang.String cacheDir,
                RemoteJist.ResourceFinderRemote resources,
                java.io.PrintStream serverOut)
Initialize an Rewriter instance, with a list of packages to be processed (others are ignored).

Parameters:
processedPackages - list of packages to process, or null to process all packages, except those in the (default) ignoredPackages list.
cacheDir - directory for rewritten classfile cache
resources - remote resources finder
serverOut - server machine output stream
Method Detail

loadClass

public java.lang.Class loadClass(java.lang.String name,
                                 boolean resolve)
                          throws java.lang.ClassNotFoundException,
                                 java.lang.VerifyError
Find and load class. This method is invoked by the VM.

Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
name - qualified class name (e.g. java.lang.String)
resolve - not relevant
Returns:
requested class object
Throws:
java.lang.ClassNotFoundException - thrown if class can not be found
java.lang.VerifyError - throw if given class does not satify various JIST programming constraints.

findClass

protected java.lang.Class findClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException,
                                    java.lang.VerifyError
Called by loadClass and actually does all the rewriting work, but checks in caches first.

Overrides:
findClass in class java.lang.ClassLoader
Parameters:
name - qualified class name (e.g. java.lang.String)
Returns:
requested class object
Throws:
java.lang.ClassNotFoundException - thrown if class can not be found
java.lang.VerifyError - throw if given class does not satify various JIST programming constraints.

lookupJavaClass

public org.apache.bcel.classfile.JavaClass lookupJavaClass(java.lang.String name)
                                                    throws java.lang.ClassNotFoundException
Search the class path and return requested BCEL JavaClass object. This is the ONLY point through which the Rewriter retrieves new JavaClass objects. Therefore, it is also a convenient point to perform caching and incremental maintenance of the call-graph.

Parameters:
name - classname
Returns:
BCEL JavaClass object
Throws:
java.lang.ClassNotFoundException - when class not found

clearLookupCache

public void clearLookupCache()
Reset the JavaClass lookup cache.


define

public java.lang.Class define(org.apache.bcel.classfile.JavaClass jcl)
Load a given BCEL class into the JVM.

Parameters:
jcl - BCEL Java class
Returns:
loaded class object

rewriteClass

protected org.apache.bcel.classfile.JavaClass rewriteClass(org.apache.bcel.classfile.JavaClass jcl)
                                                    throws java.lang.ClassNotFoundException,
                                                           java.lang.VerifyError
Performs JiST rewriting of given JavaClass file.

Parameters:
jcl - BCEL JavaClass structure to rewrite
Returns:
rewritten class object
Throws:
java.lang.VerifyError - throw if given class does not satify various JIST programming constraints.
java.lang.ClassNotFoundException - failure to find referenced class

getDiskRewrittenClass

protected java.lang.Class getDiskRewrittenClass(java.lang.String name)
Read a cached rewritten class file from disk.

Parameters:
name - class name
Returns:
rewritten class, or null if it does not exist/invalid

putDiskRewrittenClass

protected void putDiskRewrittenClass(java.lang.String name,
                                     byte[] b)
Write a rewritten class file to the disk cache.

Parameters:
name - class name
b - class bytecode

addContinuable

public boolean addContinuable(java.lang.String sig)
                       throws java.lang.VerifyError
Add signature to list of continables. Verify that it is not a constructor, and return whether it is newly discovered.

Parameters:
sig - continuable to add
Returns:
whether this is a newly found continuable method
Throws:
java.lang.VerifyError - if signature is of an initialization method

updateCallGraphAndContinuable

public void updateCallGraphAndContinuable(org.apache.bcel.classfile.JavaClass jcl)
                                   throws java.lang.ClassNotFoundException
Update call-graph with methods of a new class.

Parameters:
jcl - BCEL class object to analyze
Throws:
java.lang.ClassNotFoundException - failure to load class in call graph

computeContinuableFixedPoint

public void computeContinuableFixedPoint()
Compute continuable fixed-point using call-graph.


getAllClassReferences

public java.lang.String[] getAllClassReferences(java.lang.String classname)
                                         throws java.lang.ClassNotFoundException
Return all the classes that are statically, directly referenced by this classes.

Parameters:
classname - name of class to inspect
Returns:
array of classes statically referenced directly
Throws:
java.lang.ClassNotFoundException - failure to find referenced class

getAllClassReferencesRecursively

public java.lang.String[] getAllClassReferencesRecursively(java.lang.String classname)
                                                    throws java.lang.ClassNotFoundException
Return all the classes that are statically, recursively (directly and indirectly) referenced by this class.

Parameters:
classname - name of class to inspect
Returns:
array of classes statically referenced directly or indirectly
Throws:
java.lang.ClassNotFoundException - failure to find referenced class

getInterfaceNames

public java.lang.String[] getInterfaceNames(org.apache.bcel.classfile.JavaClass jcl)
                                     throws java.lang.ClassNotFoundException
Return an array of the names of all interfaces implemented by a given class.

Parameters:
jcl - BCEL JavaClass object to inspect
Returns:
array of the names of all interfaces implemented.
Throws:
java.lang.ClassNotFoundException - interface classes not found

getDeclaringClass

public java.lang.String getDeclaringClass(java.lang.String classname,
                                          java.lang.String methodname,
                                          org.apache.bcel.generic.Type methodreturn,
                                          org.apache.bcel.generic.Type[] methodargs)
                                   throws java.lang.ClassNotFoundException
Find class that declares a method, or null otherwise.

Parameters:
classname - classname to initiate search from
methodname - name of method being sought
methodreturn - BCEL return type of method being sought
methodargs - BCEL argument type of method being sought
Returns:
name of class that declares given method
Throws:
java.lang.ClassNotFoundException - parent class not found

containsMethod

public static boolean containsMethod(org.apache.bcel.classfile.JavaClass jcl,
                                     java.lang.String methodname,
                                     org.apache.bcel.generic.Type methodreturn,
                                     org.apache.bcel.generic.Type[] methodargs)
Return whether method contained (declared) within class.

Parameters:
jcl - BCEL JavaClass object to inspect
methodname - method name
methodreturn - method return BCEL type
methodargs - method parameter BCEL types
Returns:
whether method is contained within class

isIgnored

public boolean isIgnored(java.lang.String classname)
Determine whether a class should be rewritten or left alone. If processedPackages is defined, then we only process packages with those prefixes. Otherwise, any package that does not begin with a prefix in the ignoredPackages array is rewritten.

Parameters:
classname - given class name
Returns:
whether the given class should be rewritten

isIgnoredStatic

public static boolean isIgnoredStatic(java.lang.String classname)
Determine whether a class should be rewritten or left alone. Any package that does not begin with a prefix in the ignoredPackages array is rewritten.

Parameters:
classname - given class name
Returns:
whether the given class should be rewritten

isEntity

public boolean isEntity(org.apache.bcel.classfile.JavaClass c)
                 throws java.lang.ClassNotFoundException
Determine whether given class is an entity. A class is an entity if and only if it implements the JistAPI.Entity interface.

Parameters:
c - BCEL class object
Returns:
whether given class is an entity
Throws:
java.lang.ClassNotFoundException
See Also:
JistAPI.Entity

isEntity

public boolean isEntity(java.lang.String name)
                 throws java.lang.ClassNotFoundException
Determine whether given class is an entity. A class is an entity if and only if it implements the JistAPI.Entity interface.

Parameters:
name - class name
Returns:
whether given class is an entity
Throws:
java.lang.ClassNotFoundException - class could not be loaded
See Also:
JistAPI.Entity

isEntityRuntime

public static boolean isEntityRuntime(java.lang.Class c)
Determine whether given class is an entity. A class is an entity (at runtime) if and only if it implement the Entity interface.

Parameters:
c - runtime class object
Returns:
whether given class is an entity
See Also:
JistAPI.Entity

isTimeless

public boolean isTimeless(org.apache.bcel.classfile.JavaClass c)
                   throws java.lang.ClassNotFoundException
Determine whether given class is timeless. A class is timeless if and only if it implements the JistAPI.Timeless interface, or the object is immutable, as determined automatically or through membership in the static timeless list.

Parameters:
c - BCEL class object
Returns:
whether given class is an timeless
Throws:
java.lang.ClassNotFoundException
See Also:
JistAPI.Timeless

isTimeless

public boolean isTimeless(java.lang.String name)
                   throws java.lang.ClassNotFoundException
Determine whether given class is timeless. A class is timeless if and only if it implements the JistAPI.Timeless interface, or it is determined to be immutable.

Parameters:
name - class name
Returns:
whether given class is an entity
Throws:
java.lang.ClassNotFoundException
See Also:
JistAPI.Entity

isTimeless

public boolean isTimeless(org.apache.bcel.generic.Type type)
                   throws java.lang.ClassNotFoundException
Determine whether given type is timeclass. A type is timeless if and only if it is a primitive type or it is a timeless class

Parameters:
type - type
Returns:
whether t is a timeless
Throws:
java.lang.ClassNotFoundException

isTimelessRuntime

public static boolean isTimelessRuntime(java.lang.Class c)
Determine whether given class is timeless. A class is timeless (at runtime) if and only if it implements the Timeless interface.

Parameters:
c - runtime class object
Returns:
whether given class is an timeless
See Also:
JistAPI.Timeless

isProxiable

public boolean isProxiable(org.apache.bcel.classfile.JavaClass c)
                    throws java.lang.ClassNotFoundException
Determine whether given class is an entity. A class is an entity if and only if it implements the JistAPI.Entity interface.

Parameters:
c - BCEL class object
Returns:
whether given class is an entity
Throws:
java.lang.ClassNotFoundException
See Also:
JistAPI.Entity

isProxiable

public boolean isProxiable(java.lang.String name)
                    throws java.lang.ClassNotFoundException
Determine whether given class is proxiable. A class is proxiable if and only if it implements the JistAPI.Proxiable interface.

Parameters:
name - class name
Returns:
whether given class is an entity
Throws:
java.lang.ClassNotFoundException - class could not be loaded
See Also:
JistAPI.Entity

isBlocking

public static boolean isBlocking(org.apache.bcel.generic.MethodGen mg)
Whether a given method has blocking semantics (whether the caller needs to call with continuation). A method is blocking iff it declares that it throws a JistAPI.Continuation.

Parameters:
mg - method object
Returns:
whether method is blocking

isBlocking

public boolean isBlocking(java.lang.String classname,
                          java.lang.String methodname,
                          org.apache.bcel.generic.Type methodreturn,
                          org.apache.bcel.generic.Type[] methodargs)
                   throws java.lang.ClassNotFoundException
Whether a specified method has blocking semantics (whether the caller needs to call with continuation). A method is blocking iff it declares that it throws a JistAPI.Continuation.

Parameters:
classname - class name
methodname - method name
methodreturn - method return type
methodargs - method parameter types
Returns:
whether method is blocking
Throws:
java.lang.ClassNotFoundException - could not find parent classes

isBlockingRuntime

public static boolean isBlockingRuntime(java.lang.reflect.Method m)
Whether a given regular entity method has blocking semantics (whether the caller needs to call with continuation). A regular (non-proxy) entity method is blocking, at runtime, iff it declares that it throws a Event.ContinuationFrame.

Parameters:
m - method object
Returns:
whether regular entity method is blocking

isBlockingRuntimeProxy

public static boolean isBlockingRuntimeProxy(java.lang.reflect.Method m)
Whether a given proxy entity method has blocking semantics (whether the caller needs to call with continuation). A proxy entity method is blocking, at runtime, iff it declares that it throws a JistAPI.Continuation.

Parameters:
m - method object
Returns:
whether proxy entity method is blocking

isContinuable

public boolean isContinuable(org.apache.bcel.generic.MethodGen mg)
Whether a given method is marked as "continuable". Continuable methods are methods that calls blocking methods (those that declare throws Continuation) or other continuable methods in the same entity.

Parameters:
mg - BCEL MethodGen object
Returns:
whether method is "continuable"

isContinuable

public boolean isContinuable(org.apache.bcel.generic.InvokeInstruction ii,
                             org.apache.bcel.generic.ConstantPoolGen cpg)
Whether a given invocation target is "continuable". Continuable methods are methods that calls blocking methods (those that declare throws Continuation) or other continuable methods in the same entity.

Parameters:
ii - invocation instruction
cpg - class constant pool
Returns:
whether invocation target is "continuable"

isDoNotRewrite

public boolean isDoNotRewrite(org.apache.bcel.classfile.JavaClass c)
                       throws java.lang.ClassNotFoundException
Determine whether given class should not be rewritten. A class can turn off the rewriter by implementing the JistAPI.DoNotRewrite interface.

Parameters:
c - BCEL class object
Returns:
whether given class has rewriting disabled
Throws:
java.lang.ClassNotFoundException
See Also:
JistAPI.DoNotRewrite

setClassName

public static void setClassName(org.apache.bcel.classfile.JavaClass jcl,
                                java.lang.String name)
Modify the name of a class.

Parameters:
jcl - BCEL class object
name - new name for class

logAccessFlags

public static void logAccessFlags(org.apache.bcel.classfile.AccessFlags a)
Emit the access flags to Rewriter log.

Parameters:
a - access flags to log

getRefType

public org.apache.bcel.generic.Type getRefType(org.apache.bcel.generic.Type t)
                                        throws java.lang.ClassNotFoundException
Return the reference type of given type. The reference type of an object type is an EntityRef if the object is an entity. All other types (non-entity objects, arrays and primitives) are their own reference types. Array types are processed recursively.

Parameters:
t - Java type
Returns:
reference type of given type
Throws:
java.lang.ClassNotFoundException
See Also:
EntityRef

getRefTypes

public org.apache.bcel.generic.Type[] getRefTypes(org.apache.bcel.generic.Type[] t)
                                           throws java.lang.ClassNotFoundException
Return an array of reference types for a given array of types. The reference type of an object type is an EntityRef if the object is an entity. All other types (non-entity objects, arrays and primitives) are their own reference types. Array types are processed recursively.

Parameters:
t - array of Java types
Returns:
array of reference type of given array
Throws:
java.lang.ClassNotFoundException

isRefType

public boolean isRefType(org.apache.bcel.generic.Type t)
                  throws java.lang.ClassNotFoundException
Return whether this type is a non-entity. (i.e. whether it needs to be converted into an entity reference)

Parameters:
t - type
Returns:
whether t is a non-entity
Throws:
java.lang.ClassNotFoundException

isRefTypes

public boolean isRefTypes(org.apache.bcel.generic.Type[] t)
                   throws java.lang.ClassNotFoundException
Return whether all types in array are non-entities. (i.e. whether anything in the array needs to be converted to an entity reference)

Parameters:
t - array of types
Returns:
whether all types in t are non-entities
Throws:
java.lang.ClassNotFoundException

getType

public static org.apache.bcel.generic.Type getType(java.lang.Class c)
Return the BCEL Type object for a corresponding Java Class object.

Parameters:
c - type given as Java class object
Returns:
given type as a BCEL Type object

getTypes

public static org.apache.bcel.generic.Type[] getTypes(java.lang.Class[] c)
Return a BCEL Type object array corresponding to Java Class object array.

Parameters:
c - type array given as Java class objects
Returns:
given type array converted to BCEL Type objects

getPrimitiveObjectType

public static java.lang.Class getPrimitiveObjectType(org.apache.bcel.generic.BasicType t)
Return a Class object for a given primitive Java Type.

Parameters:
t - primitive type given as BCEL Type object
Returns:
primitive type as Java class object

getPrimitiveObjectConversionMethod

public static java.lang.String getPrimitiveObjectConversionMethod(org.apache.bcel.generic.BasicType t)
Return name of method used to convert a primitive type wrapper object to a primitive. (eg. doubleValue to convert Double to double.)

Parameters:
t - primitive BCEL type object
Returns:
name of method used to convert a primitive type wrapper object to a primitive type.

getSignature

public static java.lang.String getSignature(java.lang.Class c)
Return the internal Java signature string of a given class.

Parameters:
c - given class type to convert
Returns:
internal Java signature of given class type

getSignature

public static java.lang.String getSignature(java.lang.Class[] args,
                                            java.lang.Class ret)
Return the internal Java signature string of a method.

Parameters:
args - method argument types
ret - method return type
Returns:
internal Java signature of method with given parameter and return types

getSignature

public static java.lang.String getSignature(org.apache.bcel.generic.MethodGen mg)
Return a method signature for given BCEL methodgen object.

Parameters:
mg - BCEL MethodGen object
Returns:
Java method signature

getSignature

public static java.lang.String getSignature(org.apache.bcel.generic.InvokeInstruction ii,
                                            org.apache.bcel.generic.ConstantPoolGen cpg)
Return a method signature from an invocation instruction.

Parameters:
ii - invocation instruction
cpg - class constant pool
Returns:
method signature

getSignature

public static java.lang.String getSignature(java.lang.reflect.Member m)
Return a method signature for given Java reflection method object.

Parameters:
m - Java reflection method object
Returns:
Java method signature

getSignature

public static java.lang.String getSignature(java.lang.String classname,
                                            java.lang.String methodname,
                                            org.apache.bcel.generic.Type methodreturn,
                                            org.apache.bcel.generic.Type[] methodargs)
Return a method signature for the given information.

Parameters:
classname - class name
methodname - method name
methodreturn - method return BCEL type
methodargs - method argument BCEL types
Returns:
method signature string

getMethodStubFieldName

public java.lang.String getMethodStubFieldName(org.apache.bcel.generic.MethodGen mg)
                                        throws java.lang.ClassNotFoundException
Return the name of the method stub field for a given method.

Parameters:
mg - BCEL method generator object
Returns:
name of method stub field for given method
Throws:
java.lang.ClassNotFoundException

getMethodStubFieldName

public static java.lang.String getMethodStubFieldName(java.lang.reflect.Method m)
Return the name of the method stub field for a given method.

Parameters:
m - Java method object
Returns:
name of method stub field for given method

getMethodStubFieldName

public static java.lang.String getMethodStubFieldName(java.lang.String methodName,
                                                      java.lang.String sig)
Return the name of the method stub field for a method with given name and signature (argument and return types).

Parameters:
methodName - name of method
sig - method signature (internal Java representation of method arguments and return types)
Returns:
name of method stub field for method with given name and signature

getContinutationClassName

public static java.lang.String getContinutationClassName(org.apache.bcel.generic.MethodGen mg,
                                                         int pc)
Return the name of the class used to store the continuation of a method at a given "program counter" point. The name needs to be a valid class name, to be in the same package as the method's class, to be unique among other (class, method name, method arguments, pc) values.

Parameters:
mg - method being continued
pc - "program counter" point within method
Returns:
name of class used to store continuation state

getTypeClassname

public static java.lang.String getTypeClassname(org.apache.bcel.generic.Type t)
Return the class name of the given Type or array type, or null for primitive types, or arrays of primitives.

Parameters:
t - BCEL Type object
Returns:
class name of type, or null for primitives

getConstantPoolSize

public static int getConstantPoolSize(org.apache.bcel.classfile.JavaClass jcl)
Return the (byte) size of the constant pool.

Parameters:
jcl - BCEL Java class object
Returns:
size of constant pool in bytes

initializeMethodStubs

public static void initializeMethodStubs(java.lang.String classname)
Generic method for initializing method stubs of entities at runtime. This method uses reflection to simply initialize the static stubs in a generic manner at load time with Method objects. It is called by each entity in its class initializer. The same (or more specific) code could have been placed in each class initializer, but this saves a lot of bytecode generation during transformation, and has no performance implications.

Parameters:
classname - class name that should have its static stubs initialized with Method objects

prime

public int prime(java.lang.String classname)
          throws java.lang.ClassNotFoundException
Prime the rewriter doing a breadth-first search loading (and rewrite) of all classes transitively statically referenced.

Parameters:
classname - root class of the breadth-first traversal
Returns:
number of classes loaded
Throws:
java.lang.ClassNotFoundException - when requested or (directly or indirectly) referenced classes cannot be loaded

installPreRewriteTraversal

public void installPreRewriteTraversal(ClassTraversal.Visitor rewrite)
Install a new rewrite traversal handler.

Parameters:
rewrite - rewriter traversal handler

classToFileName

public static java.lang.String classToFileName(java.lang.String classname)
Convert class name into a filename.

Parameters:
classname - class name to converted
Returns:
file name containing given class