diff options
author | aclement <aclement> | 2006-05-24 07:15:42 +0000 |
---|---|---|
committer | aclement <aclement> | 2006-05-24 07:15:42 +0000 |
commit | b2247654a3b35eb26731fac20247fc3007612eab (patch) | |
tree | 3b3bc6d6e2833e1d62aaf4506b1e8e3f4d12f51d /tests/src/org | |
parent | 917a3a70f5c09f16151200f13eb89283c4bb2abf (diff) | |
download | aspectj-b2247654a3b35eb26731fac20247fc3007612eab.tar.gz aspectj-b2247654a3b35eb26731fac20247fc3007612eab.zip |
synchronization joinpoints: testcode
Diffstat (limited to 'tests/src/org')
3 files changed, 1153 insertions, 0 deletions
diff --git a/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTests.java b/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTests.java new file mode 100644 index 000000000..094a211f3 --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTests.java @@ -0,0 +1,240 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc152; + +import java.io.File; +import java.util.List; + +import junit.framework.Test; + +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IProgramElement; +import org.aspectj.asm.IRelationship; +import org.aspectj.testing.XMLBasedAjcTestCase; + +/** + * Work items, phase #1: lock()/unlock() + * x expose new joinpoints + * x parse new pcds + * x fix tjp string + * x preventing double unlock() messages/markers in structure model + * x error messages appropriate for attempting to use around advice on synchronization join points + * x making the use of lock/unlock conditional on an -Xjoinpoints:synchronization + * x activating the -Xjoinpoints options from LTW configurations rather than through batch/AJDT + * x ensure the lock/unlock joinpoints only appear when -Xjoinpoints:synchronization specified + * TAG: Completion of PHASE1 + * + * + * Work items, phase #2: transformation + * + * Design: transform all synchronized methods: + * public synchronized void m() { + * ... + * } + * => + * public void m() { + * synchronized (this) { + * ... + * } + * } + * + * x transforming synchronized methods + * x matching execution(synchronized * *(..)) for transformed code + * x warning message for execution() hitting a synchronized method + * x ensure verifier runs over generated code (done by just executing the code as part of the test spec) + * TAG: Completion of PHASE2 + * + * + * Need sorting before claiming complete: + * - coping with asking 'regular' AspectJ to process an Aspect built by this variant of AJ that provides lock()/unlock() + * - targetting 1.2 runtime + * + * TAG: Finished + * + * 'Other' work items: + * - optimize matching for transformed methods since we *know* the type we are locking on + * - supporting type pattern in lock() unlock() - this is not entirely trivial as kinded pointcuts do not usually have any residue + * - weaving messages include 'unusual' strings for the join points, not the + * same as revealed by thisJoinPoint.getSignature() in code - handler is probably similar + * - documentation + * - Ant task support for -Xjoinpoints + * - lazy translation of synchronized methods, rather than eager + * - applying execution(* *(..)) correctly to transformed methods (i.e. inside lock/unlock) + * - use knowledge of type containing synchronized methods to optimize matching of (un)lock() - not always needing residue + * - line number table is incorrect for transformed code (lock joinpoint has no line number) + * + * Notes: + * IllegalMonitorStateException + * Thrown to indicate that a thread has attempted to wait on an object's monitor or to + * notify other threads waiting on an object's monitor without owning the specified monitor. + * + * around advice won't work on SUN VMs (may be a bug that it does work on other VMs) since the monitor + * instructions are extracted to a separate method for proceed() calls and yet the VM seems to want + * them paired inside a single method. + * + * Really we only need to restrict the use of around advice on synchronization join points + * if the advice uses proceed() - but policing that is a little tough because (DOH) the + * AdviceAttribute field 'proceedCallSignatures' is never filled in (which records how many + * proceeds occur in the advice) - see where it isnt filled in at + * AdviceDeclaration.resolveStatements() in the loop that goes over the proceedCalls list. + * + * + * Problems: + * - Can't run it on a 1.2.1 runtime - just not practical + * - It ain't going to work with the aspectjrt.jar 1.5.0 that websphere will be shipping. + * *IF* someone manages to get into a situation where they ask for the signature of a lock jp, but the lock + * jp won't have been exposed if they weren't weaving with a 1.5 weaver... + * + * + * Method transformation, example: + + public synchronized void m(); + Code: + Stack=2, Locals=1, Args_size=1 + 0: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 3: ldc #3; //String hello + 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 8: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 11: ldc #5; //String world + 13: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 16: return + LineNumberTable: + line 4: 0 + line 5: 8 + line 6: 16 + + public void m2(); + Code: + Stack=2, Locals=3, Args_size=1 + 0: aload_0 + 1: dup + 2: astore_1 + 3: monitorenter + 4: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 7: ldc #3; //String hello + 9: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 12: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 15: ldc #5; //String world + 17: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 20: aload_1 + 21: monitorexit + 22: goto 30 + 25: astore_2 + 26: aload_1 + 27: monitorexit + 28: aload_2 + 29: athrow + 30: return + Exception table: + from to target type + 4 22 25 any + 25 28 25 any + * + * Factors affecting transformation: + * - LDC in Java5 supports referring to a class literal, e.g. Foo.class whereas before Java5, it did not. + * This means if generating the synchronized() block for a static method from a preJava5 class then + * we have to generate a lot of crap to build the class object for locking and unlocking. The object + * is also stored in a local field of the type (if we follow the pattern of JDT/JAVAC) + */ + +public class SynchronizationTests extends XMLBasedAjcTestCase { + + // testing the new join points for monitorenter/monitorexit + public void testTheBasics_1() { runTest("basic"); } + public void testTheBasics_2() { runTest("basic - within"); } + public void testTheBasics_3() { runTest("basic - within plus args"); } + public void testTheBasics_4() { runTest("basic - within plus this"); } // this null in static context + public void testTheBasics_5() { runTest("basic - within plus target"); } // target null in static context? + + + // testing parsing of the new PCDs lock/unlock + public void testParsing_1() { runTest("parsing - lock"); } + public void testParsing_2() { runTest("parsing - unlock"); } + public void testParsing_errors_1() { runTest("parsing - error - lock"); } + public void testParsing_errors_2() { runTest("parsing - error - unlock"); } + + // testing parsing and matching with the new PCDs + public void testParsingAndMatching_1() { runTest("parsing and matching - lock and static context"); } + public void testParsingAndMatching_2() { runTest("parsing and matching - unlock and static context"); } + public void testParsingAndMatching_3() { runTest("parsing and matching - lock and non-static context"); } + public void testParsingAndMatching_4() { runTest("parsing and matching - unlock and non-static context"); } + public void testParsingAndMatching_5() { runTest("parsing and matching - lock and non-static context"); } + public void testParsingAndMatching_6() { runTest("parsing and matching - unlock and non-static context"); } + + // using the new PCDs in a LTW environment + public void testUsingWithLTW_MissingFlag_1() { runTest("using lock with LTW - missing flag");} + public void testUsingWithLTW_MissingFlag_2() { runTest("using unlock with LTW - missing flag");} + public void testUsingWithLTW_1() { runTest("using lock with LTW");} + public void testUsingWithLTW_2() { runTest("using unlock with LTW");} + + // multiple PCDs + public void testCombiningPCDs_1() { runTest("combining pcds - lock and this");} + public void testCombiningPCDs_2() { runTest("combining pcds - unlock and this");} + + // useful examples + public void testUseful_1() { runTest("a useful program"); } // just uses within/args - matching the (un)lock jps + public void testUseful_2() { runTest("a useful program - with lock"); } // uses lock/args + + // all the methods of thisJoinPoint + public void testThisJoinPoint_1() { runTest("thisjoinpoint - monitor entry");} + public void testThisJoinPoint_2() { runTest("thisjoinpoint - monitor exit"); } + + public void testDoubleMessagesOnUnlock() { + //AsmManager.setReporting("c:/foo.txt",true,true,true,true); + runTest("prevent double unlock weaving messages and model contents"); + //checkModel1(); + } + + // targetting 1.2 runtime - signature creation code in LazyClassGen.initializeTjp may not work + + // different advice kinds + public void testBeforeAdvice_1() { runTest("before advice - lock");} + public void testBeforeAdvice_2() { runTest("before advice - unlock");} + public void testAfterAdvice_1() { runTest("after advice - lock"); } + public void testAfterAdvice_2() { runTest("after advice - unlock"); } + public void testAroundAdvice_1() { runTest("around advice - lock");} + public void testAroundAdvice_2() { runTest("around advice - unlock");} + + + public void testLockingTJP() { runTest("obtaining locked object through getArgs");} + + // binary weaving? + + // nested locking/unlocking + + // --- helpers + + // Half finished - could check there is only one relationship for unlock() rather than two - but + // that seems to be the case anyway (peculiar...) + private void checkModel1() { + // Verifies only one unlock relationship, not two + IProgramElement unlockNode = AsmManager.getDefault().getHierarchy().findElementForLabel(AsmManager.getDefault().getHierarchy().getRoot(), + IProgramElement.Kind.CODE,"unlock(void java.lang.Object.<unlock>(java.lang.Object))"); + assertTrue("Couldn't find the unlock node",unlockNode!=null); + List l = AsmManager.getDefault().getRelationshipMap().get(unlockNode); + assertTrue("should be one entry :"+l,l!=null && l.size()==1); + IRelationship ir = (IRelationship)l.get(0); + System.err.println(ir); + List targs = ir.getTargets(); + System.err.println(targs.size()); + System.err.println(targs.get(0)); + } + + // --- + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(SynchronizationTests.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc152/synchronization.xml"); + } + +} diff --git a/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java b/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java new file mode 100644 index 000000000..681f9b3ed --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java @@ -0,0 +1,328 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc152; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import junit.framework.Test; + +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IProgramElement; +import org.aspectj.asm.IRelationship; +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.testing.util.TestUtil; +import org.aspectj.testing.util.TestUtil.LineStream; +import org.aspectj.weaver.ReferenceType; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.World; +import org.aspectj.weaver.bcel.BcelObjectType; +import org.aspectj.weaver.bcel.BcelWorld; +import org.aspectj.weaver.bcel.LazyClassGen; +import org.aspectj.weaver.bcel.LazyMethodGen; + + +/** + * Method transformation, example: + + public synchronized void m(); + Code: + Stack=2, Locals=1, Args_size=1 + 0: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 3: ldc #3; //String hello + 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 8: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 11: ldc #5; //String world + 13: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 16: return + LineNumberTable: + line 4: 0 + line 5: 8 + line 6: 16 + + public void m2(); + Code: + Stack=2, Locals=3, Args_size=1 + 0: aload_0 + 1: dup + 2: astore_1 + 3: monitorenter + 4: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 7: ldc #3; //String hello + 9: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 12: getstatic #2; //Field java/lang/System.err:Ljava/io/PrintStream; + 15: ldc #5; //String world + 17: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V + 20: aload_1 + 21: monitorexit + 22: goto 30 + 25: astore_2 + 26: aload_1 + 27: monitorexit + 28: aload_2 + 29: athrow + 30: return + Exception table: + from to target type + 4 22 25 any + 25 28 25 any + */ + +public class SynchronizationTransformTests extends XMLBasedAjcTestCase { + + private static boolean regenerate; + + static { regenerate = false; } + + private World world; + + public void testInvestigatingTransforming() { + runTest("investigation"); + checkMethod("Investigation","b"); // similar output to One.b + checkMethod("Investigation","c"); + checkMethod("Investigation","d"); + checkMethod("Investigation","e"); + } + + public void testTransform1() { + runTest("One"); + checkMethod("One","b"); + checkMethod("One","c"); + checkMethod("One","e"); + } + + // before() on execution jp + public void testTransform2() { + runTest("Two"); + checkMethod("C","ma"); + } + + // after() returning/after() throwing on execution jp + // after() returning -> make all returns go through the same exit point and make + // it call the advice + // after() throwing -> add a catch block that calls the advice + public void testTransform3() { + runTest("Three"); + checkMethod("C","m3"); + checkMethod("C","m32"); + checkMethod("C","m33"); // like m() but synchronized block + checkMethod("C","m34"); // like m2() but synchronized block + } + + // like testTransform3() but pointcuts explicitly specify synchronized + public void testTransform4() { + runTest("Four"); + checkMethod("C","m"); + checkMethod("C","m2"); + } + + + + // Java5 variant + public void testStaticSynchronizedMethodTransformJava5() { + runTest("Five - Java5"); + checkMethod("C","b"); + } + + // < Java5 variant + public void testStaticSynchronizedMethodTransformPreJava5() { + runTest("Six - preJava5"); + checkMethod("C","bbb"); + } + + public void testLockPcdOnTransformedNonStaticMethod() { + runTest("lock pcd on transformed non-static method"); + } + + public void testUnlockPcdOnTransformedNonStaticMethod() { + runTest("unlock pcd on transformed non-static method"); + } + + public void testLockPcdOnTransformedStaticMethod() { + runTest("lock pcd on transformed static method - J5"); + } + + public void testUnlockPcdOnTransformedStaticMethod() { + runTest("unlock pcd on transformed static method - J5"); + } + + public void testLockPcdOnTransformedStaticMethodPreJ5() { + runTest("lock pcd on transformed static method - preJ5"); + } + + public void testUnlockPcdOnTransformedStaticMethodPreJ5() { + runTest("unlock pcd on transformed static method - preJ5"); + } + + // more complex code sequences... + public void testOtherTargeters() { + runTest("other targeters"); + } + + // --- infrastructure below + + private void checkMethod(String typename,String methodname) { + LazyMethodGen m = getMethod(typename,methodname); + File expectedF = new File(".."+File.separator+"tests"+File.separator+"features152"+File.separator+"synchronization"+File.separator+ + "transformed"+File.separator+"expected"+File.separator+ + typename+"."+methodname+".txt"); + if (regenerate) { + saveMethod(expectedF, m); + } else { + compareMethod(expectedF, m); + } + } + + + + private LazyMethodGen getMethod(String typename,String methodname) { + BcelObjectType type = getBcelObjectFor(typename); + LazyClassGen lcg = type.getLazyClassGen(); + List /*LazyMethodGen*/ methods = lcg.getMethodGens(); + for (Iterator iter = methods.iterator(); iter.hasNext();) { + LazyMethodGen element = (LazyMethodGen) iter.next(); + if (element.getName().equals(methodname)) { + return element; + } + } + return null; + } + + private BcelObjectType getBcelObjectFor(String clazzname) { + ensureWorldSetup(); + ResolvedType rt = world.resolve(clazzname); + if (rt==null) fail("Couldn't find class "+clazzname); + ReferenceType rtt = (ReferenceType)rt; + BcelObjectType bot = (BcelObjectType)rtt.getDelegate(); + return bot; + } + + private void ensureWorldSetup() { + if (world == null) { + world = new BcelWorld( + getSandboxDirectory()+File.pathSeparator+ + System.getProperty("java.class.path")); + world.setFastDelegateSupport(false); + } + } + + protected Method getMethod(JavaClass cl,String methodname) { + Method[] methods = cl.getMethods(); + for (int i = 0; i < methods.length; i++) { + Method m = methods[i]; + if (m.getName().equals(methodname)) { + return m; + } + } + return null; + } + + public void dump(String title,String[] strs) { + System.err.println(title); + for (int i = 0; i < strs.length; i++) { + System.err.println(i+") "+strs[i]); + } + } + + private void compareMethod(File f,LazyMethodGen m) { + BufferedReader fr; + if (!f.exists()) { + fail("Can't find expected output file "+f); + } + try { + // Load the file in + fr = new BufferedReader(new FileReader(f)); + String line = null; + List originalFileContents = new ArrayList(); + while ((line=fr.readLine())!=null) originalFileContents.add(line); + String[] fileContents = (String[])originalFileContents.toArray(new String[]{}); + + LineStream ls = new TestUtil.LineStream(); + m.print(ls,null); + String[] lines = ls.getLines(); + for (int i = 0; i < lines.length; i++) { + String existingLine = lines[i]; + if (!fileContents[i].equals(existingLine)) { + dump("File contents:",fileContents); + dump("Actual:",lines); + fail("\nDifference in method "+m.getName()+" on line "+i+" between the expected:\n"+fileContents[i]+ + "\nand the found:\n"+existingLine); + } + } + } catch (Exception e) { + fail("Unexpected exception saving weaving messages:"+e); + } + } + + private String stringify(List l) { + StringBuffer result = new StringBuffer(); + for (Iterator iter = l.iterator(); iter.hasNext();) { + String str = (String) iter.next(); + result.append(str);result.append("\n"); + } + return result.toString(); + } + + + private void saveMethod(File f,LazyMethodGen m) { + System.out.println("Saving method into "+f.getName()); + try { + m.print(new PrintStream(f),null); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail("Couldn't store the method in file "+f); + } + } + + + + + + + + // --- helpers + + // Half finished - could check there is only one relationship for unlock() rather than two - but + // that seems to be the case anyway (peculiar...) + private void checkModel1() { + // Verifies only one unlock relationship, not two + IProgramElement unlockNode = AsmManager.getDefault().getHierarchy().findElementForLabel(AsmManager.getDefault().getHierarchy().getRoot(), + IProgramElement.Kind.CODE,"unlock(void java.lang.Object.<unlock>(java.lang.Object))"); + assertTrue("Couldn't find the unlock node",unlockNode!=null); + List l = AsmManager.getDefault().getRelationshipMap().get(unlockNode); + assertTrue("should be one entry :"+l,l!=null && l.size()==1); + IRelationship ir = (IRelationship)l.get(0); + System.err.println(ir); + List targs = ir.getTargets(); + System.err.println(targs.size()); + System.err.println(targs.get(0)); + } + + // --- + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(SynchronizationTransformTests.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc152/synchronization.xml"); + } + + public void tearDown() { world = null; } + +} diff --git a/tests/src/org/aspectj/systemtest/ajc152/synchronization.xml b/tests/src/org/aspectj/systemtest/ajc152/synchronization.xml new file mode 100644 index 000000000..0f9dbbfb6 --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc152/synchronization.xml @@ -0,0 +1,585 @@ +<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]> + +<!-- AspectJ v1.5.1 Tests --> +<suite> + + <ajc-test dir="features152/synchronization" title="basic"> + <compile files="Basic.java" options="-1.5 -showWeaveInfo -Xjoinpoints:synchronization"> + </compile> + <run class="Basic"> + <stderr> + <line text="methodWithSyncBlock1"/> + <line text="staticMethodWithSyncBlock1"/> + <line text="methodWithSyncBlock2"/> + <line text="staticMethodWithSyncBlock2"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="basic - within"> + <compile files="Basic2.java" options="-1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Basic2"> + <stderr> + <line text="methodWithSyncBlock1"/> + <line text="Advice running at lock(Object)"/> + <line text="Advice running at unlock(Object)"/> + <line text="staticMethodWithSyncBlock1"/> + <line text="Advice running at lock(Object)"/> + <line text="Advice running at unlock(Object)"/> + <line text="methodWithSyncBlock2"/> + <line text="Advice running at lock(Object)"/> + <line text="Advice running at unlock(Object)"/> + <line text="staticMethodWithSyncBlock2"/> + <line text="Advice running at lock(Object)"/> + <line text="Advice running at unlock(Object)"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="basic - within plus args"> + <compile files="Basic3.java" options="-1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Basic3"> + <stderr> + <line text="methodWithSyncBlock1"/> + <line text="Advice running at lock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="Advice running at unlock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="staticMethodWithSyncBlock1"/> + <line text="Advice running at lock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="Advice running at unlock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="methodWithSyncBlock2"/> + <line text="Advice running at lock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="Advice running at unlock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="staticMethodWithSyncBlock2"/> + <line text="Advice running at lock(Object) with this of type class Basic3 with value Basic3@"/> + <line text="Advice running at unlock(Object) with this of type class Basic3 with value Basic3@"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="basic - within plus this"> + <compile files="Basic4.java" options="-1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Basic4"> + <stderr> + <line text="methodWithSyncBlock1"/> + <line text="Advice running at lock(Object) with args of type class Basic4 with value Basic4@"/> + <line text="Advice running at unlock(Object) with args of type class Basic4 with value Basic4@"/> + <line text="staticMethodWithSyncBlock1"/> + <line text="Advice running at lock(Object) with args of type class java.lang.Class with value class Basic4"/> + <line text="Advice running at unlock(Object) with args of type class java.lang.Class with value class Basic4"/> + <line text="methodWithSyncBlock2"/> + <line text="Advice running at lock(Object) with args of type class Basic4 with value Basic4@"/> + <line text="Advice running at unlock(Object) with args of type class Basic4 with value Basic4@"/> + <line text="staticMethodWithSyncBlock2"/> + <line text="Advice running at lock(Object) with args of type class java.lang.Class with value class Basic4"/> + <line text="Advice running at unlock(Object) with args of type class java.lang.Class with value class Basic4"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="basic - within plus target"> + <compile files="Basic5.java" options="-1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Basic5"> + <stderr> + <line text="Advice running at void Basic5.methodWithSyncBlock1() with target of type class Basic5 with value Basic5@"/> + <line text="Advice running at void Basic5.methodWithSyncBlock1() with target of type class Basic5 with value Basic5@"/> + <line text="methodWithSyncBlock1"/> + <line text="Advice running at void Basic5.staticMethodWithSyncBlock1() with target of type class Basic5 with value Basic5@"/> + <line text="Advice running at void Basic5.staticMethodWithSyncBlock1() with target of type class Basic5 with value Basic5@"/> + <line text="staticMethodWithSyncBlock1"/> + <line text="Advice running at void Basic5.methodWithSyncBlock2() with target of type class Basic5 with value Basic5@"/> + <line text="Advice running at void Basic5.methodWithSyncBlock2() with target of type class Basic5 with value Basic5@"/> + <line text="methodWithSyncBlock2"/> + <line text="Advice running at void Basic5.staticMethodWithSyncBlock2() with target of type class Basic5 with value Basic5@"/> + <line text="Advice running at void Basic5.staticMethodWithSyncBlock2() with target of type class Basic5 with value Basic5@"/> + <line text="staticMethodWithSyncBlock2"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="a useful program"> + <compile files="Useful1.java" options="-1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Useful1"> + <stderr> + <line text="Average lock taking time over 2000"/> + <line text="We did time something!"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing - lock"> + <compile files="Parsing1.java" options="-1.5 -Xjoinpoints:synchronization"> + <message kind="warning" line="5" text="advice defined in Parsing1 has not been applied [Xlint:adviceDidNotMatch]"/> + </compile> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing - unlock"> + <compile files="Parsing2.java" options="-1.5 -Xjoinpoints:synchronization"> + <message kind="warning" line="5" text="advice defined in Parsing2 has not been applied [Xlint:adviceDidNotMatch]"/> + </compile> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing - error - lock"> + <compile files="Parsing1.java" options="-1.5"> + <message kind="warning" line="5" text="advice defined in Parsing1 has not been applied [Xlint:adviceDidNotMatch]"/> + <!-- this next warning comes out twice because we unpack the attributes twice... --> + <message kind="warning" line="5" text="lock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization"/> + </compile> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing - error - unlock"> + <compile files="Parsing2.java" options="-1.5"> + <message kind="warning" line="5" text="advice defined in Parsing2 has not been applied [Xlint:adviceDidNotMatch]"/> + <!-- this next warning comes out twice because we unpack the attributes twice... --> + <message kind="warning" line="5" text="unlock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization"/> + </compile> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing and matching - lock and static context"> + <compile files="ParsingAndMatching1.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="ParsingAndMatching1"> + <stderr> + <line text="Advice running at ParsingAndMatching1.java:14"/> + <line text="static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="using lock with LTW - missing flag"> + <compile files="LockAspect1.java" options="-1.5"> + <message kind="warning" line="6" text="lock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization"/> + </compile> + <compile files="BasicProgram1.java" options="-1.5"/> + <run class="BasicProgram1" ltw="aop1.xml"> + <stderr> + <!-- warning is something like 'warning at C:\temp\ajcSandbox\ajcTest61975.tmp\LockAspect1.java:6::0 lock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization'/--> + <line text="warning at "/> + <line text="nonstatic method running"/> + <line text="static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="using lock with LTW"> + <compile files="LockAspect1.java" options="-1.5 -Xjoinpoints:synchronization"/> + <compile files="BasicProgram1.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="BasicProgram1" ltw="aop3.xml"> + <stderr> + <line text="weaveinfo Join point 'lock(void java.lang.Object.<lock>(java.lang.Object))' in Type 'BasicProgram1' (BasicProgram1.java:11) advised by before advice from 'LockAspect1' (LockAspect1.java:6)"/> + <line text="weaveinfo Join point 'lock(void java.lang.Object.<lock>(java.lang.Object))' in Type 'BasicProgram1' (BasicProgram1.java:17) advised by before advice from 'LockAspect1' (LockAspect1.java:6)"/> + <line text="Lock advice running at BasicProgram1.java:17"/> + <line text="nonstatic method running"/> + <line text="Lock advice running at BasicProgram1.java:11"/> + <line text="static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="using unlock with LTW"> + <compile files="UnlockAspect1.java" options="-1.5 -Xjoinpoints:synchronization"/> + <compile files="BasicProgram1.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="BasicProgram1" ltw="aop4.xml"> + <stderr> + <line text="weaveinfo Join point 'unlock(void java.lang.Object.<unlock>(java.lang.Object))' in Type 'BasicProgram1' (BasicProgram1.java:11) advised by before advice from 'UnlockAspect1' (UnlockAspect1.java:6)"/> + <line text="weaveinfo Join point 'unlock(void java.lang.Object.<unlock>(java.lang.Object))' in Type 'BasicProgram1' (BasicProgram1.java:17) advised by before advice from 'UnlockAspect1' (UnlockAspect1.java:6)"/> + <line text="nonstatic method running"/> + <line text="Unlock advice running at BasicProgram1.java:17"/> + <line text="static method running"/> + <line text="Unlock advice running at BasicProgram1.java:11"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="using unlock with LTW - missing flag"> + <compile files="UnlockAspect1.java" options="-1.5"> + <message kind="warning" line="6" text="unlock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization"/> + </compile> + <compile files="BasicProgram1.java" options="-1.5"/> + <run class="BasicProgram1" ltw="aop2.xml"> + <stderr> + <line text="warning at "/> + <line text="nonstatic method running"/> + <line text="static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing and matching - unlock and static context"> + <compile files="ParsingAndMatching2.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="ParsingAndMatching2"> + <stderr> + <line text="static method running"/> + <line text="Advice running at ParsingAndMatching2.java:14"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing and matching - lock and non-static context"> + <compile files="ParsingAndMatching3.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="ParsingAndMatching3"> + <stderr> + <line text="Advice running at ParsingAndMatching3.java:15"/> + <line text="non-static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="parsing and matching - unlock and non-static context"> + <compile files="ParsingAndMatching4.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="ParsingAndMatching4"> + <stderr> + <line text="non-static method running"/> + <line text="Advice running at ParsingAndMatching4.java:15"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="a useful program - with lock"> + <compile files="Useful2.java" options="-1.5 -showWeaveInfo -Xjoinpoints:synchronization"> + <message kind="weave" text="Join point 'method-execution(void Useful2.main(java.lang.String[]))' in Type 'Useful2' (Useful2.java:33) advised by afterReturning advice from 'LockMonitor' (Useful2.java:25)"/> + <message kind="weave" text="Join point 'lock(void java.lang.Object.<lock>(java.lang.Object))' in Type 'Useful2' (Useful2.java:42) advised by before advice from 'LockMonitor' (Useful2.java:9) [with runtime test]"/> + <message kind="weave" text="Join point 'unlock(void java.lang.Object.<unlock>(java.lang.Object))' in Type 'Useful2' (Useful2.java:42) advised by after advice from 'LockMonitor' (Useful2.java:14) [with runtime test]"/> + <!-- hope we aren't getting double messages out --> + </compile> + <run class="Useful2"> + <stderr> + <line text="Average time spent with lock over"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="combining pcds - lock and this"> + <compile files="CombiningPCDs1.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="CombiningPCDs1"> + <stderr> + <line text="static method running"/> + <line text="advice running at CombiningPCDs1.java:17"/> + <line text="non-static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="combining pcds - unlock and this"> + <compile files="CombiningPCDs2.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="CombiningPCDs2"> + <stderr> + <line text="static method running"/> + <line text="non-static method running"/> + <line text="advice running at CombiningPCDs2.java:17"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="thisjoinpoint - monitor entry"> + <compile files="ThisJoinPointLock.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="ThisJoinPointLock"> + <stderr> + <line text="match.toString(): lock(lock(Object))"/> + <line text="match.toShortString(): lock(lock(Object))"/> + <line text="match.toLongString(): lock(lock(java.lang.Object))"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="thisjoinpoint - monitor exit"> + <compile files="ThisJoinPointUnlock.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="ThisJoinPointUnlock"> + <stderr> + <line text="match.toString(): unlock(unlock(Object))"/> + <line text="match.toShortString(): unlock(unlock(Object))"/> + <line text="match.toLongString(): unlock(unlock(java.lang.Object))"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="prevent double unlock weaving messages and model contents"> + <compile files="ThisJoinPointUnlock.java" options="-1.5 -Xjoinpoints:synchronization -showWeaveInfo -emacssym"> + <message kind="weave" text="Join point 'lock(void java.lang.Object.<lock>(java.lang.Object))' in Type 'ThisJoinPointUnlock' (ThisJoinPointUnlock.java:38) advised by before advice from 'TJPAspect' (ThisJoinPointUnlock.java:4)"/> + <message kind="weave" text="Join point 'method-call(void ThisJoinPointUnlock.staticMethod())' in Type 'ThisJoinPointUnlock' (ThisJoinPointUnlock.java:39) advised by before advice from 'TJPAspect' (ThisJoinPointUnlock.java:4)"/> + <message kind="weave" text="Join point 'unlock(void java.lang.Object.<unlock>(java.lang.Object))' in Type 'ThisJoinPointUnlock' (ThisJoinPointUnlock.java:38) advised by before advice from 'TJPAspect' (ThisJoinPointUnlock.java:4)"/> + </compile> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="before advice - lock"> + <compile files="BeforeLock.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="BeforeLock"> + <stderr> + <line text="before() lock: advice running at BeforeLock.java:26"/> + <line text="static method running"/> + <line text="before(Foo) lock: advice running at BeforeLock.java:21"/> + <line text="before() lock: advice running at BeforeLock.java:21"/> + <line text="non-static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="before advice - unlock"> + <compile files="BeforeUnlock.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="BeforeUnlock"> + <stderr> + <line text="static method running"/> + <line text="before() unlock: advice running at BeforeUnlock.java:26"/> + <line text="non-static method running"/> + <line text="before(Foo) unlock: advice running at BeforeUnlock.java:21"/> + <line text="before() unlock: advice running at BeforeUnlock.java:21"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="after advice - lock"> + <compile files="AfterLock.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="AfterLock"> + <stderr> + <line text="after() lock: advice running at AfterLock.java:26"/> + <line text="static method running"/> + <line text="after(Foo) lock: advice running at AfterLock.java:21"/> + <line text="after() lock: advice running at AfterLock.java:21"/> + <line text="non-static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="after advice - unlock"> + <compile files="AfterUnlock.java" options="-1.5 -Xjoinpoints:synchronization"/> + <run class="AfterUnlock"> + <stderr> + <line text="static method running"/> + <line text="after() unlock: advice running at AfterUnlock.java:26"/> + <line text="non-static method running"/> + <line text="after(Foo) unlock: advice running at AfterUnlock.java:21"/> + <line text="after() unlock: advice running at AfterUnlock.java:21"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="around advice - lock"> + <compile files="AroundLock.java" options="-1.5 -Xjoinpoints:synchronization"> + <message kind="warning" line="11" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="17" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="31" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="36" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="11" text="advice defined in AroundLock has not been applied [Xlint:adviceDidNotMatch]"/> + <message kind="warning" line="17" text="advice defined in AroundLock has not been applied [Xlint:adviceDidNotMatch]"/> + </compile> + <run class="AroundLock"> + <stderr> + <!--line text="around() lock: advice running at AroundLock.java:26"/--> + <line text="static method running"/> + <!--line text="around(Foo) lock: advice running at AroundLock.java:21"/> + <line text="around() lock: advice running at AroundLock.java:21"/--> + <line text="non-static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="around advice - unlock"> + <compile files="AroundUnlock.java" options="-1.5 -Xjoinpoints:synchronization"> + <message kind="warning" line="5" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="10" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="23" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="28" text="Around advice is not supported on the lock and unlock join points (compiler limitation)"/> + <message kind="warning" line="5" text="advice defined in AroundUnlock has not been applied [Xlint:adviceDidNotMatch]"/> + <message kind="warning" line="10" text="advice defined in AroundUnlock has not been applied [Xlint:adviceDidNotMatch]"/> + </compile> + <run class="AroundUnlock"> + <stderr> + <!--line text="around() unlock: advice running at AroundUnlock.java:26"/--> + <line text="static method running"/> + <!--line text="around(Foo) unlock: advice running at AroundUnlock.java:21"/--> + <!--line text="around() unlock: advice running at AroundUnlock.java:21"/--> + <line text="non-static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="investigation"> + <compile files="Investigation.java"> + </compile> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="One"> + <compile files="One.java -Xjoinpoints:synchronization"> + </compile> + <run class="One"/><!-- will check verification ... --> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="Two"> + <compile files="Two.java -Xjoinpoints:synchronization"> + <message kind="warning" line="14" text="advice matching the synchronized method shadow 'method-execution(void C.ma())' will be executed outside the lock rather than inside (compiler limitation)"/> + </compile> + <run class="Two"> + <stderr> + <line text="execution advice running"/> + <line text="hello"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="Three"> + <compile files="Three.java -Xjoinpoints:synchronization"> + <message kind="warning" line="20" text="advice matching the synchronized method shadow 'method-execution(void C.m3())' will be executed outside the lock rather than inside (compiler limitation)"/> + <message kind="warning" line="24" text="advice matching the synchronized method shadow 'method-execution(void C.m32())' will be executed outside the lock rather than inside (compiler limitation)"/> + </compile> + <run class="Three"> + <stderr> + <line text="hello"/> + <line text="execution advice running"/> + <line text="hello"/> + <line text="execution advice running2"/> + <line text="hello"/> + <line text="execution advice running3"/> + <line text="hello"/> + <line text="execution advice running4"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="Four"> + <compile files="Four.java -Xjoinpoints:synchronization"> + <message kind="warning" line="16" text="advice matching the synchronized method shadow 'method-execution(void C.m())' will be executed outside the lock rather than inside (compiler limitation)"/> + <message kind="warning" line="20" text="advice matching the synchronized method shadow 'method-execution(void C.m2())' will be executed outside the lock rather than inside (compiler limitation)"/> + </compile> + <run class="Four"> + <stderr> + <line text="hello"/> + <line text="execution advice running"/> + <line text="hello"/> + <line text="execution advice running2"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="Five - Java5"> + <compile files="Five.java -1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Five"> + <stderr> + <line text="test"/> + <line text="hello"/> + <line text="test"/> + <line text="hello"/> + <line text="test"/> + <line text="hello"/> + <line text="test"/> + <line text="hello"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="Six - preJava5"> + <compile files="Six.java -Xjoinpoints:synchronization"> + </compile> + <run class="Six"> + <stderr> + <line text="test"/> + <line text="hello"/> + <line text="test"/> + <line text="hello"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="lock pcd on transformed non-static method"> + <compile files="Seven.java -Xjoinpoints:synchronization"> + </compile> + <run class="Seven"> + <stderr> + <line text="Locking occurring at lock(lock(Object))"/> + <line text="Seven.java"/> + <line text="hello"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="unlock pcd on transformed non-static method"> + <compile files="Eight.java -Xjoinpoints:synchronization"> + </compile> + <run class="Eight"> + <stderr> + <line text="hello"/> + <line text="Unlocking occurring at unlock(unlock(Object))"/> + <line text="Eight.java"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="lock pcd on transformed static method - J5"> + <compile files="Nine.java -1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Nine"> + <stderr> + <line text="Locking occurring at lock(lock(Object))"/> + <line text="Nine.java"/> + <line text="hello"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="unlock pcd on transformed static method - J5"> + <compile files="Ten.java -1.5 -Xjoinpoints:synchronization"> + </compile> + <run class="Ten"> + <stderr> + <line text="hello"/> + <line text="Unlocking occurring at unlock(unlock(Object))"/> + <line text="Ten.java"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="lock pcd on transformed static method - preJ5"> + <compile files="Eleven.java -Xjoinpoints:synchronization"> + </compile> + <run class="Eleven"> + <stderr> + <line text="Locking occurring at lock(lock(Object))"/> + <line text="Eleven.java"/> + <line text="hello"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="unlock pcd on transformed static method - preJ5"> + <compile files="Twelve.java" options="-Xjoinpoints:synchronization"> + </compile> + <run class="Twelve"> + <stderr> + <line text="hello"/> + <line text="Unlocking occurring at unlock(unlock(Object))"/> + <line text="Twelve.java"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization" title="obtaining locked object through getArgs"> + <compile files="LockingWithTJP.java" options="-Xjoinpoints:synchronization"> + </compile> + <run class="LockingWithTJP"> + <stderr> + <line text="before() lock: advice running at LockingWithTJP.java:18"/> + <line text="Locked on LockingWithTJP$Foo"/> + <line text="non-static method running"/> + <line text="before() lock: advice running at LockingWithTJP.java:23"/> + <line text="Locked on class java.lang.String"/> + <line text="static method running"/> + </stderr> + </run> + </ajc-test> + + <ajc-test dir="features152/synchronization/transformed" title="other targeters"> + <compile files="OtherTargeters.java" options="-Xjoinpoints:synchronization"> + <message kind="warning" line="8" text="advice matching the synchronized "/> + </compile> + <run class="OtherTargeters"> + <stderr> + <line text="advice running"/> + <line text="foo() running"/> + </stderr> + </run> + </ajc-test> + +</suite> |