KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > measurements > suites > JoinPointMeasurements2_rejitOverhead2


1 package measurements.suites;
2
3 import junit.framework.Assert;
4 import junit.framework.Test;
5 import ch.ethz.prose.DefaultAspect;
6 import ch.ethz.prose.Aspect;
7 import ch.ethz.prose.ProseSystem;
8 import ch.ethz.prose.crosscut.Crosscut;
9 import ch.ethz.prose.crosscut.MethodCut;
10 import ch.ethz.prose.crosscut.MethodRedefineCut;
11 import ch.ethz.prose.crosscut.GetCut;
12 import ch.ethz.prose.crosscut.SetCut;
13 import ch.ethz.prose.filter.Fields;
14 import ch.ethz.prose.filter.PointCutter;
15 import ch.ethz.prose.filter.Executions;
16 import ch.ethz.prose.filter.Within;
17 import ch.ethz.inf.util.junit.PerformanceTest;
18 import ch.ethz.inf.util.junit.PerformanceTestSuite;
19 //import ch.ethz.prose.jikesrvm.JikesRVMPerformanceTest;
20

21
22 /**
23  * JoinPoint measurements
24  *
25  * Performance tests to calculate the relative rejit overhead
26  * after the aspect has been inserted.
27  *
28  * @version $Revision: 1.1 $
29  * @author Angela Nicoara
30  */

31 public class JoinPointMeasurements2_rejitOverhead2 extends PerformanceTest {
32 //public class JoinPointMeasurements2_rejitOverhead2 extends JikesRVMPerformanceTest {
33

34     public int x;
35     public int y = 10;
36     public int z;
37     public int field = 0;
38     public boolean checkAssert = true;
39
40     public void localMethod()
41     {
42         x = 1; //set the "x" field
43
//System.err.println("LocalMethod");
44
}
45
46     public void otherMethod()
47     {
48         z = y; // get the "y" field
49
//System.err.println("OtherMethod");
50
}
51
52     // METHOD ENTRY
53
public class MethodEntryAspect extends DefaultAspect
54     {
55         public Crosscut c1 = new MethodCut()
56         {
57             // execute the advice 'before' the method 'localMethod'
58
public void METHOD_ARGS(JoinPointMeasurements2_rejitOverhead2 target)
59             {
60                 //int q;
61
//q = 20;
62
target.field = 20;
63             }
64
65             // .. && calls(* localMethod())
66
protected PointCutter pointCutter()
67             {
68                     return ( (Executions.before()) . AND
69                                    (Within.method("localMethod")) . AND
70                                    (Within.type("JoinPointMeasurements2_rejitOverhead2")) );
71             }
72         };
73     }
74
75     // METHOD EXIT
76
public class MethodExitAspect extends DefaultAspect
77     {
78         public Crosscut c2 = new MethodCut()
79         {
80             // execute the advice 'after' the method 'localMethod'
81
public void METHOD_ARGS(JoinPointMeasurements2_rejitOverhead2 target)
82             {
83                 //int q;
84
//q = 30;
85
target.field = 30;
86             }
87
88             // .. && calls(* localMethod())
89
protected PointCutter pointCutter()
90             {
91                 return ( (Executions.after()) . AND
92                                (Within.method("localMethod")) . AND
93                                (Within.type("JoinPointMeasurements2_rejitOverhead2")) );
94             }
95         };
96     }
97
98     // METHOD REDEFINITION
99
public class MethodRedefineAspect extends DefaultAspect
100     {
101         public Crosscut c3 = new MethodRedefineCut()
102         {
103             // the body of new method
104
public void METHOD_ARGS(JoinPointMeasurements2_rejitOverhead2 target)
105             {
106                 //int q;
107
//q = 40;
108
target.field = 40;
109             }
110
111             protected PointCutter pointCutter()
112             {
113                 return ( (Within.method("localMethod")) .AND
114                               (Within.type("JoinPointMeasurements2_rejitOverhead2")) );
115             }
116         };
117     }
118     
119     // FIELD ACCESS
120
public class FieldAccessAspect extends DefaultAspect
121     {
122         public Crosscut c4 = new GetCut()
123         {
124             //public void GET_ARGS() //EMPTY -> equivalent with GET_ARGS(ANY,ANY)
125
public void GET_ARGS(JoinPointMeasurements2_rejitOverhead2 target, int x) //CONCRETE__CONCRETE
126
//public void GET_ARGS(ANY obj, double x) //WILDCARD__CONCRETE
127
//public void GET_ARGS(ANY obj, ANY x) //WILDCARD__WILDCARD -> equivalent with GET_ARGS()
128
{
129                 //int q;
130
//q = 50;
131
target.field = 50;
132             }
133             
134             protected PointCutter pointCutter()
135             {
136                 return ( (Fields.named("y.*")) .AND (Fields.declaredInClass("JoinPointMeasurements2_rejitOverhead2")) );
137             }
138         };
139     }
140
141     // FIELD MODIFICATION
142
public class FieldModificationAspect extends DefaultAspect
143     {
144         public Crosscut c5 = new SetCut()
145         {
146             //public void SET_ARGS() //EMPTY -> equivalent with GET_ARGS(ANY,ANY)
147
public void SET_ARGS(JoinPointMeasurements2_rejitOverhead2 target, int x) //CONCRETE__CONCRETE
148
//public void SET_ARGS(ANY obj, double x) //WILDCARD__CONCRETE
149
//public void SET_ARGS(ANY obj, ANY x) //WILDCARD__WILDCARD -> equivalent with GET_ARGS()
150
{
151                 //int q;
152
//q = 60;
153
target.field = 60;
154             }
155                 
156             protected PointCutter pointCutter()
157             {
158                 return ( Fields.named("x.*") .AND (Fields.declaredInClass("JoinPointMeasurements2_rejitOverhead2")) );
159             }
160         };
161     }
162     
163     Aspect aspect1; // METHOD ENTRY
164
Aspect aspect2; // METHOD EXIT
165
Aspect aspect3; // METHOD REDEFINITION
166
Aspect aspect4; // FIELD ACCESS
167
Aspect aspect5; // FIELD MODIFICATION
168

169     public boolean useProse = false;
170
171     /**
172      * Construct test with given name.
173      * @param name test name
174      */

175     public JoinPointMeasurements2_rejitOverhead2(String JavaDoc name)
176     {
177         super(name);
178         //RANGE = new int[] { 1 };
179
RANGE = new int[] { 100000 };
180         
181         String JavaDoc proseParam = System.getProperty("useprose");
182         if (proseParam != null) useProse = true;
183     }
184     
185     /**
186      * Set up fixture.
187      */

188     protected void setUp()
189     {
190         if (!useProse) return;
191
192         try {
193             ProseSystem.startup();
194         } catch (Exception JavaDoc e) {
195             Assert.fail("ProseSystem.startup() failed");
196         }
197         
198         aspect1 = new MethodEntryAspect();
199         aspect2 = new MethodExitAspect();
200         aspect3 = new MethodRedefineAspect();
201         aspect4 = new FieldAccessAspect();
202         aspect5 = new FieldModificationAspect();
203         
204         field = 0;
205     }
206
207     protected void tearDown()
208     {
209         if (!useProse) return;
210
211         try {
212             ProseSystem.teardown();
213         } catch (Exception JavaDoc e) {
214             Assert.fail("ProseSystem.teardown() failed");
215         }
216     }
217
218     //========= METHOD ENTRY =========
219

220     // the rejit overhead is included
221
public void test_the_rejit_overhead_for_MethodEntry_1()
222     {
223         if (useProse) ProseSystem.getAspectManager().insert(aspect1);
224         
225         startChronometer();
226         for (int i=0; i < RUNS; i++) localMethod();
227         stopChronometer();
228
229         if (useProse) ProseSystem.getAspectManager().withdraw(aspect1);
230
231         if(checkAssert) assertEquals("Hook notifications", 20, field);
232     }
233
234     // the rejit overhead isn't included
235
public void test_the_rejit_overhead_for_MethodEntry_2()
236     {
237         if (useProse) ProseSystem.getAspectManager().insert(aspect1);
238
239         startChronometer();
240         for (int i=0; i < RUNS; i++) localMethod();
241         stopChronometer();
242
243         if (useProse) ProseSystem.getAspectManager().withdraw(aspect1);
244
245         if(checkAssert) assertEquals("Hook notifications", 20, field);
246     }
247
248
249     //========= METHOD EXIT =========
250

251     // the rejit overhead is included
252
public void test_the_rejit_overhead_for_MethodExit_1()
253     {
254         if (useProse) ProseSystem.getAspectManager().insert(aspect2);
255         
256         startChronometer();
257         for (int i=0; i < RUNS; i++) localMethod();
258         stopChronometer();
259
260         if (useProse) ProseSystem.getAspectManager().withdraw(aspect2);
261
262         if(checkAssert) assertEquals("Hook notifications", 30, field);
263     }
264
265
266     // the rejit overhead isn't included
267
public void test_the_rejit_overhead_for_MethodExit_2()
268     {
269         if (useProse) ProseSystem.getAspectManager().insert(aspect2);
270
271         startChronometer();
272         for (int i=0; i < RUNS; i++) localMethod();
273         stopChronometer();
274
275         if (useProse) ProseSystem.getAspectManager().withdraw(aspect2);
276
277         if(checkAssert) assertEquals("Hook notifications", 30, field);
278     }
279
280
281     //========= METHOD REDEFINITION =========
282

283     // the rejit overhead is included
284
public void test_the_rejit_overhead_for_MethodRedefinition_1()
285     {
286         if (useProse) ProseSystem.getAspectManager().insert(aspect3);
287         
288         startChronometer();
289         for (int i=0; i < RUNS; i++) localMethod();
290         stopChronometer();
291
292         if (useProse) ProseSystem.getAspectManager().withdraw(aspect3);
293
294         if(checkAssert) assertEquals("Hook notifications", 40, field);
295     }
296
297
298     // the rejit overhead isn't included
299
public void test_the_rejit_overhead_for_MethodRedefinition_2()
300     {
301         if (useProse) ProseSystem.getAspectManager().insert(aspect3);
302         
303         startChronometer();
304         for (int i=0; i < RUNS; i++) localMethod();
305         stopChronometer();
306
307         if (useProse) ProseSystem.getAspectManager().withdraw(aspect3);
308
309         if(checkAssert) assertEquals("Hook notifications", 40, field);
310     }
311
312
313     //========= FIELD ACCESS =========
314

315     // the rejit overhead is included
316
public void test_the_rejit_overhead_for_FieldAccess_1()
317     {
318         if (useProse) ProseSystem.getAspectManager().insert(aspect4);
319         
320         startChronometer();
321         for (int i=0; i < RUNS; i++) otherMethod();
322         stopChronometer();
323
324         if (useProse) ProseSystem.getAspectManager().withdraw(aspect4);
325
326         if(checkAssert) assertEquals("Hook notifications", 50, field);
327     }
328
329
330     // the rejit overhead isn't included
331
public void test_the_rejit_overhead_for_FieldAccess_2()
332     {
333         if (useProse) ProseSystem.getAspectManager().insert(aspect4);
334         
335         startChronometer();
336         for (int i=0; i < RUNS; i++) otherMethod();
337         stopChronometer();
338
339         if (useProse) ProseSystem.getAspectManager().withdraw(aspect4);
340
341         if(checkAssert) assertEquals("Hook notifications", 50, field);
342     }
343
344
345     //========= FIELD MODIFICATION =========
346

347     // the rejit overhead is included
348
public void test_the_rejit_overhead_for_FieldModification_1()
349     {
350         if (useProse) ProseSystem.getAspectManager().insert(aspect5);
351         
352         startChronometer();
353         for (int i=0; i < RUNS; i++) localMethod();
354         stopChronometer();
355
356         if (useProse) ProseSystem.getAspectManager().withdraw(aspect5);
357
358         if(checkAssert) assertEquals("Hook notifications", 60, field);
359     }
360
361     // the rejit overhead isn't included
362
public void test_the_rejit_overhead_for_FieldModification_2()
363     {
364         if (useProse) ProseSystem.getAspectManager().insert(aspect5);
365         
366         startChronometer();
367         for (int i=0; i < RUNS; i++) localMethod();
368         stopChronometer();
369
370         if (useProse) ProseSystem.getAspectManager().withdraw(aspect5);
371
372         if(checkAssert) assertEquals("Hook notifications", 60, field);
373     }
374
375     /**
376      * Test suite.
377      * @return test instance
378      */

379     public static Test suite() {
380         return new PerformanceTestSuite(JoinPointMeasurements2_rejitOverhead2.class);
381     }
382 }
Popular Tags