|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.ClassLoader
jist.runtime.Rewriter
public final class Rewriter
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).
Field Summary | |
---|---|
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. |
static java.lang.reflect.Member[] |
continuableMethod
List of methods that are pre-defined to be continuable. |
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. |
static org.apache.log4j.Logger |
log
Logger instance. |
static java.lang.reflect.Method |
method_initializeMethodStubs
Method stub of the generic static method initializer method. |
static java.lang.String[] |
timeless
List of objects that are pre-defined to be timeless. |
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 |
---|
public static final java.lang.String JAVA_MAIN_NAME
public static final java.lang.String JIST_METHOD_PREFIX
public static final java.lang.String JIST_FIELD_PREFIX
public static final java.lang.String JIST_METHODSTUB_PREFIX
public static final java.lang.String JIST_METHOD_SET
public static final java.lang.String JIST_METHOD_GET
public static final java.lang.String JIST_REF_SUFFIX
public static final java.lang.String JIST_ENTITYREF
public static final java.lang.String JIST_STATIC_TRIGGER_SUFFIX
public static final java.lang.String JIST_STATIC_TRIGGER
public static final java.lang.String JIST_CONTINUATION_STATE_PREFIX
public static final org.apache.log4j.Logger log
public static final java.lang.String CACHE_PREFIX
public static final java.lang.String[] timeless
public static java.lang.reflect.Member[] blockingMethod
public static java.lang.reflect.Member[] continuableMethod
public static final java.lang.Class[] blockingClass
public static java.lang.reflect.Method method_initializeMethodStubs
Constructor Detail |
---|
public Rewriter(java.lang.String[] processedPackages, java.lang.String cacheDir, RemoteJist.ResourceFinderRemote resources, java.io.PrintStream serverOut)
processedPackages
- list of packages to process, or null to process
all packages, except those in the (default) ignoredPackages list.cacheDir
- directory for rewritten classfile cacheresources
- remote resources finderserverOut
- server machine output streamMethod Detail |
---|
public java.lang.Class loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException, java.lang.VerifyError
loadClass
in class java.lang.ClassLoader
name
- qualified class name (e.g. java.lang.String)resolve
- not relevant
java.lang.ClassNotFoundException
- thrown if class can not be found
java.lang.VerifyError
- throw if given class does not satify various
JIST programming constraints.protected java.lang.Class findClass(java.lang.String name) throws java.lang.ClassNotFoundException, java.lang.VerifyError
findClass
in class java.lang.ClassLoader
name
- qualified class name (e.g. java.lang.String)
java.lang.ClassNotFoundException
- thrown if class can not be found
java.lang.VerifyError
- throw if given class does not satify various
JIST programming constraints.public org.apache.bcel.classfile.JavaClass lookupJavaClass(java.lang.String name) throws java.lang.ClassNotFoundException
name
- classname
java.lang.ClassNotFoundException
- when class not foundpublic void clearLookupCache()
public java.lang.Class define(org.apache.bcel.classfile.JavaClass jcl)
jcl
- BCEL Java class
protected org.apache.bcel.classfile.JavaClass rewriteClass(org.apache.bcel.classfile.JavaClass jcl) throws java.lang.ClassNotFoundException, java.lang.VerifyError
jcl
- BCEL JavaClass structure to rewrite
java.lang.VerifyError
- throw if given class does not satify various
JIST programming constraints.
java.lang.ClassNotFoundException
- failure to find referenced classprotected java.lang.Class getDiskRewrittenClass(java.lang.String name)
name
- class name
protected void putDiskRewrittenClass(java.lang.String name, byte[] b)
name
- class nameb
- class bytecodepublic boolean addContinuable(java.lang.String sig) throws java.lang.VerifyError
sig
- continuable to add
java.lang.VerifyError
- if signature is of an initialization methodpublic void updateCallGraphAndContinuable(org.apache.bcel.classfile.JavaClass jcl) throws java.lang.ClassNotFoundException
jcl
- BCEL class object to analyze
java.lang.ClassNotFoundException
- failure to load class in call graphpublic void computeContinuableFixedPoint()
public java.lang.String[] getAllClassReferences(java.lang.String classname) throws java.lang.ClassNotFoundException
classname
- name of class to inspect
java.lang.ClassNotFoundException
- failure to find referenced classpublic java.lang.String[] getAllClassReferencesRecursively(java.lang.String classname) throws java.lang.ClassNotFoundException
classname
- name of class to inspect
java.lang.ClassNotFoundException
- failure to find referenced classpublic java.lang.String[] getInterfaceNames(org.apache.bcel.classfile.JavaClass jcl) throws java.lang.ClassNotFoundException
jcl
- BCEL JavaClass object to inspect
java.lang.ClassNotFoundException
- interface classes not foundpublic 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
classname
- classname to initiate search frommethodname
- name of method being soughtmethodreturn
- BCEL return type of method being soughtmethodargs
- BCEL argument type of method being sought
java.lang.ClassNotFoundException
- parent class not foundpublic 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)
jcl
- BCEL JavaClass object to inspectmethodname
- method namemethodreturn
- method return BCEL typemethodargs
- method parameter BCEL types
public boolean isIgnored(java.lang.String classname)
ignoredPackages
array is rewritten.
classname
- given class name
public static boolean isIgnoredStatic(java.lang.String classname)
ignoredPackages
array is
rewritten.
classname
- given class name
public boolean isEntity(org.apache.bcel.classfile.JavaClass c) throws java.lang.ClassNotFoundException
JistAPI.Entity
interface.
c
- BCEL class object
java.lang.ClassNotFoundException
JistAPI.Entity
public boolean isEntity(java.lang.String name) throws java.lang.ClassNotFoundException
JistAPI.Entity
interface.
name
- class name
java.lang.ClassNotFoundException
- class could not be loadedJistAPI.Entity
public static boolean isEntityRuntime(java.lang.Class c)
Entity
interface.
c
- runtime class object
JistAPI.Entity
public boolean isTimeless(org.apache.bcel.classfile.JavaClass c) throws java.lang.ClassNotFoundException
JistAPI.Timeless
interface,
or the object is immutable, as determined automatically or through
membership in the static timeless list.
c
- BCEL class object
java.lang.ClassNotFoundException
JistAPI.Timeless
public boolean isTimeless(java.lang.String name) throws java.lang.ClassNotFoundException
JistAPI.Timeless
interface,
or it is determined to be immutable.
name
- class name
java.lang.ClassNotFoundException
JistAPI.Entity
public boolean isTimeless(org.apache.bcel.generic.Type type) throws java.lang.ClassNotFoundException
type
- type
java.lang.ClassNotFoundException
public static boolean isTimelessRuntime(java.lang.Class c)
Timeless
interface.
c
- runtime class object
JistAPI.Timeless
public boolean isProxiable(org.apache.bcel.classfile.JavaClass c) throws java.lang.ClassNotFoundException
JistAPI.Entity
interface.
c
- BCEL class object
java.lang.ClassNotFoundException
JistAPI.Entity
public boolean isProxiable(java.lang.String name) throws java.lang.ClassNotFoundException
JistAPI.Proxiable
interface.
name
- class name
java.lang.ClassNotFoundException
- class could not be loadedJistAPI.Entity
public static boolean isBlocking(org.apache.bcel.generic.MethodGen mg)
JistAPI.Continuation
.
mg
- method object
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
JistAPI.Continuation
.
classname
- class namemethodname
- method namemethodreturn
- method return typemethodargs
- method parameter types
java.lang.ClassNotFoundException
- could not find parent classespublic static boolean isBlockingRuntime(java.lang.reflect.Method m)
Event.ContinuationFrame
.
m
- method object
public static boolean isBlockingRuntimeProxy(java.lang.reflect.Method m)
JistAPI.Continuation
.
m
- method object
public boolean isContinuable(org.apache.bcel.generic.MethodGen mg)
mg
- BCEL MethodGen object
public boolean isContinuable(org.apache.bcel.generic.InvokeInstruction ii, org.apache.bcel.generic.ConstantPoolGen cpg)
ii
- invocation instructioncpg
- class constant pool
public boolean isDoNotRewrite(org.apache.bcel.classfile.JavaClass c) throws java.lang.ClassNotFoundException
JistAPI.DoNotRewrite
interface.
c
- BCEL class object
java.lang.ClassNotFoundException
JistAPI.DoNotRewrite
public static void setClassName(org.apache.bcel.classfile.JavaClass jcl, java.lang.String name)
jcl
- BCEL class objectname
- new name for classpublic static void logAccessFlags(org.apache.bcel.classfile.AccessFlags a)
a
- access flags to logpublic org.apache.bcel.generic.Type getRefType(org.apache.bcel.generic.Type t) throws java.lang.ClassNotFoundException
t
- Java type
java.lang.ClassNotFoundException
EntityRef
public org.apache.bcel.generic.Type[] getRefTypes(org.apache.bcel.generic.Type[] t) throws java.lang.ClassNotFoundException
t
- array of Java types
java.lang.ClassNotFoundException
public boolean isRefType(org.apache.bcel.generic.Type t) throws java.lang.ClassNotFoundException
t
- type
java.lang.ClassNotFoundException
public boolean isRefTypes(org.apache.bcel.generic.Type[] t) throws java.lang.ClassNotFoundException
t
- array of types
java.lang.ClassNotFoundException
public static org.apache.bcel.generic.Type getType(java.lang.Class c)
c
- type given as Java class object
public static org.apache.bcel.generic.Type[] getTypes(java.lang.Class[] c)
c
- type array given as Java class objects
public static java.lang.Class getPrimitiveObjectType(org.apache.bcel.generic.BasicType t)
t
- primitive type given as BCEL Type object
public static java.lang.String getPrimitiveObjectConversionMethod(org.apache.bcel.generic.BasicType t)
t
- primitive BCEL type object
public static java.lang.String getSignature(java.lang.Class c)
c
- given class type to convert
public static java.lang.String getSignature(java.lang.Class[] args, java.lang.Class ret)
args
- method argument typesret
- method return type
public static java.lang.String getSignature(org.apache.bcel.generic.MethodGen mg)
mg
- BCEL MethodGen object
public static java.lang.String getSignature(org.apache.bcel.generic.InvokeInstruction ii, org.apache.bcel.generic.ConstantPoolGen cpg)
ii
- invocation instructioncpg
- class constant pool
public static java.lang.String getSignature(java.lang.reflect.Member m)
m
- Java reflection method object
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)
classname
- class namemethodname
- method namemethodreturn
- method return BCEL typemethodargs
- method argument BCEL types
public java.lang.String getMethodStubFieldName(org.apache.bcel.generic.MethodGen mg) throws java.lang.ClassNotFoundException
mg
- BCEL method generator object
java.lang.ClassNotFoundException
public static java.lang.String getMethodStubFieldName(java.lang.reflect.Method m)
m
- Java method object
public static java.lang.String getMethodStubFieldName(java.lang.String methodName, java.lang.String sig)
methodName
- name of methodsig
- method signature (internal Java representation of method
arguments and return types)
public static java.lang.String getContinutationClassName(org.apache.bcel.generic.MethodGen mg, int pc)
mg
- method being continuedpc
- "program counter" point within method
public static java.lang.String getTypeClassname(org.apache.bcel.generic.Type t)
t
- BCEL Type object
public static int getConstantPoolSize(org.apache.bcel.classfile.JavaClass jcl)
jcl
- BCEL Java class object
public static void initializeMethodStubs(java.lang.String classname)
classname
- class name that should have its static stubs initialized
with Method objectspublic int prime(java.lang.String classname) throws java.lang.ClassNotFoundException
classname
- root class of the breadth-first traversal
java.lang.ClassNotFoundException
- when requested or (directly or indirectly) referenced classes
cannot be loadedpublic void installPreRewriteTraversal(ClassTraversal.Visitor rewrite)
rewrite
- rewriter traversal handlerpublic static java.lang.String classToFileName(java.lang.String classname)
classname
- class name to converted
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |