summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2023-11-17 17:02:09 +0000
committer Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2023-11-17 19:09:04 +0000
commitcb7cfe5dec30e5ec802cfd4eb872f9a7669bac8e (patch)
tree6d1e16fa34128a451809ea24b5c6f34106d8986b
parentde6567b8fc3a08ac70ffbfef0fb4d73009b1d895 (diff)
Fix the ClassLoaderContext mismatch error message.
Before this change, ClassLoaderContext encoding relied on `info.opened_dex_files`. This doesn't work for the error message presentation because we no longer open dex files for ClassLoaderContext verification since https://r.android.com/1531339. This problem leads to empty dex paths in the error message and causes confusion. Note that it does not affect the correctness of ClassLoaderContext verification. This change fixes the presentation problem. Bug: 311126962 Test: m test-art-host-gtest-art_runtime_tests Change-Id: I83972aba7d06a086b7684e2c7ac7640e135e0ee0
-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);