Class Decoder

java.lang.Object
com.ibm.wala.shrike.shrikeBT.Decoder
All Implemented Interfaces:
Constants
Direct Known Subclasses:
CTDecoder

public abstract class Decoder extends Object implements Constants
A Decoder translates a method's Java bytecode into shrikeBT code, i.e. an array of Instruction objects and an array of lists of ExceptionHandlers.

This class implements basic decoding functionality. A toolkit for reading class files must specialize this class with particular constant pool reader implementation.

Normal usage of this class looks like this:


    Decoder d = new MyToolkitDecoder(...);
    try {
      d.decode();
    } catch (Decoder.InvalidBytecodeException ex) {
      ...
    }
    Instruction[] myInstructions = d.getInstructions();
    ExceptionHandler[][] exnHandlers = d.getHandlers();

 
  • Constructor Details

    • Decoder

      protected Decoder(byte[] code, int[] rawHandlers, ConstantPoolReader cp)
      This constructor is only supposed to be used by subclasses.
      Parameters:
      code - the bytecodes for a method as per JVM spec
      rawHandlers - flattened array of (startPC, endPC, targetPC, classIndex) tuples defined as per the JVM spec
  • Method Details

    • getConstantPool

      public ConstantPoolReader getConstantPool()
    • decode

      public final void decode() throws Decoder.InvalidBytecodeException
      Perform the decoding.
      Throws:
      Decoder.InvalidBytecodeException - the incoming code is invalid and would fail Java bytecode verification
    • getInstructions

      public final IInstruction[] getInstructions()
      Get the decoded instructions.
      Returns:
      array of decoded instructions
    • getHandlers

      public final ExceptionHandler[][] getHandlers()
      Get the decoded exception handlers.
      Returns:
      array of exception handler lists
    • getInstructionsToBytecodes

      public final int[] getInstructionsToBytecodes()
      Get the mapping between instructions and input bytecodes.
      Returns:
      an array m such that m[i] is the offset of the bytecode instruction which gave rise to the Instruction referenced in the instructions array at offset i
    • containsSubroutines

      public final boolean containsSubroutines()
      Returns:
      true iff the method decoded by this Decoder contains subroutines (JSRs)