Add compact-dex-level argument to dex2oat
No-op right now but will be passed to dexlayout to generate
CompactDex.
Added the following dex2oat options:
--compact-dex-level=none generates no CompactDex.
--compact-dex-level=fast generates CompactDex with optimizations
that are fast and take low resources.
Will add test in follow up through dex2oat/compact_dex_file_test.
Test: test-art-host-gtest
Bug: 63756964
Change-Id: If9d6f4a383bdad1086b3e37daefe108bdd5cd36d
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 3abf36f..49fee17 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -448,6 +448,9 @@
UsageError(" --dirty-image-objects=<directory-path>: list of known dirty objects in the image.");
UsageError(" The image writer will group them together.");
UsageError("");
+ UsageError(" --compact-dex-level=none|fast: None avoids generating compact dex, fast");
+ UsageError(" generates compact dex with fast optimiations.");
+ UsageError("");
std::cerr << "See log for usage error information\n";
exit(EXIT_FAILURE);
}
@@ -1163,6 +1166,7 @@
std::unique_ptr<ParserOptions> parser_options(new ParserOptions());
+ AssignIfExists(args, M::CompactDexLevel, &compact_dex_level_);
AssignIfExists(args, M::DexFiles, &dex_filenames_);
AssignIfExists(args, M::DexLocations, &dex_locations_);
AssignIfExists(args, M::OatFiles, &oat_filenames_);
@@ -2226,8 +2230,12 @@
return UseProfile();
}
+ bool DoGenerateCompactDex() const {
+ return compact_dex_level_ != CompactDexLevel::kCompactDexLevelNone;
+ }
+
bool DoDexLayoutOptimizations() const {
- return DoProfileGuidedOptimizations();
+ return DoProfileGuidedOptimizations() || DoGenerateCompactDex();
}
bool DoOatLayoutOptimizations() const {
@@ -2814,6 +2822,7 @@
// Dex files we are compiling, does not include the class path dex files.
std::vector<const DexFile*> dex_files_;
std::string no_inline_from_string_;
+ CompactDexLevel compact_dex_level_ = CompactDexLevel::kCompactDexLevelNone;
std::vector<std::unique_ptr<linker::ElfWriter>> elf_writers_;
std::vector<std::unique_ptr<linker::OatWriter>> oat_writers_;
diff --git a/dex2oat/dex2oat_options.cc b/dex2oat/dex2oat_options.cc
index 43e6c4d..3606c61 100644
--- a/dex2oat/dex2oat_options.cc
+++ b/dex2oat/dex2oat_options.cc
@@ -239,6 +239,11 @@
.Define("--class-loader-context=_")
.WithType<std::string>()
.IntoKey(M::ClassLoaderContext)
+ .Define("--compact-dex-level=_")
+ .WithType<CompactDexLevel>()
+ .WithValueMap({{"none", CompactDexLevel::kCompactDexLevelNone},
+ {"fast", CompactDexLevel::kCompactDexLevelFast}})
+ .IntoKey(M::CompactDexLevel)
.Define("--runtime-arg _")
.WithType<std::vector<std::string>>().AppendValues()
.IntoKey(M::RuntimeOptions);
diff --git a/dex2oat/dex2oat_options.def b/dex2oat/dex2oat_options.def
index 83a3035..9362a3d 100644
--- a/dex2oat/dex2oat_options.def
+++ b/dex2oat/dex2oat_options.def
@@ -34,6 +34,7 @@
//
// Parse-able keys from the command line.
+DEX2OAT_OPTIONS_KEY (CompactDexLevel, CompactDexLevel)
DEX2OAT_OPTIONS_KEY (std::vector<std::string>, DexFiles)
DEX2OAT_OPTIONS_KEY (std::vector<std::string>, DexLocations)
DEX2OAT_OPTIONS_KEY (int, ZipFd)
diff --git a/dex2oat/dex2oat_options.h b/dex2oat/dex2oat_options.h
index a4c7186..f8198ee 100644
--- a/dex2oat/dex2oat_options.h
+++ b/dex2oat/dex2oat_options.h
@@ -22,6 +22,7 @@
#include <vector>
#include "base/variant_map.h"
+#include "cdex/compact_dex_level.h"
#include "cmdline_types.h" // TODO: don't need to include this file here
#include "compiler.h"
#include "driver/compiler_options_map.h"
diff --git a/runtime/cdex/compact_dex_level.h b/runtime/cdex/compact_dex_level.h
new file mode 100644
index 0000000..b824462
--- /dev/null
+++ b/runtime/cdex/compact_dex_level.h
@@ -0,0 +1,34 @@
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_CDEX_COMPACT_DEX_LEVEL_H_
+#define ART_RUNTIME_CDEX_COMPACT_DEX_LEVEL_H_
+
+#include "dex_file.h"
+
+namespace art {
+
+// Optimization level for compact dex generation.
+enum class CompactDexLevel {
+ // Level none means not generated.
+ kCompactDexLevelNone,
+ // Level fast means optimizations that don't take many resources to perform.
+ kCompactDexLevelFast,
+};
+
+} // namespace art
+
+#endif // ART_RUNTIME_CDEX_COMPACT_DEX_LEVEL_H_