diff options
Diffstat (limited to 'runtime/utils.cc')
| -rw-r--r-- | runtime/utils.cc | 91 |
1 files changed, 83 insertions, 8 deletions
diff --git a/runtime/utils.cc b/runtime/utils.cc index 8b1ad39edc..48d6cdf263 100644 --- a/runtime/utils.cc +++ b/runtime/utils.cc @@ -281,6 +281,11 @@ std::string PrettyDescriptor(const std::string& descriptor) { return result; } +std::string PrettyDescriptor(Primitive::Type type) { + std::string descriptor_string(Primitive::Descriptor(type)); + return PrettyDescriptor(descriptor_string); +} + std::string PrettyField(mirror::ArtField* f, bool with_type) { if (f == NULL) { return "null"; @@ -1154,22 +1159,55 @@ const char* GetAndroidRoot() { } const char* GetAndroidData() { + std::string error_msg; + const char* dir = GetAndroidDataSafe(&error_msg); + if (dir != nullptr) { + return dir; + } else { + LOG(FATAL) << error_msg; + return ""; + } +} + +const char* GetAndroidDataSafe(std::string* error_msg) { const char* android_data = getenv("ANDROID_DATA"); if (android_data == NULL) { if (OS::DirectoryExists("/data")) { android_data = "/data"; } else { - LOG(FATAL) << "ANDROID_DATA not set and /data does not exist"; - return ""; + *error_msg = "ANDROID_DATA not set and /data does not exist"; + return nullptr; } } if (!OS::DirectoryExists(android_data)) { - LOG(FATAL) << "Failed to find ANDROID_DATA directory " << android_data; - return ""; + *error_msg = StringPrintf("Failed to find ANDROID_DATA directory %s", android_data); + return nullptr; } return android_data; } +void GetDalvikCache(const char* subdir, const bool create_if_absent, std::string* dalvik_cache, + bool* have_android_data, bool* dalvik_cache_exists) { + CHECK(subdir != nullptr); + std::string error_msg; + const char* android_data = GetAndroidDataSafe(&error_msg); + if (android_data == nullptr) { + *have_android_data = false; + *dalvik_cache_exists = false; + return; + } else { + *have_android_data = true; + } + const std::string dalvik_cache_root(StringPrintf("%s/dalvik-cache/", android_data)); + *dalvik_cache = dalvik_cache_root + subdir; + *dalvik_cache_exists = OS::DirectoryExists(dalvik_cache->c_str()); + if (create_if_absent && !*dalvik_cache_exists && strcmp(android_data, "/data") != 0) { + // Don't create the system's /data/dalvik-cache/... because it needs special permissions. + *dalvik_cache_exists = ((mkdir(dalvik_cache_root.c_str(), 0700) == 0 || errno == EEXIST) && + (mkdir(dalvik_cache->c_str(), 0700) == 0 || errno == EEXIST)); + } +} + std::string GetDalvikCacheOrDie(const char* subdir, const bool create_if_absent) { CHECK(subdir != nullptr); const char* android_data = GetAndroidData(); @@ -1196,17 +1234,29 @@ std::string GetDalvikCacheOrDie(const char* subdir, const bool create_if_absent) return dalvik_cache; } -std::string GetDalvikCacheFilenameOrDie(const char* location, const char* cache_location) { +bool GetDalvikCacheFilename(const char* location, const char* cache_location, + std::string* filename, std::string* error_msg) { if (location[0] != '/') { - LOG(FATAL) << "Expected path in location to be absolute: "<< location; + *error_msg = StringPrintf("Expected path in location to be absolute: %s", location); + return false; } std::string cache_file(&location[1]); // skip leading slash - if (!EndsWith(location, ".dex") && !EndsWith(location, ".art")) { + if (!EndsWith(location, ".dex") && !EndsWith(location, ".art") && !EndsWith(location, ".oat")) { cache_file += "/"; cache_file += DexFile::kClassesDex; } std::replace(cache_file.begin(), cache_file.end(), '/', '@'); - return StringPrintf("%s/%s", cache_location, cache_file.c_str()); + *filename = StringPrintf("%s/%s", cache_location, cache_file.c_str()); + return true; +} + +std::string GetDalvikCacheFilenameOrDie(const char* location, const char* cache_location) { + std::string ret; + std::string error_msg; + if (!GetDalvikCacheFilename(location, cache_location, &ret, &error_msg)) { + LOG(FATAL) << error_msg; + } + return ret; } static void InsertIsaDirectory(const InstructionSet isa, std::string* filename) { @@ -1309,4 +1359,29 @@ bool Exec(std::vector<std::string>& arg_vector, std::string* error_msg) { return true; } +void EncodeUnsignedLeb128(uint32_t data, std::vector<uint8_t>* dst) { + size_t encoded_size = UnsignedLeb128Size(data); + size_t cur_index = dst->size(); + dst->resize(dst->size() + encoded_size); + uint8_t* write_pos = &((*dst)[cur_index]); + uint8_t* write_pos_after = EncodeUnsignedLeb128(write_pos, data); + DCHECK_EQ(static_cast<size_t>(write_pos_after - write_pos), encoded_size); +} + +void EncodeSignedLeb128(int32_t data, std::vector<uint8_t>* dst) { + size_t encoded_size = SignedLeb128Size(data); + size_t cur_index = dst->size(); + dst->resize(dst->size() + encoded_size); + uint8_t* write_pos = &((*dst)[cur_index]); + uint8_t* write_pos_after = EncodeSignedLeb128(write_pos, data); + DCHECK_EQ(static_cast<size_t>(write_pos_after - write_pos), encoded_size); +} + +void PushWord(std::vector<uint8_t>* buf, int data) { + buf->push_back(data & 0xff); + buf->push_back((data >> 8) & 0xff); + buf->push_back((data >> 16) & 0xff); + buf->push_back((data >> 24) & 0xff); +} + } // namespace art |