diff options
author | 2020-12-11 18:26:14 -0800 | |
---|---|---|
committer | 2020-12-14 19:00:35 +0000 | |
commit | 5ff2393e1fb6e61fc74f20c66f80f4b8656987d1 (patch) | |
tree | e94b8cfc92379678b4f2e6446aa6d28a6408222f | |
parent | 99459f3bdd8d569ec7054920cbc32e6915d1e125 (diff) |
Remove stripped-apk related logic from CLC
Stripped-apks are no longer supported by the runtime and
the current logic prevents bug fixes and code evolution.
Bug: 111442216
Test: test-art-host
Change-Id: I30d5825e4f6453981ca9165bebafe67557c28b93
-rw-r--r-- | dex2oat/dex2oat.cc | 3 | ||||
-rw-r--r-- | dex2oat/dex2oat_test.cc | 50 | ||||
-rw-r--r-- | dexoptanalyzer/dexoptanalyzer_test.cc | 37 | ||||
-rw-r--r-- | libdexfile/dex/art_dex_file_loader.cc | 12 | ||||
-rw-r--r-- | libdexfile/dex/art_dex_file_loader.h | 10 | ||||
-rw-r--r-- | runtime/class_loader_context.cc | 48 | ||||
-rw-r--r-- | runtime/class_loader_context.h | 3 | ||||
-rw-r--r-- | runtime/class_loader_context_test.cc | 36 | ||||
-rw-r--r-- | runtime/dex2oat_environment_test.h | 10 | ||||
-rw-r--r-- | runtime/native/dalvik_system_DexFile.cc | 2 | ||||
-rw-r--r-- | runtime/oat_file_assistant.cc | 23 | ||||
-rw-r--r-- | runtime/oat_file_assistant_test.cc | 8 | ||||
-rw-r--r-- | runtime/oat_file_manager.cc | 2 |
13 files changed, 73 insertions, 171 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index eebe4eee51..eeb2d6b1a2 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -1619,8 +1619,7 @@ class Dex2Oat final { // (because the encoding adds the dex checksum...) // TODO(calin): consider redesigning this so we don't have to open the dex files before // creating the actual class loader. - if (!class_loader_context_->OpenDexFiles(runtime_->GetInstructionSet(), - classpath_dir_, + if (!class_loader_context_->OpenDexFiles(classpath_dir_, class_loader_context_fds_)) { // Do not abort if we couldn't open files from the classpath. They might be // apks without dex files and right now are opening flow will fail them. diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc index 7ff6cfc532..c0dd84cc17 100644 --- a/dex2oat/dex2oat_test.cc +++ b/dex2oat/dex2oat_test.cc @@ -959,55 +959,15 @@ TEST_F(Dex2oatClassLoaderContextTest, ContextWithOtherDexFiles) { RunTest(context.c_str(), expected_classpath_key.c_str(), true); } -TEST_F(Dex2oatClassLoaderContextTest, ContextWithStrippedDexFiles) { - std::string stripped_classpath = GetScratchDir() + "/stripped_classpath.jar"; - Copy(GetStrippedDexSrc1(), stripped_classpath); +TEST_F(Dex2oatClassLoaderContextTest, ContextWithResourceOnlyDexFiles) { + std::string resource_only_classpath = GetScratchDir() + "/resource_only_classpath.jar"; + Copy(GetResourceOnlySrc1(), resource_only_classpath); - std::string context = "PCL[" + stripped_classpath + "]"; - // Expect an empty context because stripped dex files cannot be open. + std::string context = "PCL[" + resource_only_classpath + "]"; + // Expect an empty context because resource only dex files cannot be open. RunTest(context.c_str(), kEmptyClassPathKey , /*expected_success*/ true); } -TEST_F(Dex2oatClassLoaderContextTest, ContextWithStrippedDexFilesBackedByOdex) { - std::string stripped_classpath = GetScratchDir() + "/stripped_classpath.jar"; - std::string odex_for_classpath = GetOdexDir() + "/stripped_classpath.odex"; - - Copy(GetDexSrc1(), stripped_classpath); - - ASSERT_TRUE(GenerateOdexForTest(stripped_classpath, - odex_for_classpath, - CompilerFilter::kVerify, - {}, - true)); - - // Strip the dex file - Copy(GetStrippedDexSrc1(), stripped_classpath); - - std::string context = "PCL[" + stripped_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, 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_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_key.c_str(), - /*expected_success*/ true, - /*use_second_source*/ true); -} - TEST_F(Dex2oatClassLoaderContextTest, ContextWithNotExistentDexFiles) { std::string context = "PCL[does_not_exists.dex]"; // Expect an empty context because stripped dex files cannot be open. diff --git a/dexoptanalyzer/dexoptanalyzer_test.cc b/dexoptanalyzer/dexoptanalyzer_test.cc index d8321d6c55..4fb0b9e391 100644 --- a/dexoptanalyzer/dexoptanalyzer_test.cc +++ b/dexoptanalyzer/dexoptanalyzer_test.cc @@ -228,47 +228,12 @@ TEST_F(DexoptAnalyzerTest, DexOdexNoOat) { Verify(dex_location, CompilerFilter::kEverything); } -// Case: We have a stripped DEX file and a PIC ODEX file, but no OAT file. -TEST_F(DexoptAnalyzerTest, StrippedDexOdexNoOat) { - std::string dex_location = GetScratchDir() + "/StrippedDexOdexNoOat.jar"; - std::string odex_location = GetOdexDir() + "/StrippedDexOdexNoOat.odex"; - - Copy(GetDexSrc1(), dex_location); - GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); - - // Strip the dex file - Copy(GetStrippedDexSrc1(), dex_location); - - Verify(dex_location, CompilerFilter::kSpeed); -} - -// Case: We have a stripped DEX file, a PIC ODEX file, and an out-of-date OAT file. -TEST_F(DexoptAnalyzerTest, StrippedDexOdexOat) { - std::string dex_location = GetScratchDir() + "/StrippedDexOdexOat.jar"; - std::string odex_location = GetOdexDir() + "/StrippedDexOdexOat.odex"; - - // Create the oat file from a different dex file so it looks out of date. - Copy(GetDexSrc2(), dex_location); - GenerateOatForTest(dex_location.c_str(), CompilerFilter::kSpeed); - - // Create the odex file - Copy(GetDexSrc1(), dex_location); - GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed); - - // Strip the dex file. - Copy(GetStrippedDexSrc1(), dex_location); - - Verify(dex_location, CompilerFilter::kExtract); - Verify(dex_location, CompilerFilter::kSpeed); - Verify(dex_location, CompilerFilter::kEverything); -} - // Case: We have a stripped (or resource-only) DEX file, no ODEX file and no // OAT file. Expect: The status is kNoDexOptNeeded. TEST_F(DexoptAnalyzerTest, ResourceOnlyDex) { std::string dex_location = GetScratchDir() + "/ResourceOnlyDex.jar"; - Copy(GetStrippedDexSrc1(), dex_location); + Copy(GetResourceOnlySrc1(), dex_location); Verify(dex_location, CompilerFilter::kSpeed); Verify(dex_location, CompilerFilter::kExtract); diff --git a/libdexfile/dex/art_dex_file_loader.cc b/libdexfile/dex/art_dex_file_loader.cc index d17c61e5cd..a35559e3dd 100644 --- a/libdexfile/dex/art_dex_file_loader.cc +++ b/libdexfile/dex/art_dex_file_loader.cc @@ -250,6 +250,18 @@ bool ArtDexFileLoader::Open(int fd, return OpenWithMagic(magic, fd, location, verify, verify_checksum, error_msg, dex_files); } +bool ArtDexFileLoader::Open(const char* filename, + int fd, + const std::string& location, + bool verify, + bool verify_checksum, + std::string* error_msg, + std::vector<std::unique_ptr<const DexFile>>* dex_files) const { + return fd == -1 + ? Open(filename, location, verify, verify_checksum, error_msg, dex_files) + : Open(fd, location, verify, verify_checksum, error_msg, dex_files); +} + bool ArtDexFileLoader::OpenWithMagic(uint32_t magic, int fd, const std::string& location, diff --git a/libdexfile/dex/art_dex_file_loader.h b/libdexfile/dex/art_dex_file_loader.h index bf3852745c..05ed8bd766 100644 --- a/libdexfile/dex/art_dex_file_loader.h +++ b/libdexfile/dex/art_dex_file_loader.h @@ -86,6 +86,16 @@ class ArtDexFileLoader : public DexFileLoader { bool verify_checksum, std::string* error_msg, std::vector<std::unique_ptr<const DexFile>>* dex_files) const; + // Opens all .dex files found in the file, guessing the container format based on file magic. + // If the fd is -1 then the dex files are opened using the filename; otherwise they are + // opened using the fd. + bool Open(const char* filename, + int fd, + const std::string& location, + bool verify, + bool verify_checksum, + std::string* error_msg, + std::vector<std::unique_ptr<const DexFile>>* dex_files) const; // Open a single dex file from an fd. This function closes the fd. std::unique_ptr<const DexFile> OpenDex(int fd, diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc index 74f464c0bd..34a1722adf 100644 --- a/runtime/class_loader_context.cc +++ b/runtime/class_loader_context.cc @@ -399,10 +399,8 @@ ClassLoaderContext::ClassLoaderInfo* ClassLoaderContext::ParseInternal( return first.release(); } -// Opens requested class path files and appends them to opened_dex_files. If the dex files have -// been stripped, this opens them from their oat files (which get added to opened_oat_files). -bool ClassLoaderContext::OpenDexFiles(InstructionSet isa, - const std::string& classpath_dir, +// Opens requested class path files and appends them to opened_dex_files. +bool ClassLoaderContext::OpenDexFiles(const std::string& classpath_dir, const std::vector<int>& fds) { if (dex_files_open_attempted_) { // Do not attempt to re-open the files if we already tried. @@ -460,40 +458,14 @@ bool ClassLoaderContext::OpenDexFiles(InstructionSet isa, // contents. So pass true to verify_checksum. // We don't need to do structural dex file verification, we only need to // check the checksum, so pass false to verify. - if (fd < 0) { - if (!dex_file_loader.Open(location.c_str(), - location.c_str(), - /*verify=*/ false, - /*verify_checksum=*/ true, - &error_msg, - &info->opened_dex_files)) { - // If we fail to open the dex file because it's been stripped, try to - // open the dex file from its corresponding oat file. - // This could happen when we need to recompile a pre-build whose dex - // code has been stripped (for example, if the pre-build is only - // quicken and we want to re-compile it speed-profile). - // TODO(calin): Use the vdex directly instead of going through the oat file. - OatFileAssistant oat_file_assistant(location.c_str(), isa, false); - std::unique_ptr<OatFile> oat_file(oat_file_assistant.GetBestOatFile()); - std::vector<std::unique_ptr<const DexFile>> oat_dex_files; - if (oat_file != nullptr && - OatFileAssistant::LoadDexFiles(*oat_file, location, &oat_dex_files)) { - info->opened_oat_files.push_back(std::move(oat_file)); - info->opened_dex_files.insert(info->opened_dex_files.end(), - std::make_move_iterator(oat_dex_files.begin()), - std::make_move_iterator(oat_dex_files.end())); - } else { - LOG(WARNING) << "Could not open dex files from location: " << location; - dex_files_open_result_ = false; - } - } - } else if (!dex_file_loader.Open(fd, - location.c_str(), - /*verify=*/ false, - /*verify_checksum=*/ true, - &error_msg, - &info->opened_dex_files)) { - LOG(WARNING) << "Could not open dex files from fd " << fd << " for location: " << location; + if (!dex_file_loader.Open(location.c_str(), + fd, + location.c_str(), + /*verify=*/ false, + /*verify_checksum=*/ true, + &error_msg, + &info->opened_dex_files)) { + LOG(WARNING) << "Could not open dex files for location " << location << ", fd=" << fd; dex_files_open_result_ = false; } } diff --git a/runtime/class_loader_context.h b/runtime/class_loader_context.h index d564ec8eb4..a5eb2f1838 100644 --- a/runtime/class_loader_context.h +++ b/runtime/class_loader_context.h @@ -81,8 +81,7 @@ class ClassLoaderContext { // TODO(calin): we're forced to complicate the flow in this class with a different // OpenDexFiles step because the current dex2oat flow requires the dex files be opened before // the class loader is created. Consider reworking the dex2oat part. - bool OpenDexFiles(InstructionSet isa, - const std::string& classpath_dir, + bool OpenDexFiles(const std::string& classpath_dir = "", const std::vector<int>& context_fds = std::vector<int>()); // Remove the specified compilation sources from all classpaths present in this context. diff --git a/runtime/class_loader_context_test.cc b/runtime/class_loader_context_test.cc index 2447616729..987f0d14fd 100644 --- a/runtime/class_loader_context_test.cc +++ b/runtime/class_loader_context_test.cc @@ -401,7 +401,7 @@ TEST_F(ClassLoaderContextTest, OpenInvalidDexFiles) { std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create("PCL[does_not_exist.dex]"); VerifyContextSize(context.get(), 1); - ASSERT_FALSE(context->OpenDexFiles(InstructionSet::kArm, ".")); + ASSERT_FALSE(context->OpenDexFiles(".")); } TEST_F(ClassLoaderContextTest, OpenValidDexFiles) { @@ -415,7 +415,7 @@ TEST_F(ClassLoaderContextTest, OpenValidDexFiles) { "PCL[" + multidex_name + ":" + myclass_dex_name + "];" + "DLC[" + dex_name + "]"); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, /*classpath_dir=*/ "")); + ASSERT_TRUE(context->OpenDexFiles()); VerifyContextSize(context.get(), 2); @@ -465,7 +465,7 @@ TEST_F(ClassLoaderContextTest, OpenValidDexFilesRelative) { "PCL[" + multidex_name + ":" + myclass_dex_name + "];" + "DLC[" + dex_name + "]"); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, /*classpath_dir=*/ "")); + ASSERT_TRUE(context->OpenDexFiles()); std::vector<std::unique_ptr<const DexFile>> all_dex_files0 = OpenTestDexFiles("MultiDex"); std::vector<std::unique_ptr<const DexFile>> myclass_dex_files = OpenTestDexFiles("MyClass"); @@ -499,7 +499,7 @@ TEST_F(ClassLoaderContextTest, OpenValidDexFilesClasspathDir) { "PCL[" + multidex_name + ":" + myclass_dex_name + "];" + "DLC[" + dex_name + "]"); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, cwd_buf)); + ASSERT_TRUE(context->OpenDexFiles(cwd_buf)); VerifyContextSize(context.get(), 2); std::vector<std::unique_ptr<const DexFile>> all_dex_files0 = OpenTestDexFiles("MultiDex"); @@ -517,7 +517,7 @@ TEST_F(ClassLoaderContextTest, OpenInvalidDexFilesMix) { std::string dex_name = GetTestDexFileName("Main"); std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create("PCL[does_not_exist.dex];DLC[" + dex_name + "]"); - ASSERT_FALSE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_FALSE(context->OpenDexFiles()); } TEST_F(ClassLoaderContextTest, OpenDexFilesForIMCFails) { @@ -526,14 +526,14 @@ TEST_F(ClassLoaderContextTest, OpenDexFilesForIMCFails) { context = ParseContextWithChecksums("IMC[<unknown>*111]"); VerifyContextSize(context.get(), 1); - ASSERT_FALSE(context->OpenDexFiles(InstructionSet::kArm, ".")); + ASSERT_FALSE(context->OpenDexFiles(".")); } TEST_F(ClassLoaderContextTest, CreateClassLoader) { std::string dex_name = GetTestDexFileName("Main"); std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create("PCL[" + dex_name + "]"); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_TRUE(context->OpenDexFiles()); std::vector<std::unique_ptr<const DexFile>> classpath_dex = OpenTestDexFiles("Main"); std::vector<std::unique_ptr<const DexFile>> compilation_sources = OpenTestDexFiles("MultiDex"); @@ -570,7 +570,7 @@ TEST_F(ClassLoaderContextTest, CreateClassLoader) { TEST_F(ClassLoaderContextTest, CreateClassLoaderWithEmptyContext) { std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(""); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_TRUE(context->OpenDexFiles()); std::vector<std::unique_ptr<const DexFile>> compilation_sources = OpenTestDexFiles("MultiDex"); @@ -597,7 +597,7 @@ TEST_F(ClassLoaderContextTest, CreateClassLoaderWithEmptyContext) { TEST_F(ClassLoaderContextTest, CreateClassLoaderWithSharedLibraryContext) { std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create("&"); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_TRUE(context->OpenDexFiles()); std::vector<std::unique_ptr<const DexFile>> compilation_sources = OpenTestDexFiles("MultiDex"); @@ -635,7 +635,7 @@ TEST_F(ClassLoaderContextTest, CreateClassLoaderWithComplexChain) { "PCL[" + CreateClassPath(classpath_dex_d) + "]"; std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_spec); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_TRUE(context->OpenDexFiles()); // Setup the compilation sources. std::vector<std::unique_ptr<const DexFile>> compilation_sources = OpenTestDexFiles("MultiDex"); @@ -705,7 +705,7 @@ TEST_F(ClassLoaderContextTest, CreateClassLoaderWithSharedLibraries) { "PCL[" + CreateClassPath(classpath_dex_d) + "]}"; std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_spec); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_TRUE(context->OpenDexFiles()); // Setup the compilation sources. std::vector<std::unique_ptr<const DexFile>> compilation_sources = OpenTestDexFiles("MultiDex"); @@ -793,7 +793,7 @@ TEST_F(ClassLoaderContextTest, CreateClassLoaderWithSharedLibrariesInParentToo) "PCL[" + CreateClassPath(classpath_dex_d) + "]}"; std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_spec); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_TRUE(context->OpenDexFiles()); // Setup the compilation sources. std::vector<std::unique_ptr<const DexFile>> compilation_sources = OpenTestDexFiles("MultiDex"); @@ -893,7 +893,7 @@ TEST_F(ClassLoaderContextTest, CreateClassLoaderWithSharedLibrariesDependencies) "PCL[" + CreateClassPath(classpath_dex_d) + "]"; std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_spec); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_TRUE(context->OpenDexFiles()); // Setup the compilation sources. std::vector<std::unique_ptr<const DexFile>> compilation_sources = OpenTestDexFiles("MultiDex"); @@ -1008,7 +1008,7 @@ TEST_F(ClassLoaderContextTest, CreateClassLoaderWithSameSharedLibraries) { "PCL[" + CreateClassPath(classpath_dex_b) + "]}"; std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_spec); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_TRUE(context->OpenDexFiles()); // Setup the compilation sources. std::vector<std::unique_ptr<const DexFile>> compilation_sources = OpenTestDexFiles("MultiDex"); @@ -1085,7 +1085,7 @@ TEST_F(ClassLoaderContextTest, EncodeInOatFile) { std::string dex2_name = GetTestDexFileName("MyClass"); std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create("PCL[" + dex1_name + ":" + dex2_name + "]"); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_TRUE(context->OpenDexFiles()); std::vector<std::unique_ptr<const DexFile>> dex1 = OpenTestDexFiles("Main"); std::vector<std::unique_ptr<const DexFile>> dex2 = OpenTestDexFiles("MyClass"); @@ -1100,7 +1100,7 @@ TEST_F(ClassLoaderContextTest, EncodeInOatFileIMC) { jobject class_loader_b = LoadDexInInMemoryDexClassLoader("MyClass", class_loader_a); std::unique_ptr<ClassLoaderContext> context = CreateContextForClassLoader(class_loader_b); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_TRUE(context->OpenDexFiles()); std::vector<std::unique_ptr<const DexFile>> dex1 = OpenTestDexFiles("Main"); std::vector<std::unique_ptr<const DexFile>> dex2 = OpenTestDexFiles("MyClass"); @@ -1117,7 +1117,7 @@ TEST_F(ClassLoaderContextTest, EncodeForDex2oat) { std::string dex2_name = GetTestDexFileName("MultiDex"); std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create("PCL[" + dex1_name + ":" + dex2_name + "]"); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_TRUE(context->OpenDexFiles()); std::string encoding = context->EncodeContextForDex2oat(""); std::string expected_encoding = "PCL[" + dex1_name + ":" + dex2_name + "]"; @@ -1129,7 +1129,7 @@ TEST_F(ClassLoaderContextTest, EncodeForDex2oatIMC) { jobject class_loader_b = LoadDexInInMemoryDexClassLoader("MyClass", class_loader_a); std::unique_ptr<ClassLoaderContext> context = CreateContextForClassLoader(class_loader_b); - ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + ASSERT_TRUE(context->OpenDexFiles()); std::string encoding = context->EncodeContextForDex2oat(""); std::string expected_encoding = "IMC[<unknown>];PCL[" + GetTestDexFileName("Main") + "]"; diff --git a/runtime/dex2oat_environment_test.h b/runtime/dex2oat_environment_test.h index 8182e16ff5..b180873501 100644 --- a/runtime/dex2oat_environment_test.h +++ b/runtime/dex2oat_environment_test.h @@ -75,11 +75,11 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { << "Expected pre-compiled boot image to be at: " << GetSystemImageFile(); ASSERT_TRUE(OS::FileExists(GetDexSrc1().c_str())) << "Expected dex file to be at: " << GetDexSrc1(); - ASSERT_TRUE(OS::FileExists(GetStrippedDexSrc1().c_str())) - << "Expected stripped dex file to be at: " << GetStrippedDexSrc1(); + ASSERT_TRUE(OS::FileExists(GetResourceOnlySrc1().c_str())) + << "Expected stripped dex file to be at: " << GetResourceOnlySrc1(); ASSERT_FALSE( - dex_file_loader.GetMultiDexChecksums(GetStrippedDexSrc1().c_str(), &checksums, &error_msg)) - << "Expected stripped dex file to be stripped: " << GetStrippedDexSrc1(); + dex_file_loader.GetMultiDexChecksums(GetResourceOnlySrc1().c_str(), &checksums, &error_msg)) + << "Expected stripped dex file to be stripped: " << GetResourceOnlySrc1(); ASSERT_TRUE(OS::FileExists(GetDexSrc2().c_str())) << "Expected dex file to be at: " << GetDexSrc2(); @@ -145,7 +145,7 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { // Returns the path to a dex file equivalent to GetDexSrc1, but with the dex // file stripped. - std::string GetStrippedDexSrc1() const { + std::string GetResourceOnlySrc1() const { return GetTestDexFileName("MainStripped"); } diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc index d2b5edf333..8bb8ce8310 100644 --- a/runtime/native/dalvik_system_DexFile.cc +++ b/runtime/native/dalvik_system_DexFile.cc @@ -333,7 +333,7 @@ static jstring DexFile_getClassLoaderContext(JNIEnv* env, constexpr const char* kBaseDir = ""; std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::CreateContextForClassLoader(class_loader, dex_elements); - if (context == nullptr || !context->OpenDexFiles(kRuntimeISA, kBaseDir)) { + if (context == nullptr || !context->OpenDexFiles(kBaseDir)) { LOG(WARNING) << "Could not establish class loader context"; return nullptr; } diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc index 8e8dc89390..d7cf513cf8 100644 --- a/runtime/oat_file_assistant.cc +++ b/runtime/oat_file_assistant.cc @@ -572,25 +572,10 @@ const std::vector<uint32_t>* OatFileAssistant::GetRequiredDexChecksums() { required_dex_checksums_found_ = true; has_original_dex_files_ = true; } else { - // This can happen if the original dex file has been stripped from the - // apk. - VLOG(oat) << "OatFileAssistant: " << error_msg; + // The only valid case here is for APKs without dex files. + required_dex_checksums_found_ = false; has_original_dex_files_ = false; - - // Get the checksums from the odex if we can. - const OatFile* odex_file = odex_.GetFile(); - if (odex_file != nullptr) { - required_dex_checksums_found_ = true; - for (size_t i = 0; i < odex_file->GetOatHeader().GetDexFileCount(); i++) { - std::string dex = DexFileLoader::GetMultiDexLocation(i, dex_location_.c_str()); - const OatDexFile* odex_dex_file = odex_file->GetOatDexFile(dex.c_str(), nullptr); - if (odex_dex_file == nullptr) { - required_dex_checksums_found_ = false; - break; - } - cached_required_dex_checksums_.push_back(odex_dex_file->GetDexFileLocationChecksum()); - } - } + VLOG(oat) << "Could not get required checksum: " << error_msg; } } return required_dex_checksums_found_ ? &cached_required_dex_checksums_ : nullptr; @@ -890,7 +875,7 @@ bool OatFileAssistant::OatFileInfo::ClassLoaderContextIsOkay(ClassLoaderContext* ? oat_file_assistant_->dex_location_.substr(0, dir_index) : ""; - if (!context->OpenDexFiles(oat_file_assistant_->isa_, classpath_dir, context_fds)) { + if (!context->OpenDexFiles(classpath_dir, context_fds)) { VLOG(oat) << "ClassLoaderContext check failed: dex files from the context could not be opened"; return false; } diff --git a/runtime/oat_file_assistant_test.cc b/runtime/oat_file_assistant_test.cc index 223b6f4fae..a1aa6433d5 100644 --- a/runtime/oat_file_assistant_test.cc +++ b/runtime/oat_file_assistant_test.cc @@ -177,7 +177,7 @@ TEST_F(OatFileAssistantTest, MakeUpToDateWithContext) { std::string context_str = "PCL[" + context_location + "]"; std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_str); ASSERT_TRUE(context != nullptr); - ASSERT_TRUE(context->OpenDexFiles(kRuntimeISA, "")); + ASSERT_TRUE(context->OpenDexFiles()); std::string error_msg; std::vector<std::string> args; @@ -204,7 +204,7 @@ TEST_F(OatFileAssistantTest, GetDexOptNeededWithUpToDateContextRelative) { std::string context_str = "PCL[" + context_location + "]"; std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_str); ASSERT_TRUE(context != nullptr); - ASSERT_TRUE(context->OpenDexFiles(kRuntimeISA, "")); + ASSERT_TRUE(context->OpenDexFiles()); std::string error_msg; std::vector<std::string> args; @@ -851,7 +851,7 @@ TEST_F(OatFileAssistantTest, DexOdexNoOat) { TEST_F(OatFileAssistantTest, ResourceOnlyDex) { std::string dex_location = GetScratchDir() + "/ResourceOnlyDex.jar"; - Copy(GetStrippedDexSrc1(), dex_location); + Copy(GetResourceOnlySrc1(), dex_location); // Verify the status. OatFileAssistant oat_file_assistant(dex_location.c_str(), kRuntimeISA, true); @@ -1293,7 +1293,7 @@ TEST_F(OatFileAssistantTest, GetDexOptNeededWithOutOfDateContext) { std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_str); ASSERT_TRUE(context != nullptr); - ASSERT_TRUE(context->OpenDexFiles(kRuntimeISA, "")); + ASSERT_TRUE(context->OpenDexFiles()); std::string error_msg; std::vector<std::string> args; diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc index 8c6d87272d..1c715817d1 100644 --- a/runtime/oat_file_manager.cc +++ b/runtime/oat_file_manager.cc @@ -553,7 +553,7 @@ std::vector<std::unique_ptr<const DexFile>> OatFileManager::OpenDexFilesFromOat_ LOG(ERROR) << "Could not create class loader context for " << vdex_path; return dex_files; } - DCHECK(context->OpenDexFiles(kRuntimeISA, "")) + DCHECK(context->OpenDexFiles()) << "Context created from already opened dex files should not attempt to open again"; // Check that we can use the vdex against this boot class path and in this class loader context. |