Pass the class loader context to dex2oat when optimizing at runtime
Until now we always passed the special shared library symbol "&" when we
called dex2oat at runtime without an explicit class path.
This CL changes that and passes the class loader context inferred from the
runtime class loaders to dex2oat. If any of the runtime class loaders is
not supported we continue to pass the special library symbol.
Bug: 38138251
Test: m test-art-host
Change-Id: Ica43ee8a3f36dab2d9ed0e634a9f6341379c8e1c
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc
index 92d0f8d..b50aec0 100644
--- a/runtime/class_loader_context.cc
+++ b/runtime/class_loader_context.cc
@@ -263,7 +263,16 @@
return removed_locations;
}
+std::string ClassLoaderContext::EncodeContextForDex2oat(const std::string& base_dir) const {
+ return EncodeContext(base_dir, /*for_dex2oat*/ true);
+}
+
std::string ClassLoaderContext::EncodeContextForOatFile(const std::string& base_dir) const {
+ return EncodeContext(base_dir, /*for_dex2oat*/ false);
+}
+
+std::string ClassLoaderContext::EncodeContext(const std::string& base_dir,
+ bool for_dex2oat) const {
CheckDexFilesOpened("EncodeContextForOatFile");
if (special_shared_library_) {
return OatFile::kSpecialSharedLibrary;
@@ -286,8 +295,17 @@
}
out << GetClassLoaderTypeName(info.type);
out << kClassLoaderOpeningMark;
+ std::set<std::string> seen_locations;
for (size_t k = 0; k < info.opened_dex_files.size(); k++) {
const std::unique_ptr<const DexFile>& dex_file = info.opened_dex_files[k];
+ if (for_dex2oat) {
+ // dex2oat only needs the base location. It cannot accept multidex locations.
+ // So ensure we only add each file once.
+ bool new_insert = seen_locations.insert(dex_file->GetBaseLocation()).second;
+ if (!new_insert) {
+ continue;
+ }
+ }
const std::string& location = dex_file->GetLocation();
if (k > 0) {
out << kClasspathSeparator;
@@ -298,8 +316,11 @@
} else {
out << dex_file->GetLocation().c_str();
}
- out << kDexFileChecksumSeparator;
- out << dex_file->GetLocationChecksum();
+ // dex2oat does not need the checksums.
+ if (!for_dex2oat) {
+ out << kDexFileChecksumSeparator;
+ out << dex_file->GetLocationChecksum();
+ }
}
out << kClassLoaderClosingMark;
}
@@ -593,7 +614,7 @@
}
}
-bool ClassLoaderContext::VerifyClassLoaderContextMatch(const std::string& context_spec) {
+bool ClassLoaderContext::VerifyClassLoaderContextMatch(const std::string& context_spec) const {
ClassLoaderContext expected_context;
if (!expected_context.Parse(context_spec, /*parse_checksums*/ true)) {
LOG(WARNING) << "Invalid class loader context: " << context_spec;