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
voidaddTransformer(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
longgetObjectSize(Object objectToSize)
Get the size of an object.
booleanisRedefineClassesSupported()
Returns if the current JVM supports class redefinition
voidredefineClasses(ClassDefinition[] definitions)
Redefine classes present in the definitions array, with the corresponding class files.
booleanremoveTransformer(ClassFileTransformer transformer)
Removes the given transformer from the set of transformers this Instrumentation object has.

Method Detail

addTransformer

public 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

getAllLoadedClasses

public 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

public 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

public 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.

isRedefineClassesSupported

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

Returns: true if the current JVM supports class redefinition

redefineClasses

public void redefineClasses(ClassDefinition[] definitions)
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 ClassFileTransformer

removeTransformer

public 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