org.apache.bcel.generic

Class Instruction

public abstract class Instruction extends Object implements Cloneable, Serializable

Abstract super class for all Java byte codes.

Version: $Id: Instruction.java 386056 2006-03-15 11:31:56Z tcurdt $

Author: M. Dahm

Field Summary
static InstructionComparatorcmp
protected shortlength
protected shortopcode
Constructor Summary
Instruction()
Empty constructor needed for the Class.newInstance() statement in Instruction.readInstruction().
Instruction(short opcode, short length)
Method Summary
abstract voidaccept(Visitor v)
Call corresponding visitor method(s).
static StringclassName(short opcode)
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).
voiddispose()
Some instructions may be reused, so don't do anything by default.
voiddump(DataOutputStream out)
Dump instruction as byte code to stream out.
booleanequals(Object that)
Check for equality, delegated to comparator
static InstructionComparatorgetComparator()
Get Comparator object used in the equals() method to determine equality of instructions.
intgetLength()
StringgetName()
shortgetOpcode()
protected voidinitFromFile(ByteSequence bytes, boolean wide)
Read needed data (e.g. index) from file.
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)
Set comparator to be used for equals().
voidsetOpcode(short opcode)
Needed in readInstruction.
StringtoString(boolean verbose)
Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")"
StringtoString()
StringtoString(ConstantPool cp)

Field Detail

cmp

private static InstructionComparator cmp

length

protected short length

opcode

protected short opcode

Constructor Detail

Instruction

Instruction()
Empty constructor needed for the Class.newInstance() statement in Instruction.readInstruction(). Not to be used otherwise.

Instruction

public Instruction(short opcode, short length)

Method Detail

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

className

private static final String className(short opcode)

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

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

dispose

void dispose()
Some instructions may be reused, so don't do anything by default.

dump

public void dump(DataOutputStream out)
Dump instruction as byte code to stream out.

Parameters: out Output stream

equals

public boolean equals(Object that)
Check for equality, delegated to comparator

Returns: true if that is an Instruction and has the same opcode

getComparator

public static InstructionComparator getComparator()
Get Comparator object used in the equals() method to determine equality of instructions.

Returns: currently used comparator for equals()

getLength

public int getLength()

Returns: length (in bytes) of instruction

getName

public String getName()

Returns: name of instruction, i.e., opcode name

getOpcode

public short getOpcode()

Returns: this instructions opcode

initFromFile

protected void initFromFile(ByteSequence bytes, boolean wide)
Read needed data (e.g. index) from file.

Parameters: bytes byte sequence to read from wide "wide" instruction flag

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

readInstruction

public static final Instruction readInstruction(ByteSequence bytes)
Read an instruction from (byte code) input stream and return the appropiate object.

Parameters: bytes input stream bytes

Returns: instruction object being read

setComparator

public static void setComparator(InstructionComparator c)
Set comparator to be used for equals().

setOpcode

private void setOpcode(short opcode)
Needed in readInstruction.

toString

public 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 String toString()

Returns: mnemonic for instruction in verbose format

toString

public String toString(ConstantPool cp)

Returns: mnemonic for instruction with sumbolic references resolved