KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > measurements > suites > JVMAIInfoMeasurement


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

7 package measurements.suites;
8
9 import java.lang.reflect.Field JavaDoc;
10 import java.lang.reflect.Method JavaDoc;
11
12 import junit.framework.Assert;
13 import junit.framework.Test;
14 import ch.ethz.inf.util.junit.PerformanceTest;
15 import ch.ethz.inf.util.junit.PerformanceTestSuite;
16 import ch.ethz.jvmai.*;
17
18 /**
19  * Performance testcase for measuring the speed of the info-interface.
20  *
21  * @version $Revision: 1.3 $
22  * @author Andrei Popovici
23  */

24 public class JVMAIInfoMeasurement extends PerformanceTest {
25
26     // fixture
27

28
29     public int theMethodToCall(int i, long l, double d, Object JavaDoc o) { return i; }
30     public void theMethodToCall(long i){}
31     public void theMethodToCall(Object JavaDoc o){}
32     public void theMethodToCall(int i){}
33     public void theMethodToCall(double d){}
34     public void theMethodToCall(){}
35
36     public int theFieldToAccess = 0;
37
38     public static class EmptyTestHook extends JoinPointHook
39     {
40         public void onFieldAccess (FieldAccessJoinPoint joinPoint) { }
41         public void onFieldModification(FieldModificationJoinPoint joinPoint) { }
42         public void onMethodEntry (MethodEntryJoinPoint joinPoint) { }
43         public void onMethodExit (MethodExitJoinPoint joinPoint) { }
44         public void onExceptionThrow (ExceptionJoinPoint joinPoint) { }
45         public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { }
46         public void onClassLoad (Class JavaDoc cls) { }
47     }
48
49     final boolean useProse;
50
51     /**
52      * Construct test with given name.
53      * @param name test name
54      */

55     public JVMAIInfoMeasurement(String JavaDoc name)
56     {
57     super(name);
58     String JavaDoc proseParam = System.getProperty("useprose");
59     if(proseParam==null)
60         useProse = isDebuggerEnabled();
61     else
62         useProse = proseParam.toUpperCase().equals("TRUE");
63     if (isDebuggerEnabled())
64         RANGE = new int[]{ 10000};
65     else
66         RANGE = new int[]{ 1000000 };
67     }
68
69     JVMAspectInterface aspectInterface;
70
71     Method JavaDoc method,methodI,methodL,methodD,methodO,methodV;
72     Field JavaDoc field;
73     Object JavaDoc param;
74
75     protected void setUp()
76     {
77     if (!useProse) Assert.fail("unable to test info-interface if prose is disabled");
78     try {
79         String JavaDoc providerName = System.getProperty("ch.ethz.prose.JVMAIProvider");
80         Class JavaDoc providerClass = Class.forName(providerName);
81         Provider provider = (Provider)providerClass.newInstance();
82
83         aspectInterface = provider.getAspectInterface();
84
85         aspectInterface.startup(new String JavaDoc[]{"ch.ethz.prose."},true);
86
87         method = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",
88                                   new Class JavaDoc[]{Integer.TYPE,Long.TYPE,Double.TYPE,Object JavaDoc.class});
89         methodI = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class JavaDoc[]{Integer.TYPE});
90         methodL = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class JavaDoc[]{Long.TYPE});
91         methodD = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class JavaDoc[]{Double.TYPE});
92         methodO = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class JavaDoc[]{Object JavaDoc.class});
93         methodV = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class JavaDoc[]{});
94         field = JVMAIInfoMeasurement.class.getDeclaredField("theFieldToAccess");
95
96
97         param = new String JavaDoc("hello world;");
98         EmptyTestHook hook = new EmptyTestHook();
99         // call every method at least once ...
100
aspectInterface.setJoinPointHook(hook);
101         aspectInterface.setMethodEntryWatch(method,new Object JavaDoc());
102        aspectInterface.setMethodExitWatch(method,new Object JavaDoc());
103
104
105         aspectInterface.setFieldAccessWatch(field,new Object JavaDoc());
106         aspectInterface.setFieldModificationWatch(field,new Object JavaDoc());
107         this.theMethodToCall(1,1,1.0,param);
108         int n = this.theFieldToAccess;
109         this.theFieldToAccess = 1;
110         aspectInterface.clearMethodEntryWatch(method);
111         aspectInterface.clearMethodExitWatch(method);
112         aspectInterface.clearFieldAccessWatch(field);
113         aspectInterface.clearFieldModificationWatch(field);
114         aspectInterface.setJoinPointHook(null);
115         aspectInterface.suspendNotification(Thread.currentThread());
116         aspectInterface.resumeNotification(Thread.currentThread());
117
118         } catch (Exception JavaDoc e) {
119             Assert.fail("loading provider or initializing aspect-interface failed");
120         }
121     }
122
123     protected void tearDown()
124     {
125     }
126
127     public void test_06_MethodEntry()
128     {
129         aspectInterface.setMethodEntryWatch(method,new Object JavaDoc());
130         EmptyTestHook hook = new EmptyTestHook();
131         aspectInterface.setJoinPointHook(hook);
132         startChronometer();
133         for(int i =0; i<RUNS; i++)
134             this.theMethodToCall(1,1,1.0,param);
135         stopChronometer();
136         aspectInterface.clearMethodEntryWatch(method);
137         aspectInterface.setJoinPointHook(null);
138     }
139
140     public void test_13_MethodExit()
141     {
142         aspectInterface.setMethodExitWatch(method,new Object JavaDoc());
143         EmptyTestHook hook = new EmptyTestHook();
144         aspectInterface.setJoinPointHook(hook);
145         startChronometer();
146         for(int i =0; i<RUNS; i++)
147             this.theMethodToCall(1,1,1.0,param);
148         stopChronometer();
149         aspectInterface.clearMethodExitWatch(method);
150         aspectInterface.setJoinPointHook(null);
151     }
152
153     public void test_15_FieldAccess()
154     {
155         aspectInterface.setFieldAccessWatch(field,new Object JavaDoc());
156         EmptyTestHook hook = new EmptyTestHook();
157         aspectInterface.setJoinPointHook(hook);
158         int n = 0;
159         startChronometer();
160         for(int i =0; i<RUNS; i++)
161             n = this.theFieldToAccess;
162         stopChronometer();
163         aspectInterface.clearFieldAccessWatch(field);
164         aspectInterface.setJoinPointHook(null);
165     }
166
167     public void test_18_FieldModification()
168     {
169         aspectInterface.setFieldModificationWatch(field,new Object JavaDoc());
170         EmptyTestHook hook = new EmptyTestHook();
171         aspectInterface.setJoinPointHook(hook);
172         startChronometer();
173         for(int i =0; i<RUNS; i++)
174             this.theFieldToAccess = 1;
175         stopChronometer();
176         aspectInterface.clearFieldModificationWatch(field);
177         aspectInterface.setJoinPointHook(null);
178     }
179
180
181
182
183
184
185
186     // ###############################################################################
187

188     public static class LocalVariableTestHook extends JoinPointHook
189     {
190         public LocalVariableTestHook() {}
191         public void onFieldAccess (FieldAccessJoinPoint joinPoint) { }
192         public void onFieldModification(FieldModificationJoinPoint joinPoint) { }
193         public void onMethodEntry (MethodEntryJoinPoint joinPoint) {
194         joinPoint.getArgs();
195         }
196         public void onMethodExit (MethodExitJoinPoint joinPoint) { }
197         public void onExceptionThrow (ExceptionJoinPoint joinPoint) { }
198         public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { }
199         public void onClassLoad (Class JavaDoc cls) { }
200
201     }
202
203     public void test_08_GetLocalVariableValue_int()
204     {
205     aspectInterface.setMethodEntryWatch(methodI,new Object JavaDoc());
206     LocalVariableTestHook hook = new LocalVariableTestHook();
207     aspectInterface.setJoinPointHook(hook);
208     startChronometer();
209     int param =1 ;
210     for(int i =0; i<RUNS; i++)
211         this.theMethodToCall(i);
212     stopChronometer();
213     aspectInterface.clearMethodEntryWatch(methodI); aspectInterface.setJoinPointHook(null);
214     }
215
216     public void test_09_GetLocalVariableValue_long()
217     {
218     long longParam = 1;
219     aspectInterface.setMethodEntryWatch(methodL,new Object JavaDoc());
220     LocalVariableTestHook hook = new LocalVariableTestHook();
221     aspectInterface.setJoinPointHook(hook);
222     startChronometer();
223     for(int i =0; i<RUNS; i++)
224         this.theMethodToCall(longParam);
225     stopChronometer();
226     aspectInterface.clearMethodEntryWatch(methodL);
227     aspectInterface.setJoinPointHook(null);
228     }
229
230     public void test_10_GetLocalVariableValue_double()
231     {
232     double doubleParam = 12.0;
233     aspectInterface.setMethodEntryWatch(methodD,new Object JavaDoc());
234     LocalVariableTestHook hook = new LocalVariableTestHook();
235     aspectInterface.setJoinPointHook(hook);
236     startChronometer();
237     for(int i =0; i<RUNS; i++)
238         this.theMethodToCall(doubleParam);
239     stopChronometer();
240     aspectInterface.clearMethodEntryWatch(methodD);
241     aspectInterface.setJoinPointHook(null);
242     }
243
244     public void test_11_GetLocalVariableValue_Object()
245     {
246     Object JavaDoc objectParam = new Object JavaDoc();
247     aspectInterface.setMethodEntryWatch(methodO,new Object JavaDoc());
248     LocalVariableTestHook hook = new LocalVariableTestHook();
249     aspectInterface.setJoinPointHook(hook);
250     startChronometer();
251     for(int i =0; i<RUNS; i++)
252         this.theMethodToCall(objectParam);
253     stopChronometer();
254     aspectInterface.clearMethodEntryWatch(methodO);
255     aspectInterface.setJoinPointHook(null);
256     }
257
258     // ###############################################################################
259

260     public static class ThisValueTestHook extends JoinPointHook
261     {
262
263     public ThisValueTestHook() { }
264     public void onFieldAccess (FieldAccessJoinPoint joinPoint) { }
265     public void onFieldModification(FieldModificationJoinPoint joinPoint) { }
266     public void onMethodEntry (MethodEntryJoinPoint joinPoint) {
267         joinPoint.getThis();
268     }
269     public void onMethodExit (MethodExitJoinPoint joinPoint) { }
270     public void onExceptionThrow (ExceptionJoinPoint joinPoint) { }
271     public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { }
272     public void onClassLoad (Class JavaDoc cls) { }
273     }
274
275     public void test_12_GetThisValue()
276     {
277     aspectInterface.setMethodEntryWatch(method,new Object JavaDoc());
278     ThisValueTestHook hook = new ThisValueTestHook();
279     aspectInterface.setJoinPointHook(hook);
280     startChronometer();
281     for(int i =0; i<RUNS; i++)
282         this.theMethodToCall(1,1,1.0,param);
283     stopChronometer();
284     aspectInterface.clearMethodEntryWatch(method);
285     aspectInterface.setJoinPointHook(null);
286     }
287
288     // ###############################################################################
289

290     public static class ReturnValueTestHook extends JoinPointHook
291     {
292
293     public ReturnValueTestHook() { }
294     public void onFieldAccess (FieldAccessJoinPoint joinPoint) { }
295     public void onFieldModification(FieldModificationJoinPoint joinPoint) { }
296     public void onMethodEntry (MethodEntryJoinPoint joinPoint) { }
297     public void onMethodExit (MethodExitJoinPoint joinPoint) {
298         joinPoint.getResult();
299     }
300     public void onExceptionThrow (ExceptionJoinPoint joinPoint) { }
301     public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { }
302     public void onClassLoad (Class JavaDoc cls) { }
303     }
304
305     public void test_14_GetReturnValue()
306     {
307         aspectInterface.setMethodExitWatch(method,new Object JavaDoc());
308         ReturnValueTestHook hook = new ReturnValueTestHook();
309         aspectInterface.setJoinPointHook(hook);
310         startChronometer();
311         for(int i =0; i<RUNS; i++)
312         this.theMethodToCall(1,1,1.0,param);
313         stopChronometer();
314         aspectInterface.clearMethodExitWatch(method);
315         aspectInterface.setJoinPointHook(null);
316     }
317
318     // ###############################################################################
319

320     public static class FieldOwnerTestHook extends JoinPointHook
321     {
322
323     public FieldOwnerTestHook() { }
324     public void onFieldAccess (FieldAccessJoinPoint joinPoint) {
325         joinPoint.getTarget();
326     }
327     public void onFieldModification(FieldModificationJoinPoint joinPoint) { }
328     public void onMethodEntry (MethodEntryJoinPoint joinPoint) { }
329     public void onMethodExit (MethodExitJoinPoint joinPoint) { }
330     public void onExceptionThrow (ExceptionJoinPoint joinPoint) { }
331     public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { }
332     public void onClassLoad (Class JavaDoc cls) { }
333     }
334
335     public void test_16_GetFieldOwner()
336     {
337     aspectInterface.setFieldAccessWatch(field,new Object JavaDoc());
338     FieldOwnerTestHook hook = new FieldOwnerTestHook();
339     aspectInterface.setJoinPointHook(hook);
340     int n = 0;
341     startChronometer();
342     for(int i =0; i<RUNS; i++)
343         n = this.theFieldToAccess;
344     stopChronometer();
345     aspectInterface.clearFieldAccessWatch(field);
346     aspectInterface.setJoinPointHook(null);
347     }
348
349     // ###############################################################################
350

351     public static class FieldValueTestHook extends JoinPointHook
352     {
353
354     public FieldValueTestHook() { }
355     public void onFieldAccess (FieldAccessJoinPoint joinPoint) {
356         joinPoint.getValue();
357     }
358     public void onFieldModification(FieldModificationJoinPoint joinPoint) {
359         joinPoint.getNewValue();
360     }
361     public void onMethodEntry (MethodEntryJoinPoint joinPoint) { }
362     public void onMethodExit (MethodExitJoinPoint joinPoint) { }
363     public void onExceptionThrow (ExceptionJoinPoint joinPoint) { }
364     public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { }
365     public void onClassLoad (Class JavaDoc cls) { }
366     }
367
368     public void test_17_GetFieldValue()
369     {
370     aspectInterface.setFieldAccessWatch(field,new Object JavaDoc());
371     FieldValueTestHook hook = new FieldValueTestHook();
372     aspectInterface.setJoinPointHook(hook);
373     int n = 0;
374     startChronometer();
375     for(int i =0; i<RUNS; i++)
376         n = this.theFieldToAccess;
377     stopChronometer();
378     aspectInterface.clearFieldAccessWatch(field);
379     aspectInterface.setJoinPointHook(null);
380     }
381
382     public void test_19_GetNewFieldValue()
383     {
384     aspectInterface.setFieldModificationWatch(field,new Object JavaDoc());
385     FieldValueTestHook hook = new FieldValueTestHook();
386     aspectInterface.setJoinPointHook(hook);
387     startChronometer();
388     for(int i =0; i<RUNS; i++)
389         this.theFieldToAccess = 1;
390     stopChronometer();
391     aspectInterface.clearFieldModificationWatch(field);
392     aspectInterface.setJoinPointHook(null);
393     }
394
395
396     /*
397       missing measurements for :
398
399       public void setLocalVariableValue(JoinPoint joinPoint, LocalVariableInfo info, Object value);
400       public void setFieldValue(FieldJoinPoint joinPoint, Object value);
401       public void setNewFieldValue(FieldModificationJoinPoint joinPoint, Object value);
402       public void setReturnValue(MethodExitJoinPoint joinPoint, Object value);
403     */

404
405     //#####################################################################################################################
406

407     /**
408      * Test suite.
409      * @return test instance
410      */

411     public static Test suite()
412     {
413     return new PerformanceTestSuite(JVMAIInfoMeasurement.class);
414     }
415
416 }
417
418
419 //======================================================================
420
//
421
// $Log: JVMAIInfoMeasurement.java,v $
422
// Revision 1.3 2004/05/12 17:26:53 anicoara
423
// Adapt Junit tests to 3.8.1 version and the new package structure
424
//
425
// Revision 1.1.1.1 2003/07/02 15:30:45 apopovic
426
// Imported from ETH Zurich
427
//
428
// Revision 1.10 2003/07/02 12:42:39 anicoara
429
// Added CatchJoinPoint Functionality (Requests, Join-Points, Filters, CatchCuts, Tests)
430
//
431
// Revision 1.9 2003/05/05 14:03:03 popovici
432
// renaming from runes to prose
433
//
434
// Revision 1.8 2003/03/04 18:35:59 popovici
435
// Organization of imprts
436
//
437
// Revision 1.7 2003/03/04 11:26:12 popovici
438
// Important refactorization step (march):
439
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
440
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
441
// structures
442
//
443
// Revision 1.6 2002/10/17 17:05:48 pschoch
444
// Added throw capabability to JVMAI
445
//
446
// Revision 1.5 2002/09/27 14:19:58 popovici
447
// Added unified nr of iterations depending on enabled debugger
448
//
449
// Revision 1.4 2002/03/11 11:02:42 smarkwal
450
// JVMInfoInterface and JoinPointHook changed to abstract classes
451
//
452
// Revision 1.3 2002/02/28 17:35:43 smarkwal
453
// error-handling in case of disabled prose-system changed
454
//
455
// Revision 1.2 2002/02/25 16:01:12 smarkwal
456
// null aop tags replaced with Object aop tags to let tests run with both rvm & runes
457
//
458
// Revision 1.1 2002/02/25 15:19:15 smarkwal
459
// initial revision
460
//
461
// Revision 1.3 2002/02/15 12:29:31 smarkwal
462
// doesn't rely anymore on Provider.getProvider(). test testEmtpy removed.
463
//
464
// Revision 1.2 2002/02/11 12:16:48 smarkwal
465
// many more tests added
466
//
467
// Revision 1.1 2002/02/05 11:24:12 smarkwal
468
// JVMDIMeasurement renamed to JVMAIMeasurement, JVMDI-based code replaced by JVMAI
469
//
470
// Revision 1.1.1.1 2001/11/29 18:13:34 popovici
471
// Sources from runes
472
//
473
// Revision 1.1.2.3 2001/11/21 11:56:42 popovici
474
//
475
// -The sun.tools.agent and ch.ethz.inf.util.JVMDIUtil functionality
476
// replaced with the iks.jvmdi package. References to this old
477
// functionality replaced throughout the code.
478
// -Partial reimplementation of the ch.ethz.inf.iks.runes classes,
479
// part of their functionality moved to the ch.ethz.prose.reflect
480
// abstract classes. New classes and functionality added to the
481
// ch.ethz.prose.reflect package, partially to reflect the
482
// more stable features taken from the iks.runes packages, partially
483
// to reflect the structure of the VM (constant pool, etc). Functionality in
484
// ch.ethz.prose.crosscut and the junit classes adapted to use the
485
// new form of the ch.ethz.prose.reflect package
486
//
487
// Revision 1.1.2.2 2001/02/22 16:23:32 popovici
488
// ProseSystem.setup replaced with startup; teardown introduced
489
//
490
// Revision 1.1.2.1 2001/01/22 07:28:20 popovici
491
// Initial Revision
492
//
493
Popular Tags