Commit ff4c2a94 authored by Lionel Seinturier's avatar Lionel Seinturier

Lifecycle interceptor generator for component-based interceptors reused from Juliac.

parent c47c1214
......@@ -16,7 +16,7 @@
<dependencies>
<dependency>
<groupId>org.ow2.fractal.juliac</groupId>
<artifactId>juliac-comp</artifactId>
<artifactId>juliac-ultra-comp</artifactId>
<version>${juliac.version}</version>
</dependency>
<dependency>
......
......@@ -61,7 +61,7 @@ import org.ow2.frascati.tinfi.reflect.Util;
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
*/
public class FCCompCtrlSourceCodeGenerator
extends org.objectweb.fractal.juliac.opt.comp.FCCompCtrlSourceCodeGenerator {
extends org.objectweb.fractal.juliac.opt.ultracomp.FCUltraCompCtrlSourceCodeGenerator {
@Override
protected void postInit() throws IOException {
......
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2011-2012 Inria, Univ. Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package org.ow2.frascati.tinfi.opt.comp;
import java.lang.reflect.Modifier;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.juliac.Juliac;
import org.objectweb.fractal.juliac.control.lifecycle.ExtendedLifeCycleCoordinator;
import org.objectweb.fractal.juliac.desc.MembraneDesc;
import org.objectweb.fractal.juliac.ucf.UnifiedClass;
import org.objectweb.fractal.juliac.ucf.UnifiedMethod;
import org.objectweb.fractal.juliac.visit.BlockSourceCodeVisitor;
import org.objectweb.fractal.juliac.visit.ClassSourceCodeVisitor;
/**
* This class generates the source code of lifecycle interceptors.
*
* This class has been specialized from the original Julia/Juliac version for
* the Scala version. The reason is that the original interceptor increments and
* decrements the public field fcInvocationCounter defined in the {@link
* BasicLifeCycleControllerMixin} which is part of the implementation of the
* lifecycle controller. It appears that public fields are privatized when
* compiled into bytecode by Scala and are then no longer accessible from the
* generated Java interceptor code.
*
* To solve the issue, this interceptor generates only calls to the
* incrementFcInvocationCounter() and decrementFcInvocationCounter() methods.
* The thing is that the increment and the decrement of the public field is only
* an optimization to prevent calling these methods (which do the same thing).
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 1.4.5
*/
public class LifeCycleSourceCodeGenerator
extends org.objectweb.fractal.juliac.opt.comp.LifeCycleSourceCodeGenerator {
public LifeCycleSourceCodeGenerator() {
super();
}
public LifeCycleSourceCodeGenerator(
InterfaceType it, MembraneDesc<?> membraneDesc, boolean mergeable,
Juliac jc ) {
super(it,membraneDesc,mergeable,jc);
}
@Override
public void generateFields( ClassSourceCodeVisitor cv, UnifiedClass proxycl ) {
cv.visitField(
Modifier.PRIVATE, ExtendedLifeCycleCoordinator.class.getName(),
"_lc", null );
}
@Override
public void generateMethodInitFcController( BlockSourceCodeVisitor mv, UnifiedClass proxycl ) {
mv.visitSet(
"_lc","(",ExtendedLifeCycleCoordinator.class.getName(),")",
"ic.getInterface(\"lifecycle-controller\")");
}
@Override
public void generateProxyMethodBodyBeforeCode(
BlockSourceCodeVisitor mv, UnifiedClass proxycl, UnifiedMethod proxym ) {
BlockSourceCodeVisitor sync = mv.visitSync("_lc");
sync.visitIns("_lc.incrementFcInvocationCounter()");
sync.visitEnd();
mv.visitln(" try {");
}
@Override
public void generateProxyMethodBodyFinallyCode(
BlockSourceCodeVisitor mv, UnifiedClass proxycl, UnifiedMethod proxym ) {
mv.visitln(" }");
mv.visitln(" finally {");
BlockSourceCodeVisitor sync = mv.visitSync("_lc");
sync.visitIns("_lc.decrementFcInvocationCounter()");
sync.visitEnd();
mv.visitln(" }");
}
}
......@@ -164,7 +164,7 @@
<interface.java interface="org.ow2.frascati.tinfi.api.control.SCAIntentController" />
</reference>
<implementation.java class="org.objectweb.fractal.koch.control.interceptor.InterceptorControllerImpl" />
<property name="interceptors">(org.ow2.frascati.tinfi.opt.oo.InterceptorClassGenerator org.ow2.frascati.tinfi.opt.oo.SCATinfiInterceptorSourceCodeGenerator org.ow2.frascati.tinfi.opt.comp.LifeCycleSourceCodeGenerator org.ow2.frascati.tinfi.opt.oo.SCAContentInterceptorSourceCodeGenerator org.ow2.frascati.tinfi.opt.oo.SCAIntentInterceptorSourceCodeGenerator)</property>
<property name="interceptors">(org.ow2.frascati.tinfi.opt.oo.InterceptorClassGenerator org.ow2.frascati.tinfi.opt.oo.SCATinfiInterceptorSourceCodeGenerator org.objectweb.fractal.juliac.opt.ultracomp.LifeCycleSourceCodeGenerator org.ow2.frascati.tinfi.opt.oo.SCAContentInterceptorSourceCodeGenerator org.ow2.frascati.tinfi.opt.oo.SCAIntentInterceptorSourceCodeGenerator)</property>
</component>
<component name="MC">
......
......@@ -148,7 +148,7 @@
<interface.java interface="org.ow2.frascati.tinfi.api.control.SCAIntentController" />
</reference>
<implementation.java class="org.objectweb.fractal.koch.control.interceptor.InterceptorControllerImpl" />
<property name="interceptors">(org.ow2.frascati.tinfi.opt.oo.InterceptorClassGenerator org.ow2.frascati.tinfi.opt.oo.SCATinfiInterceptorSourceCodeGenerator org.ow2.frascati.tinfi.opt.comp.LifeCycleSourceCodeGenerator org.ow2.frascati.tinfi.opt.oo.SCAContentInterceptorSourceCodeGenerator org.ow2.frascati.tinfi.opt.oo.SCAIntentInterceptorSourceCodeGenerator)</property>
<property name="interceptors">(org.ow2.frascati.tinfi.opt.oo.InterceptorClassGenerator org.ow2.frascati.tinfi.opt.oo.SCATinfiInterceptorSourceCodeGenerator org.objectweb.fractal.juliac.opt.ultracomp.LifeCycleSourceCodeGenerator org.ow2.frascati.tinfi.opt.oo.SCAContentInterceptorSourceCodeGenerator org.ow2.frascati.tinfi.opt.oo.SCAIntentInterceptorSourceCodeGenerator)</property>
</component>
<component name="MC">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment