|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.objectweb.fractal.julia.asm.AbstractCodeGenerator
org.objectweb.fractal.julia.asm.LifeCycleCodeGenerator
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.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 |
public LifeCycleCodeGenerator()
| Method Detail |
public int init(InterceptorClassGenerator icg)
CodeGenerator
init in interface CodeGeneratorinit in class AbstractCodeGenerator
public void generateInitCode(CodeVisitor cv)
throws ClassGenerationException
CodeGeneratorinitFcController 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.
generateInitCode in interface CodeGeneratorgenerateInitCode in class AbstractCodeGeneratorClassGenerationExceptionprotected int getInterceptionType(Method m)
AbstractCodeGeneratorNORMAL for all methods.
getInterceptionType in class AbstractCodeGeneratorm - a method object.
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).protected int getInterceptionCodeFormals(Method m)
AbstractCodeGenerator
getInterceptionCodeFormals in class AbstractCodeGeneratorm - a method object.
public void generateCloneCode(CodeVisitor cv)
CodeGeneratorclone
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.
generateCloneCode in interface CodeGeneratorgenerateCloneCode in class AbstractCodeGenerator
protected void generateInterceptionCodeBlock(Method m,
boolean pre,
CodeVisitor cv,
int formals)
AbstractCodeGenerator
generateInterceptionCodeBlock in class AbstractCodeGeneratorm - 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.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||