final class SymbolTable
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
SymbolTable.Entry
An entry of a SymbolTable.
|
Modifier and Type | Field and Description |
---|---|
private int |
bootstrapMethodCount
The number of bootstrap methods in
bootstrapMethods . |
private ByteVector |
bootstrapMethods
The content of the BootstrapMethods attribute 'bootstrap_methods' array corresponding to this
SymbolTable.
|
private java.lang.String |
className
The internal name of the class to which this symbol table belongs.
|
(package private) ClassWriter |
classWriter
The ClassWriter to which this SymbolTable belongs.
|
private ByteVector |
constantPool
The content of the ClassFile's constant_pool JVMS structure corresponding to this SymbolTable.
|
private int |
constantPoolCount
The number of constant pool items in
constantPool , plus 1. |
private SymbolTable.Entry[] |
entries
A hash set of all the entries in this SymbolTable (this includes the constant pool entries, the
bootstrap method entries and the type table entries).
|
private int |
entryCount
The total number of
SymbolTable.Entry instances in entries . |
private int |
majorVersion
The major version number of the class to which this symbol table belongs.
|
private ClassReader |
sourceClassReader
The ClassReader from which this SymbolTable was constructed, or null if it was
constructed from scratch.
|
private int |
typeCount
The actual number of elements in
typeTable . |
private SymbolTable.Entry[] |
typeTable
An ASM specific type table used to temporarily store internal names that will not necessarily
be stored in the constant pool.
|
Constructor and Description |
---|
SymbolTable(ClassWriter classWriter)
Constructs a new, empty SymbolTable for the given ClassWriter.
|
SymbolTable(ClassWriter classWriter,
ClassReader classReader)
Constructs a new SymbolTable for the given ClassWriter, initialized with the constant pool and
bootstrap methods of the given ClassReader.
|
Modifier and Type | Method and Description |
---|---|
private void |
add(SymbolTable.Entry entry)
Adds the given entry in the
entries hash set. |
(package private) Symbol |
addBootstrapMethod(Handle bootstrapMethodHandle,
java.lang.Object... bootstrapMethodArguments)
Adds a bootstrap method to the BootstrapMethods attribute of this symbol table.
|
private Symbol |
addBootstrapMethod(int offset,
int length,
int hashCode)
Adds a bootstrap method to the BootstrapMethods attribute of this symbol table.
|
(package private) Symbol |
addConstant(java.lang.Object value)
Adds a number or string constant to the constant pool of this symbol table.
|
(package private) Symbol |
addConstantClass(java.lang.String value)
Adds a CONSTANT_Class_info to the constant pool of this symbol table.
|
(package private) Symbol |
addConstantDouble(double value)
Adds a CONSTANT_Double_info to the constant pool of this symbol table.
|
(package private) Symbol |
addConstantDynamic(java.lang.String name,
java.lang.String descriptor,
Handle bootstrapMethodHandle,
java.lang.Object... bootstrapMethodArguments)
Adds a CONSTANT_Dynamic_info to the constant pool of this symbol table.
|
private void |
addConstantDynamicOrInvokeDynamicReference(int tag,
int index,
java.lang.String name,
java.lang.String descriptor,
int bootstrapMethodIndex)
Adds a new CONSTANT_Dynamic_info or CONSTANT_InvokeDynamic_info to the constant pool of this
symbol table.
|
private Symbol |
addConstantDynamicOrInvokeDynamicReference(int tag,
java.lang.String name,
java.lang.String descriptor,
int bootstrapMethodIndex)
Adds a CONSTANT_Dynamic or a CONSTANT_InvokeDynamic_info to the constant pool of this symbol
table.
|
(package private) Symbol |
addConstantFieldref(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
Adds a CONSTANT_Fieldref_info to the constant pool of this symbol table.
|
(package private) Symbol |
addConstantFloat(float value)
Adds a CONSTANT_Float_info to the constant pool of this symbol table.
|
(package private) Symbol |
addConstantInteger(int value)
Adds a CONSTANT_Integer_info to the constant pool of this symbol table.
|
private Symbol |
addConstantIntegerOrFloat(int tag,
int value)
Adds a CONSTANT_Integer_info or CONSTANT_Float_info to the constant pool of this symbol table.
|
private void |
addConstantIntegerOrFloat(int index,
int tag,
int value)
Adds a new CONSTANT_Integer_info or CONSTANT_Float_info to the constant pool of this symbol
table.
|
(package private) Symbol |
addConstantInvokeDynamic(java.lang.String name,
java.lang.String descriptor,
Handle bootstrapMethodHandle,
java.lang.Object... bootstrapMethodArguments)
Adds a CONSTANT_InvokeDynamic_info to the constant pool of this symbol table.
|
(package private) Symbol |
addConstantLong(long value)
Adds a CONSTANT_Long_info to the constant pool of this symbol table.
|
private void |
addConstantLongOrDouble(int index,
int tag,
long value)
Adds a new CONSTANT_Long_info or CONSTANT_Double_info to the constant pool of this symbol
table.
|
private Symbol |
addConstantLongOrDouble(int tag,
long value)
Adds a CONSTANT_Long_info or CONSTANT_Double_info to the constant pool of this symbol table.
|
private void |
addConstantMemberReference(int index,
int tag,
java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
Adds a new CONSTANT_Fieldref_info, CONSTANT_Methodref_info or CONSTANT_InterfaceMethodref_info
to the constant pool of this symbol table.
|
private SymbolTable.Entry |
addConstantMemberReference(int tag,
java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
Adds a CONSTANT_Fieldref_info, CONSTANT_Methodref_info or CONSTANT_InterfaceMethodref_info to
the constant pool of this symbol table.
|
private void |
addConstantMethodHandle(int index,
int referenceKind,
java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
Adds a new CONSTANT_MethodHandle_info to the constant pool of this symbol table.
|
(package private) Symbol |
addConstantMethodHandle(int referenceKind,
java.lang.String owner,
java.lang.String name,
java.lang.String descriptor,
boolean isInterface)
Adds a CONSTANT_MethodHandle_info to the constant pool of this symbol table.
|
(package private) Symbol |
addConstantMethodref(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor,
boolean isInterface)
Adds a CONSTANT_Methodref_info or CONSTANT_InterfaceMethodref_info to the constant pool of this
symbol table.
|
(package private) Symbol |
addConstantMethodType(java.lang.String methodDescriptor)
Adds a CONSTANT_MethodType_info to the constant pool of this symbol table.
|
(package private) Symbol |
addConstantModule(java.lang.String moduleName)
Adds a CONSTANT_Module_info to the constant pool of this symbol table.
|
private void |
addConstantNameAndType(int index,
java.lang.String name,
java.lang.String descriptor)
Adds a new CONSTANT_NameAndType_info to the constant pool of this symbol table.
|
(package private) int |
addConstantNameAndType(java.lang.String name,
java.lang.String descriptor)
Adds a CONSTANT_NameAndType_info to the constant pool of this symbol table.
|
(package private) Symbol |
addConstantPackage(java.lang.String packageName)
Adds a CONSTANT_Package_info to the constant pool of this symbol table.
|
(package private) Symbol |
addConstantString(java.lang.String value)
Adds a CONSTANT_String_info to the constant pool of this symbol table.
|
private void |
addConstantUtf8(int index,
java.lang.String value)
Adds a new CONSTANT_String_info to the constant pool of this symbol table.
|
(package private) int |
addConstantUtf8(java.lang.String value)
Adds a CONSTANT_Utf8_info to the constant pool of this symbol table.
|
private void |
addConstantUtf8Reference(int index,
int tag,
java.lang.String value)
Adds a new CONSTANT_Class_info, CONSTANT_String_info, CONSTANT_MethodType_info,
CONSTANT_Module_info or CONSTANT_Package_info to the constant pool of this symbol table.
|
private Symbol |
addConstantUtf8Reference(int tag,
java.lang.String value)
Adds a CONSTANT_Class_info, CONSTANT_String_info, CONSTANT_MethodType_info,
CONSTANT_Module_info or CONSTANT_Package_info to the constant pool of this symbol table.
|
(package private) int |
addMergedType(int typeTableIndex1,
int typeTableIndex2)
Adds a merged type in the type table of this symbol table.
|
(package private) int |
addType(java.lang.String value)
Adds a type in the type table of this symbol table.
|
private int |
addTypeInternal(SymbolTable.Entry entry)
Adds the given type Symbol to
typeTable . |
(package private) int |
addUninitializedType(java.lang.String value,
int bytecodeOffset)
Adds an
Frame.ITEM_UNINITIALIZED type in the type table of this symbol table. |
(package private) int |
computeBootstrapMethodsSize()
Returns the size in bytes of this symbol table's BootstrapMethods attribute.
|
private void |
copyBootstrapMethods(ClassReader classReader,
char[] charBuffer)
Read the BootstrapMethods 'bootstrap_methods' array binary content and add them as entries of
the SymbolTable.
|
private SymbolTable.Entry |
get(int hashCode)
Returns the list of entries which can potentially have the given hash code.
|
(package private) java.lang.String |
getClassName()
Returns the internal name of the class to which this symbol table belongs.
|
(package private) int |
getConstantPoolCount()
Returns the number of items in this symbol table's constant_pool array (plus 1).
|
(package private) int |
getConstantPoolLength()
Returns the length in bytes of this symbol table's constant_pool array.
|
(package private) int |
getMajorVersion()
Returns the major version of the class to which this symbol table belongs.
|
(package private) ClassReader |
getSource()
Returns the ClassReader from which this SymbolTable was constructed.
|
(package private) Symbol |
getType(int typeIndex)
Returns the type table element whose index is given.
|
private static int |
hash(int tag,
int value) |
private static int |
hash(int tag,
long value) |
private static int |
hash(int tag,
java.lang.String value) |
private static int |
hash(int tag,
java.lang.String value1,
int value2) |
private static int |
hash(int tag,
java.lang.String value1,
java.lang.String value2) |
private static int |
hash(int tag,
java.lang.String value1,
java.lang.String value2,
int value3) |
private static int |
hash(int tag,
java.lang.String value1,
java.lang.String value2,
java.lang.String value3) |
private static int |
hash(int tag,
java.lang.String value1,
java.lang.String value2,
java.lang.String value3,
int value4) |
private SymbolTable.Entry |
put(SymbolTable.Entry entry)
Puts the given entry in the
entries hash set. |
(package private) void |
putBootstrapMethods(ByteVector output)
Puts this symbol table's BootstrapMethods attribute in the given ByteVector.
|
(package private) void |
putConstantPool(ByteVector output)
Puts this symbol table's constant_pool array in the given ByteVector, preceded by the
constant_pool_count value.
|
(package private) int |
setMajorVersionAndClassName(int majorVersion,
java.lang.String className)
Sets the major version and the name of the class to which this symbol table belongs.
|
final ClassWriter classWriter
ClassWriter.getCommonSuperClass(java.lang.String, java.lang.String)
and to serialize custom attributes with Attribute.write(org.springframework.asm.ClassWriter, byte[], int, int, int)
.private final ClassReader sourceClassReader
private int majorVersion
private java.lang.String className
private int entryCount
SymbolTable.Entry
instances in entries
. This includes entries that are
accessible (recursively) via SymbolTable.Entry.next
.private SymbolTable.Entry[] entries
SymbolTable.Entry
instance is stored at
the array index given by its hash code modulo the array size. If several entries must be stored
at the same array index, they are linked together via their SymbolTable.Entry.next
field. The
factory methods of this class make sure that this table does not contain duplicated entries.private int constantPoolCount
constantPool
, plus 1. The first constant pool
item has index 1, and long and double items count for two items.private ByteVector constantPool
private int bootstrapMethodCount
bootstrapMethods
. Corresponds to the
BootstrapMethods_attribute's num_bootstrap_methods field value.private ByteVector bootstrapMethods
private int typeCount
typeTable
. These elements are stored from index 0 to
typeCount (excluded). The other array entries are empty.private SymbolTable.Entry[] typeTable
Symbol.TYPE_TAG
and Symbol.UNINITIALIZED_TYPE_TAG
) Symbol. The type symbol at index
i
has its Symbol.index
equal to i
(and vice versa).SymbolTable(ClassWriter classWriter)
classWriter
- a ClassWriter.SymbolTable(ClassWriter classWriter, ClassReader classReader)
classWriter
- a ClassWriter.classReader
- the ClassReader whose constant pool and bootstrap methods must be copied to
initialize the SymbolTable.private void copyBootstrapMethods(ClassReader classReader, char[] charBuffer)
classReader
- the ClassReader whose bootstrap methods must be copied to initialize the
SymbolTable.charBuffer
- a buffer used to read strings in the constant pool.ClassReader getSource()
int getMajorVersion()
java.lang.String getClassName()
int setMajorVersionAndClassName(int majorVersion, java.lang.String className)
majorVersion
- a major ClassFile version number.className
- an internal class name.int getConstantPoolCount()
int getConstantPoolLength()
void putConstantPool(ByteVector output)
output
- where the JVMS ClassFile's constant_pool array must be put.int computeBootstrapMethodsSize()
void putBootstrapMethods(ByteVector output)
output
- where the JVMS BootstrapMethods attribute must be put.private SymbolTable.Entry get(int hashCode)
hashCode
- a SymbolTable.Entry.hashCode
value.SymbolTable.Entry.next
field.private SymbolTable.Entry put(SymbolTable.Entry entry)
entries
hash set. This method does not check
whether entries
already contains a similar entry or not. entries
is resized
if necessary to avoid hash collisions (multiple entries needing to be stored at the same entries
array index) as much as possible, with reasonable memory usage.entry
- an Entry (which must not already be contained in entries
).private void add(SymbolTable.Entry entry)
entries
hash set. This method does not check
whether entries
already contains a similar entry or not, and does not resize
entries
if necessary.entry
- an Entry (which must not already be contained in entries
).Symbol addConstant(java.lang.Object value)
Symbol addConstantClass(java.lang.String value)
value
- the internal name of a class.Symbol addConstantFieldref(java.lang.String owner, java.lang.String name, java.lang.String descriptor)
owner
- the internal name of a class.name
- a field name.descriptor
- a field descriptor.Symbol addConstantMethodref(java.lang.String owner, java.lang.String name, java.lang.String descriptor, boolean isInterface)
owner
- the internal name of a class.name
- a method name.descriptor
- a method descriptor.isInterface
- whether owner is an interface or not.private SymbolTable.Entry addConstantMemberReference(int tag, java.lang.String owner, java.lang.String name, java.lang.String descriptor)
tag
- one of Symbol.CONSTANT_FIELDREF_TAG
, Symbol.CONSTANT_METHODREF_TAG
or Symbol.CONSTANT_INTERFACE_METHODREF_TAG
.owner
- the internal name of a class.name
- a field or method name.descriptor
- a field or method descriptor.private void addConstantMemberReference(int index, int tag, java.lang.String owner, java.lang.String name, java.lang.String descriptor)
index
- the constant pool index of the new Symbol.tag
- one of Symbol.CONSTANT_FIELDREF_TAG
, Symbol.CONSTANT_METHODREF_TAG
or Symbol.CONSTANT_INTERFACE_METHODREF_TAG
.owner
- the internal name of a class.name
- a field or method name.descriptor
- a field or method descriptor.Symbol addConstantString(java.lang.String value)
value
- a string.Symbol addConstantInteger(int value)
value
- an int.Symbol addConstantFloat(float value)
value
- a float.private Symbol addConstantIntegerOrFloat(int tag, int value)
tag
- one of Symbol.CONSTANT_INTEGER_TAG
or Symbol.CONSTANT_FLOAT_TAG
.value
- an int or float.private void addConstantIntegerOrFloat(int index, int tag, int value)
index
- the constant pool index of the new Symbol.tag
- one of Symbol.CONSTANT_INTEGER_TAG
or Symbol.CONSTANT_FLOAT_TAG
.value
- an int or float.Symbol addConstantLong(long value)
value
- a long.Symbol addConstantDouble(double value)
value
- a double.private Symbol addConstantLongOrDouble(int tag, long value)
tag
- one of Symbol.CONSTANT_LONG_TAG
or Symbol.CONSTANT_DOUBLE_TAG
.value
- a long or double.private void addConstantLongOrDouble(int index, int tag, long value)
index
- the constant pool index of the new Symbol.tag
- one of Symbol.CONSTANT_LONG_TAG
or Symbol.CONSTANT_DOUBLE_TAG
.value
- a long or double.int addConstantNameAndType(java.lang.String name, java.lang.String descriptor)
name
- a field or method name.descriptor
- a field or method descriptor.private void addConstantNameAndType(int index, java.lang.String name, java.lang.String descriptor)
index
- the constant pool index of the new Symbol.name
- a field or method name.descriptor
- a field or method descriptor.int addConstantUtf8(java.lang.String value)
value
- a string.private void addConstantUtf8(int index, java.lang.String value)
index
- the constant pool index of the new Symbol.value
- a string.Symbol addConstantMethodHandle(int referenceKind, java.lang.String owner, java.lang.String name, java.lang.String descriptor, boolean isInterface)
referenceKind
- one of Opcodes.H_GETFIELD
, Opcodes.H_GETSTATIC
, Opcodes.H_PUTFIELD
, Opcodes.H_PUTSTATIC
, Opcodes.H_INVOKEVIRTUAL
, Opcodes.H_INVOKESTATIC
, Opcodes.H_INVOKESPECIAL
, Opcodes.H_NEWINVOKESPECIAL
or Opcodes.H_INVOKEINTERFACE
.owner
- the internal name of a class of interface.name
- a field or method name.descriptor
- a field or method descriptor.isInterface
- whether owner is an interface or not.private void addConstantMethodHandle(int index, int referenceKind, java.lang.String owner, java.lang.String name, java.lang.String descriptor)
index
- the constant pool index of the new Symbol.referenceKind
- one of Opcodes.H_GETFIELD
, Opcodes.H_GETSTATIC
, Opcodes.H_PUTFIELD
, Opcodes.H_PUTSTATIC
, Opcodes.H_INVOKEVIRTUAL
, Opcodes.H_INVOKESTATIC
, Opcodes.H_INVOKESPECIAL
, Opcodes.H_NEWINVOKESPECIAL
or Opcodes.H_INVOKEINTERFACE
.owner
- the internal name of a class of interface.name
- a field or method name.descriptor
- a field or method descriptor.Symbol addConstantMethodType(java.lang.String methodDescriptor)
methodDescriptor
- a method descriptor.Symbol addConstantDynamic(java.lang.String name, java.lang.String descriptor, Handle bootstrapMethodHandle, java.lang.Object... bootstrapMethodArguments)
name
- a method name.descriptor
- a field descriptor.bootstrapMethodHandle
- a bootstrap method handle.bootstrapMethodArguments
- the bootstrap method arguments.Symbol addConstantInvokeDynamic(java.lang.String name, java.lang.String descriptor, Handle bootstrapMethodHandle, java.lang.Object... bootstrapMethodArguments)
name
- a method name.descriptor
- a method descriptor.bootstrapMethodHandle
- a bootstrap method handle.bootstrapMethodArguments
- the bootstrap method arguments.private Symbol addConstantDynamicOrInvokeDynamicReference(int tag, java.lang.String name, java.lang.String descriptor, int bootstrapMethodIndex)
tag
- one of Symbol.CONSTANT_DYNAMIC_TAG
or Symbol.CONSTANT_INVOKE_DYNAMIC_TAG
.name
- a method name.descriptor
- a field descriptor for CONSTANT_DYNAMIC_TAG) or a method descriptor for
CONSTANT_INVOKE_DYNAMIC_TAG.bootstrapMethodIndex
- the index of a bootstrap method in the BootstrapMethods attribute.private void addConstantDynamicOrInvokeDynamicReference(int tag, int index, java.lang.String name, java.lang.String descriptor, int bootstrapMethodIndex)
tag
- one of Symbol.CONSTANT_DYNAMIC_TAG
or Symbol.CONSTANT_INVOKE_DYNAMIC_TAG
.index
- the constant pool index of the new Symbol.name
- a method name.descriptor
- a field descriptor for CONSTANT_DYNAMIC_TAG or a method descriptor for
CONSTANT_INVOKE_DYNAMIC_TAG.bootstrapMethodIndex
- the index of a bootstrap method in the BootstrapMethods attribute.Symbol addConstantModule(java.lang.String moduleName)
moduleName
- a fully qualified name (using dots) of a module.Symbol addConstantPackage(java.lang.String packageName)
packageName
- the internal name of a package.private Symbol addConstantUtf8Reference(int tag, java.lang.String value)
tag
- one of Symbol.CONSTANT_CLASS_TAG
, Symbol.CONSTANT_STRING_TAG
, Symbol.CONSTANT_METHOD_TYPE_TAG
, Symbol.CONSTANT_MODULE_TAG
or Symbol.CONSTANT_PACKAGE_TAG
.value
- an internal class name, an arbitrary string, a method descriptor, a module or a
package name, depending on tag.private void addConstantUtf8Reference(int index, int tag, java.lang.String value)
index
- the constant pool index of the new Symbol.tag
- one of Symbol.CONSTANT_CLASS_TAG
, Symbol.CONSTANT_STRING_TAG
, Symbol.CONSTANT_METHOD_TYPE_TAG
, Symbol.CONSTANT_MODULE_TAG
or Symbol.CONSTANT_PACKAGE_TAG
.value
- an internal class name, an arbitrary string, a method descriptor, a module or a
package name, depending on tag.Symbol addBootstrapMethod(Handle bootstrapMethodHandle, java.lang.Object... bootstrapMethodArguments)
bootstrapMethodHandle
- a bootstrap method handle.bootstrapMethodArguments
- the bootstrap method arguments.private Symbol addBootstrapMethod(int offset, int length, int hashCode)
bootstrapMethods
to remove the last, duplicate bootstrap method).offset
- the offset of the last bootstrap method in bootstrapMethods
, in bytes.length
- the length of this bootstrap method in bootstrapMethods
, in bytes.hashCode
- the hash code of this bootstrap method.Symbol getType(int typeIndex)
typeIndex
- a type table index.int addType(java.lang.String value)
value
- an internal class name.int addUninitializedType(java.lang.String value, int bytecodeOffset)
Frame.ITEM_UNINITIALIZED
type in the type table of this symbol table. Does
nothing if the type table already contains a similar type.value
- an internal class name.bytecodeOffset
- the bytecode offset of the NEW instruction that created this Frame.ITEM_UNINITIALIZED
type value.int addMergedType(int typeTableIndex1, int typeTableIndex2)
typeTableIndex1
- a Symbol.TYPE_TAG
type, specified by its index in the type
table.typeTableIndex2
- another Symbol.TYPE_TAG
type, specified by its index in the type
table.Symbol.TYPE_TAG
type Symbol,
corresponding to the common super class of the given types.private int addTypeInternal(SymbolTable.Entry entry)
typeTable
.entry
- a Symbol.TYPE_TAG
or Symbol.UNINITIALIZED_TYPE_TAG
type symbol.
The index of this Symbol must be equal to the current value of typeCount
.typeTable
where the given type was added, which is also equal to
entry's index by hypothesis.private static int hash(int tag, int value)
private static int hash(int tag, long value)
private static int hash(int tag, java.lang.String value)
private static int hash(int tag, java.lang.String value1, int value2)
private static int hash(int tag, java.lang.String value1, java.lang.String value2)
private static int hash(int tag, java.lang.String value1, java.lang.String value2, int value3)
private static int hash(int tag, java.lang.String value1, java.lang.String value2, java.lang.String value3)
private static int hash(int tag, java.lang.String value1, java.lang.String value2, java.lang.String value3, int value4)