Retransform the supplied set of classes.
This function facilitates the instrumentation
of already loaded classes.
When classes are initially loaded or when they are
redefined,
the initial class file bytes can be transformed with the
ClassFileTransformer.
This function reruns the transformation process
(whether or not a transformation has previously occurred).
This retransformation follows these steps:
canRetransform
false, the bytes returned by
transform
during the last class load or redefine are
reused as the output of the transformation; note that this is
equivalent to reapplying the previous transformation, unaltered;
except that
transform
is not called
canRetransform
true, the
transform
method is called in these transformers
The order of transformation is described in the
transform method.
This same order is used in the automatic reapplication of retransformation
incapable transforms.
The initial class file bytes represent the bytes passed to
ClassLoader.defineClass or
redefineClasses
(before any transformations
were applied), however they might not exactly match them.
The constant pool might not have the same layout or contents.
The constant pool may have more or fewer entries.
Constant pool entries may be in a different order; however,
constant pool indices in the bytecodes of methods will correspond.
Some attributes may not be present.
Where order is not meaningful, for example the order of methods,
order might not be preserved.
This method operates on a set in order to allow interdependent changes to more than one class at the same time (a retransformation of class A can require a retransformation of class B).
If a retransformed method has active stack frames, those active frames continue to run the bytecodes of the original method. The retransformed 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 retransformed class are not affected.
The retransformation may change method bodies, the constant pool and attributes. The retransformation 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. The class file bytes are not checked, verified and installed until after the transformations have been applied, if the resultant bytes are in error this method will throw an exception.
If this method throws an exception, no classes have been retransformed.
This method is intended for use in instrumentation, as described in the class specification.
classes | array of classes to retransform; a zero-length array is allowed, in this case, this method does nothing |
java.lang.instrument.UnmodifiableClassException | if a specified class cannot be modified
(isModifiableClass would return false) | |
java.lang.UnsupportedOperationException | if the current configuration of the JVM does not allow
retransformation (isRetransformClassesSupported is false) or the retransformation attempted
to make unsupported changes | |
java.lang.ClassFormatError | if the data did not contain a valid class | |
java.lang.NoClassDefFoundError | if the name in the class file is not equal to the name of the class | |
java.lang.UnsupportedClassVersionError | if the class file version numbers are not supported | |
java.lang.ClassCircularityError | if the new classes contain a circularity | |
java.lang.LinkageError | if a linkage error occurs | |
java.lang.NullPointerException | if the supplied classes array or any of its components
is null. |
isRetransformClassesSupported, addTransformer, java.lang.instrument.ClassFileTransformer
Diagram: instrument