Top Description Fields Constructors Methods
com.sun.org.apache.bcel.internal.generic

public abstract Class Instruction

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Known Direct Subclasses
com.sun.org.apache.bcel.internal.generic.LCMP, com.sun.org.apache.bcel.internal.generic.LCONST, com.sun.org.apache.bcel.internal.generic.LocalVariableInstruction, com.sun.org.apache.bcel.internal.generic.MONITORENTER, com.sun.org.apache.bcel.internal.generic.MONITOREXIT, com.sun.org.apache.bcel.internal.generic.NEWARRAY, com.sun.org.apache.bcel.internal.generic.NOP, com.sun.org.apache.bcel.internal.generic.RET, com.sun.org.apache.bcel.internal.generic.ReturnInstruction, com.sun.org.apache.bcel.internal.generic.SIPUSH, com.sun.org.apache.bcel.internal.generic.StackInstruction, com.sun.org.apache.xalan.internal.xsltc.compiler.util.MarkerInstruction, com.sun.org.apache.bcel.internal.generic.ACONST_NULL, com.sun.org.apache.bcel.internal.generic.ArithmeticInstruction, com.sun.org.apache.bcel.internal.generic.ArrayInstruction, com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH, com.sun.org.apache.bcel.internal.generic.ATHROW, com.sun.org.apache.bcel.internal.generic.BIPUSH, com.sun.org.apache.bcel.internal.generic.BranchInstruction, com.sun.org.apache.bcel.internal.generic.BREAKPOINT, com.sun.org.apache.bcel.internal.generic.CPInstruction, com.sun.org.apache.bcel.internal.generic.DCMPG, com.sun.org.apache.bcel.internal.generic.DCMPL, com.sun.org.apache.bcel.internal.generic.DCONST, com.sun.org.apache.bcel.internal.generic.FCMPG, com.sun.org.apache.bcel.internal.generic.FCMPL, com.sun.org.apache.bcel.internal.generic.ConversionInstruction, com.sun.org.apache.bcel.internal.generic.FCONST, com.sun.org.apache.bcel.internal.generic.ICONST, com.sun.org.apache.bcel.internal.generic.IMPDEP1, com.sun.org.apache.bcel.internal.generic.IMPDEP2
Imports
java.io.DataOutputStream, .IOException, com.sun.org.apache.bcel.internal.Const, com.sun.org.apache.bcel.internal.classfile.ConstantPool, com.sun.org.apache.bcel.internal.util.ByteSequence

Abstract super class for all Java byte codes.

Field Summary

Modifier and TypeField and Description
private static InstructionComparator
pack-priv static final Instruction[]
protected short
length

Deprecated (since 6.0) will be made private; do not access directly, use getter/setter
protected short
opcode

Deprecated (since 6.0) will be made private; do not access directly, use getter/setter

Constructor Summary

AccessConstructor and Description
pack-priv
Instruction()

Empty constructor needed for Instruction.readInstruction.

public
Instruction(final short opcode, final short length)

Method Summary

Modifier and TypeMethod and Description
public abstract void
accept(Visitor
Visitor object
v
)

Call corresponding visitor method(s).

public int

Returns:

Number of words consumed from stack by this instruction, or Constants.UNPREDICTABLE, if this can not be computed statically
consumeStack
(final ConstantPoolGen cpg)

This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.

public Instruction

Returns:

(shallow) copy of an instruction
copy
()

Use with caution, since 'BranchInstruction's have a 'target' reference which is not copied correctly (only basic types are).

pack-priv void
dispose()

Some instructions may be reused, so don't do anything by default.

public void
dump(final DataOutputStream
Output stream
out
)

Dumps instruction as byte code to stream out.

public boolean

Returns:

true if that is an Instruction and has the same opcode
equals
(final Object
the reference object with which to compare.
that
)

Overrides java.lang.Object.equals.

Tests for equality, delegated to comparator
public static InstructionComparator

Returns:

currently used comparator for equals()
getComparator
()

Deprecated (6.0) use the built in comparator, or wrap this class in another object that implements these methods
Gets Comparator object used in the equals() method to determine equality of instructions.
public int

Returns:

length (in bytes) of instruction
getLength
()

public String

Returns:

name of instruction, i.e., opcode name
getName
()

public short

Returns:

this instructions opcode
getOpcode
()

public int

Returns:

the hashCode
hashCode
()

Overrides java.lang.Object.hashCode.

Gets the hashCode of this object.
protected void
initFromFile(final ByteSequence
byte sequence to read from
bytes
,
final boolean
"wide" instruction flag
wide
)

Reads needed data (e.g. index) from file.

public static boolean

Returns:

true if the value is in range
isValidByte
(final int
the value to check
value
)

Tests if the value can fit in a byte (signed)

public static boolean

Returns:

true if the value is in range
isValidShort
(final int
the value to check
value
)

Tests if the value can fit in a short (signed)

public int

Returns:

Number of words produced onto stack by this instruction, or Constants.UNPREDICTABLE, if this can not be computed statically
produceStack
(final ConstantPoolGen cpg)

This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.

public static Instruction

Returns:

instruction object being read
readInstruction
(final ByteSequence
input stream bytes
bytes
)

Reads an instruction from (byte code) input stream and return the appropriate object.

public static void
setComparator(final InstructionComparator c)

Deprecated (6.0) use the built in comparator, or wrap this class in another object that implements these methods
Sets comparator to be used for equals().
pack-priv final void
setLength(final int length)

Needed in readInstruction and subclasses in this package

pack-priv void
setOpcode(final short opcode)

Needed in readInstruction and subclasses in this package

public String

Returns:

mnemonic for instruction in verbose format
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public String

Returns:

mnemonic for instruction
toString
(final boolean
long/short format switch
verbose
)

Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")"

public String

Returns:

mnemonic for instruction with sumbolic references resolved
toString
(final ConstantPool cp)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

cmpback to summary
private static InstructionComparator cmp
EMPTY_ARRAYback to summary
pack-priv static final Instruction[] EMPTY_ARRAY
lengthback to summary
protected short length

Deprecated

(since 6.0) will be made private; do not access directly, use getter/setter

Annotations
@Deprecated
opcodeback to summary
protected short opcode

Deprecated

(since 6.0) will be made private; do not access directly, use getter/setter

Annotations
@Deprecated

Constructor Detail

Instructionback to summary
pack-priv Instruction()

Empty constructor needed for Instruction.readInstruction. Not to be used otherwise.

Instructionback to summary
public Instruction(final short opcode, final short length)

Method Detail

acceptback to summary
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

Visitor object

consumeStackback to summary
public int consumeStack(final ConstantPoolGen cpg)

This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.

Returns:int

Number of words consumed from stack by this instruction, or Constants.UNPREDICTABLE, if this can not be computed statically

copyback to summary
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:Instruction

(shallow) copy of an instruction

See Also
BranchInstruction
disposeback to summary
pack-priv void dispose()

Some instructions may be reused, so don't do anything by default.

dumpback to summary
public void dump(final DataOutputStream out) throws IOException

Dumps instruction as byte code to stream out.

Parameters
out:DataOutputStream

Output stream

Exceptions
IOException:
Thrown when an I/O exception of some sort has occurred.
equalsback to summary
public boolean equals(final Object that)

Overrides java.lang.Object.equals.

Tests for equality, delegated to comparator

Parameters
that:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

true if that is an Instruction and has the same opcode

Annotations
@Override
getComparatorback to summary
public static InstructionComparator getComparator()

Deprecated

(6.0) use the built in comparator, or wrap this class in another object that implements these methods

Gets Comparator object used in the equals() method to determine equality of instructions.

Returns:InstructionComparator

currently used comparator for equals()

Annotations
@Deprecated
getLengthback to summary
public int getLength()
Returns:int

length (in bytes) of instruction

getNameback to summary
public String getName()
Returns:String

name of instruction, i.e., opcode name

getOpcodeback to summary
public short getOpcode()
Returns:short

this instructions opcode

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Gets the hashCode of this object.

Returns:int

the hashCode

Annotations
@Override
Since
6.0
initFromFileback to summary
protected void initFromFile(final ByteSequence bytes, final boolean wide) throws IOException

Reads needed data (e.g. index) from file.

Parameters
bytes:ByteSequence

byte sequence to read from

wide:boolean

"wide" instruction flag

Annotations
@SuppressWarnings:unused
Exceptions
IOException:
may be thrown if the implementation needs to read data from the file
isValidByteback to summary
public static boolean isValidByte(final int value)

Tests if the value can fit in a byte (signed)

Parameters
value:int

the value to check

Returns:boolean

true if the value is in range

Since
6.0
isValidShortback to summary
public static boolean isValidShort(final int value)

Tests if the value can fit in a short (signed)

Parameters
value:int

the value to check

Returns:boolean

true if the value is in range

Since
6.0
produceStackback to summary
public int produceStack(final ConstantPoolGen cpg)

This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.

Returns:int

Number of words produced onto stack by this instruction, or Constants.UNPREDICTABLE, if this can not be computed statically

readInstructionback to summary
public static Instruction readInstruction(final ByteSequence bytes) throws IOException

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:ByteSequence

input stream bytes

Returns:Instruction

instruction object being read

Exceptions
IOException:
Thrown when an I/O exception of some sort has occurred.
See Also
InstructionConst#getInstruction(int)
setComparatorback to summary
public static void setComparator(final InstructionComparator c)

Deprecated

(6.0) use the built in comparator, or wrap this class in another object that implements these methods

Sets comparator to be used for equals().

Annotations
@Deprecated
setLengthback to summary
pack-priv final void setLength(final int length)

Needed in readInstruction and subclasses in this package

Since
6.0
setOpcodeback to summary
pack-priv void setOpcode(final short opcode)

Needed in readInstruction and subclasses in this package

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

mnemonic for instruction in verbose format

Annotations
@Override
toStringback to summary
public String toString(final boolean verbose)

Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")"

Parameters
verbose:boolean

long/short format switch

Returns:String

mnemonic for instruction

toStringback to summary
public String toString(final ConstantPool cp)
Returns:String

mnemonic for instruction with sumbolic references resolved