2 Replies Latest reply on Jul 10, 2012 10:02 AM by Pontus Ullgren

    Injecting code into JVM classes using Byteman 1.0.3 and Java 5 JVM

    Pontus Ullgren Newbie

      Hello,

       

      I try to inject code into JVM classes and unfortuantly I need to do this on a system running Java 5 JVM, so I'm stuck using byteman 1.0.3.

      However using byteman 1.0.3 I fail to get the result I expect.

       

      As a POC we can use the example from the Byteman Tutorial

      https://community.jboss.org/wiki/ABytemanTutorial#how_do_i_inject_code_into_jvm_classes

       

      Executing this with latest byteman works as expected, however when I change to byteman 1.0.3 it does not work anymore.

       

      If this a known limitation or is there a way to solve this and get code injected into JVM classes ?

       

      {code}

      ponu@devws:~/work$ export BYTEMAN_HOME=/opt/byteman-download-2.0.4

      ponu@devws:~/work$ java -Dorg.jboss.byteman.debug=true -Dorg.jboss.byteman.transform.all -javaagent:${BYTEMAN_HOME}/lib/byteman.jar=script:./thread.btm,boot:${BYTEMAN_HOME}/lib/byteman.jar -cp . AppMain2 test

      Default helper activated

      Installed rule using default helper : trace thread start

      *** start for thread: test

      test

      ponu@devws:~/work$ export BYTEMAN_HOME=/opt/byteman-1.0.3

      ponu@devws:~/work$ java -Dorg.jboss.byteman.debug=true -Dorg.jboss.byteman.transform.all -javaagent:${BYTEMAN_HOME}/lib/byteman.jar=script:./thread.btm,boot:${BYTEMAN_HOME}/lib/byteman.jar -cp . AppMain2 test

      test

      ponu@devws:~/work$

      {code}

       

      Best regards

      Pontus Ullgren

        • 1. Re: Injecting code into JVM classes using Byteman 1.0.3 and Java 5 JVM
          Andrew Dinn Master

          Hi Pontus,

          Pontus Ullgren wrote:

           

          Executing this with latest byteman works as expected, however when I change to byteman 1.0.3 it does not work anymore.

           

          If this a known limitation or is there a way to solve this and get code injected into JVM classes ?

           

          Yes, this is a known limitation of JDK5. The problem is that in JDK5 an agent transformer can only modify classes as they are loaded. Unfortunately java.lang.Thread is already loaded into the system before the Byteman agent is loaded so it never gets a chance to change this class. That's not the case for all classes in teh bootstrap classpath but it is fo rmany of the interesting ones. You can transform bootstrap classes  if they are i) not loaded before the Byteman agent andf ii) not needed by the agent in order to perform the transformation. Otherwise you eill need to use JDK6 and Byteman versions >= 1.2.x.

          • 2. Re: Injecting code into JVM classes using Byteman 1.0.3 and Java 5 JVM
            Pontus Ullgren Newbie

            I was afraid that I would get this answer :-)

             

            I will see if we can switch to JDK6 for the testing of this or if there is some other way I can rewrite the rule so that it only needs to change classes that are not loaded before the byteman agent.

             

            Thanks

            Pontus Ullgren