Class ConstructorInstrumenter
- java.lang.Object
-
- com.google.monitoring.runtime.instrumentation.ConstructorInstrumenter
-
- All Implemented Interfaces:
java.lang.instrument.ClassFileTransformer
public class ConstructorInstrumenter extends java.lang.Object implements java.lang.instrument.ClassFileTransformerInstruments bytecode by inserting a specified call in the constructor of a given class. This class is intended to be loaded by a javaagent; end-users will want to addConstructorCallbacks by invokinginstrumentClass(Class, ConstructorCallback).
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static byte[]instrument(byte[] originalBytes, java.lang.Class<?> classBeingRedefined)Given the bytes representing a class, add invocations of the ConstructorCallback method to the constructor.static voidinstrumentClass(java.lang.Class<?> c, ConstructorCallback<?> sampler)Ensures that the given sampler will be invoked every time a constructor for class c is invoked.static voidinvokeSamplers(java.lang.Object o)Bytecode is rewritten to invoke this method; it calls the sampler for the given class.byte[]transform(java.lang.ClassLoader loader, java.lang.String className, java.lang.Class<?> classBeingRedefined, java.security.ProtectionDomain protectionDomain, byte[] classfileBuffer)
-
-
-
Method Detail
-
instrumentClass
public static void instrumentClass(java.lang.Class<?> c, ConstructorCallback<?> sampler) throws java.lang.instrument.UnmodifiableClassExceptionEnsures that the given sampler will be invoked every time a constructor for class c is invoked.- Parameters:
c- The class to be trackedsampler- the code to be invoked when an instance of c is constructed- Throws:
java.lang.instrument.UnmodifiableClassException- if c cannot be modified.
-
transform
public byte[] transform(java.lang.ClassLoader loader, java.lang.String className, java.lang.Class<?> classBeingRedefined, java.security.ProtectionDomain protectionDomain, byte[] classfileBuffer)- Specified by:
transformin interfacejava.lang.instrument.ClassFileTransformer
-
instrument
public static byte[] instrument(byte[] originalBytes, java.lang.Class<?> classBeingRedefined)Given the bytes representing a class, add invocations of the ConstructorCallback method to the constructor.- Parameters:
originalBytes- the originalbyte[]code.classBeingRedefined- the class being redefined.- Returns:
- the instrumented
byte[]code.
-
invokeSamplers
public static void invokeSamplers(java.lang.Object o)
Bytecode is rewritten to invoke this method; it calls the sampler for the given class. Note that, unless the javaagent command line argument "subclassesAlso" is specified, it won't do anything if o is a subclass of the class that was supposed to be tracked.- Parameters:
o- the object passed to the samplers.
-
-