Source code: measurements/suites/CrosscutMeasurement.java
1 // $Id: CrosscutMeasurement.java,v 1.1.1.1 2003/07/02 15:30:45 apopovic 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.jvmai.FieldAccessJoinPoint;
13 import ch.ethz.jvmai.FieldModificationJoinPoint;
14 import ch.ethz.jvmai.JoinPoint;
15 import ch.ethz.jvmai.MethodEntryJoinPoint;
16 import ch.ethz.prose.DefaultAspect;
17 import ch.ethz.prose.ProseSystem;
18 import ch.ethz.prose.SystemTeardownException;
19 import ch.ethz.prose.crosscut.ANY;
20 import ch.ethz.prose.crosscut.AbstractCrosscut;
21 import ch.ethz.prose.crosscut.Crosscut;
22 import ch.ethz.prose.crosscut.GetCut;
23 import ch.ethz.prose.crosscut.MethodCut;
24 import ch.ethz.prose.crosscut.REST;
25 import ch.ethz.prose.crosscut.SetCut;
26 import ch.ethz.prose.crosscut.MissingInformationException;
27 import ch.ethz.prose.filter.Executions;
28 import ch.ethz.prose.filter.Fields;
29 import ch.ethz.prose.filter.Within;
30 import ch.ethz.prose.filter.PointCutter;
31 import ch.ethz.inf.util.junit.PerformanceTest;
32 import ch.ethz.inf.util.junit.PerformanceTestSuite;
33 import ch.ethz.prose.filter.Within;
34
35
36 /**
37 * Performance testcase for measuring a simulation of runes.
38 * <p>
39 * In this testcase,the column <code>RUNS</code> (the fifths)
40 * represents the time needed to dispatch a faked Breakpoint
41 * implementation event.
42 *
43 * @version $Revision: 1.1.1.1 $
44 * @author Andrei Popovici
45 */
46 public class CrosscutMeasurement extends PerformanceTest {
47
48 // fixture
49 { RANGE = new int[]{10000}; }
50
51
52 public static void staticVoidMethod()
53 {
54 }
55
56 public int toBeAccessedOrModified;
57 public String stringToBeAccessedOrModified;
58
59 public void voidMethod()
60 {
61 }
62
63 public void voidMethodLong(String a, String b)
64 {
65 }
66
67 public static class TestAspect extends DefaultAspect
68 {
69
70 public AbstractCrosscut allGetsCrsc = new GetCut()
71 {
72 public void joinPointAction(FieldAccessJoinPoint e)
73 {}
74
75 protected void GET_ARGS()
76 {}
77
78 protected PointCutter pointCutter() { return null;}
79 };
80
81 public AbstractCrosscut allSetsCrsc = new SetCut()
82 {
83
84 public void joinPointAction(FieldModificationJoinPoint e)
85 {}
86
87 protected PointCutter pointCutter() { return null;}
88
89 protected void SET_ARGS()
90 {}
91
92 };
93
94
95
96 public AbstractCrosscut alFast = new MethodCut()
97 {
98 protected PointCutter pointCutter() { return null;}
99
100 public void METHOD_ARGS() { }
101
102 };
103
104 public AbstractCrosscut alNormalShort = new MethodCut()
105 {
106 protected PointCutter pointCutter() { return null;}
107 public void METHOD_ARGS() { }
108 };
109
110 public AbstractCrosscut wcShort = new MethodCut()
111 {
112 protected PointCutter pointCutter() { return Within.method("voidMethod");}
113
114 public void METHOD_ARGS(ANY t0) { }
115 {
116 }
117 };
118
119 public AbstractCrosscut wwLong = new MethodCut()
120 {
121
122 protected PointCutter pointCutter() { return Within.method("voidMethodLong");}
123 public void METHOD_ARGS(ANY t0, REST t1) { }
124 {
125 }
126 };
127
128 public AbstractCrosscut cwLong = new MethodCut()
129 {
130
131 protected PointCutter pointCutter(){ return Within.method("voidMethodLong");}
132 public void METHOD_ARGS(CrosscutMeasurement t0, REST t1) { }
133 {
134 }
135 };
136
137 public AbstractCrosscut ccShort = new MethodCut()
138 {
139 protected PointCutter pointCutter(){ return Within.method("voidMethod");}
140
141 public void METHOD_ARGS(CrosscutMeasurement tO) { }
142 {
143 }
144 };
145
146 public AbstractCrosscut ccStaticShort = new MethodCut()
147 {
148 protected PointCutter pointCutter(){ return Within.method("staticVoidMethod");}
149
150 public void METHOD_ARGS(CrosscutMeasurement tO) { }
151 {
152 }
153 };
154
155
156
157 public AbstractCrosscut ccLong = new MethodCut()
158 {
159 protected PointCutter pointCutter() { return Within.method("voidMethodLong");}
160 public void METHOD_ARGS(CrosscutMeasurement tO, String a, String b) { }
161 {
162 }
163 };
164
165
166
167 public AbstractCrosscut notOptimizable = new MethodCut()
168 {
169 protected PointCutter pointCutter() { return Within.method("voidMethod");}
170 public void METHOD_ARGS(CrosscutMeasurement tO, ANY a, String b)
171 {
172 }
173 };
174 }
175
176 public static class MeasurementExtension extends DefaultAspect
177 {
178 Object measuredCrosscut=null;
179 int range = 0;
180 public MeasurementExtension(Crosscut toMeasure,int r)
181 {
182 measuredCrosscut = toMeasure;
183 this.range = r;
184 }
185
186 boolean doAccess = true;
187 public AbstractCrosscut fieldsMsmt = new MySetCut();
188
189 public class MySetCut extends SetCut
190 {
191
192
193 protected void SET_ARGS()
194 {
195 System.err.println("NOT REACHABLE");
196 }
197
198
199 public void joinPointAction(FieldModificationJoinPoint fmo)
200 {
201 try
202 {
203 Crosscut mC = (Crosscut)measuredCrosscut;
204 PerformanceTest.startChronometer();
205 for(int i = 0; i < range; i++)
206 {
207 mC.joinPointReached(fmo);
208 }
209 PerformanceTest.stopChronometer();
210 }
211 catch (Exception e)
212 {
213 throw new RuntimeException(e.toString());
214 }
215 }
216
217
218 public void joinPointAction(FieldAccessJoinPoint fac)
219 {
220
221 try
222 {
223 Crosscut mC = (Crosscut)measuredCrosscut;
224 PerformanceTest.startChronometer();
225 for(int i = 0; i < range; i++)
226 {
227 mC.joinPointReached(fac);
228 }
229 PerformanceTest.stopChronometer();
230 }
231 catch (Exception e)
232 {
233 throw new RuntimeException(e.toString());
234 }
235 }
236
237
238 PointCutter theSpec = null;
239 public void setSpecializer(PointCutter cs)
240 {
241 theSpec = cs;
242 }
243
244 protected PointCutter pointCutter()
245 {
246 if (theSpec == null)
247 return (Fields.named("nevergonnabeafieldwiththisname"));
248 else
249 return theSpec;
250 }
251
252 };
253
254 public AbstractCrosscut c1 = new MyMethodCut();
255 public class MyMethodCut extends MethodCut
256 {
257 public void METHOD_ARGS()
258 {
259 try
260 {
261 PerformanceTest.startChronometer();
262 Crosscut mC = (Crosscut)measuredCrosscut;
263 MethodEntryJoinPoint mejp = (MethodEntryJoinPoint)thisJoinPoint();
264 for(int i = 0; i < range; i++)
265 {
266 mC.joinPointReached(mejp);
267 }
268 PerformanceTest.stopChronometer();
269 }
270 catch (Exception e)
271 {
272 e.printStackTrace();
273 throw new RuntimeException(e.toString());
274 }
275 }
276
277 PointCutter theSpec = null;
278 public void setSpecializer(PointCutter cs)
279 {
280 theSpec = cs;
281 }
282
283 protected PointCutter pointCutter()
284 {
285 if (theSpec == null)
286 return (Within.method("Unless this specializer is exchanged, no matches"));
287 else
288 return theSpec;
289 }
290 };
291 }
292
293 final boolean useProse;
294
295 /**
296 * Construct test with given name.
297 * @param name test name
298 */
299 public CrosscutMeasurement(String name)
300 {
301 super(name);
302 String proseParam = System.getProperty("useprose");
303 if(proseParam==null)
304 useProse = isDebuggerEnabled();
305 else
306 useProse = proseParam.toUpperCase().equals("TRUE");
307
308 if (!isDebuggerEnabled())
309 {
310 RANGE=new int[] {1000000};
311 }
312 }
313
314 TestAspect testAspect;
315
316 protected void setUp() throws Exception
317 {
318 if(!useProse) Assert.fail("unable to test crosscuts if prose is disabled");
319 ProseSystem.startup();
320 testAspect= new TestAspect();
321 testAspect.ccShort.insertionAction(true);
322 testAspect.ccStaticShort.insertionAction(true);
323 testAspect.notOptimizable.insertionAction(true);
324 testAspect.ccLong.insertionAction(true);
325 testAspect.alFast.insertionAction(true);
326 testAspect.alNormalShort.insertionAction(true);
327 testAspect.wcShort.insertionAction(true);
328 testAspect.wwLong.insertionAction(true);
329 testAspect.cwLong.insertionAction(true);
330 testAspect.allSetsCrsc.insertionAction(true);
331 testAspect.allGetsCrsc.insertionAction(true);
332 }
333
334 protected void tearDown() throws SystemTeardownException
335 {
336 ProseSystem.teardown();
337 }
338
339 /** Test the time needed to simulate the dispatching of a
340 * join-point to a all locations listener.
341 *
342 */
343
344
345 public void testAllLocationShort()
346 {
347 MeasurementExtension me = new MeasurementExtension(testAspect.alNormalShort,RUNS);
348 ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
349 (Within.subType(CrosscutMeasurement.class)) .AND
350 (Within.method("voidMethod")));
351 ProseSystem.getAspectManager().insert(me);
352 voidMethod();
353 ProseSystem.getAspectManager().withdraw(me);
354 }
355
356 public void testAllLocationLong()
357 {
358 MeasurementExtension me = new MeasurementExtension(testAspect.alNormalShort,RUNS);
359 ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
360 (Within.subType(CrosscutMeasurement.class)) .AND
361 (Within.method("voidMethodLong")));
362 ProseSystem.getAspectManager().insert(me);
363 voidMethodLong("foo","bar");
364 ProseSystem.getAspectManager().withdraw(me);
365 }
366
367
368 public void testAllLocationFast()
369 {
370 MeasurementExtension me = new MeasurementExtension(testAspect.alFast,RUNS);
371 ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
372 (Within.subType(CrosscutMeasurement.class)) .AND
373 (Within.method("voidMethod")));
374 ProseSystem.getAspectManager().insert(me);
375 voidMethod();
376 ProseSystem.getAspectManager().withdraw(me);
377 }
378
379 public void testWildcardWildcardLong()
380 {
381 MeasurementExtension me = new MeasurementExtension(testAspect.wwLong,RUNS);
382 ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
383 (Within.subType(CrosscutMeasurement.class)) .AND
384 (Within.method("voidMethodLong")));
385 ProseSystem.getAspectManager().insert(me);
386 voidMethodLong("foo","bar");
387 ProseSystem.getAspectManager().withdraw(me);
388 }
389 public void testConcreteWildcardLong()
390 {
391 MeasurementExtension me = new MeasurementExtension(testAspect.cwLong,RUNS);
392 ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
393 (Within.subType(CrosscutMeasurement.class)) .AND
394 (Within.method("voidMethodLong")));
395 ProseSystem.getAspectManager().insert(me);
396 voidMethodLong("foo","bar");
397 ProseSystem.getAspectManager().withdraw(me);
398 }
399
400 public void testWildcardConcreteShort()
401 {
402 MeasurementExtension me = new MeasurementExtension(testAspect.wcShort,RUNS);
403 ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
404 (Within.subType(CrosscutMeasurement.class)) .AND
405 (Within.method("voidMethod")));
406 ProseSystem.getAspectManager().insert(me);
407 voidMethod();
408 ProseSystem.getAspectManager().withdraw(me);
409 }
410
411
412 public void testConcreteConcreteShort()
413 {
414 MeasurementExtension me = new MeasurementExtension(testAspect.ccShort,RUNS);
415 ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
416 (Within.subType(CrosscutMeasurement.class)) .AND
417 (Within.method("voidMethod")));
418 ProseSystem.getAspectManager().insert(me);
419 voidMethod();
420 ProseSystem.getAspectManager().withdraw(me);
421 }
422
423
424 /** Test the time needed to simulate the dispatching of a
425 * join-point to a all locations listener.
426 *
427 */
428 public void testConcreteConcreteStaticShort()
429 {
430 MeasurementExtension me = new MeasurementExtension(testAspect.ccStaticShort,RUNS);
431 ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
432 (Within.subType(CrosscutMeasurement.class)) .AND
433 (Within.method("staticVoidMethod")));
434 ProseSystem.getAspectManager().insert(me);
435 staticVoidMethod();
436 ProseSystem.getAspectManager().withdraw(me);
437 }
438
439 public void testConcreteConcreteLong()
440 {
441 MeasurementExtension me = new MeasurementExtension(testAspect.ccLong,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("foo","bar");
447 ProseSystem.getAspectManager().withdraw(me);
448 }
449
450
451 /** Test the time needed to simulate the dispatching of a
452 * join-point to a all locations listener.
453 *
454 */
455 public void testNotOptimized()
456 {
457 MeasurementExtension me = new MeasurementExtension(testAspect.notOptimizable,RUNS);
458 ((MeasurementExtension.MyMethodCut)me.c1).setSpecializer((Executions.before()) .AND
459 (Within.subType(CrosscutMeasurement.class)) .AND
460 (Within.method("voidMethodLong")));
461 ProseSystem.getAspectManager().insert(me);
462 voidMethodLong("hallo","mr x");
463 ProseSystem.getAspectManager().withdraw(me);
464
465 }
466
467
468 /** Test the time needed to simulate the dispatching of a
469 * join-point to a all locations listener.
470 *
471 */
472 public void testAllFieldsAccess()
473 {
474 MeasurementExtension me = new MeasurementExtension(testAspect.allGetsCrsc,RUNS);
475 ((MeasurementExtension.MySetCut)me.fieldsMsmt).setSpecializer( (Within.subType(CrosscutMeasurement.class)) .AND
476 (Fields.named("toBeAccessedOrModified")) );
477 me.doAccess = true;
478 ProseSystem.getAspectManager().insert(me);
479 int i = toBeAccessedOrModified;
480 ProseSystem.getAspectManager().withdraw(me);
481 }
482
483 public void testAllFieldsIntModifications()
484 {
485 MeasurementExtension me = new MeasurementExtension(testAspect.allSetsCrsc,RUNS);
486 ((MeasurementExtension.MySetCut)me.fieldsMsmt).setSpecializer( (Within.subType(CrosscutMeasurement.class)) .AND
487 (Fields.named("toBeAccessedOrModified")) );
488 me.doAccess = false;
489 ProseSystem.getAspectManager().insert(me);
490 toBeAccessedOrModified = 3;
491 ProseSystem.getAspectManager().withdraw(me);
492 }
493
494 public void testAllFieldsStringModifications()
495 {
496 MeasurementExtension me = new MeasurementExtension(testAspect.allSetsCrsc,RUNS);
497 ((MeasurementExtension.MySetCut)me.fieldsMsmt).setSpecializer( (Within.subType(CrosscutMeasurement.class)) .AND
498 (Fields.named("stringToBeAccessedOrModified")) );
499 me.doAccess = false;
500 ProseSystem.getAspectManager().insert(me);
501 stringToBeAccessedOrModified = "foo";
502 ProseSystem.getAspectManager().withdraw(me);
503 }
504
505 /**
506 * Test suite.
507 * @return test instance
508 */
509 public static Test suite()
510 {
511 return new PerformanceTestSuite(CrosscutMeasurement.class);
512 }
513
514 }
515
516
517 //======================================================================
518 //
519 // $Log: CrosscutMeasurement.java,v $
520 // Revision 1.1.1.1 2003/07/02 15:30:45 apopovic
521 // Imported from ETH Zurich
522 //
523 // Revision 1.23 2003/05/05 14:03:03 popovici
524 // renaming from runes to prose
525 //
526 // Revision 1.22 2003/04/27 13:08:59 popovici
527 // Specializers renamed to PointCutter
528 //
529 // Revision 1.21 2003/04/25 15:15:16 popovici
530 // FieldS renamed to 'Fields'
531 //
532 // Revision 1.20 2003/04/17 15:14:53 popovici
533 // Extension->Aspect renaming
534 //
535 // Revision 1.19 2003/04/17 13:54:30 popovici
536 // Refactorization of 'ExecutionS' into 'Within' and 'Executions'.
537 // Method names refer now to 'types'
538 //
539 // Revision 1.18 2003/04/17 12:49:18 popovici
540 // Refactoring of the crosscut package
541 // ExceptionCut renamed to ThrowCut
542 // McutSignature is now SignaturePattern
543 //
544 // Revision 1.17 2003/04/17 08:46:57 popovici
545 // Important functionality additions
546 // - Cflow specializers
547 // - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
548 // - Transactional capabilities
549 // - Total refactoring of Specializer evaluation, which permits fine-grained distinction
550 // between static and dynamic specializers.
551 // - Functionality pulled up in abstract classes
552 // - Uniformization of advice methods patterns and names
553 //
554 // Revision 1.16 2003/03/05 08:31:25 popovici
555 // Bug fix afeer import organization
556 //
557 // Revision 1.15 2003/03/04 18:35:59 popovici
558 // Organization of imprts
559 //
560 // Revision 1.14 2003/03/04 11:26:09 popovici
561 // Important refactorization step (march):
562 // - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
563 // - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
564 // structures
565 //
566 // Revision 1.13 2002/11/26 17:15:49 pschoch
567 // RootComponent now added (replaces RootComponent now added (replaces old ProseSystem)
568 // ProseSystem now owns and starts the Aspect interface.
569 // ProseSystem now containes a 'test' AspectManager
570 // AspectManager now owns the JoinPointManager.
571 // ExtensionManger can be 'connected' to the JVM, or disconnected. The
572 // JoinPointManager of a connected Ext.Mgr enables joinpoints; the
573 // JoinPointManger of a disconnected Ext.Mgr never enables join-points
574 // Documentation updated accordingly.
575 //
576 // Revision 1.12 2002/06/06 18:53:51 popovici
577 // 1. Bug fix: methodAdvice is now public; the constructor works for all subclasses.
578 // 2. Feature change/bug fix: ADVICE_NAME is now a protected method
579 //
580 // Revision 1.11 2002/06/06 15:23:31 popovici
581 // Bug fix: fieldModificationAdvice was not renamed to setAdvice
582 //
583 // Revision 1.10 2002/06/06 14:39:50 popovici
584 // Renamings: FunctionalCrosscut->MethodCut
585 // AllFields->SetCut
586 // SetCu.fieldModiticationAdvice -> SetCut.setAdvice
587 //
588 // Revision 1.9 2002/06/06 12:01:48 popovici
589 // fieldAccessAdvice removed from AllFields; tests and usage of AllFields's
590 // ability to intercept gets moved to 'GetCut'
591 // Minor bug fixes;
592 //
593 // Revision 1.8 2002/06/05 12:03:50 popovici
594 // thisJoinPoint() updated everywhere. The 'fieldModificationAdvice is now parameterless'; older implemnentations now
595 // use 'thisJoinPoint()'
596 //
597 // Revision 1.7 2002/06/04 12:36:10 popovici
598 // AllLocations occurences replaced with FunctionalCrosscut
599 //
600 // Revision 1.6 2002/06/03 13:01:56 popovici
601 // getAdviceMethod() removed from the abstract
602 // crosscuts.
603 //
604 // Revision 1.5 2002/05/22 11:00:33 popovici
605 // ClasseS replaced with DeclarationS
606 //
607 // Revision 1.4 2002/03/12 09:50:14 popovici
608 // Initial version of the Benchmark measurements
609 //
610 // Revision 1.3 2002/03/06 13:48:51 popovici
611 // joinPointAction now in 4 flavours, depending on the join point type
612 //
613 // Revision 1.2 2002/02/28 17:34:44 smarkwal
614 // field useProse and error-message in setUp added.
615 //
616 // Revision 1.1 2002/02/21 12:57:15 popovici
617 // CrosscutMeasurements replaces AllLocatgionsMeasurement and is more comprehensive
618 //