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