From 531092ca08c86bdfdb6c783e9fd47b1d2df87899 Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 30 Oct 2008 19:10:30 +0000 Subject: [PATCH] fix for 163005 --- .../org/aspectj/weaver/bcel/BcelAdvice.java | 14 +- .../org/aspectj/weaver/bcel/BcelShadow.java | 1 - .../aspectj/weaver/bcel/IdWeaveTestCase.java | 146 ++++++++-------- .../bcel/MoveInstructionsWeaveTestCase.java | 73 ++++---- .../weaver/bcel/PatternWeaveTestCase.java | 160 +++++++++--------- 5 files changed, 200 insertions(+), 194 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java index 59c77e6b4..25a20746b 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java @@ -59,7 +59,7 @@ class BcelAdvice extends Advice { private ExposedState exposedState; public BcelAdvice(AjAttribute.AdviceAttribute attribute, Pointcut pointcut, Member signature, ResolvedType concreteAspect) { - super(attribute, pointcut, shrink(attribute.getKind(), concreteAspect, signature));//(signature==null?null:signature.slimline + super(attribute, pointcut, shrink(attribute.getKind(), concreteAspect, signature));// (signature==null?null:signature.slimline // ())); this.concreteAspect = concreteAspect; } @@ -82,7 +82,7 @@ class BcelAdvice extends Advice { if (bm.getMethod() != null && bm.getMethod().getAnnotations() != null) return m; ResolvedMemberImpl simplermember = new ResolvedMemberImpl(bm.getKind(), bm.getDeclaringType(), bm.getModifiers(), - bm.getReturnType(), bm.getName(), bm.getParameterTypes());//,bm.getExceptions(),bm.getBackingGenericMember() + bm.getReturnType(), bm.getName(), bm.getParameterTypes());// ,bm.getExceptions(),bm.getBackingGenericMember() // ); simplermember.setParameterNames(bm.getParameterNames()); return simplermember; @@ -212,7 +212,7 @@ class BcelAdvice extends Advice { return BcelWorld.getBcelObjectType(concreteAspect).getLazyClassGen().isWoven(); } - public void implementOn(Shadow s) { + public boolean implementOn(Shadow s) { hasMatchedAtLeastOnce = true; BcelShadow shadow = (BcelShadow) s; @@ -284,6 +284,13 @@ class BcelAdvice extends Advice { // It might be dangerous to change that especially for @AJ aspect non compiled with AJC since if those // are not weaved (f.e. use of some limiteed LTW etc) then they cannot be prepared for inlining. // One solution would be to flag @AJ aspect with an annotation as "prepared" and query that one. + LazyClassGen enclosingClass = shadow.getEnclosingClass(); + if (enclosingClass != null && enclosingClass.isInterface() && shadow.getEnclosingMethod().getName().charAt(0) == '<') { + // Do not add methods with bodies to an interface (252198, 163005) + shadow.getWorld().getLint().cannotAdviseJoinpointInInterfaceWithAroundAdvice.signal(shadow.toString(), shadow + .getSourceLocation()); + return false; + } if (!canInline(s)) { shadow.weaveAroundClosure(this, hasDynamicTests()); } else { @@ -305,6 +312,7 @@ class BcelAdvice extends Advice { } else { throw new BCException("unimplemented kind: " + getKind()); } + return true; } private void removeUnnecessaryProblems(BcelMethod method, int problemLineNumber) { diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java index d6eb93781..c22ae880e 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java @@ -2044,7 +2044,6 @@ public class BcelShadow extends Shadow { * method-execution, then the new method for the advice can also be re-lined. We are not doing that presently. */ public void weaveAroundInline(BcelAdvice munger, boolean hasDynamicTest) { - // !!! THIS BLOCK OF CODE SHOULD BE IN A METHOD CALLED weaveAround(...); Member mungerSig = munger.getSignature(); // Member originalSig = mungerSig; // If mungerSig is on a parameterized type, originalSig is the member on the generic type diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/IdWeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/IdWeaveTestCase.java index 218233c37..cf16b73b1 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/IdWeaveTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/IdWeaveTestCase.java @@ -10,13 +10,14 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver.bcel; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.List; -import org.aspectj.weaver.*; +import org.aspectj.weaver.Shadow; +import org.aspectj.weaver.World; import org.aspectj.weaver.patterns.Pointcut; public class IdWeaveTestCase extends WeaveTestCase { @@ -27,81 +28,74 @@ public class IdWeaveTestCase extends WeaveTestCase { public IdWeaveTestCase(String name) { super(name); } - - public void testFancyId() throws IOException { - final List l = new ArrayList(); + + public void testFancyId() throws IOException { + final List l = new ArrayList(); Pointcut pointcut2 = makePointcutAll(); - BcelAdvice p = - new BcelAdvice(null, pointcut2, null, 0, -1, -1, null, null) { - public boolean match(Shadow shadow, World world) { - if (super.match(shadow, world)) { - l.add(shadow); - } - return false; - } - }; - weaveTest(new String[] {"FancyHelloWorld"}, "Id2", p); - - checkShadowSet(l, new String[] { - "method-call(void java.io.PrintStream.println(java.lang.Object))", - "method-call(void java.io.PrintStream.println(java.lang.String))", - "method-call(java.lang.StringBuffer java.lang.StringBuffer.append(int))", - "method-call(java.lang.String java.lang.StringBuffer.toString())", - "method-execution(java.lang.String FancyHelloWorld.getName())", - "field-get(java.io.PrintStream java.lang.System.out)", - "method-call(void java.io.PrintStream.println(java.lang.String))", - "method-execution(void FancyHelloWorld.main(java.lang.String[]))", - "method-call(int java.lang.String.hashCode())", - "constructor-execution(void FancyHelloWorld.())", - "constructor-call(void java.lang.StringBuffer.(java.lang.String))" - }); - } + BcelAdvice p = new BcelAdvice(null, pointcut2, null, 0, -1, -1, null, null) { + public boolean match(Shadow shadow, World world) { + if (super.match(shadow, world)) { + l.add(shadow); + } + return false; + } + }; + weaveTest(new String[] { "FancyHelloWorld" }, "Id2", p); + + checkShadowSet(l, new String[] { "method-call(void java.io.PrintStream.println(java.lang.Object))", + "method-call(void java.io.PrintStream.println(java.lang.String))", + "method-call(java.lang.StringBuffer java.lang.StringBuffer.append(int))", + "method-call(java.lang.String java.lang.StringBuffer.toString())", + "method-execution(java.lang.String FancyHelloWorld.getName())", + "field-get(java.io.PrintStream java.lang.System.out)", + "method-call(void java.io.PrintStream.println(java.lang.String))", + "method-execution(void FancyHelloWorld.main(java.lang.String[]))", "method-call(int java.lang.String.hashCode())", + "constructor-execution(void FancyHelloWorld.())", + "constructor-call(void java.lang.StringBuffer.(java.lang.String))" }); + } + + public void testId() throws IOException { + final List l = new ArrayList(); + BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) { + public boolean implementOn(Shadow shadow) { + l.add(shadow); + return true; + } + }; + weaveTest(new String[] { "HelloWorld" }, "Id2", p); + checkShadowSet(l, new String[] { "method-execution(void HelloWorld.main(java.lang.String[]))", + "method-call(void java.io.PrintStream.println(java.lang.String))", + "field-get(java.io.PrintStream java.lang.System.out)", "constructor-execution(void HelloWorld.())", }); + } - public void testId() throws IOException { - final List l = new ArrayList(); - BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) { - public void implementOn(Shadow shadow) { - l.add(shadow); - } - }; - weaveTest(new String[] {"HelloWorld"}, "Id2", p); - - checkShadowSet(l, new String[] { - "method-execution(void HelloWorld.main(java.lang.String[]))", - "method-call(void java.io.PrintStream.println(java.lang.String))", - "field-get(java.io.PrintStream java.lang.System.out)", - "constructor-execution(void HelloWorld.())", - }); - } - - // this test requires that Trace has been unzipped and placed in the correct place -// public void testTraceId() throws IOException { -// String saveClassDir = classDir; -// try { -// classDir = "testdata/dummyAspect.jar"; -// -// -// -// final List l = new ArrayList(); -// BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) { -// public void implementOn(Shadow shadow) { -// l.add(shadow); -// } -// }; -// boolean tempRunTests = runTests; -// runTests = false; -// weaveTest(new String[] {"DummyAspect"}, "Id", p); -// runTests = tempRunTests; -// -// checkShadowSet(l, new String[] { -// "constructor-execution(void DummyAspect.())", -// // XXX waiting on parser stuff -// //"advice-execution(void DummyAspect.ajc_before_1(java.lang.Object))", -// }); -// } finally { -// classDir = saveClassDir; -// } -// } + // this test requires that Trace has been unzipped and placed in the correct place + // public void testTraceId() throws IOException { + // String saveClassDir = classDir; + // try { + // classDir = "testdata/dummyAspect.jar"; + // + // + // + // final List l = new ArrayList(); + // BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) { + // public void implementOn(Shadow shadow) { + // l.add(shadow); + // } + // }; + // boolean tempRunTests = runTests; + // runTests = false; + // weaveTest(new String[] {"DummyAspect"}, "Id", p); + // runTests = tempRunTests; + // + // checkShadowSet(l, new String[] { + // "constructor-execution(void DummyAspect.())", + // // XXX waiting on parser stuff + // //"advice-execution(void DummyAspect.ajc_before_1(java.lang.Object))", + // }); + // } finally { + // classDir = saveClassDir; + // } + // } } diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/MoveInstructionsWeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/MoveInstructionsWeaveTestCase.java index 04c00dc39..73bd7dd3e 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/MoveInstructionsWeaveTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/MoveInstructionsWeaveTestCase.java @@ -10,13 +10,13 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver.bcel; -import java.io.*; +import java.io.IOException; import org.aspectj.apache.bcel.generic.InstructionFactory; -import org.aspectj.weaver.*; +import org.aspectj.weaver.NameMangler; +import org.aspectj.weaver.Shadow; public class MoveInstructionsWeaveTestCase extends WeaveTestCase { { @@ -26,48 +26,51 @@ public class MoveInstructionsWeaveTestCase extends WeaveTestCase { public MoveInstructionsWeaveTestCase(String name) { super(name); } - public void testHello() throws IOException { - BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) { - public void specializeOn(Shadow s) { - super.specializeOn(s); - ((BcelShadow) s).initializeForAroundClosure(); - } - public void implementOn(Shadow s) { + + public void testHello() throws IOException { + BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) { + public void specializeOn(Shadow s) { + super.specializeOn(s); + ((BcelShadow) s).initializeForAroundClosure(); + } + + public boolean implementOn(Shadow s) { BcelShadow shadow = (BcelShadow) s; - LazyMethodGen newMethod = - shadow.extractMethod( - NameMangler.getExtractableName(shadow.getSignature()) + "_extracted", - 0, - this); + LazyMethodGen newMethod = shadow.extractMethod( + NameMangler.getExtractableName(shadow.getSignature()) + "_extracted", 0, this); shadow.getRange().append(shadow.makeCallToCallback(newMethod)); if (!shadow.isFallsThrough()) { - shadow.getRange().append( - InstructionFactory.createReturn(newMethod.getReturnType())); + shadow.getRange().append(InstructionFactory.createReturn(newMethod.getReturnType())); } + return true; } - }; + }; + + weaveTest("HelloWorld", "ExtractedHelloWorld", p); + } + + static int counter = 0; - weaveTest("HelloWorld", "ExtractedHelloWorld", p); - } - - static int counter = 0; public void testFancyHello() throws IOException { BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) { - public void specializeOn(Shadow s) { - super.specializeOn(s); - ((BcelShadow) s).initializeForAroundClosure(); - } - public void implementOn(Shadow s) { - BcelShadow shadow = (BcelShadow) s; - LazyMethodGen newMethod = shadow.extractMethod(NameMangler.getExtractableName(shadow.getSignature()) + "_extracted" + counter++, 0, this); - shadow.getRange().append(shadow.makeCallToCallback(newMethod)); + public void specializeOn(Shadow s) { + super.specializeOn(s); + ((BcelShadow) s).initializeForAroundClosure(); + } + + public boolean implementOn(Shadow s) { + BcelShadow shadow = (BcelShadow) s; + LazyMethodGen newMethod = shadow.extractMethod(NameMangler.getExtractableName(shadow.getSignature()) + "_extracted" + + counter++, 0, this); + shadow.getRange().append(shadow.makeCallToCallback(newMethod)); - if (! shadow.isFallsThrough()) { - shadow.getRange().append(InstructionFactory.createReturn(newMethod.getReturnType())); - } - } - }; + if (!shadow.isFallsThrough()) { + shadow.getRange().append(InstructionFactory.createReturn(newMethod.getReturnType())); + } + return true; + } + }; weaveTest("FancyHelloWorld", "ExtractedFancyHelloWorld", p); } diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/PatternWeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/PatternWeaveTestCase.java index 6bdc4e142..3d0e2edbd 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/PatternWeaveTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/PatternWeaveTestCase.java @@ -10,109 +10,111 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver.bcel; -import java.io.*; -import java.util.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; -import org.aspectj.weaver.*; -import org.aspectj.weaver.patterns.*; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.Shadow; +import org.aspectj.weaver.VersionedDataInputStream; +import org.aspectj.weaver.patterns.FormalBinding; +import org.aspectj.weaver.patterns.Pointcut; +import org.aspectj.weaver.patterns.SimpleScope; public class PatternWeaveTestCase extends WeaveTestCase { { regenerate = false; } - + public PatternWeaveTestCase(String name) { super(name); } - - String[] none = new String[0]; - //XXX this test is incompatible with optimizations made to weaver + String[] none = new String[0]; + + // XXX this test is incompatible with optimizations made to weaver public void testPublic() throws IOException { - String[] publicHello = new String[] { - "method-execution(void HelloWorld.main(java.lang.String[]))", - }; - String[] publicFancyHello = new String[] { - "method-execution(void FancyHelloWorld.main(java.lang.String[]))", - "method-execution(java.lang.String FancyHelloWorld.getName())", - }; + String[] publicHello = new String[] { "method-execution(void HelloWorld.main(java.lang.String[]))", }; + String[] publicFancyHello = new String[] { "method-execution(void FancyHelloWorld.main(java.lang.String[]))", + "method-execution(java.lang.String FancyHelloWorld.getName())", }; checkPointcut("execution(public * *(..))", publicHello, publicFancyHello); } -// -// public void testPrintln() throws IOException { -// String[] callPrintlnHello = new String[] { -// "method-call(void java.io.PrintStream.println(java.lang.String))", -// }; -// String[] callPrintlnFancyHello = new String[] { -// "method-call(void java.io.PrintStream.println(java.lang.String))", -// "method-call(void java.io.PrintStream.println(java.lang.String))", -// "method-call(void java.io.PrintStream.println(java.lang.Object))", -// }; -// checkPointcut("call(* println(*))", callPrintlnHello, callPrintlnFancyHello); -// } -// -// public void testMumble() throws IOException { -// checkPointcut("call(* mumble(*))", none, none); -// } -// -// public void testFooBar() throws IOException { -// checkPointcut("call(FooBar *(..))", none, none); -// } -// -// public void testGetOut() throws IOException { -// String[] getOutHello = new String[] { -// "field-get(java.io.PrintStream java.lang.System.out)", -// }; -// -// checkPointcut("get(* java.lang.System.out)", getOutHello, getOutHello); -// } -// -//// private Pointcut makePointcut(String s) { -//// return new PatternParser(s).parsePointcut(); -//// } -// - private void checkPointcut(String pointcutSource, String[] expectedHelloShadows, - String[] expectedFancyShadows) throws IOException - { - Pointcut sp = Pointcut.fromString(pointcutSource); - Pointcut rp = sp.resolve(new SimpleScope(world, FormalBinding.NONE)); - Pointcut cp = rp.concretize(ResolvedType.MISSING, ResolvedType.MISSING, 0); - - final List l = new ArrayList(); - BcelAdvice p = new BcelAdvice(null, cp, null, 0, -1, -1, null, null) { - public void implementOn(Shadow shadow) { - l.add(shadow); - } - }; - weaveTest(new String[] {"HelloWorld"}, "PatternWeave", p); - - checkShadowSet(l, expectedHelloShadows); - - - l.clear(); - weaveTest(new String[] {"FancyHelloWorld"}, "PatternWeave", p); - - checkShadowSet(l, expectedFancyShadows); - - checkSerialize(rp); - } - + + // + // public void testPrintln() throws IOException { + // String[] callPrintlnHello = new String[] { + // "method-call(void java.io.PrintStream.println(java.lang.String))", + // }; + // String[] callPrintlnFancyHello = new String[] { + // "method-call(void java.io.PrintStream.println(java.lang.String))", + // "method-call(void java.io.PrintStream.println(java.lang.String))", + // "method-call(void java.io.PrintStream.println(java.lang.Object))", + // }; + // checkPointcut("call(* println(*))", callPrintlnHello, callPrintlnFancyHello); + // } + // + // public void testMumble() throws IOException { + // checkPointcut("call(* mumble(*))", none, none); + // } + // + // public void testFooBar() throws IOException { + // checkPointcut("call(FooBar *(..))", none, none); + // } + // + // public void testGetOut() throws IOException { + // String[] getOutHello = new String[] { + // "field-get(java.io.PrintStream java.lang.System.out)", + // }; + // + // checkPointcut("get(* java.lang.System.out)", getOutHello, getOutHello); + // } + // + // // private Pointcut makePointcut(String s) { + // // return new PatternParser(s).parsePointcut(); + // // } + // + private void checkPointcut(String pointcutSource, String[] expectedHelloShadows, String[] expectedFancyShadows) + throws IOException { + Pointcut sp = Pointcut.fromString(pointcutSource); + Pointcut rp = sp.resolve(new SimpleScope(world, FormalBinding.NONE)); + Pointcut cp = rp.concretize(ResolvedType.MISSING, ResolvedType.MISSING, 0); + + final List l = new ArrayList(); + BcelAdvice p = new BcelAdvice(null, cp, null, 0, -1, -1, null, null) { + public boolean implementOn(Shadow shadow) { + l.add(shadow); + return true; + } + }; + weaveTest(new String[] { "HelloWorld" }, "PatternWeave", p); + + checkShadowSet(l, expectedHelloShadows); + + l.clear(); + weaveTest(new String[] { "FancyHelloWorld" }, "PatternWeave", p); + + checkShadowSet(l, expectedFancyShadows); + + checkSerialize(rp); + } + public void checkSerialize(Pointcut p) throws IOException { ByteArrayOutputStream bo = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bo); p.write(out); out.close(); - + ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray()); VersionedDataInputStream in = new VersionedDataInputStream(bi); Pointcut newP = Pointcut.read(in, null); - - assertEquals("write/read", p, newP); - } + assertEquals("write/read", p, newP); + } } -- 2.39.5