|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jikesrvm.classloader.BytecodeStream
public class BytecodeStream
Provides minimal abstraction layer to a stream of bytecodes from the code attribute of a method.
Field Summary | |
---|---|
private int |
bcIndex
|
private int |
bcLength
|
private byte[] |
bcodes
|
private NormalMethod |
method
|
private int |
opcode
|
private boolean |
wide
|
Constructor Summary | |
---|---|
BytecodeStream(NormalMethod m,
byte[] bc)
|
Method Summary | |
---|---|
void |
alignInvokeInterface()
Skips the extra stuff after an invokeinterface instruction. |
void |
alignSwitch()
Skips the padding of a switch instruction. |
int |
computeLookupSwitchOffset(int value,
int num)
Returns the offset for a given value of the lookupswitch (as a signed int) or 0 if the value is not in the table.. |
int |
computeTableSwitchOffset(int value,
int low,
int high)
Returns the offset for a given value of the tableswitch (as a signed int) or 0 if the value is out of range.. |
int |
getArrayDimension()
Returns the dimension of the array (as an unsigned byte). |
int |
getArrayElementType()
Returns the element type (primitive) of the array (as an unsigned byte). |
int |
getBranchOffset()
Returns the offset of the branch (as a signed short). |
int |
getByteValue()
Returns a signed byte value Used for bipush |
int |
getConstantIndex()
Returns the constant pool index of a constant (as an unsigned byte). |
byte |
getConstantType(int index)
Returns the type of a constant at a given constant pool index (as a byte). |
RVMClass |
getDeclaringClass()
Returns the declaring class that this bytecode stream is from |
int |
getDefaultSwitchOffset()
Returns the default offset of the switch (as a signed int). |
double |
getDoubleConstant(int index)
Returns the constant at a given constant pool index (as a double). |
FieldReference |
getFieldReference()
Returns a reference to a field. |
FieldReference |
getFieldReference(int[] constantPool)
Returns a reference to a field, for use prior to the class being loaded. |
float |
getFloatConstant(int index)
Returns the constant at a given constant pool index (as a float). |
int |
getHighSwitchValue()
Returns the highest value of the tableswitch (as a signed int). |
int |
getIncrement()
Returns an increment value (as a signed byte). |
int |
getIntConstant(int index)
Returns the constant at a given constant pool index (as an int). |
int |
getLocalNumber()
Returns the number of the local (as an unsigned byte) Used for iload, lload, fload, dload, aload, istore, lstore, fstore, dstore, astore, iinc, ret |
long |
getLongConstant(int index)
Returns the constant at a given constant pool index (as a long). |
int |
getLookupSwitchOffset(int num)
Returns the numbered offset of the lookupswitch (as a signed int). |
int |
getLookupSwitchValue(int num)
Returns the numbered value of the lookupswitch (as a signed int). |
int |
getLowSwitchValue()
Returns the lowest value of the tableswitch (as a signed int). |
NormalMethod |
getMethod()
Returns the method that this bytecode stream is from |
MethodReference |
getMethodReference()
Returns a reference to a field. |
MethodReference |
getMethodReference(int[] constantPool)
Returns a reference to a field, for use prior to the class being loaded. |
TypeReference |
getObjectArrayType()
Returns the type of the object array (as a RVMType). |
RVMType |
getObjectArrayType(RVMType klass)
Returns the type of the array of given object type (as a RVMType). |
int |
getOpcode()
Returns the opcode of the current instruction in the sequence. |
RVMType |
getPrimitiveArrayType()
Returns the type of the primitive array (as a RVMType). |
RVMArray |
getPrimitiveArrayType(int etype)
Returns the type of the array of given primitive type (as a RVMType). |
int |
getShortValue()
Returns a signed short value Used for sipush |
private int |
getSignedInt(int index)
|
String |
getStringConstant(int index)
Returns the constant at a given constant pool index (as a String). |
int |
getSwitchLength()
Returns the number of match-offset pairs in the lookupswitch (as a signed int). |
int |
getTableSwitchOffset(int num)
Returns the numbered offset of the tableswitch (as a signed int). |
TypeReference |
getTypeReference()
Returns the type reference (as a RVMType). |
private int |
getUnsignedByte(int index)
|
int |
getWideBranchOffset()
Returns the wide offset of the branch (as a signed int). |
int |
getWideConstantIndex()
Returns the wide constant pool index of a constant (as an unsigned short). |
int |
getWideIncrement()
Returns an increment value (as a signed short). |
int |
getWideLocalNumber()
Returns the wide number of the local (as an unsigned short) Used for iload, lload, fload, dload, aload, istore, lstore, fstore, dstore, astore, iinc prefixed by wide |
int |
getWideOpcode()
Returns the opcode of the wide instruction. |
boolean |
hasMoreBytecodes()
Does the stream have more bytecodes in it? |
int |
index()
Returns the current bytecode index |
boolean |
isWide()
Are we currently processing a wide instruction? |
int |
length()
Returns the length of the bytecode stream Returns 0 if the method doesn't have any bytecodes (i.e. is abstract or native) |
int |
nextInstruction()
Sets up the next instruction in the sequence |
int |
nextPseudoInstruction()
|
int |
peekNextOpcode()
Returns the opcode of the next instruction in the sequence without advancing to it |
int |
readIntConst()
|
private long |
readLong()
|
long |
readLongConst()
|
private byte |
readSignedByte()
|
private int |
readSignedInt()
|
private int |
readSignedShort()
|
private int |
readUnsignedByte()
|
private int |
readUnsignedShort()
|
void |
reset()
Resets the stream to the beginning |
void |
reset(int index)
Resets the stream to a given position Use with caution |
void |
skipInstruction()
Skips the current instruction |
void |
skipInstruction(int opcode,
boolean wide)
Skips the current instruction (without using the opcode field) A slightly optimized version of skipInstruction() |
void |
skipLookupSwitchPairs(int num)
Skips the match-offset pairs of a lookupswitch instruction. |
private void |
skipSpecialInstruction(int opcode)
|
void |
skipTableSwitchOffsets(int num)
Skips the offsets of a tableswitch instruction. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final NormalMethod method
private final int bcLength
private final byte[] bcodes
private int bcIndex
private int opcode
private boolean wide
Constructor Detail |
---|
public BytecodeStream(NormalMethod m, byte[] bc)
m
- the method containing the bytecodesbc
- the array of bytecodesMethod Detail |
---|
public final NormalMethod getMethod()
public final RVMClass getDeclaringClass()
public final int length()
public final int index()
public final void reset()
reset(int)
public final void reset(int index)
index
- the position to reset the stream toreset()
public final boolean hasMoreBytecodes()
public final int peekNextOpcode()
nextInstruction()
public final int nextInstruction()
peekNextOpcode()
public final int getOpcode()
Note: if skipInstruction has been called, but nextInstruction has not, this method will return the opcode of the skipped instruction!
nextInstruction()
,
isWide()
public final boolean isWide()
true
if current instruction is widenextInstruction()
,
getOpcode()
public final void skipInstruction()
skipInstruction(int,boolean)
public final void skipInstruction(int opcode, boolean wide)
opcode
- current opcodewide
- whether current instruction follows wideskipInstruction()
public final int getByteValue()
public final int getShortValue()
public final int getLocalNumber()
getWideLocalNumber()
public final int getWideLocalNumber()
getLocalNumber()
public final int getIncrement()
Used for iinc
getWideIncrement()
public final int getWideIncrement()
Used for iinc prefixed by wide
getIncrement()
public final int getBranchOffset()
Used for if<cond>
, ificmp<cond>
, ifacmp<cond>
,
goto
, jsr
getWideBranchOffset()
public final int getWideBranchOffset()
Used for goto_w, jsr_w
getBranchOffset()
public final void alignSwitch()
Used for tableswitch, lookupswitch
public final int getDefaultSwitchOffset()
Used for tableswitch, lookupswitch
public final int getLowSwitchValue()
Used for tableswitch
getHighSwitchValue()
public final int getHighSwitchValue()
Used for tableswitch
getLowSwitchValue()
public final void skipTableSwitchOffsets(int num)
Used for tableswitch
num
- the number of offsets to skipgetTableSwitchOffset(int)
public final int getTableSwitchOffset(int num)
Used for tableswitch.
The "cursor" has to be positioned at the start of the offset table.
NOTE: Will NOT advance cursor
num
- the number of the offset to retrieve
public final int computeTableSwitchOffset(int value, int low, int high)
Used for tableswitch.
The "cursor" has to be positioned at the start of the offset table.
NOTE: Will NOT advance cursor
value
- the value to retrieve offset forlow
- the lowest value of the tableswitchhigh
- the highest value of the tableswitch
public final int getSwitchLength()
Used for lookupswitch
public final void skipLookupSwitchPairs(int num)
Used for lookupswitch
num
- the number of match-offset pairs to skipgetLookupSwitchValue(int)
,
getLookupSwitchOffset(int)
public final int getLookupSwitchOffset(int num)
Used for lookupswitch.
The "cursor" has to be positioned at the start of the pair table.
NOTE: Will NOT advance cursor
num
- the number of the offset to retrieve
getLookupSwitchValue(int)
public final int getLookupSwitchValue(int num)
Used for lookupswitch.
The "cursor" has to be positioned at the start of the pair table.
NOTE: Will NOT advance cursor
num
- the number of the value to retrieve
getLookupSwitchOffset(int)
public final int computeLookupSwitchOffset(int value, int num)
Used for lookupswitch.
The "cursor" has to be positioned at the start of the offset table.
NOTE: Will NOT advance cursor.
WARNING: Uses LINEAR search.
XXX Whoever has time on their hands can re-implement this as a binary search.
value
- the value to retrieve offset fornum
- the number of match-offset pairs in the lookupswitch
public final FieldReference getFieldReference()
Used for getstatic, putstatic, getfield, putfield
public final FieldReference getFieldReference(int[] constantPool)
Used for getstatic, putstatic, getfield, putfield
public final MethodReference getMethodReference()
Used for invokevirtual, invokespecial, invokestatic, invokeinterface
public final MethodReference getMethodReference(int[] constantPool)
Used for invokevirtual, invokespecial, invokestatic, invokeinterface
public final void alignInvokeInterface()
Used for invokeinterface
public final TypeReference getTypeReference()
Used for new, anewarray, checkcast, instanceof, multianewarray
public final int getArrayElementType()
Used for newarray
getPrimitiveArrayType()
,
getPrimitiveArrayType(int)
public final RVMArray getPrimitiveArrayType(int etype)
Used for newarray
etype
- element type
getArrayElementType()
,
getPrimitiveArrayType()
public final RVMType getPrimitiveArrayType()
Used for newarray
getArrayElementType()
,
getPrimitiveArrayType(int)
public final RVMType getObjectArrayType(RVMType klass)
Used for anewarray
klass
- element type
getTypeReference()
,
getObjectArrayType()
public final TypeReference getObjectArrayType()
Used for anewarray
getObjectArrayType(RVMType)
public final int getArrayDimension()
Used for multianewarray
public final int getWideOpcode()
Used for wide.
Can be one of iload, lload, fload, dload, aload, istore, lstore, fstore, dstore, astore, iinc
public final int getConstantIndex()
Used for ldc
getWideConstantIndex()
,
getConstantType(int)
,
getIntConstant(int)
,
getLongConstant(int)
,
getFloatConstant(int)
,
getDoubleConstant(int)
,
getStringConstant(int)
public final int getWideConstantIndex()
Used for ldc_w, ldc2_w
getConstantIndex()
,
getConstantType(int)
,
getIntConstant(int)
,
getLongConstant(int)
,
getFloatConstant(int)
,
getDoubleConstant(int)
,
getStringConstant(int)
public final byte getConstantType(int index)
Used for ldc, ldc_w, ldc2_w
getConstantIndex()
,
getWideConstantIndex()
,
getIntConstant(int)
,
getLongConstant(int)
,
getFloatConstant(int)
,
getDoubleConstant(int)
,
getStringConstant(int)
public final int getIntConstant(int index)
Used for ldc, ldc_w
getConstantIndex()
,
getWideConstantIndex()
,
getConstantType(int)
,
getLongConstant(int)
,
getFloatConstant(int)
,
getDoubleConstant(int)
,
getStringConstant(int)
public final long getLongConstant(int index)
Used for ldc2_w
getConstantIndex()
,
getWideConstantIndex()
,
getConstantType(int)
,
getIntConstant(int)
,
getFloatConstant(int)
,
getDoubleConstant(int)
,
getStringConstant(int)
public final float getFloatConstant(int index)
Used for ldc, ldc_w
getConstantIndex()
,
getWideConstantIndex()
,
getConstantType(int)
,
getIntConstant(int)
,
getLongConstant(int)
,
getDoubleConstant(int)
,
getStringConstant(int)
public final double getDoubleConstant(int index)
Used for ldc2_w
getConstantIndex()
,
getWideConstantIndex()
,
getConstantType(int)
,
getIntConstant(int)
,
getLongConstant(int)
,
getFloatConstant(int)
,
getStringConstant(int)
public final String getStringConstant(int index)
Used for ldc, ldc_w
getConstantIndex()
,
getWideConstantIndex()
,
getConstantType(int)
,
getIntConstant(int)
,
getLongConstant(int)
,
getFloatConstant(int)
,
getDoubleConstant(int)
private void skipSpecialInstruction(int opcode)
public final int nextPseudoInstruction()
public final int readIntConst()
public final long readLongConst()
private long readLong()
private byte readSignedByte()
private int readUnsignedByte()
private int getUnsignedByte(int index)
private int readSignedShort()
private int readUnsignedShort()
private int readSignedInt()
private int getSignedInt(int index)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |