summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/class_loader_context.cc13
-rw-r--r--runtime/class_loader_context_test.cc17
2 files changed, 22 insertions, 8 deletions
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc
index afdbb4a38a..e6cb6d6f8e 100644
--- a/runtime/class_loader_context.cc
+++ b/runtime/class_loader_context.cc
@@ -696,20 +696,17 @@ void ClassLoaderContext::EncodeContextInternal(const ClassLoaderInfo& info,
}
}
- for (size_t k = 0; k < info.opened_dex_files.size();) {
- const std::unique_ptr<const DexFile>& dex_file = info.opened_dex_files[k];
- uint32_t checksum = DexFileLoader::GetMultiDexChecksum(info.opened_dex_files, &k);
- CHECK(!DexFileLoader::IsMultiDexLocation(dex_file->GetLocation()));
-
+ DCHECK_EQ(info.classpath.size(), info.checksums.size());
+ for (size_t i = 0; i < info.classpath.size(); i++) {
if (for_dex2oat) {
// De-duplicate locations.
- bool new_insert = seen_locations.insert(dex_file->GetLocation()).second;
+ bool new_insert = seen_locations.insert(info.classpath[i]).second;
if (!new_insert) {
continue;
}
}
- std::string location = dex_file->GetLocation();
+ std::string location = info.classpath[i];
// If there is a stored class loader remap, fix up the multidex strings.
if (!remap.empty()) {
auto it = remap.find(location);
@@ -720,7 +717,7 @@ void ClassLoaderContext::EncodeContextInternal(const ClassLoaderInfo& info,
// dex2oat does not need the checksums.
if (!for_dex2oat) {
- checksums.push_back(checksum);
+ checksums.push_back(info.checksums[i]);
}
}
EncodeClassPath(base_dir, locations, checksums, info.type, out);
diff --git a/runtime/class_loader_context_test.cc b/runtime/class_loader_context_test.cc
index 47a7f2d739..2a6d87753a 100644
--- a/runtime/class_loader_context_test.cc
+++ b/runtime/class_loader_context_test.cc
@@ -1215,6 +1215,23 @@ TEST_F(ClassLoaderContextTest, EncodeInOatFile) {
ASSERT_EQ(expected_encoding, context->EncodeContextForOatFile(""));
}
+// Same as above, but passes `only_read_checksums=true` to `OpenDexFiles`.
+TEST_F(ClassLoaderContextTest, EncodeInOatFileOnlyReadChecksums) {
+ std::string dex1_name = GetTestDexFileName("Main");
+ std::string dex2_name = GetTestDexFileName("MyClass");
+ std::unique_ptr<ClassLoaderContext> context =
+ ClassLoaderContext::Create("PCL[" + dex1_name + ":" + dex2_name + "]");
+ ASSERT_TRUE(context->OpenDexFiles(
+ /*classpath_dir=*/"", /*context_fds=*/{}, /*only_read_checksums=*/true));
+
+ std::vector<std::unique_ptr<const DexFile>> dex1 = OpenTestDexFiles("Main");
+ std::vector<std::unique_ptr<const DexFile>> dex2 = OpenTestDexFiles("MyClass");
+ std::string encoding = context->EncodeContextForOatFile("");
+ std::string expected_encoding =
+ "PCL[" + CreateClassPathWithChecksums(dex1) + ":" + CreateClassPathWithChecksums(dex2) + "]";
+ ASSERT_EQ(expected_encoding, context->EncodeContextForOatFile(""));
+}
+
TEST_F(ClassLoaderContextTest, EncodeInOatFileIMC) {
jobject class_loader_a = LoadDexInPathClassLoader("Main", nullptr);
jobject class_loader_b = LoadDexInInMemoryDexClassLoader("MyClass", class_loader_a);