Dex2Oat执行参数总结

来源:互联网 发布:漫画绘图软件免费下载 编辑:程序博客网 时间:2024/06/05 14:35

Android源码编译完的产物,都会放在out目录下,而/out/host目录中主要存放Android开发工具的产物,包含SDK各种工具,比如adb,dex2oat,aapt等。在整个编译完成之后,可以使用这些工具,比如dex2oat可以用来将dex文件转化为oat文件,在aosp目录下,执行out/host/linux-x86/bin/dex2oatd + 参数即可完成这个转化工作。
例如:

out/host/linux-x86/bin/dex2oatd --runtime-arg -Xms64m --runtime-arg -Xmx512m --boot-image=out/target/product/ranchu/dex_bootjars/system/framework/boot.art --dex-file=out/target/product/ranchu/obj/APPS/Telecom_intermediates/oat/arm64/package.odex.input --dex-location=/system/priv-app/Telecom/Telecom.apk --oat-file=out/target/product/ranchu/obj/APPS/Telecom_intermediates/oat/arm64/package.odex --android-root=out/target/product/ranchu/system --instruction-set=arm64 --instruction-set-variant=generic --instruction-set-features=default --include-patch-information --runtime-arg -Xnorelocate --no-generate-debug-info --abort-on-hard-verifier-error --no-inline-from=core-oj.jar

参数说明:

--dex-file=<dex-file>: specifies a .dex, .jar, or .apk file to compile.Example: --dex-file=/system/framework/core.jar指定要编译的文件路径,这个文件既可以是一个dex文件,也可以是一个内部包含dex文件的apk或jar文件。对于一次要编译多个文件的情况,每个文件都要用单独的一个--dex-file来指定。
--dex-location=<dex-location>: specifies an alternative dex location to encode in the oat file for the corresponding --dex-file argument.Example: --dex-file=/home/build/out/system/framework/core.jar         --dex-location=/system/framework/core.jar指定要写入最终编译出目标oat文件内部的编译文件的路径。对于一次要编译多个文件的情况,每一个路径都需要用--dex-location来指定,且出现的次序要和--dex-file指定的次序相同。
--zip-fd=<file-descriptor>: specifies a file descriptor of a zip filecontaining a classes.dex file to compile.Example: --zip-fd=5指定要编译文件的文件描述符。--zip-fd和--dex-file必须指定一个,但两者也相互冲突,不能同时出现,否则都会报错退出。
--zip-location=<zip-location>: specifies a symbolic name for the filecorresponding to the file descriptor specified by --zip-fd.Example: --zip-location=/system/app/Calculator.apk说明前面通过--zip-fd参数传入的那个文件描述符号对应的文件的路径。这个参数和--zip-location必须配对使用,也就是说,如果没有--zip-fd但是传入了--zip-location,或者有--zip-fd但是没有传入--zip-location,两种情况dex2oat都会报错退出。
--oat-file=<file.oat>: specifies the oat output destination via a filename.Example: --oat-file=/system/framework/boot.oat指定编译输出的oat文件的路径。
--oat-fd=<number>: specifies the oat output destination via a file descriptor.Example: --oat-fd=6指定编译输出的oat文件的文件描述符。--oat-fd和--oat-file必须指定一个,但两者也是冲突的,不能同时出现,否则都会报错退出。
--oat-location=<oat-name>: specifies a symbolic name for the file corresponding to the file descriptor specified by --oat-fd.Example: --oat-location=/data/dalvik-cache/system@app@Calculator.apk.oat也是指定编译输出的oat文件的路径,不过与--oat-file不同,--oat-location是必须要和--oat-fd配对使用的,两个参数必须同时出现。通过上面可以看出,dex2oat接受两种方式指定要编译的文件和输出的文件,分别是通过文件路径或通过文件的描述符。如果是通过文件的描述符的话,dex2oat虽然可以对这个文件进行操作,但并不知道这个文件在什么位置,因此还需要通过以location结尾的参数来告之;而如果是通过文件路径的话,则dex2oat会直接打开这个文件,再对其进行操作。而对于结尾为fd的参数来说,一般都是父进程先将文件打开,获得文件描述符后,在fork出的子进程中掉用execv来运行dex2oat程序,因为子进程是继承父进程所打开的文件描述符的,因此可以直接对其操作。
--oat-symbols=<file.oat>: specifies the oat output destination with full symbols.Example: --oat-symbols=/symbols/system/framework/boot.oat也是指定编译要输出的oat文件,但和--oat-file不同的是,如果使用--oat-symbols,则输出的oat文件会包含所有的符号,而--oat-file则不会。并且--oat-symbols--oat-fd是冲突的,只允许出现一个,如果两个同时出现,则会报错退出。
--image=<file.art>: specifies the output image filename.Example: --image=/system/framework/boot.art指定要编译出的ART镜像文件(Image)所存放的路径。如果指定了这个参数,就说明此次掉用dex2oat是为了编译出系统镜像文件,而不是编译一个普通的应用程序。这个参数和--oat-fd是冲突的,两者不能同时出现,否则dex2oat会报错退出。
--image-classes=<classname-file>: specifies classes to include in an image.Example: --image=frameworks/base/preloaded-classes指定要编译处的ART镜像文件(Image)需要包含哪些类的一个列表。对于Android 5.x和6.x系统来说,这个参数被设置成“/system/etc/preloaded-classes”。
--base=<hex-address>: specifies the base address when creating a boot image.Example: --base=0x50000000指定image加载进内存时,被映射到的起始内存地址。
--boot-image=<file.art>: provide the image file for the boot class path.Example: --boot-image=/system/framework/boot.artDefault: $ANDROID_ROOT/system/framework/boot.art指定系统镜像文件存放的路径。如果不指定的话,默认系统将其设置成“/system/framework/boot.art”。但是,实际上镜像文件并不是存放在这个位置,而是在“/system/framework/<image_isa>/boot.art”,比如在arm平台上(非64位),其镜像文件是放在“/system/framework/arm/boot.art”中的。
--android-root=<path>: used to locate libraries for portable linking.Example: --android-root=out/host/linux-x86Default: $ANDROID_ROOT指定Android系统的根路径。如果不指定的话,默认情况下dex2oat会读取当前系统的环境变量ANDROID_ROOT,将其值作为Android系统的根路径,继续编译下去。如果连环境变量ANDROID_ROOT也读不到的话,则报错退出。一般情况下,Android设备上,环境变量ANDROID_ROOT被设置成了“/system”。
--instruction-set=(arm|arm64|mips|mips64|x86|x86_64): compile for a particular instruction set.Example: --instruction-set=x86Default: arm指定要用什么指令集来编译dex文件。目前共支持六种指令集,三种平台(arm、mips和x86),每种平台有分为32位和64位两种。
--instruction-set-features=...,: Specify instruction set featuresExample: --instruction-set-features=divDefault: default对于一个处理器来说,除了要知道其能执行代码的指令集之外,还需要知道它的一些特别的属性,从而可以在编译中的代码中使用到。对于支持arm指令集的处理器来说,有“smp”(对称多处理器,也就是多核)、“div”(硬件除法器)和“lpae”(大内存模式)三个。
--compile-pic: Force indirect use of code, methods, and classesDefault: disabled用PIC(Position Independent Code,位置无关代码)模式来编译。
--compiler-backend=(Quick|Optimizing): select compiler backend set.Example: --compiler-backend=OptimizingDefault: Quick指定编译器的后端使用哪种模式,可选的是所谓快模式(Quick)或优化模式(Optimizing)。如果没有特别指定的话,编译镜像使用快模式,而编译一般的应用程序则使用优化模式。什么是编译器的后段呢?其实这是LLVM引入的概念。所有的程序先用前端翻译成中间表示层,然后进行优化,最后用后端将优化过的中间表示层代码编译成平台相关的代码。Android虽然没有直接用LLVM编译器(以前也确实用过,但从6.0开始就废弃掉了),但是借鉴了这种编译器的设计结构。值得一提的是,如果使用优化模式,则一定是用PIC模式进行编译。
--compiler-filter=(verify-none|interpret-only|space|balanced|speed|everything|time):select compiler filter.Example: --compiler-filter=everythingDefault: speed指定一些编译选项,默认是speed,以速度优先。
--huge-method-max=<method-instruction-count>: threshold size for a hugemethod for compiler filter tuning.Example: --huge-method-max=10000Default: 10000告诉dex2oat,当发现一个函数内包含的指令数目超过多少时,被当作巨大函数来处理。如果不指定,默认的值是10000
--large-method-max=<method-instruction-count>: threshold size for a largemethod for compiler filter tuning.Example: --large-method-max=600Default: 600告诉dex2oat,当发现一个函数内包含的指令数目超过多少时,被当作大函数来处理。如果不指定,默认的值是600
--small-method-max=<method-instruction-count>: threshold size for a smallmethod for compiler filter tuning.Example: --small-method-max=60Default: 60告诉dex2oat,当发现一个函数内包含的指令数目超过多少时,被当作小函数来处理。如果不指定,默认的值是60
--tiny-method-max=<method-instruction-count>: threshold size for a tinymethod for compiler filter tuning.Example: --tiny-method-max=20Default: 20告诉dex2oat,当发现一个函数内包含的指令数目超过多少时,被当作微型函数来处理。如果不指定,默认的值是20
--num-dex-methods=<method-count>: threshold size for a small dex file forcompiler filter tuning. If the input has fewer than this many methods and the filter is not interpret-only or verify-none, overrides the filter to use speedExample: --num-dex-method=900Default: 900告诉dex2oat,当发现一个dex文件内部包含的方法数少于多少时,将被当作小dex文件来处理。具体的来说,如果一个dex文件内部的方法数小于这个指定值的话,且--compiler-filter编译过滤器不是被设置成verify-none或interpret-only的话,将编译过滤器强制设置成speed。
--include-patch-information: Include patching information so the generated codecan have its base address moved without full recompilation.通知dex2oat要把patch的信息也写入编译出的oat文件中。
--no-include-patch-information: Do not include patching information.通知dex2oat不要把patch的信息也写入编译出的oat文件中。
-g--generate-debug-info: Generate debug information for native debugging, such as stack unwinding information, ELF symbols and DWARF sections.This generates all the available information. Unneeded parts can be stripped using standard command line tools such as strip or objcopy.(enabled by default in debug builds, disabled by default otherwise)通知dex2oat,要在编译出的oat文件中包含调试的信息。
--no-generate-debug-info: Do not generate debug information for native debugging.通知dex2oat,不要在编译出的oat文件中包含调试的信息。
--runtime-arg <argument>: used to specify various arguments for the runtime,such as initial heap size, maximum heap size, and verbose output.Use a separate --runtime-arg switch for each argument.Example: --runtime-arg -Xms256m告诉ART运行时(Runtime)的参数,例如初始堆大小和最大堆大小之类的,且对每一个不通的参数都要在前面加上--runtime-arg。顺便提一句,dex2oat在编译的时候会在内部创建一个ART运行时。
--swap-file=<file-name>:  specifies a file to use for swap.Example: --swap-file=/data/tmp/swap.001指定编译所需要的交换文件的路径。
--swap-fd=<file-descriptor>:  specifies a file to use for swap (by descriptor).Example: --swap-fd=10指定编译所需要的交换文件的文件描述符。这个交换文件是用来临时存放编译过程中所产生的一些数据的,并不是指定了这个交换文件dex2oat就一定会使用,还必须要满足一定条件。如果是编译镜像文件的话,则一定不会用交换文件。如果要编译的所有dex文件的数目小于2的话,也不会使用。最后,如果要编译的所有dex文件的总大小小于20MB的话,也不会用(这么说基本上都不会使用了)。

参考资料:dex2oat程序参数总结

原创粉丝点击