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