blob: d038571e96c2299ceebadf6becf34b8436ca8164 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Elliott Hughes11e45072011-08-16 17:40:46 -070016
Elliott Hughes42ee1422011-09-06 12:33:32 -070017#include "utils.h"
18
Christopher Ferris943af7d2014-01-16 12:41:46 -080019#include <inttypes.h>
Elliott Hughes92b3b562011-09-08 16:32:26 -070020#include <pthread.h>
Brian Carlstroma9f19782011-10-13 00:14:47 -070021#include <sys/stat.h>
Elliott Hughes42ee1422011-09-06 12:33:32 -070022#include <sys/syscall.h>
23#include <sys/types.h>
Brian Carlstrom4cf5e572014-02-25 11:47:48 -080024#include <sys/wait.h>
Elliott Hughes42ee1422011-09-06 12:33:32 -070025#include <unistd.h>
Ian Rogers700a4022014-05-19 16:49:03 -070026#include <memory>
Elliott Hughes42ee1422011-09-06 12:33:32 -070027
Brian Carlstrom6449c622014-02-10 23:48:36 -080028#include "base/stl_util.h"
Elliott Hughes76160052012-12-12 16:31:20 -080029#include "base/unix_file/fd_file.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070030#include "dex_file-inl.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070031#include "mirror/art_field-inl.h"
32#include "mirror/art_method-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070033#include "mirror/class-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034#include "mirror/class_loader.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035#include "mirror/object-inl.h"
36#include "mirror/object_array-inl.h"
37#include "mirror/string.h"
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080038#include "object_utils.h"
buzbeec143c552011-08-20 17:38:58 -070039#include "os.h"
Kenny Root067d20f2014-03-05 14:57:21 -080040#include "scoped_thread_state_change.h"
Ian Rogersa6724902013-09-23 09:23:37 -070041#include "utf-inl.h"
Elliott Hughes11e45072011-08-16 17:40:46 -070042
Elliott Hughesad6c9c32012-01-19 17:39:12 -080043#if !defined(HAVE_POSIX_CLOCKS)
44#include <sys/time.h>
45#endif
46
Elliott Hughesdcc24742011-09-07 14:02:44 -070047#if defined(HAVE_PRCTL)
48#include <sys/prctl.h>
49#endif
50
Elliott Hughes4ae722a2012-03-13 11:08:51 -070051#if defined(__APPLE__)
Brian Carlstrom7934ac22013-07-26 10:54:15 -070052#include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED
Elliott Hughesf1498432012-03-28 19:34:27 -070053#include <sys/syscall.h>
Elliott Hughes4ae722a2012-03-13 11:08:51 -070054#endif
55
Christopher Ferris7b5f0cf2013-11-01 15:18:45 -070056#include <backtrace/Backtrace.h> // For DumpNativeStack.
Elliott Hughes46e251b2012-05-22 15:10:45 -070057
Elliott Hughes058a6de2012-05-24 19:13:02 -070058#if defined(__linux__)
Elliott Hughese1aee692012-01-17 16:40:10 -080059#include <linux/unistd.h>
Elliott Hughese1aee692012-01-17 16:40:10 -080060#endif
61
Elliott Hughes11e45072011-08-16 17:40:46 -070062namespace art {
63
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080064pid_t GetTid() {
Brian Carlstromf3a26412012-08-24 11:06:02 -070065#if defined(__APPLE__)
66 uint64_t owner;
67 CHECK_PTHREAD_CALL(pthread_threadid_np, (NULL, &owner), __FUNCTION__); // Requires Mac OS 10.6
68 return owner;
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080069#else
70 // Neither bionic nor glibc exposes gettid(2).
71 return syscall(__NR_gettid);
72#endif
73}
74
Elliott Hughes289be852012-06-12 13:57:20 -070075std::string GetThreadName(pid_t tid) {
76 std::string result;
77 if (ReadFileToString(StringPrintf("/proc/self/task/%d/comm", tid), &result)) {
Brian Carlstrom7934ac22013-07-26 10:54:15 -070078 result.resize(result.size() - 1); // Lose the trailing '\n'.
Elliott Hughes289be852012-06-12 13:57:20 -070079 } else {
80 result = "<unknown>";
81 }
82 return result;
83}
84
Brian Carlstrom29212012013-09-12 22:18:30 -070085void GetThreadStack(pthread_t thread, void** stack_base, size_t* stack_size) {
Elliott Hughese1884192012-04-23 12:38:15 -070086#if defined(__APPLE__)
Brian Carlstrom29212012013-09-12 22:18:30 -070087 *stack_size = pthread_get_stacksize_np(thread);
Ian Rogers120f1c72012-09-28 17:17:10 -070088 void* stack_addr = pthread_get_stackaddr_np(thread);
Elliott Hughese1884192012-04-23 12:38:15 -070089
90 // Check whether stack_addr is the base or end of the stack.
91 // (On Mac OS 10.7, it's the end.)
92 int stack_variable;
93 if (stack_addr > &stack_variable) {
Brian Carlstrom29212012013-09-12 22:18:30 -070094 *stack_base = reinterpret_cast<byte*>(stack_addr) - *stack_size;
Elliott Hughese1884192012-04-23 12:38:15 -070095 } else {
Brian Carlstrom29212012013-09-12 22:18:30 -070096 *stack_base = stack_addr;
Elliott Hughese1884192012-04-23 12:38:15 -070097 }
98#else
99 pthread_attr_t attributes;
Ian Rogers120f1c72012-09-28 17:17:10 -0700100 CHECK_PTHREAD_CALL(pthread_getattr_np, (thread, &attributes), __FUNCTION__);
Brian Carlstrom29212012013-09-12 22:18:30 -0700101 CHECK_PTHREAD_CALL(pthread_attr_getstack, (&attributes, stack_base, stack_size), __FUNCTION__);
Elliott Hughese1884192012-04-23 12:38:15 -0700102 CHECK_PTHREAD_CALL(pthread_attr_destroy, (&attributes), __FUNCTION__);
103#endif
104}
105
Elliott Hughesd92bec42011-09-02 17:04:36 -0700106bool ReadFileToString(const std::string& file_name, std::string* result) {
Ian Rogers700a4022014-05-19 16:49:03 -0700107 std::unique_ptr<File> file(new File);
Elliott Hughes76160052012-12-12 16:31:20 -0800108 if (!file->Open(file_name, O_RDONLY)) {
Elliott Hughesd92bec42011-09-02 17:04:36 -0700109 return false;
110 }
buzbeec143c552011-08-20 17:38:58 -0700111
Elliott Hughes3b6baaa2011-10-14 19:13:56 -0700112 std::vector<char> buf(8 * KB);
buzbeec143c552011-08-20 17:38:58 -0700113 while (true) {
Elliott Hughes76160052012-12-12 16:31:20 -0800114 int64_t n = TEMP_FAILURE_RETRY(read(file->Fd(), &buf[0], buf.size()));
Elliott Hughesd92bec42011-09-02 17:04:36 -0700115 if (n == -1) {
116 return false;
buzbeec143c552011-08-20 17:38:58 -0700117 }
Elliott Hughesd92bec42011-09-02 17:04:36 -0700118 if (n == 0) {
119 return true;
120 }
Elliott Hughes3b6baaa2011-10-14 19:13:56 -0700121 result->append(&buf[0], n);
buzbeec143c552011-08-20 17:38:58 -0700122 }
buzbeec143c552011-08-20 17:38:58 -0700123}
124
Elliott Hughese27955c2011-08-26 15:21:24 -0700125std::string GetIsoDate() {
126 time_t now = time(NULL);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700127 tm tmbuf;
128 tm* ptm = localtime_r(&now, &tmbuf);
Elliott Hughese27955c2011-08-26 15:21:24 -0700129 return StringPrintf("%04d-%02d-%02d %02d:%02d:%02d",
130 ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday,
131 ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
132}
133
Elliott Hughes7162ad92011-10-27 14:08:42 -0700134uint64_t MilliTime() {
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800135#if defined(HAVE_POSIX_CLOCKS)
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700136 timespec now;
Elliott Hughes7162ad92011-10-27 14:08:42 -0700137 clock_gettime(CLOCK_MONOTONIC, &now);
Ian Rogers0f678472014-03-10 16:18:37 -0700138 return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000) + now.tv_nsec / UINT64_C(1000000);
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800139#else
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700140 timeval now;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800141 gettimeofday(&now, NULL);
Ian Rogers0f678472014-03-10 16:18:37 -0700142 return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000) + now.tv_usec / UINT64_C(1000);
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800143#endif
Elliott Hughes7162ad92011-10-27 14:08:42 -0700144}
145
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800146uint64_t MicroTime() {
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800147#if defined(HAVE_POSIX_CLOCKS)
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700148 timespec now;
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800149 clock_gettime(CLOCK_MONOTONIC, &now);
Ian Rogers0f678472014-03-10 16:18:37 -0700150 return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000) + now.tv_nsec / UINT64_C(1000);
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800151#else
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700152 timeval now;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800153 gettimeofday(&now, NULL);
Ian Rogers0f678472014-03-10 16:18:37 -0700154 return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000) + now.tv_usec;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800155#endif
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800156}
157
Elliott Hughes83df2ac2011-10-11 16:37:54 -0700158uint64_t NanoTime() {
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800159#if defined(HAVE_POSIX_CLOCKS)
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700160 timespec now;
Elliott Hughes83df2ac2011-10-11 16:37:54 -0700161 clock_gettime(CLOCK_MONOTONIC, &now);
Ian Rogers0f678472014-03-10 16:18:37 -0700162 return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800163#else
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700164 timeval now;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800165 gettimeofday(&now, NULL);
Ian Rogers0f678472014-03-10 16:18:37 -0700166 return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_usec * UINT64_C(1000);
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800167#endif
Elliott Hughes83df2ac2011-10-11 16:37:54 -0700168}
169
Elliott Hughes0512f022012-03-15 22:10:52 -0700170uint64_t ThreadCpuNanoTime() {
171#if defined(HAVE_POSIX_CLOCKS)
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700172 timespec now;
Elliott Hughes0512f022012-03-15 22:10:52 -0700173 clock_gettime(CLOCK_THREAD_CPUTIME_ID, &now);
Ian Rogers0f678472014-03-10 16:18:37 -0700174 return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec;
Elliott Hughes0512f022012-03-15 22:10:52 -0700175#else
176 UNIMPLEMENTED(WARNING);
177 return -1;
178#endif
179}
180
Ian Rogers56edc432013-01-18 16:51:51 -0800181void NanoSleep(uint64_t ns) {
182 timespec tm;
183 tm.tv_sec = 0;
184 tm.tv_nsec = ns;
185 nanosleep(&tm, NULL);
186}
187
Brian Carlstrombcc29262012-11-02 11:36:03 -0700188void InitTimeSpec(bool absolute, int clock, int64_t ms, int32_t ns, timespec* ts) {
189 int64_t endSec;
190
191 if (absolute) {
192#if !defined(__APPLE__)
193 clock_gettime(clock, ts);
194#else
195 UNUSED(clock);
196 timeval tv;
197 gettimeofday(&tv, NULL);
198 ts->tv_sec = tv.tv_sec;
199 ts->tv_nsec = tv.tv_usec * 1000;
200#endif
201 } else {
202 ts->tv_sec = 0;
203 ts->tv_nsec = 0;
204 }
205 endSec = ts->tv_sec + ms / 1000;
206 if (UNLIKELY(endSec >= 0x7fffffff)) {
207 std::ostringstream ss;
208 LOG(INFO) << "Note: end time exceeds epoch: " << ss.str();
209 endSec = 0x7ffffffe;
210 }
211 ts->tv_sec = endSec;
212 ts->tv_nsec = (ts->tv_nsec + (ms % 1000) * 1000000) + ns;
213
214 // Catch rollover.
215 if (ts->tv_nsec >= 1000000000L) {
216 ts->tv_sec++;
217 ts->tv_nsec -= 1000000000L;
218 }
219}
220
Ian Rogersef7d42f2014-01-06 12:55:46 -0800221std::string PrettyDescriptor(mirror::String* java_descriptor) {
Brian Carlstrome24fa612011-09-29 00:53:55 -0700222 if (java_descriptor == NULL) {
223 return "null";
224 }
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700225 return PrettyDescriptor(java_descriptor->ToModifiedUtf8());
226}
Elliott Hughes5174fe62011-08-23 15:12:35 -0700227
Ian Rogersef7d42f2014-01-06 12:55:46 -0800228std::string PrettyDescriptor(mirror::Class* klass) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800229 if (klass == NULL) {
230 return "null";
231 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700232 return PrettyDescriptor(klass->GetDescriptor());
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800233}
234
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700235std::string PrettyDescriptor(const std::string& descriptor) {
Elliott Hughes11e45072011-08-16 17:40:46 -0700236 // Count the number of '['s to get the dimensionality.
Elliott Hughes5174fe62011-08-23 15:12:35 -0700237 const char* c = descriptor.c_str();
Elliott Hughes11e45072011-08-16 17:40:46 -0700238 size_t dim = 0;
239 while (*c == '[') {
240 dim++;
241 c++;
242 }
243
244 // Reference or primitive?
245 if (*c == 'L') {
246 // "[[La/b/C;" -> "a.b.C[][]".
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700247 c++; // Skip the 'L'.
Elliott Hughes11e45072011-08-16 17:40:46 -0700248 } else {
249 // "[[B" -> "byte[][]".
250 // To make life easier, we make primitives look like unqualified
251 // reference types.
252 switch (*c) {
253 case 'B': c = "byte;"; break;
254 case 'C': c = "char;"; break;
255 case 'D': c = "double;"; break;
256 case 'F': c = "float;"; break;
257 case 'I': c = "int;"; break;
258 case 'J': c = "long;"; break;
259 case 'S': c = "short;"; break;
260 case 'Z': c = "boolean;"; break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700261 case 'V': c = "void;"; break; // Used when decoding return types.
Elliott Hughes5174fe62011-08-23 15:12:35 -0700262 default: return descriptor;
Elliott Hughes11e45072011-08-16 17:40:46 -0700263 }
264 }
265
266 // At this point, 'c' is a string of the form "fully/qualified/Type;"
267 // or "primitive;". Rewrite the type with '.' instead of '/':
268 std::string result;
269 const char* p = c;
270 while (*p != ';') {
271 char ch = *p++;
272 if (ch == '/') {
273 ch = '.';
274 }
275 result.push_back(ch);
276 }
277 // ...and replace the semicolon with 'dim' "[]" pairs:
278 while (dim--) {
279 result += "[]";
280 }
281 return result;
282}
283
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700284std::string PrettyDescriptor(Primitive::Type type) {
Elliott Hughes91250e02011-12-13 22:30:35 -0800285 std::string descriptor_string(Primitive::Descriptor(type));
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700286 return PrettyDescriptor(descriptor_string);
287}
288
Ian Rogersef7d42f2014-01-06 12:55:46 -0800289std::string PrettyField(mirror::ArtField* f, bool with_type) {
Elliott Hughesa2501992011-08-26 19:39:54 -0700290 if (f == NULL) {
291 return "null";
292 }
Elliott Hughes54e7df12011-09-16 11:47:04 -0700293 std::string result;
294 if (with_type) {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700295 result += PrettyDescriptor(f->GetTypeDescriptor());
Elliott Hughes54e7df12011-09-16 11:47:04 -0700296 result += ' ';
297 }
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700298 StackHandleScope<1> hs(Thread::Current());
299 result += PrettyDescriptor(FieldHelper(hs.NewHandle(f)).GetDeclaringClassDescriptor());
Elliott Hughesa2501992011-08-26 19:39:54 -0700300 result += '.';
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700301 result += f->GetName();
Elliott Hughesa2501992011-08-26 19:39:54 -0700302 return result;
303}
304
Brian Carlstrom6f29d0e2012-05-11 15:50:29 -0700305std::string PrettyField(uint32_t field_idx, const DexFile& dex_file, bool with_type) {
Elliott Hughes60641a72013-02-27 14:36:16 -0800306 if (field_idx >= dex_file.NumFieldIds()) {
307 return StringPrintf("<<invalid-field-idx-%d>>", field_idx);
308 }
Brian Carlstrom6f29d0e2012-05-11 15:50:29 -0700309 const DexFile::FieldId& field_id = dex_file.GetFieldId(field_idx);
310 std::string result;
311 if (with_type) {
312 result += dex_file.GetFieldTypeDescriptor(field_id);
313 result += ' ';
314 }
315 result += PrettyDescriptor(dex_file.GetFieldDeclaringClassDescriptor(field_id));
316 result += '.';
317 result += dex_file.GetFieldName(field_id);
318 return result;
319}
320
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700321std::string PrettyType(uint32_t type_idx, const DexFile& dex_file) {
Elliott Hughes60641a72013-02-27 14:36:16 -0800322 if (type_idx >= dex_file.NumTypeIds()) {
323 return StringPrintf("<<invalid-type-idx-%d>>", type_idx);
324 }
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700325 const DexFile::TypeId& type_id = dex_file.GetTypeId(type_idx);
Mathieu Chartier4c70d772012-09-10 14:08:32 -0700326 return PrettyDescriptor(dex_file.GetTypeDescriptor(type_id));
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700327}
328
Elliott Hughes9058f2b2012-03-22 18:06:48 -0700329std::string PrettyArguments(const char* signature) {
330 std::string result;
331 result += '(';
332 CHECK_EQ(*signature, '(');
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700333 ++signature; // Skip the '('.
Elliott Hughes9058f2b2012-03-22 18:06:48 -0700334 while (*signature != ')') {
335 size_t argument_length = 0;
336 while (signature[argument_length] == '[') {
337 ++argument_length;
338 }
339 if (signature[argument_length] == 'L') {
340 argument_length = (strchr(signature, ';') - signature + 1);
341 } else {
342 ++argument_length;
343 }
344 std::string argument_descriptor(signature, argument_length);
345 result += PrettyDescriptor(argument_descriptor);
346 if (signature[argument_length] != ')') {
347 result += ", ";
348 }
349 signature += argument_length;
350 }
351 CHECK_EQ(*signature, ')');
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700352 ++signature; // Skip the ')'.
Elliott Hughes9058f2b2012-03-22 18:06:48 -0700353 result += ')';
354 return result;
355}
356
357std::string PrettyReturnType(const char* signature) {
358 const char* return_type = strchr(signature, ')');
359 CHECK(return_type != NULL);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700360 ++return_type; // Skip ')'.
Elliott Hughes9058f2b2012-03-22 18:06:48 -0700361 return PrettyDescriptor(return_type);
362}
363
Ian Rogersef7d42f2014-01-06 12:55:46 -0800364std::string PrettyMethod(mirror::ArtMethod* m, bool with_signature) {
Ian Rogers16ce0922014-01-10 14:59:36 -0800365 if (m == nullptr) {
Elliott Hughesa0b8feb2011-08-20 09:50:55 -0700366 return "null";
367 }
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700368 std::string result(PrettyDescriptor(m->GetDeclaringClassDescriptor()));
Elliott Hughesa0b8feb2011-08-20 09:50:55 -0700369 result += '.';
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700370 result += m->GetName();
Ian Rogers16ce0922014-01-10 14:59:36 -0800371 if (UNLIKELY(m->IsFastNative())) {
372 result += "!";
373 }
Elliott Hughesa0b8feb2011-08-20 09:50:55 -0700374 if (with_signature) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700375 const Signature signature = m->GetSignature();
Ian Rogersd91d6d62013-09-25 20:26:14 -0700376 std::string sig_as_string(signature.ToString());
377 if (signature == Signature::NoSignature()) {
378 return result + sig_as_string;
Elliott Hughesf8c11932012-03-23 19:53:59 -0700379 }
Ian Rogersd91d6d62013-09-25 20:26:14 -0700380 result = PrettyReturnType(sig_as_string.c_str()) + " " + result +
381 PrettyArguments(sig_as_string.c_str());
Elliott Hughesa0b8feb2011-08-20 09:50:55 -0700382 }
383 return result;
384}
385
Ian Rogers0571d352011-11-03 19:51:38 -0700386std::string PrettyMethod(uint32_t method_idx, const DexFile& dex_file, bool with_signature) {
Elliott Hughes60641a72013-02-27 14:36:16 -0800387 if (method_idx >= dex_file.NumMethodIds()) {
388 return StringPrintf("<<invalid-method-idx-%d>>", method_idx);
389 }
Ian Rogers0571d352011-11-03 19:51:38 -0700390 const DexFile::MethodId& method_id = dex_file.GetMethodId(method_idx);
391 std::string result(PrettyDescriptor(dex_file.GetMethodDeclaringClassDescriptor(method_id)));
392 result += '.';
393 result += dex_file.GetMethodName(method_id);
394 if (with_signature) {
Ian Rogersd91d6d62013-09-25 20:26:14 -0700395 const Signature signature = dex_file.GetMethodSignature(method_id);
396 std::string sig_as_string(signature.ToString());
397 if (signature == Signature::NoSignature()) {
398 return result + sig_as_string;
Elliott Hughesf8c11932012-03-23 19:53:59 -0700399 }
Ian Rogersd91d6d62013-09-25 20:26:14 -0700400 result = PrettyReturnType(sig_as_string.c_str()) + " " + result +
401 PrettyArguments(sig_as_string.c_str());
Ian Rogers0571d352011-11-03 19:51:38 -0700402 }
403 return result;
404}
405
Ian Rogersef7d42f2014-01-06 12:55:46 -0800406std::string PrettyTypeOf(mirror::Object* obj) {
Elliott Hughes11e45072011-08-16 17:40:46 -0700407 if (obj == NULL) {
408 return "null";
409 }
410 if (obj->GetClass() == NULL) {
411 return "(raw)";
412 }
Mathieu Chartierf8322842014-05-16 10:59:25 -0700413 std::string result(PrettyDescriptor(obj->GetClass()->GetDescriptor()));
Elliott Hughes11e45072011-08-16 17:40:46 -0700414 if (obj->IsClass()) {
Mathieu Chartierf8322842014-05-16 10:59:25 -0700415 result += "<" + PrettyDescriptor(obj->AsClass()->GetDescriptor()) + ">";
Elliott Hughes11e45072011-08-16 17:40:46 -0700416 }
417 return result;
418}
419
Ian Rogersef7d42f2014-01-06 12:55:46 -0800420std::string PrettyClass(mirror::Class* c) {
Elliott Hughes54e7df12011-09-16 11:47:04 -0700421 if (c == NULL) {
422 return "null";
423 }
424 std::string result;
425 result += "java.lang.Class<";
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800426 result += PrettyDescriptor(c);
Elliott Hughes54e7df12011-09-16 11:47:04 -0700427 result += ">";
428 return result;
429}
430
Ian Rogersef7d42f2014-01-06 12:55:46 -0800431std::string PrettyClassAndClassLoader(mirror::Class* c) {
Ian Rogersd81871c2011-10-03 13:57:23 -0700432 if (c == NULL) {
433 return "null";
434 }
435 std::string result;
436 result += "java.lang.Class<";
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800437 result += PrettyDescriptor(c);
Ian Rogersd81871c2011-10-03 13:57:23 -0700438 result += ",";
439 result += PrettyTypeOf(c->GetClassLoader());
440 // TODO: add an identifying hash value for the loader
441 result += ">";
442 return result;
443}
444
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800445std::string PrettySize(int64_t byte_count) {
Elliott Hughesc967f782012-04-16 10:23:15 -0700446 // The byte thresholds at which we display amounts. A byte count is displayed
447 // in unit U when kUnitThresholds[U] <= bytes < kUnitThresholds[U+1].
Ian Rogersef7d42f2014-01-06 12:55:46 -0800448 static const int64_t kUnitThresholds[] = {
Elliott Hughesc967f782012-04-16 10:23:15 -0700449 0, // B up to...
450 3*1024, // KB up to...
451 2*1024*1024, // MB up to...
452 1024*1024*1024 // GB from here.
453 };
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800454 static const int64_t kBytesPerUnit[] = { 1, KB, MB, GB };
Elliott Hughesc967f782012-04-16 10:23:15 -0700455 static const char* const kUnitStrings[] = { "B", "KB", "MB", "GB" };
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800456 const char* negative_str = "";
457 if (byte_count < 0) {
458 negative_str = "-";
459 byte_count = -byte_count;
460 }
Elliott Hughesc967f782012-04-16 10:23:15 -0700461 int i = arraysize(kUnitThresholds);
462 while (--i > 0) {
463 if (byte_count >= kUnitThresholds[i]) {
464 break;
465 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800466 }
Brian Carlstrom474cc792014-03-07 14:18:15 -0800467 return StringPrintf("%s%" PRId64 "%s",
468 negative_str, byte_count / kBytesPerUnit[i], kUnitStrings[i]);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800469}
470
Mathieu Chartierf5997b42014-06-20 10:37:54 -0700471std::string PrettyDuration(uint64_t nano_duration, size_t max_fraction_digits) {
Ian Rogers3bb17a62012-01-27 23:56:44 -0800472 if (nano_duration == 0) {
473 return "0";
474 } else {
Mathieu Chartierf5997b42014-06-20 10:37:54 -0700475 return FormatDuration(nano_duration, GetAppropriateTimeUnit(nano_duration),
476 max_fraction_digits);
Mathieu Chartier0325e622012-09-05 14:22:51 -0700477 }
478}
479
480TimeUnit GetAppropriateTimeUnit(uint64_t nano_duration) {
481 const uint64_t one_sec = 1000 * 1000 * 1000;
482 const uint64_t one_ms = 1000 * 1000;
483 const uint64_t one_us = 1000;
484 if (nano_duration >= one_sec) {
485 return kTimeUnitSecond;
486 } else if (nano_duration >= one_ms) {
487 return kTimeUnitMillisecond;
488 } else if (nano_duration >= one_us) {
489 return kTimeUnitMicrosecond;
490 } else {
491 return kTimeUnitNanosecond;
492 }
493}
494
495uint64_t GetNsToTimeUnitDivisor(TimeUnit time_unit) {
496 const uint64_t one_sec = 1000 * 1000 * 1000;
497 const uint64_t one_ms = 1000 * 1000;
498 const uint64_t one_us = 1000;
499
500 switch (time_unit) {
501 case kTimeUnitSecond:
502 return one_sec;
503 case kTimeUnitMillisecond:
504 return one_ms;
505 case kTimeUnitMicrosecond:
506 return one_us;
507 case kTimeUnitNanosecond:
508 return 1;
509 }
510 return 0;
511}
512
Mathieu Chartierf5997b42014-06-20 10:37:54 -0700513std::string FormatDuration(uint64_t nano_duration, TimeUnit time_unit,
514 size_t max_fraction_digits) {
515 const char* unit = nullptr;
Mathieu Chartier0325e622012-09-05 14:22:51 -0700516 uint64_t divisor = GetNsToTimeUnitDivisor(time_unit);
Mathieu Chartier0325e622012-09-05 14:22:51 -0700517 switch (time_unit) {
518 case kTimeUnitSecond:
Ian Rogers3bb17a62012-01-27 23:56:44 -0800519 unit = "s";
Mathieu Chartier0325e622012-09-05 14:22:51 -0700520 break;
521 case kTimeUnitMillisecond:
Ian Rogers3bb17a62012-01-27 23:56:44 -0800522 unit = "ms";
Mathieu Chartier0325e622012-09-05 14:22:51 -0700523 break;
524 case kTimeUnitMicrosecond:
Ian Rogers3bb17a62012-01-27 23:56:44 -0800525 unit = "us";
Mathieu Chartier0325e622012-09-05 14:22:51 -0700526 break;
527 case kTimeUnitNanosecond:
Ian Rogers3bb17a62012-01-27 23:56:44 -0800528 unit = "ns";
Mathieu Chartier0325e622012-09-05 14:22:51 -0700529 break;
530 }
Mathieu Chartierf5997b42014-06-20 10:37:54 -0700531 const uint64_t whole_part = nano_duration / divisor;
Mathieu Chartier0325e622012-09-05 14:22:51 -0700532 uint64_t fractional_part = nano_duration % divisor;
533 if (fractional_part == 0) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800534 return StringPrintf("%" PRIu64 "%s", whole_part, unit);
Mathieu Chartier0325e622012-09-05 14:22:51 -0700535 } else {
Mathieu Chartierf5997b42014-06-20 10:37:54 -0700536 static constexpr size_t kMaxDigits = 30;
Andreas Gampe829b4ba2014-06-26 13:49:36 -0700537 size_t avail_digits = kMaxDigits;
Mathieu Chartierf5997b42014-06-20 10:37:54 -0700538 char fraction_buffer[kMaxDigits];
539 char* ptr = fraction_buffer;
540 uint64_t multiplier = 10;
541 // This infinite loops if fractional part is 0.
Andreas Gampe829b4ba2014-06-26 13:49:36 -0700542 while (avail_digits > 1 && fractional_part * multiplier < divisor) {
Mathieu Chartierf5997b42014-06-20 10:37:54 -0700543 multiplier *= 10;
544 *ptr++ = '0';
Andreas Gampe829b4ba2014-06-26 13:49:36 -0700545 avail_digits--;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800546 }
Andreas Gampe829b4ba2014-06-26 13:49:36 -0700547 snprintf(ptr, avail_digits, "%" PRIu64, fractional_part);
Mathieu Chartierf5997b42014-06-20 10:37:54 -0700548 fraction_buffer[std::min(kMaxDigits - 1, max_fraction_digits)] = '\0';
549 return StringPrintf("%" PRIu64 ".%s%s", whole_part, fraction_buffer, unit);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800550 }
551}
552
Ian Rogers576ca0c2014-06-06 15:58:22 -0700553std::string PrintableChar(uint16_t ch) {
554 std::string result;
555 result += '\'';
556 if (NeedsEscaping(ch)) {
557 StringAppendF(&result, "\\u%04x", ch);
558 } else {
559 result += ch;
560 }
561 result += '\'';
562 return result;
563}
564
Elliott Hughes82914b62012-04-09 15:56:29 -0700565std::string PrintableString(const std::string& utf) {
566 std::string result;
567 result += '"';
568 const char* p = utf.c_str();
569 size_t char_count = CountModifiedUtf8Chars(p);
570 for (size_t i = 0; i < char_count; ++i) {
571 uint16_t ch = GetUtf16FromUtf8(&p);
572 if (ch == '\\') {
573 result += "\\\\";
574 } else if (ch == '\n') {
575 result += "\\n";
576 } else if (ch == '\r') {
577 result += "\\r";
578 } else if (ch == '\t') {
579 result += "\\t";
580 } else if (NeedsEscaping(ch)) {
581 StringAppendF(&result, "\\u%04x", ch);
582 } else {
583 result += ch;
584 }
585 }
586 result += '"';
587 return result;
588}
589
Elliott Hughesd8c00d02012-01-30 14:08:31 -0800590// See http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp615 for the full rules.
Elliott Hughes79082e32011-08-25 12:07:32 -0700591std::string MangleForJni(const std::string& s) {
592 std::string result;
593 size_t char_count = CountModifiedUtf8Chars(s.c_str());
594 const char* cp = &s[0];
595 for (size_t i = 0; i < char_count; ++i) {
596 uint16_t ch = GetUtf16FromUtf8(&cp);
Elliott Hughesd8c00d02012-01-30 14:08:31 -0800597 if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) {
598 result.push_back(ch);
599 } else if (ch == '.' || ch == '/') {
600 result += "_";
601 } else if (ch == '_') {
602 result += "_1";
603 } else if (ch == ';') {
604 result += "_2";
605 } else if (ch == '[') {
606 result += "_3";
Elliott Hughes79082e32011-08-25 12:07:32 -0700607 } else {
Elliott Hughesd8c00d02012-01-30 14:08:31 -0800608 StringAppendF(&result, "_0%04x", ch);
Elliott Hughes79082e32011-08-25 12:07:32 -0700609 }
610 }
611 return result;
612}
613
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700614std::string DotToDescriptor(const char* class_name) {
615 std::string descriptor(class_name);
616 std::replace(descriptor.begin(), descriptor.end(), '.', '/');
617 if (descriptor.length() > 0 && descriptor[0] != '[') {
618 descriptor = "L" + descriptor + ";";
619 }
620 return descriptor;
621}
622
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800623std::string DescriptorToDot(const char* descriptor) {
Elliott Hughes2435a572012-02-17 16:07:41 -0800624 size_t length = strlen(descriptor);
625 if (descriptor[0] == 'L' && descriptor[length - 1] == ';') {
626 std::string result(descriptor + 1, length - 2);
627 std::replace(result.begin(), result.end(), '/', '.');
628 return result;
629 }
630 return descriptor;
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800631}
632
633std::string DescriptorToName(const char* descriptor) {
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800634 size_t length = strlen(descriptor);
Elliott Hughes2435a572012-02-17 16:07:41 -0800635 if (descriptor[0] == 'L' && descriptor[length - 1] == ';') {
636 std::string result(descriptor + 1, length - 2);
637 return result;
638 }
639 return descriptor;
Brian Carlstromaded5f72011-10-07 17:15:04 -0700640}
641
Ian Rogersef7d42f2014-01-06 12:55:46 -0800642std::string JniShortName(mirror::ArtMethod* m) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700643 std::string class_name(m->GetDeclaringClassDescriptor());
Elliott Hughes79082e32011-08-25 12:07:32 -0700644 // Remove the leading 'L' and trailing ';'...
Elliott Hughesf5a7a472011-10-07 14:31:02 -0700645 CHECK_EQ(class_name[0], 'L') << class_name;
646 CHECK_EQ(class_name[class_name.size() - 1], ';') << class_name;
Elliott Hughes79082e32011-08-25 12:07:32 -0700647 class_name.erase(0, 1);
648 class_name.erase(class_name.size() - 1, 1);
649
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700650 std::string method_name(m->GetName());
Elliott Hughes79082e32011-08-25 12:07:32 -0700651
652 std::string short_name;
653 short_name += "Java_";
654 short_name += MangleForJni(class_name);
655 short_name += "_";
656 short_name += MangleForJni(method_name);
657 return short_name;
658}
659
Ian Rogersef7d42f2014-01-06 12:55:46 -0800660std::string JniLongName(mirror::ArtMethod* m) {
Elliott Hughes79082e32011-08-25 12:07:32 -0700661 std::string long_name;
662 long_name += JniShortName(m);
663 long_name += "__";
664
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700665 std::string signature(m->GetSignature().ToString());
Elliott Hughes79082e32011-08-25 12:07:32 -0700666 signature.erase(0, 1);
667 signature.erase(signature.begin() + signature.find(')'), signature.end());
668
669 long_name += MangleForJni(signature);
670
671 return long_name;
672}
673
jeffhao10037c82012-01-23 15:06:23 -0800674// Helper for IsValidPartOfMemberNameUtf8(), a bit vector indicating valid low ascii.
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700675uint32_t DEX_MEMBER_VALID_LOW_ASCII[4] = {
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700676 0x00000000, // 00..1f low control characters; nothing valid
677 0x03ff2010, // 20..3f digits and symbols; valid: '0'..'9', '$', '-'
678 0x87fffffe, // 40..5f uppercase etc.; valid: 'A'..'Z', '_'
679 0x07fffffe // 60..7f lowercase etc.; valid: 'a'..'z'
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700680};
681
jeffhao10037c82012-01-23 15:06:23 -0800682// Helper for IsValidPartOfMemberNameUtf8(); do not call directly.
683bool IsValidPartOfMemberNameUtf8Slow(const char** pUtf8Ptr) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700684 /*
685 * It's a multibyte encoded character. Decode it and analyze. We
686 * accept anything that isn't (a) an improperly encoded low value,
687 * (b) an improper surrogate pair, (c) an encoded '\0', (d) a high
688 * control character, or (e) a high space, layout, or special
689 * character (U+00a0, U+2000..U+200f, U+2028..U+202f,
690 * U+fff0..U+ffff). This is all specified in the dex format
691 * document.
692 */
693
694 uint16_t utf16 = GetUtf16FromUtf8(pUtf8Ptr);
695
696 // Perform follow-up tests based on the high 8 bits.
697 switch (utf16 >> 8) {
698 case 0x00:
699 // It's only valid if it's above the ISO-8859-1 high space (0xa0).
700 return (utf16 > 0x00a0);
701 case 0xd8:
702 case 0xd9:
703 case 0xda:
704 case 0xdb:
705 // It's a leading surrogate. Check to see that a trailing
706 // surrogate follows.
707 utf16 = GetUtf16FromUtf8(pUtf8Ptr);
708 return (utf16 >= 0xdc00) && (utf16 <= 0xdfff);
709 case 0xdc:
710 case 0xdd:
711 case 0xde:
712 case 0xdf:
713 // It's a trailing surrogate, which is not valid at this point.
714 return false;
715 case 0x20:
716 case 0xff:
717 // It's in the range that has spaces, controls, and specials.
718 switch (utf16 & 0xfff8) {
719 case 0x2000:
720 case 0x2008:
721 case 0x2028:
722 case 0xfff0:
723 case 0xfff8:
724 return false;
725 }
726 break;
727 }
728 return true;
729}
730
731/* Return whether the pointed-at modified-UTF-8 encoded character is
732 * valid as part of a member name, updating the pointer to point past
733 * the consumed character. This will consume two encoded UTF-16 code
734 * points if the character is encoded as a surrogate pair. Also, if
735 * this function returns false, then the given pointer may only have
736 * been partially advanced.
737 */
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700738static bool IsValidPartOfMemberNameUtf8(const char** pUtf8Ptr) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700739 uint8_t c = (uint8_t) **pUtf8Ptr;
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700740 if (LIKELY(c <= 0x7f)) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700741 // It's low-ascii, so check the table.
742 uint32_t wordIdx = c >> 5;
743 uint32_t bitIdx = c & 0x1f;
744 (*pUtf8Ptr)++;
745 return (DEX_MEMBER_VALID_LOW_ASCII[wordIdx] & (1 << bitIdx)) != 0;
746 }
747
748 // It's a multibyte encoded character. Call a non-inline function
749 // for the heavy lifting.
jeffhao10037c82012-01-23 15:06:23 -0800750 return IsValidPartOfMemberNameUtf8Slow(pUtf8Ptr);
751}
752
753bool IsValidMemberName(const char* s) {
754 bool angle_name = false;
755
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700756 switch (*s) {
jeffhao10037c82012-01-23 15:06:23 -0800757 case '\0':
758 // The empty string is not a valid name.
759 return false;
760 case '<':
761 angle_name = true;
762 s++;
763 break;
764 }
765
766 while (true) {
767 switch (*s) {
768 case '\0':
769 return !angle_name;
770 case '>':
771 return angle_name && s[1] == '\0';
772 }
773
774 if (!IsValidPartOfMemberNameUtf8(&s)) {
775 return false;
776 }
777 }
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700778}
779
Elliott Hughes906e6852011-10-28 14:52:10 -0700780enum ClassNameType { kName, kDescriptor };
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700781static bool IsValidClassName(const char* s, ClassNameType type, char separator) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700782 int arrayCount = 0;
783 while (*s == '[') {
784 arrayCount++;
785 s++;
786 }
787
788 if (arrayCount > 255) {
789 // Arrays may have no more than 255 dimensions.
790 return false;
791 }
792
793 if (arrayCount != 0) {
794 /*
795 * If we're looking at an array of some sort, then it doesn't
796 * matter if what is being asked for is a class name; the
797 * format looks the same as a type descriptor in that case, so
798 * treat it as such.
799 */
Elliott Hughes906e6852011-10-28 14:52:10 -0700800 type = kDescriptor;
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700801 }
802
Elliott Hughes906e6852011-10-28 14:52:10 -0700803 if (type == kDescriptor) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700804 /*
805 * We are looking for a descriptor. Either validate it as a
806 * single-character primitive type, or continue on to check the
807 * embedded class name (bracketed by "L" and ";").
808 */
809 switch (*(s++)) {
810 case 'B':
811 case 'C':
812 case 'D':
813 case 'F':
814 case 'I':
815 case 'J':
816 case 'S':
817 case 'Z':
818 // These are all single-character descriptors for primitive types.
819 return (*s == '\0');
820 case 'V':
821 // Non-array void is valid, but you can't have an array of void.
822 return (arrayCount == 0) && (*s == '\0');
823 case 'L':
824 // Class name: Break out and continue below.
825 break;
826 default:
827 // Oddball descriptor character.
828 return false;
829 }
830 }
831
832 /*
833 * We just consumed the 'L' that introduces a class name as part
834 * of a type descriptor, or we are looking for an unadorned class
835 * name.
836 */
837
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700838 bool sepOrFirst = true; // first character or just encountered a separator.
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700839 for (;;) {
840 uint8_t c = (uint8_t) *s;
841 switch (c) {
842 case '\0':
843 /*
844 * Premature end for a type descriptor, but valid for
845 * a class name as long as we haven't encountered an
846 * empty component (including the degenerate case of
847 * the empty string "").
848 */
Elliott Hughes906e6852011-10-28 14:52:10 -0700849 return (type == kName) && !sepOrFirst;
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700850 case ';':
851 /*
852 * Invalid character for a class name, but the
853 * legitimate end of a type descriptor. In the latter
854 * case, make sure that this is the end of the string
855 * and that it doesn't end with an empty component
856 * (including the degenerate case of "L;").
857 */
Elliott Hughes906e6852011-10-28 14:52:10 -0700858 return (type == kDescriptor) && !sepOrFirst && (s[1] == '\0');
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700859 case '/':
860 case '.':
861 if (c != separator) {
862 // The wrong separator character.
863 return false;
864 }
865 if (sepOrFirst) {
866 // Separator at start or two separators in a row.
867 return false;
868 }
869 sepOrFirst = true;
870 s++;
871 break;
872 default:
jeffhao10037c82012-01-23 15:06:23 -0800873 if (!IsValidPartOfMemberNameUtf8(&s)) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700874 return false;
875 }
876 sepOrFirst = false;
877 break;
878 }
879 }
880}
881
Elliott Hughes906e6852011-10-28 14:52:10 -0700882bool IsValidBinaryClassName(const char* s) {
883 return IsValidClassName(s, kName, '.');
884}
885
886bool IsValidJniClassName(const char* s) {
887 return IsValidClassName(s, kName, '/');
888}
889
890bool IsValidDescriptor(const char* s) {
891 return IsValidClassName(s, kDescriptor, '/');
892}
893
Elliott Hughes48436bb2012-02-07 15:23:28 -0800894void Split(const std::string& s, char separator, std::vector<std::string>& result) {
Elliott Hughes34023802011-08-30 12:06:17 -0700895 const char* p = s.data();
896 const char* end = p + s.size();
897 while (p != end) {
Elliott Hughes48436bb2012-02-07 15:23:28 -0800898 if (*p == separator) {
Elliott Hughes34023802011-08-30 12:06:17 -0700899 ++p;
900 } else {
901 const char* start = p;
Elliott Hughes48436bb2012-02-07 15:23:28 -0800902 while (++p != end && *p != separator) {
903 // Skip to the next occurrence of the separator.
Elliott Hughes34023802011-08-30 12:06:17 -0700904 }
905 result.push_back(std::string(start, p - start));
906 }
907 }
908}
909
Dave Allison70202782013-10-22 17:52:19 -0700910std::string Trim(std::string s) {
911 std::string result;
912 unsigned int start_index = 0;
913 unsigned int end_index = s.size() - 1;
914
915 // Skip initial whitespace.
916 while (start_index < s.size()) {
917 if (!isspace(s[start_index])) {
918 break;
919 }
920 start_index++;
921 }
922
923 // Skip terminating whitespace.
924 while (end_index >= start_index) {
925 if (!isspace(s[end_index])) {
926 break;
927 }
928 end_index--;
929 }
930
931 // All spaces, no beef.
932 if (end_index < start_index) {
933 return "";
934 }
935 // Start_index is the first non-space, end_index is the last one.
936 return s.substr(start_index, end_index - start_index + 1);
937}
938
Elliott Hughes48436bb2012-02-07 15:23:28 -0800939template <typename StringT>
940std::string Join(std::vector<StringT>& strings, char separator) {
941 if (strings.empty()) {
942 return "";
943 }
944
945 std::string result(strings[0]);
946 for (size_t i = 1; i < strings.size(); ++i) {
947 result += separator;
948 result += strings[i];
949 }
950 return result;
951}
952
953// Explicit instantiations.
954template std::string Join<std::string>(std::vector<std::string>& strings, char separator);
955template std::string Join<const char*>(std::vector<const char*>& strings, char separator);
956template std::string Join<char*>(std::vector<char*>& strings, char separator);
957
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800958bool StartsWith(const std::string& s, const char* prefix) {
959 return s.compare(0, strlen(prefix), prefix) == 0;
960}
961
Brian Carlstrom7a967b32012-03-28 15:23:10 -0700962bool EndsWith(const std::string& s, const char* suffix) {
963 size_t suffix_length = strlen(suffix);
964 size_t string_length = s.size();
965 if (suffix_length > string_length) {
966 return false;
967 }
968 size_t offset = string_length - suffix_length;
969 return s.compare(offset, suffix_length, suffix) == 0;
970}
971
Elliott Hughes22869a92012-03-27 14:08:24 -0700972void SetThreadName(const char* thread_name) {
Elliott Hughesdcc24742011-09-07 14:02:44 -0700973 int hasAt = 0;
974 int hasDot = 0;
Elliott Hughes22869a92012-03-27 14:08:24 -0700975 const char* s = thread_name;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700976 while (*s) {
977 if (*s == '.') {
978 hasDot = 1;
979 } else if (*s == '@') {
980 hasAt = 1;
981 }
982 s++;
983 }
Elliott Hughes22869a92012-03-27 14:08:24 -0700984 int len = s - thread_name;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700985 if (len < 15 || hasAt || !hasDot) {
Elliott Hughes22869a92012-03-27 14:08:24 -0700986 s = thread_name;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700987 } else {
Elliott Hughes22869a92012-03-27 14:08:24 -0700988 s = thread_name + len - 15;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700989 }
990#if defined(HAVE_ANDROID_PTHREAD_SETNAME_NP)
Elliott Hughes7c6a61e2012-03-12 18:01:41 -0700991 // pthread_setname_np fails rather than truncating long strings.
Elliott Hughesdcc24742011-09-07 14:02:44 -0700992 char buf[16]; // MAX_TASK_COMM_LEN=16 is hard-coded into bionic
993 strncpy(buf, s, sizeof(buf)-1);
994 buf[sizeof(buf)-1] = '\0';
995 errno = pthread_setname_np(pthread_self(), buf);
996 if (errno != 0) {
997 PLOG(WARNING) << "Unable to set the name of current thread to '" << buf << "'";
998 }
Elliott Hughes4ae722a2012-03-13 11:08:51 -0700999#elif defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
Elliott Hughes22869a92012-03-27 14:08:24 -07001000 pthread_setname_np(thread_name);
Elliott Hughesdcc24742011-09-07 14:02:44 -07001001#elif defined(HAVE_PRCTL)
Elliott Hughes398f64b2012-03-26 18:05:48 -07001002 prctl(PR_SET_NAME, (unsigned long) s, 0, 0, 0); // NOLINT (unsigned long)
Elliott Hughesdcc24742011-09-07 14:02:44 -07001003#else
Elliott Hughes22869a92012-03-27 14:08:24 -07001004 UNIMPLEMENTED(WARNING) << thread_name;
Elliott Hughesdcc24742011-09-07 14:02:44 -07001005#endif
1006}
1007
Brian Carlstrom29212012013-09-12 22:18:30 -07001008void GetTaskStats(pid_t tid, char* state, int* utime, int* stime, int* task_cpu) {
1009 *utime = *stime = *task_cpu = 0;
Elliott Hughesbfe487b2011-10-26 15:48:55 -07001010 std::string stats;
Elliott Hughes8a31b502012-04-30 19:36:11 -07001011 if (!ReadFileToString(StringPrintf("/proc/self/task/%d/stat", tid), &stats)) {
Elliott Hughesbfe487b2011-10-26 15:48:55 -07001012 return;
1013 }
1014 // Skip the command, which may contain spaces.
1015 stats = stats.substr(stats.find(')') + 2);
1016 // Extract the three fields we care about.
1017 std::vector<std::string> fields;
1018 Split(stats, ' ', fields);
Brian Carlstrom29212012013-09-12 22:18:30 -07001019 *state = fields[0][0];
1020 *utime = strtoull(fields[11].c_str(), NULL, 10);
1021 *stime = strtoull(fields[12].c_str(), NULL, 10);
1022 *task_cpu = strtoull(fields[36].c_str(), NULL, 10);
Elliott Hughesbfe487b2011-10-26 15:48:55 -07001023}
1024
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001025std::string GetSchedulerGroupName(pid_t tid) {
1026 // /proc/<pid>/cgroup looks like this:
1027 // 2:devices:/
1028 // 1:cpuacct,cpu:/
1029 // We want the third field from the line whose second field contains the "cpu" token.
1030 std::string cgroup_file;
1031 if (!ReadFileToString(StringPrintf("/proc/self/task/%d/cgroup", tid), &cgroup_file)) {
1032 return "";
1033 }
1034 std::vector<std::string> cgroup_lines;
1035 Split(cgroup_file, '\n', cgroup_lines);
1036 for (size_t i = 0; i < cgroup_lines.size(); ++i) {
1037 std::vector<std::string> cgroup_fields;
1038 Split(cgroup_lines[i], ':', cgroup_fields);
1039 std::vector<std::string> cgroups;
1040 Split(cgroup_fields[1], ',', cgroups);
1041 for (size_t i = 0; i < cgroups.size(); ++i) {
1042 if (cgroups[i] == "cpu") {
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001043 return cgroup_fields[2].substr(1); // Skip the leading slash.
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001044 }
1045 }
1046 }
1047 return "";
1048}
1049
Christopher Ferrisa2cee182014-04-16 19:13:59 -07001050void DumpNativeStack(std::ostream& os, pid_t tid, const char* prefix,
Kenny Root067d20f2014-03-05 14:57:21 -08001051 mirror::ArtMethod* current_method) {
1052 // We may be called from contexts where current_method is not null, so we must assert this.
1053 if (current_method != nullptr) {
1054 Locks::mutator_lock_->AssertSharedHeld(Thread::Current());
1055 }
Ian Rogersc5f17732014-06-05 20:48:42 -07001056#ifdef __linux__
Ian Rogers700a4022014-05-19 16:49:03 -07001057 std::unique_ptr<Backtrace> backtrace(Backtrace::Create(BACKTRACE_CURRENT_PROCESS, tid));
Christopher Ferris7b5f0cf2013-11-01 15:18:45 -07001058 if (!backtrace->Unwind(0)) {
1059 os << prefix << "(backtrace::Unwind failed for thread " << tid << ")\n";
Elliott Hughes46e251b2012-05-22 15:10:45 -07001060 return;
Christopher Ferris7b5f0cf2013-11-01 15:18:45 -07001061 } else if (backtrace->NumFrames() == 0) {
Elliott Hughes225f5a12012-06-11 11:23:48 -07001062 os << prefix << "(no native stack frames for thread " << tid << ")\n";
Elliott Hughes46e251b2012-05-22 15:10:45 -07001063 return;
1064 }
1065
Christopher Ferris943af7d2014-01-16 12:41:46 -08001066 for (Backtrace::const_iterator it = backtrace->begin();
1067 it != backtrace->end(); ++it) {
Elliott Hughes46e251b2012-05-22 15:10:45 -07001068 // We produce output like this:
Christopher Ferrisa2cee182014-04-16 19:13:59 -07001069 // ] #00 pc 000075bb8 /system/lib/libc.so (unwind_backtrace_thread+536)
1070 // In order for parsing tools to continue to function, the stack dump
1071 // format must at least adhere to this format:
1072 // #XX pc <RELATIVE_ADDR> <FULL_PATH_TO_SHARED_LIBRARY> ...
1073 // The parsers require a single space before and after pc, and two spaces
1074 // after the <RELATIVE_ADDR>. There can be any prefix data before the
1075 // #XX. <RELATIVE_ADDR> has to be a hex number but with no 0x prefix.
1076 os << prefix << StringPrintf("#%02zu pc ", it->num);
1077 if (!it->map) {
1078 os << StringPrintf("%08" PRIxPTR " ???", it->pc);
Christopher Ferris7b5f0cf2013-11-01 15:18:45 -07001079 } else {
Christopher Ferrisa2cee182014-04-16 19:13:59 -07001080 os << StringPrintf("%08" PRIxPTR " ", it->pc - it->map->start)
1081 << it->map->name << " (";
1082 if (!it->func_name.empty()) {
1083 os << it->func_name;
1084 if (it->func_offset != 0) {
1085 os << "+" << it->func_offset;
1086 }
1087 } else if (current_method != nullptr && current_method->IsWithinQuickCode(it->pc)) {
Brian Carlstrom474cc792014-03-07 14:18:15 -08001088 const void* start_of_code = current_method->GetEntryPointFromQuickCompiledCode();
1089 os << JniLongName(current_method) << "+"
1090 << (it->pc - reinterpret_cast<uintptr_t>(start_of_code));
Kenny Root067d20f2014-03-05 14:57:21 -08001091 } else {
1092 os << "???";
1093 }
Christopher Ferrisa2cee182014-04-16 19:13:59 -07001094 os << ")";
Elliott Hughes46e251b2012-05-22 15:10:45 -07001095 }
Christopher Ferrisa2cee182014-04-16 19:13:59 -07001096 os << "\n";
Elliott Hughes46e251b2012-05-22 15:10:45 -07001097 }
Ian Rogersc5f17732014-06-05 20:48:42 -07001098#endif
Elliott Hughes46e251b2012-05-22 15:10:45 -07001099}
1100
Elliott Hughes058a6de2012-05-24 19:13:02 -07001101#if defined(__APPLE__)
1102
1103// TODO: is there any way to get the kernel stack on Mac OS?
1104void DumpKernelStack(std::ostream&, pid_t, const char*, bool) {}
1105
1106#else
1107
Elliott Hughes46e251b2012-05-22 15:10:45 -07001108void DumpKernelStack(std::ostream& os, pid_t tid, const char* prefix, bool include_count) {
Elliott Hughes12a95022012-05-24 21:41:38 -07001109 if (tid == GetTid()) {
1110 // There's no point showing that we're reading our stack out of /proc!
1111 return;
1112 }
1113
Elliott Hughes46e251b2012-05-22 15:10:45 -07001114 std::string kernel_stack_filename(StringPrintf("/proc/self/task/%d/stack", tid));
1115 std::string kernel_stack;
1116 if (!ReadFileToString(kernel_stack_filename, &kernel_stack)) {
Elliott Hughes058a6de2012-05-24 19:13:02 -07001117 os << prefix << "(couldn't read " << kernel_stack_filename << ")\n";
jeffhaoc4c3ee22012-05-25 16:16:32 -07001118 return;
Elliott Hughes46e251b2012-05-22 15:10:45 -07001119 }
1120
1121 std::vector<std::string> kernel_stack_frames;
1122 Split(kernel_stack, '\n', kernel_stack_frames);
1123 // We skip the last stack frame because it's always equivalent to "[<ffffffff>] 0xffffffff",
1124 // which looking at the source appears to be the kernel's way of saying "that's all, folks!".
1125 kernel_stack_frames.pop_back();
1126 for (size_t i = 0; i < kernel_stack_frames.size(); ++i) {
Brian Carlstrom474cc792014-03-07 14:18:15 -08001127 // Turn "[<ffffffff8109156d>] futex_wait_queue_me+0xcd/0x110"
1128 // into "futex_wait_queue_me+0xcd/0x110".
Elliott Hughes46e251b2012-05-22 15:10:45 -07001129 const char* text = kernel_stack_frames[i].c_str();
1130 const char* close_bracket = strchr(text, ']');
1131 if (close_bracket != NULL) {
1132 text = close_bracket + 2;
1133 }
1134 os << prefix;
1135 if (include_count) {
1136 os << StringPrintf("#%02zd ", i);
1137 }
1138 os << text << "\n";
1139 }
1140}
1141
1142#endif
1143
Brian Carlstroma56fcd62012-02-04 21:23:01 -08001144const char* GetAndroidRoot() {
1145 const char* android_root = getenv("ANDROID_ROOT");
1146 if (android_root == NULL) {
1147 if (OS::DirectoryExists("/system")) {
1148 android_root = "/system";
Brian Carlstroma9f19782011-10-13 00:14:47 -07001149 } else {
Brian Carlstroma56fcd62012-02-04 21:23:01 -08001150 LOG(FATAL) << "ANDROID_ROOT not set and /system does not exist";
1151 return "";
Brian Carlstroma9f19782011-10-13 00:14:47 -07001152 }
1153 }
Brian Carlstroma56fcd62012-02-04 21:23:01 -08001154 if (!OS::DirectoryExists(android_root)) {
1155 LOG(FATAL) << "Failed to find ANDROID_ROOT directory " << android_root;
Brian Carlstroma9f19782011-10-13 00:14:47 -07001156 return "";
1157 }
Brian Carlstroma56fcd62012-02-04 21:23:01 -08001158 return android_root;
1159}
Brian Carlstroma9f19782011-10-13 00:14:47 -07001160
Brian Carlstroma56fcd62012-02-04 21:23:01 -08001161const char* GetAndroidData() {
1162 const char* android_data = getenv("ANDROID_DATA");
1163 if (android_data == NULL) {
1164 if (OS::DirectoryExists("/data")) {
1165 android_data = "/data";
1166 } else {
1167 LOG(FATAL) << "ANDROID_DATA not set and /data does not exist";
1168 return "";
1169 }
1170 }
1171 if (!OS::DirectoryExists(android_data)) {
1172 LOG(FATAL) << "Failed to find ANDROID_DATA directory " << android_data;
1173 return "";
1174 }
1175 return android_data;
1176}
1177
Narayan Kamath11d9f062014-04-23 20:24:57 +01001178std::string GetDalvikCacheOrDie(const char* subdir, const bool create_if_absent) {
1179 CHECK(subdir != nullptr);
Brian Carlstrom41ccffd2014-05-06 10:37:30 -07001180 const char* android_data = GetAndroidData();
1181 const std::string dalvik_cache_root(StringPrintf("%s/dalvik-cache/", android_data));
Narayan Kamath11d9f062014-04-23 20:24:57 +01001182 const std::string dalvik_cache = dalvik_cache_root + subdir;
1183 if (create_if_absent && !OS::DirectoryExists(dalvik_cache.c_str())) {
Brian Carlstrom41ccffd2014-05-06 10:37:30 -07001184 // Don't create the system's /data/dalvik-cache/... because it needs special permissions.
1185 if (strcmp(android_data, "/data") != 0) {
Narayan Kamath11d9f062014-04-23 20:24:57 +01001186 int result = mkdir(dalvik_cache_root.c_str(), 0700);
Narayan Kamathef204fa2014-04-30 17:25:23 +01001187 if (result != 0 && errno != EEXIST) {
Narayan Kamath11d9f062014-04-23 20:24:57 +01001188 PLOG(FATAL) << "Failed to create dalvik-cache directory " << dalvik_cache_root;
1189 return "";
1190 }
1191 result = mkdir(dalvik_cache.c_str(), 0700);
1192 if (result != 0) {
1193 PLOG(FATAL) << "Failed to create dalvik-cache directory " << dalvik_cache;
Brian Carlstroma9f19782011-10-13 00:14:47 -07001194 return "";
1195 }
1196 } else {
Brian Carlstrom7675e162013-06-10 16:18:04 -07001197 LOG(FATAL) << "Failed to find dalvik-cache directory " << dalvik_cache;
Brian Carlstroma9f19782011-10-13 00:14:47 -07001198 return "";
1199 }
1200 }
Brian Carlstrom7675e162013-06-10 16:18:04 -07001201 return dalvik_cache;
Brian Carlstroma9f19782011-10-13 00:14:47 -07001202}
1203
Narayan Kamath11d9f062014-04-23 20:24:57 +01001204std::string GetDalvikCacheFilenameOrDie(const char* location, const char* cache_location) {
Ian Rogerse6060102013-05-16 12:01:04 -07001205 if (location[0] != '/') {
1206 LOG(FATAL) << "Expected path in location to be absolute: "<< location;
1207 }
Ian Rogers8d31bbd2013-10-13 10:44:14 -07001208 std::string cache_file(&location[1]); // skip leading slash
Brian Carlstrom19a08362013-10-16 14:37:22 -07001209 if (!EndsWith(location, ".dex") && !EndsWith(location, ".art")) {
Brian Carlstrom30e2ea42013-06-19 23:25:37 -07001210 cache_file += "/";
1211 cache_file += DexFile::kClassesDex;
1212 }
Brian Carlstromb7bbba42011-10-13 14:58:47 -07001213 std::replace(cache_file.begin(), cache_file.end(), '/', '@');
Narayan Kamath11d9f062014-04-23 20:24:57 +01001214 return StringPrintf("%s/%s", cache_location, cache_file.c_str());
Brian Carlstromb7bbba42011-10-13 14:58:47 -07001215}
1216
Brian Carlstrom2afe4942014-05-19 10:25:33 -07001217static void InsertIsaDirectory(const InstructionSet isa, std::string* filename) {
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -07001218 // in = /foo/bar/baz
1219 // out = /foo/bar/<isa>/baz
1220 size_t pos = filename->rfind('/');
1221 CHECK_NE(pos, std::string::npos) << *filename << " " << isa;
1222 filename->insert(pos, "/", 1);
1223 filename->insert(pos + 1, GetInstructionSetString(isa));
1224}
1225
1226std::string GetSystemImageFilename(const char* location, const InstructionSet isa) {
1227 // location = /system/framework/boot.art
1228 // filename = /system/framework/<isa>/boot.art
1229 std::string filename(location);
Brian Carlstrom2afe4942014-05-19 10:25:33 -07001230 InsertIsaDirectory(isa, &filename);
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -07001231 return filename;
1232}
1233
1234std::string DexFilenameToOdexFilename(const std::string& location, const InstructionSet isa) {
1235 // location = /foo/bar/baz.jar
1236 // odex_location = /foo/bar/<isa>/baz.odex
Andreas Gampe833a4852014-05-21 18:46:59 -07001237
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -07001238 CHECK_GE(location.size(), 4U) << location; // must be at least .123
1239 std::string odex_location(location);
Brian Carlstrom2afe4942014-05-19 10:25:33 -07001240 InsertIsaDirectory(isa, &odex_location);
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -07001241 size_t dot_index = odex_location.size() - 3 - 1; // 3=dex or zip or apk
1242 CHECK_EQ('.', odex_location[dot_index]) << location;
1243 odex_location.resize(dot_index + 1);
1244 CHECK_EQ('.', odex_location[odex_location.size()-1]) << location << " " << odex_location;
1245 odex_location += "odex";
1246 return odex_location;
1247}
1248
Brian Carlstrom7c3d13a2013-09-04 17:15:11 -07001249bool IsZipMagic(uint32_t magic) {
1250 return (('P' == ((magic >> 0) & 0xff)) &&
1251 ('K' == ((magic >> 8) & 0xff)));
jeffhao262bf462011-10-20 18:36:32 -07001252}
1253
Brian Carlstrom7c3d13a2013-09-04 17:15:11 -07001254bool IsDexMagic(uint32_t magic) {
1255 return DexFile::IsMagicValid(reinterpret_cast<const byte*>(&magic));
Brian Carlstrom7a967b32012-03-28 15:23:10 -07001256}
1257
Brian Carlstrom7c3d13a2013-09-04 17:15:11 -07001258bool IsOatMagic(uint32_t magic) {
1259 return (memcmp(reinterpret_cast<const byte*>(magic),
1260 OatHeader::kOatMagic,
1261 sizeof(OatHeader::kOatMagic)) == 0);
jeffhao262bf462011-10-20 18:36:32 -07001262}
1263
Brian Carlstrom6449c622014-02-10 23:48:36 -08001264bool Exec(std::vector<std::string>& arg_vector, std::string* error_msg) {
1265 const std::string command_line(Join(arg_vector, ' '));
1266
1267 CHECK_GE(arg_vector.size(), 1U) << command_line;
1268
1269 // Convert the args to char pointers.
1270 const char* program = arg_vector[0].c_str();
1271 std::vector<char*> args;
Brian Carlstrom35d8b8e2014-02-25 10:51:11 -08001272 for (size_t i = 0; i < arg_vector.size(); ++i) {
1273 const std::string& arg = arg_vector[i];
1274 char* arg_str = const_cast<char*>(arg.c_str());
1275 CHECK(arg_str != nullptr) << i;
1276 args.push_back(arg_str);
Brian Carlstrom6449c622014-02-10 23:48:36 -08001277 }
1278 args.push_back(NULL);
1279
1280 // fork and exec
1281 pid_t pid = fork();
1282 if (pid == 0) {
1283 // no allocation allowed between fork and exec
1284
1285 // change process groups, so we don't get reaped by ProcessManager
1286 setpgid(0, 0);
1287
1288 execv(program, &args[0]);
1289
Brian Carlstrom13db9aa2014-02-27 12:44:32 -08001290 PLOG(ERROR) << "Failed to execv(" << command_line << ")";
1291 exit(1);
Brian Carlstrom6449c622014-02-10 23:48:36 -08001292 } else {
1293 if (pid == -1) {
1294 *error_msg = StringPrintf("Failed to execv(%s) because fork failed: %s",
1295 command_line.c_str(), strerror(errno));
1296 return false;
1297 }
1298
1299 // wait for subprocess to finish
1300 int status;
1301 pid_t got_pid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0));
1302 if (got_pid != pid) {
1303 *error_msg = StringPrintf("Failed after fork for execv(%s) because waitpid failed: "
1304 "wanted %d, got %d: %s",
1305 command_line.c_str(), pid, got_pid, strerror(errno));
1306 return false;
1307 }
1308 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
1309 *error_msg = StringPrintf("Failed execv(%s) because non-0 exit status",
1310 command_line.c_str());
1311 return false;
1312 }
1313 }
1314 return true;
1315}
1316
Elliott Hughes42ee1422011-09-06 12:33:32 -07001317} // namespace art