]> source.dussan.org Git - aspectj.git/commitdiff
fix for problem with transform of static synchronized method on pre Java5.
authoraclement <aclement>
Thu, 3 Aug 2006 07:53:27 +0000 (07:53 +0000)
committeraclement <aclement>
Thu, 3 Aug 2006 07:53:27 +0000 (07:53 +0000)
tests/src/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java
tests/src/org/aspectj/systemtest/ajc152/synchronization.xml
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java

index ec4c1280a88ac80dd5a1300998a000cd99a1aba9..92785bfef5608092e1b73daaf8e994e0c7bcaef1 100644 (file)
@@ -178,6 +178,15 @@ public class SynchronizationTransformTests extends XMLBasedAjcTestCase {
     public void testTransformWithLTW() {
        runTest("transform with LTW");
     }
+    
+
+    public void testTransformStaticMethodPreJava5() {
+       runTest("transform static method - preJ5");
+    }
+
+    public void testTransformStaticMethodPreJava5_2() {
+       runTest("transform static method - packages - preJ5");
+    }
 
     // more complex code sequences...
     public void testOtherTargeters() {
index 8b4a7ed475224e96f291fdea12aa253de38e4a1f..2803a16225359e9e43bfdae2ca8386810ecb3bd9 100644 (file)
       </run>
     </ajc-test>
     
+    
+    <ajc-test dir="features152/synchronization/transformed" title="transform static method - preJ5">
+      <compile files="Fifteen.java" options="-Xjoinpoints:synchronization -1.4">
+      </compile>
+      <run class="Fifteen">
+        <stderr>
+          <line text="Locking occurring at lock(lock(Object))"/>
+          <line text="Fifteen.java"/>
+          <line text="hello"/>
+        </stderr>
+      </run>
+    </ajc-test>
+    
+    
+    <ajc-test dir="features152/synchronization/transformed" title="transform static method - packages - preJ5">
+      <compile files="Sixteen.java" options="-Xjoinpoints:synchronization -1.4">
+      </compile>
+      <run class="a.b.c.d.Sixteen">
+        <stderr>
+          <line text="Locking occurring at lock(lock(Object))"/>
+          <line text="Sixteen.java"/>
+          <line text="hello"/>
+        </stderr>
+      </run>
+    </ajc-test>
+    
     <ajc-test dir="features152/synchronization" title="obtaining locked object through getArgs">
       <compile files="LockingWithTJP.java" options="-Xjoinpoints:synchronization">
       </compile>
index a7cece45e47185399daf27b97f94329a8895a3b4..623bfb3360da9b1c5ea1f32b1feed53f73622122 100644 (file)
@@ -1610,7 +1610,6 @@ class BcelClassWeaver implements IClassWeaver {
                        parttwo.append(InstructionFactory.MONITORENTER);
                
                        String fieldname = synchronizedMethod.getEnclosingClass().allocateField("class$");
-                       System.err.println("Going to use field name "+fieldname);
                        Field f = new FieldGen(Modifier.STATIC | Modifier.PRIVATE,
                                    Type.getType(Class.class),fieldname,synchronizedMethod.getEnclosingClass().getConstantPoolGen()).getField();
                        synchronizedMethod.getEnclosingClass().addField(f, null);
@@ -1625,12 +1624,14 @@ class BcelClassWeaver implements IClassWeaver {
 //                     25:  invokevirtual   #52; //Method java/lang/Throwable.getMessage:()Ljava/lang/String;
 //                     28:  invokespecial   #54; //Method java/lang/NoClassDefFoundError."<init>":(Ljava/lang/String;)V
 //                     31:  athrow
-                       prepend.append(fact.createGetStatic("C", fieldname, Type.getType(Class.class)));
+                       String name = synchronizedMethod.getEnclosingClass().getName();
+                       
+                       prepend.append(fact.createGetStatic(name, fieldname, Type.getType(Class.class)));
                        prepend.append(InstructionFactory.createDup(1));
                        prepend.append(InstructionFactory.createBranchInstruction(Constants.IFNONNULL, parttwo.getStart()));
                        prepend.append(InstructionFactory.POP);
                        
-                       prepend.append(fact.createConstant("C"));
+                       prepend.append(fact.createConstant(name));
                        InstructionHandle tryInstruction = prepend.getEnd();
                        prepend.append(fact.createInvoke("java.lang.Class", "forName", clazzType,new Type[]{ Type.getType(String.class)}, Constants.INVOKESTATIC));
                        InstructionHandle catchInstruction = prepend.getEnd();