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 /weaver/src | |
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 'weaver/src')
-rw-r--r-- | weaver/src/org/aspectj/weaver/Lint.java | 3 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/World.java | 10 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/XlintDefault.properties | 2 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java | 4 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelShadow.java | 168 |
5 files changed, 157 insertions, 30 deletions
diff --git a/weaver/src/org/aspectj/weaver/Lint.java b/weaver/src/org/aspectj/weaver/Lint.java index 5a2d1c566..c9fc271cd 100644 --- a/weaver/src/org/aspectj/weaver/Lint.java +++ b/weaver/src/org/aspectj/weaver/Lint.java @@ -50,6 +50,9 @@ public class Lint { public final Kind unmatchedSuperTypeInCall = new Kind("unmatchedSuperTypeInCall", "does not match because declaring type is {0}, if match desired use target({1})"); + public final Kind canNotImplementLazyTjp = + new Kind("canNotImplementLazyTjp", "can not implement lazyTjp on this joinpoint {0} because around advice is used"); + public Lint(World world) { this.world = world; } diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java index 289c5ae7f..481778532 100644 --- a/weaver/src/org/aspectj/weaver/World.java +++ b/weaver/src/org/aspectj/weaver/World.java @@ -41,6 +41,7 @@ public abstract class World { protected Lint lint = new Lint(this); protected boolean XnoInline; + protected boolean XlazyTjp; protected World() { super(); @@ -367,6 +368,14 @@ public abstract class World { public void setXnoInline(boolean xnoInline) { XnoInline = xnoInline; } + + public boolean isXlazyTjp() { + return XlazyTjp; + } + + public void setXlazyTjp(boolean b) { + XlazyTjp = b; + } public ResolvedTypeX.Name lookupOrCreateName(TypeX ty) { String signature = ty.getSignature(); @@ -378,4 +387,5 @@ public abstract class World { return ret; } + } diff --git a/weaver/src/org/aspectj/weaver/XlintDefault.properties b/weaver/src/org/aspectj/weaver/XlintDefault.properties index 10da55a66..7ddba894d 100644 --- a/weaver/src/org/aspectj/weaver/XlintDefault.properties +++ b/weaver/src/org/aspectj/weaver/XlintDefault.properties @@ -8,3 +8,5 @@ typeNotExposedToWeaver = warning shadowNotInStructure = ignore unmatchedSuperTypeInCall = warning + +canNotImplementLazyTjp = warning
\ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java index 88b1e9b7c..65b90ef2e 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java @@ -92,7 +92,7 @@ public class BcelAdvice extends Advice { } if ((getExtraParameterFlags() & ThisJoinPoint) != 0) { - ((BcelShadow)shadow).getThisJoinPointVar(); + ((BcelShadow)shadow).requireThisJoinPoint(pointcutTest != Literal.TRUE && getKind() != AdviceKind.Around); } if ((getExtraParameterFlags() & ThisEnclosingJoinPointStaticPart) != 0) { @@ -298,7 +298,7 @@ public class BcelAdvice extends Advice { } if ((getExtraParameterFlags() & ThisJoinPoint) != 0) { - shadow.getThisJoinPointBcelVar().appendLoad(il, fact); + il.append(shadow.loadThisJoinPoint()); } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java index 081d9f634..9069c915e 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java @@ -43,6 +43,7 @@ import org.apache.bcel.generic.SWAP; import org.apache.bcel.generic.TargetLostException; import org.apache.bcel.generic.Type; import org.aspectj.bridge.ISourceLocation; +import org.aspectj.weaver.Advice; import org.aspectj.weaver.AdviceKind; import org.aspectj.weaver.AjcMemberMaker; import org.aspectj.weaver.BCException; @@ -248,11 +249,15 @@ public class BcelShadow extends Shadow { } // now we ask each munger to request our state + isThisJoinPointLazy = world.isXlazyTjp(); + for (Iterator iter = mungers.iterator(); iter.hasNext();) { ShadowMunger munger = (ShadowMunger) iter.next(); munger.specializeOn(this); } + initializeThisJoinPoint(); + // If we are an expression kind, we require our target/arguments on the stack // before we do our actual thing. However, they may have been removed // from the stack as the shadowMungers have requested state. @@ -765,12 +770,11 @@ public class BcelShadow extends Shadow { // reflective thisJoinPoint support private BcelVar thisJoinPointVar = null; + private boolean isThisJoinPointLazy; + private int lazyTjpConsumers = 0; private BcelVar thisJoinPointStaticPartVar = null; // private BcelVar thisEnclosingJoinPointStaticPartVar = null; - public final Var getThisJoinPointVar() { - return getThisJoinPointBcelVar(); - } public final Var getThisJoinPointStaticPartVar() { return getThisJoinPointStaticPartBcelVar(); } @@ -778,36 +782,144 @@ public class BcelShadow extends Shadow { return getThisEnclosingJoinPointStaticPartBcelVar(); } - public BcelVar getThisJoinPointBcelVar() { + public void requireThisJoinPoint(boolean hasGuardTest) { + if (!hasGuardTest) { + isThisJoinPointLazy = false; + } else { + lazyTjpConsumers++; + } if (thisJoinPointVar == null) { - thisJoinPointVar = genTempVar(TypeX.forName("org.aspectj.lang.JoinPoint")); - InstructionFactory fact = getFactory(); - InstructionList il = new InstructionList(); - BcelVar staticPart = getThisJoinPointStaticPartBcelVar(); - staticPart.appendLoad(il, fact); - if (hasThis()) { - ((BcelVar)getThisVar()).appendLoad(il, fact); - } else { - il.append(new ACONST_NULL()); - } - if (hasTarget()) { - ((BcelVar)getTargetVar()).appendLoad(il, fact); - } else { - il.append(new ACONST_NULL()); - } - il.append(makeArgsObjectArray()); - - il.append(fact.createInvoke("org.aspectj.runtime.reflect.Factory", - "makeJP", LazyClassGen.tjpType, - new Type[] { LazyClassGen.staticTjpType, - Type.OBJECT, Type.OBJECT, new ArrayType(Type.OBJECT, 1)}, - Constants.INVOKESTATIC)); - il.append(thisJoinPointVar.createStore(fact)); - range.insert(il, Range.OutsideBefore); + thisJoinPointVar = genTempVar(TypeX.forName("org.aspectj.lang.JoinPoint")); } + } + + + public Var getThisJoinPointVar() { + requireThisJoinPoint(false); return thisJoinPointVar; } + void initializeThisJoinPoint() { + if (thisJoinPointVar == null) return; + + if (isThisJoinPointLazy) { + isThisJoinPointLazy = checkLazyTjp(); + } + + if (isThisJoinPointLazy) { + createThisJoinPoint(); // make sure any state needed is initialized, but throw the instructions out + + if (lazyTjpConsumers == 1) return; // special case only one lazyTjpUser + + InstructionFactory fact = getFactory(); + InstructionList il = new InstructionList(); + il.append(InstructionConstants.ACONST_NULL); + il.append(thisJoinPointVar.createStore(fact)); + range.insert(il, Range.OutsideBefore); + } else { + InstructionFactory fact = getFactory(); + InstructionList il = createThisJoinPoint(); + il.append(thisJoinPointVar.createStore(fact)); + range.insert(il, Range.OutsideBefore); + } + } + + private boolean checkLazyTjp() { + // check for around advice + for (Iterator i = mungers.iterator(); i.hasNext();) { + ShadowMunger munger = (ShadowMunger) i.next(); + if (munger instanceof Advice) { + if ( ((Advice)munger).getKind() == AdviceKind.Around) { + world.getLint().canNotImplementLazyTjp.signal( + new String[] {toString()}, + getSourceLocation(), + new ISourceLocation[] { munger.getSourceLocation() } + ); + return false; + } + } + } + + return true; + } + + InstructionList loadThisJoinPoint() { + InstructionFactory fact = getFactory(); + InstructionList il = new InstructionList(); + + if (isThisJoinPointLazy) { + il.append(createThisJoinPoint()); + + if (lazyTjpConsumers > 1) { + il.append(thisJoinPointVar.createStore(fact)); + + InstructionHandle end = il.append(thisJoinPointVar.createLoad(fact)); + + il.insert(InstructionFactory.createBranchInstruction(Constants.IFNONNULL, end)); + il.insert(thisJoinPointVar.createLoad(fact)); + } + } else { + thisJoinPointVar.appendLoad(il, fact); + } + + return il; + } + + InstructionList createThisJoinPoint() { + InstructionFactory fact = getFactory(); + InstructionList il = new InstructionList(); + + BcelVar staticPart = getThisJoinPointStaticPartBcelVar(); + staticPart.appendLoad(il, fact); + if (hasThis()) { + ((BcelVar)getThisVar()).appendLoad(il, fact); + } else { + il.append(new ACONST_NULL()); + } + if (hasTarget()) { + ((BcelVar)getTargetVar()).appendLoad(il, fact); + } else { + il.append(new ACONST_NULL()); + } + + switch(getArgCount()) { + case 0: + il.append(fact.createInvoke("org.aspectj.runtime.reflect.Factory", + "makeJP", LazyClassGen.tjpType, + new Type[] { LazyClassGen.staticTjpType, + Type.OBJECT, Type.OBJECT}, + Constants.INVOKESTATIC)); + break; + case 1: + ((BcelVar)getArgVar(0)).appendLoadAndConvert(il, fact, world.resolve(ResolvedTypeX.OBJECT)); + il.append(fact.createInvoke("org.aspectj.runtime.reflect.Factory", + "makeJP", LazyClassGen.tjpType, + new Type[] { LazyClassGen.staticTjpType, + Type.OBJECT, Type.OBJECT, Type.OBJECT}, + Constants.INVOKESTATIC)); + break; + case 2: + ((BcelVar)getArgVar(0)).appendLoadAndConvert(il, fact, world.resolve(ResolvedTypeX.OBJECT)); + ((BcelVar)getArgVar(1)).appendLoadAndConvert(il, fact, world.resolve(ResolvedTypeX.OBJECT)); + il.append(fact.createInvoke("org.aspectj.runtime.reflect.Factory", + "makeJP", LazyClassGen.tjpType, + new Type[] { LazyClassGen.staticTjpType, + Type.OBJECT, Type.OBJECT, Type.OBJECT, Type.OBJECT}, + Constants.INVOKESTATIC)); + break; + default: + il.append(makeArgsObjectArray()); + il.append(fact.createInvoke("org.aspectj.runtime.reflect.Factory", + "makeJP", LazyClassGen.tjpType, + new Type[] { LazyClassGen.staticTjpType, + Type.OBJECT, Type.OBJECT, new ArrayType(Type.OBJECT, 1)}, + Constants.INVOKESTATIC)); + break; + } + + return il; + } + public BcelVar getThisJoinPointStaticPartBcelVar() { if (thisJoinPointStaticPartVar == null) { Field field = getEnclosingClass().getTjpField(this); |