001: // $Id: JVMAIInfoMeasurement.java,v 1.3 2004/05/12 17:26:53 anicoara Exp $
002: // =====================================================================
003: //
004: // (history at end)
005: //
006:
007: package measurements.suites;
008:
009: import java.lang.reflect.Field;
010: import java.lang.reflect.Method;
011:
012: import junit.framework.Assert;
013: import junit.framework.Test;
014: import ch.ethz.inf.util.junit.PerformanceTest;
015: import ch.ethz.inf.util.junit.PerformanceTestSuite;
016: import ch.ethz.jvmai.*;
017:
018: /**
019: * Performance testcase for measuring the speed of the info-interface.
020: *
021: * @version $Revision: 1.3 $
022: * @author Andrei Popovici
023: * @author Angela Nicoara
024: */
025: public class JVMAIInfoMeasurement extends PerformanceTest {
026:
027: public int theMethodToCall(int i, long l, double d, Object o) {
028: return i;
029: }
030:
031: public void theMethodToCall(long i) {
032: }
033:
034: public void theMethodToCall(Object o) {
035: }
036:
037: public void theMethodToCall(int i) {
038: }
039:
040: public void theMethodToCall(double d) {
041: }
042:
043: public void theMethodToCall() {
044: }
045:
046: public int theFieldToAccess = 0;
047:
048: public static class EmptyTestHook extends JoinPointHook {
049: public void onFieldAccess(FieldAccessJoinPoint joinPoint) {
050: }
051:
052: public void onFieldModification(
053: FieldModificationJoinPoint joinPoint) {
054: }
055:
056: public void onMethodEntry(MethodEntryJoinPoint joinPoint) {
057: }
058:
059: public void onMethodExit(MethodExitJoinPoint joinPoint) {
060: }
061:
062: public void onExceptionThrow(ExceptionJoinPoint joinPoint) {
063: }
064:
065: public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) {
066: }
067:
068: public void onClassLoad(Class cls) {
069: }
070:
071: public void onConstructor(ConstructorJoinPoint joinPoint) {
072: }
073: }
074:
075: final boolean useProse;
076:
077: /**
078: * Construct test with given name.
079: * @param name test name
080: */
081: public JVMAIInfoMeasurement(String name) {
082: super (name);
083: String proseParam = System.getProperty("useprose");
084: if (proseParam == null)
085: useProse = isDebuggerEnabled();
086: else
087: useProse = proseParam.toUpperCase().equals("TRUE");
088: if (isDebuggerEnabled())
089: RANGE = new int[] { 10000 };
090: else
091: RANGE = new int[] { 1000000 };
092: }
093:
094: JVMAspectInterface aspectInterface;
095:
096: Method method, methodI, methodL, methodD, methodO, methodV;
097: Field field;
098: Object param;
099:
100: protected void setUp() {
101: if (!useProse)
102: Assert
103: .fail("unable to test info-interface if prose is disabled");
104: try {
105: String providerName = System
106: .getProperty("ch.ethz.prose.JVMAIProvider");
107: Class providerClass = Class.forName(providerName);
108: Provider provider = (Provider) providerClass.newInstance();
109:
110: aspectInterface = provider.getAspectInterface();
111:
112: aspectInterface.startup(new String[] { "ch.ethz.prose." },
113: true);
114:
115: method = JVMAIInfoMeasurement.class.getDeclaredMethod(
116: "theMethodToCall", new Class[] { Integer.TYPE,
117: Long.TYPE, Double.TYPE, Object.class });
118: methodI = JVMAIInfoMeasurement.class.getDeclaredMethod(
119: "theMethodToCall", new Class[] { Integer.TYPE });
120: methodL = JVMAIInfoMeasurement.class.getDeclaredMethod(
121: "theMethodToCall", new Class[] { Long.TYPE });
122: methodD = JVMAIInfoMeasurement.class.getDeclaredMethod(
123: "theMethodToCall", new Class[] { Double.TYPE });
124: methodO = JVMAIInfoMeasurement.class.getDeclaredMethod(
125: "theMethodToCall", new Class[] { Object.class });
126: methodV = JVMAIInfoMeasurement.class.getDeclaredMethod(
127: "theMethodToCall", new Class[] {});
128: field = JVMAIInfoMeasurement.class
129: .getDeclaredField("theFieldToAccess");
130:
131: param = new String("hello world;");
132: EmptyTestHook hook = new EmptyTestHook();
133: // call every method at least once ...
134: aspectInterface.setJoinPointHook(hook);
135: aspectInterface.setMethodEntryWatch(method, new Object());
136: aspectInterface.setMethodExitWatch(method, new Object());
137:
138: aspectInterface.setFieldAccessWatch(field, new Object());
139: aspectInterface.setFieldModificationWatch(field,
140: new Object());
141: this .theMethodToCall(1, 1, 1.0, param);
142: int n = this .theFieldToAccess;
143: this .theFieldToAccess = 1;
144: aspectInterface.clearMethodEntryWatch(method);
145: aspectInterface.clearMethodExitWatch(method);
146: aspectInterface.clearFieldAccessWatch(field);
147: aspectInterface.clearFieldModificationWatch(field);
148: aspectInterface.setJoinPointHook(null);
149: aspectInterface.suspendNotification(Thread.currentThread());
150: aspectInterface.resumeNotification(Thread.currentThread());
151:
152: } catch (Exception e) {
153: Assert
154: .fail("loading provider or initializing aspect-interface failed");
155: }
156: }
157:
158: protected void tearDown() {
159: }
160:
161: public void test_06_MethodEntry() {
162: aspectInterface.setMethodEntryWatch(method, new Object());
163: EmptyTestHook hook = new EmptyTestHook();
164: aspectInterface.setJoinPointHook(hook);
165: startChronometer();
166: for (int i = 0; i < RUNS; i++)
167: this .theMethodToCall(1, 1, 1.0, param);
168: stopChronometer();
169: aspectInterface.clearMethodEntryWatch(method);
170: aspectInterface.setJoinPointHook(null);
171: }
172:
173: public void test_13_MethodExit() {
174: aspectInterface.setMethodExitWatch(method, new Object());
175: EmptyTestHook hook = new EmptyTestHook();
176: aspectInterface.setJoinPointHook(hook);
177: startChronometer();
178: for (int i = 0; i < RUNS; i++)
179: this .theMethodToCall(1, 1, 1.0, param);
180: stopChronometer();
181: aspectInterface.clearMethodExitWatch(method);
182: aspectInterface.setJoinPointHook(null);
183: }
184:
185: public void test_15_FieldAccess() {
186: aspectInterface.setFieldAccessWatch(field, new Object());
187: EmptyTestHook hook = new EmptyTestHook();
188: aspectInterface.setJoinPointHook(hook);
189: int n = 0;
190: startChronometer();
191: for (int i = 0; i < RUNS; i++)
192: n = this .theFieldToAccess;
193: stopChronometer();
194: aspectInterface.clearFieldAccessWatch(field);
195: aspectInterface.setJoinPointHook(null);
196: }
197:
198: public void test_18_FieldModification() {
199: aspectInterface.setFieldModificationWatch(field, new Object());
200: EmptyTestHook hook = new EmptyTestHook();
201: aspectInterface.setJoinPointHook(hook);
202: startChronometer();
203: for (int i = 0; i < RUNS; i++)
204: this .theFieldToAccess = 1;
205: stopChronometer();
206: aspectInterface.clearFieldModificationWatch(field);
207: aspectInterface.setJoinPointHook(null);
208: }
209:
210: // ###############################################################################
211:
212: public static class LocalVariableTestHook extends JoinPointHook {
213: public LocalVariableTestHook() {
214: }
215:
216: public void onFieldAccess(FieldAccessJoinPoint joinPoint) {
217: }
218:
219: public void onFieldModification(
220: FieldModificationJoinPoint joinPoint) {
221: }
222:
223: public void onMethodEntry(MethodEntryJoinPoint joinPoint) {
224: joinPoint.getArgs();
225: }
226:
227: public void onMethodExit(MethodExitJoinPoint joinPoint) {
228: }
229:
230: public void onExceptionThrow(ExceptionJoinPoint joinPoint) {
231: }
232:
233: public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) {
234: }
235:
236: public void onClassLoad(Class cls) {
237: }
238:
239: public void onConstructor(ConstructorJoinPoint joinPoin) {
240: }
241:
242: }
243:
244: public void test_08_GetLocalVariableValue_int() {
245: aspectInterface.setMethodEntryWatch(methodI, new Object());
246: LocalVariableTestHook hook = new LocalVariableTestHook();
247: aspectInterface.setJoinPointHook(hook);
248: startChronometer();
249: int param = 1;
250: for (int i = 0; i < RUNS; i++)
251: this .theMethodToCall(i);
252: stopChronometer();
253: aspectInterface.clearMethodEntryWatch(methodI);
254: aspectInterface.setJoinPointHook(null);
255: }
256:
257: public void test_09_GetLocalVariableValue_long() {
258: long longParam = 1;
259: aspectInterface.setMethodEntryWatch(methodL, new Object());
260: LocalVariableTestHook hook = new LocalVariableTestHook();
261: aspectInterface.setJoinPointHook(hook);
262: startChronometer();
263: for (int i = 0; i < RUNS; i++)
264: this .theMethodToCall(longParam);
265: stopChronometer();
266: aspectInterface.clearMethodEntryWatch(methodL);
267: aspectInterface.setJoinPointHook(null);
268: }
269:
270: public void test_10_GetLocalVariableValue_double() {
271: double doubleParam = 12.0;
272: aspectInterface.setMethodEntryWatch(methodD, new Object());
273: LocalVariableTestHook hook = new LocalVariableTestHook();
274: aspectInterface.setJoinPointHook(hook);
275: startChronometer();
276: for (int i = 0; i < RUNS; i++)
277: this .theMethodToCall(doubleParam);
278: stopChronometer();
279: aspectInterface.clearMethodEntryWatch(methodD);
280: aspectInterface.setJoinPointHook(null);
281: }
282:
283: public void test_11_GetLocalVariableValue_Object() {
284: Object objectParam = new Object();
285: aspectInterface.setMethodEntryWatch(methodO, new Object());
286: LocalVariableTestHook hook = new LocalVariableTestHook();
287: aspectInterface.setJoinPointHook(hook);
288: startChronometer();
289: for (int i = 0; i < RUNS; i++)
290: this .theMethodToCall(objectParam);
291: stopChronometer();
292: aspectInterface.clearMethodEntryWatch(methodO);
293: aspectInterface.setJoinPointHook(null);
294: }
295:
296: // ###############################################################################
297:
298: public static class ThisValueTestHook extends JoinPointHook {
299:
300: public ThisValueTestHook() {
301: }
302:
303: public void onFieldAccess(FieldAccessJoinPoint joinPoint) {
304: }
305:
306: public void onFieldModification(
307: FieldModificationJoinPoint joinPoint) {
308: }
309:
310: public void onMethodEntry(MethodEntryJoinPoint joinPoint) {
311: joinPoint.getThis();
312: }
313:
314: public void onMethodExit(MethodExitJoinPoint joinPoint) {
315: }
316:
317: public void onExceptionThrow(ExceptionJoinPoint joinPoint) {
318: }
319:
320: public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) {
321: }
322:
323: public void onClassLoad(Class cls) {
324: }
325:
326: public void onConstructor(ConstructorJoinPoint joinPoint) {
327: }
328: }
329:
330: public void test_12_GetThisValue() {
331: aspectInterface.setMethodEntryWatch(method, new Object());
332: ThisValueTestHook hook = new ThisValueTestHook();
333: aspectInterface.setJoinPointHook(hook);
334: startChronometer();
335: for (int i = 0; i < RUNS; i++)
336: this .theMethodToCall(1, 1, 1.0, param);
337: stopChronometer();
338: aspectInterface.clearMethodEntryWatch(method);
339: aspectInterface.setJoinPointHook(null);
340: }
341:
342: // ###############################################################################
343:
344: public static class ReturnValueTestHook extends JoinPointHook {
345:
346: public ReturnValueTestHook() {
347: }
348:
349: public void onFieldAccess(FieldAccessJoinPoint joinPoint) {
350: }
351:
352: public void onFieldModification(
353: FieldModificationJoinPoint joinPoint) {
354: }
355:
356: public void onMethodEntry(MethodEntryJoinPoint joinPoint) {
357: }
358:
359: public void onMethodExit(MethodExitJoinPoint joinPoint) {
360: joinPoint.getResult();
361: }
362:
363: public void onExceptionThrow(ExceptionJoinPoint joinPoint) {
364: }
365:
366: public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) {
367: }
368:
369: public void onClassLoad(Class cls) {
370: }
371:
372: public void onConstructor(ConstructorJoinPoint joinPoint) {
373: }
374: }
375:
376: public void test_14_GetReturnValue() {
377: aspectInterface.setMethodExitWatch(method, new Object());
378: ReturnValueTestHook hook = new ReturnValueTestHook();
379: aspectInterface.setJoinPointHook(hook);
380: startChronometer();
381: for (int i = 0; i < RUNS; i++)
382: this .theMethodToCall(1, 1, 1.0, param);
383: stopChronometer();
384: aspectInterface.clearMethodExitWatch(method);
385: aspectInterface.setJoinPointHook(null);
386: }
387:
388: // ###############################################################################
389:
390: public static class FieldOwnerTestHook extends JoinPointHook {
391:
392: public FieldOwnerTestHook() {
393: }
394:
395: public void onFieldAccess(FieldAccessJoinPoint joinPoint) {
396: joinPoint.getTarget();
397: }
398:
399: public void onFieldModification(
400: FieldModificationJoinPoint joinPoint) {
401: }
402:
403: public void onMethodEntry(MethodEntryJoinPoint joinPoint) {
404: }
405:
406: public void onMethodExit(MethodExitJoinPoint joinPoint) {
407: }
408:
409: public void onExceptionThrow(ExceptionJoinPoint joinPoint) {
410: }
411:
412: public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) {
413: }
414:
415: public void onClassLoad(Class cls) {
416: }
417:
418: public void onConstructor(ConstructorJoinPoint joinPoint) {
419: }
420: }
421:
422: public void test_16_GetFieldOwner() {
423: aspectInterface.setFieldAccessWatch(field, new Object());
424: FieldOwnerTestHook hook = new FieldOwnerTestHook();
425: aspectInterface.setJoinPointHook(hook);
426: int n = 0;
427: startChronometer();
428: for (int i = 0; i < RUNS; i++)
429: n = this .theFieldToAccess;
430: stopChronometer();
431: aspectInterface.clearFieldAccessWatch(field);
432: aspectInterface.setJoinPointHook(null);
433: }
434:
435: // ###############################################################################
436:
437: public static class FieldValueTestHook extends JoinPointHook {
438:
439: public FieldValueTestHook() {
440: }
441:
442: public void onFieldAccess(FieldAccessJoinPoint joinPoint) {
443: joinPoint.getValue();
444: }
445:
446: public void onFieldModification(
447: FieldModificationJoinPoint joinPoint) {
448: joinPoint.getNewValue();
449: }
450:
451: public void onMethodEntry(MethodEntryJoinPoint joinPoint) {
452: }
453:
454: public void onMethodExit(MethodExitJoinPoint joinPoint) {
455: }
456:
457: public void onExceptionThrow(ExceptionJoinPoint joinPoint) {
458: }
459:
460: public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) {
461: }
462:
463: public void onClassLoad(Class cls) {
464: }
465:
466: public void onConstructor(ConstructorJoinPoint joinPoint) {
467: }
468: }
469:
470: public void test_17_GetFieldValue() {
471: aspectInterface.setFieldAccessWatch(field, new Object());
472: FieldValueTestHook hook = new FieldValueTestHook();
473: aspectInterface.setJoinPointHook(hook);
474: int n = 0;
475: startChronometer();
476: for (int i = 0; i < RUNS; i++)
477: n = this .theFieldToAccess;
478: stopChronometer();
479: aspectInterface.clearFieldAccessWatch(field);
480: aspectInterface.setJoinPointHook(null);
481: }
482:
483: public void test_19_GetNewFieldValue() {
484: aspectInterface.setFieldModificationWatch(field, new Object());
485: FieldValueTestHook hook = new FieldValueTestHook();
486: aspectInterface.setJoinPointHook(hook);
487: startChronometer();
488: for (int i = 0; i < RUNS; i++)
489: this .theFieldToAccess = 1;
490: stopChronometer();
491: aspectInterface.clearFieldModificationWatch(field);
492: aspectInterface.setJoinPointHook(null);
493: }
494:
495: /*
496: missing measurements for :
497:
498: public void setLocalVariableValue(JoinPoint joinPoint, LocalVariableInfo info, Object value);
499: public void setFieldValue(FieldJoinPoint joinPoint, Object value);
500: public void setNewFieldValue(FieldModificationJoinPoint joinPoint, Object value);
501: public void setReturnValue(MethodExitJoinPoint joinPoint, Object value);
502: */
503:
504: //#####################################################################################################################
505: /**
506: * Test suite.
507: * @return test instance
508: */
509: public static Test suite() {
510: return new PerformanceTestSuite(JVMAIInfoMeasurement.class);
511: }
512:
513: }
514:
515: //======================================================================
516: //
517: // $Log: JVMAIInfoMeasurement.java,v $
518: // Revision 1.3 2004/05/12 17:26:53 anicoara
519: // Adapt Junit tests to 3.8.1 version and the new package structure
520: //
521: // Revision 1.1.1.1 2003/07/02 15:30:45 apopovic
522: // Imported from ETH Zurich
523: //
524: // Revision 1.10 2003/07/02 12:42:39 anicoara
525: // Added CatchJoinPoint Functionality (Requests, Join-Points, Filters, CatchCuts, Tests)
526: //
527: // Revision 1.9 2003/05/05 14:03:03 popovici
528: // renaming from runes to prose
529: //
530: // Revision 1.8 2003/03/04 18:35:59 popovici
531: // Organization of imprts
532: //
533: // Revision 1.7 2003/03/04 11:26:12 popovici
534: // Important refactorization step (march):
535: // - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
536: // - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
537: // structures
538: //
539: // Revision 1.6 2002/10/17 17:05:48 pschoch
540: // Added throw capabability to JVMAI
541: //
542: // Revision 1.5 2002/09/27 14:19:58 popovici
543: // Added unified nr of iterations depending on enabled debugger
544: //
545: // Revision 1.4 2002/03/11 11:02:42 smarkwal
546: // JVMInfoInterface and JoinPointHook changed to abstract classes
547: //
548: // Revision 1.3 2002/02/28 17:35:43 smarkwal
549: // error-handling in case of disabled prose-system changed
550: //
551: // Revision 1.2 2002/02/25 16:01:12 smarkwal
552: // null aop tags replaced with Object aop tags to let tests run with both rvm & runes
553: //
554: // Revision 1.1 2002/02/25 15:19:15 smarkwal
555: // initial revision
556: //
557: // Revision 1.3 2002/02/15 12:29:31 smarkwal
558: // doesn't rely anymore on Provider.getProvider(). test testEmtpy removed.
559: //
560: // Revision 1.2 2002/02/11 12:16:48 smarkwal
561: // many more tests added
562: //
563: // Revision 1.1 2002/02/05 11:24:12 smarkwal
564: // JVMDIMeasurement renamed to JVMAIMeasurement, JVMDI-based code replaced by JVMAI
565: //
566: // Revision 1.1.1.1 2001/11/29 18:13:34 popovici
567: // Sources from runes
568: //
569: // Revision 1.1.2.3 2001/11/21 11:56:42 popovici
570: //
571: // -The sun.tools.agent and ch.ethz.inf.util.JVMDIUtil functionality
572: // replaced with the iks.jvmdi package. References to this old
573: // functionality replaced throughout the code.
574: // -Partial reimplementation of the ch.ethz.inf.iks.runes classes,
575: // part of their functionality moved to the ch.ethz.prose.reflect
576: // abstract classes. New classes and functionality added to the
577: // ch.ethz.prose.reflect package, partially to reflect the
578: // more stable features taken from the iks.runes packages, partially
579: // to reflect the structure of the VM (constant pool, etc). Functionality in
580: // ch.ethz.prose.crosscut and the junit classes adapted to use the
581: // new form of the ch.ethz.prose.reflect package
582: //
583: // Revision 1.1.2.2 2001/02/22 16:23:32 popovici
584: // ProseSystem.setup replaced with startup; teardown introduced
585: //
586: // Revision 1.1.2.1 2001/01/22 07:28:20 popovici
587: // Initial Revision
588: //
|