From b2247654a3b35eb26731fac20247fc3007612eab Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 24 May 2006 07:15:42 +0000 Subject: [PATCH] synchronization joinpoints: testcode --- .../synchronization/AfterLock.java | 31 + .../synchronization/AfterUnlock.java | 31 + .../synchronization/AroundLock.java | 41 ++ .../synchronization/AroundUnlock.java | 33 + tests/features152/synchronization/Basic.java | 44 ++ tests/features152/synchronization/Basic2.java | 51 ++ tests/features152/synchronization/Basic3.java | 52 ++ tests/features152/synchronization/Basic4.java | 52 ++ tests/features152/synchronization/Basic5.java | 52 ++ .../synchronization/BasicProgram1.java | 21 + .../synchronization/BeforeLock.java | 31 + .../synchronization/BeforeUnlock.java | 31 + .../synchronization/CombiningPCDs1.java | 27 + .../synchronization/CombiningPCDs2.java | 27 + .../synchronization/LockAspect1.java | 9 + .../synchronization/LockingWithTJP.java | 28 + .../features152/synchronization/Parsing1.java | 14 + .../features152/synchronization/Parsing2.java | 14 + .../synchronization/ParsingAndMatching1.java | 18 + .../synchronization/ParsingAndMatching2.java | 18 + .../synchronization/ParsingAndMatching3.java | 20 + .../synchronization/ParsingAndMatching4.java | 20 + .../synchronization/ThisJoinPointLock.java | 48 ++ .../synchronization/ThisJoinPointUnlock.java | 48 ++ .../synchronization/UnlockAspect1.java | 9 + .../features152/synchronization/Useful1.java | 51 ++ .../features152/synchronization/Useful2.java | 47 ++ tests/features152/synchronization/aop1.xml | 8 + tests/features152/synchronization/aop2.xml | 8 + tests/features152/synchronization/aop3.xml | 8 + tests/features152/synchronization/aop4.xml | 8 + .../synchronization/transformed/Eight.java | 22 + .../synchronization/transformed/Eleven.java | 22 + .../synchronization/transformed/Five.java | 38 ++ .../synchronization/transformed/Four.java | 29 + .../transformed/Investigation.java | 357 +++++++++++ .../synchronization/transformed/Nine.java | 22 + .../synchronization/transformed/One.java | 39 ++ .../transformed/OtherTargeters.java | 25 + .../synchronization/transformed/Seven.java | 22 + .../synchronization/transformed/Six.java | 26 + .../synchronization/transformed/Ten.java | 22 + .../synchronization/transformed/Thirteen.java | 6 + .../synchronization/transformed/Three.java | 44 ++ .../synchronization/transformed/Twelve.java | 22 + .../synchronization/transformed/Two.java | 19 + .../transformed/expected/C.b.txt | 22 + .../transformed/expected/C.bbb.txt | 38 ++ .../transformed/expected/C.m.txt | 23 + .../transformed/expected/C.m2.txt | 28 + .../transformed/expected/C.m3.txt | 23 + .../transformed/expected/C.m32.txt | 28 + .../transformed/expected/C.m33.txt | 24 + .../transformed/expected/C.m34.txt | 26 + .../transformed/expected/C.m4.txt | 26 + .../transformed/expected/C.ma.txt | 22 + .../transformed/expected/Investigation.b.txt | 21 + .../transformed/expected/Investigation.c.txt | 35 ++ .../transformed/expected/Investigation.d.txt | 38 ++ .../transformed/expected/Investigation.e.txt | 40 ++ .../transformed/expected/One.b.txt | 22 + .../transformed/expected/One.c.txt | 36 ++ .../transformed/expected/One.e.txt | 43 ++ .../ajc152/SynchronizationTests.java | 240 +++++++ .../ajc152/SynchronizationTransformTests.java | 328 ++++++++++ .../systemtest/ajc152/synchronization.xml | 585 ++++++++++++++++++ 66 files changed, 3263 insertions(+) create mode 100644 tests/features152/synchronization/AfterLock.java create mode 100644 tests/features152/synchronization/AfterUnlock.java create mode 100644 tests/features152/synchronization/AroundLock.java create mode 100644 tests/features152/synchronization/AroundUnlock.java create mode 100644 tests/features152/synchronization/Basic.java create mode 100644 tests/features152/synchronization/Basic2.java create mode 100644 tests/features152/synchronization/Basic3.java create mode 100644 tests/features152/synchronization/Basic4.java create mode 100644 tests/features152/synchronization/Basic5.java create mode 100644 tests/features152/synchronization/BasicProgram1.java create mode 100644 tests/features152/synchronization/BeforeLock.java create mode 100644 tests/features152/synchronization/BeforeUnlock.java create mode 100644 tests/features152/synchronization/CombiningPCDs1.java create mode 100644 tests/features152/synchronization/CombiningPCDs2.java create mode 100644 tests/features152/synchronization/LockAspect1.java create mode 100644 tests/features152/synchronization/LockingWithTJP.java create mode 100644 tests/features152/synchronization/Parsing1.java create mode 100644 tests/features152/synchronization/Parsing2.java create mode 100644 tests/features152/synchronization/ParsingAndMatching1.java create mode 100644 tests/features152/synchronization/ParsingAndMatching2.java create mode 100644 tests/features152/synchronization/ParsingAndMatching3.java create mode 100644 tests/features152/synchronization/ParsingAndMatching4.java create mode 100644 tests/features152/synchronization/ThisJoinPointLock.java create mode 100644 tests/features152/synchronization/ThisJoinPointUnlock.java create mode 100644 tests/features152/synchronization/UnlockAspect1.java create mode 100644 tests/features152/synchronization/Useful1.java create mode 100644 tests/features152/synchronization/Useful2.java create mode 100644 tests/features152/synchronization/aop1.xml create mode 100644 tests/features152/synchronization/aop2.xml create mode 100644 tests/features152/synchronization/aop3.xml create mode 100644 tests/features152/synchronization/aop4.xml create mode 100644 tests/features152/synchronization/transformed/Eight.java create mode 100644 tests/features152/synchronization/transformed/Eleven.java create mode 100644 tests/features152/synchronization/transformed/Five.java create mode 100644 tests/features152/synchronization/transformed/Four.java create mode 100644 tests/features152/synchronization/transformed/Investigation.java create mode 100644 tests/features152/synchronization/transformed/Nine.java create mode 100644 tests/features152/synchronization/transformed/One.java create mode 100644 tests/features152/synchronization/transformed/OtherTargeters.java create mode 100644 tests/features152/synchronization/transformed/Seven.java create mode 100644 tests/features152/synchronization/transformed/Six.java create mode 100644 tests/features152/synchronization/transformed/Ten.java create mode 100644 tests/features152/synchronization/transformed/Thirteen.java create mode 100644 tests/features152/synchronization/transformed/Three.java create mode 100644 tests/features152/synchronization/transformed/Twelve.java create mode 100644 tests/features152/synchronization/transformed/Two.java create mode 100644 tests/features152/synchronization/transformed/expected/C.b.txt create mode 100644 tests/features152/synchronization/transformed/expected/C.bbb.txt create mode 100644 tests/features152/synchronization/transformed/expected/C.m.txt create mode 100644 tests/features152/synchronization/transformed/expected/C.m2.txt create mode 100644 tests/features152/synchronization/transformed/expected/C.m3.txt create mode 100644 tests/features152/synchronization/transformed/expected/C.m32.txt create mode 100644 tests/features152/synchronization/transformed/expected/C.m33.txt create mode 100644 tests/features152/synchronization/transformed/expected/C.m34.txt create mode 100644 tests/features152/synchronization/transformed/expected/C.m4.txt create mode 100644 tests/features152/synchronization/transformed/expected/C.ma.txt create mode 100644 tests/features152/synchronization/transformed/expected/Investigation.b.txt create mode 100644 tests/features152/synchronization/transformed/expected/Investigation.c.txt create mode 100644 tests/features152/synchronization/transformed/expected/Investigation.d.txt create mode 100644 tests/features152/synchronization/transformed/expected/Investigation.e.txt create mode 100644 tests/features152/synchronization/transformed/expected/One.b.txt create mode 100644 tests/features152/synchronization/transformed/expected/One.c.txt create mode 100644 tests/features152/synchronization/transformed/expected/One.e.txt create mode 100644 tests/src/org/aspectj/systemtest/ajc152/SynchronizationTests.java create mode 100644 tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java create mode 100644 tests/src/org/aspectj/systemtest/ajc152/synchronization.xml 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 @@ + + + + + + + + \ 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 @@ + + + + + + + + \ 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 @@ + + + + + + + + \ 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 @@ + + + + + + + + \ 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 ; + const #6 = Asciz ()V; + const #7 = Asciz Code; + const #8 = NameAndType #5:#6;// "":()V + const #9 = Method #4.#8; // java/lang/Object."":()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;// "":(Ljava/lang/String;)V + const #41 = Method #37.#40; // java/io/File."":(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;// "":(Ljava/io/File;)V + const #46 = Method #43.#45; // java/io/FileInputStream."":(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."":()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."":()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."":(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."":(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."":()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. (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. ()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. ()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. ()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. ()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. (Ljava/lang/String;)V + | | ASTORE_2 + | | NEW java.io.FileInputStream (line 30) + | | DUP + | | ALOAD_2 // Ljava/io/File; f + | | INVOKESPECIAL java.io.FileInputStream. (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. ()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. (Ljava/lang/String;)V + | | ASTORE_1 + | | NEW java.io.FileInputStream (line 21) + | | DUP + | | ALOAD_1 // Ljava/io/File; f + | | INVOKESPECIAL java.io.FileInputStream. (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. ()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.(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.(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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5