blob: 4e35cd2867a0b13c6ab21eeeda8832346e15bb4a [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
Elliott Hughes06e3ad42012-02-07 14:51:57 -080019#include <dynamic_annotations.h>
Elliott Hughes92b3b562011-09-08 16:32:26 -070020#include <pthread.h>
Brian Carlstroma9f19782011-10-13 00:14:47 -070021#include <sys/stat.h>
Elliott Hughes42ee1422011-09-06 12:33:32 -070022#include <sys/syscall.h>
23#include <sys/types.h>
24#include <unistd.h>
25
Elliott Hughes90a33692011-08-30 13:27:07 -070026#include "UniquePtr.h"
Ian Rogersd81871c2011-10-03 13:57:23 -070027#include "class_loader.h"
buzbeec143c552011-08-20 17:38:58 -070028#include "file.h"
Elliott Hughes11e45072011-08-16 17:40:46 -070029#include "object.h"
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080030#include "object_utils.h"
buzbeec143c552011-08-20 17:38:58 -070031#include "os.h"
Elliott Hughes11e45072011-08-16 17:40:46 -070032
Elliott Hughesad6c9c32012-01-19 17:39:12 -080033#if !defined(HAVE_POSIX_CLOCKS)
34#include <sys/time.h>
35#endif
36
Elliott Hughesdcc24742011-09-07 14:02:44 -070037#if defined(HAVE_PRCTL)
38#include <sys/prctl.h>
39#endif
40
Elliott Hughes4ae722a2012-03-13 11:08:51 -070041#if defined(__APPLE__)
Elliott Hughesb08e8a32012-04-02 10:51:41 -070042#include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED
Elliott Hughesf1498432012-03-28 19:34:27 -070043#include <sys/syscall.h>
Elliott Hughes4ae722a2012-03-13 11:08:51 -070044#endif
45
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080046#if defined(__linux__)
Elliott Hughese1aee692012-01-17 16:40:10 -080047#include <linux/unistd.h>
Elliott Hughese1aee692012-01-17 16:40:10 -080048#endif
49
Elliott Hughes11e45072011-08-16 17:40:46 -070050namespace art {
51
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080052pid_t GetTid() {
Elliott Hughes5d6d5dc2012-03-29 11:59:27 -070053#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
54 // Darwin has a gettid(2), but it does something completely unrelated to tids.
55 // There is a thread_selfid(2) that does what we want though, and it seems to be what their
Elliott Hughesf1498432012-03-28 19:34:27 -070056 // pthreads implementation uses.
57 return syscall(SYS_thread_selfid);
Elliott Hughes5d6d5dc2012-03-29 11:59:27 -070058#elif defined(__APPLE__)
59 // On Mac OS 10.5 (which the build servers are still running) there was nothing usable.
Elliott Hughesd23f5202012-03-30 19:50:04 -070060 // We know we build 32-bit binaries and that the pthread_t is a pointer that uniquely identifies
61 // the calling thread.
62 return reinterpret_cast<pid_t>(pthread_self());
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080063#else
64 // Neither bionic nor glibc exposes gettid(2).
65 return syscall(__NR_gettid);
66#endif
67}
68
Elliott Hughese1884192012-04-23 12:38:15 -070069void GetThreadStack(void*& stack_base, size_t& stack_size) {
70#if defined(__APPLE__)
71 stack_size = pthread_get_stacksize_np(pthread_self());
72 void* stack_addr = pthread_get_stackaddr_np(pthread_self());
73
74 // Check whether stack_addr is the base or end of the stack.
75 // (On Mac OS 10.7, it's the end.)
76 int stack_variable;
77 if (stack_addr > &stack_variable) {
78 stack_base = reinterpret_cast<byte*>(stack_addr) - stack_size;
79 } else {
80 stack_base = stack_addr;
81 }
82#else
83 pthread_attr_t attributes;
84 CHECK_PTHREAD_CALL(pthread_getattr_np, (pthread_self(), &attributes), __FUNCTION__);
85 CHECK_PTHREAD_CALL(pthread_attr_getstack, (&attributes, &stack_base, &stack_size), __FUNCTION__);
86 CHECK_PTHREAD_CALL(pthread_attr_destroy, (&attributes), __FUNCTION__);
87#endif
88}
89
Elliott Hughesd92bec42011-09-02 17:04:36 -070090bool ReadFileToString(const std::string& file_name, std::string* result) {
91 UniquePtr<File> file(OS::OpenFile(file_name.c_str(), false));
92 if (file.get() == NULL) {
93 return false;
94 }
buzbeec143c552011-08-20 17:38:58 -070095
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070096 std::vector<char> buf(8 * KB);
buzbeec143c552011-08-20 17:38:58 -070097 while (true) {
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070098 int64_t n = file->Read(&buf[0], buf.size());
Elliott Hughesd92bec42011-09-02 17:04:36 -070099 if (n == -1) {
100 return false;
buzbeec143c552011-08-20 17:38:58 -0700101 }
Elliott Hughesd92bec42011-09-02 17:04:36 -0700102 if (n == 0) {
103 return true;
104 }
Elliott Hughes3b6baaa2011-10-14 19:13:56 -0700105 result->append(&buf[0], n);
buzbeec143c552011-08-20 17:38:58 -0700106 }
buzbeec143c552011-08-20 17:38:58 -0700107}
108
Elliott Hughese27955c2011-08-26 15:21:24 -0700109std::string GetIsoDate() {
110 time_t now = time(NULL);
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700111 tm tmbuf;
112 tm* ptm = localtime_r(&now, &tmbuf);
Elliott Hughese27955c2011-08-26 15:21:24 -0700113 return StringPrintf("%04d-%02d-%02d %02d:%02d:%02d",
114 ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday,
115 ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
116}
117
Elliott Hughes7162ad92011-10-27 14:08:42 -0700118uint64_t MilliTime() {
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800119#if defined(HAVE_POSIX_CLOCKS)
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700120 timespec now;
Elliott Hughes7162ad92011-10-27 14:08:42 -0700121 clock_gettime(CLOCK_MONOTONIC, &now);
122 return static_cast<uint64_t>(now.tv_sec) * 1000LL + now.tv_nsec / 1000000LL;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800123#else
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700124 timeval now;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800125 gettimeofday(&now, NULL);
126 return static_cast<uint64_t>(now.tv_sec) * 1000LL + now.tv_usec / 1000LL;
127#endif
Elliott Hughes7162ad92011-10-27 14:08:42 -0700128}
129
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800130uint64_t MicroTime() {
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800131#if defined(HAVE_POSIX_CLOCKS)
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700132 timespec now;
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800133 clock_gettime(CLOCK_MONOTONIC, &now);
134 return static_cast<uint64_t>(now.tv_sec) * 1000000LL + now.tv_nsec / 1000LL;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800135#else
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700136 timeval now;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800137 gettimeofday(&now, NULL);
TDYa12754825032012-04-11 10:45:23 -0700138 return static_cast<uint64_t>(now.tv_sec) * 1000000LL + now.tv_usec;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800139#endif
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800140}
141
Elliott Hughes83df2ac2011-10-11 16:37:54 -0700142uint64_t NanoTime() {
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800143#if defined(HAVE_POSIX_CLOCKS)
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700144 timespec now;
Elliott Hughes83df2ac2011-10-11 16:37:54 -0700145 clock_gettime(CLOCK_MONOTONIC, &now);
146 return static_cast<uint64_t>(now.tv_sec) * 1000000000LL + now.tv_nsec;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800147#else
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700148 timeval now;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800149 gettimeofday(&now, NULL);
150 return static_cast<uint64_t>(now.tv_sec) * 1000000000LL + now.tv_usec * 1000LL;
151#endif
Elliott Hughes83df2ac2011-10-11 16:37:54 -0700152}
153
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800154uint64_t ThreadCpuMicroTime() {
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800155#if defined(HAVE_POSIX_CLOCKS)
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700156 timespec now;
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800157 clock_gettime(CLOCK_THREAD_CPUTIME_ID, &now);
158 return static_cast<uint64_t>(now.tv_sec) * 1000000LL + now.tv_nsec / 1000LL;
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800159#else
160 UNIMPLEMENTED(WARNING);
161 return -1;
162#endif
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800163}
164
Elliott Hughes0512f022012-03-15 22:10:52 -0700165uint64_t ThreadCpuNanoTime() {
166#if defined(HAVE_POSIX_CLOCKS)
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700167 timespec now;
Elliott Hughes0512f022012-03-15 22:10:52 -0700168 clock_gettime(CLOCK_THREAD_CPUTIME_ID, &now);
169 return static_cast<uint64_t>(now.tv_sec) * 1000000000LL + now.tv_nsec;
170#else
171 UNIMPLEMENTED(WARNING);
172 return -1;
173#endif
174}
175
Elliott Hughes5174fe62011-08-23 15:12:35 -0700176std::string PrettyDescriptor(const String* java_descriptor) {
Brian Carlstrome24fa612011-09-29 00:53:55 -0700177 if (java_descriptor == NULL) {
178 return "null";
179 }
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700180 return PrettyDescriptor(java_descriptor->ToModifiedUtf8());
181}
Elliott Hughes5174fe62011-08-23 15:12:35 -0700182
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800183std::string PrettyDescriptor(const Class* klass) {
184 if (klass == NULL) {
185 return "null";
186 }
187 return PrettyDescriptor(ClassHelper(klass).GetDescriptor());
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800188}
189
Elliott Hughes6c8867d2011-10-03 16:34:05 -0700190std::string PrettyDescriptor(const std::string& descriptor) {
Elliott Hughes11e45072011-08-16 17:40:46 -0700191 // Count the number of '['s to get the dimensionality.
Elliott Hughes5174fe62011-08-23 15:12:35 -0700192 const char* c = descriptor.c_str();
Elliott Hughes11e45072011-08-16 17:40:46 -0700193 size_t dim = 0;
194 while (*c == '[') {
195 dim++;
196 c++;
197 }
198
199 // Reference or primitive?
200 if (*c == 'L') {
201 // "[[La/b/C;" -> "a.b.C[][]".
202 c++; // Skip the 'L'.
203 } else {
204 // "[[B" -> "byte[][]".
205 // To make life easier, we make primitives look like unqualified
206 // reference types.
207 switch (*c) {
208 case 'B': c = "byte;"; break;
209 case 'C': c = "char;"; break;
210 case 'D': c = "double;"; break;
211 case 'F': c = "float;"; break;
212 case 'I': c = "int;"; break;
213 case 'J': c = "long;"; break;
214 case 'S': c = "short;"; break;
215 case 'Z': c = "boolean;"; break;
Elliott Hughes9058f2b2012-03-22 18:06:48 -0700216 case 'V': c = "void;"; break; // Used when decoding return types.
Elliott Hughes5174fe62011-08-23 15:12:35 -0700217 default: return descriptor;
Elliott Hughes11e45072011-08-16 17:40:46 -0700218 }
219 }
220
221 // At this point, 'c' is a string of the form "fully/qualified/Type;"
222 // or "primitive;". Rewrite the type with '.' instead of '/':
223 std::string result;
224 const char* p = c;
225 while (*p != ';') {
226 char ch = *p++;
227 if (ch == '/') {
228 ch = '.';
229 }
230 result.push_back(ch);
231 }
232 // ...and replace the semicolon with 'dim' "[]" pairs:
233 while (dim--) {
234 result += "[]";
235 }
236 return result;
237}
238
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700239std::string PrettyDescriptor(Primitive::Type type) {
Elliott Hughes91250e02011-12-13 22:30:35 -0800240 std::string descriptor_string(Primitive::Descriptor(type));
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700241 return PrettyDescriptor(descriptor_string);
242}
243
Elliott Hughes54e7df12011-09-16 11:47:04 -0700244std::string PrettyField(const Field* f, bool with_type) {
Elliott Hughesa2501992011-08-26 19:39:54 -0700245 if (f == NULL) {
246 return "null";
247 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800248 FieldHelper fh(f);
Elliott Hughes54e7df12011-09-16 11:47:04 -0700249 std::string result;
250 if (with_type) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800251 result += PrettyDescriptor(fh.GetTypeDescriptor());
Elliott Hughes54e7df12011-09-16 11:47:04 -0700252 result += ' ';
253 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800254 result += PrettyDescriptor(fh.GetDeclaringClassDescriptor());
Elliott Hughesa2501992011-08-26 19:39:54 -0700255 result += '.';
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800256 result += fh.GetName();
Elliott Hughesa2501992011-08-26 19:39:54 -0700257 return result;
258}
259
Brian Carlstrom6f29d0e2012-05-11 15:50:29 -0700260std::string PrettyField(uint32_t field_idx, const DexFile& dex_file, bool with_type) {
261 const DexFile::FieldId& field_id = dex_file.GetFieldId(field_idx);
262 std::string result;
263 if (with_type) {
264 result += dex_file.GetFieldTypeDescriptor(field_id);
265 result += ' ';
266 }
267 result += PrettyDescriptor(dex_file.GetFieldDeclaringClassDescriptor(field_id));
268 result += '.';
269 result += dex_file.GetFieldName(field_id);
270 return result;
271}
272
Elliott Hughes9058f2b2012-03-22 18:06:48 -0700273std::string PrettyArguments(const char* signature) {
274 std::string result;
275 result += '(';
276 CHECK_EQ(*signature, '(');
277 ++signature; // Skip the '('.
278 while (*signature != ')') {
279 size_t argument_length = 0;
280 while (signature[argument_length] == '[') {
281 ++argument_length;
282 }
283 if (signature[argument_length] == 'L') {
284 argument_length = (strchr(signature, ';') - signature + 1);
285 } else {
286 ++argument_length;
287 }
288 std::string argument_descriptor(signature, argument_length);
289 result += PrettyDescriptor(argument_descriptor);
290 if (signature[argument_length] != ')') {
291 result += ", ";
292 }
293 signature += argument_length;
294 }
295 CHECK_EQ(*signature, ')');
296 ++signature; // Skip the ')'.
297 result += ')';
298 return result;
299}
300
301std::string PrettyReturnType(const char* signature) {
302 const char* return_type = strchr(signature, ')');
303 CHECK(return_type != NULL);
304 ++return_type; // Skip ')'.
305 return PrettyDescriptor(return_type);
306}
307
Elliott Hughesa0b8feb2011-08-20 09:50:55 -0700308std::string PrettyMethod(const Method* m, bool with_signature) {
309 if (m == NULL) {
310 return "null";
311 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800312 MethodHelper mh(m);
313 std::string result(PrettyDescriptor(mh.GetDeclaringClassDescriptor()));
Elliott Hughesa0b8feb2011-08-20 09:50:55 -0700314 result += '.';
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800315 result += mh.GetName();
Elliott Hughesa0b8feb2011-08-20 09:50:55 -0700316 if (with_signature) {
Elliott Hughes9058f2b2012-03-22 18:06:48 -0700317 std::string signature(mh.GetSignature());
Elliott Hughesf8c11932012-03-23 19:53:59 -0700318 if (signature == "<no signature>") {
319 return result + signature;
320 }
Elliott Hughes9058f2b2012-03-22 18:06:48 -0700321 result = PrettyReturnType(signature.c_str()) + " " + result + PrettyArguments(signature.c_str());
Elliott Hughesa0b8feb2011-08-20 09:50:55 -0700322 }
323 return result;
324}
325
Ian Rogers0571d352011-11-03 19:51:38 -0700326std::string PrettyMethod(uint32_t method_idx, const DexFile& dex_file, bool with_signature) {
327 const DexFile::MethodId& method_id = dex_file.GetMethodId(method_idx);
328 std::string result(PrettyDescriptor(dex_file.GetMethodDeclaringClassDescriptor(method_id)));
329 result += '.';
330 result += dex_file.GetMethodName(method_id);
331 if (with_signature) {
Elliott Hughes9058f2b2012-03-22 18:06:48 -0700332 std::string signature(dex_file.GetMethodSignature(method_id));
Elliott Hughesf8c11932012-03-23 19:53:59 -0700333 if (signature == "<no signature>") {
334 return result + signature;
335 }
Elliott Hughes9058f2b2012-03-22 18:06:48 -0700336 result = PrettyReturnType(signature.c_str()) + " " + result + PrettyArguments(signature.c_str());
Ian Rogers0571d352011-11-03 19:51:38 -0700337 }
338 return result;
339}
340
Elliott Hughes54e7df12011-09-16 11:47:04 -0700341std::string PrettyTypeOf(const Object* obj) {
Elliott Hughes11e45072011-08-16 17:40:46 -0700342 if (obj == NULL) {
343 return "null";
344 }
345 if (obj->GetClass() == NULL) {
346 return "(raw)";
347 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800348 ClassHelper kh(obj->GetClass());
349 std::string result(PrettyDescriptor(kh.GetDescriptor()));
Elliott Hughes11e45072011-08-16 17:40:46 -0700350 if (obj->IsClass()) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800351 kh.ChangeClass(obj->AsClass());
352 result += "<" + PrettyDescriptor(kh.GetDescriptor()) + ">";
Elliott Hughes11e45072011-08-16 17:40:46 -0700353 }
354 return result;
355}
356
Elliott Hughes54e7df12011-09-16 11:47:04 -0700357std::string PrettyClass(const Class* c) {
358 if (c == NULL) {
359 return "null";
360 }
361 std::string result;
362 result += "java.lang.Class<";
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800363 result += PrettyDescriptor(c);
Elliott Hughes54e7df12011-09-16 11:47:04 -0700364 result += ">";
365 return result;
366}
367
Ian Rogersd81871c2011-10-03 13:57:23 -0700368std::string PrettyClassAndClassLoader(const Class* c) {
369 if (c == NULL) {
370 return "null";
371 }
372 std::string result;
373 result += "java.lang.Class<";
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800374 result += PrettyDescriptor(c);
Ian Rogersd81871c2011-10-03 13:57:23 -0700375 result += ",";
376 result += PrettyTypeOf(c->GetClassLoader());
377 // TODO: add an identifying hash value for the loader
378 result += ">";
379 return result;
380}
381
Elliott Hughesc967f782012-04-16 10:23:15 -0700382std::string PrettySize(size_t byte_count) {
383 // The byte thresholds at which we display amounts. A byte count is displayed
384 // in unit U when kUnitThresholds[U] <= bytes < kUnitThresholds[U+1].
385 static const size_t kUnitThresholds[] = {
386 0, // B up to...
387 3*1024, // KB up to...
388 2*1024*1024, // MB up to...
389 1024*1024*1024 // GB from here.
390 };
391 static const size_t kBytesPerUnit[] = { 1, KB, MB, GB };
392 static const char* const kUnitStrings[] = { "B", "KB", "MB", "GB" };
393
394 int i = arraysize(kUnitThresholds);
395 while (--i > 0) {
396 if (byte_count >= kUnitThresholds[i]) {
397 break;
398 }
Ian Rogers3bb17a62012-01-27 23:56:44 -0800399 }
Elliott Hughesc967f782012-04-16 10:23:15 -0700400
401 return StringPrintf("%zd%s", byte_count / kBytesPerUnit[i], kUnitStrings[i]);
Ian Rogers3bb17a62012-01-27 23:56:44 -0800402}
403
404std::string PrettyDuration(uint64_t nano_duration) {
405 if (nano_duration == 0) {
406 return "0";
407 } else {
408 const uint64_t one_sec = 1000 * 1000 * 1000;
409 const uint64_t one_ms = 1000 * 1000;
410 const uint64_t one_us = 1000;
411 const char* unit;
412 uint64_t divisor;
413 uint32_t zero_fill;
414 if (nano_duration >= one_sec) {
415 unit = "s";
416 divisor = one_sec;
417 zero_fill = 9;
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700418 } else if (nano_duration >= one_ms) {
Ian Rogers3bb17a62012-01-27 23:56:44 -0800419 unit = "ms";
420 divisor = one_ms;
421 zero_fill = 6;
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700422 } else if (nano_duration >= one_us) {
Ian Rogers3bb17a62012-01-27 23:56:44 -0800423 unit = "us";
424 divisor = one_us;
425 zero_fill = 3;
426 } else {
427 unit = "ns";
428 divisor = 1;
429 zero_fill = 0;
430 }
431 uint64_t whole_part = nano_duration / divisor;
432 uint64_t fractional_part = nano_duration % divisor;
433 if (fractional_part == 0) {
434 return StringPrintf("%llu%s", whole_part, unit);
435 } else {
436 while ((fractional_part % 1000) == 0) {
437 zero_fill -= 3;
438 fractional_part /= 1000;
439 }
440 if (zero_fill == 3) {
441 return StringPrintf("%llu.%03llu%s", whole_part, fractional_part, unit);
442 } else if (zero_fill == 6) {
443 return StringPrintf("%llu.%06llu%s", whole_part, fractional_part, unit);
444 } else {
445 return StringPrintf("%llu.%09llu%s", whole_part, fractional_part, unit);
446 }
447 }
448 }
449}
450
Elliott Hughes82914b62012-04-09 15:56:29 -0700451std::string PrintableString(const std::string& utf) {
452 std::string result;
453 result += '"';
454 const char* p = utf.c_str();
455 size_t char_count = CountModifiedUtf8Chars(p);
456 for (size_t i = 0; i < char_count; ++i) {
457 uint16_t ch = GetUtf16FromUtf8(&p);
458 if (ch == '\\') {
459 result += "\\\\";
460 } else if (ch == '\n') {
461 result += "\\n";
462 } else if (ch == '\r') {
463 result += "\\r";
464 } else if (ch == '\t') {
465 result += "\\t";
466 } else if (NeedsEscaping(ch)) {
467 StringAppendF(&result, "\\u%04x", ch);
468 } else {
469 result += ch;
470 }
471 }
472 result += '"';
473 return result;
474}
475
Elliott Hughesd8c00d02012-01-30 14:08:31 -0800476// 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 -0700477std::string MangleForJni(const std::string& s) {
478 std::string result;
479 size_t char_count = CountModifiedUtf8Chars(s.c_str());
480 const char* cp = &s[0];
481 for (size_t i = 0; i < char_count; ++i) {
482 uint16_t ch = GetUtf16FromUtf8(&cp);
Elliott Hughesd8c00d02012-01-30 14:08:31 -0800483 if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) {
484 result.push_back(ch);
485 } else if (ch == '.' || ch == '/') {
486 result += "_";
487 } else if (ch == '_') {
488 result += "_1";
489 } else if (ch == ';') {
490 result += "_2";
491 } else if (ch == '[') {
492 result += "_3";
Elliott Hughes79082e32011-08-25 12:07:32 -0700493 } else {
Elliott Hughesd8c00d02012-01-30 14:08:31 -0800494 StringAppendF(&result, "_0%04x", ch);
Elliott Hughes79082e32011-08-25 12:07:32 -0700495 }
496 }
497 return result;
498}
499
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700500std::string DotToDescriptor(const char* class_name) {
501 std::string descriptor(class_name);
502 std::replace(descriptor.begin(), descriptor.end(), '.', '/');
503 if (descriptor.length() > 0 && descriptor[0] != '[') {
504 descriptor = "L" + descriptor + ";";
505 }
506 return descriptor;
507}
508
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800509std::string DescriptorToDot(const char* descriptor) {
Elliott Hughes2435a572012-02-17 16:07:41 -0800510 size_t length = strlen(descriptor);
511 if (descriptor[0] == 'L' && descriptor[length - 1] == ';') {
512 std::string result(descriptor + 1, length - 2);
513 std::replace(result.begin(), result.end(), '/', '.');
514 return result;
515 }
516 return descriptor;
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800517}
518
519std::string DescriptorToName(const char* descriptor) {
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800520 size_t length = strlen(descriptor);
Elliott Hughes2435a572012-02-17 16:07:41 -0800521 if (descriptor[0] == 'L' && descriptor[length - 1] == ';') {
522 std::string result(descriptor + 1, length - 2);
523 return result;
524 }
525 return descriptor;
Brian Carlstromaded5f72011-10-07 17:15:04 -0700526}
527
Elliott Hughes79082e32011-08-25 12:07:32 -0700528std::string JniShortName(const Method* m) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800529 MethodHelper mh(m);
530 std::string class_name(mh.GetDeclaringClassDescriptor());
Elliott Hughes79082e32011-08-25 12:07:32 -0700531 // Remove the leading 'L' and trailing ';'...
Elliott Hughesf5a7a472011-10-07 14:31:02 -0700532 CHECK_EQ(class_name[0], 'L') << class_name;
533 CHECK_EQ(class_name[class_name.size() - 1], ';') << class_name;
Elliott Hughes79082e32011-08-25 12:07:32 -0700534 class_name.erase(0, 1);
535 class_name.erase(class_name.size() - 1, 1);
536
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800537 std::string method_name(mh.GetName());
Elliott Hughes79082e32011-08-25 12:07:32 -0700538
539 std::string short_name;
540 short_name += "Java_";
541 short_name += MangleForJni(class_name);
542 short_name += "_";
543 short_name += MangleForJni(method_name);
544 return short_name;
545}
546
547std::string JniLongName(const Method* m) {
548 std::string long_name;
549 long_name += JniShortName(m);
550 long_name += "__";
551
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800552 std::string signature(MethodHelper(m).GetSignature());
Elliott Hughes79082e32011-08-25 12:07:32 -0700553 signature.erase(0, 1);
554 signature.erase(signature.begin() + signature.find(')'), signature.end());
555
556 long_name += MangleForJni(signature);
557
558 return long_name;
559}
560
jeffhao10037c82012-01-23 15:06:23 -0800561// Helper for IsValidPartOfMemberNameUtf8(), a bit vector indicating valid low ascii.
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700562uint32_t DEX_MEMBER_VALID_LOW_ASCII[4] = {
563 0x00000000, // 00..1f low control characters; nothing valid
564 0x03ff2010, // 20..3f digits and symbols; valid: '0'..'9', '$', '-'
565 0x87fffffe, // 40..5f uppercase etc.; valid: 'A'..'Z', '_'
566 0x07fffffe // 60..7f lowercase etc.; valid: 'a'..'z'
567};
568
jeffhao10037c82012-01-23 15:06:23 -0800569// Helper for IsValidPartOfMemberNameUtf8(); do not call directly.
570bool IsValidPartOfMemberNameUtf8Slow(const char** pUtf8Ptr) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700571 /*
572 * It's a multibyte encoded character. Decode it and analyze. We
573 * accept anything that isn't (a) an improperly encoded low value,
574 * (b) an improper surrogate pair, (c) an encoded '\0', (d) a high
575 * control character, or (e) a high space, layout, or special
576 * character (U+00a0, U+2000..U+200f, U+2028..U+202f,
577 * U+fff0..U+ffff). This is all specified in the dex format
578 * document.
579 */
580
581 uint16_t utf16 = GetUtf16FromUtf8(pUtf8Ptr);
582
583 // Perform follow-up tests based on the high 8 bits.
584 switch (utf16 >> 8) {
585 case 0x00:
586 // It's only valid if it's above the ISO-8859-1 high space (0xa0).
587 return (utf16 > 0x00a0);
588 case 0xd8:
589 case 0xd9:
590 case 0xda:
591 case 0xdb:
592 // It's a leading surrogate. Check to see that a trailing
593 // surrogate follows.
594 utf16 = GetUtf16FromUtf8(pUtf8Ptr);
595 return (utf16 >= 0xdc00) && (utf16 <= 0xdfff);
596 case 0xdc:
597 case 0xdd:
598 case 0xde:
599 case 0xdf:
600 // It's a trailing surrogate, which is not valid at this point.
601 return false;
602 case 0x20:
603 case 0xff:
604 // It's in the range that has spaces, controls, and specials.
605 switch (utf16 & 0xfff8) {
606 case 0x2000:
607 case 0x2008:
608 case 0x2028:
609 case 0xfff0:
610 case 0xfff8:
611 return false;
612 }
613 break;
614 }
615 return true;
616}
617
618/* Return whether the pointed-at modified-UTF-8 encoded character is
619 * valid as part of a member name, updating the pointer to point past
620 * the consumed character. This will consume two encoded UTF-16 code
621 * points if the character is encoded as a surrogate pair. Also, if
622 * this function returns false, then the given pointer may only have
623 * been partially advanced.
624 */
jeffhao10037c82012-01-23 15:06:23 -0800625bool IsValidPartOfMemberNameUtf8(const char** pUtf8Ptr) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700626 uint8_t c = (uint8_t) **pUtf8Ptr;
627 if (c <= 0x7f) {
628 // It's low-ascii, so check the table.
629 uint32_t wordIdx = c >> 5;
630 uint32_t bitIdx = c & 0x1f;
631 (*pUtf8Ptr)++;
632 return (DEX_MEMBER_VALID_LOW_ASCII[wordIdx] & (1 << bitIdx)) != 0;
633 }
634
635 // It's a multibyte encoded character. Call a non-inline function
636 // for the heavy lifting.
jeffhao10037c82012-01-23 15:06:23 -0800637 return IsValidPartOfMemberNameUtf8Slow(pUtf8Ptr);
638}
639
640bool IsValidMemberName(const char* s) {
641 bool angle_name = false;
642
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700643 switch (*s) {
jeffhao10037c82012-01-23 15:06:23 -0800644 case '\0':
645 // The empty string is not a valid name.
646 return false;
647 case '<':
648 angle_name = true;
649 s++;
650 break;
651 }
652
653 while (true) {
654 switch (*s) {
655 case '\0':
656 return !angle_name;
657 case '>':
658 return angle_name && s[1] == '\0';
659 }
660
661 if (!IsValidPartOfMemberNameUtf8(&s)) {
662 return false;
663 }
664 }
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700665}
666
Elliott Hughes906e6852011-10-28 14:52:10 -0700667enum ClassNameType { kName, kDescriptor };
668bool IsValidClassName(const char* s, ClassNameType type, char separator) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700669 int arrayCount = 0;
670 while (*s == '[') {
671 arrayCount++;
672 s++;
673 }
674
675 if (arrayCount > 255) {
676 // Arrays may have no more than 255 dimensions.
677 return false;
678 }
679
680 if (arrayCount != 0) {
681 /*
682 * If we're looking at an array of some sort, then it doesn't
683 * matter if what is being asked for is a class name; the
684 * format looks the same as a type descriptor in that case, so
685 * treat it as such.
686 */
Elliott Hughes906e6852011-10-28 14:52:10 -0700687 type = kDescriptor;
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700688 }
689
Elliott Hughes906e6852011-10-28 14:52:10 -0700690 if (type == kDescriptor) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700691 /*
692 * We are looking for a descriptor. Either validate it as a
693 * single-character primitive type, or continue on to check the
694 * embedded class name (bracketed by "L" and ";").
695 */
696 switch (*(s++)) {
697 case 'B':
698 case 'C':
699 case 'D':
700 case 'F':
701 case 'I':
702 case 'J':
703 case 'S':
704 case 'Z':
705 // These are all single-character descriptors for primitive types.
706 return (*s == '\0');
707 case 'V':
708 // Non-array void is valid, but you can't have an array of void.
709 return (arrayCount == 0) && (*s == '\0');
710 case 'L':
711 // Class name: Break out and continue below.
712 break;
713 default:
714 // Oddball descriptor character.
715 return false;
716 }
717 }
718
719 /*
720 * We just consumed the 'L' that introduces a class name as part
721 * of a type descriptor, or we are looking for an unadorned class
722 * name.
723 */
724
725 bool sepOrFirst = true; // first character or just encountered a separator.
726 for (;;) {
727 uint8_t c = (uint8_t) *s;
728 switch (c) {
729 case '\0':
730 /*
731 * Premature end for a type descriptor, but valid for
732 * a class name as long as we haven't encountered an
733 * empty component (including the degenerate case of
734 * the empty string "").
735 */
Elliott Hughes906e6852011-10-28 14:52:10 -0700736 return (type == kName) && !sepOrFirst;
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700737 case ';':
738 /*
739 * Invalid character for a class name, but the
740 * legitimate end of a type descriptor. In the latter
741 * case, make sure that this is the end of the string
742 * and that it doesn't end with an empty component
743 * (including the degenerate case of "L;").
744 */
Elliott Hughes906e6852011-10-28 14:52:10 -0700745 return (type == kDescriptor) && !sepOrFirst && (s[1] == '\0');
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700746 case '/':
747 case '.':
748 if (c != separator) {
749 // The wrong separator character.
750 return false;
751 }
752 if (sepOrFirst) {
753 // Separator at start or two separators in a row.
754 return false;
755 }
756 sepOrFirst = true;
757 s++;
758 break;
759 default:
jeffhao10037c82012-01-23 15:06:23 -0800760 if (!IsValidPartOfMemberNameUtf8(&s)) {
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700761 return false;
762 }
763 sepOrFirst = false;
764 break;
765 }
766 }
767}
768
Elliott Hughes906e6852011-10-28 14:52:10 -0700769bool IsValidBinaryClassName(const char* s) {
770 return IsValidClassName(s, kName, '.');
771}
772
773bool IsValidJniClassName(const char* s) {
774 return IsValidClassName(s, kName, '/');
775}
776
777bool IsValidDescriptor(const char* s) {
778 return IsValidClassName(s, kDescriptor, '/');
779}
780
Elliott Hughes48436bb2012-02-07 15:23:28 -0800781void Split(const std::string& s, char separator, std::vector<std::string>& result) {
Elliott Hughes34023802011-08-30 12:06:17 -0700782 const char* p = s.data();
783 const char* end = p + s.size();
784 while (p != end) {
Elliott Hughes48436bb2012-02-07 15:23:28 -0800785 if (*p == separator) {
Elliott Hughes34023802011-08-30 12:06:17 -0700786 ++p;
787 } else {
788 const char* start = p;
Elliott Hughes48436bb2012-02-07 15:23:28 -0800789 while (++p != end && *p != separator) {
790 // Skip to the next occurrence of the separator.
Elliott Hughes34023802011-08-30 12:06:17 -0700791 }
792 result.push_back(std::string(start, p - start));
793 }
794 }
795}
796
Elliott Hughes48436bb2012-02-07 15:23:28 -0800797template <typename StringT>
798std::string Join(std::vector<StringT>& strings, char separator) {
799 if (strings.empty()) {
800 return "";
801 }
802
803 std::string result(strings[0]);
804 for (size_t i = 1; i < strings.size(); ++i) {
805 result += separator;
806 result += strings[i];
807 }
808 return result;
809}
810
811// Explicit instantiations.
812template std::string Join<std::string>(std::vector<std::string>& strings, char separator);
813template std::string Join<const char*>(std::vector<const char*>& strings, char separator);
814template std::string Join<char*>(std::vector<char*>& strings, char separator);
815
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800816bool StartsWith(const std::string& s, const char* prefix) {
817 return s.compare(0, strlen(prefix), prefix) == 0;
818}
819
Brian Carlstrom7a967b32012-03-28 15:23:10 -0700820bool EndsWith(const std::string& s, const char* suffix) {
821 size_t suffix_length = strlen(suffix);
822 size_t string_length = s.size();
823 if (suffix_length > string_length) {
824 return false;
825 }
826 size_t offset = string_length - suffix_length;
827 return s.compare(offset, suffix_length, suffix) == 0;
828}
829
Elliott Hughes22869a92012-03-27 14:08:24 -0700830void SetThreadName(const char* thread_name) {
831 ANNOTATE_THREAD_NAME(thread_name); // For tsan.
Elliott Hughes06e3ad42012-02-07 14:51:57 -0800832
Elliott Hughesdcc24742011-09-07 14:02:44 -0700833 int hasAt = 0;
834 int hasDot = 0;
Elliott Hughes22869a92012-03-27 14:08:24 -0700835 const char* s = thread_name;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700836 while (*s) {
837 if (*s == '.') {
838 hasDot = 1;
839 } else if (*s == '@') {
840 hasAt = 1;
841 }
842 s++;
843 }
Elliott Hughes22869a92012-03-27 14:08:24 -0700844 int len = s - thread_name;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700845 if (len < 15 || hasAt || !hasDot) {
Elliott Hughes22869a92012-03-27 14:08:24 -0700846 s = thread_name;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700847 } else {
Elliott Hughes22869a92012-03-27 14:08:24 -0700848 s = thread_name + len - 15;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700849 }
850#if defined(HAVE_ANDROID_PTHREAD_SETNAME_NP)
Elliott Hughes7c6a61e2012-03-12 18:01:41 -0700851 // pthread_setname_np fails rather than truncating long strings.
Elliott Hughesdcc24742011-09-07 14:02:44 -0700852 char buf[16]; // MAX_TASK_COMM_LEN=16 is hard-coded into bionic
853 strncpy(buf, s, sizeof(buf)-1);
854 buf[sizeof(buf)-1] = '\0';
855 errno = pthread_setname_np(pthread_self(), buf);
856 if (errno != 0) {
857 PLOG(WARNING) << "Unable to set the name of current thread to '" << buf << "'";
858 }
Elliott Hughes4ae722a2012-03-13 11:08:51 -0700859#elif defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
Elliott Hughes22869a92012-03-27 14:08:24 -0700860 pthread_setname_np(thread_name);
Elliott Hughesdcc24742011-09-07 14:02:44 -0700861#elif defined(HAVE_PRCTL)
Elliott Hughes398f64b2012-03-26 18:05:48 -0700862 prctl(PR_SET_NAME, (unsigned long) s, 0, 0, 0); // NOLINT (unsigned long)
Elliott Hughesdcc24742011-09-07 14:02:44 -0700863#else
Elliott Hughes22869a92012-03-27 14:08:24 -0700864 UNIMPLEMENTED(WARNING) << thread_name;
Elliott Hughesdcc24742011-09-07 14:02:44 -0700865#endif
866}
867
Elliott Hughesbfe487b2011-10-26 15:48:55 -0700868void GetTaskStats(pid_t tid, int& utime, int& stime, int& task_cpu) {
869 utime = stime = task_cpu = 0;
870 std::string stats;
Elliott Hughes8a31b502012-04-30 19:36:11 -0700871 if (!ReadFileToString(StringPrintf("/proc/self/task/%d/stat", tid), &stats)) {
Elliott Hughesbfe487b2011-10-26 15:48:55 -0700872 return;
873 }
874 // Skip the command, which may contain spaces.
875 stats = stats.substr(stats.find(')') + 2);
876 // Extract the three fields we care about.
877 std::vector<std::string> fields;
878 Split(stats, ' ', fields);
879 utime = strtoull(fields[11].c_str(), NULL, 10);
880 stime = strtoull(fields[12].c_str(), NULL, 10);
881 task_cpu = strtoull(fields[36].c_str(), NULL, 10);
882}
883
Elliott Hughes1bac54f2012-03-16 12:48:31 -0700884std::string GetSchedulerGroupName(pid_t tid) {
885 // /proc/<pid>/cgroup looks like this:
886 // 2:devices:/
887 // 1:cpuacct,cpu:/
888 // We want the third field from the line whose second field contains the "cpu" token.
889 std::string cgroup_file;
890 if (!ReadFileToString(StringPrintf("/proc/self/task/%d/cgroup", tid), &cgroup_file)) {
891 return "";
892 }
893 std::vector<std::string> cgroup_lines;
894 Split(cgroup_file, '\n', cgroup_lines);
895 for (size_t i = 0; i < cgroup_lines.size(); ++i) {
896 std::vector<std::string> cgroup_fields;
897 Split(cgroup_lines[i], ':', cgroup_fields);
898 std::vector<std::string> cgroups;
899 Split(cgroup_fields[1], ',', cgroups);
900 for (size_t i = 0; i < cgroups.size(); ++i) {
901 if (cgroups[i] == "cpu") {
902 return cgroup_fields[2].substr(1); // Skip the leading slash.
903 }
904 }
905 }
906 return "";
907}
908
Brian Carlstroma56fcd62012-02-04 21:23:01 -0800909const char* GetAndroidRoot() {
910 const char* android_root = getenv("ANDROID_ROOT");
911 if (android_root == NULL) {
912 if (OS::DirectoryExists("/system")) {
913 android_root = "/system";
Brian Carlstroma9f19782011-10-13 00:14:47 -0700914 } else {
Brian Carlstroma56fcd62012-02-04 21:23:01 -0800915 LOG(FATAL) << "ANDROID_ROOT not set and /system does not exist";
916 return "";
Brian Carlstroma9f19782011-10-13 00:14:47 -0700917 }
918 }
Brian Carlstroma56fcd62012-02-04 21:23:01 -0800919 if (!OS::DirectoryExists(android_root)) {
920 LOG(FATAL) << "Failed to find ANDROID_ROOT directory " << android_root;
Brian Carlstroma9f19782011-10-13 00:14:47 -0700921 return "";
922 }
Brian Carlstroma56fcd62012-02-04 21:23:01 -0800923 return android_root;
924}
Brian Carlstroma9f19782011-10-13 00:14:47 -0700925
Brian Carlstroma56fcd62012-02-04 21:23:01 -0800926const char* GetAndroidData() {
927 const char* android_data = getenv("ANDROID_DATA");
928 if (android_data == NULL) {
929 if (OS::DirectoryExists("/data")) {
930 android_data = "/data";
931 } else {
932 LOG(FATAL) << "ANDROID_DATA not set and /data does not exist";
933 return "";
934 }
935 }
936 if (!OS::DirectoryExists(android_data)) {
937 LOG(FATAL) << "Failed to find ANDROID_DATA directory " << android_data;
938 return "";
939 }
940 return android_data;
941}
942
Shih-wei Liao795e3302012-04-21 00:20:57 -0700943std::string GetArtCacheOrDie(const char* android_data) {
944 std::string art_cache(StringPrintf("%s/art-cache", android_data));
Brian Carlstroma9f19782011-10-13 00:14:47 -0700945
946 if (!OS::DirectoryExists(art_cache.c_str())) {
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800947 if (StartsWith(art_cache, "/tmp/")) {
Brian Carlstroma9f19782011-10-13 00:14:47 -0700948 int result = mkdir(art_cache.c_str(), 0700);
949 if (result != 0) {
950 LOG(FATAL) << "Failed to create art-cache directory " << art_cache;
951 return "";
952 }
953 } else {
954 LOG(FATAL) << "Failed to find art-cache directory " << art_cache;
955 return "";
956 }
957 }
958 return art_cache;
959}
960
jeffhao262bf462011-10-20 18:36:32 -0700961std::string GetArtCacheFilenameOrDie(const std::string& location) {
Shih-wei Liao795e3302012-04-21 00:20:57 -0700962 std::string art_cache(GetArtCacheOrDie(GetAndroidData()));
Elliott Hughesc308a5d2012-02-16 17:12:06 -0800963 CHECK_EQ(location[0], '/') << location;
Brian Carlstromb7bbba42011-10-13 14:58:47 -0700964 std::string cache_file(location, 1); // skip leading slash
965 std::replace(cache_file.begin(), cache_file.end(), '/', '@');
966 return art_cache + "/" + cache_file;
967}
968
jeffhao262bf462011-10-20 18:36:32 -0700969bool IsValidZipFilename(const std::string& filename) {
970 if (filename.size() < 4) {
971 return false;
972 }
973 std::string suffix(filename.substr(filename.size() - 4));
974 return (suffix == ".zip" || suffix == ".jar" || suffix == ".apk");
975}
976
977bool IsValidDexFilename(const std::string& filename) {
Brian Carlstrom7a967b32012-03-28 15:23:10 -0700978 return EndsWith(filename, ".dex");
979}
980
981bool IsValidOatFilename(const std::string& filename) {
982 return EndsWith(filename, ".oat");
jeffhao262bf462011-10-20 18:36:32 -0700983}
984
Elliott Hughes42ee1422011-09-06 12:33:32 -0700985} // namespace art