Is it possible to prepend bootclasspath for Dalvik VM on Android?

742 views Asked by At

I'm experimenting with -Xbootclasspath in Java just for fun, and have added a test method int java.lang.Object#id(), just an instance-like identityHashCode method shortcut:

package java.lang;

public class Object {

    public final int id() {
        return System.identityHashCode(this);
    }

// the original code goes here

}

The code above is compiled into a single-class JAR file, and the code below is compiled and dependent on the patch JAR file, thus the following code is legal:

public static void main(final String... args) {
    System.out.println(new Object().id());
}

Running the sample application is quite easy prepending the bootstrap classes:

$ java -Xbootclasspath/p:patch.jar -cp app.jar test.Application
366712642

Works fine. Now, I wondering if it's possible to do the same trick on Android. So, the closest equivalent, I think, should be (from adb shell):

$ dalvikvm -Xbootclasspath:patch.jar -cp app.jar test.Application
java.lang.NoSuchMethodError: No virtual method id()I in class Ljava/lang/Object; or its super classes (declaration of 'java.lang.Object' appears in /syework/core-libart.jar)
    at test.Application.main(Application.java:11)

Looks like prepending, but not working since it's saying that the java.lang.Object class is already defined in another location (probably the real path is /system/framework/core-libart.jar, at least it says similar, but that JAR is quite different -- then how after all?). I also saw a few examples with the $BOOTCLASSPATH variable, but none of them works for me for some reason.

Is it possible to run dalvikvm overriding the bootclass path somehow and where are the core classes are loaded from?

EDIT 1:

It probably would work, but Android Dalvik VM is really dependent on the zygote that all new Dalvik VM processes are forked from, thus the zygote does not run with an alternative boot classpath. At least, this is what I understood from this question: How to pass dalvik command line parameters through .apk?

0

There are 0 answers