summaryrefslogtreecommitdiff
path: root/runtime/class_loader_context.cc
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2018-04-16 14:40:56 -0700
committer Mathieu Chartier <mathieuc@google.com> 2018-04-18 10:13:00 -0700
commit0d6736f8355be80ceb6ab853f8fdad45028f071f (patch)
tree24356c1dcd09eabcadf52bff8fc90f54232bda0a /runtime/class_loader_context.cc
parent8548de1c9f403b917eb2ad74a9922127da61171d (diff)
Add arg for overwriting class loader class path
Added stored_context srgument to EncodeContextForOatFile that overwrites the class path when non-null. This is used by the --stored-class-loader-context argument. Fixed the test. Bug: 70934104 Bug: 67345922 Test: test-art-host-gtest (cherry picked from commit c4440775c5627fed9701e14a1f9d14dca27ed176) Merged-In: If877d8cfe9d34eeaa941e9f6df2e12539d9c4a6f Change-Id: I16fde69bad07ae173fa30dff2fcda50b000779a5
Diffstat (limited to 'runtime/class_loader_context.cc')
-rw-r--r--runtime/class_loader_context.cc36
1 files changed, 29 insertions, 7 deletions
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc
index 216ad8f794..4afc44cb91 100644
--- a/runtime/class_loader_context.cc
+++ b/runtime/class_loader_context.cc
@@ -254,6 +254,7 @@ bool ClassLoaderContext::OpenDexFiles(InstructionSet isa, const std::string& cla
// This will allow the context to VerifyClassLoaderContextMatch which expects or multidex
// location in the class paths.
// Note that this will also remove the paths that could not be opened.
+ info.original_classpath = std::move(info.classpath);
info.classpath.clear();
info.checksums.clear();
for (size_t k = opened_dex_files_index; k < info.opened_dex_files.size(); k++) {
@@ -294,20 +295,26 @@ bool ClassLoaderContext::RemoveLocationsFromClassPaths(
}
std::string ClassLoaderContext::EncodeContextForDex2oat(const std::string& base_dir) const {
- return EncodeContext(base_dir, /*for_dex2oat*/ true);
+ return EncodeContext(base_dir, /*for_dex2oat*/ true, /*stored_context*/ nullptr);
}
-std::string ClassLoaderContext::EncodeContextForOatFile(const std::string& base_dir) const {
- return EncodeContext(base_dir, /*for_dex2oat*/ false);
+std::string ClassLoaderContext::EncodeContextForOatFile(const std::string& base_dir,
+ ClassLoaderContext* stored_context) const {
+ return EncodeContext(base_dir, /*for_dex2oat*/ false, stored_context);
}
std::string ClassLoaderContext::EncodeContext(const std::string& base_dir,
- bool for_dex2oat) const {
+ bool for_dex2oat,
+ ClassLoaderContext* stored_context) const {
CheckDexFilesOpened("EncodeContextForOatFile");
if (special_shared_library_) {
return OatFile::kSpecialSharedLibrary;
}
+ if (stored_context != nullptr) {
+ DCHECK_EQ(class_loader_chain_.size(), stored_context->class_loader_chain_.size());
+ }
+
std::ostringstream out;
if (class_loader_chain_.empty()) {
// We can get in this situation if the context was created with a class path containing the
@@ -326,6 +333,15 @@ std::string ClassLoaderContext::EncodeContext(const std::string& base_dir,
out << GetClassLoaderTypeName(info.type);
out << kClassLoaderOpeningMark;
std::set<std::string> seen_locations;
+ SafeMap<std::string, std::string> remap;
+ if (stored_context != nullptr) {
+ DCHECK_EQ(info.original_classpath.size(),
+ stored_context->class_loader_chain_[i].classpath.size());
+ for (size_t k = 0; k < info.original_classpath.size(); ++k) {
+ // Note that we don't care if the same name appears twice.
+ remap.Put(info.original_classpath[k], stored_context->class_loader_chain_[i].classpath[k]);
+ }
+ }
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) {
@@ -337,7 +353,14 @@ std::string ClassLoaderContext::EncodeContext(const std::string& base_dir,
continue;
}
}
- const std::string& location = dex_file->GetLocation();
+ std::string location = dex_file->GetLocation();
+ // If there is a stored class loader remap, fix up the multidex strings.
+ if (!remap.empty()) {
+ std::string base_dex_location = DexFileLoader::GetBaseLocation(location);
+ auto it = remap.find(base_dex_location);
+ CHECK(it != remap.end()) << base_dex_location;
+ location = it->second + DexFileLoader::GetMultiDexSuffix(location);
+ }
if (k > 0) {
out << kClasspathSeparator;
}
@@ -345,7 +368,7 @@ std::string ClassLoaderContext::EncodeContext(const std::string& base_dir,
if (!base_dir.empty() && location.substr(0, base_dir.length()) == base_dir) {
out << location.substr(base_dir.length() + 1).c_str();
} else {
- out << dex_file->GetLocation().c_str();
+ out << location.c_str();
}
// dex2oat does not need the checksums.
if (!for_dex2oat) {
@@ -776,4 +799,3 @@ jclass ClassLoaderContext::GetClassLoaderClass(ClassLoaderType type) {
}
} // namespace art
-