|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Instrumentation
This class provides services needed to instrument Java programming language code. Instrumentation is the addition of byte-codes to methods for the purpose of gathering data to be utilized by tools. Since the changes are purely additive, these tools do not modify application state or behavior. Examples of such benign tools include monitoring agents, profilers, coverage analyzers, and event loggers.
The only way to access an instance of the Instrumentation
interface is for the JVM to be launched in a way that indicates
the agent class - see
the package specification.
The Instrumentation
instance is passed
to the premain
method of the agent class.
Once an agent acquires the Instrumentation
instance,
the agent may call methods on the instance at any time.
Method Summary | |
---|---|
void |
addTransformer(ClassFileTransformer transformer)
Registers the supplied transformer. |
Class[] |
getAllLoadedClasses()
Returns an array of all classes currently loaded by the JVM. |
Class[] |
getInitiatedClasses(ClassLoader loader)
Returns an array of all classes for which loader is an initiating loader. |
long |
getObjectSize(Object objectToSize)
Returns an implementation-specific approximation of the amount of storage consumed by the specified object. |
boolean |
isRedefineClassesSupported()
Returns whether or not the current JVM configuration supports redefinition of classes. |
void |
redefineClasses(ClassDefinition[] definitions)
Redefine the supplied set of classes using the supplied class files. |
boolean |
removeTransformer(ClassFileTransformer transformer)
Unregisters the supplied transformer. |
Method Detail |
---|
void addTransformer(ClassFileTransformer transformer)
addTransformer
will always see the class files before any external JVMTI ClassFileLoadHook event listener does.
This method is intended for use in instrumentation, as described in the class specification.
transformer
- the transformer to register
NullPointerException
- if passed a null
transformerboolean removeTransformer(ClassFileTransformer transformer)
transformer
- the transformer to unregister
NullPointerException
- if passed a null
transformerboolean isRedefineClassesSupported()
redefineClasses(java.lang.instrument.ClassDefinition[])
void redefineClasses(ClassDefinition[] definitions) throws ClassNotFoundException, UnmodifiableClassException
If a redefined method has active stack frames, those active frames continue to run the bytecodes of the original method. The redefined method will be used on new invokes.
This method does not cause any initialization except that which would occur under the customary JVM semantics. In other words, redefining a class does not cause its initializers to be run. The values of static variables will remain as they were prior to the call.
Instances of the redefined class are not affected.
Registered transformers will be called before the redefine operation is applied.
The redefinition may change method bodies, the constant pool and attributes. The redefinition must not add, remove or rename fields or methods, change the signatures of methods, or change inheritance. These restrictions maybe be lifted in future versions.
A zero-length definitions
array is allowed, in this case, this
method does nothing.
If this method throws an exception, no classes have been redefined.
This method is intended for use in instrumentation, as described in the class specification.
definitions
- array of classes to redefine with corresponding definitions
ClassNotFoundException
- if a specified class cannot be found
UnmodifiableClassException
- if a specified class cannot be modified
UnsupportedOperationException
- if the current configuration of the JVM does not allow
redefinition (isRedefineClassesSupported()
is false) or the redefinition made unsupported changes
ClassFormatError
- if the data did not contain a valid class
NoClassDefFoundError
- if the name in the class file is not equal to the name of the class
UnsupportedClassVersionError
- if the class file version numbers are not supported
ClassCircularityError
- if the new classes contain a circularity
LinkageError
- if a linkage error occurs
NullPointerException
- if the supplied definitions array or any of its components is null
.isRedefineClassesSupported()
,
addTransformer(java.lang.instrument.ClassFileTransformer)
,
ClassFileTransformer
Class[] getAllLoadedClasses()
Class[] getInitiatedClasses(ClassLoader loader)
loader
is an initiating loader.
If the supplied loader is null
, classes initiated by the bootstrap class
loader are returned.
loader
- the loader whose initiated class list will be returned
long getObjectSize(Object objectToSize)
objectToSize
- the object to size
NullPointerException
- if the supplied Object is null
.
|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.