blob: 26d0ff556bc48dbc5c9e75efd80a60c7e8ace293 [file] [log] [blame]
* Copyright (C) 2017 The Android Open Source Project
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
#include "dex2oat_options.h"
#include <memory>
#include "cmdline_parser.h"
#include "driver/compiler_options_map-inl.h"
namespace art {
struct CmdlineType<InstructionSet> : CmdlineTypeParser<InstructionSet> {
Result Parse(const std::string& option) {
InstructionSet set = GetInstructionSetFromString(option.c_str());
if (set == InstructionSet::kNone) {
return Result::Failure(std::string("Not a valid instruction set: '") + option + "'");
return Result::Success(set);
static const char* Name() { return "InstructionSet"; }
static const char* DescribeType() { return "arm|arm64|x86|x86_64|none"; }
#define COMPILER_OPTIONS_MAP_TYPE Dex2oatArgumentMap
#define COMPILER_OPTIONS_MAP_KEY_TYPE Dex2oatArgumentMapKey
#include "driver/compiler_options_map-storage.h"
// Specify storage for the Dex2oatOptions keys.
#define DEX2OAT_OPTIONS_KEY(Type, Name, ...) \
const Dex2oatArgumentMap::Key<Type> Dex2oatArgumentMap::Name {__VA_ARGS__};
#include "dex2oat_options.def"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wframe-larger-than="
using M = Dex2oatArgumentMap;
using Parser = CmdlineParser<Dex2oatArgumentMap, Dex2oatArgumentMap::Key>;
using Builder = Parser::Builder;
static void AddInputMappings(Builder& builder) {
.WithHelp("Specifies a .dex, .jar, or .apk file to compile.\n"
"Eg: --dex-file=/system/framework/core.jar")
.WithHelp("specifies an alternative dex location to encode in the oat file for the\n"
"corresponding --dex-file argument. The first --dex-location corresponds to\n"
"the first --dex-file, the second to the second and so on.\n"
"Eg: --dex-file=/home/build/out/system/framework/core.jar\n"
" --dex-location=/system/framework/core.jar")
.WithHelp("specifies a file descriptor of a zip file containing a classes.dex file to\n"
"compile. Eg: --zip-fd=5")
.WithHelp("Specifies a symbolic name for the file corresponding to the FD given by\n"
.WithHelp("provide the image file for the boot class path.\n"
"Do not include the arch as part of the name, it is added automatically.\n"
"Example: --boot-image=/system/framework/\n"
" (specifies /system/framework/<arch>/ as the image file)\n"
" (specifies <bcp-path1>/<arch>/ as the image file and\n"
" <bcp-path2>/<arch>/ as the image extension file\n"
" with paths taken from corresponding boot class path components)\n"
"Example: --boot-image=/apex/*:*\n"
" (specifies /apex/<arch>/ as the image\n"
" file and search for extensions in /framework/system and boot\n"
" class path components' paths)\n"
"Default: $ANDROID_ROOT/system/framework/")
static void AddGeneratedArtifactMappings(Builder& builder) {
.WithHelp("specifies the vdex input source via a file descriptor.")
.WithHelp("specifies the vdex input source via a filename.")
.WithHelp("specifies the vdex output destination via a file descriptor.")
.WithHelp("specifies the vdex output destination via a filename.")
.WithHelp("specifies the dm output destination via a file descriptor.")
.WithHelp("specifies the dm output destination via a filename.")
.WithHelp(" Specifies an oat output destination via a filename.\n"
"Eg: --oat-file=/system/framework/boot.oat")
.WithHelp("Specifies a symbolized oat output destination.\n"
"Eg: --oat-symbols=symbols/system/framework/boot.oat")
.WithHelp("remove all debugging sections at the end (but keep mini-debug-info).\n"
"This is equivalent to the \"strip\" command as build post-processing step.\n"
"It is intended to be used with --oat-symbols and it happens after it.\n"
"Eg: --oat-symbols=/symbols/system/framework/boot.oat")
.WithHelp("Specifies the oat output destination via a file descriptor. Eg: --oat-fd=5")
.WithHelp("specifies a symbolic name for the file corresponding to the file descriptor\n"
"specified by --oat-fd.\n"
"Eg: --oat-location=/data/dalvik-cache/system@app@Calculator.apk.oat")
static void AddImageMappings(Builder& builder) {
.WithHelp("specifies an output image filename. Eg: --image=/system/framework/")
.WithHelp("specifies an output image file descriptor. Cannot be used with --image.\n"
"Eg: --image-fd=7")
.WithHelp("Specifies the base address when creating a boot image. Eg: --base=0x50000000")
.WithMetavar("{hex address}")
.WithHelp("Specify a file name for app image. Only used if a profile is passed in.")
.WithHelp("Specify a file descriptor for app image. Only used if a profile is passed in.")
.Define({"--multi-image", "--single-image"})
.WithValues({true, false})
.WithHelp("Specifies if separate oat and image files should be generated for each dex\n"
"file. --multi-image is default for boot image and --single-image for app\n"
.WithHelp("list of known dirty objects in the image. The image writer will group them"
" together")
.WithHelp("file with a list of updatable boot class path packages. Classes in these\n"
"packages and sub-packages shall not be resolved during app compilation to\n"
"avoid AOT assumptions being invalidated after applying updates to these\n"
.WithValueMap({{"lz4", ImageHeader::kStorageModeLZ4},
{"lz4hc", ImageHeader::kStorageModeLZ4HC},
{"uncompressed", ImageHeader::kStorageModeUncompressed}})
.WithHelp("Which format to store the image Defaults to uncompressed. Eg:"
" --image-format=lz4")
static void AddSwapMappings(Builder& builder) {
.WithHelp("Specify a file to use for swap. Eg: --swap-file=/data/tmp/swap.001")
.WithHelp("Specify a file to use for swap by file-descriptor. Eg: --swap-fd=3")
.WithType<unsigned int>()
.WithHelp("specifies the minimum total dex file size in bytes to allow the use of swap.")
.WithType<unsigned int>()
.WithHelp("specifies the minimum number of dex file to allow the use of swap.")
static void AddCompilerMappings(Builder& builder) {
.WithHelp("Specify profiler output file to use for compilation using a filename.")
.WithHelp("Specify profiler output file to use for compilation using a file-descriptor.")
static void AddTargetMappings(Builder& builder) {
.WithHelp("Compile for a particular instruction set.")
.WithHelp("Specify instruction set features using variant name.\n"
"Eg: --instruction-set-variant=silvermont")
.WithMetavar("{Variant Name}")
.WithHelp("Specify instruction set features.\n"
"On target the value 'runtime' can be used to detect features at run time.\n"
"If target does not support run-time detection the value 'runtime'\n"
"has the same effect as the value 'default'.\n"
"Note: the value 'runtime' has no effect if it is used on host.\n"
"Example: --instruction-set-features=div\n"
"Default: default")
Parser CreateDex2oatArgumentParser() {
std::unique_ptr<Builder> parser_builder = std::make_unique<Builder>();
Define({"--watch-dog", "--no-watch-dog"})
.WithHelp("Enable or disable the watchdog timer.")
.WithValues({true, false})
.WithHelp("Set the watchdog timeout value in seconds.")
.WithType<unsigned int>()
.WithHelp("specifies the number of threads used for compilation. Default is the number\n"
"of detected hardware threads available on the host system.")
.WithHelp("sets the cpu affinitiy to the given <set>. The <set> is a comma separated\n"
"list of cpus. Eg: --cpu-set=0,1,2,3")
.WithHelp("Used to locate libraries for portable linking.\n"
"Eg: --android-root=out/host/linux-x86\n"
"Default: $ANDROID_ROOT")
.WithValueMap({{"Quick", Compiler::Kind::kQuick},
{"Optimizing", Compiler::Kind::kOptimizing}})
.WithHelp("Select a compiler backend set. Default: optimizing")
.WithHelp("Run in host mode")
.WithHelp("Avoid storing the invocation args in the key-value store. Used to test\n"
"determinism with different args.")
.WithType<unsigned int>()
.WithHelp("Specifies the minimum total dex file size in bytes to consider the input\n"
"\"very large\" and reduce compilation done.")
.WithHelp("Force the compiler to emit a deterministic output")
.WithValueMap({{"true", linker::CopyOption::kOnlyIfCompressed},
{"false", linker::CopyOption::kNever},
{"always", linker::CopyOption::kAlways}})
.WithHelp("enable|disable copying the dex files into the output vdex.")
.WithHelp("Disables automatic no-inline for core-oj on host. Has no effect on target."
.WithHelp("Write the invocation commandline to the given file for later use. Used to\n"
"test determinism with different args.")
.WithHelp("Directory used to resolve relative class paths.")
.WithHelp("a string specifying the intended runtime loading context for the compiled\n"
"dex files.")
.WithHelp("a colon-separated list of file descriptors for dex files in\n"
"--class-loader-context. Their order must be the same as dex files in a\n"
"flattened class loader context")
.WithHelp("a string specifying the intended runtime loading context that is stored\n"
"in the oat file. Overrides --class-loader-context. Note that this ignores\n"
"the classpath_dir arg.\n"
"It describes how the class loader chain should be built in order to ensure\n"
"classes are resolved during dex2aot as they would be resolved at runtime.\n"
"This spec will be encoded in the oat file. If at runtime the dex file is\n"
"loaded in a different context, the oat file will be rejected.\n"
"The chain is interpreted in the natural 'parent order', meaning that class\n"
"loader 'i+1' will be the parent of class loader 'i'.\n"
"The compilation sources will be appended to the classpath of the first class\n"
"E.g. if the context is 'PCL[lib1.dex];DLC[lib2.dex]' and \n"
"--dex-file=src.dex then dex2oat will setup a PathClassLoader with classpath \n"
"'lib1.dex:src.dex' and set its parent to a DelegateLastClassLoader with \n"
"classpath 'lib2.dex'.\n"
"Note that the compiler will be tolerant if the source dex files specified\n"
"with --dex-file are found in the classpath. The source dex files will be\n"
"removed from any class loader's classpath possibly resulting in empty\n"
"class loaders.\n"
"Example: --class-loader-context=PCL[lib1.dex:lib2.dex];DLC[lib3.dex]")
.WithValueMap({{"none", CompactDexLevel::kCompactDexLevelNone},
{"fast", CompactDexLevel::kCompactDexLevelFast}})
.WithHelp("None avoids generating compact dex, fast generates compact dex with low\n"
"compile time. If speed-profile is specified as the compiler filter and the\n"
"profile is not empty, the default compact dex level is always used.")
.Define("--runtime-arg _")
.WithHelp("used to specify various arguments for the runtime, such as initial heap\n"
"size, maximum heap size, and verbose output. Use a separate --runtime-arg\n"
"switch for each argument.\n"
"Example: --runtime-arg -Xms256m")
.WithHelp("optional metadata specifying the reason for compiling the apk. If specified,\n"
"the string will be embedded verbatim in the key value store of the oat file.\n"
"Example: --compilation-reason=install")
.WithHelp("Compiles dex files individually, unloading classes in between compiling each"
" file.")
return parser_builder->Build();
std::unique_ptr<Dex2oatArgumentMap> Dex2oatArgumentMap::Parse(int argc,
const char** argv,
std::string* error_msg) {
Parser parser = CreateDex2oatArgumentParser();
CmdlineResult parse_result = parser.Parse(argv, argc);
if (!parse_result.IsSuccess()) {
*error_msg = parse_result.GetMessage();
return nullptr;
return std::make_unique<Dex2oatArgumentMap>(parser.ReleaseArgumentsMap());
#pragma GCC diagnostic pop
} // namespace art