Merge "Refactor register allocation to be pluggable"
diff --git a/compiler/optimizing/register_allocation_resolver.cc b/compiler/optimizing/register_allocation_resolver.cc
index 8f5a2a8..3450286 100644
--- a/compiler/optimizing/register_allocation_resolver.cc
+++ b/compiler/optimizing/register_allocation_resolver.cc
@@ -36,7 +36,7 @@
size_t float_spill_slots,
size_t double_spill_slots,
size_t catch_phi_spill_slots,
- const ArenaVector<LiveInterval*> temp_intervals) {
+ const ArenaVector<LiveInterval*>& temp_intervals) {
size_t spill_slots = int_spill_slots
+ long_spill_slots
+ float_spill_slots
diff --git a/compiler/optimizing/register_allocation_resolver.h b/compiler/optimizing/register_allocation_resolver.h
index 16a8a87..6ceb9bc 100644
--- a/compiler/optimizing/register_allocation_resolver.h
+++ b/compiler/optimizing/register_allocation_resolver.h
@@ -51,7 +51,7 @@
size_t float_spill_slots,
size_t double_spill_slots,
size_t catch_phi_spill_slots,
- const ArenaVector<LiveInterval*> temp_intervals);
+ const ArenaVector<LiveInterval*>& temp_intervals);
private:
// Connect adjacent siblings within blocks, and resolve inputs along the way.
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index 6728123..8700a90 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -81,11 +81,18 @@
load_executable_ = false;
}
- // If the user gave a target oat location, save that as the cached oat
- // location now so we won't try to construct the default location later.
+ std::string error_msg;
+ if (!DexLocationToOdexFilename(dex_location_, isa_, &odex_file_name_, &error_msg)) {
+ LOG(WARNING) << "Failed to determine odex file name: " << error_msg;
+ }
+
if (oat_location != nullptr) {
- cached_oat_file_name_ = std::string(oat_location);
- cached_oat_file_name_attempted_ = true;
+ oat_file_name_ = std::string(oat_location);
+ } else {
+ if (!DexLocationToOatFilename(dex_location_, isa_, &oat_file_name_, &error_msg)) {
+ LOG(WARNING) << "Failed to determine oat file name for dex location "
+ << dex_location_ << ": " << error_msg;
+ }
}
}
@@ -351,17 +358,7 @@
}
const std::string* OatFileAssistant::OdexFileName() {
- if (!cached_odex_file_name_attempted_) {
- cached_odex_file_name_attempted_ = true;
-
- std::string error_msg;
- if (!DexFilenameToOdexFilename(dex_location_, isa_, &cached_odex_file_name_, &error_msg)) {
- // If we can't figure out the odex file, we treat it as if the odex
- // file was inaccessible.
- LOG(WARNING) << "Failed to determine odex file name: " << error_msg;
- }
- }
- return cached_odex_file_name_.empty() ? nullptr : &cached_odex_file_name_;
+ return odex_file_name_.empty() ? nullptr : &odex_file_name_;
}
bool OatFileAssistant::OdexFileExists() {
@@ -412,25 +409,7 @@
}
const std::string* OatFileAssistant::OatFileName() {
- if (!cached_oat_file_name_attempted_) {
- cached_oat_file_name_attempted_ = true;
-
- // Compute the oat file name from the dex location.
- // TODO: The oat file assistant should be the definitive place for
- // determining the oat file name from the dex location, not
- // GetDalvikCacheFilename.
- std::string cache_dir = StringPrintf("%s%s",
- DalvikCacheDirectory().c_str(), GetInstructionSetString(isa_));
- std::string error_msg;
- if (!GetDalvikCacheFilename(dex_location_.c_str(),
- cache_dir.c_str(), &cached_oat_file_name_, &error_msg)) {
- // If we can't determine the oat file name, we treat the oat file as
- // inaccessible.
- LOG(WARNING) << "Failed to determine oat file name for dex location "
- << dex_location_ << ": " << error_msg;
- }
- }
- return cached_oat_file_name_.empty() ? nullptr : &cached_oat_file_name_;
+ return oat_file_name_.empty() ? nullptr : &oat_file_name_;
}
bool OatFileAssistant::OatFileExists() {
@@ -750,8 +729,10 @@
return Exec(argv, error_msg);
}
-bool OatFileAssistant::DexFilenameToOdexFilename(const std::string& location,
- InstructionSet isa, std::string* odex_filename, std::string* error_msg) {
+bool OatFileAssistant::DexLocationToOdexFilename(const std::string& location,
+ InstructionSet isa,
+ std::string* odex_filename,
+ std::string* error_msg) {
CHECK(odex_filename != nullptr);
CHECK(error_msg != nullptr);
@@ -790,9 +771,12 @@
return true;
}
-std::string OatFileAssistant::DalvikCacheDirectory() {
- // Note: We don't cache this, because it will only be called once by
- // OatFileName.
+bool OatFileAssistant::DexLocationToOatFilename(const std::string& location,
+ InstructionSet isa,
+ std::string* oat_filename,
+ std::string* error_msg) {
+ CHECK(oat_filename != nullptr);
+ CHECK(error_msg != nullptr);
// TODO: The work done in GetDalvikCache is overkill for what we need.
// Ideally a new API for getting the DalvikCacheDirectory the way we want
@@ -800,12 +784,16 @@
// of the GetDalvikCache family of functions. Until such an API is in place,
// we use GetDalvikCache to avoid duplicating the logic for determining the
// dalvik cache directory.
- std::string result;
- bool have_android_data;
- bool dalvik_cache_exists;
- bool is_global_cache;
- GetDalvikCache("", false, &result, &have_android_data, &dalvik_cache_exists, &is_global_cache);
- return result;
+ std::string dalvik_cache_dir;
+ bool ignored;
+ GetDalvikCache("", false, &dalvik_cache_dir, &ignored, &ignored, &ignored);
+
+ // TODO: The oat file assistant should be the definitive place for
+ // determining the oat file name from the dex location, not
+ // GetDalvikCacheFilename.
+ std::string cache_dir = StringPrintf("%s%s",
+ dalvik_cache_dir.c_str(), GetInstructionSetString(isa));
+ return GetDalvikCacheFilename(location.c_str(), cache_dir.c_str(), oat_filename, error_msg);
}
std::string OatFileAssistant::ImageLocation() {
diff --git a/runtime/oat_file_assistant.h b/runtime/oat_file_assistant.h
index e4aba3f..04bd20c 100644
--- a/runtime/oat_file_assistant.h
+++ b/runtime/oat_file_assistant.h
@@ -280,8 +280,21 @@
// Returns false on error, in which case error_msg describes the error and
// odex_filename is not changed.
// Neither odex_filename nor error_msg may be null.
- static bool DexFilenameToOdexFilename(const std::string& location,
- InstructionSet isa, std::string* odex_filename, std::string* error_msg);
+ static bool DexLocationToOdexFilename(const std::string& location,
+ InstructionSet isa,
+ std::string* odex_filename,
+ std::string* error_msg);
+
+ // Constructs the oat file name for the given dex location.
+ // Returns true on success, in which case oat_filename is set to the oat
+ // file name.
+ // Returns false on error, in which case error_msg describes the error and
+ // oat_filename is not changed.
+ // Neither oat_filename nor error_msg may be null.
+ static bool DexLocationToOatFilename(const std::string& location,
+ InstructionSet isa,
+ std::string* oat_filename,
+ std::string* error_msg);
static uint32_t CalculateCombinedImageChecksum(InstructionSet isa = kRuntimeISA);
@@ -293,11 +306,6 @@
std::string location;
};
- // Returns the path to the dalvik cache directory.
- // Does not check existence of the cache or try to create it.
- // Includes the trailing slash.
- // Returns an empty string if we can't get the dalvik cache directory path.
- std::string DalvikCacheDirectory();
// Returns the current image location.
// Returns an empty string if the image location could not be retrieved.
@@ -383,12 +391,9 @@
bool required_dex_checksum_found_;
bool has_original_dex_files_;
- // Cached value of the odex file name.
- // This should be accessed only by the OdexFileName() method.
// The sentinel value "" is used if the odex file name could not be
// determined.
- bool cached_odex_file_name_attempted_ = false;
- std::string cached_odex_file_name_;
+ std::string odex_file_name_;
// Cached value of the loaded odex file.
// Use the GetOdexFile method rather than accessing this directly, unless you
@@ -400,12 +405,9 @@
bool odex_file_status_attempted_ = false;
OatStatus cached_odex_file_status_;
- // Cached value of the oat file name.
- // This should be accessed only by the OatFileName() method.
// The sentinel value "" is used if the oat file name could not be
// determined.
- bool cached_oat_file_name_attempted_ = false;
- std::string cached_oat_file_name_;
+ std::string oat_file_name_;
// Cached value of the loaded oat file.
// Use the GetOatFile method rather than accessing this directly, unless you
diff --git a/runtime/oat_file_assistant_test.cc b/runtime/oat_file_assistant_test.cc
index 6bccea6..39848b4 100644
--- a/runtime/oat_file_assistant_test.cc
+++ b/runtime/oat_file_assistant_test.cc
@@ -213,22 +213,22 @@
// generation of oat files.
static void GenerateOatForTest(const char* dex_location, CompilerFilter::Filter filter) {
// Use an oat file assistant to find the proper oat location.
- OatFileAssistant ofa(dex_location, kRuntimeISA, false);
- const std::string* oat_location = ofa.OatFileName();
- ASSERT_TRUE(oat_location != nullptr);
+ std::string oat_location;
+ std::string error_msg;
+ ASSERT_TRUE(OatFileAssistant::DexLocationToOatFilename(
+ dex_location, kRuntimeISA, &oat_location, &error_msg)) << error_msg;
std::vector<std::string> args;
args.push_back("--dex-file=" + std::string(dex_location));
- args.push_back("--oat-file=" + *oat_location);
+ args.push_back("--oat-file=" + oat_location);
args.push_back("--compiler-filter=" + CompilerFilter::NameOfFilter(filter));
args.push_back("--runtime-arg");
args.push_back("-Xnorelocate");
- std::string error_msg;
ASSERT_TRUE(OatFileAssistant::Dex2Oat(args, &error_msg)) << error_msg;
// Verify the oat file was generated as expected.
- std::unique_ptr<OatFile> oat_file(OatFile::Open(oat_location->c_str(),
- oat_location->c_str(),
+ std::unique_ptr<OatFile> oat_file(OatFile::Open(oat_location.c_str(),
+ oat_location.c_str(),
nullptr,
nullptr,
false,
@@ -1212,21 +1212,21 @@
oat_file_assistant.MakeUpToDate(false, &error_msg));
}
-TEST(OatFileAssistantUtilsTest, DexFilenameToOdexFilename) {
+TEST(OatFileAssistantUtilsTest, DexLocationToOdexFilename) {
std::string error_msg;
std::string odex_file;
- EXPECT_TRUE(OatFileAssistant::DexFilenameToOdexFilename(
+ EXPECT_TRUE(OatFileAssistant::DexLocationToOdexFilename(
"/foo/bar/baz.jar", kArm, &odex_file, &error_msg)) << error_msg;
EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
- EXPECT_TRUE(OatFileAssistant::DexFilenameToOdexFilename(
+ EXPECT_TRUE(OatFileAssistant::DexLocationToOdexFilename(
"/foo/bar/baz.funnyext", kArm, &odex_file, &error_msg)) << error_msg;
EXPECT_EQ("/foo/bar/oat/arm/baz.odex", odex_file);
- EXPECT_FALSE(OatFileAssistant::DexFilenameToOdexFilename(
+ EXPECT_FALSE(OatFileAssistant::DexLocationToOdexFilename(
"nopath.jar", kArm, &odex_file, &error_msg));
- EXPECT_FALSE(OatFileAssistant::DexFilenameToOdexFilename(
+ EXPECT_FALSE(OatFileAssistant::DexLocationToOdexFilename(
"/foo/bar/baz_noext", kArm, &odex_file, &error_msg));
}