KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > measurements > suites > CrosscutMeasurement


1 // $Id: CrosscutMeasurement.java,v 1.2 2004/05/12 17:26:53 anicoara Exp $
2
// =====================================================================
3
//
4
// (history at end)
5
//
6

7 package measurements.suites;
8
9 // used packages
10
import junit.framework.Assert;
11 import junit.framework.Test;
12 import ch.ethz.inf.util.junit.PerformanceTest;
13 import ch.ethz.inf.util.junit.PerformanceTestSuite;
14 import ch.ethz.jvmai.*;
15 import ch.ethz.prose.*;
16 import ch.ethz.prose.crosscut.*;
17 import ch.ethz.prose.filter.*;
18
19
20 /**
21  * Performance testcase for measuring a simulation of runes.
22  * <p>
23  * In this testcase,the column <code>RUNS</code> (the fifths)
24  * represents the time needed to dispatch a faked Breakpoint
25  * implementation event.
26  *
27  * @version $Revision: 1.2 $
28  * @author Andrei Popovici
29  */

30 public class CrosscutMeasurement extends PerformanceTest {
31
32   // fixture
33
{ RANGE = new int[]{10000}; }
34
35
36   public static void staticVoidMethod()
37     {
38     }
39
40   public int toBeAccessedOrModified;
41   public String JavaDoc stringToBeAccessedOrModified;
42
43   public void voidMethod()
44     {
45     }
46
47   public void voidMethodLong(String JavaDoc a, String JavaDoc b)
48     {
49     }
50
51   public static class TestAspect extends DefaultAspect
52   {
53
54     public AbstractCrosscut allGetsCrsc = new GetCut()
55       {
56     public void joinPointAction(FieldAccessJoinPoint e)
57       {}
58
59     protected void GET_ARGS()
60       {}
61
62       protected PointCutter pointCutter() { return null;}
63       };
64
65     public AbstractCrosscut allSetsCrsc = new SetCut()
66       {
67
68     public void joinPointAction(FieldModificationJoinPoint e)
69       {}
70
71       protected PointCutter pointCutter() { return null;}
72
73       protected void SET_ARGS()
74       {}
75
76       };
77
78
79
80     public AbstractCrosscut alFast = new MethodCut()
81       {
82       protected PointCutter pointCutter() { return null;}
83
84       public void METHOD_ARGS() { }
85
86       };
87
88     public AbstractCrosscut alNormalShort = new MethodCut()
89       {
90       protected PointCutter pointCutter() { return null;}
91       public void METHOD_ARGS() { }
92     };
93
94     public AbstractCrosscut wcShort = new MethodCut()
95       {
96       protected PointCutter pointCutter() { return Within.method("voidMethod");}
97
98     public void METHOD_ARGS(ANY t0) { }
99       {
100       }
101       };
102
103     public AbstractCrosscut wwLong = new MethodCut()
104       {
105
106       protected PointCutter pointCutter() { return Within.method("voidMethodLong");}
107     public void METHOD_ARGS(ANY t0, REST t1) { }
108       {
109       }
110       };
111
112     public AbstractCrosscut cwLong = new MethodCut()
113       {
114
115       protected PointCutter pointCutter(){ return Within.method("voidMethodLong");}
116     public void METHOD_ARGS(CrosscutMeasurement t0, REST t1) { }
117       {
118       }
119       };
120
121     public AbstractCrosscut ccShort = new MethodCut()
122       {
123       protected PointCutter pointCutter(){ return Within.method("voidMethod");}
124
125     public void METHOD_ARGS(CrosscutMeasurement tO) { }
126       {
127       }
128       };
129
130     public AbstractCrosscut ccStaticShort = new MethodCut()
131       {
132       protected PointCutter pointCutter(){ return Within.method("staticVoidMethod");}
133
134     public void METHOD_ARGS(CrosscutMeasurement tO) { }
135       {
136       }
137       };
138
139
140
141     public AbstractCrosscut ccLong = new MethodCut()
142       {
143       protected PointCutter pointCutter() { return Within.method("voidMethodLong");}
144     public void METHOD_ARGS(CrosscutMeasurement tO, String JavaDoc a, String JavaDoc b) { }
145       {
146       }
147       };
148
149
150
151     public AbstractCrosscut notOptimizable = new MethodCut()
152       {
153       protected PointCutter pointCutter() { return Within.method("voidMethod");}
154     public void METHOD_ARGS(CrosscutMeasurement tO, ANY a, String JavaDoc b)
155       {
156       }
157       };
158   }
159
160   public static class MeasurementExtension extends DefaultAspect
161   {
162     Object JavaDoc measuredCrosscut=null;
163     int range = 0;
164     public MeasurementExtension(Crosscut toMeasure,int r)
165       {
166     measuredCrosscut = toMeasure;
167     this.range = r;
168       }
169
170     boolean doAccess = true;
171       public AbstractCrosscut fieldsMsmt = new MySetCut();
172
173       public class MySetCut extends SetCut
174       {
175
176
177     protected void SET_ARGS()
178       {
179         System.err.println("NOT REACHABLE");
180       }
181
182
183     public void joinPointAction(FieldModificationJoinPoint fmo)
184       {
185         try
186           {
187         Crosscut mC = (Crosscut)measuredCrosscut;
188         PerformanceTest.startChronometer();
189         for(int i = 0; i < range; i++)
190           {
191             mC.joinPointReached(fmo);
192           }
193         PerformanceTest.stopChronometer();
194           }
195         catch (Exception JavaDoc e)
196           {
197         throw new RuntimeException JavaDoc(e.toString());
198           }
199       }
200
201
202     public void joinPointAction(FieldAccessJoinPoint fac)
203       {
204
205         try
206           {
207         Crosscut mC = (Crosscut)measuredCrosscut;
208         PerformanceTest.startChronometer();
209         for(int i = 0; i < range; i++)
210           {
211             mC.joinPointReached(fac);
212           }
213         PerformanceTest.stopChronometer();
214           }
215         catch (Exception JavaDoc e)
216           {
217         throw new RuntimeException JavaDoc(e.toString());
218           }
219       }
220
221
222       PointCutter theSpec = null;
223       public void setSpecializer(PointCutter cs)
224       {
225           theSpec = cs;
226       }
227
228       protected PointCutter pointCutter()
229       {
230           if (theSpec == null)
231           return (Fields.named("nevergonnabeafieldwiththisname"));
232           else
233           return theSpec;
234       }
235
236       };
237
238       public AbstractCrosscut c1 = new MyMethodCut();
239       public class MyMethodCut extends MethodCut
240       {
241     public void METHOD_ARGS()
242       {
243         try
244           {
245         PerformanceTest.startChronometer();
246         Crosscut mC = (Crosscut)measuredCrosscut;
247         MethodEntryJoinPoint mejp = (MethodEntryJoinPoint)thisJoinPoint();
248         for(int i = 0; i < range; i++)
249           {
250             mC.joinPointReached(mejp);
251           }
252         PerformanceTest.stopChronometer();
253           }
254         catch (Exception JavaDoc e)
255           {
256         e.printStackTrace();
257         throw new RuntimeException JavaDoc(e.toString());
258           }
259       }
260
261       PointCutter theSpec = null;
262       public void setSpecializer(PointCutter cs)
263       {
264           theSpec = cs;
265       }
266
267       protected PointCutter pointCutter()
268       {
269           if (theSpec == null)
270           return (Within.method("Unless this specializer is exchanged, no matches"));
271           else
272           return theSpec;
273       }
274       };
275   }
276
277   final boolean useProse;
278
279   /**
280    * Construct test with given name.
281    * @param name test name
282    */

283   public CrosscutMeasurement(String JavaDoc name)
284     {
285       super(name);
286       String JavaDoc proseParam = System.getProperty("useprose");
287       if(proseParam==null)
288     useProse = isDebuggerEnabled();
289       else
290     useProse = proseParam.toUpperCase().equals("TRUE");
291
292       if (!isDebuggerEnabled())
293       {
294           RANGE=new int[] {1000000};
295       }
296     }
297
298   TestAspect testAspect;
299
300   protected void setUp() throws Exception JavaDoc
301     {
302       if(!useProse) Assert.fail("unable to test crosscuts if prose is disabled");
303       ProseSystem.startup();
304       testAspect= new TestAspect();
305       testAspect.ccShort.insertionAction(true);
306       testAspect.ccStaticShort.insertionAction(true);
307       testAspect.notOptimizable.insertionAction(true);
308       testAspect.ccLong.insertionAction(true);
309       testAspect.alFast.insertionAction(true);
310       testAspect.alNormalShort.insertionAction(true);
311       testAspect.wcShort.insertionAction(true);
312       testAspect.wwLong.insertionAction(true);
313       testAspect.cwLong.insertionAction(true);
314       testAspect.allSetsCrsc.insertionAction(true);
315       testAspect.allGetsCrsc.insertionAction(true);
316     }
317
318   protected void tearDown() throws SystemTeardownException
319     {
320       ProseSystem.teardown();
321     }
322
323   /** Test the time needed to simulate the dispatching of a
324    * join-point to a all locations listener.
325    *
326    */

327
328
329   public void testAllLocationShort()
330     {
331       MeasurementExtension me = new MeasurementExtension(testAspect.alNormalShort,RUNS);
332       ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
333                (Within.subType(CrosscutMeasurement.class)) .AND
334                (Within.method("voidMethod")));
335       ProseSystem.getAspectManager().insert(me);
336       voidMethod();
337       ProseSystem.getAspectManager().withdraw(me);
338     }
339
340   public void testAllLocationLong()
341     {
342       MeasurementExtension me = new MeasurementExtension(testAspect.alNormalShort,RUNS);
343       ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
344                (Within.subType(CrosscutMeasurement.class)) .AND
345                (Within.method("voidMethodLong")));
346       ProseSystem.getAspectManager().insert(me);
347       voidMethodLong("foo","bar");
348       ProseSystem.getAspectManager().withdraw(me);
349     }
350
351
352   public void testAllLocationFast()
353     {
354       MeasurementExtension me = new MeasurementExtension(testAspect.alFast,RUNS);
355       ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
356                (Within.subType(CrosscutMeasurement.class)) .AND
357                (Within.method("voidMethod")));
358       ProseSystem.getAspectManager().insert(me);
359       voidMethod();
360       ProseSystem.getAspectManager().withdraw(me);
361     }
362
363   public void testWildcardWildcardLong()
364     {
365       MeasurementExtension me = new MeasurementExtension(testAspect.wwLong,RUNS);
366       ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
367                (Within.subType(CrosscutMeasurement.class)) .AND
368                (Within.method("voidMethodLong")));
369       ProseSystem.getAspectManager().insert(me);
370       voidMethodLong("foo","bar");
371       ProseSystem.getAspectManager().withdraw(me);
372     }
373   public void testConcreteWildcardLong()
374     {
375       MeasurementExtension me = new MeasurementExtension(testAspect.cwLong,RUNS);
376       ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
377                (Within.subType(CrosscutMeasurement.class)) .AND
378                (Within.method("voidMethodLong")));
379       ProseSystem.getAspectManager().insert(me);
380       voidMethodLong("foo","bar");
381       ProseSystem.getAspectManager().withdraw(me);
382     }
383
384   public void testWildcardConcreteShort()
385     {
386       MeasurementExtension me = new MeasurementExtension(testAspect.wcShort,RUNS);
387       ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
388                (Within.subType(CrosscutMeasurement.class)) .AND
389                (Within.method("voidMethod")));
390       ProseSystem.getAspectManager().insert(me);
391       voidMethod();
392       ProseSystem.getAspectManager().withdraw(me);
393     }
394
395
396   public void testConcreteConcreteShort()
397     {
398       MeasurementExtension me = new MeasurementExtension(testAspect.ccShort,RUNS);
399       ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
400                (Within.subType(CrosscutMeasurement.class)) .AND
401                (Within.method("voidMethod")));
402       ProseSystem.getAspectManager().insert(me);
403       voidMethod();
404       ProseSystem.getAspectManager().withdraw(me);
405     }
406
407
408   /** Test the time needed to simulate the dispatching of a
409    * join-point to a all locations listener.
410    *
411    */

412   public void testConcreteConcreteStaticShort()
413     {
414       MeasurementExtension me = new MeasurementExtension(testAspect.ccStaticShort,RUNS);
415       ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
416                (Within.subType(CrosscutMeasurement.class)) .AND
417                (Within.method("staticVoidMethod")));
418       ProseSystem.getAspectManager().insert(me);
419       staticVoidMethod();
420       ProseSystem.getAspectManager().withdraw(me);
421     }
422
423   public void testConcreteConcreteLong()
424     {
425       MeasurementExtension me = new MeasurementExtension(testAspect.ccLong,RUNS);
426       ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
427                (Within.subType(CrosscutMeasurement.class)) .AND
428                (Within.method("voidMethodLong")));
429       ProseSystem.getAspectManager().insert(me);
430       voidMethodLong("foo","bar");
431       ProseSystem.getAspectManager().withdraw(me);
432     }
433
434
435   /** Test the time needed to simulate the dispatching of a
436    * join-point to a all locations listener.
437    *
438    */

439   public void testNotOptimized()
440     {
441       MeasurementExtension me = new MeasurementExtension(testAspect.notOptimizable,RUNS);
442       ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
443                (Within.subType(CrosscutMeasurement.class)) .AND
444                (Within.method("voidMethodLong")));
445       ProseSystem.getAspectManager().insert(me);
446       voidMethodLong("hallo","mr x");
447       ProseSystem.getAspectManager().withdraw(me);
448
449     }
450
451
452   /** Test the time needed to simulate the dispatching of a
453    * join-point to a all locations listener.
454    *
455    */

456   public void testAllFieldsAccess()
457     {
458       MeasurementExtension me = new MeasurementExtension(testAspect.allGetsCrsc,RUNS);
459       ((MeasurementExtension.MySetCut)me.fieldsMsmt).setSpecializer( (Within.subType(CrosscutMeasurement.class)) .AND
460                          (Fields.named("toBeAccessedOrModified")) );
461       me.doAccess = true;
462       ProseSystem.getAspectManager().insert(me);
463       int i = toBeAccessedOrModified;
464       ProseSystem.getAspectManager().withdraw(me);
465     }
466
467   public void testAllFieldsIntModifications()
468     {
469       MeasurementExtension me = new MeasurementExtension(testAspect.allSetsCrsc,RUNS);
470       ((MeasurementExtension.MySetCut)me.fieldsMsmt).setSpecializer( (Within.subType(CrosscutMeasurement.class)) .AND
471                          (Fields.named("toBeAccessedOrModified")) );
472       me.doAccess = false;
473       ProseSystem.getAspectManager().insert(me);
474       toBeAccessedOrModified = 3;
475       ProseSystem.getAspectManager().withdraw(me);
476     }
477
478   public void testAllFieldsStringModifications()
479     {
480       MeasurementExtension me = new MeasurementExtension(testAspect.allSetsCrsc,RUNS);
481       ((MeasurementExtension.MySetCut)me.fieldsMsmt).setSpecializer( (Within.subType(CrosscutMeasurement.class)) .AND
482                          (Fields.named("stringToBeAccessedOrModified")) );
483       me.doAccess = false;
484       ProseSystem.getAspectManager().insert(me);
485       stringToBeAccessedOrModified = "foo";
486       ProseSystem.getAspectManager().withdraw(me);
487     }
488
489   /**
490    * Test suite.
491    * @return test instance
492    */

493   public static Test suite()
494     {
495       return new PerformanceTestSuite(CrosscutMeasurement.class);
496     }
497
498 }
499
500
501 //======================================================================
502
//
503
// $Log: CrosscutMeasurement.java,v $
504
// Revision 1.2 2004/05/12 17:26:53 anicoara
505
// Adapt Junit tests to 3.8.1 version and the new package structure
506
//
507
// Revision 1.1.1.1 2003/07/02 15:30:45 apopovic
508
// Imported from ETH Zurich
509
//
510
// Revision 1.23 2003/05/05 14:03:03 popovici
511
// renaming from runes to prose
512
//
513
// Revision 1.22 2003/04/27 13:08:59 popovici
514
// Specializers renamed to PointCutter
515
//
516
// Revision 1.21 2003/04/25 15:15:16 popovici
517
// FieldS renamed to 'Fields'
518
//
519
// Revision 1.20 2003/04/17 15:14:53 popovici
520
// Extension->Aspect renaming
521
//
522
// Revision 1.19 2003/04/17 13:54:30 popovici
523
// Refactorization of 'ExecutionS' into 'Within' and 'Executions'.
524
// Method names refer now to 'types'
525
//
526
// Revision 1.18 2003/04/17 12:49:18 popovici
527
// Refactoring of the crosscut package
528
// ExceptionCut renamed to ThrowCut
529
// McutSignature is now SignaturePattern
530
//
531
// Revision 1.17 2003/04/17 08:46:57 popovici
532
// Important functionality additions
533
// - Cflow specializers
534
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
535
// - Transactional capabilities
536
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
537
// between static and dynamic specializers.
538
// - Functionality pulled up in abstract classes
539
// - Uniformization of advice methods patterns and names
540
//
541
// Revision 1.16 2003/03/05 08:31:25 popovici
542
// Bug fix afeer import organization
543
//
544
// Revision 1.15 2003/03/04 18:35:59 popovici
545
// Organization of imprts
546
//
547
// Revision 1.14 2003/03/04 11:26:09 popovici
548
// Important refactorization step (march):
549
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
550
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
551
// structures
552
//
553
// Revision 1.13 2002/11/26 17:15:49 pschoch
554
// RootComponent now added (replaces RootComponent now added (replaces old ProseSystem)
555
// ProseSystem now owns and starts the Aspect interface.
556
// ProseSystem now containes a 'test' AspectManager
557
// AspectManager now owns the JoinPointManager.
558
// ExtensionManger can be 'connected' to the JVM, or disconnected. The
559
// JoinPointManager of a connected Ext.Mgr enables joinpoints; the
560
// JoinPointManger of a disconnected Ext.Mgr never enables join-points
561
// Documentation updated accordingly.
562
//
563
// Revision 1.12 2002/06/06 18:53:51 popovici
564
// 1. Bug fix: methodAdvice is now public; the constructor works for all subclasses.
565
// 2. Feature change/bug fix: ADVICE_NAME is now a protected method
566
//
567
// Revision 1.11 2002/06/06 15:23:31 popovici
568
// Bug fix: fieldModificationAdvice was not renamed to setAdvice
569
//
570
// Revision 1.10 2002/06/06 14:39:50 popovici
571
// Renamings: FunctionalCrosscut->MethodCut
572
// AllFields->SetCut
573
// SetCu.fieldModiticationAdvice -> SetCut.setAdvice
574
//
575
// Revision 1.9 2002/06/06 12:01:48 popovici
576
// fieldAccessAdvice removed from AllFields; tests and usage of AllFields's
577
// ability to intercept gets moved to 'GetCut'
578
// Minor bug fixes;
579
//
580
// Revision 1.8 2002/06/05 12:03:50 popovici
581
// thisJoinPoint() updated everywhere. The 'fieldModificationAdvice is now parameterless'; older implemnentations now
582
// use 'thisJoinPoint()'
583
//
584
// Revision 1.7 2002/06/04 12:36:10 popovici
585
// AllLocations occurences replaced with FunctionalCrosscut
586
//
587
// Revision 1.6 2002/06/03 13:01:56 popovici
588
// getAdviceMethod() removed from the abstract
589
// crosscuts.
590
//
591
// Revision 1.5 2002/05/22 11:00:33 popovici
592
// ClasseS replaced with DeclarationS
593
//
594
// Revision 1.4 2002/03/12 09:50:14 popovici
595
// Initial version of the Benchmark measurements
596
//
597
// Revision 1.3 2002/03/06 13:48:51 popovici
598
// joinPointAction now in 4 flavours, depending on the join point type
599
//
600
// Revision 1.2 2002/02/28 17:34:44 smarkwal
601
// field useProse and error-message in setUp added.
602
//
603
// Revision 1.1 2002/02/21 12:57:15 popovici
604
// CrosscutMeasurements replaces AllLocatgionsMeasurement and is more comprehensive
605
//
606
Popular Tags