org.objectweb.fractal.julia.asm
Class InterceptorCodeAdapter

java.lang.Object
  extended by org.objectweb.asm.MethodAdapter
      extended by org.objectweb.fractal.julia.asm.InterceptorCodeAdapter
All Implemented Interfaces:
MethodVisitor, Opcodes

public abstract class InterceptorCodeAdapter
extends MethodAdapter
implements Opcodes

An abstract code adapter to ease the implementation of CodeGenerator. This code adapter can replace the return instructions it visits with goto or jsr instructions, in order to add a post code block after the original code of a method. This code adapter can also insert new local variables before the original local variables (which are therefore shifted), but after the actual parameters. This can be useful to use private local variables in the interception code.


Field Summary
static int EMPTY
          Describes an empty post block.
static int FINALLY
          Describes a finally post block.
protected  Method m
          The method for which this code adapter is used.
protected  int nbFormals
          Size of the formal parameters of the method for which this code adapter is used.
static int NORMAL
          Describes a normal post code block.
protected  Label postBlockLabel
          Beginning of the post code block added to the original code.
protected  int returnLocal
          The inserted local variable used to store the result value.
 
Fields inherited from class org.objectweb.asm.MethodAdapter
mv
 
Fields inherited from interface org.objectweb.asm.Opcodes
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DREM, DRETURN, DSTORE, 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, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, 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, IMUL, INEG, INSTANCEOF, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, V1_1, V1_2, V1_3, V1_4, V1_5
 
Constructor Summary
InterceptorCodeAdapter(MethodVisitor cv, Method m, int newLocals, int postBlockType)
          Constructs a new InterceptorCodeAdapter.
 
Method Summary
protected  void generateReturnCode()
          Generates the code to return the result value stored in the returnLocal local variable.
 void visitIincInsn(int var, int increment)
          Shifts the original local variables to make room for the inserted ones.
 void visitInsn(int opcode)
          Replaces returns with instructions to jump to the beginning of the post code block.
 void visitVarInsn(int opcode, int var)
          Shifts the original local variables to make room for the inserted ones.
 
Methods inherited from class org.objectweb.asm.MethodAdapter
visitAnnotation, visitAnnotationDefault, visitAttribute, visitCode, visitEnd, visitFieldInsn, visitIntInsn, visitJumpInsn, visitLabel, visitLdcInsn, visitLineNumber, visitLocalVariable, visitLookupSwitchInsn, visitMaxs, visitMethodInsn, visitMultiANewArrayInsn, visitParameterAnnotation, visitTableSwitchInsn, visitTryCatchBlock, visitTypeInsn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY

public static final int EMPTY
Describes an empty post block.

See Also:
Constant Field Values

NORMAL

public static final int NORMAL
Describes a normal post code block. A normal post code block is not executed if the original code throws an exception.

See Also:
Constant Field Values

FINALLY

public static final int FINALLY
Describes a finally post block. A finally post code block is always executed, even if the original code throws an exception.

See Also:
Constant Field Values

m

protected Method m
The method for which this code adapter is used.


nbFormals

protected int nbFormals
Size of the formal parameters of the method for which this code adapter is used. This size is also the index of the first inserted local variable.


returnLocal

protected int returnLocal
The inserted local variable used to store the result value.


postBlockLabel

protected Label postBlockLabel
Beginning of the post code block added to the original code.

Constructor Detail

InterceptorCodeAdapter

public InterceptorCodeAdapter(MethodVisitor cv,
                              Method m,
                              int newLocals,
                              int postBlockType)
Constructs a new InterceptorCodeAdapter.

Parameters:
cv - the code visitor to which this adapter must delegate calls.
m - the method for which this code adapter is used.
newLocals - the number of new local variables that must be inserted in the original method code. This number does not include the local variable used to store the result value, which is automatically inserted. The inserted local variables are those between the nbFormals index, inclusive, and the nbFormals + newLocals index, exclusive.
postBlockType - the type of the post code block that will be added after the original code, i.e., either EMPTY, NORMAL or FINALLY.
Method Detail

visitInsn

public void visitInsn(int opcode)
Replaces returns with instructions to jump to the beginning of the post code block. More precisely, if the post code bock is empty, the returns are not replaced. If the post code block is normal they are replaced by sequences of the following form:
 xSTORE returnLocal
 GOTO postCodeLabel
 
If the post code block is a finally block, they are replaced by sequences of the following form:
 xSTORE returnLocal
 JSR postCodeLabel
 xLOAD returnLocal
 xRETURN
 

Specified by:
visitInsn in interface MethodVisitor
Overrides:
visitInsn in class MethodAdapter
Parameters:
opcode - the opcode of the visited instruction.

visitVarInsn

public void visitVarInsn(int opcode,
                         int var)
Shifts the original local variables to make room for the inserted ones.

Specified by:
visitVarInsn in interface MethodVisitor
Overrides:
visitVarInsn in class MethodAdapter
Parameters:
opcode - the opcode of the visited instruction.
var - a local variable index.

visitIincInsn

public void visitIincInsn(int var,
                          int increment)
Shifts the original local variables to make room for the inserted ones.

Specified by:
visitIincInsn in interface MethodVisitor
Overrides:
visitIincInsn in class MethodAdapter
Parameters:
var - a local variable index.
increment - an increment value.

generateReturnCode

protected void generateReturnCode()
Generates the code to return the result value stored in the returnLocal local variable. More precisely, generates a sequence of the following form:
 xLOAD returnLocal
 xRETURN