2018-07-09 ZygoteInit

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.winmu.bluetooth.Manger.BleManger.testlitequry()' on a null object reference

        at com.winmu.ble.bluetoothsdk.MainActivity.onClick(MainActivity.java:383)

        at android.view.View.performClick(View.java:6256)

        at android.view.View$PerformClick.run(View.java:24701)

        at android.os.Handler.handleCallback(Handler.java:789)

        at android.os.Handler.dispatchMessage(Handler.java:98)

        at android.os.Looper.loop(Looper.java:164)

        at android.app.ActivityThread.main(ActivityThread.java:6654)

        at java.lang.reflect.Method.invoke(Native Method)

        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)

以上是crash的相关信息,仅作为参考。由此分析ZygoteInit类main函数,网络摘抄一个流程图


创建进程

public static void main(String argv[]) {

        ZygoteServer zygoteServer = new ZygoteServer(); //定义了zygoteServer 

      // Mark zygote start. This ensures that thread creation will throw error.

        ZygoteHooks.startZygoteNoThreadCreation();//看名字估计是禁止创建多线程

  // Zygote goes into its own process group.

        try {

            Os.setpgid(0, 0);

        } catch (ErrnoException ex) {

            throw new RuntimeException("Failed to setpgid(0,0)", ex);

        }

        final Runnable caller;

    try {

            // Report Zygote start time to tron unless it is a runtime restart

            if (!"1".equals(SystemProperties.get("sys.boot_completed"))) {

                MetricsLogger.histogram(null, "boot_zygote_init",

                        (int) SystemClock.elapsedRealtime());

            }

            String bootTimeTag = Process.is64Bit() ? "Zygote64Timing" : "Zygote32Timing";

            TimingsTraceLog bootTimingsTraceLog = new TimingsTraceLog(bootTimeTag,

                    Trace.TRACE_TAG_DALVIK);

            bootTimingsTraceLog.traceBegin("ZygoteInit");

            RuntimeInit.enableDdms();

            boolean startSystemServer = false;

            String socketName = "zygote";

            String abiList = null;

            boolean enableLazyPreload = false;

            for (int i = 1; i < argv.length; i++) {

                if ("start-system-server".equals(argv[i])) {

                    startSystemServer = true;

                } else if ("--enable-lazy-preload".equals(argv[i])) {

                    enableLazyPreload = true;

                } else if (argv[i].startsWith(ABI_LIST_ARG)) {

                    abiList = argv[i].substring(ABI_LIST_ARG.length());

                } else if (argv[i].startsWith(SOCKET_NAME_ARG)) {

                    socketName = argv[i].substring(SOCKET_NAME_ARG.length());

                } else {

                    throw new RuntimeException("Unknown command line argument: " + argv[i]);

                }

            }

            if (abiList == null) {

                throw new RuntimeException("No ABI list supplied.");

            }

            zygoteServer.registerServerSocketFromEnv(socketName);

            // In some configurations, we avoid preloading resources and classes eagerly.

            // In such cases, we will preload things prior to our first fork.

            if (!enableLazyPreload) {

                bootTimingsTraceLog.traceBegin("ZygotePreload");

                EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_START,

                    SystemClock.uptimeMillis());

                preload(bootTimingsTraceLog);

                EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_END,

                    SystemClock.uptimeMillis());

                bootTimingsTraceLog.traceEnd(); // ZygotePreload

            } else {

                Zygote.resetNicePriority();

            }

            // Do an initial gc to clean up after startup

            bootTimingsTraceLog.traceBegin("PostZygoteInitGC");

            gcAndFinalize();

            bootTimingsTraceLog.traceEnd(); // PostZygoteInitGC

            bootTimingsTraceLog.traceEnd(); // ZygoteInit

            // Disable tracing so that forked processes do not inherit stale tracing tags from

            // Zygote.

            Trace.setTracingEnabled(false, 0);

            Zygote.nativeSecurityInit();

            // Zygote process unmounts root storage spaces.

            Zygote.nativeUnmountStorageOnInit();

            ZygoteHooks.stopZygoteNoThreadCreation();

            if (startSystemServer) {

                Runnable r = forkSystemServer(abiList, socketName, zygoteServer);//比较重要的地方以fork的方式创建system_server进程,下面单独贴出来

                // {@code r == null} in the parent (zygote) process, and {@code r != null} in the

                // child (system_server) process.

                if (r != null) {

                    r.run();//运行创建进程,主要是本地方法nativeForkSystemServer,里面会监听system_server状态是否停止,如果停止则自杀

                    return;

                }

            }

            Log.i(TAG, "Accepting command socket connections");

            // The select loop returns early in the child process after a fork and

            // loops forever in the zygote.

            caller = zygoteServer.runSelectLoop(abiList);//接受应用的socket链接请求

        } catch (Throwable ex) {

            Log.e(TAG, "System zygote died with exception", ex);

            throw ex;

        } finally {

            zygoteServer.closeServerSocket(); //当退出循环时,系统出现问题, 所以也要将server socket关闭

        }

        // We're in the child process and have exited the select loop. Proceed to execute the

        // command.

        if (caller != null) {

            caller.run();

        }

    }

你可能感兴趣的:(2018-07-09 ZygoteInit)