Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da74a628 authored by Piotr Jastrzebski's avatar Piotr Jastrzebski
Browse files

Register DDM handlers at the beginning of main method.

Compiler initializes RuntimeInit during compilation and stores an
initialized version of the class in oat file. Same thing happens to
DdmServer which handles DDM packets in JDWP thread started during JVM
creation. This means that after the creation of JVM all
DDM packets are handled by DdmServer.dispatch and since it's already
initialized during compilation it has all framework related handlers
already registered. If a packet arrives before AndroidRuntime.startReg
is called then framework native methods are not yet registered and the
processing of the packet fails with UnsatisfiedLinkError.

To fix this problem the registration of framework related DDM handlers
is moved to the beginning of ZygoteInit.main and RuntimeInit.main. This
means that the handlers won't be registered until main method is called
and that's guaranteed to be after AndroidRuntime.startReg is called. It
also guarantees that DDM packets will be properly handled as soon as
Java code is executed.

Bug: 18081539.
Change-Id: I9c674f53f3f62d58c46886e0b60698182e08f0c3
parent b4a5c04c
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -233,6 +233,7 @@ public class RuntimeInit {
    }

    public static final void main(String[] argv) {
        enableDdms();
        if (argv.length == 2 && argv[1].equals("application")) {
            if (DEBUG) Slog.d(TAG, "RuntimeInit: Starting application");
            redirectLogStreams();
@@ -365,9 +366,9 @@ public class RuntimeInit {
    }

    /**
     * Enable debugging features.
     * Enable DDMS.
     */
    static {
    static final void enableDdms() {
        // Register handlers for DDM messages.
        android.ddm.DdmRegister.registerHandlers();
    }
+1 −0
Original line number Diff line number Diff line
@@ -557,6 +557,7 @@ public class ZygoteInit {

    public static void main(String argv[]) {
        try {
            RuntimeInit.enableDdms();
            // Start profiling the zygote initialization.
            SamplingProfilerIntegration.start();