net.sf.rej.java.instruction
Class Instruction

java.lang.Object
  extended by net.sf.rej.java.instruction.Instruction
Direct Known Subclasses:
_aaload, _aastore, _aconst_null, _aload, _aload_0, _aload_1, _aload_2, _aload_3, _anewarray, _anewarray_quick, _areturn, _arraylength, _astore, _astore_0, _astore_1, _astore_2, _astore_3, _athrow, _baload, _bastore, _bipush, _breakpoint, _caload, _castore, _checkcast, _checkcast_quick, _d2f, _d2i, _d2l, _dadd, _daload, _dastore, _dcmpg, _dcmpl, _dconst_0, _dconst_1, _ddiv, _dload, _dload_0, _dload_1, _dload_2, _dload_3, _dmul, _dneg, _drem, _dreturn, _dstore, _dstore_0, _dstore_1, _dstore_2, _dstore_3, _dsub, _dup, _dup_x1, _dup_x2, _dup2, _dup2_x1, _dup2_x2, _f2d, _f2i, _f2l, _fadd, _faload, _fastore, _fcmpg, _fcmpl, _fconst_0, _fconst_1, _fconst_2, _fdiv, _fload, _fload_0, _fload_1, _fload_2, _fload_3, _fmul, _fneg, _frem, _freturn, _fstore, _fstore_0, _fstore_1, _fstore_2, _fstore_3, _fsub, _getfield, _getfield_quick, _getfield_quick_w, _getfield2_quick, _getstatic, _getstatic_quick, _getstatic2_quick, _goto, _goto_w, _i2b, _i2c, _i2d, _i2f, _i2l, _i2s, _iadd, _iaload, _iand, _iastore, _iconst_0, _iconst_1, _iconst_2, _iconst_3, _iconst_4, _iconst_5, _iconst_m1, _idiv, _if_acmpeq, _if_acmpne, _if_icmpeq, _if_icmpge, _if_icmpgt, _if_icmple, _if_icmplt, _if_icmpne, _ifeq, _ifge, _ifgt, _ifle, _iflt, _ifne, _ifnonnull, _ifnull, _iinc, _iload, _iload_0, _iload_1, _iload_2, _iload_3, _impdep1, _impdep2, _imul, _ineg, _instanceof, _instanceof_quick, _invokeinterface, _invokeinterface_quick, _invokenonvirtual_quick, _invokespecial, _invokestatic, _invokestatic_quick, _invokesuper_quick, _invokevirtual, _invokevirtual_quick, _invokevirtual_quick_w, _invokevirtualobject_quick, _ior, _irem, _ireturn, _ishl, _ishr, _istore, _istore_0, _istore_1, _istore_2, _istore_3, _isub, _iushr, _ixor, _jsr, _jsr_w, _l2d, _l2f, _l2i, _ladd, _laload, _land, _lastore, _lcmp, _lconst_0, _lconst_1, _ldc, _ldc_quick, _ldc_w, _ldc_w_quick, _ldc2_w, _ldc2_w_quick, _ldiv, _lload, _lload_0, _lload_1, _lload_2, _lload_3, _lmul, _lneg, _lookupswitch, _lor, _lrem, _lreturn, _lshl, _lshr, _lstore, _lstore_0, _lstore_1, _lstore_2, _lstore_3, _lsub, _lushr, _lxor, _monitorenter, _monitorexit, _multianewarray, _multianewarray_quick, _new, _new_quick, _newarray, _nop, _pop, _pop2, _putfield, _putfield_quick, _putfield_quick_w, _putfield2_quick, _putstatic, _putstatic_quick, _putstatic2_quick, _ret, _return, _saload, _sastore, _sipush, _swap, _tableswitch, _wide, _xxxunusedxxx, Label

public abstract class Instruction
extends java.lang.Object

This class represents a java bytecode instruction. It is the abstract superclass of instruction type classes(_aload, _nop, _invokeinterface, etc..)

Author:
Sami Koivu

Method Summary
 Instruction createNewInstance()
          Returns a new instance of this instruction.
abstract  void execute(ExecutionContext ec)
          Reserved for possible future use.
abstract  byte[] getData(DecompilationContext dc)
          Get the bytecode data for this instruction.
 java.util.List<Label> getLabels()
          Return a list with labels relevant to this instructions.
abstract  java.lang.String getMnemonic()
          Return the mnemonic of this instruction.
abstract  int getOpcode()
          Return the Opcode of this instruction.
abstract  Parameters getParameters()
          Return a Parameters object describing the types of parameters(if any) and the values set to this particular instance for those parameters.
abstract  Parameters getParameterTypes()
          Return a Parameters object describing the types of parameters(if any) that are applicable to this type of an instruction.
 java.util.List<StackElement> getPoppedElements(DecompilationContext dc)
          Returns the elements popped from the stack by this instance.
 java.util.List<StackElement> getPushedElements(DecompilationContext dc)
          Returns the elements pushed to the stack by this instance.
abstract  int getSize()
          Return the size of this instruction.
 int getSize(DecompilationContext dc)
          Override for variable sized instructions.
abstract  void setData(byte[] data, DecompilationContext dc)
          Set the data for this instruction.
abstract  void setParameters(Parameters params)
          Update the parameter values of this instruction with the values in the Parameters object defined by params.
 java.lang.String toString()
          Returns a textual description of this instruction instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getOpcode

public abstract int getOpcode()
Return the Opcode of this instruction.

Returns:
The Opcode value of this instruction.

getMnemonic

public abstract java.lang.String getMnemonic()
Return the mnemonic of this instruction. Such as aload, invokespecial, nop, etc..

Returns:
mnemonic.

getSize

public abstract int getSize()
Return the size of this instruction.

Returns:
Size of the instruction in bytes.

execute

public abstract void execute(ExecutionContext ec)
Reserved for possible future use.

Parameters:
ec - Context for execution.

getSize

public int getSize(DecompilationContext dc)
Override for variable sized instructions. This method should be called to query the size of an instruction. The default implementation simply calls the getSize() method, but for instructions where the size depetends on the location of the instruction in a code block, this method needs to be overridden, since it offers access to the decompilation context where the current position and other attributes may be queried.

Parameters:
dc - Context information(most importantly the pc position).
Returns:
Size of instruction in this given context in bytes.

setData

public abstract void setData(byte[] data,
                             DecompilationContext dc)
Set the data for this instruction. Called by the decompiler to initialize the parameters of the instruction from bytecode data.

Parameters:
data - A byte arrray with the instruction data, starting with the opcode byte(s) and followed by any parameters if applicable.
dc - A callback mechanism to offer the instruction information about the context where it's located.

getData

public abstract byte[] getData(DecompilationContext dc)
Get the bytecode data for this instruction. In other words, tell the instruction to serialize itself. Some instructions use padding to put the subsequent parameters in a pc position that is divisible by 4 and thus require the pc position which they can obtain from the DecompilationContext

Parameters:
dc - A callback mechanism to offer the instruction information about the context where it's located.
Returns:
A byte array with the instruction data.

getParameters

public abstract Parameters getParameters()
Return a Parameters object describing the types of parameters(if any) and the values set to this particular instance for those parameters. For different parameter types see the Parameters class. Modifications in the values of the parameters class are not reflected by this instruction unless setParameters(Parameters) is called subsequently.

Returns:
A Parameters object with the types and current values of the parameters.

getParameterTypes

public abstract Parameters getParameterTypes()
Return a Parameters object describing the types of parameters(if any) that are applicable to this type of an instruction. This method is identical to the getParameters() method, only the Parameters object return by a call to this method, does not contain the values of the parameters, just the type information.

Returns:
A Parameters object with the types of parameters applicable for this type of an instruction.

setParameters

public abstract void setParameters(Parameters params)
Update the parameter values of this instruction with the values in the Parameters object defined by params. Observe that the types and count of the parameters in the Parameters object MUST match those that this instruction expects. This can be ensured by obtaining the Parameters object with a call to getParameters() of this instruction.

Parameters:
params - A Parameters object with new values for this instruction.

getLabels

public java.util.List<Label> getLabels()
Return a list with labels relevant to this instructions. Labels are symbolic and do not exist in the actual bytecode. This method returns a List containing Label objects, and by setting the position of a label with a call to Label.setPosition(int) this instruction is updated with the information. The labels are used for example for the goto instruction.

Returns:
A List of Label objects.

toString

public java.lang.String toString()
Returns a textual description of this instruction instance. The default implementation just returns the Mnemonic returned by getMnemonic().

Overrides:
toString in class java.lang.Object
Returns:
Description

createNewInstance

public Instruction createNewInstance()
                              throws java.lang.InstantiationException,
                                     java.lang.IllegalAccessException
Returns a new instance of this instruction. No parameters are copied. If the instruction is a wide instruction, also the contained, widened instruction will be cloned.

Returns:
a new blank instance of this instruction.
Throws:
java.lang.InstantiationException - a problem with instantiation.
java.lang.IllegalAccessException - access exception.

getPushedElements

public java.util.List<StackElement> getPushedElements(DecompilationContext dc)
Returns the elements pushed to the stack by this instance. This information is static for most instructions, but for example, for the invokexxx instructions it depends on the instruction that is being invoked.

Parameters:
dc - the decompilation context so that the processing can access the constant pool, when necessary.
Returns:
a StackElements instance describing the elements pushed onto the stack.

getPoppedElements

public java.util.List<StackElement> getPoppedElements(DecompilationContext dc)
Returns the elements popped from the stack by this instance. This information is static for most instructions, but for example, for the invokexxx instructions it depends on the instruction that is being invoked.

Parameters:
dc - the decompilation context so that the processing can access the constant pool, when necessary.
Returns:
a StackElements instance describing the elements popped from the stack.