Class Compiler

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

public abstract class Compiler extends Object implements Constants
This class generates Java bytecode from ShrikeBT Instructions.

If there are too many instructions to fit into 64K bytecodes, then we break the method up, generating auxiliary methods called by the main method.

This class is abstract; there are subclasses for specific class file access toolkits. These toolkits are responsible for providing ways to allocate constant pool entries.

  • Constructor Details

    • Compiler

      public Compiler(boolean isConstructor, boolean isStatic, String classType, String signature, IInstruction[] instructions, ExceptionHandler[][] handlers, int[] instructionsToBytecodes)
      Initialize a Compiler for the given method data.
      Parameters:
      isStatic - true iff the method is static
      classType - the JVM type of the class the method belongs to
      signature - the JVM signature of the method
      instructions - the ShrikeBT instructions
      handlers - the ShrikeBT exception handlers
      instructionsToBytecodes - the map from instructions to original bytecode offsets
      Throws:
      IllegalArgumentException - if handlers is null
      IllegalArgumentException - if instructions is null
      IllegalArgumentException - if instructionsToBytecodes is null
    • Compiler

      protected Compiler(MethodData info)
      Extract the data for the method to be compiled from the MethodData container.
  • Method Details

    • getClassType

      public final String getClassType()
      Returns:
      the JVM type for the class this method belongs to
    • setPresetConstants

      public final void setPresetConstants(ConstantPoolReader cp)
      Notify the compiler that the constants appearing in the ConstantPoolReader cp will appear in the final class file.

      Instructions which were extracted from a class file with the same ConstantPoolReader can be written back much more efficiently if the same constant pool indices are valid in the new class file.

    • setClassHierarchy

      public final void setClassHierarchy(ClassHierarchyProvider h)
    • allocateConstantPoolInteger

      protected abstract int allocateConstantPoolInteger(int v)
    • allocateConstantPoolFloat

      protected abstract int allocateConstantPoolFloat(float v)
    • allocateConstantPoolLong

      protected abstract int allocateConstantPoolLong(long v)
    • allocateConstantPoolDouble

      protected abstract int allocateConstantPoolDouble(double v)
    • allocateConstantPoolString

      protected abstract int allocateConstantPoolString(String v)
    • allocateConstantPoolClassType

      protected abstract int allocateConstantPoolClassType(String c)
    • allocateConstantPoolMethodType

      protected abstract int allocateConstantPoolMethodType(String c)
    • allocateConstantPoolMethodHandle

      protected abstract int allocateConstantPoolMethodHandle(ConstantPoolParser.ReferenceToken c)
    • allocateConstantPoolField

      protected abstract int allocateConstantPoolField(String c, String name, String type)
    • allocateConstantPoolMethod

      protected abstract int allocateConstantPoolMethod(String c, String name, String sig)
    • allocateConstantPoolInterfaceMethod

      protected abstract int allocateConstantPoolInterfaceMethod(String c, String name, String sig)
    • allocateConstantPoolInvokeDynamic

      protected abstract int allocateConstantPoolInvokeDynamic(BootstrapMethodsReader.BootstrapMethod b, String name, String type)
    • createHelperMethod

      protected abstract String createHelperMethod(boolean isStatic, String sig)
    • compile

      public final void compile()
      Do the work of generating new bytecodes.

      In pathological cases this could throw an Error, when the code you passed in is too large to fit into a single JVM method and Compiler can't find a way to break it up into helper methods. You probably won't encounter this unless you try to make it happen :-).

    • getOutput

      public final Compiler.Output getOutput()
      Get the output bytecodes and other information for the method.
    • getAuxiliaryMethods

      public final Compiler.Output[] getAuxiliaryMethods()
      Get bytecodes and other information for any helper methods that are required to implement the main method. These helpers represent code that could not be fit into the main method because of JVM method size constraints.