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
LongEntrys and DoubleEntrys each
occupy two indexes in the pool.- Author:
- Abe White
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptVisit(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.intAdd an entry to the pool.voidclear()Clear all entries from the pool.intfindClassEntry(String name, boolean add) Return the constant pool index of theClassEntryfor the given class name, or 0 if it does not exist.intfindDoubleEntry(double value, boolean add) Return the constant pool index of theDoubleEntryfor the given value, or 0 if it does not exist.intfindFieldEntry(String owner, String name, String desc, boolean add) Return the constant pool index of theFieldEntryfor the given name, descriptor, and owner class name.intfindFloatEntry(float value, boolean add) Return the constant pool index of theFloatEntryfor the given value, or 0 if it does not exist.intfindIntEntry(int value, boolean add) Return the constant pool index of theIntEntryfor the given value, or 0 if it does not exist.intfindInterfaceMethodEntry(String owner, String name, String desc, boolean add) Return the constant pool index of theInterfaceMethodEntryfor the given name, descriptor, and owner class name.intfindInvokeDynamicEntry(int bootstrapMethodIndex, String name, String desc, boolean add) intfindLongEntry(long value, boolean add) Return the constant pool index of theLongEntryfor the given value, or 0 if it does not exist.intfindMethodEntry(String owner, String name, String desc, boolean add) Return the constant pool index of theMethodEntryfor the given name, descriptor, and owner class name.intfindNameAndTypeEntry(String name, String desc, boolean add) Return the constant pool index of theNameAndTypeEntryfor the given name and descriptor, or 0 if it does not exist.intfindStringEntry(String value, boolean add) Return the constant pool index of theStringEntryfor the given string value, or 0 if it does not exist.intfindUTF8Entry(String value, boolean add) Return the index of theUTF8Entrywith 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.intReturn the index of the given entry, or 0 if it is not in the pool.voidFill the constant pool from the given bytecode stream.booleanremoveEntry(Entry entry) Remove the given entry from the pool.intsize()Return the number of places occupied in the pool, including the fact that long and double entries occupy two places.voidwrite(DataOutput out) Write the constant pool to the given bytecode stream.
-
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
-
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 theUTF8Entrywith 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 theDoubleEntryfor 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 theFloatEntryfor 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 theIntEntryfor 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 theLongEntryfor 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 theStringEntryfor 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 theClassEntryfor 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 theNameAndTypeEntryfor 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 theFieldEntryfor 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 theMethodEntryfor 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 theInterfaceMethodEntryfor 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
-
acceptVisit
Description copied from interface:VisitAcceptorAccept 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:
acceptVisitin 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
-