|
|||||||||
| Home >> All >> com >> techtrader >> modules >> tools >> bytecode >> [ lowlevel overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.techtrader.modules.tools.bytecode.lowlevel
Class ConstantPool

java.lang.Objectcom.techtrader.modules.tools.bytecode.lowlevel.ConstantPool
- All Implemented Interfaces:
- LowLevelConstants, com.techtrader.modules.tools.bytecode.visitor.VisitAcceptor
- public class ConstantPool
- extends java.lang.Object
- implements LowLevelConstants, com.techtrader.modules.tools.bytecode.visitor.VisitAcceptor
- extends java.lang.Object
Represents a class constant pool, containing entries for all strings, constants, classes, etc referenced in the class structure and opcodes. In keeping with the low-level bytecode representation, all pool indexes are 1-based.
NOTE: Entries are not meant to be manipulated manually. If you change
entries by hand, make sure to call the rehash(com.techtrader.modules.tools.bytecode.lowlevel.Entry, int) 55 method of the
ConstantPool so that the entry is hashed correctly for quick lookups and
to avoid duplicates.
NOTE: LongEntries and DoubleEntries are always followed by a PlaceHolderEntry in the pool, as they take up 2 pool indeces. When manually adding a new entry of these types, it is not necessary to insert the PlaceHolder as well; the system will do this automatically.
| Nested Class Summary | |
private static class |
ConstantPool.HashedEntry
|
| Field Summary | |
private static java.util.Map |
_consts
|
private java.util.List |
_entries
|
private java.util.Map |
_lookup
|
private com.techtrader.modules.tools.bytecode.BCClass |
_owner
|
| Fields inherited from interface com.techtrader.modules.tools.bytecode.lowlevel.LowLevelConstants |
ENTRY_CLASS, ENTRY_DOUBLE, ENTRY_FIELD, ENTRY_FLOAT, ENTRY_INT, ENTRY_INTMETHOD, ENTRY_LONG, ENTRY_METHOD, ENTRY_NAME_AND_TYPE, ENTRY_PLACEHOLDER, ENTRY_STRING, ENTRY_UTF8 |
| Constructor Summary | |
ConstantPool(com.techtrader.modules.tools.bytecode.BCClass owner)
|
|
| Method Summary | |
void |
acceptVisit(com.techtrader.modules.tools.bytecode.visitor.BCVisitor visit)
Accept a visit from a BCVisitor, 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 object. |
int |
addEntry(Entry entry)
Add an entry to the pool. |
void |
addEntry(int index,
Entry entry)
Set the entry at the given 1-based index. |
static Entry |
createEntry(int type)
Create an Entry based on its one-byte code: one of the constants in the LowLevelConstants class. |
private int |
find(java.lang.String key)
|
int |
getClassIndex(java.lang.String name)
Get the constant pool index of the entry for the given class name. |
java.lang.String |
getClassName(int index)
Get the value of the entry at the given index. |
int |
getComplexIndex(java.lang.String name,
java.lang.String desc,
java.lang.String owner,
java.lang.Class type)
Get the constant pool index of the entry for the given complex entry. |
java.lang.String |
getComplexName(int index)
Get the value of the entry at the given index. |
java.lang.String |
getComplexOwnerTypeName(int index)
Get the value of the entry at the given index. |
java.lang.String |
getComplexTypeName(int index)
Get the value of the entry at the given index. |
java.lang.Object |
getConstant(int index)
Get the value of the entry at the given index. |
int |
getConstantIndex(java.lang.Object value)
Get the constant pool index of the entry for the given constant value. |
Entry[] |
getEntries()
Get the entries in the pool. |
Entry |
getEntry(int index)
Retrieve the entry at the specified 1-based index. |
int |
getNameAndTypeIndex(java.lang.String name,
java.lang.String desc)
Get the constant pool index of the entry for the given name+type. |
java.lang.String |
getUTF(int index)
Get the value of the entry at the given index. |
int |
getUTFIndex(java.lang.String name)
Get the constant pool index of the entry for the given UTF value. |
private void |
hash(Entry entry,
int index)
|
void |
readData(java.io.DataInput in)
|
void |
rehash(Entry entry,
int poolIndex)
Rehash the given entry after modification; this allows for quick lookups and guarantees that entries won't be repeated in the pool. |
boolean |
removeEntry(Entry entry)
Remove the given entry from the pool. |
Entry |
removeEntry(int index)
Remove the entry at the given index. |
private void |
removeHash(Entry entry)
|
int |
setClassName(int index,
java.lang.String name)
Set the entry at the given index; if the given index is <= 0, a search will be performed for an entry with the given value, and, if it fails, a new entry will be added to the pool. |
int |
setComplex(int index,
java.lang.String name,
java.lang.String desc,
java.lang.String owner,
java.lang.Class entryType)
Set the entry at the given index; if the given index is <= 0, a search will be performed for an entry with the given value, and, if it fails, a new entry will be added to the pool. |
int |
setConstant(int index,
java.lang.Object value)
Set the entry at the given index; if the given index is <= 0, a search will be performed for an entry with the given value, and, if it fails, a new entry will be added to the pool. |
Entry |
setEntry(int index,
Entry entry)
Set the entry at the given 1-based index. |
int |
setNameAndType(int index,
java.lang.String name,
java.lang.String desc)
Set the entry at the given index; if the given index is <= 0, a search will be performed for an entry with the given value, and, if it fails, a new entry will be added to the pool. |
int |
setUTF(int index,
java.lang.String name)
Set the entry at the given index; if the given index is <= 0, a search will be performed for an entry with the given value, and, if it fails, a new entry will be added to the pool. |
int |
size()
Return the number of entries in the pool, including placeholder entries. |
void |
writeData(java.io.DataOutput out)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
_consts
private static final java.util.Map _consts
_entries
private java.util.List _entries
_lookup
private java.util.Map _lookup
_owner
private com.techtrader.modules.tools.bytecode.BCClass _owner
| Constructor Detail |
ConstantPool
public ConstantPool(com.techtrader.modules.tools.bytecode.BCClass owner)
| Method Detail |
createEntry
public static Entry createEntry(int type)
- Create an Entry based on its one-byte code: one of the constants in
the LowLevelConstants class.
getEntries
public Entry[] getEntries()
- Get the entries in the pool.
getEntry
public Entry getEntry(int index)
- Retrieve the entry at the specified 1-based index.
setEntry
public Entry setEntry(int index, Entry entry)
- Set the entry at the given 1-based index.
addEntry
public void addEntry(int index,
Entry entry)
- Set the entry at the given 1-based index.
addEntry
public int addEntry(Entry entry)
- Add an entry to the pool.
removeEntry
public Entry removeEntry(int index)
- Remove the entry at the given index.
removeEntry
public boolean removeEntry(Entry entry)
- Remove the given entry from the pool.
size
public int size()
- Return the number of entries in the pool, including placeholder
entries.
getUTFIndex
public int getUTFIndex(java.lang.String name)
- Get the constant pool index of the entry for the given UTF value.
getUTF
public java.lang.String getUTF(int index)
- Get the value of the entry at the given index.
setUTF
public int setUTF(int index,
java.lang.String name)
- Set the entry at the given index; if the given index is <= 0,
a search will be performed for an entry with the given value, and, if
it fails, a new entry will be added to the pool.
getClassIndex
public int getClassIndex(java.lang.String name)
- Get the constant pool index of the entry for the given class name.
getClassName
public java.lang.String getClassName(int index)
- Get the value of the entry at the given index.
setClassName
public int setClassName(int index,
java.lang.String name)
- Set the entry at the given index; if the given index is <= 0,
a search will be performed for an entry with the given value, and, if
it fails, a new entry will be added to the pool.
getNameAndTypeIndex
public int getNameAndTypeIndex(java.lang.String name, java.lang.String desc)
- Get the constant pool index of the entry for the given name+type.
setNameAndType
public int setNameAndType(int index,
java.lang.String name,
java.lang.String desc)
- Set the entry at the given index; if the given index is <= 0,
a search will be performed for an entry with the given value, and, if
it fails, a new entry will be added to the pool.
getComplexIndex
public int getComplexIndex(java.lang.String name, java.lang.String desc, java.lang.String owner, java.lang.Class type)
- Get the constant pool index of the entry for the given complex entry.
setComplex
public int setComplex(int index,
java.lang.String name,
java.lang.String desc,
java.lang.String owner,
java.lang.Class entryType)
- Set the entry at the given index; if the given index is <= 0,
a search will be performed for an entry with the given value, and, if
it fails, a new entry will be added to the pool.
getComplexName
public java.lang.String getComplexName(int index)
- Get the value of the entry at the given index.
getComplexTypeName
public java.lang.String getComplexTypeName(int index)
- Get the value of the entry at the given index.
getComplexOwnerTypeName
public java.lang.String getComplexOwnerTypeName(int index)
- Get the value of the entry at the given index.
getConstantIndex
public int getConstantIndex(java.lang.Object value)
- Get the constant pool index of the entry for the given constant value.
getConstant
public java.lang.Object getConstant(int index)
- Get the value of the entry at the given index.
setConstant
public int setConstant(int index,
java.lang.Object value)
- Set the entry at the given index; if the given index is <= 0,
a search will be performed for an entry with the given value, and, if
it fails, a new entry will be added to the pool.
rehash
public void rehash(Entry entry, int poolIndex)
- Rehash the given entry after modification; this allows for quick
lookups and guarantees that entries won't be repeated in the pool.
readData
public void readData(java.io.DataInput in) throws java.io.IOException
writeData
public void writeData(java.io.DataOutput out) throws java.io.IOException
find
private int find(java.lang.String key)
hash
private void hash(Entry entry, int index)
removeHash
private void removeHash(Entry entry)
acceptVisit
public void acceptVisit(com.techtrader.modules.tools.bytecode.visitor.BCVisitor visit)
- Description copied from interface:
com.techtrader.modules.tools.bytecode.visitor.VisitAcceptor - Accept a visit from a BCVisitor, 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 object.
- Specified by:
acceptVisitin interfacecom.techtrader.modules.tools.bytecode.visitor.VisitAcceptor
|
|||||||||
| Home >> All >> com >> techtrader >> modules >> tools >> bytecode >> [ lowlevel overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
com.techtrader.modules.tools.bytecode.lowlevel.ConstantPool