Package org.apache.bcel.generic
Class Instruction
java.lang.Object
org.apache.bcel.generic.Instruction
- All Implemented Interfaces:
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
Abstract super class for all Java byte codes.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
Call corresponding visitor method(s).int
This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.copy()
Use with caution, since 'BranchInstruction's have a 'target' reference which is not copied correctly (only basic types are).void
dump
(DataOutputStream out) Dumps instruction as byte code to stream out.boolean
Tests for equality, delegated to comparatorstatic InstructionComparator
Deprecated.(6.0) use the built in comparator, or wrap this class in another object that implements these methodsint
getName()
short
int
hashCode()
Gets the hashCode of this object.protected void
initFromFile
(ByteSequence bytes, boolean wide) Reads needed data (e.g.static boolean
isValidByte
(int value) Tests if the value can fit in a byte (signed)static boolean
isValidShort
(int value) Tests if the value can fit in a short (signed)int
This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.static Instruction
readInstruction
(ByteSequence bytes) Reads an instruction from (byte code) input stream and return the appropriate object.static void
Deprecated.(6.0) use the built in comparator, or wrap this class in another object that implements these methodstoString()
toString
(boolean verbose) Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")"toString
(ConstantPool cp)
-
Field Details
-
length
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter -
opcode
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter
-
-
Constructor Details
-
Instruction
-
-
Method Details
-
getComparator
Deprecated.(6.0) use the built in comparator, or wrap this class in another object that implements these methodsGets Comparator object used in the equals() method to determine equality of instructions.- Returns:
- currently used comparator for equals()
-
isValidByte
Tests 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
Tests 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
-
readInstruction
Reads an instruction from (byte code) input stream and return the appropriate 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:
IOException
- Thrown when an I/O exception of some sort has occurred.- See Also:
-
setComparator
Deprecated.(6.0) use the built in comparator, or wrap this class in another object that implements these methodsSets comparator to be used for equals(). -
accept
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
-
consumeStack
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
-
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:
-
dump
Dumps instruction as byte code to stream out.- Parameters:
out
- Output stream- Throws:
IOException
- Thrown when an I/O exception of some sort has occurred.
-
equals
Tests for equality, delegated to comparator -
getLength
- Returns:
- length (in bytes) of instruction
-
getName
- Returns:
- name of instruction, i.e., opcode name
-
getOpcode
- Returns:
- this instructions opcode
-
hashCode
Gets the hashCode of this object. -
initFromFile
Reads needed data (e.g. index) from file.- Parameters:
bytes
- byte sequence to read fromwide
- "wide" instruction flag- Throws:
IOException
- may be thrown if the implementation needs to read data from the file
-
produceStack
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
-
toString
-
toString
Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")"- Parameters:
verbose
- long/short format switch- Returns:
- mnemonic for instruction
-
toString
- Returns:
- mnemonic for instruction with sumbolic references resolved
-