Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: measurements/suites/AllLocationsMeasurement.java


1   // $Id: AllLocationsMeasurement.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   import junit.framework.Assert;
9   import junit.framework.Test;
10  import ch.ethz.jvmai.JoinPoint;
11  import ch.ethz.prose.DefaultAspect;
12  import ch.ethz.prose.Aspect;
13  import ch.ethz.prose.ProseSystem;
14  import ch.ethz.prose.crosscut.Crosscut;
15  import ch.ethz.prose.crosscut.MethodCut;
16  import ch.ethz.prose.filter.PointCutter;
17  import ch.ethz.prose.filter.PointFilter;
18  import ch.ethz.prose.filter.Executions;
19  import ch.ethz.prose.filter.Within;
20  import ch.ethz.inf.util.junit.PerformanceTest;
21  import ch.ethz.inf.util.junit.PerformanceTestSuite;
22  import ch.ethz.prose.filter.Within;
23  
24  /**
25   * JUnit performs a suite of measurements for local interceptions
26   * of a method using <em>AllLocationsCrosscut</em>.
27   *
28   * The test can be used both in native and in runes mode.
29   * In both native and runes mode, the test
30   * <code>testLocalCall</code> calls a number of <code>RUNS</code>
31   * time a void method.
32   *
33   * If RUNES in enabled, the following measurements are meaningfull
34   * <ul>
35   * <li> <code>testLocalCallsNormal</code>: measure how much it takes
36   * to call RUNS times a trapped function while extracting argument values
37   * <li> <code>testLocalCallsFast</code>: measure how much it takes
38   * to call RUNS times a trapped function without retrieving the actual
39   * arguments from the stack.
40   * </ul>
41   *
42   * @version  $Revision: 1.1.1.1 $
43   * @author  Andrei Popovici
44   */
45  public class AllLocationsMeasurement extends PerformanceTest {
46  
47    // fixture
48    public void theMethodToCall()
49    {
50      int a;
51      a=1;
52    };
53  
54    public static class TrapMethodAspect1 extends DefaultAspect
55    {
56      public static class TrapMethodCrossc1 extends MethodCut
57      {
58          public void METHOD_ARGS() {}
59  
60          protected PointCutter pointCutter()
61          {
62        PointCutter x = Executions.before().AND(Within.method("theMethodToCall"));
63        return x.AND(Within.type("AllLocationsMeasurement"));
64          }
65      }
66      public Crosscut c1 = new TrapMethodCrossc1();
67    }
68  
69    public static class TrapMethodAspect2 extends DefaultAspect
70    {
71      public static class TrapMethodCrossc2 extends MethodCut
72      {
73  
74          public void METHOD_ARGS() {}
75          protected PointCutter pointCutter()
76          {
77        PointCutter x = Executions.before().AND(Within.method("theMethodToCall"));
78        return x.AND(Within.type("AllLocationsMeasurement"));
79          }
80          public void joinPointAction(ch.ethz.jvmai.MethodEntryJoinPoint x) {}
81      }
82      public Crosscut c2 = new TrapMethodCrossc2();
83    }
84  
85    Aspect x1;
86    Aspect x2;
87    final boolean useProse;
88  
89    /**
90     * Construct test with given name.
91     * @param name test name
92     */
93    public AllLocationsMeasurement(String name)
94    {
95      super(name);
96  
97      String proseParam = System.getProperty("useprose");
98      if(proseParam==null)
99        useProse = isDebuggerEnabled();
100     else
101       useProse = proseParam.toUpperCase().equals("TRUE");
102 
103     if (useProse)
104         RANGE = new int[]{1000000};
105     else
106       RANGE = new int[]{1000000};
107 
108   }
109 
110   /**
111    * Set up fixture.
112    */
113   protected void setUp()
114   {
115     if (!useProse) return;
116 
117     x1 = new TrapMethodAspect1();
118     x2 = new TrapMethodAspect2();
119     try
120       { ProseSystem.startup(); }
121     catch (Exception e)
122       { Assert.fail("ProseSystem.startup() failed"); }
123   }
124 
125   protected void tearDown()
126   {
127     if (!useProse) return;
128 
129     try
130       { ProseSystem.teardown(); }
131     catch (Exception e)
132       { Assert.fail("ProseSystem.teardown() failed"); }
133   }
134 
135   public void testLocalCallsNormal()
136   {
137     if (useProse)
138       ProseSystem.getAspectManager().insert(x1);
139 
140       startChronometer();
141     for (int i=0; i < RUNS; i ++)
142       this.theMethodToCall();
143     stopChronometer();
144 
145     if (useProse)
146       ProseSystem.getAspectManager().withdraw(x1);
147   }
148 
149   public void testLocalCallsFast()
150   {
151     if (useProse)
152       ProseSystem.getAspectManager().insert(x2);
153 
154         startChronometer();
155     for (int i=0; i < RUNS; i++)
156       this.theMethodToCall();
157         stopChronometer();
158 
159     if (useProse)
160       ProseSystem.getAspectManager().withdraw(x2);
161   }
162 
163   /**
164    * Test suite.
165    * @return test instance
166    */
167   public static
168     Test suite()
169   {
170     return new PerformanceTestSuite(AllLocationsMeasurement.class);
171   }
172 
173 }
174 
175 
176 //======================================================================
177 //
178 // $Log: AllLocationsMeasurement.java,v $
179 // Revision 1.1.1.1  2003/07/02 15:30:45  apopovic
180 // Imported from ETH Zurich
181 //
182 // Revision 1.18  2003/05/05 14:03:03  popovici
183 // renaming from runes to prose
184 //
185 // Revision 1.17  2003/04/27 13:08:58  popovici
186 // Specializers renamed to PointCutter
187 //
188 // Revision 1.16  2003/04/17 15:14:53  popovici
189 // Extension->Aspect renaming
190 //
191 // Revision 1.15  2003/04/17 13:54:30  popovici
192 // Refactorization of 'ExecutionS' into 'Within' and 'Executions'.
193 // Method names refer now to 'types'
194 //
195 // Revision 1.14  2003/04/17 12:49:17  popovici
196 // Refactoring of the crosscut package
197 //  ExceptionCut renamed to ThrowCut
198 //  McutSignature is now SignaturePattern
199 //
200 // Revision 1.13  2003/04/17 08:46:56  popovici
201 // Important functionality additions
202 //  - Cflow specializers
203 //  - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
204 //  - Transactional capabilities
205 //  - Total refactoring of Specializer evaluation, which permits fine-grained distinction
206 //    between static and dynamic specializers.
207 //  - Functionality pulled up in abstract classes
208 //  - Uniformization of advice methods patterns and names
209 //
210 // Revision 1.12  2003/03/04 18:35:59  popovici
211 // Organization of imprts
212 //
213 // Revision 1.11  2003/03/04 11:26:08  popovici
214 // Important refactorization step (march):
215 // - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
216 // - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
217 //   structures
218 //
219 // Revision 1.10  2002/11/26 17:15:49  pschoch
220 // RootComponent now added (replaces RootComponent now added (replaces old ProseSystem)
221 // ProseSystem now owns and starts the Aspect interface.
222 // ProseSystem now containes  a 'test' AspectManager
223 // AspectManager now owns the JoinPointManager.
224 // ExtensionManger can be 'connected' to the JVM, or disconnected. The
225 // JoinPointManager of a connected Ext.Mgr enables joinpoints; the
226 // JoinPointManger of a disconnected Ext.Mgr never enables join-points
227 // Documentation updated accordingly.
228 //
229 // Revision 1.9  2002/06/06 18:53:51  popovici
230 // 1. Bug fix: methodAdvice is now public; the constructor works for all subclasses.
231 // 2. Feature change/bug fix: ADVICE_NAME is now a protected method
232 //
233 // Revision 1.8  2002/06/06 14:39:50  popovici
234 // Renamings: FunctionalCrosscut->MethodCut
235 // AllFields->SetCut
236 // SetCu.fieldModiticationAdvice -> SetCut.setAdvice
237 //
238 // Revision 1.7  2002/06/04 12:36:09  popovici
239 // AllLocations occurences replaced with FunctionalCrosscut
240 //
241 // Revision 1.6  2002/05/22 11:00:33  popovici
242 // ClasseS replaced with DeclarationS
243 //
244 // Revision 1.5  2002/03/12 09:50:13  popovici
245 // Initial version of the Benchmark measurements
246 //
247 // Revision 1.4  2002/02/15 12:31:08  smarkwal
248 // minor changes like spaces/tabs, setUp
249 //
250 // Revision 1.3  2002/02/05 13:39:04  smarkwal
251 // spaces/tabs clean-up
252 //
253 // Revision 1.2  2002/02/05 11:22:30  smarkwal
254 // modifications to test JVMAI-based implementation
255 //
256 // Revision 1.1.1.1  2001/11/29 18:13:34  popovici
257 // Sources from runes
258 //
259 // Revision 1.1.2.3  2001/11/21 11:56:40  popovici
260 //
261 // -The sun.tools.agent and ch.ethz.inf.util.JVMDIUtil functionality
262 // replaced with the iks.jvmdi package. References to this old
263 // functionality replaced throughout the code.
264 // -Partial reimplementation of the ch.ethz.inf.iks.runes classes,
265 // part of their functionality moved to the ch.ethz.prose.reflect
266 // abstract classes. New classes and functionality added to the
267 // ch.ethz.prose.reflect package, partially to reflect the
268 // more stable features taken from the iks.runes packages, partially
269 // to reflect the structure of the VM (constant pool, etc). Functionality in
270 // ch.ethz.prose.crosscut and the junit classes adapted to use the
271 // new form of the ch.ethz.prose.reflect package
272 //
273 // Revision 1.1.2.2  2001/02/22 16:22:27  popovici
274 // ProseSystem.setup replaced with startup; teardown introduced
275 //
276 // Revision 1.1.2.1  2001/01/22 07:26:37  popovici
277 // Initial Revision
278 //
279 //