Android架构 架构和 CPU ABI - NDK

查看设备架构

adb -s emulator-5554 shell getprop ro.product.cpu.abi

C:\Users\liyd>adb -s emulator-5554 shell getprop ro.product.cpu.abi
x86_64

C:\Users\liyd>adb -s 804c11f1 shell getprop ro.product.cpu.abi
arm64-v8a

mumu模拟器12

C:\Users\liyd>adb -s 127.0.0.1:7555 shell getprop ro.product.cpu.abi
x86_64

架构和 CPU

使用原生代码时,硬件很重要。NDK 提供各种 ABI 供您选择,可让您确保针对正确的架构和 CPU 进行编译。

本部分介绍了在构建时如何面向特定的架构和 CPU,如何使用 ARM Neon 扩展指令集,以及在运行时如何使用 CPU 功能库查询可选功能。

Android ABI - NDK

bookmark_border
不同的 Android 设备使用不同的 CPU,而不同的 CPU 支持不同的指令集。CPU 与指令集的每种组合都有专属的应用二进制接口 (ABI)。ABI 包含以下信息:

可使用的 CPU 指令集(和扩展指令集)。
运行时内存存储和加载的字节顺序。Android 始终是 little-endian。
在应用和系统之间传递数据的规范(包括对齐限制),以及系统调用函数时如何使用堆栈和寄存器。
可执行二进制文件(例如程序和共享库)的格式,以及它们支持的内容类型。Android 始终使用 ELF。如需了解详情,请参阅 ELF System V 应用二进制接口。
如何重整 C++ 名称。如需了解详情,请参阅 Generic/Itanium C++ ABI。
本页列举了 NDK 支持的 ABI,并且介绍了每个 ABI 的运行原理。
ABI 还可以指平台支持的原生 API。如需影响 32 位系统的此类 ABI 问题列表,请参阅 32 位 ABI 错误。

支持的 ABI

在这里插入图片描述

ZygoteInit.java

private static final String ABI_LIST_ARG = "--abi-list=";
private static final String SOCKET_NAME_ARG = "--socket-name=";


public static void main(String argv[]) {
    
    
566        try {
    
    
567            RuntimeInit.enableDdms();
568            // Start profiling the zygote initialization.
569            SamplingProfilerIntegration.start();
570
571            boolean startSystemServer = false;
572            String socketName = "zygote";
573            String abiList = null;
574            for (int i = 1; i < argv.length; i++) {
    
    
575                if ("start-system-server".equals(argv[i])) {
    
    
576                    startSystemServer = true;
577                } else if (argv[i].startsWith(ABI_LIST_ARG)) {
    
    
578                    abiList = argv[i].substring(ABI_LIST_ARG.length());
579                } else if (argv[i].startsWith(SOCKET_NAME_ARG)) {
    
    
580                    socketName = argv[i].substring(SOCKET_NAME_ARG.length());
581                } else {
    
    
582                    throw new RuntimeException("Unknown command line argument: " + argv[i]);
583                }
584            }
585
586            if (abiList == null) {
    
    
587                throw new RuntimeException("No ABI list supplied.");
588            }
589
590            registerZygoteSocket(socketName);
591            EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_START,
592                SystemClock.uptimeMillis());
593            preload();
594            EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_END,
595                SystemClock.uptimeMillis());
596
597            // Finish profiling the zygote initialization.
598            SamplingProfilerIntegration.writeZygoteSnapshot();
599
600            // Do an initial gc to clean up after startup
601            gcAndFinalize();
602
603            // Disable tracing so that forked processes do not inherit stale tracing tags from
604            // Zygote.
605            Trace.setTracingEnabled(false);
606
607            if (startSystemServer) {
    
    
608                startSystemServer(abiList, socketName);
609            }
610
611            Log.i(TAG, "Accepting command socket connections");
612            runSelectLoop(abiList);
613
614            closeServerSocket();
615        } catch (MethodAndArgsCaller caller) {
    
    
616            caller.run();
617        } catch (RuntimeException ex) {
    
    
618            Log.e(TAG, "Zygote died with exception", ex);
619            closeServerSocket();
620            throw ex;
621        }
622    }

猜你喜欢

转载自blog.csdn.net/qq_42015021/article/details/132558370