blob: 02226a8afc0cb9b298d1403fd329e14b47c1e87d (
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
public class LazyTjp {
private static final int N = 10000000;
// if lazy tjp is working, then calling the advice that uses thisJoinPoint should
// take at least this much longer than using an if pcd to bypass the advice
private static final double minimumRatio = 1.8; // was 8 but jvm seems to be improving all the time!!
public static void main(String[] args) {
Trace.enabled = false;
double tOff = timeIt(); // throw the first result out for warm-up
tOff = timeIt();
Trace.enabled = true;
double tOn = timeIt();
Trace.enabled = false;
double tEasy = timeIt0();
double tGone = timeIt1();
System.out.println("tOff: " + tOff + ", tOn: " + tOn + ", tEasy: " + tEasy + ", tGone: " + tGone);
System.out.println("ratio: " + tOn/tOff);
Trace.enabled = false;
double tOff2 = timeIt2();
tOff2 = timeIt2();
Trace.enabled = true;
double tOn2 = timeIt2();
System.out.println("tOff2: " + tOff2 + ", tOn2: " + tOn2);
System.out.println("ratio2: " + tOn2/tOff2);
if (tOn/tOff < minimumRatio) {
throw new IllegalStateException("tOn/tOff = " + tOn/tOff + " < " + minimumRatio);
}
}
public static double timeIt() {
long start = System.currentTimeMillis();
for (int i=0; i < N; i++) {
doit(i);
}
long stop = System.currentTimeMillis();
return (stop-start)/1000.0;
}
private static int doit(int x) {
return x+1;
}
public static double timeIt0() {
long start = System.currentTimeMillis();
for (int i=0; i < N; i++) {
doit0(i);
}
long stop = System.currentTimeMillis();
return (stop-start)/1000.0;
}
private static int doit0(int x) {
return x+1;
}
public static double timeIt1() {
long start = System.currentTimeMillis();
for (int i=0; i < N; i++) {
doit1(i);
}
long stop = System.currentTimeMillis();
return (stop-start)/1000.0;
}
private static int doit1(int x) {
return x+1;
}
public static double timeIt2() {
long start = System.currentTimeMillis();
for (int i=0; i < N; i++) {
doit2(i);
}
long stop = System.currentTimeMillis();
return (stop-start)/1000.0;
}
private static int doit2(int x) {
return x+1;
}
private static int doit3(int x) {
return x+1;
}
}
aspect Trace {
public static boolean enabled = false;
public static int counter = 0;
pointcut traced(): if (enabled) && execution(* LazyTjp.doit(..));
before(): traced() {
Object[] args = thisJoinPoint.getArgs();
counter += args.length;
}
before(): execution(* LazyTjp.doit0(..)) {
counter += 1;
}
pointcut traced2(): if (enabled) && execution(* LazyTjp.doit2(..));
before(): traced2() {
Object[] args = thisJoinPoint.getArgs();
counter += args.length;
}
after() returning: traced2() {
Object[] args = thisJoinPoint.getArgs();
counter += args.length;
}
pointcut traced3(): if (enabled) && execution(* LazyTjp.doit3(..));
before(): traced3() {
Object[] args = thisJoinPoint.getArgs();
counter += args.length;
}
Object around(): traced3() { // expect Xlint warning in -XlazyTjp mode
return proceed();
}
}
|