All classes given are redefined according to the definitions supplied. A method in a redefined class is called 'equivalent' (to the old version of the method) if
- their bytecodes are the same except for indicies into the constant pool, and
- the referenced constants are equal.
Otherwise, the new method is called 'non-equivalent'. If a redefined method has active stack frames, those active frames continue to run the bytecodes of the previous version of the method. If the new version of such a method is non-equivalent, then a method from one of these active frames is called 'obsolete' and {@link Method#isObsolete Method.isObsolete()}will return true when called on one of these methods. If resetting such a frame is desired, use {@link ThreadReference#popFrames ThreadReference.popFrames(StackFrame)}to pop the old obsolete method execution from the stack. New invocations of redefined methods will always invoke the new versions.
This function 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 preexisting static variables will remain as they were prior to the call. However, completely uninitialized (new) static variables will be assigned their default value.
If a redefined class has instances then all those instances will have the fields defined by the redefined class at the completion of the call. Preexisting fields will retain their previous values. Any new fields will have their default values; no instance initializers or constructors are run.
Threads need not be suspended.
No events are generated by this function.
All breakpoints in the redefined classes are deleted.
Not all target virtual machines support this operation. Use {@link #canRedefineClasses() canRedefineClasses()}to determine if the operation is supported. Use {@link #canAddMethod() canAddMethod()}to determine if the redefinition can add methods. Use {@link #canUnrestrictedlyRedefineClasses() canUnrestrictedlyRedefineClasses()}to determine if the redefinition can change the schema, delete methods, change the class hierarchy, etc.
@param classToBytes A map from {@link ReferenceType}to array of byte. The bytes represent the new class definition and are in Java Virtual Machine class file format.
@throws java.lang.UnsupportedOperationException ifthe target virtual machine does not support this operation.
- If {@link #canRedefineClasses() canRedefineClasses()}is false any call of this method will throw this exception.
- If {@link #canAddMethod() canAddMethod()} is falseattempting to add a method will throw this exception.
- If {@link #canUnrestrictedlyRedefineClasses() canUnrestrictedlyRedefineClasses()}is false, attempting any of the following will throw this exception
- changing the schema (the fields)
- changing the hierarchy (subclasses, interfaces)
- deleting a method
- changing class modifiers
- changing method modifiers
@throws java.lang.NoClassDefFoundError if the bytesdon't correspond to the reference type (the names don't match).
@throws java.lang.VerifyError if a "verifier" detectsthat a class, though well formed, contains an internal inconsistency or security problem.
@throws java.lang.ClassFormatError if the bytesdo not represent a valid class.
@throws java.lang.ClassCircularityError if acircularity has been detected while initializing a class.
@throws java.lang.UnsupportedClassVersionError if themajor and minor version numbers in bytes are not supported by the VM.
@throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
@see Method#isObsolete
@see ThreadReference#popFrames
@see #canRedefineClasses
@see #canAddMethod
@see #canUnrestrictedlyRedefineClasses
@since 1.4