| 1 7 package measurements.suites; 8 9 import java.lang.reflect.Field ; 10 import java.lang.reflect.Method ; 11 12 import junit.framework.Assert; 13 import junit.framework.Test; 14 import ch.ethz.inf.iks.jvmai.jvmdi.FieldAccessJoinPointImpl; 15 import ch.ethz.inf.util.junit.PerformanceTest; 16 import ch.ethz.inf.util.junit.PerformanceTestSuite; 17 import ch.ethz.jvmai.*; 18 19 29 public class JVMAIMeasurement extends PerformanceTest { 30 31 33 34 public void theMethodToCall() { } 35 public int theFieldToAccess = 0; 36 37 public static class TestHook extends JoinPointHook 38 { 39 public void onFieldAccess (FieldAccessJoinPoint joinPoint) { } 40 public void onFieldModification(FieldModificationJoinPoint joinPoint) { } 41 public void onMethodEntry (MethodEntryJoinPoint joinPoint) { } 42 public void onMethodExit (MethodExitJoinPoint joinPoint) { } 43 public void onExceptionThrow (ExceptionJoinPoint joinPoint) { } 44 public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { } 45 public void onClassLoad (Class cls) { } 46 } 47 48 final boolean useProse; 49 50 54 public JVMAIMeasurement(String name) 55 { 56 super(name); 57 String proseParam = System.getProperty("useprose"); 58 if(proseParam==null) 59 useProse = isDebuggerEnabled(); 60 else 61 useProse = proseParam.toUpperCase().equals("TRUE"); 62 63 if(useProse) 64 { 65 if (isDebuggerEnabled()) 67 RANGE = new int[]{ 10000}; 68 else 69 RANGE = new int[]{ 1000000}; 70 } 71 else 72 RANGE = new int[]{ 10000000 }; 73 74 } 75 76 JVMAspectInterface aspectInterface; 77 78 Method method; 79 Field field; 80 Method interfaceMethod; 81 TestHook hook; 82 83 protected void setUp() 84 { 85 86 hook = new TestHook(); 87 hook.onFieldAccess(null); 89 hook.onFieldModification(null); 90 hook.onMethodEntry(null); 91 hook.onMethodExit(null); 92 this.theMethodToCall(); 93 int n = this.theFieldToAccess; 94 this.theFieldToAccess = 1; 95 96 if (!useProse) return; 97 try 98 { 99 String providerName = System.getProperty("ch.ethz.prose.JVMAIProvider"); 100 Class providerClass = Class.forName(providerName); 101 Provider provider = (Provider)providerClass.newInstance(); 102 103 aspectInterface = provider.getAspectInterface(); 104 105 aspectInterface.startup(new String []{"ch.ethz.prose."},true); 106 107 method = JVMAIMeasurement.class.getDeclaredMethod("theMethodToCall",new Class []{}); 108 interfaceMethod = TestClass1.class.getDeclaredMethod("interfaceMethodLong", 109 new Class []{Object .class, 110 Object .class}); 111 field = JVMAIMeasurement.class.getDeclaredField("theFieldToAccess"); 112 113 aspectInterface.setJoinPointHook(hook); 115 aspectInterface.setMethodEntryWatch(method,new Object ()); 116 aspectInterface.setMethodExitWatch(method,new Object ()); 117 aspectInterface.setFieldAccessWatch(field,new Object ()); 118 aspectInterface.setFieldModificationWatch(field,new Object ()); 119 aspectInterface.clearMethodEntryWatch(method); 120 aspectInterface.clearMethodExitWatch(method); 121 aspectInterface.clearFieldAccessWatch(field); 122 aspectInterface.clearFieldModificationWatch(field); 123 aspectInterface.setJoinPointHook(null); 124 aspectInterface.suspendNotification(Thread.currentThread()); 125 aspectInterface.resumeNotification(Thread.currentThread()); 126 127 } 128 catch (Exception e) 129 { 130 Assert.fail("loading provider or initializing aspect-interface failed"); 131 } 132 } 133 134 protected void tearDown() 135 { 136 } 137 138 public void testHook() 139 { 140 FieldAccessJoinPoint joinPoint = new FieldAccessJoinPointImpl(null,null); 141 JoinPointHook jpHook = hook; 142 jpHook.onFieldAccess(null); 144 jpHook.onFieldModification(null); 145 jpHook.onMethodEntry(null); 146 jpHook.onMethodExit(null); 147 startChronometer(); 148 for(int i =0; i<RUNS; i++) 149 jpHook.onFieldAccess(joinPoint); 150 stopChronometer(); 151 } 152 153 public void testEmptyFieldAccess() 154 { 155 int n = 0; 156 157 startChronometer(); 158 for(int i =0; i<RUNS; i++) 159 n = 0; 160 stopChronometer(); 161 } 162 163 public void testDoubleField() 164 { 165 startChronometer(); 166 for(int i =0; i<RUNS; i++) 167 this.theFieldToAccess = this.theFieldToAccess; 168 stopChronometer(); 169 } 170 171 173 public void testMethod() 174 { 175 startChronometer(); 176 for(int i =0; i<RUNS; i++) 177 this.theMethodToCall(); 178 stopChronometer(); 179 } 180 181 public void testMethod_Hook() 182 { 183 if(useProse) 184 { 185 aspectInterface.setJoinPointHook(hook); 186 } 187 188 startChronometer(); 189 for(int i =0; i<RUNS; i++) 190 this.theMethodToCall(); 191 stopChronometer(); 192 193 if(useProse) 194 { 195 aspectInterface.setJoinPointHook(null); 196 } 197 198 } 199 200 public void testMethod_Suspended() 201 { 202 if(useProse) 203 { 204 aspectInterface.suspendNotification(Thread.currentThread()); 205 } 206 207 startChronometer(); 208 for(int i =0; i<RUNS; i++) 209 this.theMethodToCall(); 210 stopChronometer(); 211 212 if(useProse) 213 { 214 aspectInterface.resumeNotification(Thread.currentThread()); 215 } 216 } 217 218 public void testMethod_HookSuspended() 219 { 220 if(useProse) 221 { 222 aspectInterface.suspendNotification(Thread.currentThread()); 223 aspectInterface.setJoinPointHook(hook); 224 } 225 226 startChronometer(); 227 for(int i =0; i<RUNS; i++) 228 this.theMethodToCall(); 229 stopChronometer(); 230 231 if(useProse) 232 { 233 aspectInterface.resumeNotification(Thread.currentThread()); 234 aspectInterface.setJoinPointHook(null); 235 } 236 } 237 238 240 public void testMethodEntryWatch() 241 { 242 if(useProse) 243 { 244 aspectInterface.setMethodEntryWatch(method,new Object ()); 245 } 246 247 startChronometer(); 248 for(int i =0; i<RUNS; i++) 249 this.theMethodToCall(); 250 stopChronometer(); 251 252 if(useProse) 253 { 254 aspectInterface.clearMethodEntryWatch(method); 255 } 256 257 } 258 259 public void testMethodEntryWatch_Hook() 260 { 261 if(useProse) 262 { 263 aspectInterface.setMethodEntryWatch(method,new Object ()); 264 aspectInterface.setJoinPointHook(hook); 265 } 266 267 startChronometer(); 268 for(int i =0; i<RUNS; i++) 269 this.theMethodToCall(); 270 stopChronometer(); 271 272 if(useProse) 273 { 274 aspectInterface.clearMethodEntryWatch(method); 275 aspectInterface.setJoinPointHook(null); 276 } 277 } 278 279 public void testMethodEntryWatch_Suspended() 280 { 281 if(useProse) 282 { 283 aspectInterface.setMethodEntryWatch(method,new Object ()); 284 aspectInterface.suspendNotification(Thread.currentThread()); 285 } 286 287 startChronometer(); 288 for(int i =0; i<RUNS; i++) 289 this.theMethodToCall(); 290 stopChronometer(); 291 292 if(useProse) 293 { 294 aspectInterface.clearMethodEntryWatch(method); 295 aspectInterface.resumeNotification(Thread.currentThread()); 296 } 297 } 298 299 public void testMethodEntryWatch_HookSuspended() 300 { 301 if(useProse) 302 { 303 aspectInterface.setMethodEntryWatch(method,new Object ()); 304 aspectInterface.suspendNotification(Thread.currentThread()); 305 aspectInterface.setJoinPointHook(hook); 306 } 307 308 startChronometer(); 309 for(int i =0; i<RUNS; i++) 310 this.theMethodToCall(); 311 stopChronometer(); 312 313 if(useProse) 314 { 315 aspectInterface.clearMethodEntryWatch(method); 316 aspectInterface.resumeNotification(Thread.currentThread()); 317 aspectInterface.setJoinPointHook(null); 318 } 319 } 320 321 323 325 public void testInterfaceMethod() 326 { 327 String x = "hello"; 328 TestInterface obj = new TestClass1(); 329 startChronometer(); 330 for(int i =0; i<RUNS; i++) 331 obj.interfaceMethodLong(x,x); 332 stopChronometer(); 333 } 334 335 public void testInterfaceEntryWatch() 336 { 337 String x = "hello"; 338 TestInterface obj = new TestClass1(); 339 if(useProse) 340 { 341 aspectInterface.setMethodEntryWatch(interfaceMethod,new Object ()); 342 } 343 344 startChronometer(); 345 for(int i =0; i<RUNS; i++) 346 obj.interfaceMethodLong(x,x); 347 stopChronometer(); 348 349 if(useProse) 350 { 351 aspectInterface.clearMethodEntryWatch(interfaceMethod); 352 } 353 354 } 355 356 public void testInterfaceEntryWatch_Hook() 357 { 358 String x = "hello"; 359 TestInterface obj = new TestClass1(); 360 if(useProse) 361 { 362 aspectInterface.setMethodEntryWatch(interfaceMethod,new Object ()); 363 aspectInterface.setJoinPointHook(hook); 364 } 365 366 startChronometer(); 367 for(int i =0; i<RUNS; i++) 368 obj.interfaceMethodLong(x,x); 369 stopChronometer(); 370 371 if(useProse) 372 { 373 aspectInterface.clearMethodEntryWatch(interfaceMethod); 374 aspectInterface.setJoinPointHook(null); 375 } 376 } 377 378 public void testInterfaceEntryWatch_Suspended() 379 { 380 String x = "hello"; 381 TestInterface obj = new TestClass1(); 382 if(useProse) 383 { 384 aspectInterface.setMethodEntryWatch(interfaceMethod,new Object ()); 385 aspectInterface.suspendNotification(Thread.currentThread()); 386 } 387 388 startChronometer(); 389 for(int i =0; i<RUNS; i++) 390 obj.interfaceMethodLong(x,x); 391 stopChronometer(); 392 393 if(useProse) 394 { 395 aspectInterface.clearMethodEntryWatch(interfaceMethod); 396 aspectInterface.resumeNotification(Thread.currentThread()); 397 } 398 } 399 400 public void testInterfaceEntryWatch_HookSuspended() 401 { 402 String x = "hello"; 403 TestInterface obj = new TestClass1(); 404 if(useProse) 405 { 406 aspectInterface.setMethodEntryWatch(interfaceMethod,new Object ()); 407 aspectInterface.suspendNotification(Thread.currentThread()); 408 aspectInterface.setJoinPointHook(hook); 409 } 410 411 startChronometer(); 412 for(int i =0; i<RUNS; i++) 413 obj.interfaceMethodLong(x,x); 414 stopChronometer(); 415 416 if(useProse) 417 { 418 aspectInterface.clearMethodEntryWatch(interfaceMethod); 419 aspectInterface.resumeNotification(Thread.currentThread()); 420 aspectInterface.setJoinPointHook(null); 421 } 422 } 423 424 public void testInterfaceExitWatch() 425 { 426 String x = "hello"; 427 TestInterface obj = new TestClass1(); 428 if(useProse) 429 { 430 aspectInterface.setMethodExitWatch(interfaceMethod,new Object ()); 431 } 432 433 startChronometer(); 434 for(int i =0; i<RUNS; i++) 435 obj.interfaceMethodLong(x,x); 436 stopChronometer(); 437 438 if(useProse) 439 { 440 aspectInterface.clearMethodExitWatch(interfaceMethod); 441 } 442 443 } 444 445 public void testInterfaceExitWatch_Hook() 446 { 447 String x = "hello"; 448 TestInterface obj = new TestClass1(); 449 if(useProse) 450 { 451 aspectInterface.setMethodExitWatch(interfaceMethod,new Object ()); 452 aspectInterface.setJoinPointHook(hook); 453 } 454 455 startChronometer(); 456 for(int i =0; i<RUNS; i++) 457 obj.interfaceMethodLong(x,x); 458 stopChronometer(); 459 460 if(useProse) 461 { 462 aspectInterface.clearMethodExitWatch(interfaceMethod); 463 aspectInterface.setJoinPointHook(null); 464 } 465 } 466 467 public void testInterfaceExitWatch_Suspended() 468 { 469 String x = "hello"; 470 TestInterface obj = new TestClass1(); 471 if(useProse) 472 { 473 aspectInterface.setMethodExitWatch(interfaceMethod,new Object ()); 474 aspectInterface.suspendNotification(Thread.currentThread()); 475 } 476 477 startChronometer(); 478 for(int i =0; i<RUNS; i++) 479 obj.interfaceMethodLong(x,x); 480 stopChronometer(); 481 482 if(useProse) 483 { 484 aspectInterface.clearMethodExitWatch(interfaceMethod); 485 aspectInterface.resumeNotification(Thread.currentThread()); 486 } 487 } 488 489 public void testInterfaceExitWatch_HookSuspended() 490 { 491 String x = "hello"; 492 TestInterface obj = new TestClass1(); 493 if(useProse) 494 { 495 aspectInterface.setMethodExitWatch(interfaceMethod,new Object ()); 496 aspectInterface.suspendNotification(Thread.currentThread()); 497 aspectInterface.setJoinPointHook(hook); 498 } 499 500 startChronometer(); 501 for(int i =0; i<RUNS; i++) 502 obj.interfaceMethodLong(x,x); 503 stopChronometer(); 504 505 if(useProse) 506 { 507 aspectInterface.clearMethodExitWatch(interfaceMethod); 508 aspectInterface.resumeNotification(Thread.currentThread()); 509 aspectInterface.setJoinPointHook(null); 510 } 511 } 512 513 public void testMethodExitWatch() 515 { 516 if(useProse) 517 { 518 aspectInterface.setMethodExitWatch(method,new Object ()); 519 } 520 521 startChronometer(); 522 for(int i =0; i<RUNS; i++) 523 this.theMethodToCall(); 524 stopChronometer(); 525 526 if(useProse) 527 { 528 aspectInterface.clearMethodExitWatch(method); 529 } 530 531 } 532 533 public void testMethodExitWatch_Hook() 534 { 535 if(useProse) 536 { 537 aspectInterface.setMethodExitWatch(method,new Object ()); 538 aspectInterface.setJoinPointHook(hook); 539 } 540 541 startChronometer(); 542 for(int i =0; i<RUNS; i++) 543 this.theMethodToCall(); 544 stopChronometer(); 545 546 if(useProse) 547 { 548 aspectInterface.clearMethodExitWatch(method); 549 aspectInterface.setJoinPointHook(null); 550 } 551 } 552 553 public void testMethodExitWatch_Suspended() 554 { 555 if(useProse) 556 { 557 aspectInterface.setMethodExitWatch(method,new Object ()); 558 aspectInterface.suspendNotification(Thread.currentThread()); 559 } 560 561 startChronometer(); 562 for(int i =0; i<RUNS; i++) 563 this.theMethodToCall(); 564 stopChronometer(); 565 566 if(useProse) 567 { 568 aspectInterface.clearMethodExitWatch(method); 569 aspectInterface.resumeNotification(Thread.currentThread()); 570 } 571 } 572 573 public void testMethodExitWatch_HookSuspended() 574 { 575 if(useProse) 576 { 577 aspectInterface.setMethodExitWatch(method,new Object ()); 578 aspectInterface.suspendNotification(Thread.currentThread()); 579 aspectInterface.setJoinPointHook(hook); 580 } 581 582 startChronometer(); 583 for(int i =0; i<RUNS; i++) 584 this.theMethodToCall(); 585 stopChronometer(); 586 587 if(useProse) 588 { 589 aspectInterface.clearMethodExitWatch(method); 590 aspectInterface.resumeNotification(Thread.currentThread()); 591 aspectInterface.setJoinPointHook(null); 592 } 593 } 594 596 public void testFieldAccess() 597 { 598 int n = 0; 599 600 startChronometer(); 601 for(int i =0; i<RUNS; i++) 602 n = this.theFieldToAccess; 603 stopChronometer(); 604 } 605 606 public void testFieldAccess_Hook() 607 { 608 if(useProse) 609 { 610 aspectInterface.setJoinPointHook(hook); 611 } 612 int n = 0; 613 614 startChronometer(); 615 for(int i =0; i<RUNS; i++) 616 n = this.theFieldToAccess; 617 stopChronometer(); 618 619 if(useProse) 620 { 621 aspectInterface.setJoinPointHook(null); 622 } 623 } 624 625 public void testFieldAccess_Suspended() 626 { 627 if(useProse) 628 { 629 aspectInterface.suspendNotification(Thread.currentThread()); 630 } 631 int n = 0; 632 633 startChronometer(); 634 for(int i =0; i<RUNS; i++) 635 n = this.theFieldToAccess; 636 stopChronometer(); 637 638 if(useProse) 639 { 640 aspectInterface.resumeNotification(Thread.currentThread()); 641 } 642 } 643 644 public void testFieldAccess_HookSuspended() 645 { 646 if(useProse) 647 { 648 aspectInterface.suspendNotification(Thread.currentThread()); 649 aspectInterface.setJoinPointHook(hook); 650 } 651 int n = 0; 652 653 startChronometer(); 654 for(int i =0; i<RUNS; i++) 655 n = this.theFieldToAccess; 656 stopChronometer(); 657 658 if(useProse) 659 { 660 aspectInterface.resumeNotification(Thread.currentThread()); 661 aspectInterface.setJoinPointHook(null); 662 } 663 } 664 665 667 public void testFieldModification() 668 { 669 startChronometer(); 670 for(int i =0; i<RUNS; i++) 671 this.theFieldToAccess = 1; 672 stopChronometer(); 673 } 674 675 public void testFieldModification_Hook() 676 { 677 if(useProse) 678 { 679 aspectInterface.setJoinPointHook(hook); 680 } 681 682 startChronometer(); 683 for(int i =0; i<RUNS; i++) 684 this.theFieldToAccess = 1; 685 stopChronometer(); 686 687 if(useProse) 688 { 689 aspectInterface.setJoinPointHook(null); 690 } 691 } 692 693 public void testFieldModification_Suspended() 694 { 695 if(useProse) 696 { 697 aspectInterface.suspendNotification(Thread.currentThread()); 698 } 699 700 startChronometer(); 701 for(int i =0; i<RUNS; i++) 702 this.theFieldToAccess = 1; 703 stopChronometer(); 704 705 if(useProse) 706 { 707 aspectInterface.resumeNotification(Thread.currentThread()); 708 } 709 } 710 711 public void testFieldModification_HookSuspended() 712 { 713 if(useProse) 714 { 715 aspectInterface.suspendNotification(Thread.currentThread()); 716 aspectInterface.setJoinPointHook(hook); 717 } 718 719 startChronometer(); 720 for(int i =0; i<RUNS; i++) 721 this.theFieldToAccess = 1; 722 stopChronometer(); 723 724 if(useProse) 725 { 726 aspectInterface.resumeNotification(Thread.currentThread()); 727 aspectInterface.setJoinPointHook(null); 728 } 729 } 730 731 733 public void testFieldAccessWatch() 734 { 735 if(useProse) 736 { 737 aspectInterface.setFieldAccessWatch(field,new Object ()); 738 } 739 int n = 0; 740 741 startChronometer(); 742 for(int i =0; i<RUNS; i++) 743 n = this.theFieldToAccess; 744 stopChronometer(); 745 746 if(useProse) 747 { 748 aspectInterface.clearFieldAccessWatch(field); 749 } 750 } 751 752 public void testFieldAccessWatch_Hook() 753 { 754 if(useProse) 755 { 756 aspectInterface.setFieldAccessWatch(field,new Object ()); 757 aspectInterface.setJoinPointHook(hook); 758 } 759 int n = 0; 760 761 startChronometer(); 762 for(int i =0; i<RUNS; i++) 763 n = this.theFieldToAccess; 764 stopChronometer(); 765 766 if(useProse) 767 { 768 aspectInterface.clearFieldAccessWatch(field); 769 aspectInterface.setJoinPointHook(null); 770 } 771 } 772 773 public void testFieldAccessWatch_Suspended() 774 { 775 if(useProse) 776 { 777 aspectInterface.setFieldAccessWatch(field,new Object ()); 778 aspectInterface.suspendNotification(Thread.currentThread()); 779 } 780 int n = 0; 781 782 startChronometer(); 783 for(int i =0; i<RUNS; i++) 784 n = this.theFieldToAccess; 785 stopChronometer(); 786 787 if(useProse) 788 { 789 aspectInterface.clearFieldAccessWatch(field); 790 aspectInterface.resumeNotification(Thread.currentThread()); 791 } 792 } 793 794 public void testFieldAccessWatch_HookSuspended() 795 { 796 if(useProse) 797 { 798 aspectInterface.setFieldAccessWatch(field,new Object ()); 799 aspectInterface.suspendNotification(Thread.currentThread()); 800 aspectInterface.setJoinPointHook(hook); 801 } 802 int n = 0; 803 804 startChronometer(); 805 for(int i =0; i<RUNS; i++) 806 n = this.theFieldToAccess; 807 stopChronometer(); 808 809 if(useProse) 810 { 811 aspectInterface.clearFieldAccessWatch(field); 812 aspectInterface.resumeNotification(Thread.currentThread()); 813 aspectInterface.setJoinPointHook(null); 814 } 815 } 816 817 819 public void testFieldModificationWatch() 820 { 821 if(useProse) 822 { 823 aspectInterface.setFieldModificationWatch(field,new Object ()); 824 } 825 826 startChronometer(); 827 for(int i =0; i<RUNS; i++) 828 this.theFieldToAccess = 1; 829 stopChronometer(); 830 831 if(useProse) 832 { 833 aspectInterface.clearFieldModificationWatch(field); 834 } 835 } 836 837 public void testFieldModificationWatch_Hook() 838 { 839 if(useProse) 840 { 841 aspectInterface.setFieldModificationWatch(field,new Object ()); 842 aspectInterface.setJoinPointHook(hook); 843 } 844 845 startChronometer(); 846 for(int i =0; i<RUNS; i++) 847 this.theFieldToAccess = 1; 848 stopChronometer(); 849 850 if(useProse) 851 { 852 aspectInterface.clearFieldModificationWatch(field); 853 aspectInterface.setJoinPointHook(null); 854 } 855 } 856 857 public void testFieldModificationWatch_Suspended() 858 { 859 if(useProse) 860 { 861 aspectInterface.setFieldModificationWatch(field,new Object ()); 862 aspectInterface.suspendNotification(Thread.currentThread()); 863 } 864 865 startChronometer(); 866 for(int i =0; i<RUNS; i++) 867 this.theFieldToAccess = 1; 868 stopChronometer(); 869 870 if(useProse) 871 { 872 aspectInterface.clearFieldModificationWatch(field); 873 aspectInterface.resumeNotification(Thread.currentThread()); 874 } 875 } 876 877 public void test1FieldModificationWatch_HookSuspended() 878 { 879 if(useProse) 880 { 881 aspectInterface.setFieldModificationWatch(field,new Object ()); 882 aspectInterface.suspendNotification(Thread.currentThread()); 883 aspectInterface.setJoinPointHook(hook); 884 } 885 886 startChronometer(); 887 for(int i =0; i<RUNS; i++) 888 this.theFieldToAccess = 1; 889 stopChronometer(); 890 891 if(useProse) 892 { 893 aspectInterface.clearFieldModificationWatch(field); 894 aspectInterface.resumeNotification(Thread.currentThread()); 895 aspectInterface.setJoinPointHook(null); 896 } 897 } 898 899 901 905 public static Test suite() 906 { 907 return new PerformanceTestSuite(JVMAIMeasurement.class); 908 } 909 910 } 911 912 913 | Popular Tags |