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的相關(guān)信息,僅作為參考。由此分析ZygoteInit類main函數(shù),網(wǎng)絡(luò)摘抄一個(gè)流程圖


創(chuàng)建進(jìn)程

public static void main(String argv[]) {

? ? ? ? ZygoteServer zygoteServer = new ZygoteServer(); //定義了zygoteServer?

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

? ? ? ? ZygoteHooks.startZygoteNoThreadCreation();//看名字估計(jì)是禁止創(chuàng)建多線程

? // 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的方式創(chuàng)建system_server進(jìn)程,下面單獨(dú)貼出來

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

? ? ? ? ? ? ? ? // child (system_server) process.

? ? ? ? ? ? ? ? if (r != null) {

? ? ? ? ? ? ? ? ? ? r.run();//運(yùn)行創(chuàng)建進(jìn)程,主要是本地方法nativeForkSystemServer,里面會監(jiān)聽system_server狀態(tài)是否停止,如果停止則自殺

? ? ? ? ? ? ? ? ? ? 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);//接受應(yīng)用的socket鏈接請求

? ? ? ? } catch (Throwable ex) {

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

? ? ? ? ? ? throw ex;

? ? ? ? } finally {

? ? ? ? ? ? zygoteServer.closeServerSocket(); //當(dāng)退出循環(huán)時(shí),系統(tǒng)出現(xiàn)問題, 所以也要將server socket關(guān)閉

? ? ? ? }

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

? ? ? ? // command.

? ? ? ? if (caller != null) {

? ? ? ? ? ? caller.run();

? ? ? ? }

? ? }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容