Example
On Android phone execution getprop | grep cpu
, you will get a message similar to the following:
[ro.product.cpu.abi]: [arm64-v8a][ro.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi][ro.product.cpu.abilist32]: [armeabi-v7a,armeabi][ro.product.cpu.abilist64]: [arm64-v8a]
Each CPU supports a different set of instructions (instruction set), a combination of a CPU and instruction set defines an ABI (application Binary Interface), and the ABI defines:
-The CPU instruction set that the machine code should use
-Memory access when size-end configuration
-Executable binary file format
-Convention: If aligned, register use limit
Primary Abi vs. Secondary Abi
The Primary Abi is the ABI known when compiling the entire system image, the machine code in the system image uses the Primary ABI, and the optional secondary ABI is an ABI that the system can also support.
Get platform ABI List
In the app, you can access the Android.os.Build class to get ABI information for the current platform. The list of ABI information supported by the device is an ordered array of strings in the build class: The SUPPORTED_ABIS, SUPPORTED_32_BIT_ABIS, SUPPORTED_64_BIT_ABIS
system preferred ABI is stored in Build.SUPPORTED_ABIS[0]
, for example, the device shown in the previous example preferred Abi arm64-v8a
.
Abi and Instruction Set
Currently Android supports 7 kinds of ABI ( arm64-v8a,armeabi-v7a,armeabi,mips,mips64,x86,x86_64
), as listed in the example above ro.product.cpu.abilist
. The different ABI may map to the same runtime instruction set ( libcore/libart/src/main/java/dalvik/system/VMRuntime.java getInstructionSet(String abi)
), and the mapping of the ABI to instruction set in Android m is defined in the Vmruntime class as follows:
Abi_to_instruction_set_map. Put("Armeabi","Arm");Abi_to_instruction_set_map. Put("armeabi-v7a","Arm");Abi_to_instruction_set_map. Put("MIPS","MIPS");Abi_to_instruction_set_map. Put("Mips64","Mips64");Abi_to_instruction_set_map. Put("x86","x86");Abi_to_instruction_set_map. Put("x86_64","x86_64");Abi_to_instruction_set_map. Put("arm64-v8a","Arm64");
You can see that different ABI ( armeabi,armeabi-v7a
) mappings are mapped to the same instruction set arm
. During application installation, the Android l will begin to do AOT compilation, the target instruction at compile time. Set is calculated by applying its own platform ABI information. The calculation procedure can be found in the code in Instructionsets.java in the framework. The first is calculated based on Primarycpuabi and Secondarycpuabi in the parsed application packet appinfo, if appinfo in Primarycpuabi does not exist, then according to the system preferred ABI to compute the target instruction set.
Reference:
[1] https://developer.android.com/ndk/guides/abis.html
[2] Http://developer.android.com/reference/android/os/Build.html
Abi and Instruction Set