4 Replies Latest reply on Nov 13, 2013 6:05 AM by whitingjr

    CompileException invalid stack height 2 expecting 1

    whitingjr

      Hi,

      I am getting this exception when a Byteman Rule is being initially loaded on my server.

       

      19:58:18,028 INFO  [stdout] (ServerService Thread Pool -- 60) Rule.ensureTypeCheckedCompiled : error compiling rule TxConnectionListener state

      19:58:18,028 INFO  [stdout] (ServerService Thread Pool -- 60) org.jboss.byteman.rule.exception.CompileException: FieldExpression.compile : invalid stack height 2 expecting 1

      19:58:18,028 INFO  [stdout] (ServerService Thread Pool -- 60)   at org.jboss.byteman.rule.expression.FieldExpression.compile(FieldExpression.java:298)

      19:58:18,028 INFO  [stdout] (ServerService Thread Pool -- 60)   at org.jboss.byteman.rule.expression.LogicalExpression.compile(LogicalExpression.java:104)

      19:58:18,029 INFO  [stdout] (ServerService Thread Pool -- 60)   at org.jboss.byteman.rule.Condition.compile(Condition.java:101)

      19:58:18,029 INFO  [stdout] (ServerService Thread Pool -- 60)   at org.jboss.byteman.rule.compiler.Compiler.compileBytes(Compiler.java:406)

      19:58:18,029 INFO  [stdout] (ServerService Thread Pool -- 60)   at org.jboss.byteman.rule.compiler.Compiler.getHelperAdapter(Compiler.java:64)

      19:58:18,029 INFO  [stdout] (ServerService Thread Pool -- 60)   at org.jboss.byteman.rule.Rule.compile(Rule.java:545)

      19:58:18,029 INFO  [stdout] (ServerService Thread Pool -- 60)   at org.jboss.byteman.rule.Rule.ensureTypeCheckedCompiled(Rule.java:450)

      19:58:18,029 INFO  [stdout] (ServerService Thread Pool -- 60)   at org.jboss.byteman.rule.Rule.execute(Rule.java:672)

      19:58:18,029 INFO  [stdout] (ServerService Thread Pool -- 60)   at org.jboss.byteman.rule.Rule.execute(Rule.java:653)

      19:58:18,029 INFO  [stdout] (ServerService Thread Pool -- 60)   at org.jboss.jca.core.connectionmanager.listener.TxConnectionListener.setTrackByTx(TxConnectionListener.java)

      1

       

      Using the bmcheck tool no errors or warnings were reported.

       

      $ bmcheck -cp ./java/jboss/ironjacamar/ironjacamar_1.0.21/target/ironjacamar-core-impl.jar -cp ./java/jboss/ironjacamar/ironjacamar_1.0.21/target/ironjacamar-core-api.jar -cp ./java/jboss/jboss-eap-6.2.0.ER7/modules/system/layers/base/javax/resource/api/main/jboss-connector-api_1.6_spec-1.0.1.Final-redhat-2.jar -cp ./java/jboss/jboss-eap-6.2.0.ER7/modules/system/layers/base/javax/transaction/api/main/jboss-transaction-api_1.1_spec-1.0.1.Final-redhat-2.jar -cp ./java/jboss/jboss-eap-6.2.0.ER7/modules/system/layers/base/org/jboss/logging/main/jboss-logging-3.1.2.GA-redhat-1.jar ./java/jboss/byteman/byteman-download-2.1.3/sample/scripts/ConnectionTrackByTxStateMonitor.btm

      checking rule TxConnectionListener state against class org.jboss.jca.core.connectionmanager.listener.TxConnectionListener

      parsed rule "TxConnectionListener state" for class org.jboss.jca.core.connectionmanager.listener.TxConnectionListener

      type checked rule "TxConnectionListener state"

       

      TestScript: no errors

       

       

      This is my Byteman script

       

       

       

      # StateMonitor

      #

      # A byteman script which finds a condition causing the state for connection

      # tracking to change during a transaction.

      #

       

      ########################################################################

      #

      # Rule to detect state change

      #

       

      RULE TxConnectionListener state

      CLASS org.jboss.jca.core.connectionmanager.listener.TxConnectionListener

      METHOD setTrackByTx(boolean)

      AT ENTRY

      IF (!$1)

         AND

         ($this.isTrackByTx())

         AND

         ($this.getTransactionSynchronization().enlisted)

      DO traceStack("*** the trackByTx state is being changed to false for an inflight transaction by thread name ["+Thread.currentThread().getName()+ "]. ***")

      ENDRULE

       

       

      The class the rule has been written for is added as an attachment.

        • 1. Re: CompileException invalid stack height 2 expecting 1
          adinn

          Hi Jeremy,

          Jeremy Whiting wrote:

           

          Hi,

          I am getting this exception when a Byteman Rule is being initially loaded on my server.

           

          . . .

           

          Thanks very much for the fully detailed error report. That should make it very easy to find the problem.

           

          What I can see straight away is that the error is happening during the runtime type check of  the rule but only because the rule is being compiled to bytecode. The offline type checker does not normally compile rules when it performs its type checking so that explains the disparity between testing and offline checking. If you set

           

          BYTEMAN_JAVA_OPTS="-Dorg.jboss.byteman.compile.to.bytecode"

           

          when you run bmcheck.sh (yes, the value of the that environment variable gets added to the java command line :-)  I would expect you to see the error during the offline type check.

           

          When the Byteman engine compiles to bytecode it walks the expression tree of the parsed rule and generates bytecode to implement the desired behaviours. As a sanity check it tracks the stack heights before and after translating an expression and ensures that they differ by teh expected amount. Clearly, something is going  wrong when translating the field access in your condition, either in the counted heights or in the expectations. I'll check this as soon as I can and try to include a fix in the next Byteman release.

          • 2. Re: CompileException invalid stack height 2 expecting 1
            adinn

            And here is the JIRA BYTEMAN-253

            1 of 1 people found this helpful
            • 3. Re: CompileException invalid stack height 2 expecting 1
              whitingjr

              Thanks for creating a jira.

              • 4. Re: CompileException invalid stack height 2 expecting 1
                whitingjr

                Thank you for the detailed explanation.

                 

                So to get round this I removed the option "-Dorg.jboss.byteman.compile.to.bytecode" on the server. Transformation when the code is initially executed is working fine.

                 

                Many thanks.