6 Replies Latest reply on Jan 25, 2013 4:12 PM by Johnathon Lee

    Missing something basic?  Not seeing classes transformed after bmsubmit

    Johnathon Lee Newbie

      Based upon the method XAManagedConnection.isFailedXA,  I thought it would be good to create a Byteman rule [1]

      which would emulate some behavior I would like to verify.  I've tried several variations of this rule,  including changing the class to

      java.lang.String and method to <init>.... to try and force "something".

       

      I'm using a clean EAP 4.3.0.GA_CP08 instance. 

       

      I've tried multiple variations of [2] as well and can see that the transform listener is running [3],  but nothing seems to "stick".  

      Whenever I perform a bmsubmit I see [4] but nothing else.  I've use Byteman successfully for some other tasks... not sure what I'm missing here.  (using 2.1.0)

       

      Any advice?

       

      [1]

      RULE fail XAER_OUTSIDE 
      CLASS org.jboss.resource.adapter.jdbc.xa.XAManagedConnection 
      METHOD boolean isFailedXA(int) 
      AT ENTRY 
      IF $errorCode == XAException.XAER_OUTSIDE 
      DO debug("isFailedXA");   #will modify to return true 
      ENDRULE  
      

      [2]

      [jolee@jolee bin]$ ./bminstall.sh -Dorg.jboss.byteman.debug -Dorg.jboss.byteman.verbose <pid> 
      [jolee@jolee bin]$ ./bmsubmit.sh -l /home/jolee/ByteManGames/test.btm  
      

      [3]

      14:07:45,045 INFO  [Server] JBoss (MX MicroKernel) [4.3.0.GA_CP08 (build: SVNTag=JBPAPP_4_3_0_GA_CP08 date=201004202136)] Started in 7s:216ms 14:07:58,533 INFO  
      [STDOUT] Setting org.jboss.byteman.debug= 14:07:58,533 INFO  [STDOUT] Setting org.jboss.byteman.verbose= 14:07:58,545 INFO  
      [STDOUT] TransformListener() : accepting requests on localhost:9091
      

      [4]

      14:32:33,748 INFO  [STDOUT] TransformListener() : handling connection on port 9091
      

       

      ... had to clean this up a bit once I realized my formatting sucked.

        • 1. Re: Missing something basic?  Not seeing classes transformed after bmsubmit
          Andrew Dinn Master

          Hi jonathon

          Johnathon Lee wrote:

           

          Based upon the method XAManagedConnection.isFailedXA,  I thought it would be good to create a Byteman rule [1]

          which would emulate some behavior I would like to verify.  I've tried several variations of this rule,  including changing the class to

          java.lang.String and method to <init>.... to try and force "something".

           

          I'm using a clean EAP 4.3.0.GA_CP08 instance. 

           

          I've tried multiple variations of [2] as well and can see that the transform listener is running [3],  but nothing seems to "stick".  

          Whenever I perform a bmsubmit I see [4] but nothing else.  I've use Byteman successfully for some other tasks... not sure what I'm missing here.  (using 2.1.0)

           

          Any advice?

           

          [1]

          RULE fail XAER_OUTSIDE 
          CLASS org.jboss.resource.adapter.jdbc.xa.XAManagedConnection 
          METHOD boolean isFailedXA(int) 
          AT ENTRY 
          IF $errorCode == XAException.XAER_OUTSIDE 
          DO debug("isFailedXA");   #will modify to return true 
          ENDRULE  
          

           

          I ran this through the offline type checker program bmcheck and found this

           

          [adinn@sputstik jdbc]$ bmcheck.sh -cp jboss-as-connector-6.1.0.Final.jar -cp jboss-connector-api_1.5_spec-1.0.0.Final.jar foo.btm

          checking rule fail XAER_OUTSIDE against class org.jboss.resource.adapter.jdbc.xa.XAManagedConnection

          parsed rule "fail XAER_OUTSIDE" for class org.jboss.resource.adapter.jdbc.xa.XAManagedConnection

          ERROR : Failed to type check rule "fail XAER_OUTSIDE" loaded from foo.btm line 5 against method isFailedXA(int) boolean

          org.jboss.byteman.rule.exception.TypeException: FieldExpression.typeCheck : invalid path XAException to static field XAER_OUTSIDE file foo.btm line 5

           

          TestScript: 1 total errors

                      0 total warnings

                      0 parse errors

                      1 type errors

                      0 type warnings

           

          The problem is that XAException.XAER_OUTSIDE is nto a valid specification of the XA constant. If you modify the rule as follows it works

           

          RULE fail XAER_OUTSIDE 
          CLASS org.jboss.resource.adapter.jdbc.xa.XAManagedConnection 
          METHOD boolean isFailedXA(int) 
          AT ENTRY 
          IF $errorCode == javax.transaction.xa.XAException.XAER_OUTSIDE 
          DO debug("isFailedXA");   #will modify to return true 
          ENDRULE  
          

           

           

          [adinn@sputstik jdbc]$ bmcheck.sh -cp jboss-as-connector-6.1.0.Final.jar -cp jboss-connector-api_1.5_spec-1.0.0.Final.jar foo.btm

          checking rule fail XAER_OUTSIDE against class org.jboss.resource.adapter.jdbc.xa.XAManagedConnection

          parsed rule "fail XAER_OUTSIDE" for class org.jboss.resource.adapter.jdbc.xa.XAManagedConnection

          type checked rule "fail XAER_OUTSIDE"

           

          TestScript: no errors

           

          You may still find some problems with the use of the parameter name $errorCode when you dynamically load a rule (see BYTEMAN-28). The underlying JVM error mentioned in this issue ought to be fixed in the latest OpenJDK 7 release but it is still present in earlier releases and in OPenJDK 6. If you are not using the latest OpenJDK 7 the I suggest that you try using $1 to refer to the method parameter in place of $errorCode.

           

          regards,

           

           

          Andrew Dinn

          1 of 1 people found this helpful
          • 2. Re: Missing something basic?  Not seeing classes transformed after bmsubmit
            Johnathon Lee Newbie

            Andrew, 

              Thanks for replying.  Using the updated rule you provided,  I needed to modify the cp to stay in the realm of my problem.  I can get that to pass bmcheck.sh and believe it will move me in the direction I'm wanting to go.  However,  when I do a bminstall.sh [2] I still receive only the output [3] sans any other input.  When trying a no args bmsubmit.sh [4],  it looks like nothing has been affected.  

             

            Could this be due to XAManagedConnection not being a loaded class yet?  Or should I be seeing some evidence of the class being manipulated at this point?

             

            Thanks,

            JLee

             

             

            [1]

            [jolee@jolee bin]$ ./bmcheck.sh -cp /opt/jboss/jboss-eap-4.3-CP08/jboss-as/server/default/tmp/deploy/tmp7665091427245652427jboss-xa-jdbc.rar-contents/jboss-xa-jdbc.jar -cp /opt/jboss/jboss-eap-4.3-CP08/jboss-as/client/jboss-j2ee.jar -cp /opt/jboss/jboss-eap-4.3-CP08/jboss-as/server/default/lib/jboss-common-jdbc-wrapper.jar   /home/jolee/ByteManGames/XAER_OUTSIDE.btm 
            checking rule fail XAER_OUTSIDE against class org.jboss.resource.adapter.jdbc.xa.XAManagedConnection
            parsed rule "fail XAER_OUTSIDE" for class org.jboss.resource.adapter.jdbc.xa.XAManagedConnection
            type checked rule "fail XAER_OUTSIDE"
            
            TestScript: no errors
            

             

            [2]

            [jolee@jolee bin]$ ./bminstall.sh -Dorg.jboss.byteman.debug -Dorg.jboss.byteman.verbose 2626
            [jolee@jolee bin]$ ./bmsubmit.sh -l /home/jolee/ByteManGames/XAER_OUTSIDE.btm 
            install rule fail XAER_OUTSIDE
            

             

            [3]

            07:49:28,870 INFO  [Server] JBoss (MX MicroKernel) [4.3.0.GA_CP08 (build: SVNTag=JBPAPP_4_3_0_GA_CP08 date=201004202136)] Started in 7s:199ms
            08:03:08,083 INFO  [STDOUT] Setting org.jboss.byteman.debug=
            08:03:08,084 INFO  [STDOUT] Setting org.jboss.byteman.verbose=
            08:03:08,110 INFO  [STDOUT] TransformListener() : accepting requests on localhost:9091
            08:03:33,144 INFO  [STDOUT] TransformListener() : handling connection on port 9091
            

             

            [4]

            [jolee@jolee bin]$ ./bmsubmit.sh 
            # File /home/jolee/ByteManGames/XAER_OUTSIDE.btm line 5
            RULE fail XAER_OUTSIDE
            CLASS org.jboss.resource.adapter.jdbc.xa.XAManagedConnection
            METHOD boolean isFailedXA(int)
            AT ENTRY
            IF $errorCode == javax.transaction.xa.XAException.XAER_OUTSIDE
            DO debug("isFailedXA");   #will modify to return true
            ENDRULE
            
            [jolee@jolee bin]$
            
            • 3. Re: Missing something basic?  Not seeing classes transformed after bmsubmit
              Andrew Dinn Master

              Johnathon Lee wrote:

               

              Andrew, 

                Thanks for replying.  Using the updated rule you provided,  I needed to modify the cp to stay in the realm of my problem.  I can get that to pass bmcheck.sh and believe it will move me in the direction I'm wanting to go.  However,  when I do a bminstall.sh [2] I still receive only the output [3] sans any other input.  When trying a no args bmsubmit.sh [4],  it looks like nothing has been affected.  

               

              Could this be due to XAManagedConnection not being a loaded class yet?  Or should I be seeing some evidence of the class being manipulated at this point?

               

              Yes, bmcheck requires you to provide -cp arguments to identify the jars containing the classes mentioned in your rules and, maybe, some of the auxiliary classes referenced in their method signatures. Obviously, the appropriate argument list depends upon how you have installed the code. I could not find the 4.3.0 jars to hand so I actually cheated and used the EAP6 final jars. Apologies if you had to do a little bit of scrabbling around to resolveall the link references. :-)

               

              It may well be that the target class is not yet loaded. If it were loaded I would have expected to see a warning about not being able to inject the rule. Which version of Byteman are you using? Older versions do not necessarily print these warnings.

               

              If you could try to submit a request to the app server which exercises the related code then this ought to produce a verbose trace message about trying to inject the rule into the class (this is printed when you run with property org.jboss.byteman.verbose set which it appears you have done) and, hopefully, cause the rule to be type checked and fired.

               

              The only other thing I can think of which might stop the rule being injected is the problem mentioned in BYTEMAN-28. If this is so then you can work around it by changing your rule so to refer to the method parameter using $1 instead of $errorCode. Indexed parameter references always work.

               

              Try running a transaction and let me know what happens.

               

              regards,

               

               

              Andrew Dinn

              • 4. Re: Missing something basic?  Not seeing classes transformed after bmsubmit
                Johnathon Lee Newbie

                Andrew,

                  Looks like I was expecting results before the class was actually loaded.  When I forced an XA Transaction I saw [1] and [2].  Which is the type of feedback I was looking for.  Very nice.

                 

                  So,  now I'm going to want to force throwing that error via Byteman in order for me to validate behavior of the rule.  Fun Stuff.  Thanks for the help!

                 

                JLee

                 

                 

                 

                [1]

                10:21:13,462 INFO  [HelloBean] Getting datasource
                10:21:13,669 INFO  [STDOUT] org.jboss.byteman.agent.Transformer : possible trigger for rule fail XAER_OUTSIDE in class org.jboss.resource.adapter.jdbc.xa.XAManagedConnection
                10:21:13,690 INFO  [STDOUT] RuleTriggerMethodAdapter.injectTriggerPoint : inserting trigger into org.jboss.resource.adapter.jdbc.xa.XAManagedConnection.isFailedXA(int) boolean for rule fail XAER_OUTSIDE
                10:21:13,692 INFO  [STDOUT] org.jboss.byteman.agent.Transformer : inserted trigger for fail XAER_OUTSIDE in class org.jboss.resource.adapter.jdbc.xa.XAManagedConnection
                

                 

                [2]

                [jolee@jolee bin]$ ./bmsubmit.sh 
                # File /home/jolee/ByteManGames/XAER_OUTSIDE.btm line 5
                RULE fail XAER_OUTSIDE
                CLASS org.jboss.resource.adapter.jdbc.xa.XAManagedConnection
                METHOD boolean isFailedXA(int)
                AT ENTRY
                IF $errorCode == javax.transaction.xa.XAException.XAER_OUTSIDE
                DO debug("isFailedXA");   #will modify to return true
                ENDRULE
                Transformed in:
                loader: org.jboss.mx.loading.UnifiedClassLoader3@72d006a7{ url=file:/opt/jboss/jboss-eap-4.3-CP08/jboss-as/server/default/tmp/deploy/tmp1460815805586205404jboss-xa-jdbc.rar ,addedOrder=30}
                trigger method: org.jboss.resource.adapter.jdbc.xa.XAManagedConnection.isFailedXA(int) boolean
                
                • 5. Re: Missing something basic?  Not seeing classes transformed after bmsubmit
                  Andrew Dinn Master

                  Hi Jonathon,

                  Johnathon Lee wrote:

                   

                    Looks like I was expecting results before the class was actually loaded.  When I forced an XA Transaction I saw [1] and [2].  Which is the type of feedback I was looking for.  Very nice.

                   

                    So,  now I'm going to want to force throwing that error via Byteman in order for me to validate behavior of the rule.  Fun Stuff.  Thanks for the help!

                   

                  Excellent and thanks very much for the positive feedback. Let me know if you have any further problems getting your rules to work -- I'll be happy to see if I can find any errors or resolve any problems with Byteman itself. If you can publish your rules and explain how they help you to test your code that would be interesting for me and for other users of Byteman.

                   

                  regards,

                   

                   

                  Andrew Dinn

                  • 6. Re: Missing something basic?  Not seeing classes transformed after bmsubmit
                    Johnathon Lee Newbie

                    Late follow up.  Fairly simple but I wanted to log when a specific failure was occuring (XAER_OUTSIDE) here:

                     

                    {code}

                    RULE fail XAER_OUTSIDE

                    CLASS XAManagedConnection

                    METHOD boolean isFailedXA(int)

                    AT ENTRY

                    IF $1 == -9

                    DO debug("==================== FAILING XAER_OUTSIDE ============================");

                       return true

                    ENDRULE

                    {code}

                     

                    And nothing fancy,  I needed to throw the error at the beginning of an XA Transaction (here using MySQL):

                     

                    {code}

                    RULE throw error from XAConnection

                    CLASS com.mysql.jdbc.jdbc2.optional.MysqlXAConnection

                    METHOD start

                    IF TRUE                     

                    DO debug("==================== mysqlXAResource ====================");

                    throw javax.transaction.xa.XAException(-9)    

                    ENDRULE

                    {code}

                     

                    ugh,  don't do this enough to remember formatting.