// $Id: CrosscutMeasurement.java,v 1.3 2008/11/18 10:41:01 anicoara Exp $
// =====================================================================
package measurements.suites;
// used packages
import junit.framework.Assert;
import junit.framework.Test;
import ch.ethz.inf.util.junit.PerformanceTest;
import ch.ethz.inf.util.junit.PerformanceTestSuite;
import ch.ethz.jvmai.*;
import ch.ethz.prose.*;
import ch.ethz.prose.crosscut.*;
import ch.ethz.prose.filter.*;
/**
* Performance testcase for measuring a simulation of runes.
* <p>
* In this testcase,the column <code>RUNS</code> (the fifths)
* represents the time needed to dispatch a faked Breakpoint
* implementation event.
*
* @version $Revision: 1.3 $
* @author Andrei Popovici
*/
public class CrosscutMeasurement extends PerformanceTest {
// fixture
{ RANGE = new int[]{10000}; }
public static void staticVoidMethod() { }
public int toBeAccessedOrModified;
public String stringToBeAccessedOrModified;
public void voidMethod() { }
public void voidMethodLong(String a, String b) { }
public static class TestAspect extends DefaultAspect {
public AbstractCrosscut allGetsCrsc = new GetCut() {
public void joinPointAction(FieldAccessJoinPoint e) {}
protected void GET_ARGS() {}
protected PointCutter pointCutter() { return null;}
};
public AbstractCrosscut allSetsCrsc = new SetCut() {
public void joinPointAction(FieldModificationJoinPoint e) {}
protected PointCutter pointCutter() { return null;}
protected void SET_ARGS() {}
};
public AbstractCrosscut alFast = new MethodCut() {
protected PointCutter pointCutter() { return null;}
public void METHOD_ARGS() { }
};
public AbstractCrosscut alNormalShort = new MethodCut() {
protected PointCutter pointCutter() { return null;}
public void METHOD_ARGS() { }
};
public AbstractCrosscut wcShort = new MethodCut() {
protected PointCutter pointCutter() { return Within.method("voidMethod");}
public void METHOD_ARGS(ANY t0) { }
{
}
};
public AbstractCrosscut wwLong = new MethodCut() {
protected PointCutter pointCutter() { return Within.method("voidMethodLong");}
public void METHOD_ARGS(ANY t0, REST t1) { }
{
}
};
public AbstractCrosscut cwLong = new MethodCut() {
protected PointCutter pointCutter(){ return Within.method("voidMethodLong");}
public void METHOD_ARGS(CrosscutMeasurement t0, REST t1) { }
{
}
};
public AbstractCrosscut ccShort = new MethodCut() {
protected PointCutter pointCutter(){ return Within.method("voidMethod");}
public void METHOD_ARGS(CrosscutMeasurement tO) { }
{
}
};
public AbstractCrosscut ccStaticShort = new MethodCut() {
protected PointCutter pointCutter(){ return Within.method("staticVoidMethod");}
public void METHOD_ARGS(CrosscutMeasurement tO) { }
{
}
};
public AbstractCrosscut ccLong = new MethodCut() {
protected PointCutter pointCutter() { return Within.method("voidMethodLong");}
public void METHOD_ARGS(CrosscutMeasurement tO, String a, String b) { }
{
}
};
public AbstractCrosscut notOptimizable = new MethodCut() {
protected PointCutter pointCutter() { return Within.method("voidMethod");}
public void METHOD_ARGS(CrosscutMeasurement tO, ANY a, String b)
{
}
};
}
public static class MeasurementExtension extends DefaultAspect {
Object measuredCrosscut=null;
int range = 0;
public MeasurementExtension(Crosscut toMeasure,int r) {
measuredCrosscut = toMeasure;
this.range = r;
}
boolean doAccess = true;
public AbstractCrosscut fieldsMsmt = new MySetCut();
public class MySetCut extends SetCut {
protected void SET_ARGS() {
System.err.println("NOT REACHABLE");
}
public void joinPointAction(FieldModificationJoinPoint fmo) {
try {
Crosscut mC = (Crosscut)measuredCrosscut;
PerformanceTest.startChronometer();
for(int i = 0; i < range; i++) {
mC.joinPointReached(fmo);
}
PerformanceTest.stopChronometer();
}
catch (Exception e) {
throw new RuntimeException(e.toString());
}
}
public void joinPointAction(FieldAccessJoinPoint fac) {
try {
Crosscut mC = (Crosscut)measuredCrosscut;
PerformanceTest.startChronometer();
for(int i = 0; i < range; i++) {
mC.joinPointReached(fac);
}
PerformanceTest.stopChronometer();
}
catch (Exception e) {
throw new RuntimeException(e.toString());
}
}
PointCutter theSpec = null;
public void setSpecializer(PointCutter cs) {
theSpec = cs;
}
protected PointCutter pointCutter() {
if (theSpec == null)
return (Fields.named("nevergonnabeafieldwiththisname"));
else
return theSpec;
}
};
public AbstractCrosscut c1 = new MyMethodCut();
public class MyMethodCut extends MethodCut {
public void METHOD_ARGS() {
try {
PerformanceTest.startChronometer();
Crosscut mC = (Crosscut)measuredCrosscut;
MethodEntryJoinPoint mejp = (MethodEntryJoinPoint)thisJoinPoint();
for(int i = 0; i < range; i++) {
mC.joinPointReached(mejp);
}
PerformanceTest.stopChronometer();
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.toString());
}
}
PointCutter theSpec = null;
public void setSpecializer(PointCutter cs) {
theSpec = cs;
}
protected PointCutter pointCutter() {
if (theSpec == null)
return (Within.method("Unless this specializer is exchanged, no matches"));
else
return theSpec;
}
};
}
final boolean useProse;
/**
* Construct test with given name.
* @param name test name
*/
public CrosscutMeasurement(String name) {
super(name);
String proseParam = System.getProperty("useprose");
if(proseParam==null)
useProse = isDebuggerEnabled();
else
useProse = proseParam.toUpperCase().equals("TRUE");
if (!isDebuggerEnabled()) {
RANGE=new int[] {1000000};
}
}
TestAspect testAspect;
protected void setUp() throws Exception {
if(!useProse) Assert.fail("unable to test crosscuts if prose is disabled");
ProseSystem.startup();
testAspect= new TestAspect();
testAspect.ccShort.insertionAction(true);
testAspect.ccStaticShort.insertionAction(true);
testAspect.notOptimizable.insertionAction(true);
testAspect.ccLong.insertionAction(true);
testAspect.alFast.insertionAction(true);
testAspect.alNormalShort.insertionAction(true);
testAspect.wcShort.insertionAction(true);
testAspect.wwLong.insertionAction(true);
testAspect.cwLong.insertionAction(true);
testAspect.allSetsCrsc.insertionAction(true);
testAspect.allGetsCrsc.insertionAction(true);
}
protected void tearDown() throws SystemTeardownException {
ProseSystem.teardown();
}
/**
* Test the time needed to simulate the dispatching of a
* join-point to a all locations listener.
*/
public void testAllLocationShort() {
MeasurementExtension me = new MeasurementExtension(testAspect.alNormalShort,RUNS);
((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
(Within.subType(CrosscutMeasurement.class)) .AND
(Within.method("voidMethod")));
ProseSystem.getAspectManager().insert(me);
voidMethod();
ProseSystem.getAspectManager().withdraw(me);
}
public void testAllLocationLong() {
MeasurementExtension me = new MeasurementExtension(testAspect.alNormalShort,RUNS);
((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
(Within.subType(CrosscutMeasurement.class)) .AND
(Within.method("voidMethodLong")));
ProseSystem.getAspectManager().insert(me);
voidMethodLong("foo","bar");
ProseSystem.getAspectManager().withdraw(me);
}
public void testAllLocationFast() {
MeasurementExtension me = new MeasurementExtension(testAspect.alFast,RUNS);
((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
(Within.subType(CrosscutMeasurement.class)) .AND
(Within.method("voidMethod")));
ProseSystem.getAspectManager().insert(me);
voidMethod();
ProseSystem.getAspectManager().withdraw(me);
}
public void testWildcardWildcardLong() {
MeasurementExtension me = new MeasurementExtension(testAspect.wwLong,RUNS);
((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
(Within.subType(CrosscutMeasurement.class)) .AND
(Within.method("voidMethodLong")));
ProseSystem.getAspectManager().insert(me);
voidMethodLong("foo","bar");
ProseSystem.getAspectManager().withdraw(me);
}
public void testConcreteWildcardLong() {
MeasurementExtension me = new MeasurementExtension(testAspect.cwLong,RUNS);
((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
(Within.subType(CrosscutMeasurement.class)) .AND
(Within.method("voidMethodLong")));
ProseSystem.getAspectManager().insert(me);
voidMethodLong("foo","bar");
ProseSystem.getAspectManager().withdraw(me);
}
public void testWildcardConcreteShort() {
MeasurementExtension me = new MeasurementExtension(testAspect.wcShort,RUNS);
((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
(Within.subType(CrosscutMeasurement.class)) .AND
(Within.method("voidMethod")));
ProseSystem.getAspectManager().insert(me);
voidMethod();
ProseSystem.getAspectManager().withdraw(me);
}
public void testConcreteConcreteShort() {
MeasurementExtension me = new MeasurementExtension(testAspect.ccShort,RUNS);
((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
(Within.subType(CrosscutMeasurement.class)) .AND
(Within.method("voidMethod")));
ProseSystem.getAspectManager().insert(me);
voidMethod();
ProseSystem.getAspectManager().withdraw(me);
}
/**
* Test the time needed to simulate the dispatching of a
* join-point to a all locations listener.
*/
public void testConcreteConcreteStaticShort() {
MeasurementExtension me = new MeasurementExtension(testAspect.ccStaticShort,RUNS);
((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
(Within.subType(CrosscutMeasurement.class)) .AND
(Within.method("staticVoidMethod")));
ProseSystem.getAspectManager().insert(me);
staticVoidMethod();
ProseSystem.getAspectManager().withdraw(me);
}
public void testConcreteConcreteLong() {
MeasurementExtension me = new MeasurementExtension(testAspect.ccLong,RUNS);
((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
(Within.subType(CrosscutMeasurement.class)) .AND
(Within.method("voidMethodLong")));
ProseSystem.getAspectManager().insert(me);
voidMethodLong("foo","bar");
ProseSystem.getAspectManager().withdraw(me);
}
/**
* Test the time needed to simulate the dispatching of a
* join-point to a all locations listener.
*/
public void testNotOptimized() {
MeasurementExtension me = new MeasurementExtension(testAspect.notOptimizable,RUNS);
((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
(Within.subType(CrosscutMeasurement.class)) .AND
(Within.method("voidMethodLong")));
ProseSystem.getAspectManager().insert(me);
voidMethodLong("hallo","mr x");
ProseSystem.getAspectManager().withdraw(me);
}
/**
* Test the time needed to simulate the dispatching of a
* join-point to a all locations listener.
*/
public void testAllFieldsAccess() {
MeasurementExtension me = new MeasurementExtension(testAspect.allGetsCrsc,RUNS);
((MeasurementExtension.MySetCut)me.fieldsMsmt).setSpecializer( (Within.subType(CrosscutMeasurement.class)) .AND
(Fields.named("toBeAccessedOrModified")) );
me.doAccess = true;
ProseSystem.getAspectManager().insert(me);
int i = toBeAccessedOrModified;
ProseSystem.getAspectManager().withdraw(me);
}
public void testAllFieldsIntModifications() {
MeasurementExtension me = new MeasurementExtension(testAspect.allSetsCrsc,RUNS);
((MeasurementExtension.MySetCut)me.fieldsMsmt).setSpecializer( (Within.subType(CrosscutMeasurement.class)) .AND
(Fields.named("toBeAccessedOrModified")) );
me.doAccess = false;
ProseSystem.getAspectManager().insert(me);
toBeAccessedOrModified = 3;
ProseSystem.getAspectManager().withdraw(me);
}
public void testAllFieldsStringModifications() {
MeasurementExtension me = new MeasurementExtension(testAspect.allSetsCrsc,RUNS);
((MeasurementExtension.MySetCut)me.fieldsMsmt).setSpecializer( (Within.subType(CrosscutMeasurement.class)) .AND
(Fields.named("stringToBeAccessedOrModified")) );
me.doAccess = false;
ProseSystem.getAspectManager().insert(me);
stringToBeAccessedOrModified = "foo";
ProseSystem.getAspectManager().withdraw(me);
}
/**
* Test suite.
* @return test instance
*/
public static Test suite() {
return new PerformanceTestSuite(CrosscutMeasurement.class);
}
}