Do not open dex files in CLC if we only need to get dexopt status
The verifying the class loader context when calling GetDexOptNeeded
we only need the dex locations and the checksums. Opening the full
dex files may lead to in memory extraction which is expensive and
unnecessary.
Add a special path in ClassLoaderContext::OpenDexFiles which will
extract the locations and the checksums from the apk instead of
actually opening the dex files.
We re-uses the same logic in OpenDexFiles in order to avoid
implementing the opening algorithm twice (which, given all the edge
cases is not trivial).
Bug: 169869944
Test: test-art-host
Change-Id: Ic327889677ce697cd60c5c688281515b932a2a76
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index d7cf513..496ca15 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -564,8 +564,10 @@
cached_required_dex_checksums_.clear();
std::string error_msg;
const ArtDexFileLoader dex_file_loader;
+ std::vector<std::string> dex_locations_ignored;
if (dex_file_loader.GetMultiDexChecksums(dex_location_.c_str(),
&cached_required_dex_checksums_,
+ &dex_locations_ignored,
&error_msg,
zip_fd_,
&zip_file_only_contains_uncompressed_dex_)) {
@@ -875,7 +877,7 @@
? oat_file_assistant_->dex_location_.substr(0, dir_index)
: "";
- if (!context->OpenDexFiles(classpath_dir, context_fds)) {
+ if (!context->OpenDexFiles(classpath_dir, context_fds, /*only_read_checksums*/ true)) {
VLOG(oat) << "ClassLoaderContext check failed: dex files from the context could not be opened";
return false;
}