Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 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 Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 16 | |
Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 17 | #include "utils.h" |
| 18 | |
Christopher Ferris | 943af7d | 2014-01-16 12:41:46 -0800 | [diff] [blame] | 19 | #include <inttypes.h> |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 20 | #include <pthread.h> |
Brian Carlstrom | a9f1978 | 2011-10-13 00:14:47 -0700 | [diff] [blame] | 21 | #include <sys/stat.h> |
Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 22 | #include <sys/syscall.h> |
| 23 | #include <sys/types.h> |
Brian Carlstrom | 4cf5e57 | 2014-02-25 11:47:48 -0800 | [diff] [blame] | 24 | #include <sys/wait.h> |
Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 25 | #include <unistd.h> |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 26 | #include <memory> |
Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 27 | |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 28 | #include "base/stl_util.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 29 | #include "base/unix_file/fd_file.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 30 | #include "dex_file-inl.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 31 | #include "mirror/art_field-inl.h" |
| 32 | #include "mirror/art_method-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 33 | #include "mirror/class-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 34 | #include "mirror/class_loader.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | #include "mirror/object-inl.h" |
| 36 | #include "mirror/object_array-inl.h" |
| 37 | #include "mirror/string.h" |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 38 | #include "os.h" |
Kenny Root | 067d20f | 2014-03-05 14:57:21 -0800 | [diff] [blame] | 39 | #include "scoped_thread_state_change.h" |
Ian Rogers | a672490 | 2013-09-23 09:23:37 -0700 | [diff] [blame] | 40 | #include "utf-inl.h" |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 41 | |
Elliott Hughes | 4ae722a | 2012-03-13 11:08:51 -0700 | [diff] [blame] | 42 | #if defined(__APPLE__) |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 43 | #include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED |
Elliott Hughes | f149843 | 2012-03-28 19:34:27 -0700 | [diff] [blame] | 44 | #include <sys/syscall.h> |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 45 | #include <sys/time.h> |
Elliott Hughes | 4ae722a | 2012-03-13 11:08:51 -0700 | [diff] [blame] | 46 | #endif |
| 47 | |
Christopher Ferris | 7b5f0cf | 2013-11-01 15:18:45 -0700 | [diff] [blame] | 48 | #include <backtrace/Backtrace.h> // For DumpNativeStack. |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 49 | |
Elliott Hughes | 058a6de | 2012-05-24 19:13:02 -0700 | [diff] [blame] | 50 | #if defined(__linux__) |
Elliott Hughes | e1aee69 | 2012-01-17 16:40:10 -0800 | [diff] [blame] | 51 | #include <linux/unistd.h> |
Elliott Hughes | e1aee69 | 2012-01-17 16:40:10 -0800 | [diff] [blame] | 52 | #endif |
| 53 | |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 54 | namespace art { |
| 55 | |
Andreas Gampe | 8e1cb91 | 2015-01-08 20:11:09 -0800 | [diff] [blame] | 56 | #if defined(__linux__) |
| 57 | static constexpr bool kUseAddr2line = !kIsTargetBuild; |
| 58 | #endif |
| 59 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 60 | pid_t GetTid() { |
Brian Carlstrom | f3a2641 | 2012-08-24 11:06:02 -0700 | [diff] [blame] | 61 | #if defined(__APPLE__) |
| 62 | uint64_t owner; |
| 63 | CHECK_PTHREAD_CALL(pthread_threadid_np, (NULL, &owner), __FUNCTION__); // Requires Mac OS 10.6 |
| 64 | return owner; |
Elliott Hughes | 323aa86 | 2014-08-20 15:00:04 -0700 | [diff] [blame] | 65 | #elif defined(__BIONIC__) |
| 66 | return gettid(); |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 67 | #else |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 68 | return syscall(__NR_gettid); |
| 69 | #endif |
| 70 | } |
| 71 | |
Elliott Hughes | 289be85 | 2012-06-12 13:57:20 -0700 | [diff] [blame] | 72 | std::string GetThreadName(pid_t tid) { |
| 73 | std::string result; |
| 74 | if (ReadFileToString(StringPrintf("/proc/self/task/%d/comm", tid), &result)) { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 75 | result.resize(result.size() - 1); // Lose the trailing '\n'. |
Elliott Hughes | 289be85 | 2012-06-12 13:57:20 -0700 | [diff] [blame] | 76 | } else { |
| 77 | result = "<unknown>"; |
| 78 | } |
| 79 | return result; |
| 80 | } |
| 81 | |
Elliott Hughes | 6d3fc56 | 2014-08-27 11:47:01 -0700 | [diff] [blame] | 82 | void GetThreadStack(pthread_t thread, void** stack_base, size_t* stack_size, size_t* guard_size) { |
Elliott Hughes | e188419 | 2012-04-23 12:38:15 -0700 | [diff] [blame] | 83 | #if defined(__APPLE__) |
Brian Carlstrom | 2921201 | 2013-09-12 22:18:30 -0700 | [diff] [blame] | 84 | *stack_size = pthread_get_stacksize_np(thread); |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 85 | void* stack_addr = pthread_get_stackaddr_np(thread); |
Elliott Hughes | e188419 | 2012-04-23 12:38:15 -0700 | [diff] [blame] | 86 | |
| 87 | // Check whether stack_addr is the base or end of the stack. |
| 88 | // (On Mac OS 10.7, it's the end.) |
| 89 | int stack_variable; |
| 90 | if (stack_addr > &stack_variable) { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 91 | *stack_base = reinterpret_cast<uint8_t*>(stack_addr) - *stack_size; |
Elliott Hughes | e188419 | 2012-04-23 12:38:15 -0700 | [diff] [blame] | 92 | } else { |
Brian Carlstrom | 2921201 | 2013-09-12 22:18:30 -0700 | [diff] [blame] | 93 | *stack_base = stack_addr; |
Elliott Hughes | e188419 | 2012-04-23 12:38:15 -0700 | [diff] [blame] | 94 | } |
Elliott Hughes | 6d3fc56 | 2014-08-27 11:47:01 -0700 | [diff] [blame] | 95 | |
| 96 | // This is wrong, but there doesn't seem to be a way to get the actual value on the Mac. |
| 97 | pthread_attr_t attributes; |
| 98 | CHECK_PTHREAD_CALL(pthread_attr_init, (&attributes), __FUNCTION__); |
| 99 | CHECK_PTHREAD_CALL(pthread_attr_getguardsize, (&attributes, guard_size), __FUNCTION__); |
| 100 | CHECK_PTHREAD_CALL(pthread_attr_destroy, (&attributes), __FUNCTION__); |
Elliott Hughes | e188419 | 2012-04-23 12:38:15 -0700 | [diff] [blame] | 101 | #else |
| 102 | pthread_attr_t attributes; |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 103 | CHECK_PTHREAD_CALL(pthread_getattr_np, (thread, &attributes), __FUNCTION__); |
Brian Carlstrom | 2921201 | 2013-09-12 22:18:30 -0700 | [diff] [blame] | 104 | CHECK_PTHREAD_CALL(pthread_attr_getstack, (&attributes, stack_base, stack_size), __FUNCTION__); |
Elliott Hughes | 6d3fc56 | 2014-08-27 11:47:01 -0700 | [diff] [blame] | 105 | CHECK_PTHREAD_CALL(pthread_attr_getguardsize, (&attributes, guard_size), __FUNCTION__); |
Elliott Hughes | e188419 | 2012-04-23 12:38:15 -0700 | [diff] [blame] | 106 | CHECK_PTHREAD_CALL(pthread_attr_destroy, (&attributes), __FUNCTION__); |
Elliott Hughes | 839cc30 | 2014-08-28 10:24:44 -0700 | [diff] [blame] | 107 | |
| 108 | #if defined(__GLIBC__) |
| 109 | // If we're the main thread, check whether we were run with an unlimited stack. In that case, |
| 110 | // glibc will have reported a 2GB stack for our 32-bit process, and our stack overflow detection |
| 111 | // will be broken because we'll die long before we get close to 2GB. |
| 112 | bool is_main_thread = (::art::GetTid() == getpid()); |
| 113 | if (is_main_thread) { |
| 114 | rlimit stack_limit; |
| 115 | if (getrlimit(RLIMIT_STACK, &stack_limit) == -1) { |
| 116 | PLOG(FATAL) << "getrlimit(RLIMIT_STACK) failed"; |
| 117 | } |
| 118 | if (stack_limit.rlim_cur == RLIM_INFINITY) { |
| 119 | size_t old_stack_size = *stack_size; |
| 120 | |
| 121 | // Use the kernel default limit as our size, and adjust the base to match. |
| 122 | *stack_size = 8 * MB; |
| 123 | *stack_base = reinterpret_cast<uint8_t*>(*stack_base) + (old_stack_size - *stack_size); |
| 124 | |
| 125 | VLOG(threads) << "Limiting unlimited stack (reported as " << PrettySize(old_stack_size) << ")" |
| 126 | << " to " << PrettySize(*stack_size) |
| 127 | << " with base " << *stack_base; |
| 128 | } |
| 129 | } |
| 130 | #endif |
| 131 | |
Elliott Hughes | e188419 | 2012-04-23 12:38:15 -0700 | [diff] [blame] | 132 | #endif |
| 133 | } |
| 134 | |
Elliott Hughes | d92bec4 | 2011-09-02 17:04:36 -0700 | [diff] [blame] | 135 | bool ReadFileToString(const std::string& file_name, std::string* result) { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 136 | std::unique_ptr<File> file(new File); |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 137 | if (!file->Open(file_name, O_RDONLY)) { |
Elliott Hughes | d92bec4 | 2011-09-02 17:04:36 -0700 | [diff] [blame] | 138 | return false; |
| 139 | } |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 140 | |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 141 | std::vector<char> buf(8 * KB); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 142 | while (true) { |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 143 | int64_t n = TEMP_FAILURE_RETRY(read(file->Fd(), &buf[0], buf.size())); |
Elliott Hughes | d92bec4 | 2011-09-02 17:04:36 -0700 | [diff] [blame] | 144 | if (n == -1) { |
| 145 | return false; |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 146 | } |
Elliott Hughes | d92bec4 | 2011-09-02 17:04:36 -0700 | [diff] [blame] | 147 | if (n == 0) { |
| 148 | return true; |
| 149 | } |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 150 | result->append(&buf[0], n); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 151 | } |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 154 | std::string GetIsoDate() { |
| 155 | time_t now = time(NULL); |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 156 | tm tmbuf; |
| 157 | tm* ptm = localtime_r(&now, &tmbuf); |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 158 | return StringPrintf("%04d-%02d-%02d %02d:%02d:%02d", |
| 159 | ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday, |
| 160 | ptm->tm_hour, ptm->tm_min, ptm->tm_sec); |
| 161 | } |
| 162 | |
Elliott Hughes | 7162ad9 | 2011-10-27 14:08:42 -0700 | [diff] [blame] | 163 | uint64_t MilliTime() { |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 164 | #if defined(__linux__) |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 165 | timespec now; |
Elliott Hughes | 7162ad9 | 2011-10-27 14:08:42 -0700 | [diff] [blame] | 166 | clock_gettime(CLOCK_MONOTONIC, &now); |
Ian Rogers | 0f67847 | 2014-03-10 16:18:37 -0700 | [diff] [blame] | 167 | return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000) + now.tv_nsec / UINT64_C(1000000); |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 168 | #else // __APPLE__ |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 169 | timeval now; |
Elliott Hughes | ad6c9c3 | 2012-01-19 17:39:12 -0800 | [diff] [blame] | 170 | gettimeofday(&now, NULL); |
Ian Rogers | 0f67847 | 2014-03-10 16:18:37 -0700 | [diff] [blame] | 171 | return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000) + now.tv_usec / UINT64_C(1000); |
Elliott Hughes | ad6c9c3 | 2012-01-19 17:39:12 -0800 | [diff] [blame] | 172 | #endif |
Elliott Hughes | 7162ad9 | 2011-10-27 14:08:42 -0700 | [diff] [blame] | 173 | } |
| 174 | |
jeffhao | a9ef3fd | 2011-12-13 18:33:43 -0800 | [diff] [blame] | 175 | uint64_t MicroTime() { |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 176 | #if defined(__linux__) |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 177 | timespec now; |
jeffhao | a9ef3fd | 2011-12-13 18:33:43 -0800 | [diff] [blame] | 178 | clock_gettime(CLOCK_MONOTONIC, &now); |
Ian Rogers | 0f67847 | 2014-03-10 16:18:37 -0700 | [diff] [blame] | 179 | return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000) + now.tv_nsec / UINT64_C(1000); |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 180 | #else // __APPLE__ |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 181 | timeval now; |
Elliott Hughes | ad6c9c3 | 2012-01-19 17:39:12 -0800 | [diff] [blame] | 182 | gettimeofday(&now, NULL); |
Ian Rogers | 0f67847 | 2014-03-10 16:18:37 -0700 | [diff] [blame] | 183 | return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000) + now.tv_usec; |
Elliott Hughes | ad6c9c3 | 2012-01-19 17:39:12 -0800 | [diff] [blame] | 184 | #endif |
jeffhao | a9ef3fd | 2011-12-13 18:33:43 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Elliott Hughes | 83df2ac | 2011-10-11 16:37:54 -0700 | [diff] [blame] | 187 | uint64_t NanoTime() { |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 188 | #if defined(__linux__) |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 189 | timespec now; |
Elliott Hughes | 83df2ac | 2011-10-11 16:37:54 -0700 | [diff] [blame] | 190 | clock_gettime(CLOCK_MONOTONIC, &now); |
Ian Rogers | 0f67847 | 2014-03-10 16:18:37 -0700 | [diff] [blame] | 191 | return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec; |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 192 | #else // __APPLE__ |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 193 | timeval now; |
Elliott Hughes | ad6c9c3 | 2012-01-19 17:39:12 -0800 | [diff] [blame] | 194 | gettimeofday(&now, NULL); |
Ian Rogers | 0f67847 | 2014-03-10 16:18:37 -0700 | [diff] [blame] | 195 | return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_usec * UINT64_C(1000); |
Elliott Hughes | ad6c9c3 | 2012-01-19 17:39:12 -0800 | [diff] [blame] | 196 | #endif |
Elliott Hughes | 83df2ac | 2011-10-11 16:37:54 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 199 | uint64_t ThreadCpuNanoTime() { |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 200 | #if defined(__linux__) |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 201 | timespec now; |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 202 | clock_gettime(CLOCK_THREAD_CPUTIME_ID, &now); |
Ian Rogers | 0f67847 | 2014-03-10 16:18:37 -0700 | [diff] [blame] | 203 | return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec; |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 204 | #else // __APPLE__ |
Elliott Hughes | 0512f02 | 2012-03-15 22:10:52 -0700 | [diff] [blame] | 205 | UNIMPLEMENTED(WARNING); |
| 206 | return -1; |
| 207 | #endif |
| 208 | } |
| 209 | |
Ian Rogers | 56edc43 | 2013-01-18 16:51:51 -0800 | [diff] [blame] | 210 | void NanoSleep(uint64_t ns) { |
| 211 | timespec tm; |
| 212 | tm.tv_sec = 0; |
| 213 | tm.tv_nsec = ns; |
| 214 | nanosleep(&tm, NULL); |
| 215 | } |
| 216 | |
Brian Carlstrom | bcc2926 | 2012-11-02 11:36:03 -0700 | [diff] [blame] | 217 | void InitTimeSpec(bool absolute, int clock, int64_t ms, int32_t ns, timespec* ts) { |
| 218 | int64_t endSec; |
| 219 | |
| 220 | if (absolute) { |
| 221 | #if !defined(__APPLE__) |
| 222 | clock_gettime(clock, ts); |
| 223 | #else |
| 224 | UNUSED(clock); |
| 225 | timeval tv; |
| 226 | gettimeofday(&tv, NULL); |
| 227 | ts->tv_sec = tv.tv_sec; |
| 228 | ts->tv_nsec = tv.tv_usec * 1000; |
| 229 | #endif |
| 230 | } else { |
| 231 | ts->tv_sec = 0; |
| 232 | ts->tv_nsec = 0; |
| 233 | } |
| 234 | endSec = ts->tv_sec + ms / 1000; |
| 235 | if (UNLIKELY(endSec >= 0x7fffffff)) { |
| 236 | std::ostringstream ss; |
| 237 | LOG(INFO) << "Note: end time exceeds epoch: " << ss.str(); |
| 238 | endSec = 0x7ffffffe; |
| 239 | } |
| 240 | ts->tv_sec = endSec; |
| 241 | ts->tv_nsec = (ts->tv_nsec + (ms % 1000) * 1000000) + ns; |
| 242 | |
| 243 | // Catch rollover. |
| 244 | if (ts->tv_nsec >= 1000000000L) { |
| 245 | ts->tv_sec++; |
| 246 | ts->tv_nsec -= 1000000000L; |
| 247 | } |
| 248 | } |
| 249 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 250 | std::string PrettyDescriptor(mirror::String* java_descriptor) { |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 251 | if (java_descriptor == NULL) { |
| 252 | return "null"; |
| 253 | } |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 254 | return PrettyDescriptor(java_descriptor->ToModifiedUtf8().c_str()); |
Elliott Hughes | 6c8867d | 2011-10-03 16:34:05 -0700 | [diff] [blame] | 255 | } |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 256 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 257 | std::string PrettyDescriptor(mirror::Class* klass) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 258 | if (klass == NULL) { |
| 259 | return "null"; |
| 260 | } |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 261 | std::string temp; |
| 262 | return PrettyDescriptor(klass->GetDescriptor(&temp)); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 263 | } |
| 264 | |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 265 | std::string PrettyDescriptor(const char* descriptor) { |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 266 | // Count the number of '['s to get the dimensionality. |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 267 | const char* c = descriptor; |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 268 | size_t dim = 0; |
| 269 | while (*c == '[') { |
| 270 | dim++; |
| 271 | c++; |
| 272 | } |
| 273 | |
| 274 | // Reference or primitive? |
| 275 | if (*c == 'L') { |
| 276 | // "[[La/b/C;" -> "a.b.C[][]". |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 277 | c++; // Skip the 'L'. |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 278 | } else { |
| 279 | // "[[B" -> "byte[][]". |
| 280 | // To make life easier, we make primitives look like unqualified |
| 281 | // reference types. |
| 282 | switch (*c) { |
| 283 | case 'B': c = "byte;"; break; |
| 284 | case 'C': c = "char;"; break; |
| 285 | case 'D': c = "double;"; break; |
| 286 | case 'F': c = "float;"; break; |
| 287 | case 'I': c = "int;"; break; |
| 288 | case 'J': c = "long;"; break; |
| 289 | case 'S': c = "short;"; break; |
| 290 | case 'Z': c = "boolean;"; break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 291 | case 'V': c = "void;"; break; // Used when decoding return types. |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 292 | default: return descriptor; |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
| 296 | // At this point, 'c' is a string of the form "fully/qualified/Type;" |
| 297 | // or "primitive;". Rewrite the type with '.' instead of '/': |
| 298 | std::string result; |
| 299 | const char* p = c; |
| 300 | while (*p != ';') { |
| 301 | char ch = *p++; |
| 302 | if (ch == '/') { |
| 303 | ch = '.'; |
| 304 | } |
| 305 | result.push_back(ch); |
| 306 | } |
| 307 | // ...and replace the semicolon with 'dim' "[]" pairs: |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 308 | for (size_t i = 0; i < dim; ++i) { |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 309 | result += "[]"; |
| 310 | } |
| 311 | return result; |
| 312 | } |
| 313 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 314 | std::string PrettyField(mirror::ArtField* f, bool with_type) { |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 315 | if (f == NULL) { |
| 316 | return "null"; |
| 317 | } |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 318 | std::string result; |
| 319 | if (with_type) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 320 | result += PrettyDescriptor(f->GetTypeDescriptor()); |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 321 | result += ' '; |
| 322 | } |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 323 | std::string temp; |
| 324 | result += PrettyDescriptor(f->GetDeclaringClass()->GetDescriptor(&temp)); |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 325 | result += '.'; |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 326 | result += f->GetName(); |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 327 | return result; |
| 328 | } |
| 329 | |
Brian Carlstrom | 6f29d0e | 2012-05-11 15:50:29 -0700 | [diff] [blame] | 330 | std::string PrettyField(uint32_t field_idx, const DexFile& dex_file, bool with_type) { |
Elliott Hughes | 60641a7 | 2013-02-27 14:36:16 -0800 | [diff] [blame] | 331 | if (field_idx >= dex_file.NumFieldIds()) { |
| 332 | return StringPrintf("<<invalid-field-idx-%d>>", field_idx); |
| 333 | } |
Brian Carlstrom | 6f29d0e | 2012-05-11 15:50:29 -0700 | [diff] [blame] | 334 | const DexFile::FieldId& field_id = dex_file.GetFieldId(field_idx); |
| 335 | std::string result; |
| 336 | if (with_type) { |
| 337 | result += dex_file.GetFieldTypeDescriptor(field_id); |
| 338 | result += ' '; |
| 339 | } |
| 340 | result += PrettyDescriptor(dex_file.GetFieldDeclaringClassDescriptor(field_id)); |
| 341 | result += '.'; |
| 342 | result += dex_file.GetFieldName(field_id); |
| 343 | return result; |
| 344 | } |
| 345 | |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 346 | std::string PrettyType(uint32_t type_idx, const DexFile& dex_file) { |
Elliott Hughes | 60641a7 | 2013-02-27 14:36:16 -0800 | [diff] [blame] | 347 | if (type_idx >= dex_file.NumTypeIds()) { |
| 348 | return StringPrintf("<<invalid-type-idx-%d>>", type_idx); |
| 349 | } |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 350 | const DexFile::TypeId& type_id = dex_file.GetTypeId(type_idx); |
Mathieu Chartier | 4c70d77 | 2012-09-10 14:08:32 -0700 | [diff] [blame] | 351 | return PrettyDescriptor(dex_file.GetTypeDescriptor(type_id)); |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Elliott Hughes | 9058f2b | 2012-03-22 18:06:48 -0700 | [diff] [blame] | 354 | std::string PrettyArguments(const char* signature) { |
| 355 | std::string result; |
| 356 | result += '('; |
| 357 | CHECK_EQ(*signature, '('); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 358 | ++signature; // Skip the '('. |
Elliott Hughes | 9058f2b | 2012-03-22 18:06:48 -0700 | [diff] [blame] | 359 | while (*signature != ')') { |
| 360 | size_t argument_length = 0; |
| 361 | while (signature[argument_length] == '[') { |
| 362 | ++argument_length; |
| 363 | } |
| 364 | if (signature[argument_length] == 'L') { |
| 365 | argument_length = (strchr(signature, ';') - signature + 1); |
| 366 | } else { |
| 367 | ++argument_length; |
| 368 | } |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 369 | { |
| 370 | std::string argument_descriptor(signature, argument_length); |
| 371 | result += PrettyDescriptor(argument_descriptor.c_str()); |
| 372 | } |
Elliott Hughes | 9058f2b | 2012-03-22 18:06:48 -0700 | [diff] [blame] | 373 | if (signature[argument_length] != ')') { |
| 374 | result += ", "; |
| 375 | } |
| 376 | signature += argument_length; |
| 377 | } |
| 378 | CHECK_EQ(*signature, ')'); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 379 | ++signature; // Skip the ')'. |
Elliott Hughes | 9058f2b | 2012-03-22 18:06:48 -0700 | [diff] [blame] | 380 | result += ')'; |
| 381 | return result; |
| 382 | } |
| 383 | |
| 384 | std::string PrettyReturnType(const char* signature) { |
| 385 | const char* return_type = strchr(signature, ')'); |
| 386 | CHECK(return_type != NULL); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 387 | ++return_type; // Skip ')'. |
Elliott Hughes | 9058f2b | 2012-03-22 18:06:48 -0700 | [diff] [blame] | 388 | return PrettyDescriptor(return_type); |
| 389 | } |
| 390 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 391 | std::string PrettyMethod(mirror::ArtMethod* m, bool with_signature) { |
Ian Rogers | 16ce092 | 2014-01-10 14:59:36 -0800 | [diff] [blame] | 392 | if (m == nullptr) { |
Elliott Hughes | a0b8feb | 2011-08-20 09:50:55 -0700 | [diff] [blame] | 393 | return "null"; |
| 394 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 395 | std::string result(PrettyDescriptor(m->GetDeclaringClassDescriptor())); |
Elliott Hughes | a0b8feb | 2011-08-20 09:50:55 -0700 | [diff] [blame] | 396 | result += '.'; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 397 | result += m->GetName(); |
Ian Rogers | 16ce092 | 2014-01-10 14:59:36 -0800 | [diff] [blame] | 398 | if (UNLIKELY(m->IsFastNative())) { |
| 399 | result += "!"; |
| 400 | } |
Elliott Hughes | a0b8feb | 2011-08-20 09:50:55 -0700 | [diff] [blame] | 401 | if (with_signature) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 402 | const Signature signature = m->GetSignature(); |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 403 | std::string sig_as_string(signature.ToString()); |
| 404 | if (signature == Signature::NoSignature()) { |
| 405 | return result + sig_as_string; |
Elliott Hughes | f8c1193 | 2012-03-23 19:53:59 -0700 | [diff] [blame] | 406 | } |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 407 | result = PrettyReturnType(sig_as_string.c_str()) + " " + result + |
| 408 | PrettyArguments(sig_as_string.c_str()); |
Elliott Hughes | a0b8feb | 2011-08-20 09:50:55 -0700 | [diff] [blame] | 409 | } |
| 410 | return result; |
| 411 | } |
| 412 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 413 | std::string PrettyMethod(uint32_t method_idx, const DexFile& dex_file, bool with_signature) { |
Elliott Hughes | 60641a7 | 2013-02-27 14:36:16 -0800 | [diff] [blame] | 414 | if (method_idx >= dex_file.NumMethodIds()) { |
| 415 | return StringPrintf("<<invalid-method-idx-%d>>", method_idx); |
| 416 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 417 | const DexFile::MethodId& method_id = dex_file.GetMethodId(method_idx); |
| 418 | std::string result(PrettyDescriptor(dex_file.GetMethodDeclaringClassDescriptor(method_id))); |
| 419 | result += '.'; |
| 420 | result += dex_file.GetMethodName(method_id); |
| 421 | if (with_signature) { |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 422 | const Signature signature = dex_file.GetMethodSignature(method_id); |
| 423 | std::string sig_as_string(signature.ToString()); |
| 424 | if (signature == Signature::NoSignature()) { |
| 425 | return result + sig_as_string; |
Elliott Hughes | f8c1193 | 2012-03-23 19:53:59 -0700 | [diff] [blame] | 426 | } |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 427 | result = PrettyReturnType(sig_as_string.c_str()) + " " + result + |
| 428 | PrettyArguments(sig_as_string.c_str()); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 429 | } |
| 430 | return result; |
| 431 | } |
| 432 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 433 | std::string PrettyTypeOf(mirror::Object* obj) { |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 434 | if (obj == NULL) { |
| 435 | return "null"; |
| 436 | } |
| 437 | if (obj->GetClass() == NULL) { |
| 438 | return "(raw)"; |
| 439 | } |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 440 | std::string temp; |
| 441 | std::string result(PrettyDescriptor(obj->GetClass()->GetDescriptor(&temp))); |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 442 | if (obj->IsClass()) { |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 443 | result += "<" + PrettyDescriptor(obj->AsClass()->GetDescriptor(&temp)) + ">"; |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 444 | } |
| 445 | return result; |
| 446 | } |
| 447 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 448 | std::string PrettyClass(mirror::Class* c) { |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 449 | if (c == NULL) { |
| 450 | return "null"; |
| 451 | } |
| 452 | std::string result; |
| 453 | result += "java.lang.Class<"; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 454 | result += PrettyDescriptor(c); |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 455 | result += ">"; |
| 456 | return result; |
| 457 | } |
| 458 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 459 | std::string PrettyClassAndClassLoader(mirror::Class* c) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 460 | if (c == NULL) { |
| 461 | return "null"; |
| 462 | } |
| 463 | std::string result; |
| 464 | result += "java.lang.Class<"; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 465 | result += PrettyDescriptor(c); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 466 | result += ","; |
| 467 | result += PrettyTypeOf(c->GetClassLoader()); |
| 468 | // TODO: add an identifying hash value for the loader |
| 469 | result += ">"; |
| 470 | return result; |
| 471 | } |
| 472 | |
Andreas Gampe | c0d8229 | 2014-09-23 10:38:30 -0700 | [diff] [blame] | 473 | std::string PrettyJavaAccessFlags(uint32_t access_flags) { |
| 474 | std::string result; |
| 475 | if ((access_flags & kAccPublic) != 0) { |
| 476 | result += "public "; |
| 477 | } |
| 478 | if ((access_flags & kAccProtected) != 0) { |
| 479 | result += "protected "; |
| 480 | } |
| 481 | if ((access_flags & kAccPrivate) != 0) { |
| 482 | result += "private "; |
| 483 | } |
| 484 | if ((access_flags & kAccFinal) != 0) { |
| 485 | result += "final "; |
| 486 | } |
| 487 | if ((access_flags & kAccStatic) != 0) { |
| 488 | result += "static "; |
| 489 | } |
| 490 | if ((access_flags & kAccTransient) != 0) { |
| 491 | result += "transient "; |
| 492 | } |
| 493 | if ((access_flags & kAccVolatile) != 0) { |
| 494 | result += "volatile "; |
| 495 | } |
| 496 | if ((access_flags & kAccSynchronized) != 0) { |
| 497 | result += "synchronized "; |
| 498 | } |
| 499 | return result; |
| 500 | } |
| 501 | |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 502 | std::string PrettySize(int64_t byte_count) { |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 503 | // The byte thresholds at which we display amounts. A byte count is displayed |
| 504 | // in unit U when kUnitThresholds[U] <= bytes < kUnitThresholds[U+1]. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 505 | static const int64_t kUnitThresholds[] = { |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 506 | 0, // B up to... |
| 507 | 3*1024, // KB up to... |
| 508 | 2*1024*1024, // MB up to... |
| 509 | 1024*1024*1024 // GB from here. |
| 510 | }; |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 511 | static const int64_t kBytesPerUnit[] = { 1, KB, MB, GB }; |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 512 | static const char* const kUnitStrings[] = { "B", "KB", "MB", "GB" }; |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 513 | const char* negative_str = ""; |
| 514 | if (byte_count < 0) { |
| 515 | negative_str = "-"; |
| 516 | byte_count = -byte_count; |
| 517 | } |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 518 | int i = arraysize(kUnitThresholds); |
| 519 | while (--i > 0) { |
| 520 | if (byte_count >= kUnitThresholds[i]) { |
| 521 | break; |
| 522 | } |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 523 | } |
Brian Carlstrom | 474cc79 | 2014-03-07 14:18:15 -0800 | [diff] [blame] | 524 | return StringPrintf("%s%" PRId64 "%s", |
| 525 | negative_str, byte_count / kBytesPerUnit[i], kUnitStrings[i]); |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 526 | } |
| 527 | |
Mathieu Chartier | f5997b4 | 2014-06-20 10:37:54 -0700 | [diff] [blame] | 528 | std::string PrettyDuration(uint64_t nano_duration, size_t max_fraction_digits) { |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 529 | if (nano_duration == 0) { |
| 530 | return "0"; |
| 531 | } else { |
Mathieu Chartier | f5997b4 | 2014-06-20 10:37:54 -0700 | [diff] [blame] | 532 | return FormatDuration(nano_duration, GetAppropriateTimeUnit(nano_duration), |
| 533 | max_fraction_digits); |
Mathieu Chartier | 0325e62 | 2012-09-05 14:22:51 -0700 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | |
| 537 | TimeUnit GetAppropriateTimeUnit(uint64_t nano_duration) { |
| 538 | const uint64_t one_sec = 1000 * 1000 * 1000; |
| 539 | const uint64_t one_ms = 1000 * 1000; |
| 540 | const uint64_t one_us = 1000; |
| 541 | if (nano_duration >= one_sec) { |
| 542 | return kTimeUnitSecond; |
| 543 | } else if (nano_duration >= one_ms) { |
| 544 | return kTimeUnitMillisecond; |
| 545 | } else if (nano_duration >= one_us) { |
| 546 | return kTimeUnitMicrosecond; |
| 547 | } else { |
| 548 | return kTimeUnitNanosecond; |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | uint64_t GetNsToTimeUnitDivisor(TimeUnit time_unit) { |
| 553 | const uint64_t one_sec = 1000 * 1000 * 1000; |
| 554 | const uint64_t one_ms = 1000 * 1000; |
| 555 | const uint64_t one_us = 1000; |
| 556 | |
| 557 | switch (time_unit) { |
| 558 | case kTimeUnitSecond: |
| 559 | return one_sec; |
| 560 | case kTimeUnitMillisecond: |
| 561 | return one_ms; |
| 562 | case kTimeUnitMicrosecond: |
| 563 | return one_us; |
| 564 | case kTimeUnitNanosecond: |
| 565 | return 1; |
| 566 | } |
| 567 | return 0; |
| 568 | } |
| 569 | |
Mathieu Chartier | f5997b4 | 2014-06-20 10:37:54 -0700 | [diff] [blame] | 570 | std::string FormatDuration(uint64_t nano_duration, TimeUnit time_unit, |
| 571 | size_t max_fraction_digits) { |
| 572 | const char* unit = nullptr; |
Mathieu Chartier | 0325e62 | 2012-09-05 14:22:51 -0700 | [diff] [blame] | 573 | uint64_t divisor = GetNsToTimeUnitDivisor(time_unit); |
Mathieu Chartier | 0325e62 | 2012-09-05 14:22:51 -0700 | [diff] [blame] | 574 | switch (time_unit) { |
| 575 | case kTimeUnitSecond: |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 576 | unit = "s"; |
Mathieu Chartier | 0325e62 | 2012-09-05 14:22:51 -0700 | [diff] [blame] | 577 | break; |
| 578 | case kTimeUnitMillisecond: |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 579 | unit = "ms"; |
Mathieu Chartier | 0325e62 | 2012-09-05 14:22:51 -0700 | [diff] [blame] | 580 | break; |
| 581 | case kTimeUnitMicrosecond: |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 582 | unit = "us"; |
Mathieu Chartier | 0325e62 | 2012-09-05 14:22:51 -0700 | [diff] [blame] | 583 | break; |
| 584 | case kTimeUnitNanosecond: |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 585 | unit = "ns"; |
Mathieu Chartier | 0325e62 | 2012-09-05 14:22:51 -0700 | [diff] [blame] | 586 | break; |
| 587 | } |
Mathieu Chartier | f5997b4 | 2014-06-20 10:37:54 -0700 | [diff] [blame] | 588 | const uint64_t whole_part = nano_duration / divisor; |
Mathieu Chartier | 0325e62 | 2012-09-05 14:22:51 -0700 | [diff] [blame] | 589 | uint64_t fractional_part = nano_duration % divisor; |
| 590 | if (fractional_part == 0) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 591 | return StringPrintf("%" PRIu64 "%s", whole_part, unit); |
Mathieu Chartier | 0325e62 | 2012-09-05 14:22:51 -0700 | [diff] [blame] | 592 | } else { |
Mathieu Chartier | f5997b4 | 2014-06-20 10:37:54 -0700 | [diff] [blame] | 593 | static constexpr size_t kMaxDigits = 30; |
Andreas Gampe | 829b4ba | 2014-06-26 13:49:36 -0700 | [diff] [blame] | 594 | size_t avail_digits = kMaxDigits; |
Mathieu Chartier | f5997b4 | 2014-06-20 10:37:54 -0700 | [diff] [blame] | 595 | char fraction_buffer[kMaxDigits]; |
| 596 | char* ptr = fraction_buffer; |
| 597 | uint64_t multiplier = 10; |
| 598 | // This infinite loops if fractional part is 0. |
Andreas Gampe | 829b4ba | 2014-06-26 13:49:36 -0700 | [diff] [blame] | 599 | while (avail_digits > 1 && fractional_part * multiplier < divisor) { |
Mathieu Chartier | f5997b4 | 2014-06-20 10:37:54 -0700 | [diff] [blame] | 600 | multiplier *= 10; |
| 601 | *ptr++ = '0'; |
Andreas Gampe | 829b4ba | 2014-06-26 13:49:36 -0700 | [diff] [blame] | 602 | avail_digits--; |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 603 | } |
Andreas Gampe | 829b4ba | 2014-06-26 13:49:36 -0700 | [diff] [blame] | 604 | snprintf(ptr, avail_digits, "%" PRIu64, fractional_part); |
Mathieu Chartier | f5997b4 | 2014-06-20 10:37:54 -0700 | [diff] [blame] | 605 | fraction_buffer[std::min(kMaxDigits - 1, max_fraction_digits)] = '\0'; |
| 606 | return StringPrintf("%" PRIu64 ".%s%s", whole_part, fraction_buffer, unit); |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 610 | std::string PrintableChar(uint16_t ch) { |
| 611 | std::string result; |
| 612 | result += '\''; |
| 613 | if (NeedsEscaping(ch)) { |
| 614 | StringAppendF(&result, "\\u%04x", ch); |
| 615 | } else { |
| 616 | result += ch; |
| 617 | } |
| 618 | result += '\''; |
| 619 | return result; |
| 620 | } |
| 621 | |
Ian Rogers | 68b5685 | 2014-08-29 20:19:11 -0700 | [diff] [blame] | 622 | std::string PrintableString(const char* utf) { |
Elliott Hughes | 82914b6 | 2012-04-09 15:56:29 -0700 | [diff] [blame] | 623 | std::string result; |
| 624 | result += '"'; |
Ian Rogers | 68b5685 | 2014-08-29 20:19:11 -0700 | [diff] [blame] | 625 | const char* p = utf; |
Elliott Hughes | 82914b6 | 2012-04-09 15:56:29 -0700 | [diff] [blame] | 626 | size_t char_count = CountModifiedUtf8Chars(p); |
| 627 | for (size_t i = 0; i < char_count; ++i) { |
| 628 | uint16_t ch = GetUtf16FromUtf8(&p); |
| 629 | if (ch == '\\') { |
| 630 | result += "\\\\"; |
| 631 | } else if (ch == '\n') { |
| 632 | result += "\\n"; |
| 633 | } else if (ch == '\r') { |
| 634 | result += "\\r"; |
| 635 | } else if (ch == '\t') { |
| 636 | result += "\\t"; |
| 637 | } else if (NeedsEscaping(ch)) { |
| 638 | StringAppendF(&result, "\\u%04x", ch); |
| 639 | } else { |
| 640 | result += ch; |
| 641 | } |
| 642 | } |
| 643 | result += '"'; |
| 644 | return result; |
| 645 | } |
| 646 | |
Elliott Hughes | d8c00d0 | 2012-01-30 14:08:31 -0800 | [diff] [blame] | 647 | // See http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp615 for the full rules. |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 648 | std::string MangleForJni(const std::string& s) { |
| 649 | std::string result; |
| 650 | size_t char_count = CountModifiedUtf8Chars(s.c_str()); |
| 651 | const char* cp = &s[0]; |
| 652 | for (size_t i = 0; i < char_count; ++i) { |
| 653 | uint16_t ch = GetUtf16FromUtf8(&cp); |
Elliott Hughes | d8c00d0 | 2012-01-30 14:08:31 -0800 | [diff] [blame] | 654 | if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) { |
| 655 | result.push_back(ch); |
| 656 | } else if (ch == '.' || ch == '/') { |
| 657 | result += "_"; |
| 658 | } else if (ch == '_') { |
| 659 | result += "_1"; |
| 660 | } else if (ch == ';') { |
| 661 | result += "_2"; |
| 662 | } else if (ch == '[') { |
| 663 | result += "_3"; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 664 | } else { |
Elliott Hughes | d8c00d0 | 2012-01-30 14:08:31 -0800 | [diff] [blame] | 665 | StringAppendF(&result, "_0%04x", ch); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | return result; |
| 669 | } |
| 670 | |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 671 | std::string DotToDescriptor(const char* class_name) { |
| 672 | std::string descriptor(class_name); |
| 673 | std::replace(descriptor.begin(), descriptor.end(), '.', '/'); |
| 674 | if (descriptor.length() > 0 && descriptor[0] != '[') { |
| 675 | descriptor = "L" + descriptor + ";"; |
| 676 | } |
| 677 | return descriptor; |
| 678 | } |
| 679 | |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 680 | std::string DescriptorToDot(const char* descriptor) { |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 681 | size_t length = strlen(descriptor); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 682 | if (length > 1) { |
| 683 | if (descriptor[0] == 'L' && descriptor[length - 1] == ';') { |
| 684 | // Descriptors have the leading 'L' and trailing ';' stripped. |
| 685 | std::string result(descriptor + 1, length - 2); |
| 686 | std::replace(result.begin(), result.end(), '/', '.'); |
| 687 | return result; |
| 688 | } else { |
| 689 | // For arrays the 'L' and ';' remain intact. |
| 690 | std::string result(descriptor); |
| 691 | std::replace(result.begin(), result.end(), '/', '.'); |
| 692 | return result; |
| 693 | } |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 694 | } |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 695 | // Do nothing for non-class/array descriptors. |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 696 | return descriptor; |
Elliott Hughes | 91bf6cd | 2012-02-14 17:27:48 -0800 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | std::string DescriptorToName(const char* descriptor) { |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 700 | size_t length = strlen(descriptor); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 701 | if (descriptor[0] == 'L' && descriptor[length - 1] == ';') { |
| 702 | std::string result(descriptor + 1, length - 2); |
| 703 | return result; |
| 704 | } |
| 705 | return descriptor; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 708 | std::string JniShortName(mirror::ArtMethod* m) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 709 | std::string class_name(m->GetDeclaringClassDescriptor()); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 710 | // Remove the leading 'L' and trailing ';'... |
Elliott Hughes | f5a7a47 | 2011-10-07 14:31:02 -0700 | [diff] [blame] | 711 | CHECK_EQ(class_name[0], 'L') << class_name; |
| 712 | CHECK_EQ(class_name[class_name.size() - 1], ';') << class_name; |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 713 | class_name.erase(0, 1); |
| 714 | class_name.erase(class_name.size() - 1, 1); |
| 715 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 716 | std::string method_name(m->GetName()); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 717 | |
| 718 | std::string short_name; |
| 719 | short_name += "Java_"; |
| 720 | short_name += MangleForJni(class_name); |
| 721 | short_name += "_"; |
| 722 | short_name += MangleForJni(method_name); |
| 723 | return short_name; |
| 724 | } |
| 725 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 726 | std::string JniLongName(mirror::ArtMethod* m) { |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 727 | std::string long_name; |
| 728 | long_name += JniShortName(m); |
| 729 | long_name += "__"; |
| 730 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 731 | std::string signature(m->GetSignature().ToString()); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 732 | signature.erase(0, 1); |
| 733 | signature.erase(signature.begin() + signature.find(')'), signature.end()); |
| 734 | |
| 735 | long_name += MangleForJni(signature); |
| 736 | |
| 737 | return long_name; |
| 738 | } |
| 739 | |
jeffhao | 10037c8 | 2012-01-23 15:06:23 -0800 | [diff] [blame] | 740 | // Helper for IsValidPartOfMemberNameUtf8(), a bit vector indicating valid low ascii. |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 741 | uint32_t DEX_MEMBER_VALID_LOW_ASCII[4] = { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 742 | 0x00000000, // 00..1f low control characters; nothing valid |
| 743 | 0x03ff2010, // 20..3f digits and symbols; valid: '0'..'9', '$', '-' |
| 744 | 0x87fffffe, // 40..5f uppercase etc.; valid: 'A'..'Z', '_' |
| 745 | 0x07fffffe // 60..7f lowercase etc.; valid: 'a'..'z' |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 746 | }; |
| 747 | |
jeffhao | 10037c8 | 2012-01-23 15:06:23 -0800 | [diff] [blame] | 748 | // Helper for IsValidPartOfMemberNameUtf8(); do not call directly. |
| 749 | bool IsValidPartOfMemberNameUtf8Slow(const char** pUtf8Ptr) { |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 750 | /* |
| 751 | * It's a multibyte encoded character. Decode it and analyze. We |
| 752 | * accept anything that isn't (a) an improperly encoded low value, |
| 753 | * (b) an improper surrogate pair, (c) an encoded '\0', (d) a high |
| 754 | * control character, or (e) a high space, layout, or special |
| 755 | * character (U+00a0, U+2000..U+200f, U+2028..U+202f, |
| 756 | * U+fff0..U+ffff). This is all specified in the dex format |
| 757 | * document. |
| 758 | */ |
| 759 | |
| 760 | uint16_t utf16 = GetUtf16FromUtf8(pUtf8Ptr); |
| 761 | |
| 762 | // Perform follow-up tests based on the high 8 bits. |
| 763 | switch (utf16 >> 8) { |
| 764 | case 0x00: |
| 765 | // It's only valid if it's above the ISO-8859-1 high space (0xa0). |
| 766 | return (utf16 > 0x00a0); |
| 767 | case 0xd8: |
| 768 | case 0xd9: |
| 769 | case 0xda: |
| 770 | case 0xdb: |
| 771 | // It's a leading surrogate. Check to see that a trailing |
| 772 | // surrogate follows. |
| 773 | utf16 = GetUtf16FromUtf8(pUtf8Ptr); |
| 774 | return (utf16 >= 0xdc00) && (utf16 <= 0xdfff); |
| 775 | case 0xdc: |
| 776 | case 0xdd: |
| 777 | case 0xde: |
| 778 | case 0xdf: |
| 779 | // It's a trailing surrogate, which is not valid at this point. |
| 780 | return false; |
| 781 | case 0x20: |
| 782 | case 0xff: |
| 783 | // It's in the range that has spaces, controls, and specials. |
| 784 | switch (utf16 & 0xfff8) { |
| 785 | case 0x2000: |
| 786 | case 0x2008: |
| 787 | case 0x2028: |
| 788 | case 0xfff0: |
| 789 | case 0xfff8: |
| 790 | return false; |
| 791 | } |
| 792 | break; |
| 793 | } |
| 794 | return true; |
| 795 | } |
| 796 | |
| 797 | /* Return whether the pointed-at modified-UTF-8 encoded character is |
| 798 | * valid as part of a member name, updating the pointer to point past |
| 799 | * the consumed character. This will consume two encoded UTF-16 code |
| 800 | * points if the character is encoded as a surrogate pair. Also, if |
| 801 | * this function returns false, then the given pointer may only have |
| 802 | * been partially advanced. |
| 803 | */ |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 804 | static bool IsValidPartOfMemberNameUtf8(const char** pUtf8Ptr) { |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 805 | uint8_t c = (uint8_t) **pUtf8Ptr; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 806 | if (LIKELY(c <= 0x7f)) { |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 807 | // It's low-ascii, so check the table. |
| 808 | uint32_t wordIdx = c >> 5; |
| 809 | uint32_t bitIdx = c & 0x1f; |
| 810 | (*pUtf8Ptr)++; |
| 811 | return (DEX_MEMBER_VALID_LOW_ASCII[wordIdx] & (1 << bitIdx)) != 0; |
| 812 | } |
| 813 | |
| 814 | // It's a multibyte encoded character. Call a non-inline function |
| 815 | // for the heavy lifting. |
jeffhao | 10037c8 | 2012-01-23 15:06:23 -0800 | [diff] [blame] | 816 | return IsValidPartOfMemberNameUtf8Slow(pUtf8Ptr); |
| 817 | } |
| 818 | |
| 819 | bool IsValidMemberName(const char* s) { |
| 820 | bool angle_name = false; |
| 821 | |
Elliott Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 822 | switch (*s) { |
jeffhao | 10037c8 | 2012-01-23 15:06:23 -0800 | [diff] [blame] | 823 | case '\0': |
| 824 | // The empty string is not a valid name. |
| 825 | return false; |
| 826 | case '<': |
| 827 | angle_name = true; |
| 828 | s++; |
| 829 | break; |
| 830 | } |
| 831 | |
| 832 | while (true) { |
| 833 | switch (*s) { |
| 834 | case '\0': |
| 835 | return !angle_name; |
| 836 | case '>': |
| 837 | return angle_name && s[1] == '\0'; |
| 838 | } |
| 839 | |
| 840 | if (!IsValidPartOfMemberNameUtf8(&s)) { |
| 841 | return false; |
| 842 | } |
| 843 | } |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Elliott Hughes | 906e685 | 2011-10-28 14:52:10 -0700 | [diff] [blame] | 846 | enum ClassNameType { kName, kDescriptor }; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 847 | template<ClassNameType kType, char kSeparator> |
| 848 | static bool IsValidClassName(const char* s) { |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 849 | int arrayCount = 0; |
| 850 | while (*s == '[') { |
| 851 | arrayCount++; |
| 852 | s++; |
| 853 | } |
| 854 | |
| 855 | if (arrayCount > 255) { |
| 856 | // Arrays may have no more than 255 dimensions. |
| 857 | return false; |
| 858 | } |
| 859 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 860 | ClassNameType type = kType; |
| 861 | if (type != kDescriptor && arrayCount != 0) { |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 862 | /* |
| 863 | * If we're looking at an array of some sort, then it doesn't |
| 864 | * matter if what is being asked for is a class name; the |
| 865 | * format looks the same as a type descriptor in that case, so |
| 866 | * treat it as such. |
| 867 | */ |
Elliott Hughes | 906e685 | 2011-10-28 14:52:10 -0700 | [diff] [blame] | 868 | type = kDescriptor; |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Elliott Hughes | 906e685 | 2011-10-28 14:52:10 -0700 | [diff] [blame] | 871 | if (type == kDescriptor) { |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 872 | /* |
| 873 | * We are looking for a descriptor. Either validate it as a |
| 874 | * single-character primitive type, or continue on to check the |
| 875 | * embedded class name (bracketed by "L" and ";"). |
| 876 | */ |
| 877 | switch (*(s++)) { |
| 878 | case 'B': |
| 879 | case 'C': |
| 880 | case 'D': |
| 881 | case 'F': |
| 882 | case 'I': |
| 883 | case 'J': |
| 884 | case 'S': |
| 885 | case 'Z': |
| 886 | // These are all single-character descriptors for primitive types. |
| 887 | return (*s == '\0'); |
| 888 | case 'V': |
| 889 | // Non-array void is valid, but you can't have an array of void. |
| 890 | return (arrayCount == 0) && (*s == '\0'); |
| 891 | case 'L': |
| 892 | // Class name: Break out and continue below. |
| 893 | break; |
| 894 | default: |
| 895 | // Oddball descriptor character. |
| 896 | return false; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | /* |
| 901 | * We just consumed the 'L' that introduces a class name as part |
| 902 | * of a type descriptor, or we are looking for an unadorned class |
| 903 | * name. |
| 904 | */ |
| 905 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 906 | bool sepOrFirst = true; // first character or just encountered a separator. |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 907 | for (;;) { |
| 908 | uint8_t c = (uint8_t) *s; |
| 909 | switch (c) { |
| 910 | case '\0': |
| 911 | /* |
| 912 | * Premature end for a type descriptor, but valid for |
| 913 | * a class name as long as we haven't encountered an |
| 914 | * empty component (including the degenerate case of |
| 915 | * the empty string ""). |
| 916 | */ |
Elliott Hughes | 906e685 | 2011-10-28 14:52:10 -0700 | [diff] [blame] | 917 | return (type == kName) && !sepOrFirst; |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 918 | case ';': |
| 919 | /* |
| 920 | * Invalid character for a class name, but the |
| 921 | * legitimate end of a type descriptor. In the latter |
| 922 | * case, make sure that this is the end of the string |
| 923 | * and that it doesn't end with an empty component |
| 924 | * (including the degenerate case of "L;"). |
| 925 | */ |
Elliott Hughes | 906e685 | 2011-10-28 14:52:10 -0700 | [diff] [blame] | 926 | return (type == kDescriptor) && !sepOrFirst && (s[1] == '\0'); |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 927 | case '/': |
| 928 | case '.': |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 929 | if (c != kSeparator) { |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 930 | // The wrong separator character. |
| 931 | return false; |
| 932 | } |
| 933 | if (sepOrFirst) { |
| 934 | // Separator at start or two separators in a row. |
| 935 | return false; |
| 936 | } |
| 937 | sepOrFirst = true; |
| 938 | s++; |
| 939 | break; |
| 940 | default: |
jeffhao | 10037c8 | 2012-01-23 15:06:23 -0800 | [diff] [blame] | 941 | if (!IsValidPartOfMemberNameUtf8(&s)) { |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 942 | return false; |
| 943 | } |
| 944 | sepOrFirst = false; |
| 945 | break; |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | |
Elliott Hughes | 906e685 | 2011-10-28 14:52:10 -0700 | [diff] [blame] | 950 | bool IsValidBinaryClassName(const char* s) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 951 | return IsValidClassName<kName, '.'>(s); |
Elliott Hughes | 906e685 | 2011-10-28 14:52:10 -0700 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | bool IsValidJniClassName(const char* s) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 955 | return IsValidClassName<kName, '/'>(s); |
Elliott Hughes | 906e685 | 2011-10-28 14:52:10 -0700 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | bool IsValidDescriptor(const char* s) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 959 | return IsValidClassName<kDescriptor, '/'>(s); |
Elliott Hughes | 906e685 | 2011-10-28 14:52:10 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 962 | void Split(const std::string& s, char separator, std::vector<std::string>* result) { |
Elliott Hughes | 3402380 | 2011-08-30 12:06:17 -0700 | [diff] [blame] | 963 | const char* p = s.data(); |
| 964 | const char* end = p + s.size(); |
| 965 | while (p != end) { |
Elliott Hughes | 48436bb | 2012-02-07 15:23:28 -0800 | [diff] [blame] | 966 | if (*p == separator) { |
Elliott Hughes | 3402380 | 2011-08-30 12:06:17 -0700 | [diff] [blame] | 967 | ++p; |
| 968 | } else { |
| 969 | const char* start = p; |
Elliott Hughes | 48436bb | 2012-02-07 15:23:28 -0800 | [diff] [blame] | 970 | while (++p != end && *p != separator) { |
| 971 | // Skip to the next occurrence of the separator. |
Elliott Hughes | 3402380 | 2011-08-30 12:06:17 -0700 | [diff] [blame] | 972 | } |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 973 | result->push_back(std::string(start, p - start)); |
Elliott Hughes | 3402380 | 2011-08-30 12:06:17 -0700 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | } |
| 977 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 978 | std::string Trim(const std::string& s) { |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 979 | std::string result; |
| 980 | unsigned int start_index = 0; |
| 981 | unsigned int end_index = s.size() - 1; |
| 982 | |
| 983 | // Skip initial whitespace. |
| 984 | while (start_index < s.size()) { |
| 985 | if (!isspace(s[start_index])) { |
| 986 | break; |
| 987 | } |
| 988 | start_index++; |
| 989 | } |
| 990 | |
| 991 | // Skip terminating whitespace. |
| 992 | while (end_index >= start_index) { |
| 993 | if (!isspace(s[end_index])) { |
| 994 | break; |
| 995 | } |
| 996 | end_index--; |
| 997 | } |
| 998 | |
| 999 | // All spaces, no beef. |
| 1000 | if (end_index < start_index) { |
| 1001 | return ""; |
| 1002 | } |
| 1003 | // Start_index is the first non-space, end_index is the last one. |
| 1004 | return s.substr(start_index, end_index - start_index + 1); |
| 1005 | } |
| 1006 | |
Elliott Hughes | 48436bb | 2012-02-07 15:23:28 -0800 | [diff] [blame] | 1007 | template <typename StringT> |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1008 | std::string Join(const std::vector<StringT>& strings, char separator) { |
Elliott Hughes | 48436bb | 2012-02-07 15:23:28 -0800 | [diff] [blame] | 1009 | if (strings.empty()) { |
| 1010 | return ""; |
| 1011 | } |
| 1012 | |
| 1013 | std::string result(strings[0]); |
| 1014 | for (size_t i = 1; i < strings.size(); ++i) { |
| 1015 | result += separator; |
| 1016 | result += strings[i]; |
| 1017 | } |
| 1018 | return result; |
| 1019 | } |
| 1020 | |
| 1021 | // Explicit instantiations. |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1022 | template std::string Join<std::string>(const std::vector<std::string>& strings, char separator); |
| 1023 | template std::string Join<const char*>(const std::vector<const char*>& strings, char separator); |
Elliott Hughes | 48436bb | 2012-02-07 15:23:28 -0800 | [diff] [blame] | 1024 | |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 1025 | bool StartsWith(const std::string& s, const char* prefix) { |
| 1026 | return s.compare(0, strlen(prefix), prefix) == 0; |
| 1027 | } |
| 1028 | |
Brian Carlstrom | 7a967b3 | 2012-03-28 15:23:10 -0700 | [diff] [blame] | 1029 | bool EndsWith(const std::string& s, const char* suffix) { |
| 1030 | size_t suffix_length = strlen(suffix); |
| 1031 | size_t string_length = s.size(); |
| 1032 | if (suffix_length > string_length) { |
| 1033 | return false; |
| 1034 | } |
| 1035 | size_t offset = string_length - suffix_length; |
| 1036 | return s.compare(offset, suffix_length, suffix) == 0; |
| 1037 | } |
| 1038 | |
Elliott Hughes | 22869a9 | 2012-03-27 14:08:24 -0700 | [diff] [blame] | 1039 | void SetThreadName(const char* thread_name) { |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 1040 | int hasAt = 0; |
| 1041 | int hasDot = 0; |
Elliott Hughes | 22869a9 | 2012-03-27 14:08:24 -0700 | [diff] [blame] | 1042 | const char* s = thread_name; |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 1043 | while (*s) { |
| 1044 | if (*s == '.') { |
| 1045 | hasDot = 1; |
| 1046 | } else if (*s == '@') { |
| 1047 | hasAt = 1; |
| 1048 | } |
| 1049 | s++; |
| 1050 | } |
Elliott Hughes | 22869a9 | 2012-03-27 14:08:24 -0700 | [diff] [blame] | 1051 | int len = s - thread_name; |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 1052 | if (len < 15 || hasAt || !hasDot) { |
Elliott Hughes | 22869a9 | 2012-03-27 14:08:24 -0700 | [diff] [blame] | 1053 | s = thread_name; |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 1054 | } else { |
Elliott Hughes | 22869a9 | 2012-03-27 14:08:24 -0700 | [diff] [blame] | 1055 | s = thread_name + len - 15; |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 1056 | } |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 1057 | #if defined(__linux__) |
Elliott Hughes | 7c6a61e | 2012-03-12 18:01:41 -0700 | [diff] [blame] | 1058 | // pthread_setname_np fails rather than truncating long strings. |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 1059 | char buf[16]; // MAX_TASK_COMM_LEN=16 is hard-coded in the kernel. |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 1060 | strncpy(buf, s, sizeof(buf)-1); |
| 1061 | buf[sizeof(buf)-1] = '\0'; |
| 1062 | errno = pthread_setname_np(pthread_self(), buf); |
| 1063 | if (errno != 0) { |
| 1064 | PLOG(WARNING) << "Unable to set the name of current thread to '" << buf << "'"; |
| 1065 | } |
Elliott Hughes | 0a18df8 | 2015-01-09 15:16:16 -0800 | [diff] [blame] | 1066 | #else // __APPLE__ |
Elliott Hughes | 22869a9 | 2012-03-27 14:08:24 -0700 | [diff] [blame] | 1067 | pthread_setname_np(thread_name); |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 1068 | #endif |
| 1069 | } |
| 1070 | |
Brian Carlstrom | 2921201 | 2013-09-12 22:18:30 -0700 | [diff] [blame] | 1071 | void GetTaskStats(pid_t tid, char* state, int* utime, int* stime, int* task_cpu) { |
| 1072 | *utime = *stime = *task_cpu = 0; |
Elliott Hughes | bfe487b | 2011-10-26 15:48:55 -0700 | [diff] [blame] | 1073 | std::string stats; |
Elliott Hughes | 8a31b50 | 2012-04-30 19:36:11 -0700 | [diff] [blame] | 1074 | if (!ReadFileToString(StringPrintf("/proc/self/task/%d/stat", tid), &stats)) { |
Elliott Hughes | bfe487b | 2011-10-26 15:48:55 -0700 | [diff] [blame] | 1075 | return; |
| 1076 | } |
| 1077 | // Skip the command, which may contain spaces. |
| 1078 | stats = stats.substr(stats.find(')') + 2); |
| 1079 | // Extract the three fields we care about. |
| 1080 | std::vector<std::string> fields; |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1081 | Split(stats, ' ', &fields); |
Brian Carlstrom | 2921201 | 2013-09-12 22:18:30 -0700 | [diff] [blame] | 1082 | *state = fields[0][0]; |
| 1083 | *utime = strtoull(fields[11].c_str(), NULL, 10); |
| 1084 | *stime = strtoull(fields[12].c_str(), NULL, 10); |
| 1085 | *task_cpu = strtoull(fields[36].c_str(), NULL, 10); |
Elliott Hughes | bfe487b | 2011-10-26 15:48:55 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1088 | std::string GetSchedulerGroupName(pid_t tid) { |
| 1089 | // /proc/<pid>/cgroup looks like this: |
| 1090 | // 2:devices:/ |
| 1091 | // 1:cpuacct,cpu:/ |
| 1092 | // We want the third field from the line whose second field contains the "cpu" token. |
| 1093 | std::string cgroup_file; |
| 1094 | if (!ReadFileToString(StringPrintf("/proc/self/task/%d/cgroup", tid), &cgroup_file)) { |
| 1095 | return ""; |
| 1096 | } |
| 1097 | std::vector<std::string> cgroup_lines; |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1098 | Split(cgroup_file, '\n', &cgroup_lines); |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1099 | for (size_t i = 0; i < cgroup_lines.size(); ++i) { |
| 1100 | std::vector<std::string> cgroup_fields; |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1101 | Split(cgroup_lines[i], ':', &cgroup_fields); |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1102 | std::vector<std::string> cgroups; |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1103 | Split(cgroup_fields[1], ',', &cgroups); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 1104 | for (size_t j = 0; j < cgroups.size(); ++j) { |
| 1105 | if (cgroups[j] == "cpu") { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 1106 | return cgroup_fields[2].substr(1); // Skip the leading slash. |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | return ""; |
| 1111 | } |
| 1112 | |
Andreas Gampe | 8e1cb91 | 2015-01-08 20:11:09 -0800 | [diff] [blame] | 1113 | #if defined(__linux__) |
Andreas Gampe | 00bd2da | 2015-01-09 15:05:46 -0800 | [diff] [blame] | 1114 | |
| 1115 | ALWAYS_INLINE |
| 1116 | static inline void WritePrefix(std::ostream* os, const char* prefix, bool odd) { |
| 1117 | if (prefix != nullptr) { |
| 1118 | *os << prefix; |
| 1119 | } |
| 1120 | *os << " "; |
| 1121 | if (!odd) { |
| 1122 | *os << " "; |
| 1123 | } |
| 1124 | } |
| 1125 | |
Andreas Gampe | 8e1cb91 | 2015-01-08 20:11:09 -0800 | [diff] [blame] | 1126 | static bool RunCommand(std::string cmd, std::ostream* os, const char* prefix) { |
| 1127 | FILE* stream = popen(cmd.c_str(), "r"); |
| 1128 | if (stream) { |
| 1129 | if (os != nullptr) { |
| 1130 | bool odd_line = true; // We indent them differently. |
Andreas Gampe | 00bd2da | 2015-01-09 15:05:46 -0800 | [diff] [blame] | 1131 | bool wrote_prefix = false; // Have we already written a prefix? |
Andreas Gampe | 8e1cb91 | 2015-01-08 20:11:09 -0800 | [diff] [blame] | 1132 | constexpr size_t kMaxBuffer = 128; // Relatively small buffer. Should be OK as we're on an |
| 1133 | // alt stack, but just to be sure... |
| 1134 | char buffer[kMaxBuffer]; |
| 1135 | while (!feof(stream)) { |
| 1136 | if (fgets(buffer, kMaxBuffer, stream) != nullptr) { |
| 1137 | // Split on newlines. |
| 1138 | char* tmp = buffer; |
| 1139 | for (;;) { |
| 1140 | char* new_line = strchr(tmp, '\n'); |
| 1141 | if (new_line == nullptr) { |
| 1142 | // Print the rest. |
| 1143 | if (*tmp != 0) { |
Andreas Gampe | 00bd2da | 2015-01-09 15:05:46 -0800 | [diff] [blame] | 1144 | if (!wrote_prefix) { |
| 1145 | WritePrefix(os, prefix, odd_line); |
Andreas Gampe | 8e1cb91 | 2015-01-08 20:11:09 -0800 | [diff] [blame] | 1146 | } |
Andreas Gampe | 00bd2da | 2015-01-09 15:05:46 -0800 | [diff] [blame] | 1147 | wrote_prefix = true; |
Andreas Gampe | 8e1cb91 | 2015-01-08 20:11:09 -0800 | [diff] [blame] | 1148 | *os << tmp; |
| 1149 | } |
| 1150 | break; |
| 1151 | } |
Andreas Gampe | 00bd2da | 2015-01-09 15:05:46 -0800 | [diff] [blame] | 1152 | if (!wrote_prefix) { |
| 1153 | WritePrefix(os, prefix, odd_line); |
Andreas Gampe | 8e1cb91 | 2015-01-08 20:11:09 -0800 | [diff] [blame] | 1154 | } |
| 1155 | char saved = *(new_line + 1); |
| 1156 | *(new_line + 1) = 0; |
| 1157 | *os << tmp; |
| 1158 | *(new_line + 1) = saved; |
| 1159 | tmp = new_line + 1; |
| 1160 | odd_line = !odd_line; |
Andreas Gampe | 00bd2da | 2015-01-09 15:05:46 -0800 | [diff] [blame] | 1161 | wrote_prefix = false; |
Andreas Gampe | 8e1cb91 | 2015-01-08 20:11:09 -0800 | [diff] [blame] | 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | pclose(stream); |
| 1167 | return true; |
| 1168 | } else { |
| 1169 | return false; |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | static void Addr2line(const std::string& map_src, uintptr_t offset, std::ostream& os, |
| 1174 | const char* prefix) { |
| 1175 | std::string cmdline(StringPrintf("addr2line --functions --inlines --demangle -e %s %zx", |
| 1176 | map_src.c_str(), offset)); |
| 1177 | RunCommand(cmdline.c_str(), &os, prefix); |
| 1178 | } |
| 1179 | #endif |
| 1180 | |
Christopher Ferris | a2cee18 | 2014-04-16 19:13:59 -0700 | [diff] [blame] | 1181 | void DumpNativeStack(std::ostream& os, pid_t tid, const char* prefix, |
Andreas Gampe | 628a61a | 2015-01-07 22:08:35 -0800 | [diff] [blame] | 1182 | mirror::ArtMethod* current_method, void* ucontext_ptr) { |
Ian Rogers | 83597d0 | 2014-11-20 10:29:00 -0800 | [diff] [blame] | 1183 | #if __linux__ |
Andreas Gampe | d757632 | 2014-10-24 22:13:45 -0700 | [diff] [blame] | 1184 | // b/18119146 |
| 1185 | if (RUNNING_ON_VALGRIND != 0) { |
| 1186 | return; |
| 1187 | } |
| 1188 | |
Ian Rogers | edfdaf3 | 2014-12-05 16:12:21 +0000 | [diff] [blame] | 1189 | #if !defined(HAVE_ANDROID_OS) |
| 1190 | if (GetTid() != tid) { |
| 1191 | // TODO: dumping of other threads is disabled to avoid crashes during stress testing. |
| 1192 | // b/15446488. |
| 1193 | return; |
| 1194 | } |
| 1195 | #endif |
| 1196 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 1197 | std::unique_ptr<Backtrace> backtrace(Backtrace::Create(BACKTRACE_CURRENT_PROCESS, tid)); |
Andreas Gampe | 628a61a | 2015-01-07 22:08:35 -0800 | [diff] [blame] | 1198 | if (!backtrace->Unwind(0, reinterpret_cast<ucontext*>(ucontext_ptr))) { |
Christopher Ferris | 7b5f0cf | 2013-11-01 15:18:45 -0700 | [diff] [blame] | 1199 | os << prefix << "(backtrace::Unwind failed for thread " << tid << ")\n"; |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 1200 | return; |
Christopher Ferris | 7b5f0cf | 2013-11-01 15:18:45 -0700 | [diff] [blame] | 1201 | } else if (backtrace->NumFrames() == 0) { |
Elliott Hughes | 225f5a1 | 2012-06-11 11:23:48 -0700 | [diff] [blame] | 1202 | os << prefix << "(no native stack frames for thread " << tid << ")\n"; |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 1203 | return; |
| 1204 | } |
| 1205 | |
Andreas Gampe | 8e1cb91 | 2015-01-08 20:11:09 -0800 | [diff] [blame] | 1206 | // Check whether we have and should use addr2line. |
| 1207 | bool use_addr2line; |
| 1208 | if (kUseAddr2line) { |
| 1209 | // Try to run it to see whether we have it. Push an argument so that it doesn't assume a.out |
| 1210 | // and print to stderr. |
| 1211 | use_addr2line = RunCommand("addr2line -h", nullptr, nullptr); |
| 1212 | } else { |
| 1213 | use_addr2line = false; |
| 1214 | } |
| 1215 | |
Christopher Ferris | 943af7d | 2014-01-16 12:41:46 -0800 | [diff] [blame] | 1216 | for (Backtrace::const_iterator it = backtrace->begin(); |
| 1217 | it != backtrace->end(); ++it) { |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 1218 | // We produce output like this: |
Christopher Ferris | a2cee18 | 2014-04-16 19:13:59 -0700 | [diff] [blame] | 1219 | // ] #00 pc 000075bb8 /system/lib/libc.so (unwind_backtrace_thread+536) |
| 1220 | // In order for parsing tools to continue to function, the stack dump |
| 1221 | // format must at least adhere to this format: |
| 1222 | // #XX pc <RELATIVE_ADDR> <FULL_PATH_TO_SHARED_LIBRARY> ... |
| 1223 | // The parsers require a single space before and after pc, and two spaces |
| 1224 | // after the <RELATIVE_ADDR>. There can be any prefix data before the |
| 1225 | // #XX. <RELATIVE_ADDR> has to be a hex number but with no 0x prefix. |
| 1226 | os << prefix << StringPrintf("#%02zu pc ", it->num); |
Andreas Gampe | 8e1cb91 | 2015-01-08 20:11:09 -0800 | [diff] [blame] | 1227 | bool try_addr2line = false; |
Christopher Ferris | a2cee18 | 2014-04-16 19:13:59 -0700 | [diff] [blame] | 1228 | if (!it->map) { |
| 1229 | os << StringPrintf("%08" PRIxPTR " ???", it->pc); |
Christopher Ferris | 7b5f0cf | 2013-11-01 15:18:45 -0700 | [diff] [blame] | 1230 | } else { |
Christopher Ferris | a2cee18 | 2014-04-16 19:13:59 -0700 | [diff] [blame] | 1231 | os << StringPrintf("%08" PRIxPTR " ", it->pc - it->map->start) |
| 1232 | << it->map->name << " ("; |
| 1233 | if (!it->func_name.empty()) { |
| 1234 | os << it->func_name; |
| 1235 | if (it->func_offset != 0) { |
| 1236 | os << "+" << it->func_offset; |
| 1237 | } |
Andreas Gampe | 8e1cb91 | 2015-01-08 20:11:09 -0800 | [diff] [blame] | 1238 | try_addr2line = true; |
Hiroshi Yamauchi | 7895d55 | 2014-08-28 14:55:56 -0700 | [diff] [blame] | 1239 | } else if (current_method != nullptr && |
| 1240 | Locks::mutator_lock_->IsSharedHeld(Thread::Current()) && |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1241 | current_method->PcIsWithinQuickCode(it->pc)) { |
Brian Carlstrom | 474cc79 | 2014-03-07 14:18:15 -0800 | [diff] [blame] | 1242 | const void* start_of_code = current_method->GetEntryPointFromQuickCompiledCode(); |
| 1243 | os << JniLongName(current_method) << "+" |
| 1244 | << (it->pc - reinterpret_cast<uintptr_t>(start_of_code)); |
Kenny Root | 067d20f | 2014-03-05 14:57:21 -0800 | [diff] [blame] | 1245 | } else { |
| 1246 | os << "???"; |
| 1247 | } |
Christopher Ferris | a2cee18 | 2014-04-16 19:13:59 -0700 | [diff] [blame] | 1248 | os << ")"; |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 1249 | } |
Christopher Ferris | a2cee18 | 2014-04-16 19:13:59 -0700 | [diff] [blame] | 1250 | os << "\n"; |
Andreas Gampe | 8e1cb91 | 2015-01-08 20:11:09 -0800 | [diff] [blame] | 1251 | if (try_addr2line && use_addr2line) { |
| 1252 | Addr2line(it->map->name, it->pc - it->map->start, os, prefix); |
| 1253 | } |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 1254 | } |
Nicolas Geoffray | e6ac4fd | 2014-11-04 13:03:29 +0000 | [diff] [blame] | 1255 | #else |
Andreas Gampe | 9387c72 | 2015-01-08 11:32:22 -0800 | [diff] [blame] | 1256 | UNUSED(os, tid, prefix, current_method, ucontext_ptr); |
Ian Rogers | c5f1773 | 2014-06-05 20:48:42 -0700 | [diff] [blame] | 1257 | #endif |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
Elliott Hughes | 058a6de | 2012-05-24 19:13:02 -0700 | [diff] [blame] | 1260 | #if defined(__APPLE__) |
| 1261 | |
| 1262 | // TODO: is there any way to get the kernel stack on Mac OS? |
| 1263 | void DumpKernelStack(std::ostream&, pid_t, const char*, bool) {} |
| 1264 | |
| 1265 | #else |
| 1266 | |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 1267 | void DumpKernelStack(std::ostream& os, pid_t tid, const char* prefix, bool include_count) { |
Elliott Hughes | 12a9502 | 2012-05-24 21:41:38 -0700 | [diff] [blame] | 1268 | if (tid == GetTid()) { |
| 1269 | // There's no point showing that we're reading our stack out of /proc! |
| 1270 | return; |
| 1271 | } |
| 1272 | |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 1273 | std::string kernel_stack_filename(StringPrintf("/proc/self/task/%d/stack", tid)); |
| 1274 | std::string kernel_stack; |
| 1275 | if (!ReadFileToString(kernel_stack_filename, &kernel_stack)) { |
Elliott Hughes | 058a6de | 2012-05-24 19:13:02 -0700 | [diff] [blame] | 1276 | os << prefix << "(couldn't read " << kernel_stack_filename << ")\n"; |
jeffhao | c4c3ee2 | 2012-05-25 16:16:32 -0700 | [diff] [blame] | 1277 | return; |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | std::vector<std::string> kernel_stack_frames; |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1281 | Split(kernel_stack, '\n', &kernel_stack_frames); |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 1282 | // We skip the last stack frame because it's always equivalent to "[<ffffffff>] 0xffffffff", |
| 1283 | // which looking at the source appears to be the kernel's way of saying "that's all, folks!". |
| 1284 | kernel_stack_frames.pop_back(); |
| 1285 | for (size_t i = 0; i < kernel_stack_frames.size(); ++i) { |
Brian Carlstrom | 474cc79 | 2014-03-07 14:18:15 -0800 | [diff] [blame] | 1286 | // Turn "[<ffffffff8109156d>] futex_wait_queue_me+0xcd/0x110" |
| 1287 | // into "futex_wait_queue_me+0xcd/0x110". |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 1288 | const char* text = kernel_stack_frames[i].c_str(); |
| 1289 | const char* close_bracket = strchr(text, ']'); |
| 1290 | if (close_bracket != NULL) { |
| 1291 | text = close_bracket + 2; |
| 1292 | } |
| 1293 | os << prefix; |
| 1294 | if (include_count) { |
| 1295 | os << StringPrintf("#%02zd ", i); |
| 1296 | } |
| 1297 | os << text << "\n"; |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | #endif |
| 1302 | |
Brian Carlstrom | a56fcd6 | 2012-02-04 21:23:01 -0800 | [diff] [blame] | 1303 | const char* GetAndroidRoot() { |
| 1304 | const char* android_root = getenv("ANDROID_ROOT"); |
| 1305 | if (android_root == NULL) { |
| 1306 | if (OS::DirectoryExists("/system")) { |
| 1307 | android_root = "/system"; |
Brian Carlstrom | a9f1978 | 2011-10-13 00:14:47 -0700 | [diff] [blame] | 1308 | } else { |
Brian Carlstrom | a56fcd6 | 2012-02-04 21:23:01 -0800 | [diff] [blame] | 1309 | LOG(FATAL) << "ANDROID_ROOT not set and /system does not exist"; |
| 1310 | return ""; |
Brian Carlstrom | a9f1978 | 2011-10-13 00:14:47 -0700 | [diff] [blame] | 1311 | } |
| 1312 | } |
Brian Carlstrom | a56fcd6 | 2012-02-04 21:23:01 -0800 | [diff] [blame] | 1313 | if (!OS::DirectoryExists(android_root)) { |
| 1314 | LOG(FATAL) << "Failed to find ANDROID_ROOT directory " << android_root; |
Brian Carlstrom | a9f1978 | 2011-10-13 00:14:47 -0700 | [diff] [blame] | 1315 | return ""; |
| 1316 | } |
Brian Carlstrom | a56fcd6 | 2012-02-04 21:23:01 -0800 | [diff] [blame] | 1317 | return android_root; |
| 1318 | } |
Brian Carlstrom | a9f1978 | 2011-10-13 00:14:47 -0700 | [diff] [blame] | 1319 | |
Brian Carlstrom | a56fcd6 | 2012-02-04 21:23:01 -0800 | [diff] [blame] | 1320 | const char* GetAndroidData() { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1321 | std::string error_msg; |
| 1322 | const char* dir = GetAndroidDataSafe(&error_msg); |
| 1323 | if (dir != nullptr) { |
| 1324 | return dir; |
| 1325 | } else { |
| 1326 | LOG(FATAL) << error_msg; |
| 1327 | return ""; |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | const char* GetAndroidDataSafe(std::string* error_msg) { |
Brian Carlstrom | a56fcd6 | 2012-02-04 21:23:01 -0800 | [diff] [blame] | 1332 | const char* android_data = getenv("ANDROID_DATA"); |
| 1333 | if (android_data == NULL) { |
| 1334 | if (OS::DirectoryExists("/data")) { |
| 1335 | android_data = "/data"; |
| 1336 | } else { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1337 | *error_msg = "ANDROID_DATA not set and /data does not exist"; |
| 1338 | return nullptr; |
Brian Carlstrom | a56fcd6 | 2012-02-04 21:23:01 -0800 | [diff] [blame] | 1339 | } |
| 1340 | } |
| 1341 | if (!OS::DirectoryExists(android_data)) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1342 | *error_msg = StringPrintf("Failed to find ANDROID_DATA directory %s", android_data); |
| 1343 | return nullptr; |
Brian Carlstrom | a56fcd6 | 2012-02-04 21:23:01 -0800 | [diff] [blame] | 1344 | } |
| 1345 | return android_data; |
| 1346 | } |
| 1347 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1348 | void GetDalvikCache(const char* subdir, const bool create_if_absent, std::string* dalvik_cache, |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 1349 | bool* have_android_data, bool* dalvik_cache_exists, bool* is_global_cache) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1350 | CHECK(subdir != nullptr); |
| 1351 | std::string error_msg; |
| 1352 | const char* android_data = GetAndroidDataSafe(&error_msg); |
| 1353 | if (android_data == nullptr) { |
| 1354 | *have_android_data = false; |
| 1355 | *dalvik_cache_exists = false; |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 1356 | *is_global_cache = false; |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1357 | return; |
| 1358 | } else { |
| 1359 | *have_android_data = true; |
| 1360 | } |
| 1361 | const std::string dalvik_cache_root(StringPrintf("%s/dalvik-cache/", android_data)); |
| 1362 | *dalvik_cache = dalvik_cache_root + subdir; |
| 1363 | *dalvik_cache_exists = OS::DirectoryExists(dalvik_cache->c_str()); |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 1364 | *is_global_cache = strcmp(android_data, "/data") == 0; |
| 1365 | if (create_if_absent && !*dalvik_cache_exists && !*is_global_cache) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1366 | // Don't create the system's /data/dalvik-cache/... because it needs special permissions. |
| 1367 | *dalvik_cache_exists = ((mkdir(dalvik_cache_root.c_str(), 0700) == 0 || errno == EEXIST) && |
| 1368 | (mkdir(dalvik_cache->c_str(), 0700) == 0 || errno == EEXIST)); |
| 1369 | } |
| 1370 | } |
| 1371 | |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 1372 | std::string GetDalvikCacheOrDie(const char* subdir, const bool create_if_absent) { |
| 1373 | CHECK(subdir != nullptr); |
Brian Carlstrom | 41ccffd | 2014-05-06 10:37:30 -0700 | [diff] [blame] | 1374 | const char* android_data = GetAndroidData(); |
| 1375 | const std::string dalvik_cache_root(StringPrintf("%s/dalvik-cache/", android_data)); |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 1376 | const std::string dalvik_cache = dalvik_cache_root + subdir; |
| 1377 | if (create_if_absent && !OS::DirectoryExists(dalvik_cache.c_str())) { |
Brian Carlstrom | 41ccffd | 2014-05-06 10:37:30 -0700 | [diff] [blame] | 1378 | // Don't create the system's /data/dalvik-cache/... because it needs special permissions. |
| 1379 | if (strcmp(android_data, "/data") != 0) { |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 1380 | int result = mkdir(dalvik_cache_root.c_str(), 0700); |
Narayan Kamath | ef204fa | 2014-04-30 17:25:23 +0100 | [diff] [blame] | 1381 | if (result != 0 && errno != EEXIST) { |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 1382 | PLOG(FATAL) << "Failed to create dalvik-cache directory " << dalvik_cache_root; |
| 1383 | return ""; |
| 1384 | } |
| 1385 | result = mkdir(dalvik_cache.c_str(), 0700); |
| 1386 | if (result != 0) { |
| 1387 | PLOG(FATAL) << "Failed to create dalvik-cache directory " << dalvik_cache; |
Brian Carlstrom | a9f1978 | 2011-10-13 00:14:47 -0700 | [diff] [blame] | 1388 | return ""; |
| 1389 | } |
| 1390 | } else { |
Brian Carlstrom | 7675e16 | 2013-06-10 16:18:04 -0700 | [diff] [blame] | 1391 | LOG(FATAL) << "Failed to find dalvik-cache directory " << dalvik_cache; |
Brian Carlstrom | a9f1978 | 2011-10-13 00:14:47 -0700 | [diff] [blame] | 1392 | return ""; |
| 1393 | } |
| 1394 | } |
Brian Carlstrom | 7675e16 | 2013-06-10 16:18:04 -0700 | [diff] [blame] | 1395 | return dalvik_cache; |
Brian Carlstrom | a9f1978 | 2011-10-13 00:14:47 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1398 | bool GetDalvikCacheFilename(const char* location, const char* cache_location, |
| 1399 | std::string* filename, std::string* error_msg) { |
Ian Rogers | e606010 | 2013-05-16 12:01:04 -0700 | [diff] [blame] | 1400 | if (location[0] != '/') { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1401 | *error_msg = StringPrintf("Expected path in location to be absolute: %s", location); |
| 1402 | return false; |
Ian Rogers | e606010 | 2013-05-16 12:01:04 -0700 | [diff] [blame] | 1403 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 1404 | std::string cache_file(&location[1]); // skip leading slash |
Alex Light | 6e183f2 | 2014-07-18 14:57:04 -0700 | [diff] [blame] | 1405 | if (!EndsWith(location, ".dex") && !EndsWith(location, ".art") && !EndsWith(location, ".oat")) { |
Brian Carlstrom | 30e2ea4 | 2013-06-19 23:25:37 -0700 | [diff] [blame] | 1406 | cache_file += "/"; |
| 1407 | cache_file += DexFile::kClassesDex; |
| 1408 | } |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 1409 | std::replace(cache_file.begin(), cache_file.end(), '/', '@'); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 1410 | *filename = StringPrintf("%s/%s", cache_location, cache_file.c_str()); |
| 1411 | return true; |
| 1412 | } |
| 1413 | |
| 1414 | std::string GetDalvikCacheFilenameOrDie(const char* location, const char* cache_location) { |
| 1415 | std::string ret; |
| 1416 | std::string error_msg; |
| 1417 | if (!GetDalvikCacheFilename(location, cache_location, &ret, &error_msg)) { |
| 1418 | LOG(FATAL) << error_msg; |
| 1419 | } |
| 1420 | return ret; |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 1421 | } |
| 1422 | |
Brian Carlstrom | 2afe494 | 2014-05-19 10:25:33 -0700 | [diff] [blame] | 1423 | static void InsertIsaDirectory(const InstructionSet isa, std::string* filename) { |
Brian Carlstrom | 0e12bdc | 2014-05-14 17:44:28 -0700 | [diff] [blame] | 1424 | // in = /foo/bar/baz |
| 1425 | // out = /foo/bar/<isa>/baz |
| 1426 | size_t pos = filename->rfind('/'); |
| 1427 | CHECK_NE(pos, std::string::npos) << *filename << " " << isa; |
| 1428 | filename->insert(pos, "/", 1); |
| 1429 | filename->insert(pos + 1, GetInstructionSetString(isa)); |
| 1430 | } |
| 1431 | |
| 1432 | std::string GetSystemImageFilename(const char* location, const InstructionSet isa) { |
| 1433 | // location = /system/framework/boot.art |
| 1434 | // filename = /system/framework/<isa>/boot.art |
| 1435 | std::string filename(location); |
Brian Carlstrom | 2afe494 | 2014-05-19 10:25:33 -0700 | [diff] [blame] | 1436 | InsertIsaDirectory(isa, &filename); |
Brian Carlstrom | 0e12bdc | 2014-05-14 17:44:28 -0700 | [diff] [blame] | 1437 | return filename; |
| 1438 | } |
| 1439 | |
| 1440 | std::string DexFilenameToOdexFilename(const std::string& location, const InstructionSet isa) { |
| 1441 | // location = /foo/bar/baz.jar |
| 1442 | // odex_location = /foo/bar/<isa>/baz.odex |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 1443 | |
Brian Carlstrom | 0e12bdc | 2014-05-14 17:44:28 -0700 | [diff] [blame] | 1444 | CHECK_GE(location.size(), 4U) << location; // must be at least .123 |
| 1445 | std::string odex_location(location); |
Brian Carlstrom | 2afe494 | 2014-05-19 10:25:33 -0700 | [diff] [blame] | 1446 | InsertIsaDirectory(isa, &odex_location); |
Brian Carlstrom | 0e12bdc | 2014-05-14 17:44:28 -0700 | [diff] [blame] | 1447 | size_t dot_index = odex_location.size() - 3 - 1; // 3=dex or zip or apk |
| 1448 | CHECK_EQ('.', odex_location[dot_index]) << location; |
| 1449 | odex_location.resize(dot_index + 1); |
| 1450 | CHECK_EQ('.', odex_location[odex_location.size()-1]) << location << " " << odex_location; |
| 1451 | odex_location += "odex"; |
| 1452 | return odex_location; |
| 1453 | } |
| 1454 | |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 1455 | bool IsZipMagic(uint32_t magic) { |
| 1456 | return (('P' == ((magic >> 0) & 0xff)) && |
| 1457 | ('K' == ((magic >> 8) & 0xff))); |
jeffhao | 262bf46 | 2011-10-20 18:36:32 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 1460 | bool IsDexMagic(uint32_t magic) { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 1461 | return DexFile::IsMagicValid(reinterpret_cast<const uint8_t*>(&magic)); |
Brian Carlstrom | 7a967b3 | 2012-03-28 15:23:10 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 1464 | bool IsOatMagic(uint32_t magic) { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 1465 | return (memcmp(reinterpret_cast<const uint8_t*>(magic), |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 1466 | OatHeader::kOatMagic, |
| 1467 | sizeof(OatHeader::kOatMagic)) == 0); |
jeffhao | 262bf46 | 2011-10-20 18:36:32 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 1470 | bool Exec(std::vector<std::string>& arg_vector, std::string* error_msg) { |
| 1471 | const std::string command_line(Join(arg_vector, ' ')); |
| 1472 | |
| 1473 | CHECK_GE(arg_vector.size(), 1U) << command_line; |
| 1474 | |
| 1475 | // Convert the args to char pointers. |
| 1476 | const char* program = arg_vector[0].c_str(); |
| 1477 | std::vector<char*> args; |
Brian Carlstrom | 35d8b8e | 2014-02-25 10:51:11 -0800 | [diff] [blame] | 1478 | for (size_t i = 0; i < arg_vector.size(); ++i) { |
| 1479 | const std::string& arg = arg_vector[i]; |
| 1480 | char* arg_str = const_cast<char*>(arg.c_str()); |
| 1481 | CHECK(arg_str != nullptr) << i; |
| 1482 | args.push_back(arg_str); |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 1483 | } |
| 1484 | args.push_back(NULL); |
| 1485 | |
| 1486 | // fork and exec |
| 1487 | pid_t pid = fork(); |
| 1488 | if (pid == 0) { |
| 1489 | // no allocation allowed between fork and exec |
| 1490 | |
| 1491 | // change process groups, so we don't get reaped by ProcessManager |
| 1492 | setpgid(0, 0); |
| 1493 | |
| 1494 | execv(program, &args[0]); |
| 1495 | |
Brian Carlstrom | 13db9aa | 2014-02-27 12:44:32 -0800 | [diff] [blame] | 1496 | PLOG(ERROR) << "Failed to execv(" << command_line << ")"; |
| 1497 | exit(1); |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 1498 | } else { |
| 1499 | if (pid == -1) { |
| 1500 | *error_msg = StringPrintf("Failed to execv(%s) because fork failed: %s", |
| 1501 | command_line.c_str(), strerror(errno)); |
| 1502 | return false; |
| 1503 | } |
| 1504 | |
| 1505 | // wait for subprocess to finish |
| 1506 | int status; |
| 1507 | pid_t got_pid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0)); |
| 1508 | if (got_pid != pid) { |
| 1509 | *error_msg = StringPrintf("Failed after fork for execv(%s) because waitpid failed: " |
| 1510 | "wanted %d, got %d: %s", |
| 1511 | command_line.c_str(), pid, got_pid, strerror(errno)); |
| 1512 | return false; |
| 1513 | } |
| 1514 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { |
| 1515 | *error_msg = StringPrintf("Failed execv(%s) because non-0 exit status", |
| 1516 | command_line.c_str()); |
| 1517 | return false; |
| 1518 | } |
| 1519 | } |
| 1520 | return true; |
| 1521 | } |
| 1522 | |
Tong Shen | 547cdfd | 2014-08-05 01:54:19 -0700 | [diff] [blame] | 1523 | void EncodeUnsignedLeb128(uint32_t data, std::vector<uint8_t>* dst) { |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 1524 | Leb128Encoder(dst).PushBackUnsigned(data); |
Tong Shen | 547cdfd | 2014-08-05 01:54:19 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | void EncodeSignedLeb128(int32_t data, std::vector<uint8_t>* dst) { |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 1528 | Leb128Encoder(dst).PushBackSigned(data); |
Tong Shen | 547cdfd | 2014-08-05 01:54:19 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | void PushWord(std::vector<uint8_t>* buf, int data) { |
| 1532 | buf->push_back(data & 0xff); |
| 1533 | buf->push_back((data >> 8) & 0xff); |
| 1534 | buf->push_back((data >> 16) & 0xff); |
| 1535 | buf->push_back((data >> 24) & 0xff); |
| 1536 | } |
| 1537 | |
Mathieu Chartier | 7643327 | 2014-09-26 14:32:37 -0700 | [diff] [blame] | 1538 | std::string PrettyDescriptor(Primitive::Type type) { |
| 1539 | return PrettyDescriptor(Primitive::Descriptor(type)); |
| 1540 | } |
| 1541 | |
Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 1542 | } // namespace art |