Package com.ibm.wala.shrikeBT
Class Compiler
- java.lang.Object
-
- com.ibm.wala.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Compiler.Output
This class represents a method generated by a Compiler.
-
Field Summary
-
Fields inherited from interface com.ibm.wala.shrikeBT.Constants
ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, CONSTANT_Class, CONSTANT_Double, CONSTANT_FieldRef, CONSTANT_Float, CONSTANT_Integer, CONSTANT_InterfaceMethodRef, CONSTANT_InvokeDynamic, CONSTANT_Long, CONSTANT_MethodHandle, CONSTANT_MethodRef, CONSTANT_MethodType, CONSTANT_NameAndType, CONSTANT_String, CONSTANT_Utf8, indexedTypes, indexedTypes_T, MAYBE, NO, OP_aaload, OP_aastore, OP_aconst_null, OP_aload, OP_aload_0, OP_aload_1, OP_aload_2, OP_aload_3, OP_anewarray, OP_areturn, OP_arraylength, OP_astore, OP_astore_0, OP_astore_1, OP_astore_2, OP_astore_3, OP_athrow, OP_baload, OP_bastore, OP_bipush, OP_caload, OP_castore, OP_checkcast, OP_d2f, OP_d2i, OP_d2l, OP_dadd, OP_daload, OP_dastore, OP_dcmpg, OP_dcmpl, OP_dconst_0, OP_dconst_1, OP_ddiv, OP_dload, OP_dload_0, OP_dload_1, OP_dload_2, OP_dload_3, OP_dmul, OP_dneg, OP_drem, OP_dreturn, OP_dstore, OP_dstore_0, OP_dstore_1, OP_dstore_2, OP_dstore_3, OP_dsub, OP_dup, OP_dup_x1, OP_dup_x2, OP_dup2, OP_dup2_x1, OP_dup2_x2, OP_f2d, OP_f2i, OP_f2l, OP_fadd, OP_faload, OP_fastore, OP_fcmpg, OP_fcmpl, OP_fconst_0, OP_fconst_1, OP_fconst_2, OP_fdiv, OP_fload, OP_fload_0, OP_fload_1, OP_fload_2, OP_fload_3, OP_fmul, OP_fneg, OP_frem, OP_freturn, OP_fstore, OP_fstore_0, OP_fstore_1, OP_fstore_2, OP_fstore_3, OP_fsub, OP_getfield, OP_getstatic, OP_goto, OP_goto_w, OP_i2b, OP_i2c, OP_i2d, OP_i2f, OP_i2l, OP_i2s, OP_iadd, OP_iaload, OP_iand, OP_iastore, OP_iconst_0, OP_iconst_1, OP_iconst_2, OP_iconst_3, OP_iconst_4, OP_iconst_5, OP_iconst_m1, OP_idiv, OP_if_acmpeq, OP_if_acmpne, OP_if_icmpeq, OP_if_icmpge, OP_if_icmpgt, OP_if_icmple, OP_if_icmplt, OP_if_icmpne, OP_ifeq, OP_ifge, OP_ifgt, OP_ifle, OP_iflt, OP_ifne, OP_ifnonnull, OP_ifnull, OP_iinc, OP_iload, OP_iload_0, OP_iload_1, OP_iload_2, OP_iload_3, OP_imul, OP_ineg, OP_instanceof, OP_invokedynamic, OP_invokeinterface, OP_invokespecial, OP_invokestatic, OP_invokevirtual, OP_ior, OP_irem, OP_ireturn, OP_ishl, OP_ishr, OP_istore, OP_istore_0, OP_istore_1, OP_istore_2, OP_istore_3, OP_isub, OP_iushr, OP_ixor, OP_jsr, OP_jsr_w, OP_l2d, OP_l2f, OP_l2i, OP_ladd, OP_laload, OP_land, OP_lastore, OP_lcmp, OP_lconst_0, OP_lconst_1, OP_ldc, OP_ldc_w, OP_ldc2_w, OP_ldiv, OP_lload, OP_lload_0, OP_lload_1, OP_lload_2, OP_lload_3, OP_lmul, OP_lneg, OP_lookupswitch, OP_lor, OP_lrem, OP_lreturn, OP_lshl, OP_lshr, OP_lstore, OP_lstore_0, OP_lstore_1, OP_lstore_2, OP_lstore_3, OP_lsub, OP_lushr, OP_lxor, OP_monitorenter, OP_monitorexit, OP_multianewarray, OP_new, OP_newarray, OP_nop, OP_pop, OP_pop2, OP_putfield, OP_putstatic, OP_ret, OP_return, OP_saload, OP_sastore, OP_sipush, OP_swap, OP_tableswitch, OP_wide, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TYPE_boolean, TYPE_boolean_index, TYPE_byte, TYPE_byte_index, TYPE_char, TYPE_char_index, TYPE_Class, TYPE_double, TYPE_double_index, TYPE_Error, TYPE_Exception, TYPE_float, TYPE_float_index, TYPE_int, TYPE_int_index, TYPE_long, TYPE_long_index, TYPE_MethodHandle, TYPE_MethodType, TYPE_null, TYPE_Object, TYPE_Object_index, TYPE_RuntimeException, TYPE_short, TYPE_short_index, TYPE_String, TYPE_Throwable, TYPE_unknown, TYPE_void, YES
-
-
Constructor Summary
Constructors Modifier Constructor Description Compiler(boolean isConstructor, boolean isStatic, String classType, String signature, IInstruction[] instructions, ExceptionHandler[][] handlers, int[] instructionsToBytecodes)
Initialize a Compiler for the given method data.protected
Compiler(MethodData info)
Extract the data for the method to be compiled from the MethodData container.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract int
allocateConstantPoolClassType(String c)
protected abstract int
allocateConstantPoolDouble(double v)
protected abstract int
allocateConstantPoolField(String c, String name, String type)
protected abstract int
allocateConstantPoolFloat(float v)
protected abstract int
allocateConstantPoolInteger(int v)
protected abstract int
allocateConstantPoolInterfaceMethod(String c, String name, String sig)
protected abstract int
allocateConstantPoolLong(long v)
protected abstract int
allocateConstantPoolMethod(String c, String name, String sig)
protected abstract int
allocateConstantPoolMethodHandle(ConstantPoolParser.ReferenceToken c)
protected abstract int
allocateConstantPoolMethodType(String c)
protected abstract int
allocateConstantPoolString(String v)
void
compile()
Do the work of generating new bytecodes.protected abstract String
createHelperMethod(boolean isStatic, String sig)
Compiler.Output[]
getAuxiliaryMethods()
Get bytecodes and other information for any helper methods that are required to implement the main method.String
getClassType()
Compiler.Output
getOutput()
Get the output bytecodes and other information for the method.void
setClassHierarchy(ClassHierarchyProvider h)
void
setPresetConstants(ConstantPoolReader cp)
Notify the compiler that the constants appearing in the ConstantPoolReader cp will appear in the final class file.
-
-
-
Constructor Detail
-
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 staticclassType
- the JVM type of the class the method belongs tosignature
- the JVM signature of the methodinstructions
- the ShrikeBT instructionshandlers
- the ShrikeBT exception handlersinstructionsToBytecodes
- the map from instructions to original bytecode offsets- Throws:
IllegalArgumentException
- if handlers is nullIllegalArgumentException
- if instructions is nullIllegalArgumentException
- if instructionsToBytecodes is null
-
Compiler
protected Compiler(MethodData info)
Extract the data for the method to be compiled from the MethodData container.
-
-
Method Detail
-
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)
-
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.
-
-