blob: fc1c91ab22b7c77deb3bec7acf15dff14a24fc31 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Elliott Hughes11e45072011-08-16 17:40:46 -070016
Elliott Hughes42ee1422011-09-06 12:33:32 -070017#include "utils.h"
18
Christopher Ferris943af7d2014-01-16 12:41:46 -080019#include <inttypes.h>
Elliott Hughes92b3b562011-09-08 16:32:26 -070020#include <pthread.h>
Mathieu Chartier120aa282017-08-05 16:03:03 -070021#include <sys/mman.h> // For madvise
Brian Carlstroma9f19782011-10-13 00:14:47 -070022#include <sys/stat.h>
Elliott Hughes42ee1422011-09-06 12:33:32 -070023#include <sys/syscall.h>
24#include <sys/types.h>
Brian Carlstrom4cf5e572014-02-25 11:47:48 -080025#include <sys/wait.h>
Elliott Hughes42ee1422011-09-06 12:33:32 -070026#include <unistd.h>
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070027
Ian Rogers700a4022014-05-19 16:49:03 -070028#include <memory>
Elliott Hughes42ee1422011-09-06 12:33:32 -070029
Andreas Gampe46ee31b2016-12-14 10:11:49 -080030#include "android-base/stringprintf.h"
Andreas Gampe9186ced2016-12-12 14:28:21 -080031#include "android-base/strings.h"
32
Brian Carlstrom6449c622014-02-10 23:48:36 -080033#include "base/stl_util.h"
Elliott Hughes76160052012-12-12 16:31:20 -080034#include "base/unix_file/fd_file.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070035#include "dex_file-inl.h"
Andreas Gampe5073fed2015-08-10 11:40:25 -070036#include "dex_instruction.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010037#include "oat_quick_method_header.h"
buzbeec143c552011-08-20 17:38:58 -070038#include "os.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070039#include "scoped_thread_state_change-inl.h"
Ian Rogersa6724902013-09-23 09:23:37 -070040#include "utf-inl.h"
Elliott Hughes11e45072011-08-16 17:40:46 -070041
Elliott Hughes4ae722a2012-03-13 11:08:51 -070042#if defined(__APPLE__)
David Sehrfa442002016-08-22 18:42:08 -070043#include <crt_externs.h>
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070044#include <sys/syscall.h>
45#include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED
Elliott Hughes4ae722a2012-03-13 11:08:51 -070046#endif
47
Elliott Hughes058a6de2012-05-24 19:13:02 -070048#if defined(__linux__)
Elliott Hughese1aee692012-01-17 16:40:10 -080049#include <linux/unistd.h>
Elliott Hughese1aee692012-01-17 16:40:10 -080050#endif
51
Elliott Hughes11e45072011-08-16 17:40:46 -070052namespace art {
53
Andreas Gampe46ee31b2016-12-14 10:11:49 -080054using android::base::StringAppendF;
55using android::base::StringPrintf;
56
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080057pid_t GetTid() {
Brian Carlstromf3a26412012-08-24 11:06:02 -070058#if defined(__APPLE__)
59 uint64_t owner;
Mathieu Chartier2cebb242015-04-21 16:50:40 -070060 CHECK_PTHREAD_CALL(pthread_threadid_np, (nullptr, &owner), __FUNCTION__); // Requires Mac OS 10.6
Brian Carlstromf3a26412012-08-24 11:06:02 -070061 return owner;
Elliott Hughes323aa862014-08-20 15:00:04 -070062#elif defined(__BIONIC__)
63 return gettid();
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080064#else
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080065 return syscall(__NR_gettid);
66#endif
67}
68
Elliott Hughes289be852012-06-12 13:57:20 -070069std::string GetThreadName(pid_t tid) {
70 std::string result;
71 if (ReadFileToString(StringPrintf("/proc/self/task/%d/comm", tid), &result)) {
Brian Carlstrom7934ac22013-07-26 10:54:15 -070072 result.resize(result.size() - 1); // Lose the trailing '\n'.
Elliott Hughes289be852012-06-12 13:57:20 -070073 } else {
74 result = "<unknown>";
75 }
76 return result;
77}
78
Elliott Hughesd92bec42011-09-02 17:04:36 -070079bool ReadFileToString(const std::string& file_name, std::string* result) {
Andreas Gampedf878922015-08-13 16:44:54 -070080 File file(file_name, O_RDONLY, false);
81 if (!file.IsOpened()) {
Elliott Hughesd92bec42011-09-02 17:04:36 -070082 return false;
83 }
buzbeec143c552011-08-20 17:38:58 -070084
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070085 std::vector<char> buf(8 * KB);
buzbeec143c552011-08-20 17:38:58 -070086 while (true) {
Andreas Gampea6dfdae2015-02-24 15:50:19 -080087 int64_t n = TEMP_FAILURE_RETRY(read(file.Fd(), &buf[0], buf.size()));
Elliott Hughesd92bec42011-09-02 17:04:36 -070088 if (n == -1) {
89 return false;
buzbeec143c552011-08-20 17:38:58 -070090 }
Elliott Hughesd92bec42011-09-02 17:04:36 -070091 if (n == 0) {
92 return true;
93 }
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070094 result->append(&buf[0], n);
buzbeec143c552011-08-20 17:38:58 -070095 }
buzbeec143c552011-08-20 17:38:58 -070096}
97
Andreas Gampea6dfdae2015-02-24 15:50:19 -080098bool PrintFileToLog(const std::string& file_name, LogSeverity level) {
Andreas Gampedf878922015-08-13 16:44:54 -070099 File file(file_name, O_RDONLY, false);
100 if (!file.IsOpened()) {
Andreas Gampea6dfdae2015-02-24 15:50:19 -0800101 return false;
102 }
103
104 constexpr size_t kBufSize = 256; // Small buffer. Avoid stack overflow and stack size warnings.
105 char buf[kBufSize + 1]; // +1 for terminator.
106 size_t filled_to = 0;
107 while (true) {
108 DCHECK_LT(filled_to, kBufSize);
109 int64_t n = TEMP_FAILURE_RETRY(read(file.Fd(), &buf[filled_to], kBufSize - filled_to));
110 if (n <= 0) {
111 // Print the rest of the buffer, if it exists.
112 if (filled_to > 0) {
113 buf[filled_to] = 0;
114 LOG(level) << buf;
115 }
116 return n == 0;
117 }
118 // Scan for '\n'.
119 size_t i = filled_to;
120 bool found_newline = false;
121 for (; i < filled_to + n; ++i) {
122 if (buf[i] == '\n') {
123 // Found a line break, that's something to print now.
124 buf[i] = 0;
125 LOG(level) << buf;
126 // Copy the rest to the front.
127 if (i + 1 < filled_to + n) {
128 memmove(&buf[0], &buf[i + 1], filled_to + n - i - 1);
129 filled_to = filled_to + n - i - 1;
130 } else {
131 filled_to = 0;
132 }
133 found_newline = true;
134 break;
135 }
136 }
137 if (found_newline) {
138 continue;
139 } else {
140 filled_to += n;
141 // Check if we must flush now.
142 if (filled_to == kBufSize) {
143 buf[kBufSize] = 0;
144 LOG(level) << buf;
145 filled_to = 0;
146 }
147 }
148 }
149}
150
Vladimir Markob8a55f82017-09-21 16:21:43 +0100151void AppendPrettyDescriptor(const char* descriptor, std::string* result) {
Elliott Hughes11e45072011-08-16 17:40:46 -0700152 // Count the number of '['s to get the dimensionality.
Ian Rogers1ff3c982014-08-12 02:30:58 -0700153 const char* c = descriptor;
Elliott Hughes11e45072011-08-16 17:40:46 -0700154 size_t dim = 0;
155 while (*c == '[') {
156 dim++;
157 c++;
158 }
159
160 // Reference or primitive?
161 if (*c == 'L') {
162 // "[[La/b/C;" -> "a.b.C[][]".
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700163 c++; // Skip the 'L'.
Elliott Hughes11e45072011-08-16 17:40:46 -0700164 } else {
165 // "[[B" -> "byte[][]".
166 // To make life easier, we make primitives look like unqualified
167 // reference types.
168 switch (*c) {
Vladimir Markob8a55f82017-09-21 16:21:43 +0100169 case 'B': c = "byte;"; break;
170 case 'C': c = "char;"; break;
171 case 'D': c = "double;"; break;
172 case 'F': c = "float;"; break;
173 case 'I': c = "int;"; break;
174 case 'J': c = "long;"; break;
175 case 'S': c = "short;"; break;
176 case 'Z': c = "boolean;"; break;
177 case 'V': c = "void;"; break; // Used when decoding return types.
178 default: result->append(descriptor); return;
Elliott Hughes11e45072011-08-16 17:40:46 -0700179 }
180 }
181
182 // At this point, 'c' is a string of the form "fully/qualified/Type;"
183 // or "primitive;". Rewrite the type with '.' instead of '/':
Elliott Hughes11e45072011-08-16 17:40:46 -0700184 const char* p = c;
185 while (*p != ';') {
186 char ch = *p++;
187 if (ch == '/') {
188 ch = '.';
189 }
Vladimir Markob8a55f82017-09-21 16:21:43 +0100190 result->push_back(ch);
Elliott Hughes11e45072011-08-16 17:40:46 -0700191 }
192 // ...and replace the semicolon with 'dim' "[]" pairs:
Ian Rogers1ff3c982014-08-12 02:30:58 -0700193 for (size_t i = 0; i < dim; ++i) {
Vladimir Markob8a55f82017-09-21 16:21:43 +0100194 result->append("[]");
Elliott Hughes11e45072011-08-16 17:40:46 -0700195 }
Elliott Hughes11e45072011-08-16 17:40:46 -0700196}
197
Vladimir Markob8a55f82017-09-21 16:21:43 +0100198std::string PrettyDescriptor(const char* descriptor) {
Elliott Hughes9058f2b2012-03-22 18:06:48 -0700199 std::string result;
Vladimir Markob8a55f82017-09-21 16:21:43 +0100200 AppendPrettyDescriptor(descriptor, &result);
Elliott Hughes9058f2b2012-03-22 18:06:48 -0700201 return result;
202}
203
Andreas Gampec0d82292014-09-23 10:38:30 -0700204std::string PrettyJavaAccessFlags(uint32_t access_flags) {
205 std::string result;
206 if ((access_flags & kAccPublic) != 0) {
207 result += "public ";
208 }
209 if ((access_flags & kAccProtected) != 0) {
210 result += "protected ";
211 }
212 if ((access_flags & kAccPrivate) != 0) {
213 result += "private ";
214 }
215 if ((access_flags & kAccFinal) != 0) {
216 result += "final ";
217 }
218 if ((access_flags & kAccStatic) != 0) {
219 result += "static ";
220 }
David Brazdilca3c8c32016-09-06 14:04:48 +0100221 if ((access_flags & kAccAbstract) != 0) {
222 result += "abstract ";
223 }
224 if ((access_flags & kAccInterface) != 0) {
225 result += "interface ";
226 }
Andreas Gampec0d82292014-09-23 10:38:30 -0700227 if ((access_flags & kAccTransient) != 0) {
228 result += "transient ";
229 }
230 if ((access_flags & kAccVolatile) != 0) {
231 result += "volatile ";
232 }
233 if ((access_flags & kAccSynchronized) != 0) {
234 result += "synchronized ";
235 }
236 return result;
237}
238
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800239std::string PrettySize(int64_t byte_count) {
Elliott Hughesc967f782012-04-16 10:23:15 -0700240 // The byte thresholds at which we display amounts. A byte count is displayed
241 // in unit U when kUnitThresholds[U] <= bytes < kUnitThresholds[U+1].
Ian Rogersef7d42f2014-01-06 12:55:46 -0800242 static const int64_t kUnitThresholds[] = {
Elliott Hughesc967f782012-04-16 10:23:15 -0700243 0, // B up to...
244 3*1024, // KB up to...
245 2*1024*1024, // MB up to...
246 1024*1024*1024 // GB from here.
247 };
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800248 static const int64_t kBytesPerUnit[] = { 1, KB, MB, GB };
Elliott Hughesc967f782012-04-16 10:23:15 -0700249 static const char* const kUnitStrings[] = { "B", "KB", "MB", "GB" };
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800250 const char* negative_str = "";
251 if (byte_count < 0) {
252 negative_str = "-";
253 byte_count = -byte_count;
254 }
Elliott Hughesc967f782012-04-16 10:23:15 -0700255 int i = arraysize(kUnitThresholds);
256 while (--i > 0) {
257 if (byte_count >= kUnitThresholds[i]) {
258 break;
259 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800260 }
Brian Carlstrom474cc792014-03-07 14:18:15 -0800261 return StringPrintf("%s%" PRId64 "%s",
262 negative_str, byte_count / kBytesPerUnit[i], kUnitStrings[i]);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800263}
264
Andreas Gampe9186ced2016-12-12 14:28:21 -0800265static inline constexpr bool NeedsEscaping(uint16_t ch) {
266 return (ch < ' ' || ch > '~');
267}
268
Ian Rogers576ca0c2014-06-06 15:58:22 -0700269std::string PrintableChar(uint16_t ch) {
270 std::string result;
271 result += '\'';
272 if (NeedsEscaping(ch)) {
273 StringAppendF(&result, "\\u%04x", ch);
274 } else {
Andreas Gampef45d61c2017-06-07 10:29:33 -0700275 result += static_cast<std::string::value_type>(ch);
Ian Rogers576ca0c2014-06-06 15:58:22 -0700276 }
277 result += '\'';
278 return result;
279}
280
Ian Rogers68b56852014-08-29 20:19:11 -0700281std::string PrintableString(const char* utf) {
Elliott Hughes82914b62012-04-09 15:56:29 -0700282 std::string result;
283 result += '"';
Ian Rogers68b56852014-08-29 20:19:11 -0700284 const char* p = utf;
Elliott Hughes82914b62012-04-09 15:56:29 -0700285 size_t char_count = CountModifiedUtf8Chars(p);
286 for (size_t i = 0; i < char_count; ++i) {
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000287 uint32_t ch = GetUtf16FromUtf8(&p);
Elliott Hughes82914b62012-04-09 15:56:29 -0700288 if (ch == '\\') {
289 result += "\\\\";
290 } else if (ch == '\n') {
291 result += "\\n";
292 } else if (ch == '\r') {
293 result += "\\r";
294 } else if (ch == '\t') {
295 result += "\\t";
Elliott Hughes82914b62012-04-09 15:56:29 -0700296 } else {
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000297 const uint16_t leading = GetLeadingUtf16Char(ch);
298
299 if (NeedsEscaping(leading)) {
300 StringAppendF(&result, "\\u%04x", leading);
301 } else {
Andreas Gampef45d61c2017-06-07 10:29:33 -0700302 result += static_cast<std::string::value_type>(leading);
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000303 }
304
305 const uint32_t trailing = GetTrailingUtf16Char(ch);
306 if (trailing != 0) {
307 // All high surrogates will need escaping.
308 StringAppendF(&result, "\\u%04x", trailing);
309 }
Elliott Hughes82914b62012-04-09 15:56:29 -0700310 }
311 }
312 result += '"';
313 return result;
314}
315
Alex Light888a59e2017-01-25 11:41:41 -0800316std::string GetJniShortName(const std::string& class_descriptor, const std::string& method) {
317 // Remove the leading 'L' and trailing ';'...
318 std::string class_name(class_descriptor);
319 CHECK_EQ(class_name[0], 'L') << class_name;
320 CHECK_EQ(class_name[class_name.size() - 1], ';') << class_name;
321 class_name.erase(0, 1);
322 class_name.erase(class_name.size() - 1, 1);
323
324 std::string short_name;
325 short_name += "Java_";
326 short_name += MangleForJni(class_name);
327 short_name += "_";
328 short_name += MangleForJni(method);
329 return short_name;
330}
331
Elliott Hughesd8c00d02012-01-30 14:08:31 -0800332// See http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp615 for the full rules.
Elliott Hughes79082e32011-08-25 12:07:32 -0700333std::string MangleForJni(const std::string& s) {
334 std::string result;
335 size_t char_count = CountModifiedUtf8Chars(s.c_str());
336 const char* cp = &s[0];
337 for (size_t i = 0; i < char_count; ++i) {
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000338 uint32_t ch = GetUtf16FromUtf8(&cp);
Elliott Hughesd8c00d02012-01-30 14:08:31 -0800339 if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) {
340 result.push_back(ch);
341 } else if (ch == '.' || ch == '/') {
342 result += "_";
343 } else if (ch == '_') {
344 result += "_1";
345 } else if (ch == ';') {
346 result += "_2";
347 } else if (ch == '[') {
348 result += "_3";
Elliott Hughes79082e32011-08-25 12:07:32 -0700349 } else {
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000350 const uint16_t leading = GetLeadingUtf16Char(ch);
351 const uint32_t trailing = GetTrailingUtf16Char(ch);
352
353 StringAppendF(&result, "_0%04x", leading);
354 if (trailing != 0) {
355 StringAppendF(&result, "_0%04x", trailing);
356 }
Elliott Hughes79082e32011-08-25 12:07:32 -0700357 }
358 }
359 return result;
360}
361
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700362std::string DotToDescriptor(const char* class_name) {
363 std::string descriptor(class_name);
364 std::replace(descriptor.begin(), descriptor.end(), '.', '/');
365 if (descriptor.length() > 0 && descriptor[0] != '[') {
366 descriptor = "L" + descriptor + ";";
367 }
368 return descriptor;
369}
370
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800371std::string DescriptorToDot(const char* descriptor) {
Elliott Hughes2435a572012-02-17 16:07:41 -0800372 size_t length = strlen(descriptor);
Ian Rogers1ff3c982014-08-12 02:30:58 -0700373 if (length > 1) {
374 if (descriptor[0] == 'L' && descriptor[length - 1] == ';') {
375 // Descriptors have the leading 'L' and trailing ';' stripped.
376 std::string result(descriptor + 1, length - 2);
377 std::replace(result.begin(), result.end(), '/', '.');
378 return result;
379 } else {
380 // For arrays the 'L' and ';' remain intact.
381 std::string result(descriptor);
382 std::replace(result.begin(), result.end(), '/', '.');
383 return result;
384 }
Elliott Hughes2435a572012-02-17 16:07:41 -0800385 }
Ian Rogers1ff3c982014-08-12 02:30:58 -0700386 // Do nothing for non-class/array descriptors.
Elliott Hughes2435a572012-02-17 16:07:41 -0800387 return descriptor;
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800388}
389
390std::string DescriptorToName(const char* descriptor) {
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800391 size_t length = strlen(descriptor);
Elliott Hughes2435a572012-02-17 16:07:41 -0800392 if (descriptor[0] == 'L' && descriptor[length - 1] == ';') {
393 std::string result(descriptor + 1, length - 2);
394 return result;
395 }
396 return descriptor;
Brian Carlstromaded5f72011-10-07 17:15:04 -0700397}
398
jeffhao10037c82012-01-23 15:06:23 -0800399// Helper for IsValidPartOfMemberNameUtf8(), a bit vector indicating valid low ascii.
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700400uint32_t DEX_MEMBER_VALID_LOW_ASCII[4] = {
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700401 0x00000000, // 00..1f low control characters; nothing valid
402 0x03ff2010, // 20..3f digits and symbols; valid: '0'..'9', '$', '-'
403 0x87fffffe, // 40..5f uppercase etc.; valid: 'A'..'Z', '_'
404 0x07fffffe // 60..7f lowercase etc.; valid: 'a'..'z'
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700405};
406
jeffhao10037c82012-01-23 15:06:23 -0800407// Helper for IsValidPartOfMemberNameUtf8(); do not call directly.
408bool IsValidPartOfMemberNameUtf8Slow(const char** pUtf8Ptr) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700409 /*
410 * It's a multibyte encoded character. Decode it and analyze. We
411 * accept anything that isn't (a) an improperly encoded low value,
412 * (b) an improper surrogate pair, (c) an encoded '\0', (d) a high
413 * control character, or (e) a high space, layout, or special
414 * character (U+00a0, U+2000..U+200f, U+2028..U+202f,
415 * U+fff0..U+ffff). This is all specified in the dex format
416 * document.
417 */
418
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000419 const uint32_t pair = GetUtf16FromUtf8(pUtf8Ptr);
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000420 const uint16_t leading = GetLeadingUtf16Char(pair);
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000421
Narayan Kamath8508e372015-05-06 14:55:43 +0100422 // We have a surrogate pair resulting from a valid 4 byte UTF sequence.
423 // No further checks are necessary because 4 byte sequences span code
424 // points [U+10000, U+1FFFFF], which are valid codepoints in a dex
425 // identifier. Furthermore, GetUtf16FromUtf8 guarantees that each of
426 // the surrogate halves are valid and well formed in this instance.
427 if (GetTrailingUtf16Char(pair) != 0) {
428 return true;
429 }
430
431
432 // We've encountered a one, two or three byte UTF-8 sequence. The
433 // three byte UTF-8 sequence could be one half of a surrogate pair.
434 switch (leading >> 8) {
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000435 case 0x00:
436 // It's only valid if it's above the ISO-8859-1 high space (0xa0).
437 return (leading > 0x00a0);
438 case 0xd8:
439 case 0xd9:
440 case 0xda:
441 case 0xdb:
Narayan Kamath8508e372015-05-06 14:55:43 +0100442 {
443 // We found a three byte sequence encoding one half of a surrogate.
444 // Look for the other half.
445 const uint32_t pair2 = GetUtf16FromUtf8(pUtf8Ptr);
446 const uint16_t trailing = GetLeadingUtf16Char(pair2);
447
448 return (GetTrailingUtf16Char(pair2) == 0) && (0xdc00 <= trailing && trailing <= 0xdfff);
449 }
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000450 case 0xdc:
451 case 0xdd:
452 case 0xde:
453 case 0xdf:
454 // It's a trailing surrogate, which is not valid at this point.
455 return false;
456 case 0x20:
457 case 0xff:
458 // It's in the range that has spaces, controls, and specials.
459 switch (leading & 0xfff8) {
Narayan Kamath8508e372015-05-06 14:55:43 +0100460 case 0x2000:
461 case 0x2008:
462 case 0x2028:
463 case 0xfff0:
464 case 0xfff8:
465 return false;
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000466 }
Narayan Kamath8508e372015-05-06 14:55:43 +0100467 return true;
468 default:
469 return true;
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700470 }
Narayan Kamatha5afcfc2015-01-29 20:06:46 +0000471
Narayan Kamath8508e372015-05-06 14:55:43 +0100472 UNREACHABLE();
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700473}
474
475/* Return whether the pointed-at modified-UTF-8 encoded character is
476 * valid as part of a member name, updating the pointer to point past
477 * the consumed character. This will consume two encoded UTF-16 code
478 * points if the character is encoded as a surrogate pair. Also, if
479 * this function returns false, then the given pointer may only have
480 * been partially advanced.
481 */
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700482static bool IsValidPartOfMemberNameUtf8(const char** pUtf8Ptr) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700483 uint8_t c = (uint8_t) **pUtf8Ptr;
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700484 if (LIKELY(c <= 0x7f)) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700485 // It's low-ascii, so check the table.
486 uint32_t wordIdx = c >> 5;
487 uint32_t bitIdx = c & 0x1f;
488 (*pUtf8Ptr)++;
489 return (DEX_MEMBER_VALID_LOW_ASCII[wordIdx] & (1 << bitIdx)) != 0;
490 }
491
492 // It's a multibyte encoded character. Call a non-inline function
493 // for the heavy lifting.
jeffhao10037c82012-01-23 15:06:23 -0800494 return IsValidPartOfMemberNameUtf8Slow(pUtf8Ptr);
495}
496
497bool IsValidMemberName(const char* s) {
498 bool angle_name = false;
499
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700500 switch (*s) {
jeffhao10037c82012-01-23 15:06:23 -0800501 case '\0':
502 // The empty string is not a valid name.
503 return false;
504 case '<':
505 angle_name = true;
506 s++;
507 break;
508 }
509
510 while (true) {
511 switch (*s) {
512 case '\0':
513 return !angle_name;
514 case '>':
515 return angle_name && s[1] == '\0';
516 }
517
518 if (!IsValidPartOfMemberNameUtf8(&s)) {
519 return false;
520 }
521 }
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700522}
523
Elliott Hughes906e6852011-10-28 14:52:10 -0700524enum ClassNameType { kName, kDescriptor };
Ian Rogers7b078e82014-09-10 14:44:24 -0700525template<ClassNameType kType, char kSeparator>
526static bool IsValidClassName(const char* s) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700527 int arrayCount = 0;
528 while (*s == '[') {
529 arrayCount++;
530 s++;
531 }
532
533 if (arrayCount > 255) {
534 // Arrays may have no more than 255 dimensions.
535 return false;
536 }
537
Ian Rogers7b078e82014-09-10 14:44:24 -0700538 ClassNameType type = kType;
539 if (type != kDescriptor && arrayCount != 0) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700540 /*
541 * If we're looking at an array of some sort, then it doesn't
542 * matter if what is being asked for is a class name; the
543 * format looks the same as a type descriptor in that case, so
544 * treat it as such.
545 */
Elliott Hughes906e6852011-10-28 14:52:10 -0700546 type = kDescriptor;
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700547 }
548
Elliott Hughes906e6852011-10-28 14:52:10 -0700549 if (type == kDescriptor) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700550 /*
551 * We are looking for a descriptor. Either validate it as a
552 * single-character primitive type, or continue on to check the
553 * embedded class name (bracketed by "L" and ";").
554 */
555 switch (*(s++)) {
556 case 'B':
557 case 'C':
558 case 'D':
559 case 'F':
560 case 'I':
561 case 'J':
562 case 'S':
563 case 'Z':
564 // These are all single-character descriptors for primitive types.
565 return (*s == '\0');
566 case 'V':
567 // Non-array void is valid, but you can't have an array of void.
568 return (arrayCount == 0) && (*s == '\0');
569 case 'L':
570 // Class name: Break out and continue below.
571 break;
572 default:
573 // Oddball descriptor character.
574 return false;
575 }
576 }
577
578 /*
579 * We just consumed the 'L' that introduces a class name as part
580 * of a type descriptor, or we are looking for an unadorned class
581 * name.
582 */
583
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700584 bool sepOrFirst = true; // first character or just encountered a separator.
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700585 for (;;) {
586 uint8_t c = (uint8_t) *s;
587 switch (c) {
588 case '\0':
589 /*
590 * Premature end for a type descriptor, but valid for
591 * a class name as long as we haven't encountered an
592 * empty component (including the degenerate case of
593 * the empty string "").
594 */
Elliott Hughes906e6852011-10-28 14:52:10 -0700595 return (type == kName) && !sepOrFirst;
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700596 case ';':
597 /*
598 * Invalid character for a class name, but the
599 * legitimate end of a type descriptor. In the latter
600 * case, make sure that this is the end of the string
601 * and that it doesn't end with an empty component
602 * (including the degenerate case of "L;").
603 */
Elliott Hughes906e6852011-10-28 14:52:10 -0700604 return (type == kDescriptor) && !sepOrFirst && (s[1] == '\0');
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700605 case '/':
606 case '.':
Ian Rogers7b078e82014-09-10 14:44:24 -0700607 if (c != kSeparator) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700608 // The wrong separator character.
609 return false;
610 }
611 if (sepOrFirst) {
612 // Separator at start or two separators in a row.
613 return false;
614 }
615 sepOrFirst = true;
616 s++;
617 break;
618 default:
jeffhao10037c82012-01-23 15:06:23 -0800619 if (!IsValidPartOfMemberNameUtf8(&s)) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700620 return false;
621 }
622 sepOrFirst = false;
623 break;
624 }
625 }
626}
627
Elliott Hughes906e6852011-10-28 14:52:10 -0700628bool IsValidBinaryClassName(const char* s) {
Ian Rogers7b078e82014-09-10 14:44:24 -0700629 return IsValidClassName<kName, '.'>(s);
Elliott Hughes906e6852011-10-28 14:52:10 -0700630}
631
632bool IsValidJniClassName(const char* s) {
Ian Rogers7b078e82014-09-10 14:44:24 -0700633 return IsValidClassName<kName, '/'>(s);
Elliott Hughes906e6852011-10-28 14:52:10 -0700634}
635
636bool IsValidDescriptor(const char* s) {
Ian Rogers7b078e82014-09-10 14:44:24 -0700637 return IsValidClassName<kDescriptor, '/'>(s);
Elliott Hughes906e6852011-10-28 14:52:10 -0700638}
639
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700640void Split(const std::string& s, char separator, std::vector<std::string>* result) {
Elliott Hughes34023802011-08-30 12:06:17 -0700641 const char* p = s.data();
642 const char* end = p + s.size();
643 while (p != end) {
Elliott Hughes48436bb2012-02-07 15:23:28 -0800644 if (*p == separator) {
Elliott Hughes34023802011-08-30 12:06:17 -0700645 ++p;
646 } else {
647 const char* start = p;
Elliott Hughes48436bb2012-02-07 15:23:28 -0800648 while (++p != end && *p != separator) {
649 // Skip to the next occurrence of the separator.
Elliott Hughes34023802011-08-30 12:06:17 -0700650 }
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700651 result->push_back(std::string(start, p - start));
Elliott Hughes34023802011-08-30 12:06:17 -0700652 }
653 }
654}
655
Elliott Hughes22869a92012-03-27 14:08:24 -0700656void SetThreadName(const char* thread_name) {
Elliott Hughesdcc24742011-09-07 14:02:44 -0700657 int hasAt = 0;
658 int hasDot = 0;
Elliott Hughes22869a92012-03-27 14:08:24 -0700659 const char* s = thread_name;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700660 while (*s) {
661 if (*s == '.') {
662 hasDot = 1;
663 } else if (*s == '@') {
664 hasAt = 1;
665 }
666 s++;
667 }
Elliott Hughes22869a92012-03-27 14:08:24 -0700668 int len = s - thread_name;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700669 if (len < 15 || hasAt || !hasDot) {
Elliott Hughes22869a92012-03-27 14:08:24 -0700670 s = thread_name;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700671 } else {
Elliott Hughes22869a92012-03-27 14:08:24 -0700672 s = thread_name + len - 15;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700673 }
Elliott Hughes0a18df82015-01-09 15:16:16 -0800674#if defined(__linux__)
Elliott Hughes7c6a61e2012-03-12 18:01:41 -0700675 // pthread_setname_np fails rather than truncating long strings.
Elliott Hughes0a18df82015-01-09 15:16:16 -0800676 char buf[16]; // MAX_TASK_COMM_LEN=16 is hard-coded in the kernel.
Elliott Hughesdcc24742011-09-07 14:02:44 -0700677 strncpy(buf, s, sizeof(buf)-1);
678 buf[sizeof(buf)-1] = '\0';
679 errno = pthread_setname_np(pthread_self(), buf);
680 if (errno != 0) {
681 PLOG(WARNING) << "Unable to set the name of current thread to '" << buf << "'";
682 }
Elliott Hughes0a18df82015-01-09 15:16:16 -0800683#else // __APPLE__
Elliott Hughes22869a92012-03-27 14:08:24 -0700684 pthread_setname_np(thread_name);
Elliott Hughesdcc24742011-09-07 14:02:44 -0700685#endif
686}
687
Brian Carlstrom29212012013-09-12 22:18:30 -0700688void GetTaskStats(pid_t tid, char* state, int* utime, int* stime, int* task_cpu) {
689 *utime = *stime = *task_cpu = 0;
Elliott Hughesbfe487b2011-10-26 15:48:55 -0700690 std::string stats;
Elliott Hughes8a31b502012-04-30 19:36:11 -0700691 if (!ReadFileToString(StringPrintf("/proc/self/task/%d/stat", tid), &stats)) {
Elliott Hughesbfe487b2011-10-26 15:48:55 -0700692 return;
693 }
694 // Skip the command, which may contain spaces.
695 stats = stats.substr(stats.find(')') + 2);
696 // Extract the three fields we care about.
697 std::vector<std::string> fields;
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700698 Split(stats, ' ', &fields);
Brian Carlstrom29212012013-09-12 22:18:30 -0700699 *state = fields[0][0];
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700700 *utime = strtoull(fields[11].c_str(), nullptr, 10);
701 *stime = strtoull(fields[12].c_str(), nullptr, 10);
702 *task_cpu = strtoull(fields[36].c_str(), nullptr, 10);
Elliott Hughesbfe487b2011-10-26 15:48:55 -0700703}
704
Calin Juravle36eb3132017-01-13 16:32:38 -0800705static const char* GetAndroidDirSafe(const char* env_var,
706 const char* default_dir,
707 std::string* error_msg) {
708 const char* android_dir = getenv(env_var);
709 if (android_dir == nullptr) {
710 if (OS::DirectoryExists(default_dir)) {
711 android_dir = default_dir;
Brian Carlstroma9f19782011-10-13 00:14:47 -0700712 } else {
Calin Juravle36eb3132017-01-13 16:32:38 -0800713 *error_msg = StringPrintf("%s not set and %s does not exist", env_var, default_dir);
714 return nullptr;
Brian Carlstroma9f19782011-10-13 00:14:47 -0700715 }
716 }
Calin Juravle36eb3132017-01-13 16:32:38 -0800717 if (!OS::DirectoryExists(android_dir)) {
718 *error_msg = StringPrintf("Failed to find %s directory %s", env_var, android_dir);
719 return nullptr;
Brian Carlstroma9f19782011-10-13 00:14:47 -0700720 }
Calin Juravle36eb3132017-01-13 16:32:38 -0800721 return android_dir;
Brian Carlstroma56fcd62012-02-04 21:23:01 -0800722}
Brian Carlstroma9f19782011-10-13 00:14:47 -0700723
Calin Juravle36eb3132017-01-13 16:32:38 -0800724const char* GetAndroidDir(const char* env_var, const char* default_dir) {
Alex Lighta59dd802014-07-02 16:28:08 -0700725 std::string error_msg;
Calin Juravle36eb3132017-01-13 16:32:38 -0800726 const char* dir = GetAndroidDirSafe(env_var, default_dir, &error_msg);
Alex Lighta59dd802014-07-02 16:28:08 -0700727 if (dir != nullptr) {
728 return dir;
729 } else {
730 LOG(FATAL) << error_msg;
Calin Juravle36eb3132017-01-13 16:32:38 -0800731 return nullptr;
Alex Lighta59dd802014-07-02 16:28:08 -0700732 }
733}
734
Calin Juravle36eb3132017-01-13 16:32:38 -0800735const char* GetAndroidRoot() {
736 return GetAndroidDir("ANDROID_ROOT", "/system");
737}
738
739const char* GetAndroidRootSafe(std::string* error_msg) {
740 return GetAndroidDirSafe("ANDROID_ROOT", "/system", error_msg);
741}
742
743const char* GetAndroidData() {
744 return GetAndroidDir("ANDROID_DATA", "/data");
745}
746
Alex Lighta59dd802014-07-02 16:28:08 -0700747const char* GetAndroidDataSafe(std::string* error_msg) {
Calin Juravle36eb3132017-01-13 16:32:38 -0800748 return GetAndroidDirSafe("ANDROID_DATA", "/data", error_msg);
749}
750
751std::string GetDefaultBootImageLocation(std::string* error_msg) {
752 const char* android_root = GetAndroidRootSafe(error_msg);
753 if (android_root == nullptr) {
754 return "";
Brian Carlstroma56fcd62012-02-04 21:23:01 -0800755 }
Calin Juravle36eb3132017-01-13 16:32:38 -0800756 return StringPrintf("%s/framework/boot.art", android_root);
Brian Carlstroma56fcd62012-02-04 21:23:01 -0800757}
758
Alex Lighta59dd802014-07-02 16:28:08 -0700759void GetDalvikCache(const char* subdir, const bool create_if_absent, std::string* dalvik_cache,
Andreas Gampe3c13a792014-09-18 20:56:04 -0700760 bool* have_android_data, bool* dalvik_cache_exists, bool* is_global_cache) {
Alex Lighta59dd802014-07-02 16:28:08 -0700761 CHECK(subdir != nullptr);
762 std::string error_msg;
763 const char* android_data = GetAndroidDataSafe(&error_msg);
764 if (android_data == nullptr) {
765 *have_android_data = false;
766 *dalvik_cache_exists = false;
Andreas Gampe3c13a792014-09-18 20:56:04 -0700767 *is_global_cache = false;
Alex Lighta59dd802014-07-02 16:28:08 -0700768 return;
769 } else {
770 *have_android_data = true;
771 }
772 const std::string dalvik_cache_root(StringPrintf("%s/dalvik-cache/", android_data));
773 *dalvik_cache = dalvik_cache_root + subdir;
774 *dalvik_cache_exists = OS::DirectoryExists(dalvik_cache->c_str());
Andreas Gampe3c13a792014-09-18 20:56:04 -0700775 *is_global_cache = strcmp(android_data, "/data") == 0;
776 if (create_if_absent && !*dalvik_cache_exists && !*is_global_cache) {
Alex Lighta59dd802014-07-02 16:28:08 -0700777 // Don't create the system's /data/dalvik-cache/... because it needs special permissions.
778 *dalvik_cache_exists = ((mkdir(dalvik_cache_root.c_str(), 0700) == 0 || errno == EEXIST) &&
779 (mkdir(dalvik_cache->c_str(), 0700) == 0 || errno == EEXIST));
780 }
781}
782
Richard Uhler55b58b62016-08-12 09:05:13 -0700783std::string GetDalvikCache(const char* subdir) {
Narayan Kamath11d9f062014-04-23 20:24:57 +0100784 CHECK(subdir != nullptr);
Brian Carlstrom41ccffd2014-05-06 10:37:30 -0700785 const char* android_data = GetAndroidData();
786 const std::string dalvik_cache_root(StringPrintf("%s/dalvik-cache/", android_data));
Narayan Kamath11d9f062014-04-23 20:24:57 +0100787 const std::string dalvik_cache = dalvik_cache_root + subdir;
Andreas Gampe40da2862015-02-27 12:49:04 -0800788 if (!OS::DirectoryExists(dalvik_cache.c_str())) {
Richard Uhler55b58b62016-08-12 09:05:13 -0700789 // TODO: Check callers. Traditional behavior is to not abort.
790 return "";
Brian Carlstroma9f19782011-10-13 00:14:47 -0700791 }
Brian Carlstrom7675e162013-06-10 16:18:04 -0700792 return dalvik_cache;
Brian Carlstroma9f19782011-10-13 00:14:47 -0700793}
794
Alex Lighta59dd802014-07-02 16:28:08 -0700795bool GetDalvikCacheFilename(const char* location, const char* cache_location,
796 std::string* filename, std::string* error_msg) {
Ian Rogerse6060102013-05-16 12:01:04 -0700797 if (location[0] != '/') {
Alex Lighta59dd802014-07-02 16:28:08 -0700798 *error_msg = StringPrintf("Expected path in location to be absolute: %s", location);
799 return false;
Ian Rogerse6060102013-05-16 12:01:04 -0700800 }
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700801 std::string cache_file(&location[1]); // skip leading slash
Andreas Gampe9186ced2016-12-12 14:28:21 -0800802 if (!android::base::EndsWith(location, ".dex") &&
803 !android::base::EndsWith(location, ".art") &&
804 !android::base::EndsWith(location, ".oat")) {
Brian Carlstrom30e2ea42013-06-19 23:25:37 -0700805 cache_file += "/";
806 cache_file += DexFile::kClassesDex;
807 }
Brian Carlstromb7bbba42011-10-13 14:58:47 -0700808 std::replace(cache_file.begin(), cache_file.end(), '/', '@');
Alex Lighta59dd802014-07-02 16:28:08 -0700809 *filename = StringPrintf("%s/%s", cache_location, cache_file.c_str());
810 return true;
811}
812
Calin Juravle367b9d82017-05-15 18:18:39 -0700813std::string GetVdexFilename(const std::string& oat_location) {
814 return ReplaceFileExtension(oat_location, "vdex");
815}
816
Brian Carlstrom2afe4942014-05-19 10:25:33 -0700817static void InsertIsaDirectory(const InstructionSet isa, std::string* filename) {
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700818 // in = /foo/bar/baz
819 // out = /foo/bar/<isa>/baz
820 size_t pos = filename->rfind('/');
821 CHECK_NE(pos, std::string::npos) << *filename << " " << isa;
822 filename->insert(pos, "/", 1);
823 filename->insert(pos + 1, GetInstructionSetString(isa));
824}
825
826std::string GetSystemImageFilename(const char* location, const InstructionSet isa) {
827 // location = /system/framework/boot.art
828 // filename = /system/framework/<isa>/boot.art
829 std::string filename(location);
Brian Carlstrom2afe4942014-05-19 10:25:33 -0700830 InsertIsaDirectory(isa, &filename);
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700831 return filename;
832}
833
Calin Juravle5e2b9712015-12-18 14:10:00 +0200834bool FileExists(const std::string& filename) {
835 struct stat buffer;
836 return stat(filename.c_str(), &buffer) == 0;
837}
838
Calin Juravleb9c1b9b2016-03-17 17:07:52 +0000839bool FileExistsAndNotEmpty(const std::string& filename) {
840 struct stat buffer;
841 if (stat(filename.c_str(), &buffer) != 0) {
842 return false;
843 }
844 return buffer.st_size > 0;
845}
846
David Brazdil7b49e6c2016-09-01 11:06:18 +0100847std::string ReplaceFileExtension(const std::string& filename, const std::string& new_extension) {
848 const size_t last_ext = filename.find_last_of('.');
849 if (last_ext == std::string::npos) {
850 return filename + "." + new_extension;
851 } else {
852 return filename.substr(0, last_ext + 1) + new_extension;
853 }
854}
855
Mathieu Chartier76433272014-09-26 14:32:37 -0700856std::string PrettyDescriptor(Primitive::Type type) {
857 return PrettyDescriptor(Primitive::Descriptor(type));
858}
859
Nicolas Geoffrayabbb0f72015-10-29 18:55:58 +0000860static void ParseStringAfterChar(const std::string& s,
861 char c,
862 std::string* parsed_value,
863 UsageFn Usage) {
864 std::string::size_type colon = s.find(c);
865 if (colon == std::string::npos) {
866 Usage("Missing char %c in option %s\n", c, s.c_str());
867 }
868 // Add one to remove the char we were trimming until.
869 *parsed_value = s.substr(colon + 1);
870}
871
872void ParseDouble(const std::string& option,
873 char after_char,
874 double min,
875 double max,
876 double* parsed_value,
877 UsageFn Usage) {
878 std::string substring;
879 ParseStringAfterChar(option, after_char, &substring, Usage);
880 bool sane_val = true;
881 double value;
882 if ((false)) {
883 // TODO: this doesn't seem to work on the emulator. b/15114595
884 std::stringstream iss(substring);
885 iss >> value;
886 // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range.
887 sane_val = iss.eof() && (value >= min) && (value <= max);
888 } else {
889 char* end = nullptr;
890 value = strtod(substring.c_str(), &end);
891 sane_val = *end == '\0' && value >= min && value <= max;
892 }
893 if (!sane_val) {
894 Usage("Invalid double value %s for option %s\n", substring.c_str(), option.c_str());
895 }
896 *parsed_value = value;
897}
898
Calin Juravle4d77b6a2015-12-01 18:38:09 +0000899int64_t GetFileSizeBytes(const std::string& filename) {
900 struct stat stat_buf;
901 int rc = stat(filename.c_str(), &stat_buf);
902 return rc == 0 ? stat_buf.st_size : -1;
903}
904
Mathieu Chartier4d87df62016-01-07 15:14:19 -0800905void SleepForever() {
906 while (true) {
907 usleep(1000000);
908 }
909}
910
Mathieu Chartier120aa282017-08-05 16:03:03 -0700911int MadviseLargestPageAlignedRegion(const uint8_t* begin, const uint8_t* end, int advice) {
912 DCHECK_LE(begin, end);
913 begin = AlignUp(begin, kPageSize);
914 end = AlignDown(end, kPageSize);
915 if (begin < end) {
916 int result = madvise(const_cast<uint8_t*>(begin), end - begin, advice);
917 if (result != 0) {
918 PLOG(WARNING) << "madvise failed " << result;
919 }
920 return result;
921 }
922 return 0;
923}
924
Elliott Hughes42ee1422011-09-06 12:33:32 -0700925} // namespace art