Commit ca5af82e authored by Lionel Seinturier's avatar Lionel Seinturier
Browse files

Tagging version 2.2.6.1.

parent f891260d
/***
* Fractal Hello World Example
* Copyright (C) 2001-2002 France Telecom R&D
*
* 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: Eric.Bruneton@rd.francetelecom.com
* Contact: Lionel.Seinturier@lifl.fr
*
* Author: Eric Bruneton
* Author: Lionel Seinturier
*/
package hw.kvm;
import org.objectweb.fractal.aokell.AOKell;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.factory.GenericFactory;
import org.objectweb.fractal.api.type.ComponentType;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.api.type.TypeFactory;
import org.objectweb.fractal.util.Fractal;
public class Main {
public static void main(String[] args) {
/*
* Contrary to the jvm, the kvm does not by default displays the stack
* trace when the main method throws an exception.
*/
try
{
mmain(args);
}
catch (Throwable t)
{
t.printStackTrace();
}
}
public static void mmain(String[] args) throws Exception {
// ----------------------------------------------------------
// Get the bootstrap component and factories
// ----------------------------------------------------------
// Component boot = Fractal.getBootstrapComponent();
Component boot = new AOKell().newFcInstance();
TypeFactory tf = Fractal.getTypeFactory(boot);
GenericFactory cf = Fractal.getGenericFactory(boot);
// ----------------------------------------------------------
// Create the component types
// ----------------------------------------------------------
ComponentType rType = tf.createFcType(new InterfaceType[] {
tf.createFcItfType(
"m",
"java.lang.Runnable",
false, // server interface
false, // mandatory
false) // singleton
});
ComponentType cType = tf.createFcType(new InterfaceType[] {
tf.createFcItfType("m", "java.lang.Runnable", false, false, false),
tf.createFcItfType("s", Service.class.getName(), true, false, false)
});
ComponentType sType = tf.createFcType(new InterfaceType[] {
tf.createFcItfType("s", Service.class.getName(), false, false, false),
tf.createFcItfType(
"attribute-controller",
ServiceAttributes.class.getName(),
false,
false,
false)
});
// ----------------------------------------------------------
// Instantiate and initialize the components
// ----------------------------------------------------------
Component rComp = cf.newFcInstance(
rType,
"composite",
null);
Component cComp = cf.newFcInstance(cType, "primitive", ClientImpl.class.getName());
Component sComp = cf.newFcInstance(sType, "parametricPrimitive", ServerImpl.class.getName());
ServiceAttributes sa = (ServiceAttributes)
Fractal.getAttributeController(sComp);
sa.setHeader("->");
sa.setCount(1);
// ----------------------------------------------------------
// Set component names
// ----------------------------------------------------------
Fractal.getNameController(rComp).setFcName("root");
Fractal.getNameController(cComp).setFcName("client");
Fractal.getNameController(sComp).setFcName("server");
// ----------------------------------------------------------
// Add the Client and Server components in the Root composite
// ----------------------------------------------------------
Fractal.getContentController(rComp).addFcSubComponent(cComp);
Fractal.getContentController(rComp).addFcSubComponent(sComp);
// ----------------------------------------------------------
// Create bindings
// ----------------------------------------------------------
Fractal.getBindingController(rComp).bindFc("m", cComp.getFcInterface("m"));
Fractal.getBindingController(cComp).bindFc("s", sComp.getFcInterface("s"));
// ----------------------------------------------------------
// Start the Root component
// ----------------------------------------------------------
Fractal.getLifeCycleController(rComp).startFc();
// ----------------------------------------------------------
// Call the entry point of the application
// ----------------------------------------------------------
Runnable mainItf = (Runnable)rComp.getFcInterface("m");
mainItf.run();
}
}
/***
* Fractal Hello World Example
* Copyright (C) 2001-2002 France Telecom R&D
*
* 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: Eric.Bruneton@rd.francetelecom.com
* Contact: Lionel.Seinturier@lifl.fr
*
* Author: Eric Bruneton
* Author: Lionel Seinturier
*/
package hw.kvm;
public class ServerImpl implements Service, ServiceAttributes {
private String header;
private int count;
public ServerImpl () {
System.err.println("SERVER created");
}
public void print (final String msg) {
System.err.println("Server: begin printing...");
for (int i = 0; i < count; ++i) {
System.err.println(header + msg);
}
System.err.println("Server: print done.");
}
public String getHeader () {
return header;
}
public void setHeader (final String header) {
this.header = header;
}
public int getCount () {
return count;
}
public void setCount (final int count) {
this.count = count;
}
}
/***
* Fractal Hello World Example
* Copyright (C) 2001-2002 France Telecom R&D
*
* 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: Eric.Bruneton@rd.francetelecom.com
* Contact: Lionel.Seinturier@lifl.fr
*
* Author: Eric Bruneton
* Author: Lionel Seinturier
*/
package hw.kvm;
public interface Service {
void print (String msg);
}
/***
* Fractal Hello World Example
* Copyright (C) 2001-2002 France Telecom R&D
*
* 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: Eric.Bruneton@rd.francetelecom.com
* Contact: Lionel.Seinturier@lifl.fr
*
* Author: Eric Bruneton
* Author: Lionel Seinturier
*/
package hw.kvm;
import org.objectweb.fractal.api.control.AttributeController;
public interface ServiceAttributes extends AttributeController {
String getHeader ();
void setHeader (String header);
int getCount ();
void setCount (int count);
}
This example implements a benchmark suite to measure the cost of
programming components with AOKell.
To execute the example type:
ant execute
The available Ant targets are:
compile: compile the example
execute: execute the example
help: display this help message
clean: clean the generated files
When run, the example creates the following components
architecture:
- 1 root composite component
- 2 primitive components included in the root composite
|--------------------------------------|
| |
| |--------| |--------| |
|-|-|--->|-| Client |-|--->|-| Server | |
| |--------| |--------| |
| |
|--------------------------------------|
The server component exports an interface with 8 different methods,
each of them being trivial but non empty to bypass VM
optimizations.
The bench consists in calling the 8 methods of the server 1,000,000
times. The bench is performed 4 times in a warmup phase, and then
measures are taken on 5 different executions of the bench. The
result is the average (in milliseconds) of these last 5 executions.
A typical run of the program should return something like:
BENCH CREATED
Warming up ....
Starting bench
0: 741ms; 1: 751ms; 2: 751ms; 3: 751ms; 4: 742ms; average=747ms
# JVM arguments
run.jvm.parameters -Dfractal.provider=org.objectweb.fractal.aokell.AOKell
# Java class to be launched
run.classname benchmain.Main
# Application arguments
run.parameters
# Java interfaces used as Fractal interfaces
# This property is only needed when compile-time generation of Fractal
# interfaces is used (fcinterface set to ct)
fcinterface.ct.parameters java.lang.Runnable bench.BenchInterface
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE definition PUBLIC "-//objectweb.org//DTD Fractal ADL 2.0//EN" "classpath://org/objectweb/fractal/adl/xml/basic.dtd">
<!--
* JACBenchmark
* Copyright (C) 2002 AOPSYS
*
* 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: laurent@aopsys.com
* Contact: Nicolas.Pessemier@lifl.fr
*
* Author: Laurent Martelli
* Author: Nicolas Pessemier
-->
<definition name="bench.Bench">
<interface name="r" role="server" signature="java.lang.Runnable"/>
<component name="client">
<interface name="r" role="server" signature="java.lang.Runnable"/>
<interface name="bench" role="client" signature="bench.BenchInterface"/>
<content class="bench.ClientImpl"/>
<controller desc="primitive"/>
</component>
<component name="bench">
<interface name="bench" role="server" signature="bench.BenchInterface"/>
<content class="bench.Bench"/>
</component>
<binding client="this.r" server="client.r"/>
<binding client="client.bench" server="bench.bench"/>
</definition>
/***
* JACBenchmark
* Copyright (C) 2002 AOPSYS
*
* 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: laurent@aopsys.com
* Contact: Nicolas.Pessemier@lifl.fr
*
* Author: Laurent Martelli
* Author: Nicolas Pessemier
*/
package bench;
public class Bench implements BenchInterface {
public Bench() {
System.out.println("BENCH CREATED");
}
public void m1() {
// System.out.println("m1");
int i = 0;
}
public void m2(Integer a) {
int i = 0;
}
public void m3(Integer a, Integer b) {
int i = 0;
}
public Integer m4() {
return new Integer(0);
}
public Integer m5(Integer a) {
return new Integer(0);
}
public Integer m6(Integer a, Integer b) {
return new Integer(0);
}
public void m7(Object a) {
return;
}
public void m8(Object a, Object b) {
return;
}
}
\ No newline at end of file
/***
* JACBenchmark
* Copyright (C) 2002 AOPSYS
*
* 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: laurent@aopsys.com
* Contact: Nicolas.Pessemier@lifl.fr
*
* Author: Laurent Martelli
* Author: Nicolas Pessemier
*/
package bench;
/**
* @author Nicolas Pessemier <Nicolas.Pessemier@lifl.fr>
*/
public interface BenchInterface {
public void m1();
public void m2(Integer a);
public void m3(Integer a, Integer b);
public Integer m4();
public Integer m5(Integer a);
public Integer m6(Integer a, Integer b);
public void m7(Object a);
public void m8(Object a, Object b);
}
\ No newline at end of file
/***
* JACBenchmark
* Copyright (C) 2002 AOPSYS
*
* 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: laurent@aopsys.com
* Contact: Nicolas.Pessemier@lifl.fr
*
* Author: Laurent Martelli
* Author: Nicolas Pessemier
*/
package bench;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.BindingController;
/**
* @author Nicolas Pessemier <Nicolas.Pessemier@lifl.fr>
*/
public class ClientImpl implements Runnable {
private BenchInterface b;
boolean rCalls;
private int n;
String s;
// from Main interface
public void run() {
this.n = 1000000;
this.rCalls=false;
try {
b = (BenchInterface) ((BindingController) this).lookupFc("bench");
}
catch( NoSuchInterfaceException nsie ) {
throw new RuntimeException(nsie.getMessage());
}
// Let the VM optimize
System.out.print("Warming up ");
doBench(); System.out.print(".");
doBench(); System.out.print(".");
doBench(); System.out.print(".");
doBench(); System.out.println(".");
//Thread.currentThread().sleep(5000);
System.out.println("Starting bench");
long total = 0;
int num_runs = 5;
for (int i=0; i<num_runs; i++) {
long start = System.currentTimeMillis();
doBench();
long end = System.currentTimeMillis();
System.out.print(i+": "+(end-start)+"ms; ");
total += end-start;
}
System.out.println(" average="+(total/num_runs)+"ms; ");
}
void doBench() {
sbench1();
sbench2();
sbench3();
sbench4();
sbench5();
sbench6();
sbench7();
sbench8();
}
void sbench1() {
for(int i=0; i<n; i++) {
b.m1();
}
}
void sbench2() {
//System.out.print("bench 2: ");
for(int i=0; i<n; i++) {
b.m2(new Integer(0));
}
}
void sbench3() {
for(int i=0; i<n; i++) {
b.m3(new Integer(0),new Integer(0));
}
}
void sbench4() {
for(int i=0; i<n; i++) {
b.m4();