[jboss-svn-commits] JBL Code SVN: r24398 - in labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration: agent/adapter and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Dec 17 06:58:50 EST 2008


Author: adinn
Date: 2008-12-17 06:58:49 -0500 (Wed, 17 Dec 2008)
New Revision: 24398

Modified:
   labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Main.java
   labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java
   labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/AccessTriggerAdapter.java
   labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/InvokeTriggerAdapter.java
   labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/LineTriggerAdapter.java
   labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/SynchronizeTriggerAdapter.java
   labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java
Log:
Defined System property org.jboss.jbossts.orchestration.verbose
which can be set on the JVM command line (using -D) to enable display
of trace messages generated by the rule agent and the rule execution
engine.

Modified transformer to cache the value of thsis flag at bootstrap and
made all current verbose output from the agent and execution engine
conditional upon the flag being set.

Fixed problem which led to NullPointerException when rule location was
defaulted to AT ENTRY (location object attached to rule was null)

Fixed problem with AT ENTRY and AT LINE locations whcih caused a
NullPointerException when generating the transformed bytecode for a
constructor method (trigger call was nto being generated which caused
the bytecode writer to trip up on a catch block with no start and end
labels)


Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Main.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Main.java	2008-12-17 10:37:46 UTC (rev 24397)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Main.java	2008-12-17 11:58:49 UTC (rev 24398)
@@ -73,7 +73,9 @@
 
         for (String scriptPath : scriptPaths) {
             try {
-                System.out.println("processing script file " + scriptPath);
+                if (Transformer.isVerbose()) {
+                    System.out.println("processing script file " + scriptPath);
+                }
 
                 FileInputStream fis = new FileInputStream(scriptPath);
                 byte[] bytes = new byte[fis.available()];

Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java	2008-12-17 10:37:46 UTC (rev 24397)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java	2008-12-17 11:58:49 UTC (rev 24398)
@@ -117,18 +117,23 @@
                                 scripts = new ArrayList<Script>();
                                 targetToScriptMap.put(targetClass, scripts);
                             }
+                            if (targetLocation == null) {
+                                targetLocation = Location.create(LocationType.ENTRY, "");
+                            }
                             Script script = new Script(name, targetClass, targetMethod, targetLocation, nextRule);
                             scripts.add(script);
-                            System.out.println("RULE " + script.getName());
-                            System.out.println("CLASS " + script.getTargetClass());
-                            System.out.println("METHOD " + script.getTargetMethod());
-                            if (targetLocation != null) {
-                                System.out.println(targetLocation);
-                            } else {
-                                System.out.println("AT ENTRY");
+                            if (isVerbose()) {
+                                System.out.println("RULE " + script.getName());
+                                System.out.println("CLASS " + script.getTargetClass());
+                                System.out.println("METHOD " + script.getTargetMethod());
+                                if (targetLocation != null) {
+                                    System.out.println(targetLocation);
+                                } else {
+                                    System.out.println("AT ENTRY");
+                                }
+                                System.out.println(script.getRuleText());
+                                System.out.println("ENDRULE");
                             }
-                            System.out.println(script.getRuleText());
-                            System.out.println("ENDRULE");
                         }
                         name = null;
                         targetClass = null;
@@ -276,6 +281,11 @@
     private static final String ORCHESTRATION_PACKAGE_PREFIX = "org.jboss.jbossts.orchestration.";
 
     /**
+     * prefix for orchestration test package
+     */
+    private static final String ORCHESTRATION_TEST_PACKAGE_PREFIX = "org.jboss.jbossts.orchestration.test.";
+
+    /**
      * prefix for com.arjuna package
      */
     private static final String COM_ARJUNA_PACKAGE_PREFIX = "com.arjuna.";
@@ -293,6 +303,11 @@
     /**
      * system property set (to any value) in order to switch on dumping of generated bytecode to .class files
      */
+    public static final String VERBOSE = ORCHESTRATION_PACKAGE_PREFIX + "verbose";
+
+    /**
+     * system property set (to any value) in order to switch on dumping of generated bytecode to .class files
+     */
     public static final String DUMP_GENERATED_CLASSES = ORCHESTRATION_PACKAGE_PREFIX + "dump.generated.classes";
 
     /* implementation */
@@ -307,10 +322,12 @@
         final String handlerClass = script.getTargetClass();
         final String handlerMethod = script.getTargetMethod();
         final Location handlerLocation = script.getTargetLocation();
-        System.out.println("org.jboss.jbossts.orchestration.agent.Transformer : Inserting trigger event");
-        System.out.println("  class " + handlerClass);
-        System.out.println("  method " + handlerMethod);
-        System.out.println("  " + handlerLocation);
+        if (isVerbose()) {
+            System.out.println("org.jboss.jbossts.orchestration.agent.Transformer : Inserting trigger event");
+            System.out.println("  class " + handlerClass);
+            System.out.println("  method " + handlerMethod);
+            System.out.println("  " + handlerLocation);
+        }
         final Rule rule;
         String ruleName = script.getName();
         try {
@@ -374,10 +391,19 @@
      */
     private boolean isOrchestrationClass(String className)
     {
-        return className.startsWith(ORCHESTRATION_PACKAGE_PREFIX);
+        return className.startsWith(ORCHESTRATION_PACKAGE_PREFIX) && !className.startsWith(ORCHESTRATION_TEST_PACKAGE_PREFIX);
     }
 
     /**
+     * check whether verbose mode for rule processing is enabled or disable
+     * @return true if verbose mode is enabled etherwise false
+     */
+    public static boolean isVerbose()
+    {
+        return verbose;
+    }
+
+    /**
      * test whether a class with a given name is a potential candidate for insertion of event notifications
      * @param className
      * @return true if a class is a potential candidate for insertion of event notifications otherwise return false
@@ -407,6 +433,11 @@
     private final HashMap<String, List<Script>> targetToScriptMap;
 
     /**
+     *  switch to control verbose output during rule processing
+     */
+    private final static boolean verbose = (System.getProperty(VERBOSE) != null);
+
+    /**
      *  switch to control dumping of generated bytecode to .class files
      */
     private final static boolean dumpGeneratedClasses = (System.getProperty(DUMP_GENERATED_CLASSES) != null);

Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/AccessTriggerAdapter.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/AccessTriggerAdapter.java	2008-12-17 10:37:46 UTC (rev 24397)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/AccessTriggerAdapter.java	2008-12-17 11:58:49 UTC (rev 24398)
@@ -26,6 +26,7 @@
 import org.jboss.jbossts.orchestration.rule.Rule;
 import org.jboss.jbossts.orchestration.rule.type.TypeHelper;
 import org.jboss.jbossts.orchestration.agent.Location;
+import org.jboss.jbossts.orchestration.agent.Transformer;
 import org.objectweb.asm.*;
 import org.objectweb.asm.commons.GeneratorAdapter;
 import org.objectweb.asm.commons.Method;
@@ -56,7 +57,7 @@
     {
         MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
         if (matchTargetMethod(name, desc)) {
-            if (name == "<init>") {
+            if (name.equals("<init>")) {
                 return new AccessTriggerConstructorAdapter(mv, access, name, desc, signature, exceptions);
             } else {
                 return new AccessTriggerMethodAdapter(mv, access, name, desc, signature, exceptions);
@@ -119,7 +120,9 @@
                     Type ruleType = Type.getType(TypeHelper.externalizeType("org.jboss.jbossts.orchestration.rule.Rule"));
                     Method method = Method.getMethod("void execute(String, Object, Object[])");
                     // we are at the relevant line in the method -- so add a trigger call here
-                    System.out.println("AccessTriggerMethodAdapter.visitFieldInsn : inserting trigger for " + rule.getName());
+                    if (Transformer.isVerbose()) {
+                        System.out.println("AccessTriggerMethodAdapter.visitFieldInsn : inserting trigger for " + rule.getName());
+                    }
                     startLabel = super.newLabel();
                     endLabel = super.newLabel();
                     super.visitLabel(startLabel);

Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/InvokeTriggerAdapter.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/InvokeTriggerAdapter.java	2008-12-17 10:37:46 UTC (rev 24397)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/InvokeTriggerAdapter.java	2008-12-17 11:58:49 UTC (rev 24398)
@@ -25,6 +25,7 @@
 
 import org.jboss.jbossts.orchestration.rule.Rule;
 import org.jboss.jbossts.orchestration.rule.type.TypeHelper;
+import org.jboss.jbossts.orchestration.agent.Transformer;
 import org.objectweb.asm.*;
 import org.objectweb.asm.commons.GeneratorAdapter;
 import org.objectweb.asm.commons.Method;
@@ -55,7 +56,7 @@
     {
         MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
         if (matchTargetMethod(name, desc)) {
-            if (name == "<init>") {
+            if (name.equals("<init>")) {
                 return new InvokeTriggerConstructorAdapter(mv, access, name, desc, signature, exceptions);
             } else {
                 return new InvokeTriggerMethodAdapter(mv, access, name, desc, signature, exceptions);
@@ -118,7 +119,9 @@
                     Type ruleType = Type.getType(TypeHelper.externalizeType("org.jboss.jbossts.orchestration.rule.Rule"));
                     Method method = Method.getMethod("void execute(String, Object, Object[])");
                     // we are at the relevant line in the method -- so add a trigger call here
-                    System.out.println("AccessTriggerMethodAdapter.visitMethodInsn : inserting trigger for " + rule.getName());
+                    if (Transformer.isVerbose()) {
+                        System.out.println("AccessTriggerMethodAdapter.visitMethodInsn : inserting trigger for " + rule.getName());
+                    }
                     startLabel = super.newLabel();
                     endLabel = super.newLabel();
                     super.visitLabel(startLabel);

Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/LineTriggerAdapter.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/LineTriggerAdapter.java	2008-12-17 10:37:46 UTC (rev 24397)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/LineTriggerAdapter.java	2008-12-17 11:58:49 UTC (rev 24398)
@@ -25,6 +25,7 @@
 
 import org.jboss.jbossts.orchestration.rule.Rule;
 import org.jboss.jbossts.orchestration.rule.type.TypeHelper;
+import org.jboss.jbossts.orchestration.agent.Transformer;
 import org.objectweb.asm.*;
 import org.objectweb.asm.commons.GeneratorAdapter;
 import org.objectweb.asm.commons.Method;
@@ -50,7 +51,7 @@
     {
         MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
         if (matchTargetMethod(name, desc)) {
-            if (name == "<init>") {
+            if (name.equals("<init>")) {
                 return new LineTriggerConstructorAdapter(mv, access, name, desc, signature, exceptions);
             } else {
                 return new LineTriggerMethodAdapter(mv, access, name, desc, signature, exceptions);
@@ -72,6 +73,7 @@
         private String[] exceptions;
         private Label startLabel;
         private Label endLabel;
+        protected boolean unlatched;
 
         LineTriggerMethodAdapter(MethodVisitor mv, int access, String name, String descriptor, String signature, String[] exceptions)
         {
@@ -81,6 +83,7 @@
             this.descriptor = descriptor;
             this.signature = signature;
             this.exceptions = exceptions;
+            this.unlatched = true;  // subclass can manipulate this to postponne visit
             startLabel = null;
             endLabel = null;
         }
@@ -89,13 +92,15 @@
         // super.catchException(startLabel, endLabel, new Type("org.jboss.jbossts.orchestration.rule.exception.ExecuteException")));
 
         public void visitLineNumber(final int line, final Label start) {
-            if (!visitedLine && (targetLine <= line)) {
+            if (unlatched && !visitedLine && (targetLine <= line)) {
                 rule.setTypeInfo(targetClass, access, name, descriptor, exceptions);
                 String key = rule.getKey();
                 Type ruleType = Type.getType(TypeHelper.externalizeType("org.jboss.jbossts.orchestration.rule.Rule"));
                 Method method = Method.getMethod("void execute(String, Object, Object[])");
                 // we are at the relevant line in the method -- so add a trigger call here
-                System.out.println("AccessTriggerMethodAdapter.visitLineNumber : inserting trigger for " + rule.getName());
+                if (Transformer.isVerbose()) {
+                    System.out.println("AccessTriggerMethodAdapter.visitLineNumber : inserting trigger for " + rule.getName());
+                }
                 startLabel = super.newLabel();
                 endLabel = super.newLabel();
                 super.visitLabel(startLabel);
@@ -185,21 +190,12 @@
 
     private class LineTriggerConstructorAdapter extends LineTriggerMethodAdapter
     {
-        private boolean superCalled;
-
         LineTriggerConstructorAdapter(MethodVisitor mv, int access, String name, String descriptor, String signature, String[] exceptions)
         {
             super(mv, access, name, descriptor, signature, exceptions);
-            this.superCalled = false;
+            this.unlatched = false;
         }
 
-        // don't pass on line visits until we have seen an INVOKESPECIAL
-        public void visitLineNumber(final int line, final Label start) {
-            if (superCalled) {
-                super.visitLineNumber(line, start);
-            }
-        }
-
         public void visitMethodInsn(
             final int opcode,
             final String owner,
@@ -208,7 +204,7 @@
         {
             super.visitMethodInsn(opcode, owner, name, desc);
             // hmm, this probably means the super constructor has been invoked :-)
-            superCalled &= (opcode == Opcodes.INVOKESPECIAL);
+            unlatched |= (opcode == Opcodes.INVOKESPECIAL);
         }
     }
 

Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/SynchronizeTriggerAdapter.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/SynchronizeTriggerAdapter.java	2008-12-17 10:37:46 UTC (rev 24397)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/adapter/SynchronizeTriggerAdapter.java	2008-12-17 11:58:49 UTC (rev 24398)
@@ -25,6 +25,7 @@
 
 import org.jboss.jbossts.orchestration.rule.Rule;
 import org.jboss.jbossts.orchestration.rule.type.TypeHelper;
+import org.jboss.jbossts.orchestration.agent.Transformer;
 import org.objectweb.asm.*;
 import org.objectweb.asm.commons.GeneratorAdapter;
 import org.objectweb.asm.commons.Method;
@@ -104,7 +105,9 @@
                     Type ruleType = Type.getType(TypeHelper.externalizeType("org.jboss.jbossts.orchestration.rule.Rule"));
                     Method method = Method.getMethod("void execute(String, Object, Object[])");
                     // we are at the relevant line in the method -- so add a trigger call here
-                    System.out.println("SynchronizeTriggerMethodAdapter.visitMethodInsn : inserting trigger for " + rule.getName());
+                    if (Transformer.isVerbose()) {
+                        System.out.println("SynchronizeTriggerMethodAdapter.visitMethodInsn : inserting trigger for " + rule.getName());
+                    }
                     startLabel = super.newLabel();
                     endLabel = super.newLabel();
                     super.visitLabel(startLabel);

Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java	2008-12-17 10:37:46 UTC (rev 24397)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java	2008-12-17 11:58:49 UTC (rev 24398)
@@ -38,6 +38,7 @@
 import org.jboss.jbossts.orchestration.synchronization.Waiter;
 import org.jboss.jbossts.orchestration.agent.Location;
 import org.jboss.jbossts.orchestration.agent.LocationType;
+import org.jboss.jbossts.orchestration.agent.Transformer;
 import org.objectweb.asm.Opcodes;
 
 import java.io.StringWriter;
@@ -347,7 +348,9 @@
     public static void execute(String key, Object recipient, Object[] args) throws ExecuteException
     {
         Rule rule = ruleKeyMap.get(key);
-        System.out.println("Rule.execute called for " + key);
+        if (Transformer.isVerbose()) {
+            System.out.println("Rule.execute called for " + key);
+        }
 
         if (rule == null) {
             throw new ExecuteException("Rule.execute : unable to find rule with key " + key);
@@ -805,7 +808,9 @@
         public void execute(Bindings bindings, Object recipient, Object[] args)
                 throws ExecuteException
         {
-            System.out.println(rule.getName() + " execute");
+            if (Transformer.isVerbose()) {
+                System.out.println(rule.getName() + " execute");
+            }
             Iterator<Binding> iterator = bindings.iterator();
             while (iterator.hasNext()) {
                 Binding binding = iterator.next();




More information about the jboss-svn-commits mailing list