diff options
66 files changed, 3263 insertions, 0 deletions
diff --git a/tests/features152/synchronization/AfterLock.java b/tests/features152/synchronization/AfterLock.java new file mode 100644 index 000000000..34e5f9e2e --- /dev/null +++ b/tests/features152/synchronization/AfterLock.java @@ -0,0 +1,31 @@ +// after advice and lock + +public aspect AfterLock { + + after(Foo f): lock() && this(f) { + System.err.println("after(Foo) lock: advice running at "+thisJoinPoint.getSourceLocation()); + } + + after(): lock() { + System.err.println("after() lock: advice running at "+thisJoinPoint.getSourceLocation()); + } + + public static void main(String[] args) { + Foo aFoo = new Foo(); + aFoo.staticM(); + aFoo.nonstaticM(); + } + + static class Foo { + public void nonstaticM() { + synchronized (this) { + System.err.println("non-static method running"); + } + } + public static void staticM() { + synchronized (String.class) { + System.err.println("static method running"); + } + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/AfterUnlock.java b/tests/features152/synchronization/AfterUnlock.java new file mode 100644 index 000000000..5463a3215 --- /dev/null +++ b/tests/features152/synchronization/AfterUnlock.java @@ -0,0 +1,31 @@ +// after advice and unlock + +public aspect AfterUnlock { + + after(Foo f): unlock() && this(f) { + System.err.println("after(Foo) unlock: advice running at "+thisJoinPoint.getSourceLocation()); + } + + after(): unlock() { + System.err.println("after() unlock: advice running at "+thisJoinPoint.getSourceLocation()); + } + + public static void main(String[] args) { + Foo aFoo = new Foo(); + aFoo.staticM(); + aFoo.nonstaticM(); + } + + static class Foo { + public void nonstaticM() { + synchronized (this) { + System.err.println("non-static method running"); + } + } + public static void staticM() { + synchronized (String.class) { + System.err.println("static method running"); + } + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/AroundLock.java b/tests/features152/synchronization/AroundLock.java new file mode 100644 index 000000000..048fc8cd5 --- /dev/null +++ b/tests/features152/synchronization/AroundLock.java @@ -0,0 +1,41 @@ +// around advice and lock + +public aspect AroundLock { + + String s = "foo"; +// void around(Object f): lock() && args(f) { +// System.err.println("around(Object) lock: advice running at "+thisJoinPoint.getSourceLocation()); +// proceed(f); +// } + + void around(Object f): lock() && args(f){ + System.err.println("around() lock: advice running at "+thisJoinPoint.getSourceLocation()); + proceed(s); + proceed(s); + } + + void around(Object f): unlock() && args(f) { + System.err.println("around() unlock: advice running at "+thisJoinPoint.getSourceLocation()); + proceed(s); + proceed(s); + } + + public static void main(String[] args) { + Foo aFoo = new Foo(); + aFoo.staticM(); + aFoo.nonstaticM(); + } + + static class Foo { + public void nonstaticM() { + synchronized (this) { + System.err.println("non-static method running"); + } + } + public static void staticM() { + synchronized (String.class) { + System.err.println("static method running"); + } + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/AroundUnlock.java b/tests/features152/synchronization/AroundUnlock.java new file mode 100644 index 000000000..a4a3a91a8 --- /dev/null +++ b/tests/features152/synchronization/AroundUnlock.java @@ -0,0 +1,33 @@ +// around advice and unlock + +public aspect AroundUnlock { + + void around(Foo f): unlock() && args(f) { + System.err.println("around(Foo) lock: advice running at "+thisJoinPoint.getSourceLocation()); + proceed(f); + } + + void around(): unlock() { + System.err.println("around() lock: advice running at "+thisJoinPoint.getSourceLocation()); + proceed(); + } + + public static void main(String[] args) { + Foo aFoo = new Foo(); + aFoo.staticM(); + aFoo.nonstaticM(); + } + + static class Foo { + public void nonstaticM() { + synchronized (this) { + System.err.println("non-static method running"); + } + } + public static void staticM() { + synchronized (String.class) { + System.err.println("static method running"); + } + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/Basic.java b/tests/features152/synchronization/Basic.java new file mode 100644 index 000000000..3af3d523c --- /dev/null +++ b/tests/features152/synchronization/Basic.java @@ -0,0 +1,44 @@ +// Exploring synchronization + +public class Basic { + public static void main(String[] args) { + Basic b = new Basic(); + + b.methodWithSyncBlock1(); + b.staticMethodWithSyncBlock1(); + b.methodWithSyncBlock2(); + b.staticMethodWithSyncBlock2(); + } + + public void methodWithSyncBlock1() { + System.err.println("methodWithSyncBlock1"); + synchronized (this) { + } + } + + public void staticMethodWithSyncBlock1() { + System.err.println("staticMethodWithSyncBlock1"); + synchronized (Basic.class) { + } + } + + public void methodWithSyncBlock2() { + System.err.println("methodWithSyncBlock2"); + synchronized (this) { + int i = 0; + while (i<100) { + i++; + } + } + } + + public void staticMethodWithSyncBlock2() { + System.err.println("staticMethodWithSyncBlock2"); + synchronized (Basic.class) { + int i = 0; + while (i<100) { + i++; + } + } + } +} diff --git a/tests/features152/synchronization/Basic2.java b/tests/features152/synchronization/Basic2.java new file mode 100644 index 000000000..c7fade755 --- /dev/null +++ b/tests/features152/synchronization/Basic2.java @@ -0,0 +1,51 @@ +// Exploring synchronization + +aspect WithinAspect { + before(): within(Basic2) { + if (thisJoinPoint.toString().indexOf("lock(")!=-1) + System.err.println("Advice running at "+thisJoinPoint.getSignature()); + } +} + +public class Basic2 { + public static void main(String[] args) { + Basic2 b = new Basic2(); + + b.methodWithSyncBlock1(); + b.staticMethodWithSyncBlock1(); + b.methodWithSyncBlock2(); + b.staticMethodWithSyncBlock2(); + } + + public void methodWithSyncBlock1() { + System.err.println("methodWithSyncBlock1"); + synchronized (this) { + } + } + + public void staticMethodWithSyncBlock1() { + System.err.println("staticMethodWithSyncBlock1"); + synchronized (Basic2.class) { + } + } + + public void methodWithSyncBlock2() { + System.err.println("methodWithSyncBlock2"); + synchronized (this) { + int i = 0; + while (i<100) { + i++; + } + } + } + + public void staticMethodWithSyncBlock2() { + System.err.println("staticMethodWithSyncBlock2"); + synchronized (Basic2.class) { + int i = 0; + while (i<100) { + i++; + } + } + } +} diff --git a/tests/features152/synchronization/Basic3.java b/tests/features152/synchronization/Basic3.java new file mode 100644 index 000000000..01c196715 --- /dev/null +++ b/tests/features152/synchronization/Basic3.java @@ -0,0 +1,52 @@ +// Exploring synchronization + +aspect WithinAspect { + before(Object o ): within(Basic3) && this(o) { + if (thisJoinPoint.getSignature().toString().indexOf("lock(")!=-1) + System.err.println("Advice running at "+thisJoinPoint.getSignature()+ + " with this of type "+o.getClass()+" with value "+o); + } +} + +public class Basic3 { + public static void main(String[] args) { + Basic3 b = new Basic3(); + + b.methodWithSyncBlock1(); + b.staticMethodWithSyncBlock1(); + b.methodWithSyncBlock2(); + b.staticMethodWithSyncBlock2(); + } + + public void methodWithSyncBlock1() { + System.err.println("methodWithSyncBlock1"); + synchronized (this) { + } + } + + public void staticMethodWithSyncBlock1() { + System.err.println("staticMethodWithSyncBlock1"); + synchronized (Basic3.class) { + } + } + + public void methodWithSyncBlock2() { + System.err.println("methodWithSyncBlock2"); + synchronized (this) { + int i = 0; + while (i<100) { + i++; + } + } + } + + public void staticMethodWithSyncBlock2() { + System.err.println("staticMethodWithSyncBlock2"); + synchronized (Basic3.class) { + int i = 0; + while (i<100) { + i++; + } + } + } +} diff --git a/tests/features152/synchronization/Basic4.java b/tests/features152/synchronization/Basic4.java new file mode 100644 index 000000000..787f550a8 --- /dev/null +++ b/tests/features152/synchronization/Basic4.java @@ -0,0 +1,52 @@ +// Exploring synchronization + +aspect WithinAspect { + before(Object o ): within(Basic4) && args(o) { + if (thisJoinPoint.getSignature().toString().indexOf("lock(")!=-1) + System.err.println("Advice running at "+thisJoinPoint.getSignature()+ + " with args of type "+o.getClass()+" with value "+o); + } +} + +public class Basic4 { + public static void main(String[] args) { + Basic4 b = new Basic4(); + + b.methodWithSyncBlock1(); + b.staticMethodWithSyncBlock1(); + b.methodWithSyncBlock2(); + b.staticMethodWithSyncBlock2(); + } + + public void methodWithSyncBlock1() { + System.err.println("methodWithSyncBlock1"); + synchronized (this) { + } + } + + public void staticMethodWithSyncBlock1() { + System.err.println("staticMethodWithSyncBlock1"); + synchronized (Basic4.class) { + } + } + + public void methodWithSyncBlock2() { + System.err.println("methodWithSyncBlock2"); + synchronized (this) { + int i = 0; + while (i<100) { + i++; + } + } + } + + public void staticMethodWithSyncBlock2() { + System.err.println("staticMethodWithSyncBlock2"); + synchronized (Basic4.class) { + int i = 0; + while (i<100) { + i++; + } + } + } +} diff --git a/tests/features152/synchronization/Basic5.java b/tests/features152/synchronization/Basic5.java new file mode 100644 index 000000000..062b32014 --- /dev/null +++ b/tests/features152/synchronization/Basic5.java @@ -0,0 +1,52 @@ +// Exploring synchronization + +aspect WithinAspect { + before(Object o ): within(Basic5) && target(o) { + if (thisJoinPoint.getSignature().toString().indexOf("lock")!=-1) + System.err.println("Advice running at "+thisJoinPoint.getSignature()+ + " with target of type "+o.getClass()+" with value "+o); + } +} + +public class Basic5 { + public static void main(String[] args) { + Basic5 b = new Basic5(); + + b.methodWithSyncBlock1(); + b.staticMethodWithSyncBlock1(); + b.methodWithSyncBlock2(); + b.staticMethodWithSyncBlock2(); + } + + public void methodWithSyncBlock1() { + System.err.println("methodWithSyncBlock1"); + synchronized (this) { + } + } + + public void staticMethodWithSyncBlock1() { + System.err.println("staticMethodWithSyncBlock1"); + synchronized (Basic5.class) { + } + } + + public void methodWithSyncBlock2() { + System.err.println("methodWithSyncBlock2"); + synchronized (this) { + int i = 0; + while (i<100) { + i++; + } + } + } + + public void staticMethodWithSyncBlock2() { + System.err.println("staticMethodWithSyncBlock2"); + synchronized (Basic5.class) { + int i = 0; + while (i<100) { + i++; + } + } + } +} diff --git a/tests/features152/synchronization/BasicProgram1.java b/tests/features152/synchronization/BasicProgram1.java new file mode 100644 index 000000000..7e1491300 --- /dev/null +++ b/tests/features152/synchronization/BasicProgram1.java @@ -0,0 +1,21 @@ +// Subject to LTW + +public class BasicProgram1 { + + public static void main(String[] args) { + new BasicProgram1().nonstaticM(); + staticM(); + } + + public static void staticM() { + synchronized (String.class) { + System.err.println("static method running"); + } + } + + public void nonstaticM() { + synchronized (this) { + System.err.println("nonstatic method running"); + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/BeforeLock.java b/tests/features152/synchronization/BeforeLock.java new file mode 100644 index 000000000..334137ad1 --- /dev/null +++ b/tests/features152/synchronization/BeforeLock.java @@ -0,0 +1,31 @@ +// before advice and lock + +public aspect BeforeLock { + + before(Foo f): lock() && this(f) { + System.err.println("before(Foo) lock: advice running at "+thisJoinPoint.getSourceLocation()); + } + + before(): lock() { + System.err.println("before() lock: advice running at "+thisJoinPoint.getSourceLocation()); + } + + public static void main(String[] args) { + Foo aFoo = new Foo(); + aFoo.staticM(); + aFoo.nonstaticM(); + } + + static class Foo { + public void nonstaticM() { + synchronized (this) { + System.err.println("non-static method running"); + } + } + public static void staticM() { + synchronized (String.class) { + System.err.println("static method running"); + } + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/BeforeUnlock.java b/tests/features152/synchronization/BeforeUnlock.java new file mode 100644 index 000000000..8ef6401e1 --- /dev/null +++ b/tests/features152/synchronization/BeforeUnlock.java @@ -0,0 +1,31 @@ +// before advice and unlock + +public aspect BeforeUnlock { + + before(Foo f): unlock() && this(f) { + System.err.println("before(Foo) unlock: advice running at "+thisJoinPoint.getSourceLocation()); + } + + before(): unlock() { + System.err.println("before() unlock: advice running at "+thisJoinPoint.getSourceLocation()); + } + + public static void main(String[] args) { + Foo aFoo = new Foo(); + aFoo.staticM(); + aFoo.nonstaticM(); + } + + static class Foo { + public void nonstaticM() { + synchronized (this) { + System.err.println("non-static method running"); + } + } + public static void staticM() { + synchronized (String.class) { + System.err.println("static method running"); + } + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/CombiningPCDs1.java b/tests/features152/synchronization/CombiningPCDs1.java new file mode 100644 index 000000000..153c6134b --- /dev/null +++ b/tests/features152/synchronization/CombiningPCDs1.java @@ -0,0 +1,27 @@ +// lock/this + +public aspect CombiningPCDs1 { + + before(Foo f): lock() && this(f) { + System.err.println("advice running at "+thisJoinPoint.getSourceLocation()); + } + + public static void main(String[] args) { + Foo aFoo = new Foo(); + aFoo.staticM(); + aFoo.nonstaticM(); + } + + static class Foo { + public void nonstaticM() { + synchronized (this) { + System.err.println("non-static method running"); + } + } + public static void staticM() { + synchronized (String.class) { + System.err.println("static method running"); + } + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/CombiningPCDs2.java b/tests/features152/synchronization/CombiningPCDs2.java new file mode 100644 index 000000000..bd0653eed --- /dev/null +++ b/tests/features152/synchronization/CombiningPCDs2.java @@ -0,0 +1,27 @@ +// unlock/this + +public aspect CombiningPCDs2 { + + before(Foo f): unlock() && this(f) { + System.err.println("advice running at "+thisJoinPoint.getSourceLocation()); + } + + public static void main(String[] args) { + Foo aFoo = new Foo(); + aFoo.staticM(); + aFoo.nonstaticM(); + } + + static class Foo { + public void nonstaticM() { + synchronized (this) { + System.err.println("non-static method running"); + } + } + public static void staticM() { + synchronized (String.class) { + System.err.println("static method running"); + } + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/LockAspect1.java b/tests/features152/synchronization/LockAspect1.java new file mode 100644 index 000000000..a1b0bbc08 --- /dev/null +++ b/tests/features152/synchronization/LockAspect1.java @@ -0,0 +1,9 @@ +// to be LTW with BasicProgram1 +import org.aspectj.lang.annotation.*; + +public aspect LockAspect1 { + @SuppressAjWarnings("adviceDidNotMatch") + before(): lock() { + System.err.println("Lock advice running at "+thisJoinPoint.getSourceLocation()); + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/LockingWithTJP.java b/tests/features152/synchronization/LockingWithTJP.java new file mode 100644 index 000000000..a07b567ce --- /dev/null +++ b/tests/features152/synchronization/LockingWithTJP.java @@ -0,0 +1,28 @@ +// obtaining the object being locked on + +public aspect LockingWithTJP { + + before(): lock() { + System.err.println("before() lock: advice running at "+thisJoinPoint.getSourceLocation()); + System.err.println("Locked on "+thisJoinPoint.getArgs()[0]); + } + + public static void main(String[] args) { + Foo aFoo = new Foo(); + aFoo.nonstaticM(); + aFoo.staticM(); + } + + static class Foo { + public void nonstaticM() { + synchronized (this) { + System.err.println("non-static method running"); + } + } + public static void staticM() { + synchronized (String.class) { + System.err.println("static method running"); + } + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/Parsing1.java b/tests/features152/synchronization/Parsing1.java new file mode 100644 index 000000000..a1ee5fdfd --- /dev/null +++ b/tests/features152/synchronization/Parsing1.java @@ -0,0 +1,14 @@ +// Exploring synchronization + +public aspect Parsing1 { + + before(): lock() { } + + public static void main(String[] args) { + staticM(); + } + + public static void staticM() { +// synchronized (String.class) {} + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/Parsing2.java b/tests/features152/synchronization/Parsing2.java new file mode 100644 index 000000000..f0d4a1cbb --- /dev/null +++ b/tests/features152/synchronization/Parsing2.java @@ -0,0 +1,14 @@ +// Exploring synchronization + +public aspect Parsing2 { + + before(): unlock() { } + + public static void main(String[] args) { + staticM(); + } + + public static void staticM() { +// synchronized (String.class) {} + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/ParsingAndMatching1.java b/tests/features152/synchronization/ParsingAndMatching1.java new file mode 100644 index 000000000..9c6ab82aa --- /dev/null +++ b/tests/features152/synchronization/ParsingAndMatching1.java @@ -0,0 +1,18 @@ +// lock and static context + +public aspect ParsingAndMatching1 { + + before(): lock() { + System.err.println("Advice running at "+thisJoinPoint.getSourceLocation()); + } + + public static void main(String[] args) { + staticM(); + } + + public static void staticM() { + synchronized (String.class) { + System.err.println("static method running"); + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/ParsingAndMatching2.java b/tests/features152/synchronization/ParsingAndMatching2.java new file mode 100644 index 000000000..87599cb07 --- /dev/null +++ b/tests/features152/synchronization/ParsingAndMatching2.java @@ -0,0 +1,18 @@ +// unlock and static context + +public aspect ParsingAndMatching2 { + + before(): unlock() { + System.err.println("Advice running at "+thisJoinPoint.getSourceLocation()); + } + + public static void main(String[] args) { + staticM(); + } + + public static void staticM() { + synchronized (String.class) { + System.err.println("static method running"); + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/ParsingAndMatching3.java b/tests/features152/synchronization/ParsingAndMatching3.java new file mode 100644 index 000000000..7a6fee6c2 --- /dev/null +++ b/tests/features152/synchronization/ParsingAndMatching3.java @@ -0,0 +1,20 @@ +// lock and non-static context + +public aspect ParsingAndMatching3 { + + before(): lock() { + System.err.println("Advice running at "+thisJoinPoint.getSourceLocation()); + } + + public static void main(String[] args) { + new Foo().nonstaticM(); + } + + static class Foo { + public void nonstaticM() { + synchronized (String.class) { + System.err.println("non-static method running"); + } + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/ParsingAndMatching4.java b/tests/features152/synchronization/ParsingAndMatching4.java new file mode 100644 index 000000000..4fe3c6f5d --- /dev/null +++ b/tests/features152/synchronization/ParsingAndMatching4.java @@ -0,0 +1,20 @@ +// unlock and non-static context + +public aspect ParsingAndMatching4 { + + before(): unlock() { + System.err.println("Advice running at "+thisJoinPoint.getSourceLocation()); + } + + public static void main(String[] args) { + new Foo().nonstaticM(); + } + + static class Foo { + public void nonstaticM() { + synchronized (String.class) { + System.err.println("non-static method running"); + } + } + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/ThisJoinPointLock.java b/tests/features152/synchronization/ThisJoinPointLock.java new file mode 100644 index 000000000..ed5376a79 --- /dev/null +++ b/tests/features152/synchronization/ThisJoinPointLock.java @@ -0,0 +1,48 @@ +import org.aspectj.lang.reflect.*; + +aspect TJPAspect { + before(): withincode(void ThisJoinPointLock.nonStaticMethod()) { + if (thisJoinPoint.getSignature() instanceof LockSignature) { + System.err.println("match.toString(): "+thisJoinPoint.toString()); + System.err.println("match.toShortString(): "+thisJoinPoint.toShortString()); + System.err.println("match.toLongString(): "+thisJoinPoint.toLongString()); + } + + // SHORT => shorttypenames, no args, no throws, no modifiers, short type names + // MIDDLE=> args included + // LONG => modifiers included + } + +// before(): withincode(void ThisJoinPointLock.nonStaticMethod()) { +// if (thisJoinPoint.getSignature() instanceof MethodSignature) { +// System.err.println("match.toString(): "+thisJoinPoint.toString()); +// System.err.println("match.toShortString(): "+thisJoinPoint.toShortString()); +// System.err.println("match.toLongString(): "+thisJoinPoint.toLongString()); +// } +// +// // SHORT => shorttypenames, no args, no throws, no modifiers, short type names +// // MIDDLE=> args included +// // LONG => modifiers included +// } + +} + +public class ThisJoinPointLock { + public static void main(String[] args) { + ThisJoinPointLock b = new ThisJoinPointLock(); + b.nonStaticMethod(); + b.staticMethod(); + } + + public void nonStaticMethod() { + synchronized (this) { + staticMethod(); + } + } + + public void staticMethod() { + synchronized (ThisJoinPointLock.class) { + } + } + +} diff --git a/tests/features152/synchronization/ThisJoinPointUnlock.java b/tests/features152/synchronization/ThisJoinPointUnlock.java new file mode 100644 index 000000000..46bee3da5 --- /dev/null +++ b/tests/features152/synchronization/ThisJoinPointUnlock.java @@ -0,0 +1,48 @@ +import org.aspectj.lang.reflect.*; + +aspect TJPAspect { + before(): withincode(void ThisJoinPointUnlock.nonStaticMethod()) { + if (thisJoinPoint.getSignature() instanceof UnlockSignature) { + System.err.println("match.toString(): "+thisJoinPoint.toString()); + System.err.println("match.toShortString(): "+thisJoinPoint.toShortString()); + System.err.println("match.toLongString(): "+thisJoinPoint.toLongString()); + } + + // SHORT => shorttypenames, no args, no throws, no modifiers, short type names + // MIDDLE=> args included + // LONG => modifiers included + } + +// before(): withincode(void ThisJoinPointLock.nonStaticMethod()) { +// if (thisJoinPoint.getSignature() instanceof MethodSignature) { +// System.err.println("match.toString(): "+thisJoinPoint.toString()); +// System.err.println("match.toShortString(): "+thisJoinPoint.toShortString()); +// System.err.println("match.toLongString(): "+thisJoinPoint.toLongString()); +// } +// +// // SHORT => shorttypenames, no args, no throws, no modifiers, short type names +// // MIDDLE=> args included +// // LONG => modifiers included +// } + +} + +public class ThisJoinPointUnlock { + public static void main(String[] args) { + ThisJoinPointUnlock b = new ThisJoinPointUnlock(); + b.nonStaticMethod(); + b.staticMethod(); + } + + public void nonStaticMethod() { + synchronized (this) { + staticMethod(); + } + } + + public void staticMethod() { + synchronized (ThisJoinPointUnlock.class) { + } + } + +} diff --git a/tests/features152/synchronization/UnlockAspect1.java b/tests/features152/synchronization/UnlockAspect1.java new file mode 100644 index 000000000..b91e0a1e2 --- /dev/null +++ b/tests/features152/synchronization/UnlockAspect1.java @@ -0,0 +1,9 @@ +// to be LTW with BasicProgram1 +import org.aspectj.lang.annotation.*; + +public aspect UnlockAspect1 { + @SuppressAjWarnings("adviceDidNotMatch") + before(): unlock() { + System.err.println("Unlock advice running at "+thisJoinPoint.getSourceLocation()); + } +}
\ No newline at end of file diff --git a/tests/features152/synchronization/Useful1.java b/tests/features152/synchronization/Useful1.java new file mode 100644 index 000000000..d8ecbe3a0 --- /dev/null +++ b/tests/features152/synchronization/Useful1.java @@ -0,0 +1,51 @@ +// Exploring synchronization + +aspect WithinAspect { + long locktimer = 0; + int iterations = 0; + Object currentObject = null; + boolean didSomething = false; + long activeTimer; + + before(Object o ): within(Useful1) && args(o) { + if (thisJoinPoint.getSignature().toString().startsWith("lock(")) { + activeTimer = System.currentTimeMillis(); + didSomething = true; + } + } + + after(Object o ): within(Useful1) && args(o) { + if (thisJoinPoint.getSignature().toString().startsWith("unlock(")) { + if (activeTimer!=0) { + locktimer+=(System.currentTimeMillis()-activeTimer); + iterations++; + activeTimer=0; + didSomething = true; + } + } + } + + after() returning: execution(* main(..)) { + System.err.println("Average lock taking time over "+iterations+" iterations is "+ + (((double)locktimer)/ + ((double)iterations))+"ms"); + if (didSomething) System.err.println("We did time something!"); // can write a test looking for this line, it won't vary + } +} + +public class Useful1 { + public static void main(String[] args) { + Useful1 u = new Useful1(); + + for (int i = 0; i < 2000; i++) { + u.methodWithSynchronizedBlock(); + } + } + + public void methodWithSynchronizedBlock() { + synchronized (this) { + for (int ii=0;ii<100;ii++); + } + } + +} diff --git a/tests/features152/synchronization/Useful2.java b/tests/features152/synchronization/Useful2.java new file mode 100644 index 000000000..46fc82d5a --- /dev/null +++ b/tests/features152/synchronization/Useful2.java @@ -0,0 +1,47 @@ +// Exploring synchronization + +aspect LockMonitor { + long locktimer = 0; + int iterations = 0; + Object currentObject = null; + long activeTimer; + + before(Useful2 o ): lock() && args(o) { + activeTimer = System.currentTimeMillis(); + currentObject = o; + } + + after(Useful2 o ): unlock() && args(o) { + if (o!=currentObject) { + throw new RuntimeException("Unlocking on incorrect thing?!?"); + } + if (activeTimer!=0) { + locktimer+=(System.currentTimeMillis()-activeTimer); + iterations++; + activeTimer=0; + } + } + + after() returning: execution(* main(..)) { + System.err.println("Average time spent with lock over "+iterations+" iterations is "+ + (((double)locktimer)/ + ((double)iterations))+"ms"); + } +} + +public class Useful2 { + public static void main(String[] args) { + Useful2 u = new Useful2(); + + for (int i = 0; i < 20; i++) { + u.methodWithSynchronizedBlock(); + } + } + + public void methodWithSynchronizedBlock() { + synchronized (this) { + for (int ii=0;ii<1000000;ii++); + } + } + +} diff --git a/tests/features152/synchronization/aop1.xml b/tests/features152/synchronization/aop1.xml new file mode 100644 index 000000000..c4c26ddaa --- /dev/null +++ b/tests/features152/synchronization/aop1.xml @@ -0,0 +1,8 @@ +<aspectj> + <aspects> + <aspect name="LockAspect1"/> + </aspects> + + <weaver options="-showWeaveInfo "> + </weaver> +</aspectj>
\ No newline at end of file diff --git a/tests/features152/synchronization/aop2.xml b/tests/features152/synchronization/aop2.xml new file mode 100644 index 000000000..1488e6e22 --- /dev/null +++ b/tests/features152/synchronization/aop2.xml @@ -0,0 +1,8 @@ +<aspectj> + <aspects> + <aspect name="UnlockAspect1"/> + </aspects> + + <weaver options="-showWeaveInfo"> + </weaver> +</aspectj>
\ No newline at end of file diff --git a/tests/features152/synchronization/aop3.xml b/tests/features152/synchronization/aop3.xml new file mode 100644 index 000000000..e07f8feae --- /dev/null +++ b/tests/features152/synchronization/aop3.xml @@ -0,0 +1,8 @@ +<aspectj> + <aspects> + <aspect name="LockAspect1"/> + </aspects> + + <weaver options=" -showWeaveInfo -Xjoinpoints:synchronization,trivial"> + </weaver> +</aspectj>
\ No newline at end of file diff --git a/tests/features152/synchronization/aop4.xml b/tests/features152/synchronization/aop4.xml new file mode 100644 index 000000000..892a16a0d --- /dev/null +++ b/tests/features152/synchronization/aop4.xml @@ -0,0 +1,8 @@ +<aspectj> + <aspects> + <aspect name="UnlockAspect1"/> + </aspects> + + <weaver options=" -showWeaveInfo -Xjoinpoints:synchronization"> + </weaver> +</aspectj>
\ No newline at end of file diff --git a/tests/features152/synchronization/transformed/Eight.java b/tests/features152/synchronization/transformed/Eight.java new file mode 100644 index 000000000..79af0a625 --- /dev/null +++ b/tests/features152/synchronization/transformed/Eight.java @@ -0,0 +1,22 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +// matching unlock in a transformed non-static method... + +public aspect Eight { + public static void main(String[] args) { + new C().b(); + } + + before(): !within(Eight) && unlock() { + System.err.println("Unlocking occurring at "+thisJoinPoint); + System.err.println(thisJoinPoint.getSourceLocation().getFileName()); + } +} + +class C { + public synchronized void b() { + System.err.println("hello"); + } +} diff --git a/tests/features152/synchronization/transformed/Eleven.java b/tests/features152/synchronization/transformed/Eleven.java new file mode 100644 index 000000000..e9a3fa85a --- /dev/null +++ b/tests/features152/synchronization/transformed/Eleven.java @@ -0,0 +1,22 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +// matching lock on transformed static method ( pre J5) + +public aspect Eleven { + public static void main(String[] args) { + C.b(); + } + + before(): !within(Eleven) && lock() { + System.err.println("Locking occurring at "+thisJoinPoint); + System.err.println(thisJoinPoint.getSourceLocation().getFileName()); + } +} + +class C { + public static synchronized void b() { + System.err.println("hello"); + } +} diff --git a/tests/features152/synchronization/transformed/Five.java b/tests/features152/synchronization/transformed/Five.java new file mode 100644 index 000000000..e5e30c6f5 --- /dev/null +++ b/tests/features152/synchronization/transformed/Five.java @@ -0,0 +1,38 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public aspect Five { + public static void main(String[] args) { + C.b(); + C.c(); + C.d(); + C.e(); + } + + before(): !within(Five) && call(* println(..)) { System.err.println("test");} +} + +class C { + public static synchronized void b() { + System.err.println("hello"); + } + + public static void c() { + synchronized (C.class) { + System.err.println("hello"); + } + } + public static void d() { + synchronized (String.class) { + System.err.println("hello"); + } + } + public static void e() { + synchronized (Five.class) { + System.err.println("hello"); + } + } +} + +aspect FiveX { pointcut p(): unlock(); } diff --git a/tests/features152/synchronization/transformed/Four.java b/tests/features152/synchronization/transformed/Four.java new file mode 100644 index 000000000..454fdb1f1 --- /dev/null +++ b/tests/features152/synchronization/transformed/Four.java @@ -0,0 +1,29 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public aspect Four { + public static void main(String[] args) { + new C().m(); + try {new C().m2(); } catch (MyException me) {int i=1;} + } + after() returning: execution(synchronized * m(..)) { System.err.println("execution advice running1");} + after() throwing: execution(synchronized * m2(..)) { System.err.println("execution advice running2");} +} + +class C { + + public synchronized void m() { + System.err.println("hello"); + } + + public synchronized void m2() { + System.err.println("hello"); + throw new MyException(); + } + +} + +class MyException extends RuntimeException { } + +aspect FourX { pointcut p(): lock(); } diff --git a/tests/features152/synchronization/transformed/Investigation.java b/tests/features152/synchronization/transformed/Investigation.java new file mode 100644 index 000000000..1fad31a6f --- /dev/null +++ b/tests/features152/synchronization/transformed/Investigation.java @@ -0,0 +1,357 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public class Investigation { + public static void main(String[] args) { + + } + + + // Basic synchronized method + public void a() { + synchronized (this) { + + } + } + + // ... that does something ... + public void b() { + synchronized (this) { + System.out.println("hello"); + } + } + + // ... that includes try/catch ... + public void c() { + synchronized(this) { + try { + File f = new File("fred"); + FileInputStream fis = new FileInputStream(f); + } catch (IOException ioe) { + System.out.println("bang"); + } + } + } + + // ... with multiple synchronized blocks ... + public void d() { + synchronized (this) { + System.out.println("hello"); + } + synchronized (this) { + System.out.println("world"); + } + } + + // ... with nested synchronized blocks ... + public void e() { + synchronized (this) { + System.out.println("hello"); + synchronized (new String()) { + System.out.println("other"); + } + } + } + + /* + Compiled from "Investigation.java" + public class Investigation extends java.lang.Object + SourceFile: "Investigation.java" + minor version: 0 + major version: 46 + Constant pool: + const #1 = Asciz Investigation; + const #2 = class #1; // Investigation + const #3 = Asciz java/lang/Object; + const #4 = class #3; // java/lang/Object + const #5 = Asciz <init>; + const #6 = Asciz ()V; + const #7 = Asciz Code; + const #8 = NameAndType #5:#6;// "<init>":()V + const #9 = Method #4.#8; // java/lang/Object."<init>":()V + const #10 = Asciz LineNumberTable; + const #11 = Asciz LocalVariableTable; + const #12 = Asciz this; + const #13 = Asciz LInvestigation;; + const #14 = Asciz main; + const #15 = Asciz ([Ljava/lang/String;)V; + const #16 = Asciz org.aspectj.weaver.MethodDeclarationLineNumber; + const #17 = Asciz args; + const #18 = Asciz [Ljava/lang/String;; + const #19 = Asciz a; + const #20 = Asciz b; + const #21 = Asciz java/lang/System; + const #22 = class #21; // java/lang/System + const #23 = Asciz out; + const #24 = Asciz Ljava/io/PrintStream;; + const #25 = NameAndType #23:#24;// out:Ljava/io/PrintStream; + const #26 = Field #22.#25; // java/lang/System.out:Ljava/io/PrintStream; + const #27 = Asciz hello; + const #28 = String #27; // hello + const #29 = Asciz java/io/PrintStream; + const #30 = class #29; // java/io/PrintStream + const #31 = Asciz println; + const #32 = Asciz (Ljava/lang/String;)V; + const #33 = NameAndType #31:#32;// println:(Ljava/lang/String;)V + const #34 = Method #30.#33; // java/io/PrintStream.println:(Ljava/lang/String;)V + const #35 = Asciz c; + const #36 = Asciz java/io/File; + const #37 = class #36; // java/io/File + const #38 = Asciz fred; + const #39 = String #38; // fred + const #40 = NameAndType #5:#32;// "<init>":(Ljava/lang/String;)V + const #41 = Method #37.#40; // java/io/File."<init>":(Ljava/lang/String;)V + const #42 = Asciz java/io/FileInputStream; + const #43 = class #42; // java/io/FileInputStream + const #44 = Asciz (Ljava/io/File;)V; + const #45 = NameAndType #5:#44;// "<init>":(Ljava/io/File;)V + const #46 = Method #43.#45; // java/io/FileInputStream."<init>":(Ljava/io/File;)V + const #47 = Asciz bang; + const #48 = String #47; // bang + const #49 = Asciz java/io/IOException; + const #50 = class #49; // java/io/IOException + const #51 = Asciz f; + const #52 = Asciz Ljava/io/File;; + const #53 = Asciz d; + const #54 = Asciz world; + const #55 = String #54; // world + const #56 = Asciz e; + const #57 = Asciz java/lang/String; + const #58 = class #57; // java/lang/String + const #59 = Method #58.#8; // java/lang/String."<init>":()V + const #60 = Asciz other; + const #61 = String #60; // other + const #62 = Asciz SourceFile; + const #63 = Asciz Investigation.java; + + { + public Investigation(); + Code: + Stack=1, Locals=1, Args_size=1 + 0: aload_0 + 1: invokespecial #9; //Method java/lang/Object."<init>":()V + 4: return + LineNumberTable: + line 5: 0 + LocalVariableTable: + Start Length Slot Name Signature + 0 5 0 this LInvestigation; + + public static void main(java.lang.String[]); + org.aspectj.weaver.MethodDeclarationLineNumber: length = 0x8 + 00 00 00 06 00 00 00 FFFFFF88 + Code: + Stack=0, Locals=1, Args_size=1 + 0: return + LineNumberTable: + line 8: 0 + LocalVariableTable: + Start Length Slot Name Signature + 0 1 0 args [Ljava/lang/String; + + public void a(); + org.aspectj.weaver.MethodDeclarationLineNumber: length = 0x8 + 00 00 00 0C 00 00 00 FFFFFFD9 + Code: + Stack=2, Locals=1, Args_size=1 + 0: aload_0 + 1: dup + 2: monitorenter + 3: monitorexit + 4: return + LineNumberTable: + line 13: 0 + line 16: 4 + LocalVariableTable: + Start Length Slot Name Signature + 0 5 0 this LInvestigation; + + public void b(); + org.aspectj.weaver.MethodDeclarationLineNumber: length = 0x8 + 00 00 00 13 00 00 01 38 + Code: + Stack=2, Locals=2, Args_size=1 + 0: aload_0 + 1: dup + 2: astore_1 + 3: monitorenter + 4: getstatic #26; //Field java/lang/System.out:Ljava/io/PrintStream; + 7: ldc #28; //String hello + 9: invokevirtual #34; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 12: aload_1 + 13: monitorexit + 14: goto 20 + 17: aload_1 + 18: monitorexit + 19: athrow + 20: return + Exception table: + from to target type + 4 14 17 any + 17 19 17 any + LineNumberTable: + line 20: 0 + line 21: 4 + line 20: 12 + line 23: 20 + LocalVariableTable: + Start Length Slot Name Signature + 0 21 0 this LInvestigation; + + public void c(); + org.aspectj.weaver.MethodDeclarationLineNumber: length = 0x8 + 00 00 00 1A 00 00 01 FFFFFFB7 + Code: + Stack=3, Locals=3, Args_size=1 + 0: aload_0 + 1: dup + 2: astore_1 + 3: monitorenter + 4: new #37; //class java/io/File + 7: dup + 8: ldc #39; //String fred + 10: invokespecial #41; //Method java/io/File."<init>":(Ljava/lang/String;)V + 13: astore_2 + 14: new #43; //class java/io/FileInputStream + 17: dup + 18: aload_2 + 19: invokespecial #46; //Method java/io/FileInputStream."<init>":(Ljava/io/File;)V + 22: pop + 23: goto 35 + 26: pop + 27: getstatic #26; //Field java/lang/System.out:Ljava/io/PrintStream; + 30: ldc #48; //String bang + 32: invokevirtual #34; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 35: aload_1 + 36: monitorexit + 37: goto 43 + 40: aload_1 + 41: monitorexit + 42: athrow + 43: return + Exception table: + from to target type + 4 26 26 Class java/io/IOException + + 4 37 40 any + 40 42 40 any + LineNumberTable: + line 27: 0 + line 29: 4 + line 30: 14 + line 31: 26 + line 32: 27 + line 27: 35 + line 35: 43 + LocalVariableTable: + Start Length Slot Name Signature + 0 44 0 this LInvestigation; + 14 12 2 f Ljava/io/File; + + public void d(); + org.aspectj.weaver.MethodDeclarationLineNumber: length = 0x8 + 00 00 00 26 00 00 02 FFFFFFC2 + Code: + Stack=2, Locals=2, Args_size=1 + 0: aload_0 + 1: dup + 2: astore_1 + 3: monitorenter + 4: getstatic #26; //Field java/lang/System.out:Ljava/io/PrintStream; + 7: ldc #28; //String hello + 9: invokevirtual #34; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 12: aload_1 + 13: monitorexit + 14: goto 20 + 17: aload_1 + 18: monitorexit + 19: athrow + 20: aload_0 + 21: dup + 22: astore_1 + 23: monitorenter + 24: getstatic #26; //Field java/lang/System.out:Ljava/io/PrintStream; + 27: ldc #55; //String world + 29: invokevirtual #34; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 32: aload_1 + 33: monitorexit + 34: goto 40 + 37: aload_1 + 38: monitorexit + 39: athrow + 40: return + Exception table: + from to target type + 4 14 17 any + 17 19 17 any + 24 34 37 any + 37 39 37 any + LineNumberTable: + line 39: 0 + line 40: 4 + line 39: 12 + line 42: 20 + line 43: 24 + line 42: 32 + line 45: 40 + LocalVariableTable: + Start Length Slot Name Signature + 0 41 0 this LInvestigation; + + public void e(); + org.aspectj.weaver.MethodDeclarationLineNumber: length = 0x8 + 00 00 00 30 00 00 03 FFFFFF88 + Code: + Stack=2, Locals=3, Args_size=1 + 0: aload_0 + 1: dup + 2: astore_1 + 3: monitorenter + 4: getstatic #26; //Field java/lang/System.out:Ljava/io/PrintStream; + 7: ldc #28; //String hello + 9: invokevirtual #34; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 12: new #58; //class java/lang/String + 15: dup + 16: invokespecial #59; //Method java/lang/String."<init>":()V + 19: dup + 20: astore_2 + 21: monitorenter + 22: getstatic #26; //Field java/lang/System.out:Ljava/io/PrintStream; + 25: ldc #61; //String other + 27: invokevirtual #34; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 30: aload_2 + 31: monitorexit + 32: goto 38 + 35: aload_2 + 36: monitorexit + 37: athrow + 38: aload_1 + 39: monitorexit + 40: goto 46 + 43: aload_1 + 44: monitorexit + 45: athrow + 46: return + Exception table: + from to target type + 22 32 35 any + 35 37 35 any + 4 40 43 any + 43 45 43 any + LineNumberTable: + line 49: 0 + line 50: 4 + line 51: 12 + line 52: 22 + line 51: 30 + line 49: 38 + line 55: 46 + LocalVariableTable: + Start Length Slot Name Signature + 0 47 0 this LInvestigation; + + } +*/ + +}
\ No newline at end of file diff --git a/tests/features152/synchronization/transformed/Nine.java b/tests/features152/synchronization/transformed/Nine.java new file mode 100644 index 000000000..8bd5fdf64 --- /dev/null +++ b/tests/features152/synchronization/transformed/Nine.java @@ -0,0 +1,22 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +// matching lock on transformed static method (J5) + +public aspect Nine { + public static void main(String[] args) { + C.b(); + } + + before(): !within(Nine) && lock() { + System.err.println("Locking occurring at "+thisJoinPoint); + System.err.println(thisJoinPoint.getSourceLocation().getFileName()); + } +} + +class C { + public static synchronized void b() { + System.err.println("hello"); + } +} diff --git a/tests/features152/synchronization/transformed/One.java b/tests/features152/synchronization/transformed/One.java new file mode 100644 index 000000000..49a80c9d7 --- /dev/null +++ b/tests/features152/synchronization/transformed/One.java @@ -0,0 +1,39 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public aspect One { + public static void main(String[] args) { + + } + + before(): call(* println(..)) {} + + // ... that does something ... + public synchronized void b() { + System.out.println("hello"); + } + + // ... that includes try/catch ... + public synchronized void c() { + try { + File f = new File("fred"); + FileInputStream fis = new FileInputStream(f); + } catch (IOException ioe) { + System.out.println("bang"); + } + } + + // ... with nested synchronized blocks ... + public synchronized void e() { + System.out.println("hello"); + synchronized (new String()) { + System.out.println("other"); + } + } + +} + +aspect OneX { + pointcut p(): lock(); +} diff --git a/tests/features152/synchronization/transformed/OtherTargeters.java b/tests/features152/synchronization/transformed/OtherTargeters.java new file mode 100644 index 000000000..e88a95f74 --- /dev/null +++ b/tests/features152/synchronization/transformed/OtherTargeters.java @@ -0,0 +1,25 @@ +public class OtherTargeters { + public static void main(String[] args) { + new OtherTargeters().foo(); + } + + // This method will have branch instructions that target a return which must be + // adjusted to target the monitor exit block + public synchronized void foo() { + int i = 35; + if (i==35) { + System.err.println("foo() running"); + } + } + + public void goo() { + int i = 35; + if (i==35) { + System.err.println("goo() running"); + } + } +} + +aspect X { + before(): execution(* foo(..)) {System.err.println("advice running");} +}
\ No newline at end of file diff --git a/tests/features152/synchronization/transformed/Seven.java b/tests/features152/synchronization/transformed/Seven.java new file mode 100644 index 000000000..6e786be63 --- /dev/null +++ b/tests/features152/synchronization/transformed/Seven.java @@ -0,0 +1,22 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +// matching lock in a transformed non-static method... + +public aspect Seven { + public static void main(String[] args) { + new C().b(); + } + + before(): !within(Seven) && lock() { + System.err.println("Locking occurring at "+thisJoinPoint); + System.err.println(thisJoinPoint.getSourceLocation().getFileName()); + } +} + +class C { + public synchronized void b() { + System.err.println("hello"); + } +} diff --git a/tests/features152/synchronization/transformed/Six.java b/tests/features152/synchronization/transformed/Six.java new file mode 100644 index 000000000..71c800a4b --- /dev/null +++ b/tests/features152/synchronization/transformed/Six.java @@ -0,0 +1,26 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public aspect Six { + public static void main(String[] args) { + C.bbb(); + C.c(); + } + + before(): !within(Six) && call(* println(..)) { System.err.println("test");} +} + +class C { + public static synchronized void bbb() { + System.err.println("hello"); + } + + public static void c() { + synchronized (C.class) { + System.err.println("hello"); + } + } +} + +aspect SixX { pointcut p(): unlock(); } diff --git a/tests/features152/synchronization/transformed/Ten.java b/tests/features152/synchronization/transformed/Ten.java new file mode 100644 index 000000000..9a7b54105 --- /dev/null +++ b/tests/features152/synchronization/transformed/Ten.java @@ -0,0 +1,22 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +// matching unlock on transformed static method (J5) + +public aspect Ten { + public static void main(String[] args) { + C.b(); + } + + before(): !within(Ten) && unlock() { + System.err.println("Unlocking occurring at "+thisJoinPoint); + System.err.println(thisJoinPoint.getSourceLocation().getFileName()); + } +} + +class C { + public static synchronized void b() { + System.err.println("hello"); + } +} diff --git a/tests/features152/synchronization/transformed/Thirteen.java b/tests/features152/synchronization/transformed/Thirteen.java new file mode 100644 index 000000000..82c71d0c6 --- /dev/null +++ b/tests/features152/synchronization/transformed/Thirteen.java @@ -0,0 +1,6 @@ +interface I { + + synchronized void foo(); +} +public class Thirteen { +} diff --git a/tests/features152/synchronization/transformed/Three.java b/tests/features152/synchronization/transformed/Three.java new file mode 100644 index 000000000..6a99c2e11 --- /dev/null +++ b/tests/features152/synchronization/transformed/Three.java @@ -0,0 +1,44 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public aspect Three { + public static void main(String[] args) { + new C().m3(); + try {new C().m32(); } catch (MyException me) {int i=1;} + new C().m33(); + try {new C().m34(); } catch (MyException me) {int i=1;} + } + after() returning: execution(* m3(..)) { System.err.println("execution advice running1");} + after() throwing: execution(* m32(..)) { System.err.println("execution advice running2");} + after() returning: execution(* m33(..)) { System.err.println("execution advice running3");} + after() throwing: execution(* m34(..)) { System.err.println("execution advice running4");} +} + +class C { + + public synchronized void m3() { + System.err.println("hello"); + } + + public synchronized void m32() { + System.err.println("hello"); + throw new MyException(); + } + + public void m33() { + synchronized (this) { + System.err.println("hello"); + } + } + + public void m34() { + synchronized (this) { + System.err.println("hello"); + throw new MyException(); + } + } +} + class MyException extends RuntimeException { } + +class ThreeX { pointcut p(): lock(); } diff --git a/tests/features152/synchronization/transformed/Twelve.java b/tests/features152/synchronization/transformed/Twelve.java new file mode 100644 index 000000000..f0016b5ef --- /dev/null +++ b/tests/features152/synchronization/transformed/Twelve.java @@ -0,0 +1,22 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +// matching unlock on transformed static method ( pre J5) + +public aspect Twelve { + public static void main(String[] args) { + C.b(); + } + + before(): !within(Twelve) && unlock() { + System.err.println("Unlocking occurring at "+thisJoinPoint); + System.err.println(thisJoinPoint.getSourceLocation().getFileName()); + } +} + +class C { + public static synchronized void b() { + System.err.println("hello"); + } +} diff --git a/tests/features152/synchronization/transformed/Two.java b/tests/features152/synchronization/transformed/Two.java new file mode 100644 index 000000000..129222cd3 --- /dev/null +++ b/tests/features152/synchronization/transformed/Two.java @@ -0,0 +1,19 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public aspect Two { + public static void main(String[] args) { + new C().ma(); + } + before(): execution(* ma(..)) { System.err.println("execution advice running");} +} + +class C { + + public synchronized void ma() { + System.err.println("hello"); + } +} + +aspect TwoX { pointcut p(): lock(); } diff --git a/tests/features152/synchronization/transformed/expected/C.b.txt b/tests/features152/synchronization/transformed/expected/C.b.txt new file mode 100644 index 000000000..15f85674d --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/C.b.txt @@ -0,0 +1,22 @@ + public static void b() org.aspectj.weaver.MethodDeclarationLineNumber: 17:340 +: + LDC C + DUP + ASTORE_0 + MONITORENTER + finally -> E1 + | GETSTATIC java.lang.System.err Ljava/io/PrintStream; (line 18) + | LDC "hello" + | INVOKESTATIC Five.aspectOf ()LFive; + | INVOKEVIRTUAL Five.ajc$before$Five$1$af123de3 ()V + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | ALOAD_0 + | MONITOREXIT + | RETURN (line 19) + finally -> E1 + finally -> E1 + | E1: ALOAD_0 + | MONITOREXIT + finally -> E1 + ATHROW + end public static void b() diff --git a/tests/features152/synchronization/transformed/expected/C.bbb.txt b/tests/features152/synchronization/transformed/expected/C.bbb.txt new file mode 100644 index 000000000..b9f54d8eb --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/C.bbb.txt @@ -0,0 +1,38 @@ + public static void bbb() org.aspectj.weaver.MethodDeclarationLineNumber: 15:316 +: + GETSTATIC C.class$1 Ljava/lang/Class; + DUP + IFNONNULL L0 + POP + catch java.lang.ClassNotFoundException -> E0 + | LDC "C" + | INVOKESTATIC java.lang.Class.forName (Ljava/lang/String;)Ljava/lang/Class; + catch java.lang.ClassNotFoundException -> E0 + DUP + PUTSTATIC C.class$1 Ljava/lang/Class; + GOTO L0 + E0: NEW java.lang.NoClassDefFoundError + DUP_X1 + SWAP + INVOKEVIRTUAL java.lang.Throwable.getMessage ()Ljava/lang/String; + INVOKESPECIAL java.lang.NoClassDefFoundError.<init> (Ljava/lang/String;)V + ATHROW + L0: DUP + ASTORE_0 + MONITORENTER + finally -> E2 + | GETSTATIC java.lang.System.err Ljava/io/PrintStream; (line 16) + | LDC "hello" + | INVOKESTATIC Six.aspectOf ()LSix; + | INVOKEVIRTUAL Six.ajc$before$Six$1$cb48297b ()V + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | ALOAD_0 + | MONITOREXIT + | RETURN (line 17) + finally -> E2 + finally -> E2 + | E2: ALOAD_0 + | MONITOREXIT + finally -> E2 + ATHROW + end public static void bbb() diff --git a/tests/features152/synchronization/transformed/expected/C.m.txt b/tests/features152/synchronization/transformed/expected/C.m.txt new file mode 100644 index 000000000..7f5a34cdc --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/C.m.txt @@ -0,0 +1,23 @@ + public void m() org.aspectj.weaver.MethodDeclarationLineNumber: 16:496 +: + ALOAD_0 + DUP + ASTORE_1 + MONITORENTER + finally -> E1 + | GETSTATIC java.lang.System.err Ljava/io/PrintStream; (line 17) + | LDC "hello" + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | ALOAD_1 + | MONITOREXIT + | GOTO L0 (line 18) + finally -> E1 + finally -> E1 + | E1: ALOAD_1 + | MONITOREXIT + finally -> E1 + ATHROW + L0: INVOKESTATIC Four.aspectOf ()LFour; + INVOKEVIRTUAL Four.ajc$afterReturning$Four$1$c2776aed ()V + RETURN + end public void m() diff --git a/tests/features152/synchronization/transformed/expected/C.m2.txt b/tests/features152/synchronization/transformed/expected/C.m2.txt new file mode 100644 index 000000000..ab4a19919 --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/C.m2.txt @@ -0,0 +1,28 @@ + public void m2() org.aspectj.weaver.MethodDeclarationLineNumber: 20:571 +: + catch java.lang.Throwable -> E2 + | ALOAD_0 + | DUP + | ASTORE_1 + | MONITORENTER + | finally -> E1 + | | GETSTATIC java.lang.System.err Ljava/io/PrintStream; (line 21) + | | LDC "hello" + | | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | | NEW MyException (line 22) + | | DUP + | | INVOKESPECIAL MyException.<init> ()V + | | ATHROW + | finally -> E1 + | finally -> E1 + | | E1: ALOAD_1 + | | MONITOREXIT + | finally -> E1 + | ATHROW + catch java.lang.Throwable -> E2 + E2: ASTORE_2 + INVOKESTATIC Four.aspectOf ()LFour; + INVOKEVIRTUAL Four.ajc$afterThrowing$Four$2$9d31eed1 ()V + ALOAD_2 + ATHROW + end public void m2() diff --git a/tests/features152/synchronization/transformed/expected/C.m3.txt b/tests/features152/synchronization/transformed/expected/C.m3.txt new file mode 100644 index 000000000..f1157285e --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/C.m3.txt @@ -0,0 +1,23 @@ + public void m3() org.aspectj.weaver.MethodDeclarationLineNumber: 20:747 +: + ALOAD_0 + DUP + ASTORE_1 + MONITORENTER + finally -> E1 + | GETSTATIC java.lang.System.err Ljava/io/PrintStream; (line 21) + | LDC "hello" + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | ALOAD_1 + | MONITOREXIT + | GOTO L0 (line 22) + finally -> E1 + finally -> E1 + | E1: ALOAD_1 + | MONITOREXIT + finally -> E1 + ATHROW + L0: INVOKESTATIC Three.aspectOf ()LThree; + INVOKEVIRTUAL Three.ajc$afterReturning$Three$1$3f09355c ()V + RETURN + end public void m3() diff --git a/tests/features152/synchronization/transformed/expected/C.m32.txt b/tests/features152/synchronization/transformed/expected/C.m32.txt new file mode 100644 index 000000000..0e2819293 --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/C.m32.txt @@ -0,0 +1,28 @@ + public void m32() org.aspectj.weaver.MethodDeclarationLineNumber: 24:823 +: + catch java.lang.Throwable -> E2 + | ALOAD_0 + | DUP + | ASTORE_1 + | MONITORENTER + | finally -> E1 + | | GETSTATIC java.lang.System.err Ljava/io/PrintStream; (line 25) + | | LDC "hello" + | | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | | NEW MyException (line 26) + | | DUP + | | INVOKESPECIAL MyException.<init> ()V + | | ATHROW + | finally -> E1 + | finally -> E1 + | | E1: ALOAD_1 + | | MONITOREXIT + | finally -> E1 + | ATHROW + catch java.lang.Throwable -> E2 + E2: ASTORE_2 + INVOKESTATIC Three.aspectOf ()LThree; + INVOKEVIRTUAL Three.ajc$afterThrowing$Three$2$b2d97242 ()V + ALOAD_2 + ATHROW + end public void m32() diff --git a/tests/features152/synchronization/transformed/expected/C.m33.txt b/tests/features152/synchronization/transformed/expected/C.m33.txt new file mode 100644 index 000000000..86b78ffb3 --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/C.m33.txt @@ -0,0 +1,24 @@ + public void m33() org.aspectj.weaver.MethodDeclarationLineNumber: 29:917 +: + ALOAD_0 // LC; this (line 30) + DUP + ASTORE_1 + MONITORENTER + finally -> E1 + | GETSTATIC java.lang.System.err Ljava/io/PrintStream; (line 31) + | LDC "hello" + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | ALOAD_1 (line 30) + | MONITOREXIT + finally -> E1 + GOTO L0 + finally -> E1 + | E1: ALOAD_1 + | MONITOREXIT + finally -> E1 + ATHROW + L0: GOTO L1 (line 33) + L1: INVOKESTATIC Three.aspectOf ()LThree; + INVOKEVIRTUAL Three.ajc$afterReturning$Three$3$b48e4ae1 ()V + RETURN + end public void m33() diff --git a/tests/features152/synchronization/transformed/expected/C.m34.txt b/tests/features152/synchronization/transformed/expected/C.m34.txt new file mode 100644 index 000000000..c787ba249 --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/C.m34.txt @@ -0,0 +1,26 @@ + public void m34() org.aspectj.weaver.MethodDeclarationLineNumber: 35:1018 +: + catch java.lang.Throwable -> E1 + | ALOAD_0 // LC; this (line 36) + | DUP + | ASTORE_1 + | MONITORENTER + | finally -> E0 + | | GETSTATIC java.lang.System.err Ljava/io/PrintStream; (line 37) + | | LDC "hello" + | | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | | NEW MyException (line 38) + | | DUP + | | INVOKESPECIAL MyException.<init> ()V + | | ATHROW + | | E0: ALOAD_1 (line 36) + | | MONITOREXIT + | finally -> E0 + | ATHROW + catch java.lang.Throwable -> E1 + E1: ASTORE_2 + INVOKESTATIC Three.aspectOf ()LThree; + INVOKEVIRTUAL Three.ajc$afterThrowing$Three$4$b6432380 ()V + ALOAD_2 + ATHROW + end public void m34() diff --git a/tests/features152/synchronization/transformed/expected/C.m4.txt b/tests/features152/synchronization/transformed/expected/C.m4.txt new file mode 100644 index 000000000..9e50085ea --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/C.m4.txt @@ -0,0 +1,26 @@ + public void m4() org.aspectj.weaver.MethodDeclarationLineNumber: 35:1007 +: + catch java.lang.Throwable -> E1 + | ALOAD_0 // LC; this (line 36) + | DUP + | ASTORE_1 + | MONITORENTER + | finally -> E0 + | | GETSTATIC java.lang.System.err Ljava/io/PrintStream; (line 37) + | | LDC "hello" + | | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | | NEW MyException (line 38) + | | DUP + | | INVOKESPECIAL MyException.<init> ()V + | | ATHROW + | | E0: ALOAD_1 (line 36) + | | MONITOREXIT + | finally -> E0 + | ATHROW + catch java.lang.Throwable -> E1 + E1: ASTORE_2 + INVOKESTATIC Three.aspectOf ()LThree; + INVOKEVIRTUAL Three.ajc$afterThrowing$Three$4$40be0dfb ()V + ALOAD_2 + ATHROW + end public void m4() diff --git a/tests/features152/synchronization/transformed/expected/C.ma.txt b/tests/features152/synchronization/transformed/expected/C.ma.txt new file mode 100644 index 000000000..0a6b97849 --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/C.ma.txt @@ -0,0 +1,22 @@ + public void ma() org.aspectj.weaver.MethodDeclarationLineNumber: 14:307 +: + INVOKESTATIC Two.aspectOf ()LTwo; + INVOKEVIRTUAL Two.ajc$before$Two$1$8d8821ee ()V + ALOAD_0 + DUP + ASTORE_1 + MONITORENTER + finally -> E1 + | GETSTATIC java.lang.System.err Ljava/io/PrintStream; (line 15) + | LDC "hello" + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | ALOAD_1 + | MONITOREXIT + | RETURN (line 16) + finally -> E1 + finally -> E1 + | E1: ALOAD_1 + | MONITOREXIT + finally -> E1 + ATHROW + end public void ma() diff --git a/tests/features152/synchronization/transformed/expected/Investigation.b.txt b/tests/features152/synchronization/transformed/expected/Investigation.b.txt new file mode 100644 index 000000000..15f83a1d6 --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/Investigation.b.txt @@ -0,0 +1,21 @@ + public void b() org.aspectj.weaver.MethodDeclarationLineNumber: 19:312 +: + ALOAD_0 // LInvestigation; this (line 20) + DUP + ASTORE_1 + MONITORENTER + finally -> E1 + | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 21) + | LDC "hello" + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | ALOAD_1 (line 20) + | MONITOREXIT + finally -> E1 + GOTO L0 + finally -> E1 + | E1: ALOAD_1 + | MONITOREXIT + finally -> E1 + ATHROW + L0: RETURN (line 23) + end public void b() diff --git a/tests/features152/synchronization/transformed/expected/Investigation.c.txt b/tests/features152/synchronization/transformed/expected/Investigation.c.txt new file mode 100644 index 000000000..7fa235d5d --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/Investigation.c.txt @@ -0,0 +1,35 @@ + public void c() org.aspectj.weaver.MethodDeclarationLineNumber: 26:439 +: + ALOAD_0 // LInvestigation; this (line 27) + DUP + ASTORE_1 + MONITORENTER + finally -> E2 + | catch java.io.IOException -> E0 + | | NEW java.io.File (line 29) + | | DUP + | | LDC "fred" + | | INVOKESPECIAL java.io.File.<init> (Ljava/lang/String;)V + | | ASTORE_2 + | | NEW java.io.FileInputStream (line 30) + | | DUP + | | ALOAD_2 // Ljava/io/File; f + | | INVOKESPECIAL java.io.FileInputStream.<init> (Ljava/io/File;)V + | | POP + | | GOTO L0 + | catch java.io.IOException -> E0 + | E0: POP (line 31) + | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 32) + | LDC "bang" + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | L0: ALOAD_1 (line 27) + | MONITOREXIT + finally -> E2 + GOTO L1 + finally -> E2 + | E2: ALOAD_1 + | MONITOREXIT + finally -> E2 + ATHROW + L1: RETURN (line 35) + end public void c() diff --git a/tests/features152/synchronization/transformed/expected/Investigation.d.txt b/tests/features152/synchronization/transformed/expected/Investigation.d.txt new file mode 100644 index 000000000..a2a73c36a --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/Investigation.d.txt @@ -0,0 +1,38 @@ + public void d() org.aspectj.weaver.MethodDeclarationLineNumber: 38:706 +: + ALOAD_0 // LInvestigation; this (line 39) + DUP + ASTORE_1 + MONITORENTER + finally -> E1 + | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 40) + | LDC "hello" + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | ALOAD_1 (line 39) + | MONITOREXIT + finally -> E1 + GOTO L0 + finally -> E1 + | E1: ALOAD_1 + | MONITOREXIT + finally -> E1 + ATHROW + L0: ALOAD_0 // LInvestigation; this (line 42) + DUP + ASTORE_1 + MONITORENTER + finally -> E3 + | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 43) + | LDC "world" + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | ALOAD_1 (line 42) + | MONITOREXIT + finally -> E3 + GOTO L1 + finally -> E3 + | E3: ALOAD_1 + | MONITOREXIT + finally -> E3 + ATHROW + L1: RETURN (line 45) + end public void d() diff --git a/tests/features152/synchronization/transformed/expected/Investigation.e.txt b/tests/features152/synchronization/transformed/expected/Investigation.e.txt new file mode 100644 index 000000000..6508daf3a --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/Investigation.e.txt @@ -0,0 +1,40 @@ + public void e() org.aspectj.weaver.MethodDeclarationLineNumber: 48:904 +: + ALOAD_0 // LInvestigation; this (line 49) + DUP + ASTORE_1 + MONITORENTER + finally -> E3 + | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 50) + | LDC "hello" + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | NEW java.lang.String (line 51) + | DUP + | INVOKESPECIAL java.lang.String.<init> ()V + | DUP + | ASTORE_2 + | MONITORENTER + | finally -> E1 + | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 52) + | | LDC "other" + | | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | | ALOAD_2 (line 51) + | | MONITOREXIT + | finally -> E1 + | GOTO L0 + | finally -> E1 + | | E1: ALOAD_2 + | | MONITOREXIT + | finally -> E1 + | ATHROW + | L0: ALOAD_1 (line 49) + | MONITOREXIT + finally -> E3 + GOTO L1 + finally -> E3 + | E3: ALOAD_1 + | MONITOREXIT + finally -> E3 + ATHROW + L1: RETURN (line 55) + end public void e() diff --git a/tests/features152/synchronization/transformed/expected/One.b.txt b/tests/features152/synchronization/transformed/expected/One.b.txt new file mode 100644 index 000000000..948cb66cd --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/One.b.txt @@ -0,0 +1,22 @@ + public void b() org.aspectj.weaver.MethodDeclarationLineNumber: 13:259 +: + ALOAD_0 + DUP + ASTORE_1 + MONITORENTER + finally -> E1 + | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 14) + | LDC "hello" + | INVOKESTATIC One.aspectOf ()LOne; + | INVOKEVIRTUAL One.ajc$before$One$1$d2a8f7b9 ()V + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | ALOAD_1 + | MONITOREXIT + | RETURN (line 15) + finally -> E1 + finally -> E1 + | E1: ALOAD_1 + | MONITOREXIT + finally -> E1 + ATHROW + end public void b() diff --git a/tests/features152/synchronization/transformed/expected/One.c.txt b/tests/features152/synchronization/transformed/expected/One.c.txt new file mode 100644 index 000000000..3641c9b36 --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/One.c.txt @@ -0,0 +1,36 @@ + public void c() org.aspectj.weaver.MethodDeclarationLineNumber: 18:368 +: + ALOAD_0 + DUP + ASTORE_2 + MONITORENTER + finally -> E2 + | catch java.io.IOException -> E0 + | | NEW java.io.File (line 20) + | | DUP + | | LDC "fred" + | | INVOKESPECIAL java.io.File.<init> (Ljava/lang/String;)V + | | ASTORE_1 + | | NEW java.io.FileInputStream (line 21) + | | DUP + | | ALOAD_1 // Ljava/io/File; f + | | INVOKESPECIAL java.io.FileInputStream.<init> (Ljava/io/File;)V + | | POP + | | GOTO L0 + | catch java.io.IOException -> E0 + | E0: POP (line 22) + | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 23) + | LDC "bang" + | INVOKESTATIC One.aspectOf ()LOne; + | INVOKEVIRTUAL One.ajc$before$One$1$d2a8f7b9 ()V + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | L0: ALOAD_2 + | MONITOREXIT + | RETURN (line 25) + finally -> E2 + finally -> E2 + | E2: ALOAD_2 + | MONITOREXIT + finally -> E2 + ATHROW + end public void c() diff --git a/tests/features152/synchronization/transformed/expected/One.e.txt b/tests/features152/synchronization/transformed/expected/One.e.txt new file mode 100644 index 000000000..85d93f0ed --- /dev/null +++ b/tests/features152/synchronization/transformed/expected/One.e.txt @@ -0,0 +1,43 @@ + public void e() org.aspectj.weaver.MethodDeclarationLineNumber: 28:611 +: + ALOAD_0 + DUP + ASTORE_2 + MONITORENTER + finally -> E3 + | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 29) + | LDC "hello" + | INVOKESTATIC One.aspectOf ()LOne; + | INVOKEVIRTUAL One.ajc$before$One$1$d2a8f7b9 ()V + | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | NEW java.lang.String (line 30) + | DUP + | INVOKESPECIAL java.lang.String.<init> ()V + | DUP + | ASTORE_1 + | MONITORENTER + | finally -> E1 + | | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line 31) + | | LDC "other" + | | INVOKESTATIC One.aspectOf ()LOne; + | | INVOKEVIRTUAL One.ajc$before$One$1$d2a8f7b9 ()V + | | INVOKEVIRTUAL java.io.PrintStream.println (Ljava/lang/String;)V + | | ALOAD_1 (line 30) + | | MONITOREXIT + | finally -> E1 + | GOTO L0 + | finally -> E1 + | | E1: ALOAD_1 + | | MONITOREXIT + | finally -> E1 + | ATHROW + | L0: ALOAD_2 + | MONITOREXIT + | RETURN (line 33) + finally -> E3 + finally -> E3 + | E3: ALOAD_2 + | MONITOREXIT + finally -> E3 + ATHROW + end public void e() diff --git a/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTests.java b/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTests.java new file mode 100644 index 000000000..094a211f3 --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTests.java @@ -0,0 +1,240 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * 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/epl-v10.html + * + * Contributors: + * Andy Clement - initial implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc152; + +import java.io.File; +import java.util.List; + +import junit.framework.Test; + +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IProgramElement; +import org.aspectj.asm.IRelationship; +import org.aspectj.testing.XMLBasedAjcTestCase; + +/** + * Work items, phase #1: lock()/unlock() + * x expose new joinpoints + * x parse new pcds + * x fix tjp string + * x preventing double unlock() messages/markers in structure model + * x error messages appropriate for attempting to use around advice on synchronization join points + * x making the use of lock/unlock conditional on an -Xjoinpoints:synchronization + * x activating the -Xjoinpoints options from LTW configurations rather than through batch/AJDT + * x ensure the lock/unlock joinpoints only appear when -Xjoinpoints:synchronization specified + * TAG: Completion of PHASE1 + * + * + * Work items, phase #2: transformation + * + * Design: transform all synchronized methods: + * public synchronized void m() { + * ... + * } + * => + * public void m() { + * synchronized (this) { + * ... + * } + * } + * + * x transforming synchronized methods + * x matching execution(synchronized * *(..)) for transformed code + * x warning message for execution() hitting a synchronized method + * x ensure verifier runs over generated code (done by just executing the code as part of the test spec) + * TAG: Completion of PHASE2 + * + * + * Need sorting before claiming complete: + * - coping with asking 'regular' AspectJ to process an Aspect built by this variant of AJ that provides lock()/unlock() + * - targetting 1.2 runtime + * + * TAG: Finished + * + * 'Other' work items: + * - optimize matching for transformed methods since we *know* the type we are locking on + * - supporting type pattern in lock() unlock() - this is not entirely trivial as kinded pointcuts do not usually have any residue + * - weaving messages include 'unusual' strings for the join points, not the + * same as revealed by thisJoinPoint.getSignature() in code - handler is probably similar + * - documentation + * - Ant task support for -Xjoinpoints + * - lazy translation of synchronized methods, rather than eager + * - applying execution(* *(..)) correctly to transformed methods (i.e. inside lock/unlock) + * - use knowledge of type containing synchronized methods to optimize matching of (un)lock() - not always needing residue + * - line number table is incorrect for transformed code (lock joinpoint has no line number) + * + * Notes: + * IllegalMonitorStateException + * Thrown to indicate that a thread has attempted to wait on an object's monitor or to + * notify other threads waiting on an object's monitor without owning the specified monitor. + * + * around advice won't work on SUN VMs (may be a bug that it does work on other VMs) since the monitor + * instructions are extracted to a separate method for proceed() calls and yet the VM seems to want + * them paired inside a single method. + * + * Really we only need to restrict the use of around advice on synchronization join points + * if the advice uses proceed() - but policing that is a little tough because (DOH) the + * AdviceAttribute field 'proceedCallSignatures' is never filled in (which records how many + * proceeds occur in the advice) - see where it isnt filled in at + * AdviceDeclaration.resolveStatements() in the loop that goes over the proceedCalls list. + * + * + * Problems: + * - Can't run it on a 1.2.1 runtime - just not practical + * - It ain't going to work with the aspectjrt.jar 1.5.0 that websphere will be shipping. + * *IF* someone manages to get into a situation where they ask for the signature of a lock jp, but the lock + * jp won't have been exposed if they weren't weaving with a 1.5 weaver... + * + * + * Method transformation, example: + + public synchronized void m(); + Code: + Stack=2, Locals=1, Args_size=1 + 0: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 3: ldc #3; //String hello + 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 8: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 11: ldc #5; //String world + 13: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 16: return + LineNumberTable: + line 4: 0 + line 5: 8 + line 6: 16 + + public void m2(); + Code: + Stack=2, Locals=3, Args_size=1 + 0: aload_0 + 1: dup + 2: astore_1 + 3: monitorenter + 4: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 7: ldc #3; //String hello + 9: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 12: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 15: ldc #5; //String world + 17: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 20: aload_1 + 21: monitorexit + 22: goto 30 + 25: astore_2 + 26: aload_1 + 27: monitorexit + 28: aload_2 + 29: athrow + 30: return + Exception table: + from to target type + 4 22 25 any + 25 28 25 any + * + * Factors affecting transformation: + * - LDC in Java5 supports referring to a class literal, e.g. Foo.class whereas before Java5, it did not. + * This means if generating the synchronized() block for a static method from a preJava5 class then + * we have to generate a lot of crap to build the class object for locking and unlocking. The object + * is also stored in a local field of the type (if we follow the pattern of JDT/JAVAC) + */ + +public class SynchronizationTests extends XMLBasedAjcTestCase { + + // testing the new join points for monitorenter/monitorexit + public void testTheBasics_1() { runTest("basic"); } + public void testTheBasics_2() { runTest("basic - within"); } + public void testTheBasics_3() { runTest("basic - within plus args"); } + public void testTheBasics_4() { runTest("basic - within plus this"); } // this null in static context + public void testTheBasics_5() { runTest("basic - within plus target"); } // target null in static context? + + + // testing parsing of the new PCDs lock/unlock + public void testParsing_1() { runTest("parsing - lock"); } + public void testParsing_2() { runTest("parsing - unlock"); } + public void testParsing_errors_1() { runTest("parsing - error - lock"); } + public void testParsing_errors_2() { runTest("parsing - error - unlock"); } + + // testing parsing and matching with the new PCDs + public void testParsingAndMatching_1() { runTest("parsing and matching - lock and static context"); } + public void testParsingAndMatching_2() { runTest("parsing and matching - unlock and static context"); } + public void testParsingAndMatching_3() { runTest("parsing and matching - lock and non-static context"); } + public void testParsingAndMatching_4() { runTest("parsing and matching - unlock and non-static context"); } + public void testParsingAndMatching_5() { runTest("parsing and matching - lock and non-static context"); } + public void testParsingAndMatching_6() { runTest("parsing and matching - unlock and non-static context"); } + + // using the new PCDs in a LTW environment + public void testUsingWithLTW_MissingFlag_1() { runTest("using lock with LTW - missing flag");} + public void testUsingWithLTW_MissingFlag_2() { runTest("using unlock with LTW - missing flag");} + public void testUsingWithLTW_1() { runTest("using lock with LTW");} + public void testUsingWithLTW_2() { runTest("using unlock with LTW");} + + // multiple PCDs + public void testCombiningPCDs_1() { runTest("combining pcds - lock and this");} + public void testCombiningPCDs_2() { runTest("combining pcds - unlock and this");} + + // useful examples + public void testUseful_1() { runTest("a useful program"); } // just uses within/args - matching the (un)lock jps + public void testUseful_2() { runTest("a useful program - with lock"); } // uses lock/args + + // all the methods of thisJoinPoint + public void testThisJoinPoint_1() { runTest("thisjoinpoint - monitor entry");} + public void testThisJoinPoint_2() { runTest("thisjoinpoint - monitor exit"); } + + public void testDoubleMessagesOnUnlock() { + //AsmManager.setReporting("c:/foo.txt",true,true,true,true); + runTest("prevent double unlock weaving messages and model contents"); + //checkModel1(); + } + + // targetting 1.2 runtime - signature creation code in LazyClassGen.initializeTjp may not work + + // different advice kinds + public void testBeforeAdvice_1() { runTest("before advice - lock");} + public void testBeforeAdvice_2() { runTest("before advice - unlock");} + public void testAfterAdvice_1() { runTest("after advice - lock"); } + public void testAfterAdvice_2() { runTest("after advice - unlock"); } + public void testAroundAdvice_1() { runTest("around advice - lock");} + public void testAroundAdvice_2() { runTest("around advice - unlock");} + + + public void testLockingTJP() { runTest("obtaining locked object through getArgs");} + + // binary weaving? + + // nested locking/unlocking + + // --- helpers + + // Half finished - could check there is only one relationship for unlock() rather than two - but + // that seems to be the case anyway (peculiar...) + private void checkModel1() { + // Verifies only one unlock relationship, not two + IProgramElement unlockNode = AsmManager.getDefault().getHierarchy().findElementForLabel(AsmManager.getDefault().getHierarchy().getRoot(), + IProgramElement.Kind.CODE,"unlock(void java.lang.Object.<unlock>(java.lang.Object))"); + assertTrue("Couldn't find the unlock node",unlockNode!=null); + List l = AsmManager.getDefault().getRelationshipMap().get(unlockNode); + assertTrue("should be one entry :"+l,l!=null && l.size()==1); + IRelationship ir = (IRelationship)l.get(0); + System.err.println(ir); + List targs = ir.getTargets(); + System.err.println(targs.size()); + System.err.println(targs.get(0)); + } + + // --- + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(SynchronizationTests.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc152/synchronization.xml"); + } + +} diff --git a/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java b/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java new file mode 100644 index 000000000..681f9b3ed --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java @@ -0,0 +1,328 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * 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/epl-v10.html + * + * Contributors: + * Andy Clement - initial implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc152; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import junit.framework.Test; + +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IProgramElement; +import org.aspectj.asm.IRelationship; +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.testing.util.TestUtil; +import org.aspectj.testing.util.TestUtil.LineStream; +import org.aspectj.weaver.ReferenceType; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.World; +import org.aspectj.weaver.bcel.BcelObjectType; +import org.aspectj.weaver.bcel.BcelWorld; +import org.aspectj.weaver.bcel.LazyClassGen; +import org.aspectj.weaver.bcel.LazyMethodGen; + + +/** + * Method transformation, example: + + public synchronized void m(); + Code: + Stack=2, Locals=1, Args_size=1 + 0: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 3: ldc #3; //String hello + 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 8: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 11: ldc #5; //String world + 13: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 16: return + LineNumberTable: + line 4: 0 + line 5: 8 + line 6: 16 + + public void m2(); + Code: + Stack=2, Locals=3, Args_size=1 + 0: aload_0 + 1: dup + 2: astore_1 + 3: monitorenter + 4: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 7: ldc #3; //String hello + 9: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 12: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 15: ldc #5; //String world + 17: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 20: aload_1 + 21: monitorexit + 22: goto 30 + 25: astore_2 + 26: aload_1 + 27: monitorexit + 28: aload_2 + 29: athrow + 30: return + Exception table: + from to target type + 4 22 25 any + 25 28 25 any + */ + +public class SynchronizationTransformTests extends XMLBasedAjcTestCase { + + private static boolean regenerate; + + static { regenerate = false; } + + private World world; + + public void testInvestigatingTransforming() { + runTest("investigation"); + checkMethod("Investigation","b"); // similar output to One.b + checkMethod("Investigation","c"); + checkMethod("Investigation","d"); + checkMethod("Investigation","e"); + } + + public void testTransform1() { + runTest("One"); + checkMethod("One","b"); + checkMethod("One","c"); + checkMethod("One","e"); + } + + // before() on execution jp + public void testTransform2() { + runTest("Two"); + checkMethod("C","ma"); + } + + // after() returning/after() throwing on execution jp + // after() returning -> make all returns go through the same exit point and make + // it call the advice + // after() throwing -> add a catch block that calls the advice + public void testTransform3() { + runTest("Three"); + checkMethod("C","m3"); + checkMethod("C","m32"); + checkMethod("C","m33"); // like m() but synchronized block + checkMethod("C","m34"); // like m2() but synchronized block + } + + // like testTransform3() but pointcuts explicitly specify synchronized + public void testTransform4() { + runTest("Four"); + checkMethod("C","m"); + checkMethod("C","m2"); + } + + + + // Java5 variant + public void testStaticSynchronizedMethodTransformJava5() { + runTest("Five - Java5"); + checkMethod("C","b"); + } + + // < Java5 variant + public void testStaticSynchronizedMethodTransformPreJava5() { + runTest("Six - preJava5"); + checkMethod("C","bbb"); + } + + public void testLockPcdOnTransformedNonStaticMethod() { + runTest("lock pcd on transformed non-static method"); + } + + public void testUnlockPcdOnTransformedNonStaticMethod() { + runTest("unlock pcd on transformed non-static method"); + } + + public void testLockPcdOnTransformedStaticMethod() { + runTest("lock pcd on transformed static method - J5"); + } + + public void testUnlockPcdOnTransformedStaticMethod() { + runTest("unlock pcd on transformed static method - J5"); + } + + public void testLockPcdOnTransformedStaticMethodPreJ5() { + runTest("lock pcd on transformed static method - preJ5"); + } + + public void testUnlockPcdOnTransformedStaticMethodPreJ5() { + runTest("unlock pcd on transformed static method - preJ5"); + } + + // more complex code sequences... + public void testOtherTargeters() { + runTest("other targeters"); + } + + // --- infrastructure below + + private void checkMethod(String typename,String methodname) { + LazyMethodGen m = getMethod(typename,methodname); + File expectedF = new File(".."+File.separator+"tests"+File.separator+"features152"+File.separator+"synchronization"+File.separator+ + "transformed"+File.separator+"expected"+File.separator+ + typename+"."+methodname+".txt"); + if (regenerate) { + saveMethod(expectedF, m); + } else { + compareMethod(expectedF, m); + } + } + + + + private LazyMethodGen getMethod(String typename,String methodname) { + BcelObjectType type = getBcelObjectFor(typename); + LazyClassGen lcg = type.getLazyClassGen(); + List /*LazyMethodGen*/ methods = lcg.getMethodGens(); + for (Iterator iter = methods.iterator(); iter.hasNext();) { + LazyMethodGen element = (LazyMethodGen) iter.next(); + if (element.getName().equals(methodname)) { + return element; + } + } + return null; + } + + private BcelObjectType getBcelObjectFor(String clazzname) { + ensureWorldSetup(); + ResolvedType rt = world.resolve(clazzname); + if (rt==null) fail("Couldn't find class "+clazzname); + ReferenceType rtt = (ReferenceType)rt; + BcelObjectType bot = (BcelObjectType)rtt.getDelegate(); + return bot; + } + + private void ensureWorldSetup() { + if (world == null) { + world = new BcelWorld( + getSandboxDirectory()+File.pathSeparator+ + System.getProperty("java.class.path")); + world.setFastDelegateSupport(false); + } + } + + protected Method getMethod(JavaClass cl,String methodname) { + Method[] methods = cl.getMethods(); + for (int i = 0; i < methods.length; i++) { + Method m = methods[i]; + if (m.getName().equals(methodname)) { + return m; + } + } + return null; + } + + public void dump(String title,String[] strs) { + System.err.println(title); + for (int i = 0; i < strs.length; i++) { + System.err.println(i+") "+strs[i]); + } + } + + private void compareMethod(File f,LazyMethodGen m) { + BufferedReader fr; + if (!f.exists()) { + fail("Can't find expected output file "+f); + } + try { + // Load the file in + fr = new BufferedReader(new FileReader(f)); + String line = null; + List originalFileContents = new ArrayList(); + while ((line=fr.readLine())!=null) originalFileContents.add(line); + String[] fileContents = (String[])originalFileContents.toArray(new String[]{}); + + LineStream ls = new TestUtil.LineStream(); + m.print(ls,null); + String[] lines = ls.getLines(); + for (int i = 0; i < lines.length; i++) { + String existingLine = lines[i]; + if (!fileContents[i].equals(existingLine)) { + dump("File contents:",fileContents); + dump("Actual:",lines); + fail("\nDifference in method "+m.getName()+" on line "+i+" between the expected:\n"+fileContents[i]+ + "\nand the found:\n"+existingLine); + } + } + } catch (Exception e) { + fail("Unexpected exception saving weaving messages:"+e); + } + } + + private String stringify(List l) { + StringBuffer result = new StringBuffer(); + for (Iterator iter = l.iterator(); iter.hasNext();) { + String str = (String) iter.next(); + result.append(str);result.append("\n"); + } + return result.toString(); + } + + + private void saveMethod(File f,LazyMethodGen m) { + System.out.println("Saving method into "+f.getName()); + try { + m.print(new PrintStream(f),null); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail("Couldn't store the method in file "+f); + } + } + + + + + + + + // --- helpers + + // Half finished - could check there is only one relationship for unlock() rather than two - but + // that seems to be the case anyway (peculiar...) + private void checkModel1() { + // Verifies only one unlock relationship, not two + IProgramElement unlockNode = AsmManager.getDefault().getHierarchy().findElementForLabel(AsmManager.getDefault().getHierarchy().getRoot(), + IProgramElement.Kind.CODE,"unlock(void java.lang.Object.<unlock>(java.lang.Object))"); + assertTrue("Couldn't find the unlock node",unlockNode!=null); + List l = AsmManager.getDefault().getRelationshipMap().get(unlockNode); + assertTrue("should be one entry :"+l,l!=null && l.size()==1); + IRelationship ir = (IRelationship)l.get(0); + System.err.println(ir); + List targs = ir.getTargets(); + System.err.println(targs.size()); + System.err.println(targs.get(0)); + } + + // --- + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(SynchronizationTransformTests.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc152/synchronization.xml"); + } + + public void tearDown() { world = null; } + +} diff --git a/tests/src/org/aspectj/systemtest/ajc152/synchronization.xml b/tests/src/org/aspectj/systemtest/ajc152/synchronization.xml new file mode 100644 index 000000000..0f9dbbfb6 --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc152/synchronization.xml @@ -0,0 +1,585 @@ +<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]> + +<!-- AspectJ v1.5.1 Tests --> +<suite> + + <ajc-test dir="features152/synchronization" title="basic"> + <compile files="Basic.java" options="-1.5 -showWeaveInfo -Xjoinpoints:synchronization"> + </compile> + <run class="Basic"> + <stderr> + <line text="methodWithSyncBlock1"/> + <line text="staticMethodWithSyncBlock1"/> + <line text="methodWithSyncBlock2"/> + <line text="staticMethodWithSyncBlock2"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="basic - within"> + <compile files="Basic2.java" options="-1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Basic2"> + <stderr> + <line text="methodWithSyncBlock1"/> + <line text="Advice running at lock(Object)"/> + <line text="Advice running at unlock(Object)"/> + <line text="staticMethodWithSyncBlock1"/> + <line text="Advice running at lock(Object)"/> + <line text="Advice running at unlock(Object)"/> + <line text="methodWithSyncBlock2"/> + <line text="Advice running at lock(Object)"/> + <line text="Advice running at unlock(Object)"/> + <line text="staticMethodWithSyncBlock2"/> + <line text="Advice running at lock(Object)"/> + <line text="Advice running at unlock(Object)"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="basic - within plus args"> + <compile files="Basic3.java" options="-1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Basic3"> + <stderr> + <line text="methodWithSyncBlock1"/> + <line text="Advice running at lock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="Advice running at unlock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="staticMethodWithSyncBlock1"/> + <line text="Advice running at lock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="Advice running at unlock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="methodWithSyncBlock2"/> + <line text="Advice running at lock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="Advice running at unlock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="staticMethodWithSyncBlock2"/> + <line text="Advice running at lock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="Advice running at unlock(Object) with this of type class Basic3 with value Basic3@"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="basic - within plus this"> + <compile files="Basic4.java" options="-1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Basic4"> + <stderr> + <line text="methodWithSyncBlock1"/> + <line text="Advice running at lock(Object) with args of type class Basic4 with value Basic4@"/> + <line text="Advice running at unlock(Object) with args of type class Basic4 with value Basic4@"/> + <line text="staticMethodWithSyncBlock1"/> + <line text="Advice running at lock(Object) with args of type class java.lang.Class with value class Basic4"/> + <line text="Advice running at unlock(Object) with args of type class java.lang.Class with value class Basic4"/> + <line text="methodWithSyncBlock2"/> + <line text="Advice running at lock(Object) with args of type class Basic4 with value Basic4@"/> + <line text="Advice running at unlock(Object) with args of type class Basic4 with value Basic4@"/> + <line text="staticMethodWithSyncBlock2"/> + <line text="Advice running at lock(Object) with args of type class java.lang.Class with value class Basic4"/> + <line text="Advice running at unlock(Object) with args of type class java.lang.Class with value class Basic4"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="basic - within plus target"> + <compile files="Basic5.java" options="-1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Basic5"> + <stderr> + <line text="Advice running at void Basic5.methodWithSyncBlock1() with target of type class Basic5 with value Basic5@"/> + <line text="Advice running at void Basic5.methodWithSyncBlock1() with target of type class Basic5 with value Basic5@"/> + <line text="methodWithSyncBlock1"/> + <line text="Advice running at void Basic5.staticMethodWithSyncBlock1() with target of type class Basic5 with value Basic5@"/> + <line text="Advice running at void Basic5.staticMethodWithSyncBlock1() with target of type class Basic5 with value Basic5@"/> + <line text="staticMethodWithSyncBlock1"/> + <line text="Advice running at void Basic5.methodWithSyncBlock2() with target of type class Basic5 with value Basic5@"/> + <line text="Advice running at void Basic5.methodWithSyncBlock2() with target of type class Basic5 with value Basic5@"/> + <line text="methodWithSyncBlock2"/> + <line text="Advice running at void Basic5.staticMethodWithSyncBlock2() with target of type class Basic5 with value Basic5@"/> + <line text="Advice running at void Basic5.staticMethodWithSyncBlock2() with target of type class Basic5 with value Basic5@"/> + <line text="staticMethodWithSyncBlock2"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="a useful program"> + <compile files="Useful1.java" options="-1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Useful1"> + <stderr> + <line text="Average lock taking time over 2000"/> + <line text="We did time something!"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing - lock"> + <compile files="Parsing1.java" options="-1.5 -Xjoinpoints:synchronization"> + <message kind="warning" line="5" text="advice defined in Parsing1 has not been applied [Xlint:adviceDidNotMatch]"/> + </compile> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing - unlock"> + <compile files="Parsing2.java" options="-1.5 -Xjoinpoints:synchronization"> + <message kind="warning" line="5" text="advice defined in Parsing2 has not been applied [Xlint:adviceDidNotMatch]"/> + </compile> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing - error - lock"> + <compile files="Parsing1.java" options="-1.5"> + <message kind="warning" line="5" text="advice defined in Parsing1 has not been applied [Xlint:adviceDidNotMatch]"/> + <!-- this next warning comes out twice because we unpack the attributes twice... --> + <message kind="warning" line="5" text="lock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization"/> + </compile> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing - error - unlock"> + <compile files="Parsing2.java" options="-1.5"> + <message kind="warning" line="5" text="advice defined in Parsing2 has not been applied [Xlint:adviceDidNotMatch]"/> + <!-- this next warning comes out twice because we unpack the attributes twice... --> + <message kind="warning" line="5" text="unlock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization"/> + </compile> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing and matching - lock and static context"> + <compile files="ParsingAndMatching1.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="ParsingAndMatching1"> + <stderr> + <line text="Advice running at ParsingAndMatching1.java:14"/> + <line text="static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="using lock with LTW - missing flag"> + <compile files="LockAspect1.java" options="-1.5"> + <message kind="warning" line="6" text="lock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization"/> + </compile> + <compile files="BasicProgram1.java" options="-1.5"/> + <run class="BasicProgram1" ltw="aop1.xml"> + <stderr> + <!-- warning is something like 'warning at C:\temp\ajcSandbox\ajcTest61975.tmp\LockAspect1.java:6::0 lock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization'/--> + <line text="warning at "/> + <line text="nonstatic method running"/> + <line text="static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="using lock with LTW"> + <compile files="LockAspect1.java" options="-1.5 -Xjoinpoints:synchronization"/> + <compile files="BasicProgram1.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="BasicProgram1" ltw="aop3.xml"> + <stderr> + <line text="weaveinfo Join point 'lock(void java.lang.Object.<lock>(java.lang.Object))' in Type 'BasicProgram1' (BasicProgram1.java:11) advised by before advice from 'LockAspect1' (LockAspect1.java:6)"/> + <line text="weaveinfo Join point 'lock(void java.lang.Object.<lock>(java.lang.Object))' in Type 'BasicProgram1' (BasicProgram1.java:17) advised by before advice from 'LockAspect1' (LockAspect1.java:6)"/> + <line text="Lock advice running at BasicProgram1.java:17"/> + <line text="nonstatic method running"/> + <line text="Lock advice running at BasicProgram1.java:11"/> + <line text="static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="using unlock with LTW"> + <compile files="UnlockAspect1.java" options="-1.5 -Xjoinpoints:synchronization"/> + <compile files="BasicProgram1.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="BasicProgram1" ltw="aop4.xml"> + <stderr> + <line text="weaveinfo Join point 'unlock(void java.lang.Object.<unlock>(java.lang.Object))' in Type 'BasicProgram1' (BasicProgram1.java:11) advised by before advice from 'UnlockAspect1' (UnlockAspect1.java:6)"/> + <line text="weaveinfo Join point 'unlock(void java.lang.Object.<unlock>(java.lang.Object))' in Type 'BasicProgram1' (BasicProgram1.java:17) advised by before advice from 'UnlockAspect1' (UnlockAspect1.java:6)"/> + <line text="nonstatic method running"/> + <line text="Unlock advice running at BasicProgram1.java:17"/> + <line text="static method running"/> + <line text="Unlock advice running at BasicProgram1.java:11"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="using unlock with LTW - missing flag"> + <compile files="UnlockAspect1.java" options="-1.5"> + <message kind="warning" line="6" text="unlock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization"/> + </compile> + <compile files="BasicProgram1.java" options="-1.5"/> + <run class="BasicProgram1" ltw="aop2.xml"> + <stderr> + <line text="warning at "/> + <line text="nonstatic method running"/> + <line text="static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing and matching - unlock and static context"> + <compile files="ParsingAndMatching2.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="ParsingAndMatching2"> + <stderr> + <line text="static method running"/> + <line text="Advice running at ParsingAndMatching2.java:14"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing and matching - lock and non-static context"> + <compile files="ParsingAndMatching3.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="ParsingAndMatching3"> + <stderr> + <line text="Advice running at ParsingAndMatching3.java:15"/> + <line text="non-static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing and matching - unlock and non-static context"> + <compile files="ParsingAndMatching4.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="ParsingAndMatching4"> + <stderr> + <line text="non-static method running"/> + <line text="Advice running at ParsingAndMatching4.java:15"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="a useful program - with lock"> + <compile files="Useful2.java" options="-1.5 -showWeaveInfo -Xjoinpoints:synchronization"> + <message kind="weave" text="Join point 'method-execution(void Useful2.main(java.lang.String[]))' in Type 'Useful2' (Useful2.java:33) advised by afterReturning advice from 'LockMonitor' (Useful2.java:25)"/> + <message kind="weave" text="Join point 'lock(void java.lang.Object.<lock>(java.lang.Object))' in Type 'Useful2' (Useful2.java:42) advised by before advice from 'LockMonitor' (Useful2.java:9) [with runtime test]"/> + <message kind="weave" text="Join point 'unlock(void java.lang.Object.<unlock>(java.lang.Object))' in Type 'Useful2' (Useful2.java:42) advised by after advice from 'LockMonitor' (Useful2.java:14) [with runtime test]"/> + <!-- hope we aren't getting double messages out --> + </compile> + <run class="Useful2"> + <stderr> + <line text="Average time spent with lock over"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="combining pcds - lock and this"> + <compile files="CombiningPCDs1.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="CombiningPCDs1"> + <stderr> + <line text="static method running"/> + <line text="advice running at CombiningPCDs1.java:17"/> + <line text="non-static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="combining pcds - unlock and this"> + <compile files="CombiningPCDs2.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="CombiningPCDs2"> + <stderr> + <line text="static method running"/> + <line text="non-static method running"/> + <line text="advice running at CombiningPCDs2.java:17"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="thisjoinpoint - monitor entry"> + <compile files="ThisJoinPointLock.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="ThisJoinPointLock"> + <stderr> + <line text="match.toString(): lock(lock(Object))"/> + <line text="match.toShortString(): lock(lock(Object))"/> + <line text="match.toLongString(): lock(lock(java.lang.Object))"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="thisjoinpoint - monitor exit"> + <compile files="ThisJoinPointUnlock.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="ThisJoinPointUnlock"> + <stderr> + <line text="match.toString(): unlock(unlock(Object))"/> + <line text="match.toShortString(): unlock(unlock(Object))"/> + <line text="match.toLongString(): unlock(unlock(java.lang.Object))"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="prevent double unlock weaving messages and model contents"> + <compile files="ThisJoinPointUnlock.java" options="-1.5 -Xjoinpoints:synchronization -showWeaveInfo -emacssym"> + <message kind="weave" text="Join point 'lock(void java.lang.Object.<lock>(java.lang.Object))' in Type 'ThisJoinPointUnlock' (ThisJoinPointUnlock.java:38) advised by before advice from 'TJPAspect' (ThisJoinPointUnlock.java:4)"/> + <message kind="weave" text="Join point 'method-call(void ThisJoinPointUnlock.staticMethod())' in Type 'ThisJoinPointUnlock' (ThisJoinPointUnlock.java:39) advised by before advice from 'TJPAspect' (ThisJoinPointUnlock.java:4)"/> + <message kind="weave" text="Join point 'unlock(void java.lang.Object.<unlock>(java.lang.Object))' in Type 'ThisJoinPointUnlock' (ThisJoinPointUnlock.java:38) advised by before advice from 'TJPAspect' (ThisJoinPointUnlock.java:4)"/> + </compile> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="before advice - lock"> + <compile files="BeforeLock.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="BeforeLock"> + <stderr> + <line text="before() lock: advice running at BeforeLock.java:26"/> + <line text="static method running"/> + <line text="before(Foo) lock: advice running at BeforeLock.java:21"/> + <line text="before() lock: advice running at BeforeLock.java:21"/> + <line text="non-static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="before advice - unlock"> + <compile files="BeforeUnlock.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="BeforeUnlock"> + <stderr> + <line text="static method running"/> + <line text="before() unlock: advice running at BeforeUnlock.java:26"/> + <line text="non-static method running"/> + <line text="before(Foo) unlock: advice running at BeforeUnlock.java:21"/> + <line text="before() unlock: advice running at BeforeUnlock.java:21"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="after advice - lock"> + <compile files="AfterLock.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="AfterLock"> + <stderr> + <line text="after() lock: advice running at AfterLock.java:26"/> + <line text="static method running"/> + <line text="after(Foo) lock: advice running at AfterLock.java:21"/> + <line text="after() lock: advice running at AfterLock.java:21"/> + <line text="non-static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="after advice - unlock"> + <compile files="AfterUnlock.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="AfterUnlock"> + <stderr> + <line text="static method running"/> + <line text="after() unlock: advice running at AfterUnlock.java:26"/> + <line text="non-static method running"/> + <line text="after(Foo) unlock: advice running at AfterUnlock.java:21"/> + <line text="after() unlock: advice running at AfterUnlock.java:21"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="around advice - lock"> + <compile files="AroundLock.java" options="-1.5 -Xjoinpoints:synchronization"> + <message kind="warning" line="11" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="17" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="31" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="36" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="11" text="advice defined in AroundLock has not been applied [Xlint:adviceDidNotMatch]"/> + <message kind="warning" line="17" text="advice defined in AroundLock has not been applied [Xlint:adviceDidNotMatch]"/> + </compile> + <run class="AroundLock"> + <stderr> + <!--line text="around() lock: advice running at AroundLock.java:26"/--> + <line text="static method running"/> + <!--line text="around(Foo) lock: advice running at AroundLock.java:21"/> + <line text="around() lock: advice running at AroundLock.java:21"/--> + <line text="non-static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="around advice - unlock"> + <compile files="AroundUnlock.java" options="-1.5 -Xjoinpoints:synchronization"> + <message kind="warning" line="5" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="10" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="23" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="28" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="5" text="advice defined in AroundUnlock has not been applied [Xlint:adviceDidNotMatch]"/> + <message kind="warning" line="10" text="advice defined in AroundUnlock has not been applied [Xlint:adviceDidNotMatch]"/> + </compile> + <run class="AroundUnlock"> + <stderr> + <!--line text="around() unlock: advice running at AroundUnlock.java:26"/--> + <line text="static method running"/> + <!--line text="around(Foo) unlock: advice running at AroundUnlock.java:21"/--> + <!--line text="around() unlock: advice running at AroundUnlock.java:21"/--> + <line text="non-static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="investigation"> + <compile files="Investigation.java"> + </compile> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="One"> + <compile files="One.java -Xjoinpoints:synchronization"> + </compile> + <run class="One"/><!-- will check verification ... --> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="Two"> + <compile files="Two.java -Xjoinpoints:synchronization"> + <message kind="warning" line="14" text="advice matching the synchronized method shadow 'method-execution(void C.ma())' will be executed outside the lock rather than inside (compiler limitation)"/> + </compile> + <run class="Two"> + <stderr> + <line text="execution advice running"/> + <line text="hello"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="Three"> + <compile files="Three.java -Xjoinpoints:synchronization"> + <message kind="warning" line="20" text="advice matching the synchronized method shadow 'method-execution(void C.m3())' will be executed outside the lock rather than inside (compiler limitation)"/> + <message kind="warning" line="24" text="advice matching the synchronized method shadow 'method-execution(void C.m32())' will be executed outside the lock rather than inside (compiler limitation)"/> + </compile> + <run class="Three"> + <stderr> + <line text="hello"/> + <line text="execution advice running"/> + <line text="hello"/> + <line text="execution advice running2"/> + <line text="hello"/> + <line text="execution advice running3"/> + <line text="hello"/> + <line text="execution advice running4"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="Four"> + <compile files="Four.java -Xjoinpoints:synchronization"> + <message kind="warning" line="16" text="advice matching the synchronized method shadow 'method-execution(void C.m())' will be executed outside the lock rather than inside (compiler limitation)"/> + <message kind="warning" line="20" text="advice matching the synchronized method shadow 'method-execution(void C.m2())' will be executed outside the lock rather than inside (compiler limitation)"/> + </compile> + <run class="Four"> + <stderr> + <line text="hello"/> + <line text="execution advice running"/> + <line text="hello"/> + <line text="execution advice running2"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="Five - Java5"> + <compile files="Five.java -1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Five"> + <stderr> + <line text="test"/> + <line text="hello"/> + <line text="test"/> + <line text="hello"/> + <line text="test"/> + <line text="hello"/> + <line text="test"/> + <line text="hello"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="Six - preJava5"> + <compile files="Six.java -Xjoinpoints:synchronization"> + </compile> + <run class="Six"> + <stderr> + <line text="test"/> + <line text="hello"/> + <line text="test"/> + <line text="hello"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="lock pcd on transformed non-static method"> + <compile files="Seven.java -Xjoinpoints:synchronization"> + </compile> + <run class="Seven"> + <stderr> + <line text="Locking occurring at lock(lock(Object))"/> + <line text="Seven.java"/> + <line text="hello"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="unlock pcd on transformed non-static method"> + <compile files="Eight.java -Xjoinpoints:synchronization"> + </compile> + <run class="Eight"> + <stderr> + <line text="hello"/> + <line text="Unlocking occurring at unlock(unlock(Object))"/> + <line text="Eight.java"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="lock pcd on transformed static method - J5"> + <compile files="Nine.java -1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Nine"> + <stderr> + <line text="Locking occurring at lock(lock(Object))"/> + <line text="Nine.java"/> + <line text="hello"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="unlock pcd on transformed static method - J5"> + <compile files="Ten.java -1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Ten"> + <stderr> + <line text="hello"/> + <line text="Unlocking occurring at unlock(unlock(Object))"/> + <line text="Ten.java"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="lock pcd on transformed static method - preJ5"> + <compile files="Eleven.java -Xjoinpoints:synchronization"> + </compile> + <run class="Eleven"> + <stderr> + <line text="Locking occurring at lock(lock(Object))"/> + <line text="Eleven.java"/> + <line text="hello"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="unlock pcd on transformed static method - preJ5"> + <compile files="Twelve.java" options="-Xjoinpoints:synchronization"> + </compile> + <run class="Twelve"> + <stderr> + <line text="hello"/> + <line text="Unlocking occurring at unlock(unlock(Object))"/> + <line text="Twelve.java"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="obtaining locked object through getArgs"> + <compile files="LockingWithTJP.java" options="-Xjoinpoints:synchronization"> + </compile> + <run class="LockingWithTJP"> + <stderr> + <line text="before() lock: advice running at LockingWithTJP.java:18"/> + <line text="Locked on LockingWithTJP$Foo"/> + <line text="non-static method running"/> + <line text="before() lock: advice running at LockingWithTJP.java:23"/> + <line text="Locked on class java.lang.String"/> + <line text="static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="other targeters"> + <compile files="OtherTargeters.java" options="-Xjoinpoints:synchronization"> + <message kind="warning" line="8" text="advice matching the synchronized "/> + </compile> + <run class="OtherTargeters"> + <stderr> + <line text="advice running"/> + <line text="foo() running"/> + </stderr> + </run> + </ajc-test> + +</suite> |