Class Transformer
- java.lang.Object
-
- org.glassfish.pfl.tf.tools.enhancer.Transformer
-
- All Implemented Interfaces:
java.util.function.Function<byte[],byte[]>
,UnaryFunction<byte[],byte[]>
public class Transformer extends java.lang.Object implements 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
Fields Modifier and Type Field Description private java.util.Set<java.lang.String>
annotationNames
private EnhancedClassData
ecd
private EnhanceTool.ProcessingMode
mode
private TimingInfoProcessor
tip
private Util
util
-
Constructor Summary
Constructors Constructor Description Transformer(Util util, EnhanceTool.ProcessingMode mode, TimingInfoProcessor tip, java.util.Set<java.lang.String> anames)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
evaluate(byte[] arg)
private java.lang.String
getSuffix(java.lang.String str)
private boolean
hasAccess(int access, int flag)
private void
processTimers()
-
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 Detail
-
util
private final Util util
-
mode
private final EnhanceTool.ProcessingMode mode
-
tip
private final TimingInfoProcessor tip
-
annotationNames
private final java.util.Set<java.lang.String> annotationNames
-
ecd
private EnhancedClassData ecd
-
-
Constructor Detail
-
Transformer
Transformer(Util util, EnhanceTool.ProcessingMode mode, TimingInfoProcessor tip, java.util.Set<java.lang.String> anames)
-
-
Method Detail
-
hasAccess
private boolean hasAccess(int access, int flag)
-
getSuffix
private java.lang.String getSuffix(java.lang.String str)
-
processTimers
private void processTimers()
-
evaluate
public byte[] evaluate(byte[] arg)
- Specified by:
evaluate
in interfaceUnaryFunction<byte[],byte[]>
-
-