Move dex files dependencies (en/de)coding to ClassLoaderContext
Encode the full class loader context in the oat file (rather than just a
list of dex files).
The context encoding matches the format used by dex2oat with the addition
of checksums.
Temporarily assert that at decoding time we are operating on a
PathClassLoader until the checking logic covers all supported cases.
Also, bump the version of the oat file because the format of the classpath
key has changed.
This is a transition step to minimize the size of follow up changes.
Test: m test-art-host
Bug: 38138251
Change-Id: I9ec0cfe092ce1afccb741a36e737896880d5f1d2
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index 1505eb5..b08b055 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -937,7 +937,7 @@
return GetOdexDir() + "/Context.odex";
}
- const char* kEmptyClassPathKey = "";
+ const char* kEmptyClassPathKey = "PCL[]";
};
TEST_F(Dex2oatClassLoaderContextTest, InvalidContext) {
@@ -961,10 +961,10 @@
TEST_F(Dex2oatClassLoaderContextTest, ContextWithOtherDexFiles) {
std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles("Nested");
- std::string expected_classpath_key =
- OatFile::EncodeDexFileDependencies(MakeNonOwningPointerVector(dex_files), "");
std::string context = "PCL[" + dex_files[0]->GetLocation() + "]";
+ std::string expected_classpath_key = "PCL[" +
+ dex_files[0]->GetLocation() + "*" + std::to_string(dex_files[0]->GetLocationChecksum()) + "]";
RunTest(context.c_str(), expected_classpath_key.c_str(), true);
}
@@ -974,7 +974,7 @@
std::string context = "PCL[" + stripped_classpath + "]";
// Expect an empty context because stripped dex files cannot be open.
- RunTest(context.c_str(), /*expected_classpath_key*/ "" , /*expected_success*/ true);
+ RunTest(context.c_str(), kEmptyClassPathKey , /*expected_success*/ true);
}
TEST_F(Dex2oatClassLoaderContextTest, ContextWithStrippedDexFilesBackedByOdex) {
@@ -993,19 +993,26 @@
Copy(GetStrippedDexSrc1(), stripped_classpath);
std::string context = "PCL[" + stripped_classpath + "]";
- std::string expected_classpath;
+ std::string expected_classpath_key;
{
// Open the oat file to get the expected classpath.
OatFileAssistant oat_file_assistant(stripped_classpath.c_str(), kRuntimeISA, false);
std::unique_ptr<OatFile> oat_file(oat_file_assistant.GetBestOatFile());
std::vector<std::unique_ptr<const DexFile>> oat_dex_files =
OatFileAssistant::LoadDexFiles(*oat_file, stripped_classpath.c_str());
- expected_classpath = OatFile::EncodeDexFileDependencies(
- MakeNonOwningPointerVector(oat_dex_files), "");
+ expected_classpath_key = "PCL[";
+ for (size_t i = 0; i < oat_dex_files.size(); i++) {
+ if (i > 0) {
+ expected_classpath_key + ":";
+ }
+ expected_classpath_key += oat_dex_files[i]->GetLocation() + "*" +
+ std::to_string(oat_dex_files[i]->GetLocationChecksum());
+ }
+ expected_classpath_key += "]";
}
RunTest(context.c_str(),
- expected_classpath.c_str(),
+ expected_classpath_key.c_str(),
/*expected_success*/ true,
/*use_second_source*/ true);
}