Move art to use dalvik names for .oat files
Change-Id: Ia383c0a0847684a513cab7db44b4ecf8fe05e1c3
diff --git a/src/class_linker.cc b/src/class_linker.cc
index 85bd9f6..70c7ff3 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -810,12 +810,12 @@
const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(dex_location);
if (oat_dex_file == NULL) {
- LOG(ERROR) << ".oat file " << oat_file->GetLocation()
+ LOG(ERROR) << "oat file " << oat_file->GetLocation()
<< " does not contain contents for " << dex_location;
std::vector<const OatFile::OatDexFile*> oat_dex_files = oat_file->GetOatDexFiles();
for (size_t i = 0; i < oat_dex_files.size(); i++) {
const OatFile::OatDexFile* oat_dex_file = oat_dex_files[i];
- LOG(ERROR) << ".oat file " << oat_file->GetLocation()
+ LOG(ERROR) << "oat file " << oat_file->GetLocation()
<< " contains contents for " << oat_dex_file->GetDexFileLocation();
}
return false;
@@ -829,14 +829,14 @@
if (!image_check) {
std::string image_file(image_header.GetImageRoot(
ImageHeader::kOatLocation)->AsString()->ToModifiedUtf8());
- LOG(WARNING) << ".oat file " << oat_file->GetLocation()
+ LOG(WARNING) << "oat file " << oat_file->GetLocation()
<< " mismatch ( " << std::hex << oat_file->GetOatHeader().GetImageFileLocationOatChecksum()
<< ", " << oat_file->GetOatHeader().GetImageFileLocationOatDataBegin()
<< ") with " << image_file
<< " (" << image_oat_checksum << ", " << std::hex << image_oat_data_begin << ")";
}
if (!dex_check) {
- LOG(WARNING) << ".oat file " << oat_file->GetLocation()
+ LOG(WARNING) << "oat file " << oat_file->GetLocation()
<< " mismatch ( " << std::hex << oat_dex_file->GetDexFileLocationChecksum()
<< ") with " << dex_location
<< " (" << std::hex << dex_location_checksum << ")";
@@ -864,16 +864,16 @@
}
// Look for an existing file next to dex. for example, for
- // /foo/bar/baz.jar, look for /foo/bar/baz.jar.oat.
- std::string oat_filename(OatFile::DexFilenameToOatFilename(dex_location));
- const OatFile* oat_file = FindOatFileFromOatLocationLocked(oat_filename);
+ // /foo/bar/baz.jar, look for /foo/bar/baz.odex.
+ std::string odex_filename(OatFile::DexFilenameToOdexFilename(dex_location));
+ const OatFile* oat_file = FindOatFileFromOatLocationLocked(odex_filename);
if (oat_file != NULL) {
uint32_t dex_location_checksum;
if (!DexFile::GetChecksum(dex_location, dex_location_checksum)) {
// If no classes.dex found in dex_location, it has been stripped, assume oat is up-to-date.
// This is the common case in user builds for jar's and apk's in the /system directory.
const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(dex_location);
- CHECK(oat_dex_file != NULL) << oat_filename << " " << dex_location;
+ CHECK(oat_dex_file != NULL) << odex_filename << " " << dex_location;
RegisterOatFileLocked(*oat_file);
return oat_dex_file->OpenDexFile();
}
@@ -885,8 +885,8 @@
}
}
// Look for an existing file in the dalvik-cache, validating the result if found
- // not found in /foo/bar/baz.oat? try /data/dalvik-cache/foo@bar@baz.oat
- std::string cache_location(GetDalvikCacheFilenameOrDie(oat_filename));
+ // not found in /foo/bar/baz.odex? try /data/dalvik-cache/foo@bar@baz.jar@classes.dex
+ std::string cache_location(GetDalvikCacheFilenameOrDie(dex_location));
oat_file = FindOatFileFromOatLocationLocked(cache_location);
if (oat_file != NULL) {
uint32_t dex_location_checksum;
@@ -901,13 +901,13 @@
return dex_file;
}
if (TEMP_FAILURE_RETRY(unlink(oat_file->GetLocation().c_str())) != 0) {
- PLOG(FATAL) << "Failed to remove obsolete .oat file " << oat_file->GetLocation();
+ PLOG(FATAL) << "Failed to remove obsolete oat file " << oat_file->GetLocation();
}
}
- LOG(INFO) << "Failed to open oat file from " << oat_filename << " or " << cache_location << ".";
+ LOG(INFO) << "Failed to open oat file from " << odex_filename << " or " << cache_location << ".";
// Try to generate oat file if it wasn't found or was obsolete.
- std::string oat_cache_filename(GetDalvikCacheFilenameOrDie(oat_filename));
+ std::string oat_cache_filename(GetDalvikCacheFilenameOrDie(dex_location));
return FindOrCreateOatFileForDexLocationLocked(dex_location, oat_cache_filename);
}
diff --git a/src/native/dalvik_system_DexFile.cc b/src/native/dalvik_system_DexFile.cc
index c49e017..e07339c 100644
--- a/src/native/dalvik_system_DexFile.cc
+++ b/src/native/dalvik_system_DexFile.cc
@@ -209,9 +209,9 @@
}
}
- // Check if we have an oat file next to the dex file.
- std::string oat_filename(OatFile::DexFilenameToOatFilename(filename.c_str()));
- UniquePtr<const OatFile> oat_file(OatFile::Open(oat_filename, oat_filename, NULL));
+ // Check if we have an odex file next to the dex file.
+ std::string odex_filename(OatFile::DexFilenameToOdexFilename(filename.c_str()));
+ UniquePtr<const OatFile> oat_file(OatFile::Open(odex_filename, odex_filename, NULL));
if (oat_file.get() != NULL) {
ScopedObjectAccess soa(env);
const art::OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(filename.c_str());
@@ -231,7 +231,7 @@
}
if (ClassLinker::VerifyOatFileChecksums(oat_file.get(), filename.c_str(), location_checksum)) {
if (debug_logging) {
- LOG(INFO) << "DexFile_isDexOptNeeded precompiled file " << oat_filename
+ LOG(INFO) << "DexFile_isDexOptNeeded precompiled file " << odex_filename
<< " is up-to-date checksum compared to " << filename.c_str();
}
return JNI_FALSE;
@@ -240,8 +240,8 @@
}
// Check if we have an oat file in the cache
- std::string cache_location(GetDalvikCacheFilenameOrDie(oat_filename));
- oat_file.reset(OatFile::Open(cache_location, oat_filename, NULL));
+ std::string cache_location(GetDalvikCacheFilenameOrDie(filename.c_str()));
+ oat_file.reset(OatFile::Open(cache_location, filename.c_str(), NULL));
if (oat_file.get() == NULL) {
LOG(INFO) << "DexFile_isDexOptNeeded cache file " << cache_location
<< " does not exist for " << filename.c_str();
diff --git a/src/oat_file.cc b/src/oat_file.cc
index 7bbf94c..ebf92a7 100644
--- a/src/oat_file.cc
+++ b/src/oat_file.cc
@@ -31,11 +31,13 @@
namespace art {
-std::string OatFile::DexFilenameToOatFilename(const std::string& location) {
+std::string OatFile::DexFilenameToOdexFilename(const std::string& location) {
CHECK(IsValidDexFilename(location) || IsValidZipFilename(location));
- std::string oat_location(location);
- oat_location += ".oat";
- return oat_location;
+ std::string odex_location(location);
+ odex_location.resize(odex_location.size() - 3); // 3=dex or zip or apk
+ CHECK_EQ('.', odex_location[odex_location.size()-1]);
+ odex_location += "odex";
+ return odex_location;
}
void OatFile::CheckLocation(const std::string& location) {
@@ -59,17 +61,7 @@
const std::string& location,
byte* requested_base) {
CHECK(!filename.empty()) << location;
- CheckLocation(location);
- /*
- * TODO: Reenable dlopen when it works again on MIPS. It may have broken from this change:
- * commit 818d98eb563ad5d7293b8b5c40f3dabf745e611f
- * Author: Brian Carlstrom <bdc@google.com>
- * Date: Sun Feb 10 21:38:12 2013 -0800
- *
- * Fix MIPS to use standard kPageSize=0x1000 section alignment for ELF sections
- *
- * Change-Id: I905f0c5f75921a65bd7426a54d6258c780d85d0e
- */
+ CheckLocation(filename);
OatFile* result = OpenDlopen(filename, location, requested_base);
if (result != NULL) {
return result;
diff --git a/src/oat_file.h b/src/oat_file.h
index 46aad4f..0bf79a9 100644
--- a/src/oat_file.h
+++ b/src/oat_file.h
@@ -36,8 +36,9 @@
class OatFile {
public:
- // Returns an OatFile name based on a DexFile location
- static std::string DexFilenameToOatFilename(const std::string& location);
+ // Returns an .odex file name next adjacent to the dex location.
+ // For example, for "/foo/bar/baz.jar", return "/foo/bar/baz.odex".
+ static std::string DexFilenameToOdexFilename(const std::string& location);
// Open an oat file. Returns NULL on failure. Requested base can
// optionally be used to request where the file should be loaded.
diff --git a/src/utils.cc b/src/utils.cc
index bb83802..723be92 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -1208,6 +1208,10 @@
LOG(FATAL) << "Expected path in location to be absolute: "<< location;
}
std::string cache_file(location, 1); // skip leading slash
+ if (!IsValidDexFilename(location)) {
+ cache_file += "/";
+ cache_file += DexFile::kClassesDex;
+ }
std::replace(cache_file.begin(), cache_file.end(), '/', '@');
return dalvik_cache + "/" + cache_file;
}
@@ -1225,7 +1229,9 @@
}
bool IsValidOatFilename(const std::string& filename) {
- return EndsWith(filename, ".oat");
+ return (EndsWith(filename, ".odex") ||
+ EndsWith(filename, ".oat") ||
+ EndsWith(filename, DexFile::kClassesDex));
}
} // namespace art