diff options
author | jhugunin <jhugunin> | 2004-01-24 02:28:54 +0000 |
---|---|---|
committer | jhugunin <jhugunin> | 2004-01-24 02:28:54 +0000 |
commit | 0c833438dadeeb26659cd901870d18d2c103658b (patch) | |
tree | cbe369e1ea2e90cdfabf09f9b343da4e9a930621 /org.aspectj.ajdt.core/testdata | |
parent | 2b4e2512530a5d0a12e92071eb2e3198722dcd6b (diff) | |
download | aspectj-0c833438dadeeb26659cd901870d18d2c103658b.tar.gz aspectj-0c833438dadeeb26659cd901870d18d2c103658b.zip |
Implemented feature for Bugzilla Bug 48091
Lazy instantiation of thisJoinPoint
Speed-ups of 10-100X are measured even when running a small test case with minimal GC issues.
The actual feature implemented is that thisJoinPoint objects are only created just before calling the method for advice that requires them. To take advantage of this feature you must use an if PCD or some other dynamic test that occurs in the PCD not the advice body to guard the expensive creation of the thisJoinPoint object.
-XlazyTjp flag must be passed to compiler to enable this feature.
If any around advice is present on the joinpoint then lazy instantiation
will be disabled. An Xlint warning will be displayed in this case.
As a related optimization, several helper methods were added to
Factory.makeJP to reduce the code size when thisJoinPoint is used.
Diffstat (limited to 'org.aspectj.ajdt.core/testdata')
-rw-r--r-- | org.aspectj.ajdt.core/testdata/src1/LazyTjp.aj | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/org.aspectj.ajdt.core/testdata/src1/LazyTjp.aj b/org.aspectj.ajdt.core/testdata/src1/LazyTjp.aj new file mode 100644 index 000000000..f3662738c --- /dev/null +++ b/org.aspectj.ajdt.core/testdata/src1/LazyTjp.aj @@ -0,0 +1,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 = 8.0;
+
+ 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();
+ }
+
+
+}
\ No newline at end of file |