Class that can enhance bytecode with information about alternative
superclass and access modifiers. It can also extract this information
later when the class is about to be loaded into the VM.
The additional information is added to attributes of the classfile (global attributes
and also member attributes) and as such the class remain compatible and
understandable for any VM. But if loaded by classloader that before defining
the class invokes:
byte[] arr = ...;
arr = PatchByteCode.patch (arr);
The class is altered in its superclass and/or access modifiers.
The patching mechanism uses two attributes. ATTR_SUPERCLASS can be just
in global attributes pool (and only once), is of length 2 and contains index
into constant pool that contains definition of a Class that should become
the alternate superclass. Attribute ATTR_MEMBER can appear in global
attribute set and also in set of each member (field or method). It is of
length 2 and contains alternate value for access flags of the class or of
the field.
For purposes for speed, each patched class file has to end with bytes "nb".
This is achieved by finishing the patching process by adding third attribute
"org.netbeans.enhanced" with value "nb". As such the PatchByteCode.patch
can quickly check the byte array and process just those that need processing.
author: Jaroslav Tulach |