[jboss-svn-commits] JBL Code SVN: r26869 - in labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/byteman/agent/adapter: cfg and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jun 8 05:01:22 EDT 2009


Author: adinn
Date: 2009-06-08 05:01:21 -0400 (Mon, 08 Jun 2009)
New Revision: 26869

Modified:
   labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/byteman/agent/adapter/RuleTriggerMethodAdapter.java
   labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/byteman/agent/adapter/cfg/CFG.java
Log:
undid code relocation from previous commit as it introduced some other errors and needs revisiting

Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/byteman/agent/adapter/RuleTriggerMethodAdapter.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/byteman/agent/adapter/RuleTriggerMethodAdapter.java	2009-06-08 08:53:21 UTC (rev 26868)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/byteman/agent/adapter/RuleTriggerMethodAdapter.java	2009-06-08 09:01:21 UTC (rev 26869)
@@ -206,11 +206,9 @@
                 // add this instruction to the current block and then start a new current block
                 cfg.add(opcode);
                 Label newStart = super.newLabel();
-                Iterator<CodeLocation> exits = cfg.currentExits();
                 // must call split before visiting the label
                 cfg.split(newStart);
                 visitLabel(newStart);
-                checkMonitorExits(exits);
             }
             break;
             case Opcodes.MONITORENTER:
@@ -302,11 +300,9 @@
                 // the second out
                 cfg.add(opcode);
                 Label newStart = super.newLabel();
-                Iterator<CodeLocation> exits = cfg.currentExits();
                 // must call split before visiting the label
                 cfg.split(newStart, label, newStart);
                 visitLabel(newStart);
-                checkMonitorExits(exits);
             }
             break;
             case Opcodes.GOTO:
@@ -315,11 +311,9 @@
                 // first out of the old current block
                 cfg.add(opcode);
                 Label newStart = super.newLabel();
-                Iterator<CodeLocation> exits = cfg.currentExits();
                 // must call split before visiting the label
                 cfg.split(newStart, label);
                 visitLabel(newStart);
-                checkMonitorExits(exits);
             }
             break;
             case Opcodes.JSR:
@@ -329,11 +323,9 @@
                 // JSR but we cannot represent that statically
                 cfg.add(opcode);
                 Label newStart = super.newLabel();
-                Iterator<CodeLocation> exits = cfg.currentExits();
                 // must call split before visiting the label
                 cfg.split(newStart, label, newStart);
                 visitLabel(newStart);
-                checkMonitorExits(exits);
             }
             break;
             case Opcodes.IFNULL:
@@ -344,11 +336,9 @@
                 // the second out
                 cfg.add(opcode);
                 Label newStart = super.newLabel();
-                Iterator<CodeLocation> exits = cfg.currentExits();
                 // must call split before visiting the label
                 cfg.split(newStart, label, newStart);
                 visitLabel(newStart);
-                checkMonitorExits(exits);
             }
             break;
         }
@@ -433,11 +423,9 @@
         // create a new current block and then add the default lable and each of the switch labels as an
         // outgoing path from the current block
         Label newStart = super.newLabel();
-        Iterator<CodeLocation> exits = cfg.currentExits();
         // must call split before visiting the label
         cfg.split(newStart, dflt, labels);
         visitLabel(newStart);
-        checkMonitorExits(exits);
     }
 
     @Override
@@ -448,11 +436,9 @@
         // create a new current block and then add the default lable and each of the switch labels as an
         // outgoing path from the current block
         Label newStart = super.newLabel();
-        Iterator<CodeLocation> exits = cfg.currentExits();
         // must call split before visiting the label
         cfg.split(newStart, dflt, labels);
         visitLabel(newStart);
-        checkMonitorExits(exits);
     }
 
     @Override
@@ -474,79 +460,71 @@
         cfg.visitTryCatchBlock(start, end, handler, type);
     }
 
-    public void checkMonitorExits(Iterator<CodeLocation> exits)
+    @Override
+    public void visitMaxs(int maxStack, int maxLocals)
     {
-        while (exits.hasNext()) {
-            CodeLocation exit = exits.next();
-            if (cfg.isPrimaryExit(exit)) {
-                CodeLocation enter = cfg.pairedEnter(exit);
+        Type returnType =  Type.getReturnType(descriptor);
 
-                // we just closed a monitor open so find any pending triggers in its scope
-                // and generate a handler block to rethrow its exceptions
+        // check whether there are outstanding monitor opens at the start of the trigger
+        // block and, if so, insert a handler which unlocks the monitor and then rethrows
+        // the exception.
 
-                Iterator<TriggerDetails> iterator = cfg.triggerDetails();
-                boolean noneLeft = true;
+        Iterator<TriggerDetails> iterator = cfg.triggerDetails();
+        boolean noneLeft = true;
 
-                while (iterator.hasNext()) {
-                    TriggerDetails details = iterator.next();
-                    Label startLabel = details.getStart();
-                    CodeLocation startLocation = cfg.getLocation(startLabel);
-                    // if the trigger start label is after the enter and before the exit
-                    // then we need to generate a handler block for it now which exits the
-                    // monitor and then rethrows the exception
-                    if (enter.compareTo(startLocation) <= 0 && startLocation.compareTo(exit) <= 0) {
-                        // add a handler here which unlocks each object and rethrows the
-                        // saved exception then protect it with a try catch block and update
-                        // the details so that it is the target of this block
+        while (iterator.hasNext()) {
+            TriggerDetails details = iterator.next();
+            Label startLabel = details.getStart();
+            CodeLocation startLocation = cfg.getLocation(startLabel);
+            List<CodeLocation> openEnters = cfg.getOpenMonitors(startLocation);
+            if (openEnters != null) {
+                // add a handler here which unlocks each object and rethrows the
+                // saved exception then protect it with a try catch block and update
+                // the details so that it is the target of this block
 
-                        // make the old exceptions arrive here
-                        visitLabel(details.getExecuteHandler());
-                        visitLabel(details.getEarlyReturnHandler());
-                        visitLabel(details.getThrowHandler());
-                        // now add a rethrow handler which exits the open monitors
-                        Label newStart = newLabel();
-                        Label newEnd = newLabel();
-                        visitLabel(newStart);
-                        int varIdx = cfg.getSavedMonitorIdx(enter);
-                        visitVarInsn(Opcodes.ALOAD, varIdx);
-                        visitInsn(Opcodes.MONITOREXIT);
-                        // throw must be in scope of the try catch
-                        visitInsn(Opcodes.ATHROW);
-
-                        // add try catch blocks for each of the exception types
-                        Label newExecute = newLabel();
-                        Label newEarlyReturn = newLabel();
-                        Label newThrow = newLabel();
-
-                        visitTryCatchBlock(newStart, newEnd, newEarlyReturn, EARLY_RETURN_EXCEPTION_TYPE_NAME);
-                        visitTryCatchBlock(newStart, newEnd, newThrow, THROW_EXCEPTION_TYPE_NAME);
-                        // this comes last because it is the superclass of the previous two
-                        visitTryCatchBlock(newStart, newEnd, newExecute, EXECUTE_EXCEPTION_TYPE_NAME);
-                        // now visit label so they get processed
-                        visitLabel(newEnd);
-                        
-                        // and update the details so it will catch these exceptions
-                        details.setStart(newStart);
-                        details.setEnd(newEnd);
-                        details.setExecuteHandler(newExecute);
-                        details.setEarlyReturnHandler(newEarlyReturn);
-                        details.setThrowHandler(newThrow);
-                    }
+                Label newStart = newLabel();
+                Label newEnd = newLabel();
+                Label newExecute = newLabel();
+                Label newEarlyReturn = newLabel();
+                Label newThrow = newLabel();
+                // make the old exceptions arrive here
+                visitLabel(details.getExecuteHandler());
+                visitLabel(details.getEarlyReturnHandler());
+                visitLabel(details.getThrowHandler());
+                // now add a rethrow handler which exits the open monitors
+                visitLabel(newStart);
+                int listIdx = openEnters.size();
+                while (listIdx-- > 0) {
+                    CodeLocation enterLocation = openEnters.get(listIdx);
+                    int varIdx = cfg.getSavedMonitorIdx(enterLocation);
+                    // call super method to avoid indexing these instructions
+                    visitVarInsn(Opcodes.ALOAD, varIdx);
+                    visitInsn(Opcodes.MONITOREXIT);
                 }
-
-
+                // throw must be in scope of the try catch
+                // call super method to avoid creating new blocks
+                visitInsn(Opcodes.ATHROW);
+                // add try catch blocks for each of the exception types
+                visitTryCatchBlock(newStart, newEnd, newEarlyReturn, EARLY_RETURN_EXCEPTION_TYPE_NAME);
+                visitTryCatchBlock(newStart, newEnd, newThrow, THROW_EXCEPTION_TYPE_NAME);
+                // this comes last because it is the superclass of the previous two
+                visitTryCatchBlock(newStart, newEnd, newExecute, EXECUTE_EXCEPTION_TYPE_NAME);
+                // now visit label so they get processed
+                visitLabel(newEnd);
+                // and update the details so it will catch these exceptions
+                details.setStart(newStart);
+                details.setEnd(newEnd);
+                details.setExecuteHandler(newExecute);
+                details.setEarlyReturnHandler(newEarlyReturn);
+                details.setThrowHandler(newThrow);
             }
         }
-    }
 
-    @Override
-    public void visitMaxs(int maxStack, int maxLocals)
-    {
-        // ok, so now we have to add the real handler code for trigger block try catch handlers
+        // ok, so now we have to add the handler code for trigger block try catch handlers
         // we only need to add the handler code once but we need to make sure it is the target of
         //  all the try catch blocks by visiting their handler label before we insert the code
 
-        Iterator<TriggerDetails> iterator = cfg.triggerDetails();
+        iterator = cfg.triggerDetails();
 
         while (iterator.hasNext()) {
             TriggerDetails details = iterator.next();

Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/byteman/agent/adapter/cfg/CFG.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/byteman/agent/adapter/cfg/CFG.java	2009-06-08 08:53:21 UTC (rev 26868)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/byteman/agent/adapter/cfg/CFG.java	2009-06-08 09:01:21 UTC (rev 26869)
@@ -742,47 +742,6 @@
     }
 
     /**
-     * return an iterator over the monitor exit locations for the current block
-     * 
-     * @return
-     */
-    public Iterator<CodeLocation> currentExits() {
-        return current.getMonitorExits();
-    }
-
-    /**
-     * return true if a location is the first monitor exit associated with a corresponding monitor enter
-     * otherwise return false
-     * @param exit the code location which should identify a MONITOREXIT instruction
-     * @return
-     */
-    public boolean isPrimaryExit(CodeLocation exit)
-    {
-        CodeLocation enter = inverseMonitorPairs.get(exit);
-        if (enter == null) {
-            // hmm, this is not a monitor exit
-            System.out.println("cfg.isPrimaryExit : location is not a monitor exit " + exit);
-            return false;
-        }
-
-        List<CodeLocation> pairs = monitorPairs.get(enter);
-        if (pairs == null && pairs.size() == 0) {
-            System.out.println("cfg.isPrimaryExit : location is not a monitor enter " + enter);
-            return false;
-        }
-        return pairs.get(0) == exit;
-    }
-
-    /**
-     * return the location oif the enter instrution paired with a given exit
-     * @param exit the code location which should identify a MONITOREXIT instruction
-     * @return
-     */
-    public CodeLocation pairedEnter(CodeLocation exit)
-    {
-        return inverseMonitorPairs.get(exit);
-    }
-    /**
      * split the graph at a control-flow dead-end using the label provided to identify the new current
      * block. the caller is obliged to call visitLabel immediately after calling this method to ensure
      * that the current block label is indexed appropriately.




More information about the jboss-svn-commits mailing list