Class AllocationInstrumenter
java.lang.Object
com.google.monitoring.runtime.instrumentation.AllocationInstrumenter
- All Implemented Interfaces:
ClassFileTransformer
Instruments bytecodes that allocate heap memory to call a recording hook.
This will add a static invocation to a recorder function to any bytecode that
looks like it will be allocating heap memory allowing users to implement heap
profiling schemes.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]instrument(byte[] originalBytes, ClassLoader loader) static byte[]instrument(byte[] originalBytes, String recorderClass, String recorderMethod, ClassLoader loader) Given the bytes representing a class, go through all the bytecode in it and instrument any occurrences of new/newarray/anewarray/multianewarray with pre- and post-allocation hooks.static voidpremain(String agentArgs, Instrumentation inst) byte[]transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] origBytes) Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.instrument.ClassFileTransformer
transform
-
Method Details
-
premain
-
transform
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] origBytes) - Specified by:
transformin interfaceClassFileTransformer
-
instrument
public static byte[] instrument(byte[] originalBytes, String recorderClass, String recorderMethod, ClassLoader loader) Given the bytes representing a class, go through all the bytecode in it and instrument any occurrences of new/newarray/anewarray/multianewarray with pre- and post-allocation hooks. Even more fun, intercept calls to the reflection API's Array.newInstance() and instrument those too.- Parameters:
originalBytes- the originalbyte[]code.recorderClass- theStringinternal name of the class containing the recorder method to run.recorderMethod- theStringname of the recorder method to run.loader- theClassLoaderfor this class.- Returns:
- the instrumented
byte[]code.
-
instrument
- Parameters:
originalBytes- The original version of the class.loader- The ClassLoader of this class.- Returns:
- the instrumented version of this class.
- See Also:
-