diff options
-rw-r--r-- | runtime/class_loader_context.cc | 18 | ||||
-rw-r--r-- | runtime/class_loader_context_test.cc | 11 |
2 files changed, 20 insertions, 9 deletions
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc index 6dc94fbd25..3bb7e426a1 100644 --- a/runtime/class_loader_context.cc +++ b/runtime/class_loader_context.cc @@ -699,22 +699,22 @@ 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().c_str())); 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(DexFileLoader::GetBaseLocation(dex_file->GetLocation())).second; - CHECK(new_insert); + // De-duplicate locations. + bool new_insert = seen_locations.insert(dex_file->GetLocation()).second; + if (!new_insert) { + continue; + } } 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); + auto it = remap.find(location); + CHECK(it != remap.end()) << location; + location = it->second; } locations.emplace_back(std::move(location)); diff --git a/runtime/class_loader_context_test.cc b/runtime/class_loader_context_test.cc index 98b8eed5d5..47a7f2d739 100644 --- a/runtime/class_loader_context_test.cc +++ b/runtime/class_loader_context_test.cc @@ -1258,6 +1258,17 @@ TEST_F(ClassLoaderContextTest, EncodeForDex2oatIMC) { ASSERT_EQ(expected_encoding, context->EncodeContextForDex2oat("")); } +TEST_F(ClassLoaderContextTest, EncodeForDex2oatDuplicates) { + std::string dex_name = GetTestDexFileName("Main"); + std::unique_ptr<ClassLoaderContext> context = + ClassLoaderContext::Create("PCL[" + dex_name + ":" + dex_name + "]"); + ASSERT_TRUE(context->OpenDexFiles()); + + std::string encoding = context->EncodeContextForDex2oat(""); + std::string expected_encoding = "PCL[" + dex_name + "]"; + ASSERT_EQ(expected_encoding, context->EncodeContextForDex2oat("")); +} + TEST_F(ClassLoaderContextTest, EncodeContextsSinglePath) { jobject class_loader = LoadDexInPathClassLoader("Main", nullptr); std::unique_ptr<ClassLoaderContext> context = |