]> source.dussan.org Git - aspectj.git/commitdiff
356612
authoraclement <aclement>
Fri, 2 Sep 2011 22:33:11 +0000 (22:33 +0000)
committeraclement <aclement>
Fri, 2 Sep 2011 22:33:11 +0000 (22:33 +0000)
tests/bugs1612/pr356612/AnnoBinding.java [new file with mode: 0644]
tests/bugs1612/pr356612/AnnoBinding2.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc1612/Ajc1612Tests.java
tests/src/org/aspectj/systemtest/ajc1612/ajc1612.xml

diff --git a/tests/bugs1612/pr356612/AnnoBinding.java b/tests/bugs1612/pr356612/AnnoBinding.java
new file mode 100644 (file)
index 0000000..7bee9c5
--- /dev/null
@@ -0,0 +1,68 @@
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import org.aspectj.lang.reflect.FieldSignature;
+
+@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")
+       static int field1;
+
+       @Marker(message = "string")
+       static int field2;
+
+       public static void runOne() {
+               field1 = field1 * 2; // set and get jps
+       }
+
+       public static void runTwo() {
+               field1 = field1 * 2; // set and get jps
+       }
+
+}
+
+aspect X {
+         pointcut pManual(): withincode(* runOne(..)) && get(@Marker * *);
+         pointcut pWoven(Marker l): withincode(* runTwo(..)) && get(@Marker * * ) && @annotation(l);
+
+          public static int a,b;
+
+          before(): pManual() {
+            Marker marker = (Marker) ((FieldSignature) thisJoinPointStaticPart.getSignature()).getField().getAnnotation(Marker.class);
+            String s = marker.message();
+            a+=s.length();
+          }
+
+          before(Marker l): pWoven(l) {
+            String s = l.message();
+            b+=s.length();
+          }
+
+
+}
diff --git a/tests/bugs1612/pr356612/AnnoBinding2.java b/tests/bugs1612/pr356612/AnnoBinding2.java
new file mode 100644 (file)
index 0000000..6c9b0b2
--- /dev/null
@@ -0,0 +1,48 @@
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import org.aspectj.lang.reflect.FieldSignature;
+
+import com.sun.org.apache.bcel.internal.classfile.Field;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Marker {
+       String message();
+}
+
+public class AnnoBinding2 {
+       public static void main(String[] argv) {
+               runOne();
+               runTwo();
+               java.lang.reflect.Field[] fs = AnnoBinding2.class.getDeclaredFields();
+               int count = 0;
+               for (java.lang.reflect.Field f: fs) {
+                       if (f.getName().startsWith("ajc$anno")) {
+                               count++;
+                       }
+               }
+               System.out.println(count+" ajc$anno$NNN fields");
+       }
+
+       @Marker(message = "foo")
+       static int field1;
+
+       @Marker(message = "bar")
+       static int field2;
+
+       public static void runOne() {
+               field1 = field1 * 2; // set and get jps
+       }
+
+       public static void runTwo() {
+               field2 = field2 * 2; // set and get jps
+       }
+}
+
+aspect X {
+       pointcut pWoven(Marker l): withincode(* run*(..)) && get(@Marker * * ) && @annotation(l);
+
+       before(Marker l): pWoven(l) {
+           System.out.println(thisJoinPointStaticPart+" "+l);
+       }
+}
index 46eb1b24b314c669bde63e538856731679dc457a..4667d617aaae5215dfbb29e153ce7de09f39d408 100644 (file)
@@ -35,6 +35,14 @@ public class Ajc1612Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
        // runTest("itd split compilation");
        // }
 
+       public void testAnnotationFieldBindingOptimization_356612() throws Exception {
+               runTest("annotation field binding optimization");
+       }
+
+       public void testAnnotationFieldBindingOptimization_356612_2() throws Exception {
+               runTest("annotation field binding optimization - 2");
+       }
+
        public void testThisAspectInstance_239649_1() throws Exception {
                // simple case
                runTest("thisAspectInstance - 1");
index 657a9281a1e7694c4f8f5dff8cb8db76c1fc258c..07b5a9993af435d108e984d6275c919e50cadefd 100644 (file)
@@ -2,6 +2,24 @@
 
 <suite>
 
+<ajc-test dir="bugs1612/pr356612" title="annotation field binding optimization">
+<compile files="AnnoBinding.java" options="-1.5"/>
+<run class="AnnoBinding">
+</run>
+</ajc-test>
+
+
+<ajc-test dir="bugs1612/pr356612" title="annotation field binding optimization - 2">
+<compile files="AnnoBinding2.java" options="-1.5"/>
+<run class="AnnoBinding2">
+<stdout>
+<line text="get(int AnnoBinding2.field1) @Marker(message=foo)"/>
+<line text="get(int AnnoBinding2.field2) @Marker(message=bar)"/>
+<line text="2 ajc$anno$NNN fields"/>
+</stdout>
+</run>
+</ajc-test>
+
 <ajc-test dir="bugs1612/pr354683" title="itd split compilation">
 <compile files="util/CommonData.java util/CommonDataImpl.java util/CommonDataImplementation.aj util/DerivedCommonDataInterface.java util/DerivedCommonDataInterfaceImpl.java util/DerivedCommonDataInterfaceImplementation.aj" options="-1.5" outjar="code.jar"/>
 <compile files="main/AbstractBaseClass.java main/DerivedClass.java main/Whatever.java " options="-1.5" aspectpath="code.jar"/>