diff options
Diffstat (limited to 'runtime/utils.cc')
| -rw-r--r-- | runtime/utils.cc | 94 |
1 files changed, 5 insertions, 89 deletions
diff --git a/runtime/utils.cc b/runtime/utils.cc index bd4175f5fd..393b18e1b3 100644 --- a/runtime/utils.cc +++ b/runtime/utils.cc @@ -26,13 +26,12 @@ #include <memory> +#include "android-base/file.h" #include "android-base/stringprintf.h" #include "android-base/strings.h" -#include "base/file_utils.h" -#include "dex/dex_file-inl.h" +#include "dex/utf-inl.h" #include "os.h" -#include "utf-inl.h" #if defined(__APPLE__) #include <crt_externs.h> @@ -46,6 +45,7 @@ namespace art { +using android::base::ReadFileToString; using android::base::StringAppendF; using android::base::StringPrintf; @@ -63,6 +63,7 @@ pid_t GetTid() { std::string GetThreadName(pid_t tid) { std::string result; + // TODO: make this less Linux-specific. if (ReadFileToString(StringPrintf("/proc/self/task/%d/comm", tid), &result)) { result.resize(result.size() - 1); // Lose the trailing '\n'. } else { @@ -124,41 +125,6 @@ std::string PrettyDescriptor(const char* descriptor) { return result; } -std::string PrettyJavaAccessFlags(uint32_t access_flags) { - std::string result; - if ((access_flags & kAccPublic) != 0) { - result += "public "; - } - if ((access_flags & kAccProtected) != 0) { - result += "protected "; - } - if ((access_flags & kAccPrivate) != 0) { - result += "private "; - } - if ((access_flags & kAccFinal) != 0) { - result += "final "; - } - if ((access_flags & kAccStatic) != 0) { - result += "static "; - } - if ((access_flags & kAccAbstract) != 0) { - result += "abstract "; - } - if ((access_flags & kAccInterface) != 0) { - result += "interface "; - } - if ((access_flags & kAccTransient) != 0) { - result += "transient "; - } - if ((access_flags & kAccVolatile) != 0) { - result += "volatile "; - } - if ((access_flags & kAccSynchronized) != 0) { - result += "synchronized "; - } - return result; -} - std::string PrettySize(int64_t byte_count) { // The byte thresholds at which we display amounts. A byte count is displayed // in unit U when kUnitThresholds[U] <= bytes < kUnitThresholds[U+1]. @@ -185,57 +151,6 @@ std::string PrettySize(int64_t byte_count) { negative_str, byte_count / kBytesPerUnit[i], kUnitStrings[i]); } -static inline constexpr bool NeedsEscaping(uint16_t ch) { - return (ch < ' ' || ch > '~'); -} - -std::string PrintableChar(uint16_t ch) { - std::string result; - result += '\''; - if (NeedsEscaping(ch)) { - StringAppendF(&result, "\\u%04x", ch); - } else { - result += static_cast<std::string::value_type>(ch); - } - result += '\''; - return result; -} - -std::string PrintableString(const char* utf) { - std::string result; - result += '"'; - const char* p = utf; - size_t char_count = CountModifiedUtf8Chars(p); - for (size_t i = 0; i < char_count; ++i) { - uint32_t ch = GetUtf16FromUtf8(&p); - if (ch == '\\') { - result += "\\\\"; - } else if (ch == '\n') { - result += "\\n"; - } else if (ch == '\r') { - result += "\\r"; - } else if (ch == '\t') { - result += "\\t"; - } else { - const uint16_t leading = GetLeadingUtf16Char(ch); - - if (NeedsEscaping(leading)) { - StringAppendF(&result, "\\u%04x", leading); - } else { - result += static_cast<std::string::value_type>(leading); - } - - const uint32_t trailing = GetTrailingUtf16Char(ch); - if (trailing != 0) { - // All high surrogates will need escaping. - StringAppendF(&result, "\\u%04x", trailing); - } - } - } - result += '"'; - return result; -} - std::string GetJniShortName(const std::string& class_descriptor, const std::string& method) { // Remove the leading 'L' and trailing ';'... std::string class_name(class_descriptor); @@ -611,6 +526,7 @@ void SetThreadName(const char* thread_name) { void GetTaskStats(pid_t tid, char* state, int* utime, int* stime, int* task_cpu) { *utime = *stime = *task_cpu = 0; std::string stats; + // TODO: make this less Linux-specific. if (!ReadFileToString(StringPrintf("/proc/self/task/%d/stat", tid), &stats)) { return; } |