2 Replies Latest reply on Oct 25, 2011 7:12 AM by swimablefish

    Dose byteman support the jvm on the android?

    swimablefish Newbie

      hi, i wonder if byteman support the jvm on the android?  we tried, but failed.

      the jvm on the android is dalvikvm.

        • 1. Re: Dose byteman support the jvm on the android?
          Andrew Dinn Master

          Hi swimable,

          swimablefish wrote:

           

          hi, i wonder if byteman support the jvm on the android?  we tried, but failed.

          the jvm on the android is dalvikvm.

          Byteman requires two things which I believe to be missing in Dalvik. Firstly, the virtual machine running Byteman must implement the JDK6 agent APIs defined in the instrumentation package. For details of this API see:

           

            http://download.oracle.com/javase/6/docs/api/java/lang/instrument/package-summary.html

           

          There is an archive release of Byteman (http://downloads.jboss.org/byteman/1.0.3.CP02/byteman-1.0.3.CP02.zip) .which only relies on the JDK5 API (and can be run on a Java 5 JVM either JRE or JDK) but it is not capable of transforming some JVM classes and does nto support dynamic agent loading. I don;t think Dalvik implements either of these APIs. In fact I don't thnk any of the Java ME VMs implement these APIs,

           

          The second issue is more fuindamental and probably acounts for the first one. Internally Dalvik uses its own bytecode format different to that of JVM bytecode. Dalvik is able to run Java bytecode because it includes a translator which turns JVM bytecode into Dalvik bytecode. This is used both offline to generate the Dalvik versions of JVM classes shipped with Dalvik and also used online to translate Java bytecode presented at runtime.

           

          Now the java agent APIs provide a Java agent program like Byteman with the opportunity to transform Java bytecode. An agent can redefine a class's byetcode when it first gets loaded; sInce JDK6, it can also redefine and reinstate different bytecode for method impolementations of classes which have already been loaded. That will not really work for a lot of Dalvik classes since there is no Java bytecode around to be transformed. Een where classes are dynamically loaded as Java bytecode it may either be too expensive to allow a Java agen tto work or  risk introducing chnages that the Dalvik translator cannot cope with.

           

          Of course Dalvik could implement the agent APIs to allow transformation of dynamic code but its not going to help much since the power of tools like Byteman is that thye can instrument any Java methods. Dalvik could implement an API allowing agents to translate Dalvik bytecode but then that would require rewriting the agent to understand and modify Dalvik bytecode which is a fairly big job.