]> source.dussan.org Git - aspectj.git/commitdiff
296484:296501: annotationbinding
authoraclement <aclement>
Mon, 30 Nov 2009 21:04:08 +0000 (21:04 +0000)
committeraclement <aclement>
Mon, 30 Nov 2009 21:04:08 +0000 (21:04 +0000)
tests/bugs167/pr296484/AnnoBinding.java [new file with mode: 0644]
tests/bugs167/pr296484/Perf.java [new file with mode: 0644]
tests/bugs167/pr296501/StringBinding.java [new file with mode: 0644]
tests/features161/optimizedAnnotationBinding/CaseFive.java
tests/src/org/aspectj/systemtest/ajc161/annotationFieldBinding.xml
tests/src/org/aspectj/systemtest/ajc167/Ajc167Tests.java
tests/src/org/aspectj/systemtest/ajc167/ajc167.xml

diff --git a/tests/bugs167/pr296484/AnnoBinding.java b/tests/bugs167/pr296484/AnnoBinding.java
new file mode 100644 (file)
index 0000000..08135e5
--- /dev/null
@@ -0,0 +1,81 @@
+import org.aspectj.lang.*;
+import org.aspectj.lang.reflect.*;
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME) 
+@interface Marker {
+   String message();
+}
+
+public class AnnoBinding {
+  public static void main(String []argv) {
+    long stime = System.currentTimeMillis();
+    for (int i=0;i<10000;i++) {
+       runOne();
+    }
+    long etime = System.currentTimeMillis();
+    long manual = (etime-stime);
+    stime = System.currentTimeMillis();
+    for (int i=0;i<10000;i++) {
+       runTwo();
+    }
+    etime = System.currentTimeMillis();
+    long woven = (etime-stime);
+    System.out.println("woven="+woven+" manual="+manual);
+    if (woven>manual) {
+      throw new RuntimeException("woven="+woven+" manual="+manual);
+    }
+    if (X.a!=X.b) {
+      throw new RuntimeException("a="+X.a+" b="+X.b);
+    }
+  }
+
+  @Marker(message="string")
+  public static void runOne() {
+  }
+
+  @Marker(message="string")
+  public static void runTwo() {
+  }
+  
+  static Annotation ajc$anno$1;
+}
+
+aspect X {
+  
+   pointcut pManual(): execution(@Marker * runOne(..));
+   pointcut pWoven(Marker l): execution(@Marker * runTwo(..)) && @annotation(l);
+
+   public static int a,b;
+
+   before(): pManual() {
+     Marker marker = (Marker) ((MethodSignature) thisJoinPointStaticPart.getSignature()).getMethod().getAnnotation(Marker.class);
+     String s = marker.message();
+     a+=s.length();
+   }
+
+   before(Marker l): pWoven(l) {
+     String s = l.message();
+     b+=s.length();
+   }
+}
+
+//
+//0:   invokestatic    #96; //Method X.aspectOf:()LX;
+//3:   getstatic       #108; //Field ajc$anno$0:Ljava/lang/Annotation;
+//6:   dup
+//7:   ifnonnull       30
+//10:  ldc     #1; //class AnnoBinding
+//12:  ldc     #109; //String runTwo
+//14:  iconst_0
+//15:  anewarray       #111; //class java/lang/Class
+//18:  invokevirtual   #115; //Method java/lang/Class.getDeclaredMethod:(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Me
+//d;
+//21:  ldc     #104; //class Marker
+//23:  invokevirtual   #121; //Method java/lang/reflect/Method.getAnnotation:(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
+//26:  dup
+//27:  putstatic       #108; //Field ajc$anno$0:Ljava/lang/Annotation;
+//30:  nop
+//31:  checkcast       #104; //class Marker
+//34:  invokevirtual   #125; //Method X.ajc$before$X$2$ea6844ce:(LMarker;)V
+//37:  return
\ No newline at end of file
diff --git a/tests/bugs167/pr296484/Perf.java b/tests/bugs167/pr296484/Perf.java
new file mode 100644 (file)
index 0000000..694c790
--- /dev/null
@@ -0,0 +1,88 @@
+import org.aspectj.lang.*;
+import org.aspectj.lang.reflect.*;
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME) 
+@interface Marker {
+   String message();
+}
+
+public class Perf {
+       
+  public static void main(String []argv) {
+       run(true);
+       run(false);
+  }
+  
+  public static void run(boolean warmup) {
+    long stime = System.currentTimeMillis();
+    for (int i=0;i<1000000;i++) {
+       runOne();
+    }
+    long etime = System.currentTimeMillis();
+    
+    long manual = (etime-stime);
+    stime = System.currentTimeMillis();
+    for (int i=0;i<1000000;i++) {
+       runTwo();
+    }
+    etime = System.currentTimeMillis();
+    long woven = (etime-stime);
+
+    stime = System.currentTimeMillis();
+    for (int i=0;i<1000000;i++) {
+       runThree();
+    }
+    etime = System.currentTimeMillis();
+    long optimal = (etime-stime);
+
+    if (!warmup) {
+       System.out.println("Manually fetching annotation with getAnnotation(): "+manual+"ms");
+       System.out.println("Binding annotation with @annotation(Marker): "+woven+"ms");
+       System.out.println("Binding annotation value with @annotation(Marker(message)): "+optimal+"ms");
+    }
+    if (woven>manual) {
+       throw new RuntimeException("woven = "+woven+" manual = "+manual);
+    }
+    if (optimal>woven) {
+       throw new RuntimeException("optimal = "+optimal+" woven = "+woven);
+    }
+  }
+
+  @Marker(message="string")
+  public static void runOne() {
+  }
+
+  @Marker(message="string")
+  public static void runTwo() {
+  }
+
+  @Marker(message="string")
+  public static void runThree() {
+  }
+}
+
+aspect X {
+   public static int a,b,c;
+  
+   // CaseOne: annotation fetching is done in the advice:
+   pointcut adviceRetrievesAnnotation(): execution(@Marker * runOne(..));
+   before(): adviceRetrievesAnnotation() {
+     Marker marker = (Marker) ((MethodSignature) thisJoinPointStaticPart.getSignature()).getMethod().getAnnotation(Marker.class);
+     String s = marker.message();
+     a+=s.length();
+   }
+
+   // CaseTwo: annotation binding is done in the pointcut, advice retrieves message
+   pointcut pointcutBindsAnnotation(Marker l): execution(@Marker * runTwo(..)) && @annotation(l);
+   before(Marker l): pointcutBindsAnnotation(l) {
+     String s = l.message();
+     b+=s.length();
+   }
+
+   // CaseThree: annotation binding directly targets the message value in the annotation
+   pointcut pointcutBindsAnnotationValue(String msg): execution(@Marker * runThree(..)) && @annotation(Marker(msg));
+   before(String s): pointcutBindsAnnotationValue(s) {
+     c+=s.length();
+   }
+}
\ No newline at end of file
diff --git a/tests/bugs167/pr296501/StringBinding.java b/tests/bugs167/pr296501/StringBinding.java
new file mode 100644 (file)
index 0000000..7345fd1
--- /dev/null
@@ -0,0 +1,19 @@
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME) 
+@interface Wibble {
+  String message();
+}
+
+public class StringBinding {
+   
+  @Wibble(message="hello world")
+  public static void main(String []argv) {
+  }
+}
+
+aspect X {
+  before(String msg): execution(* *(..)) && @annotation(Wibble(msg)) {
+    System.out.println(msg);
+  }
+}
index 59b7c767559a838fcc2852bbca44c2f18430a68f..dc168f154de0accbc61b659abaf5c51b79ec9d43 100644 (file)
@@ -8,16 +8,16 @@ public class CaseFive {
     o.a();
   }
 
-  @Anno("hello") public void a() {}
+  @Anno(4) public void a() {}
 
 }
 
 @Retention(RetentionPolicy.RUNTIME)
-@interface Anno { String value(); }
+@interface Anno { int value(); }
 
 aspect X {
 
-  before(String l): execution(@Anno * *(..)) && @annotation(Anno(l)) {
+  before(int l): execution(@Anno * *(..)) && @annotation(Anno(l)) {
     System.out.println(l);
   }
 }
index f84e08f08990acd547a53af7d630d14e12f6ba0c..00ff8a5f06e0469f7acc95d8d3b54698f5e58a0a 100644 (file)
@@ -39,7 +39,7 @@
    
    <ajc-test dir="features161/optimizedAnnotationBinding" title="case five - not an enum - compiler limitation">
      <compile options="-1.5" files="CaseFive.java">
-       <message kind="error" line="20" text="The field within the annotation must be an Enum. 'java.lang.String' is not an Enum"/>
+       <message kind="error" line="20" text="The field within the annotation must be an enum or string. 'int' is not"/>
      </compile>
    </ajc-test>
    
    
    <ajc-test dir="features161/optimizedAnnotationBinding" title="case thirteen - bug npe">
      <compile options="-1.5" files="CaseThirteen.java">
-       <message kind="error" line="31" text="The field within the annotation must be an Enum"/>
        <message kind="error" line="31" text="No field of type 'java.lang.String'"/>
        <message kind="error" line="31" text="When using @annotation"/>
        <message kind="error" line="32" text="cannot be resolved"/>
index 98a7a6f5f25fd017328f075f6bc03f5892efb9e6..8e59dd28f239eec177285f5daa19ffb422bdec14 100644 (file)
@@ -18,18 +18,35 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
 
 public class Ajc167Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
 
+       public void testOptimizingAnnotationStringValueBinding() {
+               runTest("optimizing string anno value binding");
+       }
+
+       public void testOptimizingAnnotationBinding() {
+               runTest("optimizing annotation binding");
+       }
+
+       public void testOptimizingAnnotationBindingPerfTest() {
+               runTest("optimizing annotation binding - 2");
+       }
+/*
+       public void testPerThisLTW_295092() {
+               runTest("perthis ltw");
+       }
+*/
+
        public void testNpeOnBrokenCode_296054() {
                runTest("npe on broken code");
        }
-       
+
        public void testBrokenGeneratedCode_296040() {
                runTest("broken generated code");
        }
-       
+
        public void testHierarchyBuilderNPE_pr293457() {
                runTest("hierarchy builder npe");
        }
-       
+
        public void testTimers_1() {
                runTest("timers - 1");
        }
index 1ab32fc083bef4d12ed9bb5a4c5fbf96c7c3d4df..9fad6062df296e5aed08c532fb3991d843b4f659 100644 (file)
@@ -3,6 +3,31 @@
 <suite>
 
 
+  <ajc-test dir="bugs167/pr296501" title="optimizing string anno value binding">
+     <compile files="StringBinding.java" options="-1.5"/>
+     <run class="StringBinding">
+       <stdout>
+         <line text="hello world"/>
+       </stdout>
+     </run>
+  </ajc-test>
+  
+  <ajc-test dir="bugs167/pr296484" title="optimizing annotation binding">
+     <compile files="AnnoBinding.java" options="-1.5"/>
+     <run class="AnnoBinding"/>
+  </ajc-test>
+  
+  <ajc-test dir="bugs167/pr296484" title="optimizing annotation binding - 2">
+     <compile files="Perf.java" options="-1.5"/>
+     <run class="Perf"/>
+  </ajc-test>
+  
+  <ajc-test dir="bugs167/pr295092" title="perthis ltw">
+     <compile files="AbstractAspect.aj" options="-1.5" outjar="aspects.jar"/>
+     <compile files="Wibble.java"/>
+     <run class="Wibble" ltw="aop.xml" classpath="aspects.jar"/>
+  </ajc-test>
+
   <ajc-test dir="bugs167/pr296054" title="npe on broken code">
      <compile files="Demo.java AnnotAspect.aj" options="-1.5 -emacssym">
        <message kind="error" text="The value for"/>