Class Transformer
java.lang.Object
org.glassfish.pfl.tf.tools.enhancer.Transformer
- All Implemented Interfaces:
Function<byte[],
,byte[]> UnaryFunction<byte[],
byte[]>
ClassFile enhancer for the tracing facility. This modifies the bytecode
for an applicable class, then returns the updated bytecode.
Makes extensive use of the ASM library.
This is split into two parts. The first part modifies the schema
of the class as follows:
- Adds static fields as required for the
SynchronizedHolder<MethodMonitor>
instances. - Modifies the static initializer to set up the new fields, and register the class with the MethodMonitorRegistry. This also constructs the list of method names, which is needed by the second part.
- Re-writes all @InfoMethod methods to take two extra parameters at the end of their argument lists.
- Re-writes all calls to @InfoMethod methods to supply the two extra parameters to all calls.
- Checks that @InfoMethod methods (which must be private) are only called from MM annotated methods.
The second part modifies the MM annotated methods as follows:
- Adds a preamble to set up some local variables, and to call the MethodMonitor.enter method when active.
- Adds a finally block at the end of the method that handles calling MethodMonitor.exit whenever an exception is thrown or propagated from the body of the method.
- Modifies all exit point in the method as follows:
- If the exit point is a return, call MethodMonitor.exit before the return.
- If the exit point is a throw, call MethodMonitor.exception before the throw.
Note that the second part could be run in a ClassFileTransformer or ClassLoader if desired, since this design enhances the class files in place for the first part.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate EnhancedClassData
private final EnhanceTool.ProcessingMode
private final TimingInfoProcessor
private final Util
-
Constructor Summary
ConstructorsConstructorDescriptionTransformer
(Util util, EnhanceTool.ProcessingMode mode, TimingInfoProcessor tip, Set<String> anames) -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.glassfish.pfl.basic.func.UnaryFunction
apply
-
Field Details
-
util
-
mode
-
tip
-
annotationNames
-
ecd
-
-
Constructor Details
-
Transformer
Transformer(Util util, EnhanceTool.ProcessingMode mode, TimingInfoProcessor tip, Set<String> anames)
-
-
Method Details
-
hasAccess
private boolean hasAccess(int access, int flag) -
getSuffix
-
processTimers
private void processTimers() -
evaluate
public byte[] evaluate(byte[] arg) - Specified by:
evaluate
in interfaceUnaryFunction<byte[],
byte[]>
-