public class AbstractClassTransformer extends java.lang.Object implements ISemanticsCollector
| Modifier and Type | Field and Description |
|---|---|
private HashMap<java.lang.String,java.lang.Boolean> |
analyzeMembers
Analyze the members of the individual classes.
|
private HashMap<java.lang.String,HashMap<java.lang.String,Monitor>> |
assignments
Stores the assignments.
|
(package private) static java.lang.String |
DELEGATING_RANDOM_ACCESS_FILE
The fully qualified name of the delegating random access file.
|
private java.lang.String[] |
excludeClasses
Stores classes to be excluded.
|
private boolean |
isStatic
Stores if static instrumentation should be done.
|
private int |
mainCount
Counts the number of main methods (usually only the first one
is relevant).
|
private java.util.HashSet<java.lang.String> |
registeredClasses
Stores registered classes.
|
| Constructor and Description |
|---|
AbstractClassTransformer(boolean isStatic)
Creates a new monitoring class file transformer.
|
| Modifier and Type | Method and Description |
|---|---|
private boolean |
analyzeMembers(java.lang.String clName,
de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cl)
Returns whether the members of a class shall be analyzed.
|
void |
assignSemantics(java.lang.String cls,
java.lang.String methodSignature,
Monitor semantics)
Assigns the monitoring semantics for the method
methodName
in class cls. |
void |
deleteSemantics(java.lang.String cls)
Removes the assigned semantics for
cls. |
private boolean |
doFirstMain(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cls,
de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IBehavior behavior,
Monitor mGroupClass,
TransformationType type)
Processes the first main method which occurs during instrumentation of a
program.
|
private boolean |
doMethod(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IBehavior behavior,
Monitor mGroupClass,
boolean inherited,
TransformationType type,
MethodEditor editor)
Processes a method of a regular class (system under measurement).
|
protected static <T extends java.lang.annotation.Annotation> |
getAnnotation(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IBehavior member,
java.lang.Class<T> annotation,
AnnotationSearchType search)
Returns the annotation of the specified
annotation type
if it is defined for member. |
private static <T extends java.lang.annotation.Annotation> |
getAnnotation(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IBehavior member,
de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass searchIn,
java.lang.Class<T> annotation,
AnnotationSearchType search,
boolean topCall)
Returns the annotation of the specified
annotation type
if it is defined for member. |
protected static <T extends java.lang.annotation.Annotation> |
getAnnotation(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cls,
java.lang.Class<T> annotation,
AnnotationSearchType search)
Returns the annotation of the specified
annotation type
if it is defined for cls. |
protected static <T extends java.lang.annotation.Annotation> |
getAnnotation(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IField member,
java.lang.Class<T> annotation,
AnnotationSearchType search)
Returns the annotation of the specified
annotation type
if it is defined for member. |
private static Monitor |
getMonitorAnnotation(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cl)
Returns the
Monitor annotation for cl. |
protected boolean |
handleMethodInstrumentationException(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException exception)
Is called to handle an instrumentation which occurred during
instrumenting a method.
|
private boolean |
instrumentNotifyTimer(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IBehavior behavior,
Timer notifyTimer)
Performs the instrumentation for the timer notification.
|
private boolean |
instrumentThreadRun(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cl,
TransformationType type)
Instruments the run method of a thread.
|
static java.lang.String |
internalVmFqnToJavaFqn(java.lang.String vmFqn)
Converts a given fully qualified class name in the
internal form of fully qualified class and interface names as defined
in The Java Virtual Machine Specification (slash separated) to a Java
fully qualified name (dot separated).
|
private boolean |
isRandomAccessFile(java.lang.String className)
Returns if the given class name denotes the random access file.
|
private boolean |
isRecorderClass(java.lang.String className)
Returns if the given class name denotes a recorder class.
|
private boolean |
isSocketInputStream(java.lang.String className)
Returns if the given class name denotes the socket input stream.
|
private boolean |
isSocketOutputStream(java.lang.String className)
Returns if the given class name denotes the socket output stream.
|
static java.lang.String |
javaFqnToInternalVmFqnTo(java.lang.String fqn)
Converts a given Java fully qualified class name (dot separated) to the
internal form of fully qualified class and interface names as defined
in The Java Virtual Machine Specification (slash separated).
|
private boolean |
processNotifications(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IBehavior behavior,
Monitor mGroup,
de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.ICodeModifier modifier)
Processes value notifications on the given method.
|
protected static <T extends java.lang.annotation.Annotation> |
pruneAnnotation(java.lang.Class<T> annotation)
Returns whether the specified annotation may be pruned, i.e. removed
from resulting bytecode.
|
private boolean |
registerRecorderId(Monitor mGroup,
de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cl)
Registers a monitoring element (class or method) for monitoring.
|
protected void |
retransformAssigned(java.lang.String[] classNames)
Retransforms the specified classes.
|
boolean |
shouldInstrument(java.lang.String className)
Returns if the class given by its class name should be instrumented.
|
boolean |
transform(java.lang.String name,
de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cl,
TransformationType type)
Processes a class of the system under monitoring.
|
static final java.lang.String DELEGATING_RANDOM_ACCESS_FILE
private boolean isStatic
private java.util.HashSet<java.lang.String> registeredClasses
private int mainCount
private java.lang.String[] excludeClasses
private HashMap<java.lang.String,java.lang.Boolean> analyzeMembers
public AbstractClassTransformer(boolean isStatic)
isStatic - denotes if static instrumentation should be done or
dynamicprivate final boolean isRandomAccessFile(java.lang.String className)
className - the class name to be tested given in the
internal form of fully qualified class and interface names as defined
in The Java Virtual Machine Specification. For example,
"java/util/List".false if it is not the random access file,
true elseprivate final boolean isSocketInputStream(java.lang.String className)
className - the class name to be tested given in the
internal form of fully qualified class and interface names as defined
in The Java Virtual Machine Specification. For example,
"java/util/List".false if it is not the socket input stream,
true elseprivate final boolean isSocketOutputStream(java.lang.String className)
className - the class name to be tested given in the
internal form of fully qualified class and interface names as defined
in The Java Virtual Machine Specification. For example,
"java/util/List".false if it is not the socket output stream,
true elseprivate final boolean isRecorderClass(java.lang.String className)
className - the class name to be tested given in the
internal form of fully qualified class and interface names as defined
in The Java Virtual Machine Specification. For example,
"java/util/List".false if it is not a recorder class,
true elsepublic static final java.lang.String internalVmFqnToJavaFqn(java.lang.String vmFqn)
vmFqn - the fully qualified name according to the Java Virtual
Machine Specificationpublic static final java.lang.String javaFqnToInternalVmFqnTo(java.lang.String fqn)
fqn - the fully qualified Java namepublic final boolean shouldInstrument(java.lang.String className)
className - the name of the class to be checked given in the
internal form of fully qualified class and interface names as defined
in The Java Virtual Machine Specification. For example,
"java/util/List".true if the class should be instrumented,
false elseprivate static final Monitor getMonitorAnnotation(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cl) throws de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException
Monitor annotation for cl. This method
considers whether cl or its (outer) declaring class has a
Monitor annotation and returns it or stops at a
ExcludeFromMonitoring annotation.cl - the class to be queried for the annotationde.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException - in case that some class cannot be foundprivate boolean analyzeMembers(java.lang.String clName,
de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cl)
throws de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException
analyzeMembers is not null.clName - the class namecl - the class itself for further inspectiontrue if thede.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException - in case of problems with the bytecodepublic final boolean transform(java.lang.String name,
de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cl,
TransformationType type)
throws de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException
name - the name of the class given in the
internal form of fully qualified class and interface names as defined
in The Java Virtual Machine Specification. For example,
"java/util/List".cl - the classtype - the type of the transformationtrue if the class was modified,
false elsede.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException - in case that any error occurs
while processing bytecodeprotected void retransformAssigned(java.lang.String[] classNames)
classNames - the class namesprivate final boolean instrumentThreadRun(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cl,
TransformationType type)
throws de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException
cl - the class to analyzetype - the type of the transformationtrue if the class was modified,
false elsede.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException - in case that the new code cannot be
compiledprivate final boolean registerRecorderId(Monitor mGroup, de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cl) throws de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException
mGroup - the monitoring annotationcl - the containing classtrue if the class was modified,
false elsede.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException - in case of any byte code errorprotected static final <T extends java.lang.annotation.Annotation> boolean pruneAnnotation(java.lang.Class<T> annotation)
Instrumented annotation, which
is enabled only in case of dynamic instrumentation (for staged static
instrumentations).T - the type of the annotationannotation - the type of the annotation (meta class)true if the given annotation (type) may be pruned,
false elseprotected static final <T extends java.lang.annotation.Annotation> T getAnnotation(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IField member,
java.lang.Class<T> annotation,
AnnotationSearchType search)
annotation type
if it is defined for member.T - the type of the annotationmember - the member to be considered for querying the
annotationannotation - the type of the annotation to be searched for (meta
class)search - the annotation search typemethod, null otherwiseprotected static final <T extends java.lang.annotation.Annotation> T getAnnotation(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IBehavior member,
java.lang.Class<T> annotation,
AnnotationSearchType search)
annotation type
if it is defined for member.T - the type of the annotationmember - the member to be considered for querying the
annotationannotation - the type of the annotation to be searched for (meta
class)search - the annotation search typemethod, null otherwiseprivate static final <T extends java.lang.annotation.Annotation> T getAnnotation(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IBehavior member,
de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass searchIn,
java.lang.Class<T> annotation,
AnnotationSearchType search,
boolean topCall)
annotation type
if it is defined for member.T - the type of the annotationmember - the member to be considered for querying the
annotationsearchIn - the class / interface to search inannotation - the type of the annotation to be searched for (meta
class)search - the annotation search typetopCall - is this method called from the top of the current
recursion or from withinmethod, null otherwiseprotected static final <T extends java.lang.annotation.Annotation> T getAnnotation(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cls,
java.lang.Class<T> annotation,
AnnotationSearchType search)
annotation type
if it is defined for cls.T - the type of the annotationcls - the class to be considered for querying the
annotationannotation - the type of the annotation to be searched for (meta
class)search - the annotation search typemethod, null otherwiseprivate final boolean doFirstMain(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IClass cls,
de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IBehavior behavior,
Monitor mGroupClass,
TransformationType type)
throws de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException
cls - the classbehavior - the behavior to be modifiedmGroupClass - the annotation on class level as cause for
instrumenting this method (may be null)type - the type of the transformationtrue if the class was modified,
false elsede.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException - in case that the code added by
instrumentation does not compileprivate final boolean doMethod(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IBehavior behavior,
Monitor mGroupClass,
boolean inherited,
TransformationType type,
MethodEditor editor)
throws de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException
behavior - the behavior to be modifiedmGroupClass - the annotation on class level as cause for
instrumenting this method (may be null)inherited - whether mGroupClass is inheritedtype - the type of the transformationeditor - the editor for modificationstrue if the behavior was modified,
false elsede.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException - in case that the code added by
instrumentation does not compileprivate boolean processNotifications(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IBehavior behavior,
Monitor mGroup,
de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.ICodeModifier modifier)
throws de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException
behavior - the method to be changedmGroup - the annotation which indicated recording (may be
null)modifier - the code modifier to be usedtrue if the behavior was modified,
false elsede.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException - if any instrumented code is not validprivate boolean instrumentNotifyTimer(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IBehavior behavior,
Timer notifyTimer)
throws de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException
behavior - the method / constructor being processednotifyTimer - the timer annotation appended to
behaviorInfotrue if the behavior was modified,
false elsede.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException - in case that new code cannot be compiledprotected boolean handleMethodInstrumentationException(de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.InstrumenterException exception)
exception - the exception occurredtrue if the exception was handled and
instrumentation can continue with the next method, false
if the exception should be thrown by the caller for further handlingpublic void assignSemantics(java.lang.String cls,
java.lang.String methodSignature,
Monitor semantics)
methodName
in class cls.assignSemantics in interface ISemanticsCollectorcls - the name of the class the monitoring semantics is defined formethodSignature - the name of the method to assign the semantics tosemantics - the monitoring semanticspublic void deleteSemantics(java.lang.String cls)
cls.cls - the name of the class the monitoring semantics shall be
removed for