1 package measurements.suites; 2 3 import java.lang.reflect.Field ; 4 import java.lang.reflect.Method ; 5 6 import junit.framework.Test; 7 import ch.ethz.inf.util.junit.PerformanceTest; 8 import ch.ethz.inf.util.junit.PerformanceTestSuite; 9 import ch.ethz.jvmai.*; 10 11 31 public class JoinPointMeasurements1_aj extends PerformanceTest { 32 33 public boolean useProse = false; 34 public boolean checkAssert = true; 35 36 protected JVMAspectInterface aspectInterface; 37 protected TestHook hook; 38 39 public void localMethod() { } 41 public void localMethodLongO(Object ob1, Object ob2) { } 42 public void localMethodLongI(int ob1, int ob2) { } 43 public void localMethodLongL(long ob1, long ob2) { } 44 public void localMethodLongD(double ob1, double ob2) { } 45 46 private void privatelocalMethod() { } 48 private void privatelocalMethodLongO(Object ob1, Object ob2) { } 49 private void privatelocalMethodLongI(int ob1, int ob2) { } 50 private void privatelocalMethodLongL(long ob1, long ob2) { } 51 private void privatelocalMethodLongD(double ob1, double ob2) { } 52 53 protected JoinPointTestInterface obInterface = new JoinPointTestClass(); 55 56 protected JoinPointTestClass obSync = new JoinPointTestClass(); 58 59 public int theField = 0; 60 61 public void theFieldAccess(int runs) 64 { 65 int n = 0; 66 67 startChronometer(); 68 for (int i = 0; i < RUNS; i++) n = this.theField; 69 stopChronometer(); 70 } 71 72 public void theFieldModification(int runs) 75 { 76 startChronometer(); 77 for (int i = 0; i < RUNS; i++) this.theField = i; 78 stopChronometer(); 79 } 80 81 protected Method method; 83 protected Method methodLongO; 84 protected Method methodLongI; 85 protected Method methodLongL; 86 protected Method methodLongD; 87 88 protected Method syncMethod; 90 protected Method syncMethodLongO; 91 protected Method syncMethodLongI; 92 protected Method syncMethodLongL; 93 protected Method syncMethodLongD; 94 95 protected Method interfaceMethod; 97 protected Method interfaceMethodLongO; 98 protected Method interfaceMethodLongI; 99 protected Method interfaceMethodLongL; 100 protected Method interfaceMethodLongD; 101 102 protected Method staticMethod; 104 protected Method staticMethodLongO; 105 protected Method staticMethodLongI; 106 protected Method staticMethodLongL; 107 protected Method staticMethodLongD; 108 109 protected Method privateMethod; 111 protected Method privateMethodLongO; 112 protected Method privateMethodLongI; 113 protected Method privateMethodLongL; 114 protected Method privateMethodLongD; 115 116 protected Field field; 117 118 public class TestException extends Exception {}; 119 public TestException exception = new TestException(); 120 121 129 public static int counter; 130 131 132 public static class TestHook extends JoinPointHook 133 { 134 143 public void onFieldAccess(FieldAccessJoinPoint joinPoint) { counter++; } 144 public void onFieldModification(FieldModificationJoinPoint joinPoint) { counter++; } 145 public void onMethodEntry(MethodEntryJoinPoint joinPoint) { counter++; } 146 public void onMethodExit(MethodExitJoinPoint joinPoint) { counter++; } 147 public void onExceptionThrow(ExceptionJoinPoint joinPoint) { counter++; } 148 public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) { counter++; } 149 public void onClassLoad(Class cls) {} 150 } 151 152 public JoinPointMeasurements1_aj(String name) { 153 super(name); 154 RANGE = new int[] { 100000000 }; 155 156 String proseParam = System.getProperty("useprose"); 157 if (proseParam != null) useProse = true; 158 } 159 160 protected void setUp() throws Exception 161 { 162 if (useProse) 163 { 164 String providerName = System.getProperty("ch.ethz.prose.JVMAIProvider"); 165 Class providerClass = Class.forName(providerName); 166 Provider provider = (Provider) providerClass.newInstance(); 167 168 aspectInterface = provider.getAspectInterface(); 169 aspectInterface.startup(null, true); 170 171 hook = new TestHook(); 172 aspectInterface.setJoinPointHook(hook); 173 174 method = JoinPointMeasurements1_aj.class.getDeclaredMethod("localMethod", new Class [] {}); 176 methodLongO = JoinPointMeasurements1_aj.class.getDeclaredMethod("localMethodLongO", new Class [] {Object .class, Object .class}); 177 methodLongI = JoinPointMeasurements1_aj.class.getDeclaredMethod("localMethodLongI", new Class [] {Integer.TYPE, Integer.TYPE}); 178 methodLongL = JoinPointMeasurements1_aj.class.getDeclaredMethod("localMethodLongL", new Class [] {Long.TYPE, Long.TYPE}); 179 methodLongD = JoinPointMeasurements1_aj.class.getDeclaredMethod("localMethodLongD", new Class [] {Double.TYPE, Double.TYPE}); 180 181 syncMethod = JoinPointTestClass.class.getDeclaredMethod("syncMethodShort", new Class [] {}); 183 syncMethodLongO = JoinPointTestClass.class.getDeclaredMethod("syncMethodLongO", new Class [] {Object .class, Object .class}); 184 syncMethodLongI = JoinPointTestClass.class.getDeclaredMethod("syncMethodLongI", new Class [] {Integer.TYPE, Integer.TYPE}); 185 syncMethodLongL = JoinPointTestClass.class.getDeclaredMethod("syncMethodLongL", new Class [] {Long.TYPE, Long.TYPE}); 186 syncMethodLongD = JoinPointTestClass.class.getDeclaredMethod("syncMethodLongD", new Class [] {Double.TYPE, Double.TYPE}); 187 188 interfaceMethod = JoinPointTestClass.class.getDeclaredMethod("interfaceMethodShort", new Class [] {}); 190 interfaceMethodLongO = JoinPointTestClass.class.getDeclaredMethod("interfaceMethodLongO", new Class [] {Object .class, Object .class}); 191 interfaceMethodLongI = JoinPointTestClass.class.getDeclaredMethod("interfaceMethodLongI", new Class [] {Integer.TYPE, Integer.TYPE}); 192 interfaceMethodLongL = JoinPointTestClass.class.getDeclaredMethod("interfaceMethodLongL", new Class [] {Long.TYPE, Long.TYPE}); 193 interfaceMethodLongD = JoinPointTestClass.class.getDeclaredMethod("interfaceMethodLongD", new Class [] {Double.TYPE, Double.TYPE}); 194 195 staticMethod = JoinPointTestClass.class.getDeclaredMethod("staticMethodShort", new Class [] {}); 197 staticMethodLongO = JoinPointTestClass.class.getDeclaredMethod("staticMethodLongO", new Class [] {Object .class, Object .class}); 198 staticMethodLongI = JoinPointTestClass.class.getDeclaredMethod("staticMethodLongI", new Class [] {Integer.TYPE, Integer.TYPE}); 199 staticMethodLongL = JoinPointTestClass.class.getDeclaredMethod("staticMethodLongL", new Class [] {Long.TYPE, Long.TYPE}); 200 staticMethodLongD = JoinPointTestClass.class.getDeclaredMethod("staticMethodLongD", new Class [] {Double.TYPE, Double.TYPE}); 201 202 privateMethod = JoinPointMeasurements1_aj.class.getDeclaredMethod("privatelocalMethod", new Class [] {}); 204 privateMethodLongO = JoinPointMeasurements1_aj.class.getDeclaredMethod("privatelocalMethodLongO", new Class [] {Object .class, Object .class}); 205 privateMethodLongI = JoinPointMeasurements1_aj.class.getDeclaredMethod("privatelocalMethodLongI", new Class [] {Integer.TYPE, Integer.TYPE}); 206 privateMethodLongL = JoinPointMeasurements1_aj.class.getDeclaredMethod("privatelocalMethodLongL", new Class [] {Long.TYPE, Long.TYPE}); 207 privateMethodLongD = JoinPointMeasurements1_aj.class.getDeclaredMethod("privatelocalMethodLongD", new Class [] {Double.TYPE, Double.TYPE}); 208 209 field = JoinPointMeasurements1_aj.class.getDeclaredField("theField"); 210 } 211 219 counter = 0; 220 } 221 222 protected void tearDown() 223 { 224 if (useProse) aspectInterface.teardown(); 225 } 226 227 229 public void testVirtualMethod_no_jp_NoArg() 231 { 232 startChronometer(); 233 for (int i = 0; i < RUNS; i++) localMethod(); 234 stopChronometer(); 235 236 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 237 } 238 239 241 public void testSyncVirtualMethod_no_jp_NoArg() 243 { 244 startChronometer(); 245 for (int i = 0; i < RUNS; i++) obSync.syncMethodShort(); 246 stopChronometer(); 247 248 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 249 } 250 251 253 public void testInterfaceMethod_no_jp_NoArg() 255 { 256 startChronometer(); 257 for (int i = 0; i < RUNS; i++) obInterface.interfaceMethodShort(); 258 stopChronometer(); 259 260 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 261 } 262 263 265 public void testStaticMethod_no_jp_NoArg() 267 { 268 startChronometer(); 269 for (int i = 0; i < RUNS; i++) JoinPointTestClass.staticMethodShort(); 270 stopChronometer(); 271 272 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 273 } 274 275 277 public void testSpecialMethod_no_jp_NoArg() 279 { 280 startChronometer(); 281 for (int i = 0; i < RUNS; i++) privatelocalMethod(); 282 stopChronometer(); 283 284 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 285 } 286 287 289 public void testFieldAccess_no_jp_NoArg() 291 { 292 this.theFieldAccess(RUNS); 293 294 } 296 297 299 public void testFieldModification_no_jp_NoArg() 301 { 302 this.theFieldModification(RUNS); 303 304 } 306 307 309 public void exceptionThrow() throws TestException { 310 throw exception; 311 } 312 313 public void exceptionCatch() { 314 try { 315 exceptionThrow(); 316 } catch (TestException e) {} 317 } 318 319 332 334 public void testExceptionCatch_no_jp_NoArg() 336 { 337 TestException e = new TestException(); 339 340 startChronometer(); 341 for (int i = 0; i < RUNS; i++) exceptionCatch(); 342 stopChronometer(); 343 344 } 346 347 348 354 357 public void testVirtualMethod_LongO() 359 { 360 Object obj = new Object (); 361 startChronometer(); 362 for (int i = 0; i < RUNS; i++) localMethodLongO(obj, obj); 363 stopChronometer(); 364 365 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 366 } 367 368 370 public void testSyncVirtualMethod_LongO() 372 { 373 Object obj = new Object (); 374 startChronometer(); 375 for (int i = 0; i < RUNS; i++) obSync.syncMethodLongO(obj, obj); 376 stopChronometer(); 377 378 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 379 } 380 381 383 public void testInterfaceMethod_LongO() 385 { 386 Object obj = new Object (); 387 startChronometer(); 388 for (int i = 0; i < RUNS; i++) obInterface.interfaceMethodLongO(obj, obj); 389 stopChronometer(); 390 391 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 392 } 393 394 396 public void testStaticMethod_LongO() 398 { 399 Object obj = new Object (); 400 startChronometer(); 401 for (int i = 0; i < RUNS; i++) JoinPointTestClass.staticMethodLongO(obj, obj); 402 stopChronometer(); 403 404 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 405 } 406 407 409 public void testSpecialMethod_LongO() 411 { 412 Object obj = new Object (); 413 startChronometer(); 414 for (int i = 0; i < RUNS; i++) privatelocalMethodLongO(obj, obj); 415 stopChronometer(); 416 417 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 418 } 419 420 423 424 427 public void testVirtualMethod_LongI() 429 { 430 int obj = 1; 431 startChronometer(); 432 for (int i = 0; i < RUNS; i++) localMethodLongI(obj, obj); 433 stopChronometer(); 434 435 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 436 } 437 438 440 public void testSyncVirtualMethod_LongI() 442 { 443 int obj = 1; 444 startChronometer(); 445 for (int i = 0; i < RUNS; i++) obSync.syncMethodLongI(obj, obj); 446 stopChronometer(); 447 448 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 449 } 450 451 453 public void testInterfaceMethod_LongI() 455 { 456 int obj = 1; 457 startChronometer(); 458 for (int i = 0; i < RUNS; i++) obInterface.interfaceMethodLongI(obj, obj); 459 stopChronometer(); 460 461 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 462 } 463 464 466 public void testStaticMethod_LongI() 468 { 469 int obj = 1; 470 startChronometer(); 471 for (int i = 0; i < RUNS; i++) JoinPointTestClass.staticMethodLongI(obj, obj); 472 stopChronometer(); 473 474 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 475 } 476 477 479 public void testSpecialMethod_LongI() 481 { 482 int obj = 1; 483 startChronometer(); 484 for (int i = 0; i < RUNS; i++) privatelocalMethodLongI(obj, obj); 485 stopChronometer(); 486 487 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 488 } 489 490 493 494 497 public void testVirtualMethod_LongL() 499 { 500 long obj = 1; 501 startChronometer(); 502 for (int i = 0; i < RUNS; i++) localMethodLongL(obj, obj); 503 stopChronometer(); 504 505 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 506 } 507 508 510 public void testSyncVirtualMethod_LongL() 512 { 513 long obj = 1; 514 startChronometer(); 515 for (int i = 0; i < RUNS; i++) obSync.syncMethodLongL(obj, obj); 516 stopChronometer(); 517 518 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 519 } 520 521 523 public void testInterfaceMethod_LongL() 525 { 526 long obj = 1; 527 startChronometer(); 528 for (int i = 0; i < RUNS; i++) obInterface.interfaceMethodLongL(obj, obj); 529 stopChronometer(); 530 531 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 532 } 533 534 536 public void testStaticMethod_LongL() 538 { 539 long obj = 1; 540 startChronometer(); 541 for (int i = 0; i < RUNS; i++) JoinPointTestClass.staticMethodLongL(obj, obj); 542 stopChronometer(); 543 544 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 545 } 546 547 549 public void testSpecialMethod_LongL() 551 { 552 long obj = 1; 553 startChronometer(); 554 for (int i = 0; i < RUNS; i++) privatelocalMethodLongL(obj, obj); 555 stopChronometer(); 556 557 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 558 } 559 560 563 564 567 public void testVirtualMethod_LongD() 569 { 570 double obj = 10.1; 571 startChronometer(); 572 for (int i = 0; i < RUNS; i++) localMethodLongD(obj, obj); 573 stopChronometer(); 574 575 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 576 } 577 578 580 public void testSyncVirtualMethod_LongD() 582 { 583 double obj = 10.1; 584 startChronometer(); 585 for (int i = 0; i < RUNS; i++) obSync.syncMethodLongD(obj, obj); 586 stopChronometer(); 587 588 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 589 } 590 591 593 public void testInterfaceMethod_LongD() 595 { 596 double obj = 10.1; 597 startChronometer(); 598 for (int i = 0; i < RUNS; i++) obInterface.interfaceMethodLongD(obj, obj); 599 stopChronometer(); 600 601 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 602 } 603 604 606 public void testStaticMethod_LongD() 608 { 609 double obj = 10.1; 610 startChronometer(); 611 for (int i = 0; i < RUNS; i++) JoinPointTestClass.staticMethodLongD(obj, obj); 612 stopChronometer(); 613 614 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 615 } 616 617 619 public void testSpecialMethod_LongD() 621 { 622 double obj = 10.1; 623 startChronometer(); 624 for (int i = 0; i < RUNS; i++) privatelocalMethodLongD(obj, obj); 625 stopChronometer(); 626 627 if(checkAssert) assertEquals("Hook notifications", RUNS, counter); 628 } 629 630 633 public static Test suite() { 634 return new PerformanceTestSuite(JoinPointMeasurements1_aj.class); 635 } 636 637 } | Popular Tags |