Package org.apache.bcel.generic
Class Instruction
- java.lang.Object
-
- org.apache.bcel.generic.Instruction
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
ACONST_NULL,ArithmeticInstruction,ArrayInstruction,ARRAYLENGTH,ATHROW,BIPUSH,BranchInstruction,BREAKPOINT,ConversionInstruction,CPInstruction,DCMPG,DCMPL,DCONST,FCMPG,FCMPL,FCONST,ICONST,IMPDEP1,IMPDEP2,LCMP,LCONST,LocalVariableInstruction,MONITORENTER,MONITOREXIT,NEWARRAY,NOP,RET,ReturnInstruction,SIPUSH,StackInstruction
public abstract class Instruction extends java.lang.Object implements java.lang.CloneableAbstract super class for all Java byte codes.
-
-
Field Summary
Fields Modifier and Type Field Description private static InstructionComparatorcmpprotected shortlengthDeprecated.(since 6.0) will be made private; do not access directly, use getter/setterprotected shortopcodeDeprecated.(since 6.0) will be made private; do not access directly, use getter/setter
-
Constructor Summary
Constructors Constructor Description Instruction()Empty constructor needed for Instruction.readInstruction.Instruction(short opcode, short length)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract voidaccept(Visitor v)Call corresponding visitor method(s).intconsumeStack(ConstantPoolGen cpg)This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.Instructioncopy()Use with caution, since `BranchInstruction's have a `target' reference which is not copied correctly (only basic types are).(package private) voiddispose()Some instructions may be reused, so don't do anything by default.voiddump(java.io.DataOutputStream out)Dump instruction as byte code to stream out.booleanequals(java.lang.Object that)Check for equality, delegated to comparatorstatic InstructionComparatorgetComparator()Deprecated.(6.0) use the built in comparator, or wrap this class in another object that implements these methodsintgetLength()java.lang.StringgetName()shortgetOpcode()inthashCode()calculate the hashCode of this objectprotected voidinitFromFile(ByteSequence bytes, boolean wide)Read needed data (e.g.static booleanisValidByte(int value)Check if the value can fit in a byte (signed)static booleanisValidShort(int value)Check if the value can fit in a short (signed)intproduceStack(ConstantPoolGen cpg)This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.static InstructionreadInstruction(ByteSequence bytes)Read an instruction from (byte code) input stream and return the appropiate object.static voidsetComparator(InstructionComparator c)Deprecated.(6.0) use the built in comparator, or wrap this class in another object that implements these methods(package private) voidsetLength(int length)Needed in readInstruction and subclasses in this package(package private) voidsetOpcode(short opcode)Needed in readInstruction and subclasses in this packagejava.lang.StringtoString()java.lang.StringtoString(boolean verbose)Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")"java.lang.StringtoString(ConstantPool cp)
-
-
-
Field Detail
-
length
@Deprecated protected short length
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter
-
opcode
@Deprecated protected short opcode
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter
-
cmp
private static InstructionComparator cmp
-
-
Method Detail
-
dump
public void dump(java.io.DataOutputStream out) throws java.io.IOExceptionDump instruction as byte code to stream out.- Parameters:
out- Output stream- Throws:
java.io.IOException
-
getName
public java.lang.String getName()
- Returns:
- name of instruction, i.e., opcode name
-
toString
public java.lang.String toString(boolean verbose)
Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")"- Parameters:
verbose- long/short format switch- Returns:
- mnemonic for instruction
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Returns:
- mnemonic for instruction in verbose format
-
toString
public java.lang.String toString(ConstantPool cp)
- Returns:
- mnemonic for instruction with sumbolic references resolved
-
copy
public Instruction copy()
Use with caution, since `BranchInstruction's have a `target' reference which is not copied correctly (only basic types are). This also applies for `Select' instructions with their multiple branch targets.- Returns:
- (shallow) copy of an instruction
- See Also:
BranchInstruction
-
initFromFile
protected void initFromFile(ByteSequence bytes, boolean wide) throws java.io.IOException
Read needed data (e.g. index) from file.- Parameters:
bytes- byte sequence to read fromwide- "wide" instruction flag- Throws:
java.io.IOException- may be thrown if the implementation needs to read data from the file
-
readInstruction
public static Instruction readInstruction(ByteSequence bytes) throws java.io.IOException
Read an instruction from (byte code) input stream and return the appropiate object.If the Instruction is defined in
InstructionConst, then the singleton instance is returned.- Parameters:
bytes- input stream bytes- Returns:
- instruction object being read
- Throws:
java.io.IOException- See Also:
InstructionConst.getInstruction(int)
-
consumeStack
public int consumeStack(ConstantPoolGen cpg)
This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.- Returns:
- Number of words consumed from stack by this instruction, or Constants.UNPREDICTABLE, if this can not be computed statically
-
produceStack
public int produceStack(ConstantPoolGen cpg)
This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.- Returns:
- Number of words produced onto stack by this instruction, or Constants.UNPREDICTABLE, if this can not be computed statically
-
getOpcode
public short getOpcode()
- Returns:
- this instructions opcode
-
getLength
public int getLength()
- Returns:
- length (in bytes) of instruction
-
setOpcode
final void setOpcode(short opcode)
Needed in readInstruction and subclasses in this package
-
setLength
final void setLength(int length)
Needed in readInstruction and subclasses in this package- Since:
- 6.0
-
dispose
void dispose()
Some instructions may be reused, so don't do anything by default.
-
accept
public abstract void accept(Visitor v)
Call corresponding visitor method(s). The order is: Call visitor methods of implemented interfaces first, then call methods according to the class hierarchy in descending order, i.e., the most specific visitXXX() call comes last.- Parameters:
v- Visitor object
-
getComparator
@Deprecated public static InstructionComparator getComparator()
Deprecated.(6.0) use the built in comparator, or wrap this class in another object that implements these methodsGet Comparator object used in the equals() method to determine equality of instructions.- Returns:
- currently used comparator for equals()
-
setComparator
@Deprecated public static void setComparator(InstructionComparator c)
Deprecated.(6.0) use the built in comparator, or wrap this class in another object that implements these methodsSet comparator to be used for equals().
-
equals
public boolean equals(java.lang.Object that)
Check for equality, delegated to comparator- Overrides:
equalsin classjava.lang.Object- Returns:
- true if that is an Instruction and has the same opcode
-
hashCode
public int hashCode()
calculate the hashCode of this object- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hashCode
- Since:
- 6.0
-
isValidByte
public static boolean isValidByte(int value)
Check if the value can fit in a byte (signed)- Parameters:
value- the value to check- Returns:
- true if the value is in range
- Since:
- 6.0
-
isValidShort
public static boolean isValidShort(int value)
Check if the value can fit in a short (signed)- Parameters:
value- the value to check- Returns:
- true if the value is in range
- Since:
- 6.0
-
-