Class 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 Detail

      • 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 Detail

      • 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