Browse Source

fixed Bug 30168: bad optimization of thisJoinPoint to thisJoinPointStaticPart

tags/V_1_1_b5
jhugunin 21 years ago
parent
commit
d15eb325fc

+ 14
- 20
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ThisJoinPointVisitor.java View File

@@ -61,6 +61,7 @@ public class ThisJoinPointVisitor extends AbstractSyntaxTreeVisitorAdapter {
method.traverse(this, (ClassScope) null);

//??? add support for option to disable this optimization
//System.err.println("walked: " + method);
//System.err.println("check: "+ hasEffectivelyStaticRef + ", " + needsDynamic);
if (hasEffectivelyStaticRef && !needsDynamic) {
// replace effectively static refs with thisJoinPointStaticPart
@@ -68,41 +69,30 @@ public class ThisJoinPointVisitor extends AbstractSyntaxTreeVisitorAdapter {
needsStatic = true;
method.traverse(this, (ClassScope) null);
}
//System.err.println("done: " + method);
}

boolean isRef(NameReference ref, Binding binding) {
//System.err.println("check ref: " + ref + " is " + System.identityHashCode(ref));
return ref.binding == binding;
}

boolean isRef(Expression expr, Binding binding) {
//System.err.println("isRef: " + expr + ", " + binding);
return expr != null
&& expr instanceof NameReference
&& isRef((NameReference) expr, binding);
}

public void endVisit(SingleNameReference ref, BlockScope scope) {
if (isRef(ref, thisJoinPointDec))
if (isRef(ref, thisJoinPointDec)) {
needsDynamic = true;
else if (isRef(ref, thisJoinPointStaticPartDec))
} else if (isRef(ref, thisJoinPointStaticPartDec)) {
needsStatic = true;
else if (isRef(ref, thisEnclosingJoinPointStaticPartDec))
} else if (isRef(ref, thisEnclosingJoinPointStaticPartDec)) {
needsStaticEnclosing = true;
}
}

// public void checkAndFix(ASTObject body) {
// this.process(body);
// if (needsFakeStatic && !needsDynamic) {
// if (!this.getCompiler().getOptions().noMetaJoinPointOptimization) {
// makeFakeStatics = true;
// needsStatic = true;
// this.process(body);
// } else {
// needsDynamic = true;
// }
// }
// }

boolean canTreatAsStatic(String id) {
return id.equals("toString")
|| id.equals("toShortString")
@@ -158,13 +148,17 @@ public class ThisJoinPointVisitor extends AbstractSyntaxTreeVisitorAdapter {
}

private void replaceEffectivelyStaticRef(MessageSend call) {
//System.err.println("replace static ref");
NameReference receiver = (NameReference) call.receiver;
//System.err.println("replace static ref: " + receiver + " is " + System.identityHashCode(receiver));
receiver.binding = thisJoinPointStaticPartDecLocal; //thisJoinPointStaticPartDec;
receiver.codegenBinding = thisJoinPointStaticPartDecLocal;

call.binding.declaringClass =
(ReferenceBinding) thisJoinPointStaticPartDec.type;
call.binding = call.codegenBinding = getEquivalentStaticBinding(call.binding);
}
private MethodBinding getEquivalentStaticBinding(MethodBinding template) {
ReferenceBinding b = (ReferenceBinding)thisJoinPointStaticPartDec.type;
return b.getExactMethod(template.selector, template.parameters);
}

public int removeUnusedExtraArguments() {

+ 7
- 0
tests/ajcTests.xml View File

@@ -5566,4 +5566,11 @@
<compile files="SuperToIntro.java"/>
<run class="SuperToIntro"/>
</ajc-test>
<ajc-test dir="bugs/crashes" pr="30168"
title="Error with certain combination of advice">
<compile files="test/Test3.java"/>
<run class="test.Test3"/>
</ajc-test>

</suite>

+ 0
- 6
tests/ajcTestsFailing.xml View File

@@ -51,11 +51,5 @@
<message kind="warning" line="73"/>
</compile>
</ajc-test>
<ajc-test dir="bugs" pr="29959"
title="super call in intertype method declaration body causes VerifyError">
<compile files="SuperToIntro.java"/>
<run class="SuperToIntro"/>
</ajc-test>

</suite>

+ 38
- 0
tests/bugs/crashes/test/Test3.java View File

@@ -0,0 +1,38 @@
package test;
import org.aspectj.lang.*;
import org.aspectj.lang.reflect.*;

public class Test3 {
public static void main(String[] args) throws Exception {
Test3 a = new Test3();
a.foo(-3);
}
public void foo(int i) {
this.x=i;
}
int x;
}

aspect Log {
pointcut assign(Object newval, Object targ):
set(* test..*) && args(newval) && target(targ);

before(Object newval, Object targ): assign(newval,targ) {
Signature sign = thisJoinPoint.getSignature();
System.out.println(targ.toString() + "." + sign.getName() + ":=" + newval);
}
/*
}
// Different error message if you divide into two aspects
aspect Tracing {
*/
pointcut tracedCall():
call(* test..*(..))/* && !within(Tracing)*/ && !within(Log);

after() returning (Object o): tracedCall() {
// Works if you comment out either of these two lines
thisJoinPoint.getSignature();
System.out.println(thisJoinPoint);
}
}

+ 0
- 3
tests/jimTests.xml View File

@@ -1,9 +1,6 @@
<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd">
<suite>




<!--


Loading…
Cancel
Save