KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > measurements > suites > AllLocationsMeasurement


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

7 package measurements.suites;
8
9 import junit.framework.Assert;
10 import junit.framework.Test;
11 import ch.ethz.inf.util.junit.PerformanceTest;
12 import ch.ethz.inf.util.junit.PerformanceTestSuite;
13 import ch.ethz.prose.*;
14 import ch.ethz.prose.crosscut.Crosscut;
15 import ch.ethz.prose.crosscut.MethodCut;
16 import ch.ethz.prose.filter.*;
17
18 /**
19  * JUnit performs a suite of measurements for local interceptions
20  * of a method using <em>AllLocationsCrosscut</em>.
21  *
22  * The test can be used both in native and in runes mode.
23  * In both native and runes mode, the test
24  * <code>testLocalCall</code> calls a number of <code>RUNS</code>
25  * time a void method.
26  *
27  * If RUNES in enabled, the following measurements are meaningfull
28  * <ul>
29  * <li> <code>testLocalCallsNormal</code>: measure how much it takes
30  * to call RUNS times a trapped function while extracting argument values
31  * <li> <code>testLocalCallsFast</code>: measure how much it takes
32  * to call RUNS times a trapped function without retrieving the actual
33  * arguments from the stack.
34  * </ul>
35  *
36  * @version $Revision: 1.2 $
37  * @author Andrei Popovici
38  */

39 public class AllLocationsMeasurement extends PerformanceTest {
40
41     // fixture
42
public void theMethodToCall()
43     {
44         int a;
45         a=1;
46     };
47
48     public static class TrapMethodAspect1 extends DefaultAspect
49     {
50         public static class TrapMethodCrossc1 extends MethodCut
51         {
52             public void METHOD_ARGS() {}
53
54             protected PointCutter pointCutter()
55             {
56             PointCutter x = Executions.before().AND(Within.method("theMethodToCall"));
57             return x.AND(Within.type("AllLocationsMeasurement"));
58             }
59         }
60         public Crosscut c1 = new TrapMethodCrossc1();
61     }
62
63     public static class TrapMethodAspect2 extends DefaultAspect
64     {
65         public static class TrapMethodCrossc2 extends MethodCut
66         {
67
68             public void METHOD_ARGS() {}
69             protected PointCutter pointCutter()
70             {
71             PointCutter x = Executions.before().AND(Within.method("theMethodToCall"));
72             return x.AND(Within.type("AllLocationsMeasurement"));
73             }
74             public void joinPointAction(ch.ethz.jvmai.MethodEntryJoinPoint x) {}
75         }
76         public Crosscut c2 = new TrapMethodCrossc2();
77     }
78
79     Aspect x1;
80     Aspect x2;
81     final boolean useProse;
82
83     /**
84      * Construct test with given name.
85      * @param name test name
86      */

87     public AllLocationsMeasurement(String JavaDoc name)
88     {
89         super(name);
90
91         String JavaDoc proseParam = System.getProperty("useprose");
92         if(proseParam==null)
93             useProse = isDebuggerEnabled();
94         else
95             useProse = proseParam.toUpperCase().equals("TRUE");
96
97         if (useProse)
98             RANGE = new int[]{1000000};
99         else
100             RANGE = new int[]{1000000};
101
102     }
103
104     /**
105      * Set up fixture.
106      */

107     protected void setUp()
108     {
109         if (!useProse) return;
110
111         x1 = new TrapMethodAspect1();
112         x2 = new TrapMethodAspect2();
113         try
114             { ProseSystem.startup(); }
115         catch (Exception JavaDoc e)
116             { Assert.fail("ProseSystem.startup() failed"); }
117     }
118
119     protected void tearDown()
120     {
121         if (!useProse) return;
122
123         try
124             { ProseSystem.teardown(); }
125         catch (Exception JavaDoc e)
126             { Assert.fail("ProseSystem.teardown() failed"); }
127     }
128
129     public void testLocalCallsNormal()
130     {
131         if (useProse)
132             ProseSystem.getAspectManager().insert(x1);
133
134         startChronometer();
135         for (int i=0; i < RUNS; i ++)
136             this.theMethodToCall();
137         stopChronometer();
138
139         if (useProse)
140             ProseSystem.getAspectManager().withdraw(x1);
141     }
142
143     public void testLocalCallsFast()
144     {
145         if (useProse)
146             ProseSystem.getAspectManager().insert(x2);
147
148         startChronometer();
149         for (int i=0; i < RUNS; i++)
150             this.theMethodToCall();
151         stopChronometer();
152
153         if (useProse)
154             ProseSystem.getAspectManager().withdraw(x2);
155     }
156
157     /**
158      * Test suite.
159      * @return test instance
160      */

161     public static
162         Test suite()
163     {
164         return new PerformanceTestSuite(AllLocationsMeasurement.class);
165     }
166
167 }
168
169
170 //======================================================================
171
//
172
// $Log: AllLocationsMeasurement.java,v $
173
// Revision 1.2 2004/05/12 17:26:52 anicoara
174
// Adapt Junit tests to 3.8.1 version and the new package structure
175
//
176
// Revision 1.1.1.1 2003/07/02 15:30:45 apopovic
177
// Imported from ETH Zurich
178
//
179
// Revision 1.18 2003/05/05 14:03:03 popovici
180
// renaming from runes to prose
181
//
182
// Revision 1.17 2003/04/27 13:08:58 popovici
183
// Specializers renamed to PointCutter
184
//
185
// Revision 1.16 2003/04/17 15:14:53 popovici
186
// Extension->Aspect renaming
187
//
188
// Revision 1.15 2003/04/17 13:54:30 popovici
189
// Refactorization of 'ExecutionS' into 'Within' and 'Executions'.
190
// Method names refer now to 'types'
191
//
192
// Revision 1.14 2003/04/17 12:49:17 popovici
193
// Refactoring of the crosscut package
194
// ExceptionCut renamed to ThrowCut
195
// McutSignature is now SignaturePattern
196
//
197
// Revision 1.13 2003/04/17 08:46:56 popovici
198
// Important functionality additions
199
// - Cflow specializers
200
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
201
// - Transactional capabilities
202
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
203
// between static and dynamic specializers.
204
// - Functionality pulled up in abstract classes
205
// - Uniformization of advice methods patterns and names
206
//
207
// Revision 1.12 2003/03/04 18:35:59 popovici
208
// Organization of imprts
209
//
210
// Revision 1.11 2003/03/04 11:26:08 popovici
211
// Important refactorization step (march):
212
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
213
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
214
// structures
215
//
216
// Revision 1.10 2002/11/26 17:15:49 pschoch
217
// RootComponent now added (replaces RootComponent now added (replaces old ProseSystem)
218
// ProseSystem now owns and starts the Aspect interface.
219
// ProseSystem now containes a 'test' AspectManager
220
// AspectManager now owns the JoinPointManager.
221
// ExtensionManger can be 'connected' to the JVM, or disconnected. The
222
// JoinPointManager of a connected Ext.Mgr enables joinpoints; the
223
// JoinPointManger of a disconnected Ext.Mgr never enables join-points
224
// Documentation updated accordingly.
225
//
226
// Revision 1.9 2002/06/06 18:53:51 popovici
227
// 1. Bug fix: methodAdvice is now public; the constructor works for all subclasses.
228
// 2. Feature change/bug fix: ADVICE_NAME is now a protected method
229
//
230
// Revision 1.8 2002/06/06 14:39:50 popovici
231
// Renamings: FunctionalCrosscut->MethodCut
232
// AllFields->SetCut
233
// SetCu.fieldModiticationAdvice -> SetCut.setAdvice
234
//
235
// Revision 1.7 2002/06/04 12:36:09 popovici
236
// AllLocations occurences replaced with FunctionalCrosscut
237
//
238
// Revision 1.6 2002/05/22 11:00:33 popovici
239
// ClasseS replaced with DeclarationS
240
//
241
// Revision 1.5 2002/03/12 09:50:13 popovici
242
// Initial version of the Benchmark measurements
243
//
244
// Revision 1.4 2002/02/15 12:31:08 smarkwal
245
// minor changes like spaces/tabs, setUp
246
//
247
// Revision 1.3 2002/02/05 13:39:04 smarkwal
248
// spaces/tabs clean-up
249
//
250
// Revision 1.2 2002/02/05 11:22:30 smarkwal
251
// modifications to test JVMAI-based implementation
252
//
253
// Revision 1.1.1.1 2001/11/29 18:13:34 popovici
254
// Sources from runes
255
//
256
// Revision 1.1.2.3 2001/11/21 11:56:40 popovici
257
//
258
// -The sun.tools.agent and ch.ethz.inf.util.JVMDIUtil functionality
259
// replaced with the iks.jvmdi package. References to this old
260
// functionality replaced throughout the code.
261
// -Partial reimplementation of the ch.ethz.inf.iks.runes classes,
262
// part of their functionality moved to the ch.ethz.prose.reflect
263
// abstract classes. New classes and functionality added to the
264
// ch.ethz.prose.reflect package, partially to reflect the
265
// more stable features taken from the iks.runes packages, partially
266
// to reflect the structure of the VM (constant pool, etc). Functionality in
267
// ch.ethz.prose.crosscut and the junit classes adapted to use the
268
// new form of the ch.ethz.prose.reflect package
269
//
270
// Revision 1.1.2.2 2001/02/22 16:22:27 popovici
271
// ProseSystem.setup replaced with startup; teardown introduced
272
//
273
// Revision 1.1.2.1 2001/01/22 07:26:37 popovici
274
// Initial Revision
275
//
276
//
277
Popular Tags