Mail Archive Home | gotm-commits List | August 2005 Index
| <-- Date Index --> | <-- Thread Index --> |
Date: Friday, August 5, 2005 @ 17:06:26
Author: rouvoy
Path: /cvsroot/gotm/fractal-pool
Added:
src/java/org/objectweb/fractal/julia/asm/MergeCacheClassGenerator.java
Modified: .classpath src/cfg/cache.cfg
fractal-import:
* Updating Fractal & Julia jars.
fractal-pool:
* Adding support for merge optimization with the Cache controller.
gotm:
* Adding HOWL Logging support,
* Implementing 2PC, 2PCPC & 2PCPA commit protocols,
* Adding various configuration of the Event Engine,
* Adding support for configurable current manager.
gotm-jts:
* Improving JTS implementation,
* Adding JTS JUnit tests as example,
* Adding Benchmarks (JTS, 2PC, Adaptive PC) as example.
------------------------------------------------------------------------+
.classpath |
2
src/cfg/cache.cfg |
168 ++++
src/java/org/objectweb/fractal/julia/asm/MergeCacheClassGenerator.java |
363 ++++++++++
3 files changed, 528 insertions(+), 5 deletions(-)
Index: fractal-pool/.classpath
diff -u fractal-pool/.classpath:1.4 fractal-pool/.classpath:1.5
--- fractal-pool/.classpath:1.4 Wed Mar 2 16:25:15 2005
+++ fractal-pool/.classpath Fri Aug 5 17:06:26 2005
@@ -12,5 +12,7 @@
<classpathentry kind="lib"
path="/fractal-import/lib/utils/ow_util_trace.jar"/>
<classpathentry kind="lib"
path="/fractal-import/lib/julia/julia-mixins.jar"/>
<classpathentry kind="lib"
path="/fractal-import/lib/julia/julia-runtime.jar"/>
+ <classpathentry kind="lib"
path="/fractal-import/lib/julia/julia-asm.jar"/>
+ <classpathentry kind="lib" path="/fractal-import/lib/asm/asm.jar"/>
<classpathentry kind="output" path="output/eclipse"/>
</classpath>
Index: fractal-pool/src/cfg/cache.cfg
diff -u fractal-pool/src/cfg/cache.cfg:1.2 fractal-pool/src/cfg/cache.cfg:1.3
--- fractal-pool/src/cfg/cache.cfg:1.2 Mon Mar 14 13:42:22 2005
+++ fractal-pool/src/cfg/cache.cfg Fri Aug 5 17:06:26 2005
@@ -23,7 +23,7 @@
# Contributor(s): .
#
-----------------------------------------------------------------------------
-# $Id: cache.cfg,v 1.2 2005/03/14 12:42:22 rouvoy Exp $
+# $Id: cache.cfg,v 1.3 2005/08/05 15:06:26 rouvoy Exp $
#
=============================================================================
@@ -134,6 +134,32 @@
#
-----------------------------------------------------------------------------
# Component implementation
+(bootstrap
+ (
+ 'interface-class-generator
+ (
+ 'component-itf
+ 'type-factory-itf
+ 'generic-factory-itf
+ (loader org.objectweb.fractal.julia.loader.Loader)
+ )
+ (
+ 'component-impl
+ 'type-factory-impl
+ 'generic-factory-impl
+ # choose one of the following classes:
+ # the first one loads all classes from the classpath
+ # the second one can generate missing classes on the fly, dynamically
+ # org.objectweb.fractal.julia.loader.BasicLoader
+ org.objectweb.fractal.julia.loader.DynamicLoader
+ )
+ (
+ # no interceptors
+ )
+ org.objectweb.fractal.julia.asm.MergeCacheClassGenerator
+ none
+ )
+)
(primitive
(
@@ -165,11 +191,15 @@
org.objectweb.fractal.julia.asm.LifeCycleCodeGenerator
)
)
- org.objectweb.fractal.julia.asm.MergeClassGenerator
+ org.objectweb.fractal.julia.asm.MergeCacheClassGenerator
'optimizationLevel
)
)
+(parametricPrimitive
+ 'primitive
+)
+
(composite
(
'interface-class-generator
@@ -200,7 +230,7 @@
(
# no interceptors
)
- org.objectweb.fractal.julia.asm.MergeClassGenerator
+ org.objectweb.fractal.julia.asm.MergeCacheClassGenerator
'optimizationLevel
)
)
@@ -238,7 +268,135 @@
(
# no interceptors
)
- org.objectweb.fractal.julia.asm.MergeClassGenerator
+ org.objectweb.fractal.julia.asm.MergeCacheClassGenerator
+ 'optimizationLevel
+ )
+)
+
+(primitiveTemplate
+ (
+ 'interface-class-generator
+ (
+ 'component-itf
+ 'binding-controller-itf
+ 'super-controller-itf
+ # only if super-controller-itf does not designate the Julia interface:
+ # 'julia-super-controller-itf
+ 'name-controller-itf
+ 'factory-itf
+ # only if factory-itf does not designate the Julia interface:
+ # 'julia-factory-itf
+ )
+ (
+ 'component-impl
+ 'primitive-binding-controller-impl
+ 'super-controller-impl
+ 'name-controller-impl
+ 'factory-impl
+ )
+ (
+ # no interceptors
+ )
+ org.objectweb.fractal.julia.asm.MergeCacheClassGenerator
+ 'optimizationLevel
+ )
+)
+
+(parametricPrimitiveTemplate
+ (
+ 'interface-class-generator
+ (
+ 'component-itf
+ 'julia-attribute-controller-itf
+ 'binding-controller-itf
+ 'super-controller-itf
+ # only if super-controller-itf does not designate the Julia interface:
+ # 'julia-super-controller-itf
+ 'name-controller-itf
+ 'factory-itf
+ # only if factory-itf does not designate the Julia interface:
+ # 'julia-factory-itf
+ )
+ (
+ 'component-impl
+ ((org.objectweb.fractal.julia.asm.AttributeControllerClassGenerator
+ ('attributeControllerInterface)
+ ))
+ 'primitive-binding-controller-impl
+ 'super-controller-impl
+ 'name-controller-impl
+ 'factory-impl
+ )
+ (
+ # no interceptors
+ )
+ org.objectweb.fractal.julia.asm.MergeCacheClassGenerator
+ 'optimizationLevel
+ )
+)
+
+(compositeTemplate
+ (
+ 'interface-class-generator
+ (
+ 'component-itf
+ 'binding-controller-itf
+ 'content-controller-itf
+ 'super-controller-itf
+ # only if super-controller-itf does not designate the Julia interface:
+ # 'julia-super-controller-itf
+ 'name-controller-itf
+ 'factory-itf
+ # only if factory-itf does not designate the Julia interface:
+ # 'julia-factory-itf
+ )
+ (
+ 'component-impl
+ 'composite-binding-controller-impl
+ 'content-controller-impl
+ 'super-controller-impl
+ 'name-controller-impl
+ 'factory-impl
+ )
+ (
+ # no interceptors
+ )
+ org.objectweb.fractal.julia.asm.MergeCacheClassGenerator
+ 'optimizationLevel
+ )
+)
+
+(parametricCompositeTemplate
+ (
+ 'interface-class-generator
+ (
+ 'component-itf
+ 'julia-attribute-controller-itf
+ 'binding-controller-itf
+ 'content-controller-itf
+ 'super-controller-itf
+ # only if super-controller-itf does not designate the Julia interface:
+ # 'julia-super-controller-itf
+ 'name-controller-itf
+ 'factory-itf
+ # only if factory-itf does not designate the Julia interface:
+ # 'julia-factory-itf
+ )
+ (
+ 'component-impl
+ ((org.objectweb.fractal.julia.asm.AttributeControllerClassGenerator
+ ('attributeControllerInterface)
+ ))
+ 'composite-binding-controller-impl
+ 'content-controller-impl
+ 'super-controller-impl
+ 'name-controller-impl
+ 'factory-impl
+ )
+ (
+ # no interceptors
+ )
+ org.objectweb.fractal.julia.asm.MergeCacheClassGenerator
'optimizationLevel
)
)
@@ -311,7 +469,7 @@
org.objectweb.fractal.julia.asm.LifeCycleCodeGenerator
)
)
- org.objectweb.fractal.julia.asm.MergeClassGenerator
+ org.objectweb.fractal.julia.asm.MergeCacheClassGenerator
'optimizationLevel
)
)
\ No newline at end of file
Index:
fractal-pool/src/java/org/objectweb/fractal/julia/asm/MergeCacheClassGenerator.java
diff -u /dev/null
fractal-pool/src/java/org/objectweb/fractal/julia/asm/MergeCacheClassGenerator.java:1.1
--- /dev/null Fri Aug 5 17:06:26 2005
+++
fractal-pool/src/java/org/objectweb/fractal/julia/asm/MergeCacheClassGenerator.java
Fri Aug 5 17:06:26 2005
@@ -0,0 +1,363 @@
+/*====================================================================
+
+ GoTM: GoTM is an open Transaction Monitor
+ Copyright (C) 2003-2005 INRIA - Jacquard & USTL - LIFL - GOAL
+ Contact: gotm-team@xxxxxxxxxxxxx
+
+ 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.1 of the License, or 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
+
+ Initial developer(s): Romain Rouvoy.
+ Contributor(s): .
+
+ ---------------------------------------------------------------------
+ $Id: MergeCacheClassGenerator.java,v 1.1 2005/08/05 15:06:26 rouvoy Exp $
+ ====================================================================*/
+package org.objectweb.fractal.julia.asm;
+
+import org.objectweb.fractal.api.control.BindingController;
+import org.objectweb.fractal.api.control.CacheController;
+import org.objectweb.fractal.api.control.LifeCycleController;
+
+import org.objectweb.fractal.julia.control.binding.ContentBindingController;
+import org.objectweb.fractal.julia.control.cache.ContentCacheController;
+import
org.objectweb.fractal.julia.control.lifecycle.ContentLifeCycleController;
+import org.objectweb.fractal.julia.loader.Generated;
+import org.objectweb.fractal.julia.loader.Loader;
+import org.objectweb.fractal.julia.loader.Tree;
+import org.objectweb.fractal.julia.loader.Initializable;
+
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.CodeVisitor;
+import org.objectweb.asm.Type;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+/**
+ * A class generator to merge several classes into a single one. This class
+ * generator copies all the non static fields and all the non static methods
of
+ * the given classes (and of their super class, super super class, and so on)
+ * into a new class, with the following exceptions:
+ * <ul>
+ * <li>fields whose name begins with "weaveable" are replaced by
<tt>this</tt>.
+ * One of the merged classes must implement the corresponding interface,
+ * otherwise an exception is thrown.</li>
+ * <li>fields whose name begins with "weaveableOpt" are replaced by
+ * <tt>this</tt> if the corresponding interface is implemented by one of the
+ * merged classes, or by <tt>null</tt> otherwise.</li>
+ * <li>the method of the {@link org.objectweb.fractal.julia.Controller}
+ * interface are merged into a single method.</li>
+ * </ul>
+ * <b>Notes</b>:
+ * <ul>
+ * <li>since static fields and methods are not copied, and since the
generated
+ * class will generally not be in the same package than the original classes,
+ * all the static fields and methods used by the non static methods must be
+ * public (but those that are used only by static methods may be
private).</li>
+ * <li>the constructors are not copied (this limitation will perhaps be
removed
+ * in future versions).</li>
+ * </ul>
+ * Except for the "weaveable" fields, and for the {@link
+ * org.objectweb.fractal.julia.Controller} method, the fields and methods of
the
+ * classes to be merged should all be distinct: otherwise the generated class
+ * will not be valid, because of duplicated field or method declarations.
+ * <p>
+ * As an example, the merging of the B and C classes below:
+ *
+ * <pre>
+ *
+ * public class A {
+ * public int a;
+ * public void m () { ... }
+ * }
+ *
+ * public class B extends A implements I {
+ * private int b;
+ * private J weaveableJ;
+ * private K weaveableOptK;
+ * public void m () { super.m(); ... }
+ * public void n () { weaveableJ.o(weaveableOptK); }
+ * }
+ *
+ * public class C implement J {
+ * public void o (K k) { p(); }
+ * public static p () { q(); }
+ * private static q () { ... }
+ * }
+ *
+ * </pre>
+ *
+ * is the following class:
+ *
+ * <pre>
+ *
+ * public class <i>XYZ</i> implements I, J, Generated {
+ * public int a; // copied from B's super class
+ * private int b; // copied from B
+ * // weaveableJ // NOT copied
+ * // weaveableOptK // NOT copied
+ * private void m$0 () { ... } // copied from B's super class
+ * public void m () { m$0(); ... } // copied from B
+ * public void n () { <b>o(null);</b> } // copied from B
+ * public void o (K k) { <b>C.</b>p(); } // copied from C
+ * // p // NOT copied (static)
+ * // q // NOT copied (static)
+ * public String getFcGeneratorParameters () {
+ * return "(...MergeClassGenerator java.lang.Object B C)";
+ * }
+ * }
+ *
+ * </pre>
+ *
+ * @author <a href="mailto:Romain.Rouvoy@xxxxxxx">Romain Rouvoy</a>
+ * @created 20 juil. 2005
+ * @modified $Date: 2005/08/05 15:06:26 $
+ * @version $Revision: 1.1 $
+ */
+public class MergeCacheClassGenerator
+ extends MergeClassGenerator {
+ /**
+ * Generates a class by merging the given classes.
+ *
+ * @param name
+ * the name of the class to be generated.
+ * @param args
+ * a tree of the form "(objectDescriptor superClassName
+ * className1 ... classNameN)", where className1 ...
classNameN
+ * are the names of the classes to be merged, and
superClassName
+ * is the name of the super class to be used for the merged
+ * class.
+ * @param loader1
+ * the loader to be used to load or generate auxiliary
classes,
+ * if needed.
+ * @param classLoader1
+ * the class loader to be used to load auxiliary classes, if
+ * needed.
+ * @return a class constructed by merging the given classes.
+ * @throws ClassGenerationException
+ * if a problem occurs during the generation of the class.
+ */
+ public byte[] generateClass(final String name, final Tree args,
+ final Loader loader1, final ClassLoader classLoader1)
+ throws ClassGenerationException {
+ this.loader = loader1;
+ this.classLoader = classLoader1;
+ String superClassName = args.getSubTree(1).toString().replace('.',
'/');
+ mergedClassName = name.replace('.', '/');
+
+ Class[] classes = new Class[args.getSize() - 2];
+ interfaces = new ArrayList();
+ interfaces.add(Generated.class);
+ interfaces.add(Initializable.class);
+ for (int i = 0; i < classes.length; ++i) {
+ try {
+ classes[i] = loader1.loadClass(args.getSubTree(i + 2),
+ classLoader1);
+ } catch (ClassNotFoundException e) {
+ throw new ClassGenerationException(e, args.toString(),
+ "Cannot load the '" + args.getSubTree(i + 2)
+ + "' class");
+ }
+ Class c = classes[i];
+ while (c != Object.class) {
+ Class[] citfs = c.getInterfaces();
+ for (int j = 0; j < citfs.length; ++j) {
+ if (!interfaces.contains(citfs[j])) {
+ interfaces.add(citfs[j]);
+ }
+ }
+ c = c.getSuperclass();
+ }
+ }
+ // adds the ContentLifeCycleController interface if the super class
+ // implements LifeCycleController (see ContentLifeCycleController);
+ // likewise for ContentBindingController
+ Class superClass;
+ try {
+ superClass = loader1.loadClass(args.getSubTree(1), classLoader1);
+ } catch (ClassNotFoundException e) {
+ throw new ClassGenerationException(e, args.toString(),
+ "Cannot load the '" + args.getSubTree(1) + "' class");
+ }
+ if (LifeCycleController.class.isAssignableFrom(superClass)) {
+ interfaces.add(ContentLifeCycleController.class);
+ }
+ if (CacheController.class.isAssignableFrom(superClass)) {
+ interfaces.add(ContentCacheController.class);
+ }
+ if (BindingController.class.isAssignableFrom(superClass)) {
+ interfaces.add(ContentBindingController.class);
+ }
+
+ // creates an empty class
+ ClassWriter cw = new ClassWriter(false);
+ String[] itfs = new String[interfaces.size()];
+ for (int i = 0; i < itfs.length; ++i) {
+ itfs[i] = Type.getInternalName((Class) interfaces.get(i));
+ }
+ cw.visit(V1_1, ACC_PUBLIC, mergedClassName, superClassName, itfs,
+ "MERGED");
+
+ // generates the default constructor
+ CodeVisitor mw = cw
+ .visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mw.visitVarInsn(ALOAD, 0);
+ mw.visitMethodInsn(INVOKESPECIAL, superClassName, "<init>", "()V");
+ mw.visitInsn(RETURN);
+ mw.visitMaxs(1, 1);
+
+ // generates the 'getFcGeneratorParameters' method
+ parameters = args.toString();
+ String mName = "getFcGeneratorParameters";
+ String mDesc = "()Ljava/lang/String;";
+ CodeVisitor mv = cw.visitMethod(ACC_PUBLIC, mName, mDesc, null,
null);
+ mv.visitLdcInsn(parameters);
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(1, 1);
+
+ // generates the 'initialize' method
+ inicv = cw.visitMethod(ACC_PUBLIC, "initialize",
+ "(Lorg/objectweb/fractal/julia/loader/Tree;)V", null, null);
+
+ // generates the 'initFcController' method
+ icv = cw.visitMethod(ACC_PUBLIC, "initFcController",
+ "(Lorg/objectweb/fractal/julia/InitializationContext;)V",
null,
+ null);
+
+ // merges all the classes
+ for (int i = 0; i < classes.length; ++i) {
+ inheritedClasses = new ArrayList();
+ counters = new HashMap();
+
+ Class c = classes[i];
+ while (c != Object.class) {
+ inheritedClasses.add(Type.getInternalName(c));
+ c = c.getSuperclass();
+ }
+
+ c = classes[i];
+ while (c != Object.class) {
+ currentClass = c;
+ currentClassIndex = i;
+ currentClassName = Type.getInternalName(c);
+ MergeClassAdapter mca = new MergeClassAdapter(cw);
+ try {
+ getClassReader(c).accept(mca, false);
+ } catch (IOException e) {
+ throw new ClassGenerationException(e, args.toString(),
+ "Cannot read the '" + c.getName() + "' class");
+ } catch (VisitException e) {
+ throw e.getException();
+ }
+ updateCounters(c);
+ c = c.getSuperclass();
+ }
+ }
+
+ inicv.visitInsn(RETURN);
+ inicv.visitMaxs(3, 2);
+
+ icv.visitInsn(RETURN);
+ icv.visitMaxs(2, 2);
+
+ // generates the ContentLifeCycleController interface if the super
class
+ // implements LifeCycleController (see ContentLifeCycleController)
+ if (LifeCycleController.class.isAssignableFrom(superClass)) {
+ // generates the 'startFcContent' method
+ mName = "startFcContent";
+ mv = cw.visitMethod(ACC_PUBLIC, mName, "()V", null, null);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, superClassName, "startFc",
"()V");
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(1, 1);
+ // generates the 'stopFcContent' method
+ mName = "stopFcContent";
+ mv = cw.visitMethod(ACC_PUBLIC, mName, "()V", null, null);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, superClassName, "stopFc",
"()V");
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(1, 1);
+ }
+
+ // generates the ContentCacheController interface if the super class
+ // implements CacheController (see ContentCacheController)
+ if (CacheController.class.isAssignableFrom(superClass)) {
+ // generates the 'initFcContent' method
+ mName = "initFcContent";
+ mv = cw.visitMethod(ACC_PUBLIC, mName, "()V", null, null);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, superClassName, "initFc",
"()V");
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(1, 1);
+ // generates the 'clearFcContent' method
+ mName = "clearFcContent";
+ mv = cw.visitMethod(ACC_PUBLIC, mName, "()V", null, null);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, superClassName, "clearFc",
"()V");
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(1, 1);
+ }
+
+ // generates the ContentBindingController interface if the super
class
+ // implements BindingController (see ContentBindingController)
+ if (BindingController.class.isAssignableFrom(superClass)) {
+ // generates the 'listFcContent' method
+ mName = "listFcContent";
+ mv = cw.visitMethod(ACC_PUBLIC, mName, "()[Ljava/lang/String;",
+ null, null);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, superClassName, "listFc",
+ "()[Ljava/lang/String;");
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(1, 1);
+ // generates the 'lookupFcContent' method
+ mName = "lookupFcContent";
+ mv = cw.visitMethod(ACC_PUBLIC, mName,
+ "(Ljava/lang/String;)Ljava/lang/Object;", null, null);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitMethodInsn(INVOKESPECIAL, superClassName, "lookupFc",
+ "(Ljava/lang/String;)Ljava/lang/Object;");
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(2, 2);
+ // generates the 'bindFcContent' method
+ mName = "bindFcContent";
+ mv = cw.visitMethod(ACC_PUBLIC, mName,
+ "(Ljava/lang/String;Ljava/lang/Object;)V", null, null);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitVarInsn(ALOAD, 2);
+ mv.visitMethodInsn(INVOKESPECIAL, superClassName, "bindFc",
+ "(Ljava/lang/String;Ljava/lang/Object;)V");
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(3, 3);
+ // generates the 'unbindFcContent' method
+ mName = "unbindFcContent";
+ mv = cw.visitMethod(ACC_PUBLIC, mName, "(Ljava/lang/String;)V",
+ null, null);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitMethodInsn(INVOKESPECIAL, superClassName, "unbindFc",
+ "(Ljava/lang/String;)V");
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(2, 2);
+ }
+
+ // returns the merged class
+ return cw.toByteArray();
+ }
+}
\ No newline at end of file
| <-- Date Index --> | <-- Thread Index --> |
Powered by MHonArc.
Copyright © 2006-2007, OW2 Consortium | contact | webmaster.