Browse Source

Fixes for compile time overweaving

In writing a testcase for 352389 I discovered overweaving
just wasn't working for a compile time series of test steps.
This was due to a guard preventing secondary calls to
addOrReplaceAspect. Without the secondary call the crosscutting
collector for the aspect had recorded no mungers from the
original aspect because it was still using an EclipseSourceType
delegate. Later when it was using the binary BcelObjectType
delegate and mungers were available, they weren't collected
because of that missing addOrReplaceAspect call.
tags/V1_8_9
Andy Clement 8 years ago
parent
commit
9be47cc3a9

+ 3
- 0
tests/bugs189/352389/A.java View File

@@ -0,0 +1,3 @@
public aspect A {
before(): execution(* m(..)) { System.out.println("a"); }
}

+ 3
- 0
tests/bugs189/352389/B.java View File

@@ -0,0 +1,3 @@
public aspect B {
before(): execution(* m(..)) { System.out.println("b"); }
}

+ 3
- 0
tests/bugs189/352389/C.java View File

@@ -0,0 +1,3 @@
public aspect C {
before(): execution(* m(..)) { System.out.println("c"); }
}

+ 7
- 0
tests/bugs189/352389/Code.java View File

@@ -0,0 +1,7 @@
public class Code {
public static void main(String []argv) {
new Code().m();
}

public void m() {}
}

+ 4
- 0
tests/src/org/aspectj/systemtest/ajc189/Ajc189Tests.java View File

@@ -25,6 +25,10 @@ public class Ajc189Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
runTest("while npe");
}
public void testOverweaving_352389() throws Exception {
runTest("overweaving");
}
// ---

public static Test suite() {

+ 53
- 0
tests/src/org/aspectj/systemtest/ajc189/ajc189.xml View File

@@ -6,4 +6,57 @@
<compile files="While.java" options="-1.8"/>
</ajc-test>

<ajc-test dir="bugs189/352389" title="overweaving">

<compile files="A.java Code.java" outjar="one.jar" options="-1.8 -showWeaveInfo">
<message kind="weave" text="Join point 'method-execution(void Code.m())' in Type 'Code' (Code.java:6) advised by before advice from 'A' (A.java:2)"/>
</compile>
<run class="Code" classpath="$sandbox/one.jar">
<stdout>
<line text="a"/>
</stdout>
</run>

<!-- The non overweaving case would look like this -->
<compile files="B.java" inpath="one.jar" options="-1.8 -showWeaveInfo" outjar="two.jar">
<message kind="weave" text="Join point 'method-execution(void Code.m())' in Type 'Code' (Code.java:6) advised by before advice from 'B' (B.java:2)"/>
<message kind="weave" text="Join point 'method-execution(void Code.m())' in Type 'Code' (Code.java:6) advised by before advice from 'A' (one.jar!A.class:2(from A.java))"/>
</compile>
<!-- With overweaving it looks like the advice from A isn't applying but it just isn't applying during this weave step, it
remains in the bytecode applied from before. -->
<compile files="B.java" inpath="one.jar" options="-1.8 -Xset:pipelineCompilation=false{overWeaving=true -showWeaveInfo" outjar="two.jar">
<message kind="warning" text="advice defined in A has not been applied [Xlint:adviceDidNotMatch]"/>
<message kind="weave" text="Join point 'method-execution(void Code.m())' in Type 'Code' (Code.java:6) advised by before advice from 'B' (B.java:2)"/>
</compile>
<!-- Note: with overweaving output is b>a without overweaving it is a>b -->
<run class="Code" classpath="$sandbox/two.jar">
<stdout>
<line text="b"/>
<line text="a"/>
</stdout>
</run>

<compile files="C.java" inpath="two.jar" options="-1.8 -Xset:overWeaving=true -showWeaveInfo" outjar="three.jar">
<message kind="warning" text="advice defined in A has not been applied [Xlint:adviceDidNotMatch]"/>
<message kind="warning" text="advice defined in B has not been applied [Xlint:adviceDidNotMatch]"/>
<message kind="weave" text="Join point 'method-execution(void Code.m())' in Type 'Code' (Code.java:6) advised by before advice from 'C' (C.java:2)"/>
</compile>
<!--
<compile files="C.java" inpath="two.jar" options="-1.8 -showWeaveInfo" outjar="three.jar">
<message kind="weave" text="Join point 'method-execution(void Code.m())' in Type 'Code' (Code.java:6) advised by before advice from 'C' (C.java:2)"/>
<message kind="weave" text="Join point 'method-execution(void Code.m())' in Type 'Code' (Code.java:6) advised by before advice from 'B' (two.jar!B.class:2(from B.java))"/>
<message kind="weave" text="Join point 'method-execution(void Code.m())' in Type 'Code' (Code.java:6) advised by before advice from 'A' (two.jar!A.class:2(from A.java))"/>
</compile>
-->
<!-- Note: with overweaving c>b>a but without overweaving a>b>c -->
<run class="Code" classpath="$sandbox/three.jar">
<stdout>
<line text="c"/>
<line text="b"/>
<line text="a"/>
</stdout>
</run>
</ajc-test>

</suite>

+ 5
- 1
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java View File

@@ -503,7 +503,11 @@ public class BcelWeaver {
UnwovenClassFile jc = i.next();
String name = jc.getClassName();
ResolvedType type = world.resolve(name);
if (type.isAspect() && !world.isOverWeaving()) {
// No overweaving guard. If you have one then when overweaving is on the
// addOrReplaceAspect will not be called when the aspect delegate changes from
// EclipseSourceType to BcelObjectType. This will mean the mungers
// are not picked up.
if (type.isAspect()) {
needToReweaveWorld |= xcutSet.addOrReplaceAspect(type);
}
}

Loading…
Cancel
Save