You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IfdefsAndAdvice.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* We would like to use some performance benchmarking as a way to determine
  2. if ajc is or is not generating the code for dynamic join points in all
  3. cases except for m4(). However, HotSpot is too smart for us today, and
  4. manages to optimize this away. Since the point of this code is that
  5. such an optimization is possible, I'm not sure that we can write a test case
  6. for this...
  7. So, this test case doesn't do all that good a job.
  8. */
  9. import org.aspectj.testing.Tester;
  10. public class IfdefsAndAdvice {
  11. public static void main(String[] args) {
  12. double t1 = timeIt(1);
  13. double t2 = timeIt(2);
  14. double t3 = timeIt(3);
  15. double t4 = timeIt(4);
  16. //System.out.println(t1 + ":" + t2 + ":" + t3 + ":" + t4);
  17. }
  18. public static double timeIt(int m) {
  19. callIt(m);
  20. callIt(m);
  21. final int N = 1000;
  22. long startTime = System.currentTimeMillis();
  23. for (int i = 0; i < N; i++) { callIt(m); }
  24. long stopTime = System.currentTimeMillis();
  25. return (stopTime - startTime)/1000.0;
  26. }
  27. public static void callIt(int m) {
  28. switch(m) {
  29. case 1: m1(1,2,3,4,5,6,7,8,9,10);
  30. case 2: m2(1,2,3,4,5,6,7,8,9,10);
  31. case 3: m3(1,2,3,4,5,6,7,8,9,10);
  32. case 4: m4(1,2,3,4,5,6,7,8,9,10);
  33. }
  34. }
  35. public static int m1(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10) {
  36. return i1+i2+i3+i4+i5+i6+i7+i8+i9+i10;
  37. }
  38. public static int m2(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10) {
  39. return i1+i2+i3+i4+i5+i6+i7+i8+i9+i10;
  40. }
  41. public static int m3(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10) {
  42. return i1+i2+i3+i4+i5+i6+i7+i8+i9+i10;
  43. }
  44. public static int m4(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10) {
  45. return i1+i2+i3+i4+i5+i6+i7+i8+i9+i10;
  46. }
  47. }
  48. aspect A {
  49. static final boolean DEBUG = false;
  50. before (): execution(int m1(..)) {
  51. if (DEBUG) {
  52. Object args = thisJoinPoint.getThis();
  53. } else {
  54. String sig = thisJoinPoint.toString();
  55. }
  56. }
  57. before (): execution(int m2(..)) {
  58. if (DEBUG) {
  59. Object args = thisJoinPoint.getThis();
  60. }
  61. }
  62. before (): execution(int m3(..)) {
  63. if (!DEBUG) {
  64. String sig = thisJoinPoint.toString();
  65. } else {
  66. Object args = thisJoinPoint.getThis();
  67. }
  68. }
  69. before (): execution(int m4(..)) {
  70. if (!DEBUG) {
  71. Object args = thisJoinPoint.getThis();
  72. } else {
  73. String sig = thisJoinPoint.toString();
  74. }
  75. }
  76. }