Commit bff318a9 authored by Lionel Seinturier's avatar Lionel Seinturier

Moving the InvocationCounterItf to juliac-runtime.

Include in juliac-core the lifecycle source code generator that invokes methods from this interface instead of accessing the corresponding field of the lifecycle controller (needed by Scala implemented membranes and the COMP mode of Tinfi.)
parent 4dac3c82
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2012-2015 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.julia.Interceptor;
import org.objectweb.fractal.juliac.Juliac;
import org.objectweb.fractal.juliac.control.lifecycle.InvocationCounterItf;
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;
/**
* <p>
* This class generates the source code of lifecycle interceptors.
* </p>
*
* <p>
* This class specializes the original Juliac lifecycle interceptor generator by
* always invoking the <code>incrementFcInvocationCounter()</code> and
* <code>decrementFcInvocationCounter()</code> methods instead of accessing
* directly the <code>fcInvocationCounter</code> field. This is needed, not only
* when interceptors are componentized, but also for object interceptors that
* access controllers implemented in Scala. In this last case, it appears that
* public fields are privatized when compiled into bytecode by Scala and are
* then no longer accessible from the generated Java object interceptor.
* </p>
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 1.4.5
*/
public class LifeCycleSourceCodeGenerator
extends org.objectweb.fractal.juliac.proxy.LifeCycleSourceCodeGenerator {
public LifeCycleSourceCodeGenerator() {
super();
}
public LifeCycleSourceCodeGenerator(
Juliac jc,
InterfaceType it, MembraneDesc<?> membraneDesc, boolean mergeable ) {
super(jc,it,membraneDesc,mergeable);
}
@Override
public void generateFields( ClassSourceCodeVisitor cv, UnifiedClass proxycl ) {
cv.visitField(
Modifier.PRIVATE, InvocationCounterItf.class.getName(),
"_lc", null );
}
@Override
public void generateMethodInitFcController( BlockSourceCodeVisitor mv, UnifiedClass proxycl ) {
if( ! mergeable ) {
mv.visitVar("Object","olc","ic.getInterface(\"lifecycle-controller\")");
BlockSourceCodeVisitor then = mv.visitIf("!(","olc","instanceof",InvocationCounterItf.class.getName(),")");
BlockSourceCodeVisitor wdo = then.visitWhile("olc","instanceof",Interceptor.class.getName());
wdo.visitSet("olc", "(("+Interceptor.class.getName()+")olc).getFcItfDelegate()").visitEnd();
then.visitEnd();
// Record the reference to the instance implementing the controller
mv.visitSet("_lc","("+InvocationCounterItf.class.getName()+")","olc");
}
}
@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.proxy.LifeCycleNFASourceCodeGenerator 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.proxy.LifeCycleNFASourceCodeGenerator 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