utils.h revision 2afe49450f2e018f18b5de45428b9174bfd6f196
12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/* 22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2011 The Android Open Source Project 32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License. 62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at 72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software 112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and 142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License. 152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */ 16a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro 17fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#ifndef ART_RUNTIME_UTILS_H_ 18fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#define ART_RUNTIME_UTILS_H_ 19a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro 2092b3b5623ec8b65f3e099c076e247bb8273692f8Elliott Hughes#include <pthread.h> 21e222ee0b794f941af4fb1b32fb8224e32942ea7bElliott Hughes 2234023801bd544e613d6e85c9a5b2e743f3710e8fElliott Hughes#include <string> 2334023801bd544e613d6e85c9a5b2e743f3710e8fElliott Hughes#include <vector> 2434023801bd544e613d6e85c9a5b2e743f3710e8fElliott Hughes 25e222ee0b794f941af4fb1b32fb8224e32942ea7bElliott Hughes#include "base/logging.h" 26e222ee0b794f941af4fb1b32fb8224e32942ea7bElliott Hughes#include "base/stringprintf.h" 27e222ee0b794f941af4fb1b32fb8224e32942ea7bElliott Hughes#include "globals.h" 280e12bdc49744eb6d5c29b9611a8dbe10bac4cd53Brian Carlstrom#include "instruction_set.h" 29e222ee0b794f941af4fb1b32fb8224e32942ea7bElliott Hughes#include "primitive.h" 30e222ee0b794f941af4fb1b32fb8224e32942ea7bElliott Hughes 316b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapironamespace art { 32a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro 330571d357843c53e042f370f5f2c2e9aa3fe803a9Ian Rogersclass DexFile; 342dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers 352dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogersnamespace mirror { 36ea46f950e7a51585db293cd7f047de190a482414Brian Carlstromclass ArtField; 37ea46f950e7a51585db293cd7f047de190a482414Brian Carlstromclass ArtMethod; 382dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogersclass Class; 3911e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughesclass Object; 405174fe6e4e931c423e910366ff22ce0838567940Elliott Hughesclass String; 412dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers} // namespace mirror 4211e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 430325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartierenum TimeUnit { 440325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartier kTimeUnitNanosecond, 450325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartier kTimeUnitMicrosecond, 460325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartier kTimeUnitMillisecond, 470325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartier kTimeUnitSecond, 480325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartier}; 490325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartier 50a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapirotemplate<typename T> 518194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Markostatic constexpr bool IsPowerOfTwo(T x) { 52a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro return (x & (x - 1)) == 0; 53a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro} 54a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro 5506b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughestemplate<int n, typename T> 5606b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughesstatic inline bool IsAligned(T x) { 5706b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughes COMPILE_ASSERT((n & (n - 1)) == 0, n_not_power_of_two); 58a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro return (x & (n - 1)) == 0; 59a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro} 60a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro 6106b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughestemplate<int n, typename T> 6206b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughesstatic inline bool IsAligned(T* x) { 6389521898b56f2ebc3fb68acfb6bc6dde9b6f5c38Brian Carlstrom return IsAligned<n>(reinterpret_cast<const uintptr_t>(x)); 64a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro} 65a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro 66af13ad9fd18b6f75fe82e7995224c55654594f93Andreas Gampetemplate<typename T> 67af13ad9fd18b6f75fe82e7995224c55654594f93Andreas Gampestatic inline bool IsAlignedParam(T x, int n) { 68af13ad9fd18b6f75fe82e7995224c55654594f93Andreas Gampe return (x & (n - 1)) == 0; 69af13ad9fd18b6f75fe82e7995224c55654594f93Andreas Gampe} 70af13ad9fd18b6f75fe82e7995224c55654594f93Andreas Gampe 7106b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughes#define CHECK_ALIGNED(value, alignment) \ 7289521898b56f2ebc3fb68acfb6bc6dde9b6f5c38Brian Carlstrom CHECK(::art::IsAligned<alignment>(value)) << reinterpret_cast<const void*>(value) 7306b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughes 7406b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughes#define DCHECK_ALIGNED(value, alignment) \ 7589521898b56f2ebc3fb68acfb6bc6dde9b6f5c38Brian Carlstrom DCHECK(::art::IsAligned<alignment>(value)) << reinterpret_cast<const void*>(value) 76af13ad9fd18b6f75fe82e7995224c55654594f93Andreas Gampe 77af13ad9fd18b6f75fe82e7995224c55654594f93Andreas Gampe#define DCHECK_ALIGNED_PARAM(value, alignment) \ 78af13ad9fd18b6f75fe82e7995224c55654594f93Andreas Gampe DCHECK(::art::IsAlignedParam(value, alignment)) << reinterpret_cast<const void*>(value) 7906b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughes 80a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro// Check whether an N-bit two's-complement representation can hold value. 81a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapirostatic inline bool IsInt(int N, word value) { 82a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro CHECK_LT(0, N); 83a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro CHECK_LT(N, kBitsPerWord); 84a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro word limit = static_cast<word>(1) << (N - 1); 85a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro return (-limit <= value) && (value < limit); 86a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro} 87a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro 88a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapirostatic inline bool IsUint(int N, word value) { 89a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro CHECK_LT(0, N); 90a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro CHECK_LT(N, kBitsPerWord); 91a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro word limit = static_cast<word>(1) << N; 92a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro return (0 <= value) && (value < limit); 93a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro} 94a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro 95a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapirostatic inline bool IsAbsoluteUint(int N, word value) { 96a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro CHECK_LT(0, N); 97a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro CHECK_LT(N, kBitsPerWord); 98a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro if (value < 0) value = -value; 99a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro return IsUint(N, value); 100a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro} 101a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro 1024ef3e45d7c6ec3c482a1a48f4df470811aa3cf0abuzbeestatic inline uint16_t Low16Bits(uint32_t value) { 1034ef3e45d7c6ec3c482a1a48f4df470811aa3cf0abuzbee return static_cast<uint16_t>(value); 104b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers} 105b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers 1064ef3e45d7c6ec3c482a1a48f4df470811aa3cf0abuzbeestatic inline uint16_t High16Bits(uint32_t value) { 1074ef3e45d7c6ec3c482a1a48f4df470811aa3cf0abuzbee return static_cast<uint16_t>(value >> 16); 108b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers} 109a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro 1104ef3e45d7c6ec3c482a1a48f4df470811aa3cf0abuzbeestatic inline uint32_t Low32Bits(uint64_t value) { 1114ef3e45d7c6ec3c482a1a48f4df470811aa3cf0abuzbee return static_cast<uint32_t>(value); 112a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro} 113a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro 1144ef3e45d7c6ec3c482a1a48f4df470811aa3cf0abuzbeestatic inline uint32_t High32Bits(uint64_t value) { 1154ef3e45d7c6ec3c482a1a48f4df470811aa3cf0abuzbee return static_cast<uint32_t>(value >> 32); 116a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro} 117a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro 1180a9dc05e704bfd033bac2aa38a4fc6f6b8e6cf93Mathieu Chartier// A static if which determines whether to return type A or B based on the condition boolean. 1198194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Markotemplate <bool condition, typename A, typename B> 1200a9dc05e704bfd033bac2aa38a4fc6f6b8e6cf93Mathieu Chartierstruct TypeStaticIf { 1218194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko typedef A type; 1220a9dc05e704bfd033bac2aa38a4fc6f6b8e6cf93Mathieu Chartier}; 1230a9dc05e704bfd033bac2aa38a4fc6f6b8e6cf93Mathieu Chartier 1240a9dc05e704bfd033bac2aa38a4fc6f6b8e6cf93Mathieu Chartier// Specialization to handle the false case. 1250a9dc05e704bfd033bac2aa38a4fc6f6b8e6cf93Mathieu Chartiertemplate <typename A, typename B> 1260a9dc05e704bfd033bac2aa38a4fc6f6b8e6cf93Mathieu Chartierstruct TypeStaticIf<false, A, B> { 1278194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko typedef B type; 1288194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko}; 1298194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko 1308194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko// Type identity. 1318194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Markotemplate <typename T> 1328194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Markostruct TypeIdentity { 1338194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko typedef T type; 1340a9dc05e704bfd033bac2aa38a4fc6f6b8e6cf93Mathieu Chartier}; 1350a9dc05e704bfd033bac2aa38a4fc6f6b8e6cf93Mathieu Chartier 1360941b0423537a6a5d7c1df6dd23e9864ea8f319cHiroshi Yamauchi// For rounding integers. 13761e019d291583029c01b61b93bea750f2b663c37Carl Shapirotemplate<typename T> 1388194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Markostatic constexpr T RoundDown(T x, typename TypeIdentity<T>::type n) { 1398194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko return 1408194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko // DCHECK(IsPowerOfTwo(n)) in a form acceptable in a constexpr function: 1418194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko (kIsDebugBuild && !IsPowerOfTwo(n)) ? (LOG(FATAL) << n << " isn't a power of 2", T(0)) 1428194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko : (x & -n); 14361e019d291583029c01b61b93bea750f2b663c37Carl Shapiro} 14461e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 14561e019d291583029c01b61b93bea750f2b663c37Carl Shapirotemplate<typename T> 1468194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Markostatic constexpr T RoundUp(T x, typename TypeIdentity<T>::type n) { 14761e019d291583029c01b61b93bea750f2b663c37Carl Shapiro return RoundDown(x + n - 1, n); 14861e019d291583029c01b61b93bea750f2b663c37Carl Shapiro} 14961e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 1500941b0423537a6a5d7c1df6dd23e9864ea8f319cHiroshi Yamauchi// For aligning pointers. 1510941b0423537a6a5d7c1df6dd23e9864ea8f319cHiroshi Yamauchitemplate<typename T> 1528194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Markostatic inline T* AlignDown(T* x, uintptr_t n) { 1538194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko return reinterpret_cast<T*>(RoundDown(reinterpret_cast<uintptr_t>(x), n)); 1540941b0423537a6a5d7c1df6dd23e9864ea8f319cHiroshi Yamauchi} 1550941b0423537a6a5d7c1df6dd23e9864ea8f319cHiroshi Yamauchi 1560941b0423537a6a5d7c1df6dd23e9864ea8f319cHiroshi Yamauchitemplate<typename T> 1578194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Markostatic inline T* AlignUp(T* x, uintptr_t n) { 1588194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko return reinterpret_cast<T*>(RoundUp(reinterpret_cast<uintptr_t>(x), n)); 1590941b0423537a6a5d7c1df6dd23e9864ea8f319cHiroshi Yamauchi} 1600941b0423537a6a5d7c1df6dd23e9864ea8f319cHiroshi Yamauchi 161a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro// Implementation is from "Hacker's Delight" by Henry S. Warren, Jr., 1621fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro// figure 3-3, page 48, where the function is called clp2. 1631fb8620309a4e94d11879aabc33364acfa733904Carl Shapirostatic inline uint32_t RoundUpToPowerOfTwo(uint32_t x) { 1641fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro x = x - 1; 1651fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro x = x | (x >> 1); 1661fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro x = x | (x >> 2); 1671fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro x = x | (x >> 4); 1681fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro x = x | (x >> 8); 1691fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro x = x | (x >> 16); 1701fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro return x + 1; 1711fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro} 1721fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro 1738194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Markotemplate<typename T> 1748194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Markostatic constexpr int CLZ(T x) { 1758194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko return (sizeof(T) == sizeof(uint32_t)) 1768194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko ? __builtin_clz(x) 1778194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko : __builtin_clzll(x); 178a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro} 179a2e18e1e77fc25c8260aad5daa267ababfcb65f6Carl Shapiro 180ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogerstemplate<typename T> 1818194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Markostatic constexpr int CTZ(T x) { 1828194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko return (sizeof(T) == sizeof(uint32_t)) 1838194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko ? __builtin_ctz(x) 1848194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko : __builtin_ctzll(x); 185ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers} 186ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers 187ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogerstemplate<typename T> 1888194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Markostatic constexpr int POPCOUNT(T x) { 1898194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko return (sizeof(T) == sizeof(uint32_t)) 1908194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko ? __builtin_popcount(x) 1918194963098247be6bca9cc4a54dbfa65c73e8cccVladimir Marko : __builtin_popcountll(x); 192ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers} 193ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers 194ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogersstatic inline uint32_t PointerToLowMemUInt32(const void* p) { 195ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers uintptr_t intp = reinterpret_cast<uintptr_t>(p); 196ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers DCHECK_LE(intp, 0xFFFFFFFFU); 197ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return intp & 0xFFFFFFFFU; 198ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers} 199db4d54081f09abcbe97ffdf615874f2809a9e777Brian Carlstrom 20046b92ba72247e10884714d0b683bdb5e9d9ce59dElliott Hughesstatic inline bool NeedsEscaping(uint16_t ch) { 20146b92ba72247e10884714d0b683bdb5e9d9ce59dElliott Hughes return (ch < ' ' || ch > '~'); 20246b92ba72247e10884714d0b683bdb5e9d9ce59dElliott Hughes} 20346b92ba72247e10884714d0b683bdb5e9d9ce59dElliott Hughes 204c7ac37f0b8b64cfb53d8b9cc8dddbb34be3dd5eeElliott Hughesstatic inline std::string PrintableChar(uint16_t ch) { 205c7ac37f0b8b64cfb53d8b9cc8dddbb34be3dd5eeElliott Hughes std::string result; 20646b92ba72247e10884714d0b683bdb5e9d9ce59dElliott Hughes result += '\''; 20746b92ba72247e10884714d0b683bdb5e9d9ce59dElliott Hughes if (NeedsEscaping(ch)) { 20846b92ba72247e10884714d0b683bdb5e9d9ce59dElliott Hughes StringAppendF(&result, "\\u%04x", ch); 20946b92ba72247e10884714d0b683bdb5e9d9ce59dElliott Hughes } else { 210c7ac37f0b8b64cfb53d8b9cc8dddbb34be3dd5eeElliott Hughes result += ch; 211c7ac37f0b8b64cfb53d8b9cc8dddbb34be3dd5eeElliott Hughes } 21246b92ba72247e10884714d0b683bdb5e9d9ce59dElliott Hughes result += '\''; 213c7ac37f0b8b64cfb53d8b9cc8dddbb34be3dd5eeElliott Hughes return result; 214c7ac37f0b8b64cfb53d8b9cc8dddbb34be3dd5eeElliott Hughes} 215c7ac37f0b8b64cfb53d8b9cc8dddbb34be3dd5eeElliott Hughes 21682914b6164fd0109531391975389e4f0ff6832c8Elliott Hughes// Returns an ASCII string corresponding to the given UTF-8 string. 21782914b6164fd0109531391975389e4f0ff6832c8Elliott Hughes// Java escapes are used for non-ASCII characters. 21882914b6164fd0109531391975389e4f0ff6832c8Elliott Hughesstd::string PrintableString(const std::string& utf8); 219c7ac37f0b8b64cfb53d8b9cc8dddbb34be3dd5eeElliott Hughes 220f1a5adc87760f938b01df26d906295063546b259Elliott Hughes// Tests whether 's' starts with 'prefix'. 221f1a5adc87760f938b01df26d906295063546b259Elliott Hughesbool StartsWith(const std::string& s, const char* prefix); 222f1a5adc87760f938b01df26d906295063546b259Elliott Hughes 2237a967b3d4468ab56bf1b75ebd4d7bf9e6798761bBrian Carlstrom// Tests whether 's' starts with 'suffix'. 2247a967b3d4468ab56bf1b75ebd4d7bf9e6798761bBrian Carlstrombool EndsWith(const std::string& s, const char* suffix); 2257a967b3d4468ab56bf1b75ebd4d7bf9e6798761bBrian Carlstrom 22654e7df1896a4066cbb9fe6f72249829f0b8c49c6Elliott Hughes// Used to implement PrettyClass, PrettyField, PrettyMethod, and PrettyTypeOf, 22754e7df1896a4066cbb9fe6f72249829f0b8c49c6Elliott Hughes// one of which is probably more useful to you. 228a0b8feb34a8492c6b8d430f6ca0716e7ff4f4c57Elliott Hughes// Returns a human-readable equivalent of 'descriptor'. So "I" would be "int", 229a0b8feb34a8492c6b8d430f6ca0716e7ff4f4c57Elliott Hughes// "[[I" would be "int[][]", "[Ljava/lang/String;" would be 230a0b8feb34a8492c6b8d430f6ca0716e7ff4f4c57Elliott Hughes// "java.lang.String[]", and so forth. 231ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogersstd::string PrettyDescriptor(mirror::String* descriptor) 232ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 2336c8867daab4af4667e0e816f6beafa7c5d13e043Elliott Hughesstd::string PrettyDescriptor(const std::string& descriptor); 2346b4ef025af12b158d117fc80fc79acf620f411a0Brian Carlstromstd::string PrettyDescriptor(Primitive::Type type); 235ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogersstd::string PrettyDescriptor(mirror::Class* klass) 236b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 23711e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 23854e7df1896a4066cbb9fe6f72249829f0b8c49c6Elliott Hughes// Returns a human-readable signature for 'f'. Something like "a.b.C.f" or 23954e7df1896a4066cbb9fe6f72249829f0b8c49c6Elliott Hughes// "int a.b.C.f" (depending on the value of 'with_type'). 240ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogersstd::string PrettyField(mirror::ArtField* f, bool with_type = true) 241b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 2426f29d0e6d5444ff84157c922c23c221567dcc6c5Brian Carlstromstd::string PrettyField(uint32_t field_idx, const DexFile& dex_file, bool with_type = true); 243a2501990dd0f68baf38ce19251949d7bb3ecfe5aElliott Hughes 244a0b8feb34a8492c6b8d430f6ca0716e7ff4f4c57Elliott Hughes// Returns a human-readable signature for 'm'. Something like "a.b.C.m" or 245a0b8feb34a8492c6b8d430f6ca0716e7ff4f4c57Elliott Hughes// "a.b.C.m(II)V" (depending on the value of 'with_signature'). 246ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogersstd::string PrettyMethod(mirror::ArtMethod* m, bool with_signature = true) 247b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 2480571d357843c53e042f370f5f2c2e9aa3fe803a9Ian Rogersstd::string PrettyMethod(uint32_t method_idx, const DexFile& dex_file, bool with_signature = true); 249a0b8feb34a8492c6b8d430f6ca0716e7ff4f4c57Elliott Hughes 250a0b8feb34a8492c6b8d430f6ca0716e7ff4f4c57Elliott Hughes// Returns a human-readable form of the name of the *class* of the given object. 251a0b8feb34a8492c6b8d430f6ca0716e7ff4f4c57Elliott Hughes// So given an instance of java.lang.String, the output would 25211e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes// be "java.lang.String". Given an array of int, the output would be "int[]". 25311e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes// Given String.class, the output would be "java.lang.Class<java.lang.String>". 254ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogersstd::string PrettyTypeOf(mirror::Object* obj) 255b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 2564c70d77decc1217c8b1ebf8126b8d9d024c75d82Mathieu Chartier 2574c70d77decc1217c8b1ebf8126b8d9d024c75d82Mathieu Chartier// Returns a human-readable form of the type at an index in the specified dex file. 2584c70d77decc1217c8b1ebf8126b8d9d024c75d82Mathieu Chartier// Example outputs: char[], java.lang.String. 25918c24b6e05e7591069f1a2ac9c614b28fc0853acMathieu Chartierstd::string PrettyType(uint32_t type_idx, const DexFile& dex_file); 26054e7df1896a4066cbb9fe6f72249829f0b8c49c6Elliott Hughes 26154e7df1896a4066cbb9fe6f72249829f0b8c49c6Elliott Hughes// Returns a human-readable form of the name of the given class. 26254e7df1896a4066cbb9fe6f72249829f0b8c49c6Elliott Hughes// Given String.class, the output would be "java.lang.Class<java.lang.String>". 263ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogersstd::string PrettyClass(mirror::Class* c) 264b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 26511e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes 266d81871cbbaa34c649e488f94f61a981db33123e5Ian Rogers// Returns a human-readable form of the name of the given class with its class loader. 267ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogersstd::string PrettyClassAndClassLoader(mirror::Class* c) 268b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 269d81871cbbaa34c649e488f94f61a981db33123e5Ian Rogers 270c967f78cd29b6019f7cfca40a02e9b677112da70Elliott Hughes// Returns a human-readable size string such as "1MB". 271e6da9af8dfe0a3e3fbc2be700554f6478380e7b9Mathieu Chartierstd::string PrettySize(int64_t size_in_bytes); 2723bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogers 2733bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogers// Returns a human-readable time string which prints every nanosecond while trying to limit the 2743bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogers// number of trailing zeros. Prints using the largest human readable unit up to a second. 2753bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogers// e.g. "1ms", "1.000000001s", "1.001us" 2763bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogersstd::string PrettyDuration(uint64_t nano_duration); 2773bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogers 2780325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartier// Format a nanosecond time to specified units. 2790325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartierstd::string FormatDuration(uint64_t nano_duration, TimeUnit time_unit); 2800325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartier 2810325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartier// Get the appropriate unit for a nanosecond duration. 2820325e6296d2370c42e7be80d846bfc7f8b28423bMathieu ChartierTimeUnit GetAppropriateTimeUnit(uint64_t nano_duration); 2830325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartier 2847020278bce98a0735dc6abcbd33bdf1ed2634f1dDave Allison// Get the divisor to convert from a nanoseconds to a time unit. 2850325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartieruint64_t GetNsToTimeUnitDivisor(TimeUnit time_unit); 2860325e6296d2370c42e7be80d846bfc7f8b28423bMathieu Chartier 28779082e367845bbd68ec44ef2ddd1be8ef0e1550fElliott Hughes// Performs JNI name mangling as described in section 11.3 "Linking Native Methods" 28879082e367845bbd68ec44ef2ddd1be8ef0e1550fElliott Hughes// of the JNI spec. 28979082e367845bbd68ec44ef2ddd1be8ef0e1550fElliott Hughesstd::string MangleForJni(const std::string& s); 29079082e367845bbd68ec44ef2ddd1be8ef0e1550fElliott Hughes 291f91c8c328c922ecd522e1d3508d2603e78de8a7bBrian Carlstrom// Turn "java.lang.String" into "Ljava/lang/String;". 292f91c8c328c922ecd522e1d3508d2603e78de8a7bBrian Carlstromstd::string DotToDescriptor(const char* class_name); 293f91c8c328c922ecd522e1d3508d2603e78de8a7bBrian Carlstrom 294aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom// Turn "Ljava/lang/String;" into "java.lang.String". 295f1a5adc87760f938b01df26d906295063546b259Elliott Hughesstd::string DescriptorToDot(const char* descriptor); 296aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 29791bf6cd47174f5c17265320f7a350722720390a5Elliott Hughes// Turn "Ljava/lang/String;" into "java/lang/String". 29891bf6cd47174f5c17265320f7a350722720390a5Elliott Hughesstd::string DescriptorToName(const char* descriptor); 29991bf6cd47174f5c17265320f7a350722720390a5Elliott Hughes 300906e685ce43092812bf403016057376d0657a671Elliott Hughes// Tests for whether 's' is a valid class name in the three common forms: 301906e685ce43092812bf403016057376d0657a671Elliott Hughesbool IsValidBinaryClassName(const char* s); // "java.lang.String" 302906e685ce43092812bf403016057376d0657a671Elliott Hughesbool IsValidJniClassName(const char* s); // "java/lang/String" 303906e685ce43092812bf403016057376d0657a671Elliott Hughesbool IsValidDescriptor(const char* s); // "Ljava/lang/String;" 30464bf5a33d55aa779ef452552a466943002d39e4fElliott Hughes 30510037c866b04550fc5461058c398c2e3e509381ajeffhao// Returns whether the given string is a valid field or method name, 30610037c866b04550fc5461058c398c2e3e509381ajeffhao// additionally allowing names that begin with '<' and end with '>'. 30710037c866b04550fc5461058c398c2e3e509381ajeffhaobool IsValidMemberName(const char* s); 30810037c866b04550fc5461058c398c2e3e509381ajeffhao 30979082e367845bbd68ec44ef2ddd1be8ef0e1550fElliott Hughes// Returns the JNI native function name for the non-overloaded method 'm'. 310ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogersstd::string JniShortName(mirror::ArtMethod* m) 311b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 31279082e367845bbd68ec44ef2ddd1be8ef0e1550fElliott Hughes// Returns the JNI native function name for the overloaded method 'm'. 313ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogersstd::string JniLongName(mirror::ArtMethod* m) 314b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 31579082e367845bbd68ec44ef2ddd1be8ef0e1550fElliott Hughes 316d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughesbool ReadFileToString(const std::string& file_name, std::string* result); 317c143c55718342519db5398e41dda31422cf16c79buzbee 318e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes// Returns the current date in ISO yyyy-mm-dd hh:mm:ss format. 319e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughesstd::string GetIsoDate(); 320e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 3210512f02dd6623c0870c11fbf3274d7462f732136Elliott Hughes// Returns the monotonic time since some unspecified starting point in milliseconds. 3227162ad937f5f6bec32bf78d4675ff65cd6d1a233Elliott Hughesuint64_t MilliTime(); 3237162ad937f5f6bec32bf78d4675ff65cd6d1a233Elliott Hughes 3240512f02dd6623c0870c11fbf3274d7462f732136Elliott Hughes// Returns the monotonic time since some unspecified starting point in microseconds. 325a9ef3fd82bebc6370fc3ddbb094988feb6c83022jeffhaouint64_t MicroTime(); 326a9ef3fd82bebc6370fc3ddbb094988feb6c83022jeffhao 3270512f02dd6623c0870c11fbf3274d7462f732136Elliott Hughes// Returns the monotonic time since some unspecified starting point in nanoseconds. 32883df2ac4a051ee10eafde7587de2faf3f0150fadElliott Hughesuint64_t NanoTime(); 32983df2ac4a051ee10eafde7587de2faf3f0150fadElliott Hughes 3300512f02dd6623c0870c11fbf3274d7462f732136Elliott Hughes// Returns the thread-specific CPU-time clock in nanoseconds or -1 if unavailable. 3310512f02dd6623c0870c11fbf3274d7462f732136Elliott Hughesuint64_t ThreadCpuNanoTime(); 3320512f02dd6623c0870c11fbf3274d7462f732136Elliott Hughes 333bb551fa68ffc57f679b8c914ac856666f0348b77Elliott Hughes// Converts the given number of nanoseconds to milliseconds. 334720ef7680573c1afd12f99f02eee3045daee5168Mathieu Chartierstatic constexpr inline uint64_t NsToMs(uint64_t ns) { 3353bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogers return ns / 1000 / 1000; 3363bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogers} 3373bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogers 3383bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogers// Converts the given number of milliseconds to nanoseconds 339720ef7680573c1afd12f99f02eee3045daee5168Mathieu Chartierstatic constexpr inline uint64_t MsToNs(uint64_t ns) { 3403bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogers return ns * 1000 * 1000; 3413bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogers} 3423bb17a644e2945c3913cfbde245d2f520d62a3ffIan Rogers 343bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstrom#if defined(__APPLE__) 344bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstrom// No clocks to specify on OS/X, fake value to pass to routines that require a clock. 345bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstrom#define CLOCK_REALTIME 0xebadf00d 346bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstrom#endif 347bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstrom 34856edc432fa914f7ccfa87ce443e64f5ef475666dIan Rogers// Sleep for the given number of nanoseconds, a bad way to handle contention. 34956edc432fa914f7ccfa87ce443e64f5ef475666dIan Rogersvoid NanoSleep(uint64_t ns); 35056edc432fa914f7ccfa87ce443e64f5ef475666dIan Rogers 351bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstrom// Initialize a timespec to either an absolute or relative time. 352bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstromvoid InitTimeSpec(bool absolute, int clock, int64_t ms, int32_t ns, timespec* ts); 353bcc2926b9721f94c17ed98fae5264cc98f0e066fBrian Carlstrom 35448436bbff87aae61bba20029b4382fa41ce787feElliott Hughes// Splits a string using the given separator character into a vector of 35534023801bd544e613d6e85c9a5b2e743f3710e8fElliott Hughes// strings. Empty strings will be omitted. 35648436bbff87aae61bba20029b4382fa41ce787feElliott Hughesvoid Split(const std::string& s, char separator, std::vector<std::string>& result); 35748436bbff87aae61bba20029b4382fa41ce787feElliott Hughes 3587020278bce98a0735dc6abcbd33bdf1ed2634f1dDave Allison// Trims whitespace off both ends of the given string. 3597020278bce98a0735dc6abcbd33bdf1ed2634f1dDave Allisonstd::string Trim(std::string s); 3607020278bce98a0735dc6abcbd33bdf1ed2634f1dDave Allison 36148436bbff87aae61bba20029b4382fa41ce787feElliott Hughes// Joins a vector of strings into a single string, using the given separator. 36248436bbff87aae61bba20029b4382fa41ce787feElliott Hughestemplate <typename StringT> std::string Join(std::vector<StringT>& strings, char separator); 36334023801bd544e613d6e85c9a5b2e743f3710e8fElliott Hughes 36442ee14279065352a4b9a3e8028d02c567e847d05Elliott Hughes// Returns the calling thread's tid. (The C libraries don't expose this.) 36542ee14279065352a4b9a3e8028d02c567e847d05Elliott Hughespid_t GetTid(); 36642ee14279065352a4b9a3e8028d02c567e847d05Elliott Hughes 367289be85116aaf7c48413858b5d0448868b4e61f3Elliott Hughes// Returns the given thread's name. 368289be85116aaf7c48413858b5d0448868b4e61f3Elliott Hughesstd::string GetThreadName(pid_t tid); 369289be85116aaf7c48413858b5d0448868b4e61f3Elliott Hughes 370120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers// Returns details of the given thread's stack. 3712921201dce37ba40c55b89c0deca3c34bf64168eBrian Carlstromvoid GetThreadStack(pthread_t thread, void** stack_base, size_t* stack_size); 372e188419b971936086a188843378375f5ced13724Elliott Hughes 373bfe487be25652c5456236661b9d9c3579d2296c1Elliott Hughes// Reads data from "/proc/self/task/${tid}/stat". 3742921201dce37ba40c55b89c0deca3c34bf64168eBrian Carlstromvoid GetTaskStats(pid_t tid, char* state, int* utime, int* stime, int* task_cpu); 375bfe487be25652c5456236661b9d9c3579d2296c1Elliott Hughes 3761bac54ffa933fbe9b92b62437577f2f4583eff1aElliott Hughes// Returns the name of the scheduler group for the given thread the current process, or the empty string. 3771bac54ffa933fbe9b92b62437577f2f4583eff1aElliott Hughesstd::string GetSchedulerGroupName(pid_t tid); 3781bac54ffa933fbe9b92b62437577f2f4583eff1aElliott Hughes 379dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes// Sets the name of the current thread. The name may be truncated to an 380dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes// implementation-defined limit. 38122869a9026a08b544eca4cefd67386d347e30d2cElliott Hughesvoid SetThreadName(const char* thread_name); 382dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes 38346e251bf7200cc06f5a9a82ee2030e650f5e1443Elliott Hughes// Dumps the native stack for thread 'tid' to 'os'. 384067d20fd2fddd947ce3a014d023e9de249082ebeKenny Rootvoid DumpNativeStack(std::ostream& os, pid_t tid, const char* prefix = "", 385a2cee18799d7e61adb037a4219adb23fef7d022bChristopher Ferris mirror::ArtMethod* current_method = nullptr) 386067d20fd2fddd947ce3a014d023e9de249082ebeKenny Root NO_THREAD_SAFETY_ANALYSIS; 38746e251bf7200cc06f5a9a82ee2030e650f5e1443Elliott Hughes 38846e251bf7200cc06f5a9a82ee2030e650f5e1443Elliott Hughes// Dumps the kernel stack for thread 'tid' to 'os'. Note that this is only available on linux-x86. 38946e251bf7200cc06f5a9a82ee2030e650f5e1443Elliott Hughesvoid DumpKernelStack(std::ostream& os, pid_t tid, const char* prefix = "", bool include_count = true); 39046e251bf7200cc06f5a9a82ee2030e650f5e1443Elliott Hughes 3917020278bce98a0735dc6abcbd33bdf1ed2634f1dDave Allison// Find $ANDROID_ROOT, /system, or abort. 392a56fcd60596ae8694da21fccde5c56832e437c56Brian Carlstromconst char* GetAndroidRoot(); 393a56fcd60596ae8694da21fccde5c56832e437c56Brian Carlstrom 3947020278bce98a0735dc6abcbd33bdf1ed2634f1dDave Allison// Find $ANDROID_DATA, /data, or abort. 395a56fcd60596ae8694da21fccde5c56832e437c56Brian Carlstromconst char* GetAndroidData(); 396a56fcd60596ae8694da21fccde5c56832e437c56Brian Carlstrom 39711d9f06a96a6909905c248ed684366190140095cNarayan Kamath// Returns the dalvik-cache location, or dies trying. subdir will be 39811d9f06a96a6909905c248ed684366190140095cNarayan Kamath// appended to the cache location. 39911d9f06a96a6909905c248ed684366190140095cNarayan Kamathstd::string GetDalvikCacheOrDie(const char* subdir, bool create_if_absent = true); 40011d9f06a96a6909905c248ed684366190140095cNarayan Kamath 40111d9f06a96a6909905c248ed684366190140095cNarayan Kamath// Returns the absolute dalvik-cache path for a DexFile or OatFile, or 40211d9f06a96a6909905c248ed684366190140095cNarayan Kamath// dies trying. The path returned will be rooted at cache_location. 40311d9f06a96a6909905c248ed684366190140095cNarayan Kamathstd::string GetDalvikCacheFilenameOrDie(const char* file_location, 40411d9f06a96a6909905c248ed684366190140095cNarayan Kamath const char* cache_location); 405262bf46ddc91e5b4fbd367127ff21a1877d939f2jeffhao 4060e12bdc49744eb6d5c29b9611a8dbe10bac4cd53Brian Carlstrom// Returns the system location for an image 4072afe49450f2e018f18b5de45428b9174bfd6f196Brian Carlstromstd::string GetSystemImageFilename(const char* location, InstructionSet isa); 4080e12bdc49744eb6d5c29b9611a8dbe10bac4cd53Brian Carlstrom 4090e12bdc49744eb6d5c29b9611a8dbe10bac4cd53Brian Carlstrom// Returns an .odex file name next adjacent to the dex location. 4100e12bdc49744eb6d5c29b9611a8dbe10bac4cd53Brian Carlstrom// For example, for "/foo/bar/baz.jar", return "/foo/bar/<isa>/baz.odex". 4112afe49450f2e018f18b5de45428b9174bfd6f196Brian Carlstromstd::string DexFilenameToOdexFilename(const std::string& location, InstructionSet isa); 4120e12bdc49744eb6d5c29b9611a8dbe10bac4cd53Brian Carlstrom 4137c3d13aebdd8611cae58a1048bffb13cbdc465cbBrian Carlstrom// Check whether the given magic matches a known file type. 4147c3d13aebdd8611cae58a1048bffb13cbdc465cbBrian Carlstrombool IsZipMagic(uint32_t magic); 4157c3d13aebdd8611cae58a1048bffb13cbdc465cbBrian Carlstrombool IsDexMagic(uint32_t magic); 4167c3d13aebdd8611cae58a1048bffb13cbdc465cbBrian Carlstrombool IsOatMagic(uint32_t magic); 417b7bbba49d88eae58223d9878da4069bf6d7140bfBrian Carlstrom 4186449c62e40ef3a9bb75f664f922555affb532ee4Brian Carlstrom// Wrapper on fork/execv to run a command in a subprocess. 4196449c62e40ef3a9bb75f664f922555affb532ee4Brian Carlstrombool Exec(std::vector<std::string>& arg_vector, std::string* error_msg); 4206449c62e40ef3a9bb75f664f922555affb532ee4Brian Carlstrom 421d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartierclass VoidFunctor { 422357e9be24c17a6bc2ae9fb53f25c73503116101dMathieu Chartier public: 423d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier template <typename A> 424df62950e7a32031b82360c407d46a37b94188fbbBrian Carlstrom inline void operator() (A a) const { 425d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier UNUSED(a); 426d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier } 427d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier 428d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier template <typename A, typename B> 429df62950e7a32031b82360c407d46a37b94188fbbBrian Carlstrom inline void operator() (A a, B b) const { 430d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier UNUSED(a); 431d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier UNUSED(b); 432d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier } 433d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier 434d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier template <typename A, typename B, typename C> 435df62950e7a32031b82360c407d46a37b94188fbbBrian Carlstrom inline void operator() (A a, B b, C c) const { 436d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier UNUSED(a); 437d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier UNUSED(b); 438d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier UNUSED(c); 439d22d54849c96760aa1efa259d6dcfbace54da2afMathieu Chartier } 440357e9be24c17a6bc2ae9fb53f25c73503116101dMathieu Chartier}; 441357e9be24c17a6bc2ae9fb53f25c73503116101dMathieu Chartier 4426b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapiro} // namespace art 443a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro 444fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif // ART_RUNTIME_UTILS_H_ 445