[jboss-svn-commits] JBL Code SVN: r28361 - in labs/jbosstm/workspace/adinn/byteman/trunk: tests and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jul 23 15:13:33 EDT 2009


Author: adinn
Date: 2009-07-23 15:13:33 -0400 (Thu, 23 Jul 2009)
New Revision: 28361

Added:
   labs/jbosstm/workspace/adinn/byteman/trunk/tests/dd/scripts/bugfixes/TestEnclosedSynchronizationPropagation.txt
   labs/jbosstm/workspace/adinn/byteman/trunk/tests/src/org/jboss/byteman/tests/bugfixes/TestEnclosedSynchronizationPropagation.java
Modified:
   labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/adapter/cfg/BBlock.java
   labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/adapter/cfg/CFG.java
   labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/adapter/cfg/CodeLocation.java
   labs/jbosstm/workspace/adinn/byteman/trunk/tests/build.xml
Log:
fixed problem in propagation of synchronization starts to enclosd try catch blocks and added test for it -- fixes BYTEMAN-15

Modified: labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/adapter/cfg/BBlock.java
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/adapter/cfg/BBlock.java	2009-07-23 19:09:19 UTC (rev 28360)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/adapter/cfg/BBlock.java	2009-07-23 19:13:33 UTC (rev 28361)
@@ -443,9 +443,10 @@
      */
     void printTo(StringBuffer buf)
     {
+        int blockIdx = this.getBlockIdx();
         buf.append(this.getLabel().getOffset());
         buf.append(": BB ");
-        buf.append(this.getBlockIdx());
+        buf.append(blockIdx);
         buf.append("\n");
         Link containsLink = cfg.getContains(this);
         Iterator<Label> containsIter;
@@ -553,7 +554,11 @@
                 containedLabel = (containsIter.hasNext() ? containsIter.next() : null);
                 containedPosition = (containedLabel != null ? cfg.getBlockInstructionIdx(containedLabel) : -1);
             }
-            buf.append("   ");
+            // buf.append("   ");
+            buf.append(blockIdx);
+            buf.append(".");
+            buf.append(i);
+            buf.append(": ");
             int opcode = this.getInstruction(i);
             switch (OpcodesHelper.insnType(opcode)) {
                 case OpcodesHelper.INSN_NONE:

Modified: labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/adapter/cfg/CFG.java
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/adapter/cfg/CFG.java	2009-07-23 19:09:19 UTC (rev 28360)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/adapter/cfg/CFG.java	2009-07-23 19:13:33 UTC (rev 28361)
@@ -624,16 +624,18 @@
         }
 
         // any left over values are still open
+        // n.b. the lists are now in reverse order so we use addFirst to put them back in
+        // source code order
         
-        List<CodeLocation> newOpenEnters = new LinkedList<CodeLocation>();
+        LinkedList<CodeLocation> newOpenEnters = new LinkedList<CodeLocation>();
 
         while (entersIter.hasNext()) {
-            newOpenEnters.add(entersIter.next());
+            newOpenEnters.addFirst(entersIter.next());
         }
 
         if (openEntersIter != null) {
             while (openEntersIter.hasNext()) {
-                newOpenEnters.add(openEntersIter.next());
+                newOpenEnters.addFirst(openEntersIter.next());
             }
         }
 
@@ -706,7 +708,7 @@
                     // try start is after the enter -- now see where the corresponding exit is
 
                     CodeLocation exit = getPairedExit(enter);
-                    if (exit != null && tryStart.compareTo(exit) <= 0) {
+                    if (exit == null || tryStart.compareTo(exit) <= 0) {
                         // open is in scope of try catch so attach it to the try start
                         details.addOpenEnter(enter);
                     }
@@ -732,7 +734,7 @@
                     // try start is after the enter -- now see where the corresponding exit is
 
                     CodeLocation exit = getPairedExit(enter);
-                    if (exit != null && tryStart.compareTo(exit) <= 0) {
+                    if (exit == null || tryStart.compareTo(exit) <= 0) {
                         // open is in scope of try catch so attach it to the try start
                         details.addOpenEnter(enter);
                     }

Modified: labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/adapter/cfg/CodeLocation.java
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/adapter/cfg/CodeLocation.java	2009-07-23 19:09:19 UTC (rev 28360)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/adapter/cfg/CodeLocation.java	2009-07-23 19:13:33 UTC (rev 28361)
@@ -55,7 +55,7 @@
 
     public String toString()
     {
-        return "B" + block.getBlockIdx() + "." + getInstructionIdx();
+        return "BB" + block.getBlockIdx() + "." + getInstructionIdx();
     }
 
     public int compareTo(CodeLocation loc)

Modified: labs/jbosstm/workspace/adinn/byteman/trunk/tests/build.xml
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/tests/build.xml	2009-07-23 19:09:19 UTC (rev 28360)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/tests/build.xml	2009-07-23 19:13:33 UTC (rev 28361)
@@ -365,28 +365,50 @@
     </target>
 
     <target name="tests.bugfixes">
-          <junit fork="true" showoutput="true">
-            <classpath>
-                <pathelement location="${build.lib.dir}/byteman-tests.jar"/>
-                <pathelement location="${junit.home}/${junit.jar}"/>
-            </classpath>
-            <jvmarg value="-javaagent:${byteman.home}/${byteman.jar}=script:${scripts.dir}/bugfixes/TestEmptySignature.txt"/>
-            <!-- uncomment for verbose byteman output
-            <jvmarg value="-Dorg.jboss.byteman.verbose"/>
-            -->
-            <!-- uncomment to dump generated code
-            <jvmarg value="-Dorg.jboss.byteman.dump.generated.classes"/>
-            <jvmarg value="-Dorg.jboss.byteman.dump.generated.classes.directory=dump"/>
-            -->
-            <!-- uncomment to enable debug
-            <jvmarg value="-Xdebug"/>
-            <jvmarg  value="-Xnoagent"/>
-            <jvmarg  value="-Djava.compiler=NONE"/>
-            <jvmarg  value="-Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=5005"/>
-            -->
-            <test name="org.jboss.byteman.tests.bugfixes.TestEmptySignature"/>
+        <junit fork="true" showoutput="true">
+          <classpath>
+              <pathelement location="${build.lib.dir}/byteman-tests.jar"/>
+              <pathelement location="${junit.home}/${junit.jar}"/>
+          </classpath>
+          <jvmarg value="-javaagent:${byteman.home}/${byteman.jar}=script:${scripts.dir}/bugfixes/TestEmptySignature.txt"/>
+          <!-- uncomment for verbose byteman output
+          <jvmarg value="-Dorg.jboss.byteman.verbose"/>
+          -->
+          <!-- uncomment to dump generated code
+          <jvmarg value="-Dorg.jboss.byteman.dump.generated.classes"/>
+          <jvmarg value="-Dorg.jboss.byteman.dump.generated.classes.directory=dump"/>
+          -->
+          <!-- uncomment to enable debug
+          <jvmarg value="-Xdebug"/>
+          <jvmarg  value="-Xnoagent"/>
+          <jvmarg  value="-Djava.compiler=NONE"/>
+          <jvmarg  value="-Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=5005"/>
+          -->
+          <test name="org.jboss.byteman.tests.bugfixes.TestEmptySignature"/>
         </junit>
+        <junit fork="true" showoutput="true">
+          <classpath>
+              <pathelement location="${build.lib.dir}/byteman-tests.jar"/>
+              <pathelement location="${junit.home}/${junit.jar}"/>
+          </classpath>
+          <jvmarg value="-javaagent:${byteman.home}/${byteman.jar}=script:${scripts.dir}/bugfixes/TestEnclosedSynchronizationPropagation.txt"/>
+          <!-- uncomment for verbose byteman output
+          <jvmarg value="-Dorg.jboss.byteman.verbose"/>
+          -->
+          <!-- uncomment to dump generated code
+          <jvmarg value="-Dorg.jboss.byteman.dump.generated.classes"/>
+          <jvmarg value="-Dorg.jboss.byteman.dump.generated.classes.directory=dump"/>
+          -->
+          <!-- uncomment to enable debug
+          <jvmarg value="-Xdebug"/>
+          <jvmarg  value="-Xnoagent"/>
+          <jvmarg  value="-Djava.compiler=NONE"/>
+          <jvmarg  value="-Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=5005"/>
+          -->
+          <test name="org.jboss.byteman.tests.bugfixes.TestEnclosedSynchronizationPropagation"/>
+        </junit>
   </target>
+
     <target name="tests.bugfixes.compiled">
           <junit fork="true" showoutput="true">
             <classpath>
@@ -410,5 +432,31 @@
             -->
             <test name="org.jboss.byteman.tests.bugfixes.TestEmptySignature"/>
         </junit>
+        <junit fork="true" showoutput="true">
+          <classpath>
+              <pathelement location="${build.lib.dir}/byteman-tests.jar"/>
+              <pathelement location="${junit.home}/${junit.jar}"/>
+          </classpath>
+          <jvmarg value="-javaagent:${byteman.home}/${byteman.jar}=script:${scripts.dir}/bugfixes/TestEnclosedSynchronizationPropagation.txt"/>
+          <jvmarg value="-Dorg.jboss.byteman.compileToBytecode"/>
+          <!-- uncomment for verbose byteman output
+          <jvmarg value="-Dorg.jboss.byteman.verbose"/>
+          -->
+            <!-- uncomment for cfg output
+              <jvmarg value="-Dorg.jboss.byteman.dump.cfg.partial"/>
+            -->
+          <!-- uncomment to dump generated code
+          <jvmarg value="-Dorg.jboss.byteman.dump.generated.classes"/>
+          <jvmarg value="-Dorg.jboss.byteman.dump.generated.classes.directory=dump"/>
+          -->
+          <!-- uncomment to enable debug
+          <jvmarg value="-Xdebug"/>
+          <jvmarg  value="-Xnoagent"/>
+          <jvmarg  value="-Djava.compiler=NONE"/>
+          <jvmarg  value="-Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=5005"/>
+          -->
+          <test name="org.jboss.byteman.tests.bugfixes.TestEnclosedSynchronizationPropagation"/>
+      </junit>
   </target>
+
 </project>

Copied: labs/jbosstm/workspace/adinn/byteman/trunk/tests/dd/scripts/bugfixes/TestEnclosedSynchronizationPropagation.txt (from rev 27343, labs/jbosstm/workspace/adinn/byteman/trunk/tests/dd/scripts/bugfixes/TestEmptySignature.txt)
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/tests/dd/scripts/bugfixes/TestEnclosedSynchronizationPropagation.txt	                        (rev 0)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/tests/dd/scripts/bugfixes/TestEnclosedSynchronizationPropagation.txt	2009-07-23 19:13:33 UTC (rev 28361)
@@ -0,0 +1,34 @@
+##############################################################################
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+#
+# @authors Andrew Dinn
+#
+# Test for BYTEMAN-15.
+
+RULE test enclosed synchronization propagation
+CLASS TestEnclosedSynchronizationPropagation
+METHOD test
+HELPER org.jboss.byteman.tests.helpers.Default
+AFTER CALL testAuxiliary()
+BIND NOTHING
+IF TRUE
+DO System.out.println("AFTER CALL testAuxiliary()")
+ENDRULE

Added: labs/jbosstm/workspace/adinn/byteman/trunk/tests/src/org/jboss/byteman/tests/bugfixes/TestEnclosedSynchronizationPropagation.java
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/tests/src/org/jboss/byteman/tests/bugfixes/TestEnclosedSynchronizationPropagation.java	                        (rev 0)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/tests/src/org/jboss/byteman/tests/bugfixes/TestEnclosedSynchronizationPropagation.java	2009-07-23 19:13:33 UTC (rev 28361)
@@ -0,0 +1,59 @@
+package org.jboss.byteman.tests.bugfixes;
+
+import junit.framework.TestCase;
+
+/**
+ * test that propagation of open sychronizations to try catch blocks is done correctly. this manifested an error
+ * identified by JIRA BYTEMAN-15
+ *
+ * The error happens when a try catch nested in a synchronized block follows another nested synchronized block
+ * as happens in case 2 in the following switch. The algorithm was reversing the order of the code locations
+ * for the inner and outer synchronized blocks and the deciding that the monitorexit in the catch block applied
+ * to the outer syncrhonization not the inner one. Thsi subsequently causes the catch block to have the wrong
+ * open monitor enter count, tripping warning trace in the control flow graph. This does not appear to cause any
+ * error in the trigger insertion.
+ */
+public class TestEnclosedSynchronizationPropagation extends TestCase
+{
+    public TestEnclosedSynchronizationPropagation() {
+        super(TestEnclosedSynchronizationPropagation.class.getCanonicalName());
+    }
+    private static Object lock1 = new Object();
+    private static Object lock2 = new Object();
+    public static boolean alwaysFalse = false;
+
+    public void test()
+    {
+        int value = 1;
+        
+        synchronized(lock1) {
+            boolean result = true;
+            switch(value) {
+                case 1:
+                {
+                    break;
+                }
+                case 2:
+                    synchronized(lock2) {
+                    }
+                    try {
+                        result = testAuxiliary();
+                    } catch (Exception e) {
+                        System.out.println(e);
+                    }
+                    break;
+                default:
+                    System.out.println("unexpected value " + value);
+                    break;
+            }
+        }
+    }
+    
+    public boolean testAuxiliary() throws Exception
+    {
+        if (alwaysFalse) {
+            throw new Exception("shouldn't");
+        }
+        return true;
+    }
+}



More information about the jboss-svn-commits mailing list