blob: 08135e5d225a0033d7bbacdd340abc9ab2ce97f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
|