java.lang.instrument
Interface Instrumentation


public interface Instrumentation

An Instrumentation object has transformers that will be called each time a class is defined or redefined. The object is given to a premain function that is called before the main function.

Since:
1.5

Method Summary
 void addTransformer(ClassFileTransformer transformer)
          Adds a ClassFileTransformer object to the instrumentation.
 Class[] getAllLoadedClasses()
          Get all the classes loaded by the JVM.
 Class[] getInitiatedClasses(ClassLoader loader)
          Get all the classes loaded by a given class loader
 long getObjectSize(Object objectToSize)
          Get the size of an object.
 boolean isRedefineClassesSupported()
          Returns if the current JVM supports class redefinition
 void redefineClasses(ClassDefinition[] definitions)
          Redefine classes present in the definitions array, with the corresponding class files.
 boolean removeTransformer(ClassFileTransformer transformer)
          Removes the given transformer from the set of transformers this Instrumentation object has.
 

Method Detail

addTransformer

void addTransformer(ClassFileTransformer transformer)
Adds a ClassFileTransformer object to the instrumentation. Each time a class is defined or redefined, the transform method of the transformer object is called.

Parameters:
transformer - the transformer to add
Throws:
NullPointerException - if transformer is null

removeTransformer

boolean removeTransformer(ClassFileTransformer transformer)
Removes the given transformer from the set of transformers this Instrumentation object has.

Parameters:
transformer - the transformer to remove
Returns:
true if the transformer was found and removed, false if the transformer was not found
Throws:
NullPointerException - if transformer is null

isRedefineClassesSupported

boolean isRedefineClassesSupported()
Returns if the current JVM supports class redefinition

Returns:
true if the current JVM supports class redefinition

redefineClasses

void redefineClasses(ClassDefinition[] definitions)
                     throws ClassNotFoundException,
                            UnmodifiableClassException
Redefine classes present in the definitions array, with the corresponding class files.

Parameters:
definitions - an array of classes to redefine
Throws:
ClassNotFoundException - if a class cannot be found
UnmodifiableClassException - if a class cannot be modified
UnsupportedOperationException - if the JVM does not support redefinition or the redefinition made unsupported changes
ClassFormatError - if a class file is not valid
NoClassDefFoundError - if a class name is not equal to the name in the class file specified
UnsupportedClassVersionError - if the class file version numbers are unsupported
ClassCircularityError - if circularity occured with the new classes
LinkageError - if a linkage error occurs
NullPointerException - if the definitions array is null, or any of its element
See Also:
isRedefineClassesSupported(), addTransformer(java.lang.instrument.ClassFileTransformer), ClassFileTransformer

getAllLoadedClasses

Class[] getAllLoadedClasses()
Get all the classes loaded by the JVM.

Returns:
an array containing all the classes loaded by the JVM. The array is empty if no class is loaded.

getInitiatedClasses

Class[] getInitiatedClasses(ClassLoader loader)
Get all the classes loaded by a given class loader

Parameters:
loader - the loader
Returns:
an array containing all the classes loaded by the given loader. The array is empty if no class was loaded by the loader.

getObjectSize

long getObjectSize(Object objectToSize)
Get the size of an object. It contains the size of all fields.

Parameters:
objectToSize - the object
Returns:
the size of the object
Throws:
NullPointerException - if objectToSize is null.