org.objectweb.fractal.julia.asm
Class LifeCycleCodeGenerator

java.lang.Object
  extended byorg.objectweb.fractal.julia.asm.AbstractCodeGenerator
      extended byorg.objectweb.fractal.julia.asm.LifeCycleCodeGenerator
All Implemented Interfaces:
CodeGenerator, Constants

public class LifeCycleCodeGenerator
extends AbstractCodeGenerator

A CodeGenerator to generate pre and post code to enforce the component's lifecycle. More precisely the code adapters returned by the generateInterceptionCode method (see CodeGenerator) transform the original methods into methods of the following form:

 <method signature> {
   synchronized (lc) {
     if (lc.fcState != 2)
       lc.incrementFcInvocationCounter();
     else
       lc.fcInvocationCounter++;
   }
   try {
     // original method code
   } finally {
     synchronized (lc) {
       if (lc.fcState != 2)
         lc.decrementFcInvocationCounter();
       else
         lc.fcInvocationCounter--;
     }
   }
 }
 
The generateInitCode method generates code blocks of the following form:
 lc = (...)ic.getInterface("lifecycle-controller");
 
where lc is a field added to the class that is being generated (in fact, if the controller and interceptor classes are merged (see InterceptorClassGenerator), the lc field is not generated and replaced by this in the above code).

Note: as you can see the code generated by this code generator is specific to the BasicLifeCycleControllerMixin class (in fact the generated pre and post code blocks are a partially inlined version of the incrementFcInvocationCounter and decrementFcInvocationCounter methods of this class): it can not work if the lifecycle controller of the component, either merged or not with other controllers, does not include this mixin, or an equivalent (i.e. with a fcInvocationCounter field, and with the corresponding increment and decrement methods).


Field Summary
 
Fields inherited from interface org.objectweb.asm.Constants
AALOAD, AASTORE, ACC_ABSTRACT, 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
 
Fields inherited from interface org.objectweb.fractal.julia.asm.CodeGenerator
IN, IN_OUT, OUT
 
Constructor Summary
LifeCycleCodeGenerator()
           
 
Method Summary
 void generateCloneCode(CodeVisitor cv)
          Generates the cloning code for this code generator.
 void generateInitCode(CodeVisitor cv)
          Generates the initialization code for this code generator.
protected  void generateInterceptionCodeBlock(Method m, boolean pre, CodeVisitor cv, int formals)
          Generates an interception code block for the given method.
protected  int getInterceptionCodeFormals(Method m)
          Returns the number of local variables that are used by the generated interception code.
protected  int getInterceptionType(Method m)
          Returns the type of the interception code to be generated for the given method.
 int init(InterceptorClassGenerator icg)
          Initializes this code generator.
 
Methods inherited from class org.objectweb.fractal.julia.asm.AbstractCodeGenerator
close, generateInterceptionCode, intercept
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LifeCycleCodeGenerator

public LifeCycleCodeGenerator()
Method Detail

init

public int init(InterceptorClassGenerator icg)
Description copied from interface: CodeGenerator
Initializes this code generator.

Specified by:
init in interface CodeGenerator
Overrides:
init in class AbstractCodeGenerator

generateInitCode

public void generateInitCode(CodeVisitor cv)
                      throws ClassGenerationException
Description copied from interface: CodeGenerator
Generates the initialization code for this code generator. This code is added to the initFcController method by the interceptor class generator that calls this method. By hypothesis, the stack is empty at the beginning of the generated code. Moreover, the stack must also be empty at the end of the code generated by this method.

Specified by:
generateInitCode in interface CodeGenerator
Overrides:
generateInitCode in class AbstractCodeGenerator
Throws:
ClassGenerationException

getInterceptionType

protected int getInterceptionType(Method m)
Description copied from class: AbstractCodeGenerator
Returns the type of the interception code to be generated for the given method. The default implementation of this method returns NORMAL for all methods.

Overrides:
getInterceptionType in class AbstractCodeGenerator
Parameters:
m - a method object.
Returns:
EMPTY to generate only a pre code block at the beginning of the method, NORMAL to generate both a pre code block and a post code block, or FINALLY to generate a pre code block, and a post code block inside a finally block (to be sure that the post code block will always be executed).

getInterceptionCodeFormals

protected int getInterceptionCodeFormals(Method m)
Description copied from class: AbstractCodeGenerator
Returns the number of local variables that are used by the generated interception code. The default implementation of this method returns 0 for all methods.

Overrides:
getInterceptionCodeFormals in class AbstractCodeGenerator
Parameters:
m - a method object.
Returns:
the number of local variables that are used by the generated interception code.

generateCloneCode

public void generateCloneCode(CodeVisitor cv)
Description copied from interface: CodeGenerator
Generates the cloning code for this code generator. This code is added to the clone method by the interceptor class generator that calls this method. By hypothesis, the stack is empty at the beginning of the generated code. Moreover, the stack must also be empty at the end of the code generated by this method.

Specified by:
generateCloneCode in interface CodeGenerator
Overrides:
generateCloneCode in class AbstractCodeGenerator

generateInterceptionCodeBlock

protected void generateInterceptionCodeBlock(Method m,
                                             boolean pre,
                                             CodeVisitor cv,
                                             int formals)
Description copied from class: AbstractCodeGenerator
Generates an interception code block for the given method.

Specified by:
generateInterceptionCodeBlock in class AbstractCodeGenerator
Parameters:
m - the method for which the interception code must be generated.
pre - true to generate a pre code block, or false to generate a post code block.
cv - the method visitor to be used to generate the interception code.
formals - the index of the first local variable reserved for the code block. The generated code can use the local variables between indexes formals, inclusive, and formals + getInterceptionCodeFormals(m), exclusive.