Package serp.bytecode.lowlevel
Class ConstantPool
java.lang.Object
serp.bytecode.lowlevel.ConstantPool
- All Implemented Interfaces:
VisitAcceptor
A bytecode constant pool, containing entries for all strings,
constants, classes, etc referenced in the class structure and method
opcodes. In keeping with the low-level bytecode representation, all pool
indexes are 1-based and
LongEntry
s and DoubleEntry
s each
occupy two indexes in the pool.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Key for class entries.private static class
Base class key for entries with two ptr to other entries.private static class
Key for field entries.private static class
Key for interface method entries.private static class
Key for method entries.private static class
Key for method entries.private static class
Key for name and type entries.private static class
Base class key for entries with one ptr to another entry.private static class
Key for string entries. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
acceptVisit
(BCVisitor visit) Accept a visit from aBCVisitor
, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.private int
Add an entry to the pool using the given key.int
Add an entry to the pool.void
clear()
Clear all entries from the pool.private int
Returns the constant pool index of the entry with the given key.int
findClassEntry
(String name, boolean add) Return the constant pool index of theClassEntry
for the given class name, or 0 if it does not exist.private int
findComplexEntry
(String owner, String name, String desc, int type, boolean add) Return the constant pool index of theComplexEntry
for the given name, descriptor, and owner class name.int
findDoubleEntry
(double value, boolean add) Return the constant pool index of theDoubleEntry
for the given value, or 0 if it does not exist.int
findFieldEntry
(String owner, String name, String desc, boolean add) Return the constant pool index of theFieldEntry
for the given name, descriptor, and owner class name.int
findFloatEntry
(float value, boolean add) Return the constant pool index of theFloatEntry
for the given value, or 0 if it does not exist.int
findIntEntry
(int value, boolean add) Return the constant pool index of theIntEntry
for the given value, or 0 if it does not exist.int
findInterfaceMethodEntry
(String owner, String name, String desc, boolean add) Return the constant pool index of theInterfaceMethodEntry
for the given name, descriptor, and owner class name.int
findInvokeDynamicEntry
(int bootstrapMethodIndex, String name, String desc, boolean add) int
findLongEntry
(long value, boolean add) Return the constant pool index of theLongEntry
for the given value, or 0 if it does not exist.int
findMethodEntry
(String owner, String name, String desc, boolean add) Return the constant pool index of theMethodEntry
for the given name, descriptor, and owner class name.int
findNameAndTypeEntry
(String name, String desc, boolean add) Return the constant pool index of theNameAndTypeEntry
for the given name and descriptor, or 0 if it does not exist.int
findStringEntry
(String value, boolean add) Return the constant pool index of theStringEntry
for the given string value, or 0 if it does not exist.int
findUTF8Entry
(String value, boolean add) Return the index of theUTF8Entry
with the given value, or 0 if it does not exist.Entry[]
Return all the entries in the pool.getEntry
(int index) Retrieve the entry at the specified 1-based index.(package private) static Object
Return the hash key used for the specified entry.int
Return the index of the given entry, or 0 if it is not in the pool.(package private) void
modifyEntry
(Object origKey, Entry entry) Called by constant pool entries when they are mutated.void
Fill the constant pool from the given bytecode stream.boolean
removeEntry
(Entry entry) Remove the given entry from the pool.int
size()
Return the number of places occupied in the pool, including the fact that long and double entries occupy two places.void
write
(DataOutput out) Write the constant pool to the given bytecode stream.
-
Field Details
-
_entries
-
_lookup
-
-
Constructor Details
-
ConstantPool
public ConstantPool()Default constructor.
-
-
Method Details
-
getEntries
Return all the entries in the pool. -
getEntry
Retrieve the entry at the specified 1-based index.- Throws:
IndexOutOfBoundsException
- if index is invalid, including the case that it points to the second slot of a long or double entry
-
indexOf
Return the index of the given entry, or 0 if it is not in the pool. -
addEntry
Add an entry to the pool.- Returns:
- the index at which the entry was added
-
addEntry
Add an entry to the pool using the given key. -
removeEntry
Remove the given entry from the pool.- Returns:
- false if the entry is not in the pool, true otherwise
-
clear
public void clear()Clear all entries from the pool. -
size
public int size()Return the number of places occupied in the pool, including the fact that long and double entries occupy two places. -
findUTF8Entry
Return the index of theUTF8Entry
with the given value, or 0 if it does not exist.- Parameters:
add
- if true, the entry will be added if it does not already exist, and the new entry's index returned
-
findDoubleEntry
public int findDoubleEntry(double value, boolean add) Return the constant pool index of theDoubleEntry
for the given value, or 0 if it does not exist.- Parameters:
value
- the value to findadd
- if true, the entry will be added if it does not already exist, and the new entry's index returned
-
findFloatEntry
public int findFloatEntry(float value, boolean add) Return the constant pool index of theFloatEntry
for the given value, or 0 if it does not exist.- Parameters:
value
- the value to findadd
- if true, the entry will be added if it does not already exist, and the new entry's index returned
-
findIntEntry
public int findIntEntry(int value, boolean add) Return the constant pool index of theIntEntry
for the given value, or 0 if it does not exist.- Parameters:
value
- the value to findadd
- if true, the entry will be added if it does not already exist, and the new entry's index returned
-
findLongEntry
public int findLongEntry(long value, boolean add) Return the constant pool index of theLongEntry
for the given value, or 0 if it does not exist.- Parameters:
value
- the value to findadd
- if true, the entry will be added if it does not already exist, and the new entry's index returned
-
findStringEntry
Return the constant pool index of theStringEntry
for the given string value, or 0 if it does not exist.- Parameters:
value
- the value to findadd
- if true, the entry will be added if it does not already exist, and the new entry's index returned
-
findClassEntry
Return the constant pool index of theClassEntry
for the given class name, or 0 if it does not exist.- Parameters:
name
- the class name in internal formadd
- if true, the entry will be added if it does not already exist, and the new entry's index returned
-
findNameAndTypeEntry
Return the constant pool index of theNameAndTypeEntry
for the given name and descriptor, or 0 if it does not exist.- Parameters:
name
- the name of the entitydesc
- the descriptor of the entity in internal formadd
- if true, the entry will be added if it does not already exist, and the new entry's index returned
-
findFieldEntry
Return the constant pool index of theFieldEntry
for the given name, descriptor, and owner class name.- Parameters:
owner
- the name of the field's owning class in internal formname
- the name of the fielddesc
- the descriptor of the field in internal formadd
- if true, the entry will be added if it does not already exist, and the new entry's index returned
-
findMethodEntry
Return the constant pool index of theMethodEntry
for the given name, descriptor, and owner class name.- Parameters:
owner
- the name of the method's owning class in internal formname
- the name of the methoddesc
- the descriptor of the method in internal formadd
- if true, the entry will be added if it does not already exist, and the new entry's index returned
-
findInterfaceMethodEntry
Return the constant pool index of theInterfaceMethodEntry
for the given name, descriptor, and owner class name.- Parameters:
owner
- the name of the method's owning class in internal formname
- the name of the methoddesc
- the descriptor of the method in internal formadd
- if true, the entry will be added if it does not already exist, and the new entry's index returned
-
findInvokeDynamicEntry
-
findComplexEntry
Return the constant pool index of theComplexEntry
for the given name, descriptor, and owner class name.- Parameters:
owner
- the name of the owning class in internal formname
- the name of the entitydesc
- the descriptor of the entity in internal formtype
- the type of entry: field, method, interface methodadd
- if true, the entry will be added if it does not already exist, and the new entry's index returned
-
acceptVisit
Description copied from interface:VisitAcceptor
Accept a visit from aBCVisitor
, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.- Specified by:
acceptVisit
in interfaceVisitAcceptor
-
read
Fill the constant pool from the given bytecode stream.- Throws:
IOException
-
write
Write the constant pool to the given bytecode stream.- Throws:
IOException
-
modifyEntry
Called by constant pool entries when they are mutated. -
find
Returns the constant pool index of the entry with the given key. -
getKey
Return the hash key used for the specified entry.
-