diff options
| -rw-r--r-- | dex2oat/dex2oat.cc | 14 | ||||
| -rw-r--r-- | dex2oat/dex2oat_options.cc | 5 | ||||
| -rw-r--r-- | dex2oat/dex2oat_options.def | 1 | ||||
| -rw-r--r-- | dex2oat/dex2oat_test.cc | 50 | ||||
| -rw-r--r-- | runtime/oat.h | 1 | ||||
| -rw-r--r-- | runtime/oat_file.cc | 4 | ||||
| -rw-r--r-- | runtime/oat_file.h | 2 |
7 files changed, 76 insertions, 1 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index c4e53987eb..64db7be79c 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -456,6 +456,12 @@ NO_RETURN static void Usage(const char* fmt, ...) { UsageError(" --deduplicate-code=true|false: enable|disable code deduplication. Deduplicated"); UsageError(" code will have an arbitrary symbol tagged with [DEDUPED]."); UsageError(""); + UsageError(" --compilation-reason=<string>: optional metadata specifying the reason for"); + UsageError(" compiling the apk. If specified, the string will be embedded verbatim in"); + UsageError(" the key value store of the oat file."); + UsageError(""); + UsageError(" Example: --compilation-reason=install"); + UsageError(""); std::cerr << "See log for usage error information\n"; exit(EXIT_FAILURE); } @@ -1212,6 +1218,7 @@ class Dex2Oat FINAL { AssignIfExists(args, M::ClasspathDir, &classpath_dir_); AssignIfExists(args, M::DirtyImageObjects, &dirty_image_objects_filename_); AssignIfExists(args, M::ImageFormat, &image_storage_mode_); + AssignIfExists(args, M::CompilationReason, &compilation_reason_); AssignIfExists(args, M::Backend, &compiler_kind_); parser_options->requested_specific_compiler = args.Exists(M::Backend); @@ -1512,6 +1519,10 @@ class Dex2Oat FINAL { return dex2oat::ReturnCode::kOther; } + if (!compilation_reason_.empty()) { + key_value_store_->Put(OatHeader::kCompilationReasonKey, compilation_reason_); + } + if (IsBootImage() && image_filenames_.size() > 1) { // If we're compiling the boot image, store the boot classpath into the Key-Value store. // We need this for the multi-image case. @@ -2907,6 +2918,9 @@ class Dex2Oat FINAL { // Whether the given input vdex is also the output. bool update_input_vdex_ = false; + // The reason for invoking the compiler. + std::string compilation_reason_; + DISALLOW_IMPLICIT_CONSTRUCTORS(Dex2Oat); }; diff --git a/dex2oat/dex2oat_options.cc b/dex2oat/dex2oat_options.cc index 0eecc84605..4b6f8a4a54 100644 --- a/dex2oat/dex2oat_options.cc +++ b/dex2oat/dex2oat_options.cc @@ -246,7 +246,10 @@ static Parser CreateArgumentParser() { .IntoKey(M::CompactDexLevel) .Define("--runtime-arg _") .WithType<std::vector<std::string>>().AppendValues() - .IntoKey(M::RuntimeOptions); + .IntoKey(M::RuntimeOptions) + .Define("--compilation-reason=_") + .WithType<std::string>() + .IntoKey(M::CompilationReason); AddCompilerOptionsArgumentParserOptions<Dex2oatArgumentMap>(*parser_builder); diff --git a/dex2oat/dex2oat_options.def b/dex2oat/dex2oat_options.def index 9a8bdf4aee..a1646aafe3 100644 --- a/dex2oat/dex2oat_options.def +++ b/dex2oat/dex2oat_options.def @@ -89,5 +89,6 @@ DEX2OAT_OPTIONS_KEY (std::string, ClasspathDir) DEX2OAT_OPTIONS_KEY (std::string, ClassLoaderContext) DEX2OAT_OPTIONS_KEY (std::string, DirtyImageObjects) DEX2OAT_OPTIONS_KEY (std::vector<std::string>, RuntimeOptions) +DEX2OAT_OPTIONS_KEY (std::string, CompilationReason) #undef DEX2OAT_OPTIONS_KEY diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc index 7948bcab31..4ac8e6a3eb 100644 --- a/dex2oat/dex2oat_test.cc +++ b/dex2oat/dex2oat_test.cc @@ -1731,4 +1731,54 @@ TEST_F(Dex2oatTest, StderrLoggerOutput) { EXPECT_NE(std::string::npos, output_.find("dex2oat took")); } +TEST_F(Dex2oatTest, VerifyCompilationReason) { + std::string dex_location = GetScratchDir() + "/Dex2OatCompilationReason.jar"; + std::string odex_location = GetOdexDir() + "/Dex2OatCompilationReason.odex"; + + // Test file doesn't matter. + Copy(GetDexSrc1(), dex_location); + + GenerateOdexForTest(dex_location, + odex_location, + CompilerFilter::kVerify, + { "--compilation-reason=install" }, + true); + std::string error_msg; + std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(), + odex_location.c_str(), + nullptr, + nullptr, + false, + /*low_4gb*/false, + dex_location.c_str(), + &error_msg)); + ASSERT_TRUE(odex_file != nullptr); + ASSERT_STREQ("install", odex_file->GetCompilationReason()); +} + +TEST_F(Dex2oatTest, VerifyNoCompilationReason) { + std::string dex_location = GetScratchDir() + "/Dex2OatNoCompilationReason.jar"; + std::string odex_location = GetOdexDir() + "/Dex2OatNoCompilationReason.odex"; + + // Test file doesn't matter. + Copy(GetDexSrc1(), dex_location); + + GenerateOdexForTest(dex_location, + odex_location, + CompilerFilter::kVerify, + {}, + true); + std::string error_msg; + std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(), + odex_location.c_str(), + nullptr, + nullptr, + false, + /*low_4gb*/false, + dex_location.c_str(), + &error_msg)); + ASSERT_TRUE(odex_file != nullptr); + ASSERT_EQ(nullptr, odex_file->GetCompilationReason()); +} + } // namespace art diff --git a/runtime/oat.h b/runtime/oat.h index 8f81010a06..af14b3e601 100644 --- a/runtime/oat.h +++ b/runtime/oat.h @@ -45,6 +45,7 @@ class PACKED(4) OatHeader { static constexpr const char* kClassPathKey = "classpath"; static constexpr const char* kBootClassPathKey = "bootclasspath"; static constexpr const char* kConcurrentCopying = "concurrent-copying"; + static constexpr const char* kCompilationReasonKey = "compilation-reason"; static constexpr const char kTrueValue[] = "true"; static constexpr const char kFalseValue[] = "false"; diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc index 600449ccb9..0852da5644 100644 --- a/runtime/oat_file.cc +++ b/runtime/oat_file.cc @@ -1924,6 +1924,10 @@ std::string OatFile::GetClassLoaderContext() const { return GetOatHeader().GetStoreValueByKey(OatHeader::kClassPathKey); } +const char* OatFile::GetCompilationReason() const { + return GetOatHeader().GetStoreValueByKey(OatHeader::kCompilationReasonKey); +} + OatFile::OatClass OatFile::FindOatClass(const DexFile& dex_file, uint16_t class_def_idx, bool* found) { diff --git a/runtime/oat_file.h b/runtime/oat_file.h index 46c692e568..802adc3a36 100644 --- a/runtime/oat_file.h +++ b/runtime/oat_file.h @@ -130,6 +130,8 @@ class OatFile { std::string GetClassLoaderContext() const; + const char* GetCompilationReason() const; + const std::string& GetLocation() const { return location_; } |