diff options
Diffstat (limited to 'libartbase/base/utils.h')
-rw-r--r-- | libartbase/base/utils.h | 63 |
1 files changed, 7 insertions, 56 deletions
diff --git a/libartbase/base/utils.h b/libartbase/base/utils.h index 24adbb3004..11472a8017 100644 --- a/libartbase/base/utils.h +++ b/libartbase/base/utils.h @@ -24,6 +24,7 @@ #include <string> #include <android-base/logging.h> +#include <android-base/parseint.h> #include "casts.h" #include "enums.h" @@ -33,34 +34,6 @@ namespace art { -template <typename T> -bool ParseUint(const char *in, T* out) { - char* end; - unsigned long long int result = strtoull(in, &end, 0); // NOLINT(runtime/int) - if (in == end || *end != '\0') { - return false; - } - if (std::numeric_limits<T>::max() < result) { - return false; - } - *out = static_cast<T>(result); - return true; -} - -template <typename T> -bool ParseInt(const char* in, T* out) { - char* end; - long long int result = strtoll(in, &end, 0); // NOLINT(runtime/int) - if (in == end || *end != '\0') { - return false; - } - if (result < std::numeric_limits<T>::min() || std::numeric_limits<T>::max() < result) { - return false; - } - *out = static_cast<T>(result); - return true; -} - static inline uint32_t PointerToLowMemUInt32(const void* p) { uintptr_t intp = reinterpret_cast<uintptr_t>(p); DCHECK_LE(intp, 0xFFFFFFFFU); @@ -130,7 +103,7 @@ static void ParseIntOption(const StringPiece& option, DCHECK(option.starts_with(option_prefix)) << option << " " << option_prefix; const char* value_string = option.substr(option_prefix.size()).data(); int64_t parsed_integer_value = 0; - if (!ParseInt(value_string, &parsed_integer_value)) { + if (!android::base::ParseInt(value_string, &parsed_integer_value)) { usage("Failed to parse %s '%s' as an integer", option_name.c_str(), value_string); } *out = dchecked_integral_cast<T>(parsed_integer_value); @@ -189,9 +162,6 @@ inline void FlushInstructionCache(void* begin, void* end) { __builtin___clear_cache(reinterpret_cast<char*>(begin), reinterpret_cast<char*>(end)); } -// Flush instruction pipeline. Returns true on success, false if feature is unsupported. -bool FlushInstructionPipeline(); - template <typename T> constexpr PointerSize ConvertToPointerSize(T any) { if (any == 4 || any == 8) { @@ -202,30 +172,6 @@ constexpr PointerSize ConvertToPointerSize(T any) { } } -// Returns a type cast pointer if object pointed to is within the provided bounds. -// Otherwise returns nullptr. -template <typename T> -inline static T BoundsCheckedCast(const void* pointer, - const void* lower, - const void* upper) { - const uint8_t* bound_begin = static_cast<const uint8_t*>(lower); - const uint8_t* bound_end = static_cast<const uint8_t*>(upper); - DCHECK(bound_begin <= bound_end); - - T result = reinterpret_cast<T>(pointer); - const uint8_t* begin = static_cast<const uint8_t*>(pointer); - const uint8_t* end = begin + sizeof(*result); - if (begin < bound_begin || end > bound_end || begin > end) { - return nullptr; - } - return result; -} - -template <typename T, size_t size> -constexpr size_t ArrayCount(const T (&)[size]) { - return size; -} - // Return -1 if <, 0 if ==, 1 if >. template <typename T> inline static int32_t Compare(T lhs, T rhs) { @@ -246,6 +192,11 @@ static inline void CheckedCall(const Func& function, const char* what, Args... a } } +// Lookup value for a given key in /proc/self/status. Keys and values are separated by a ':' in +// the status file. Returns value found on success and "<unknown>" if the key is not found or +// there is an I/O error. +std::string GetProcessStatus(const char* key); + } // namespace art #endif // ART_LIBARTBASE_BASE_UTILS_H_ |