summaryrefslogtreecommitdiffstats
path: root/org.aspectj.ajdt.core
diff options
context:
space:
mode:
authorjhugunin <jhugunin>2004-01-24 02:28:54 +0000
committerjhugunin <jhugunin>2004-01-24 02:28:54 +0000
commit0c833438dadeeb26659cd901870d18d2c103658b (patch)
treecbe369e1ea2e90cdfabf09f9b343da4e9a930621 /org.aspectj.ajdt.core
parent2b4e2512530a5d0a12e92071eb2e3198722dcd6b (diff)
downloadaspectj-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')
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java2
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java10
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java1
-rw-r--r--org.aspectj.ajdt.core/testdata/src1/LazyTjp.aj142
-rw-r--r--org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/AjdtBatchTests.java3
-rw-r--r--org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java8
-rw-r--r--org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/PerformanceTestCase.java42
7 files changed, 207 insertions, 1 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java
index aa40a8242..cf6174746 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java
@@ -442,6 +442,8 @@ public class BuildArgParser extends Main {
buildConfig.setNoWeave(true);
} else if (arg.equals("-XserializableAspects")) {
buildConfig.setXserializableAspects(true);
+ } else if (arg.equals("-XlazyTjp")) {
+ buildConfig.setXlazyTjp(true);
} else if (arg.equals("-XnoInline")) {
buildConfig.setXnoInline(true);
} else if (arg.equals("-Xlintfile")) {
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java
index a106f1424..ad182a589 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java
@@ -54,6 +54,7 @@ public class AjBuildConfig { // XXX needs bootclasspath?
private boolean emacsSymMode = false;
private boolean noWeave = false;
private boolean XserializableAspects = false;
+ private boolean XlazyTjp = false;
private boolean XnoInline = false;
private String lintMode = AJLINT_DEFAULT;
private File lintSpecFile = null;
@@ -452,4 +453,13 @@ public class AjBuildConfig { // XXX needs bootclasspath?
public void doNotProceed() {
shouldProceed = false;
}
+
+ public boolean isXlazyTjp() {
+ return XlazyTjp;
+ }
+
+ public void setXlazyTjp(boolean b) {
+ XlazyTjp = b;
+ }
+
}
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
index 1ab91d09e..89fc57071 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
@@ -187,6 +187,7 @@ public class AjBuildManager {
private void initBcelWorld(IMessageHandler handler) throws IOException {
bcelWorld = new BcelWorld(buildConfig.getClasspath(), handler, null);
bcelWorld.setXnoInline(buildConfig.isXnoInline());
+ bcelWorld.setXlazyTjp(buildConfig.isXlazyTjp());
bcelWeaver = new BcelWeaver(bcelWorld);
for (Iterator i = buildConfig.getAspectpath().iterator(); i.hasNext();) {
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
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/AjdtBatchTests.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/AjdtBatchTests.java
index 8075e9888..80710268c 100644
--- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/AjdtBatchTests.java
+++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/AjdtBatchTests.java
@@ -25,7 +25,8 @@ public class AjdtBatchTests extends TestCase {
//$JUnit-BEGIN$
suite.addTestSuite(BasicCommandTestCase.class);
suite.addTestSuite(BinaryFormsTestCase.class);
- suite.addTestSuite(CompileAndRunTestCase.class);
+ suite.addTestSuite(CompileAndRunTestCase.class);
+ suite.addTestSuite(PerformanceTestCase.class);
suite.addTestSuite(ImageTestCase.class);
suite.addTestSuite(MultipleCompileTestCase.class);
// XXX suite.addTestSuite(VerifyWeaveTestCase.class);
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java
index c50ac5c89..a508e512c 100644
--- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java
+++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java
@@ -45,6 +45,10 @@ public abstract class CommandTestCase extends TestCase {
public static void checkCompile(String source, int[] expectedErrors) {
+ checkCompile(source, new String[0], expectedErrors);
+ }
+
+ public static void checkCompile(String source, String[] extraArgs, int[] expectedErrors) {
List args = new ArrayList();
args.add("-verbose");
@@ -58,6 +62,10 @@ public abstract class CommandTestCase extends TestCase {
args.add("-g"); //XXX need this to get sourcefile and line numbers, shouldn't
+ for (int i = 0; i < extraArgs.length; i++) {
+ args.add(extraArgs[i]);
+ }
+
args.add(AjdtAjcTests.TESTDATA_PATH + "/" + source);
runCompiler(args, expectedErrors);
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/PerformanceTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/PerformanceTestCase.java
new file mode 100644
index 000000000..527fe9304
--- /dev/null
+++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/PerformanceTestCase.java
@@ -0,0 +1,42 @@
+/* *******************************************************************
+ * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.ajdt.internal.compiler.batch;
+
+import java.io.IOException;
+
+import org.aspectj.testing.util.TestUtil;
+
+
+public class PerformanceTestCase extends CommandTestCase {
+
+ public PerformanceTestCase(String name) {
+ super(name);
+ }
+
+
+ // this is a nice test, but not strictly needed
+ public void xxx_testLazyTjpOff() throws IOException {
+ checkCompile("src1/LazyTjp.aj", NO_ERRORS);
+ try {
+ TestUtil.runMain("out", "LazyTjp");
+ fail("expected an exception when running without -XlazyTjp");
+ } catch (IllegalStateException e) {
+ // expected exception thrown when no -XlazyTjp
+ }
+ }
+
+ public void testLazyTjp() throws IOException {
+ checkCompile("src1/LazyTjp.aj", new String[] {"-XlazyTjp","-Xlint:error"}, new int[] {97});
+ TestUtil.runMain("out", "LazyTjp");
+ }
+}