dex2oat.cc revision 6cc5076a1248582cf16bd9a6a1719e0a4c1a1de2
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 */ 16 17#include <stdio.h> 18#include <stdlib.h> 19#include <sys/stat.h> 20#include <valgrind.h> 21 22#include <fstream> 23#include <iostream> 24#include <sstream> 25#include <string> 26#include <vector> 27 28#ifndef __APPLE__ 29#include <malloc.h> // For mallinfo 30#endif 31 32#if defined(__linux__) && defined(__arm__) 33#include <sys/personality.h> 34#include <sys/utsname.h> 35#endif 36 37#include "base/stl_util.h" 38#include "base/stringpiece.h" 39#include "base/timing_logger.h" 40#include "base/unix_file/fd_file.h" 41#include "class_linker.h" 42#include "compiler.h" 43#include "compiler_callbacks.h" 44#include "dex_file-inl.h" 45#include "dex/pass_driver_me_opts.h" 46#include "dex/verification_results.h" 47#include "dex/quick_compiler_callbacks.h" 48#include "dex/quick/dex_file_to_method_inliner_map.h" 49#include "driver/compiler_driver.h" 50#include "driver/compiler_options.h" 51#include "elf_fixup.h" 52#include "elf_patcher.h" 53#include "elf_stripper.h" 54#include "gc/space/image_space.h" 55#include "gc/space/space-inl.h" 56#include "image_writer.h" 57#include "leb128.h" 58#include "mirror/art_method-inl.h" 59#include "mirror/class-inl.h" 60#include "mirror/class_loader.h" 61#include "mirror/object-inl.h" 62#include "mirror/object_array-inl.h" 63#include "oat_writer.h" 64#include "os.h" 65#include "runtime.h" 66#include "ScopedLocalRef.h" 67#include "scoped_thread_state_change.h" 68#include "utils.h" 69#include "vector_output_stream.h" 70#include "well_known_classes.h" 71#include "zip_archive.h" 72 73namespace art { 74 75static int original_argc; 76static char** original_argv; 77 78static std::string CommandLine() { 79 std::vector<std::string> command; 80 for (int i = 0; i < original_argc; ++i) { 81 command.push_back(original_argv[i]); 82 } 83 return Join(command, ' '); 84} 85 86static void UsageErrorV(const char* fmt, va_list ap) { 87 std::string error; 88 StringAppendV(&error, fmt, ap); 89 LOG(ERROR) << error; 90} 91 92static void UsageError(const char* fmt, ...) { 93 va_list ap; 94 va_start(ap, fmt); 95 UsageErrorV(fmt, ap); 96 va_end(ap); 97} 98 99static void Usage(const char* fmt, ...) { 100 va_list ap; 101 va_start(ap, fmt); 102 UsageErrorV(fmt, ap); 103 va_end(ap); 104 105 UsageError("Command: %s", CommandLine().c_str()); 106 107 UsageError("Usage: dex2oat [options]..."); 108 UsageError(""); 109 UsageError(" --dex-file=<dex-file>: specifies a .dex file to compile."); 110 UsageError(" Example: --dex-file=/system/framework/core.jar"); 111 UsageError(""); 112 UsageError(" --zip-fd=<file-descriptor>: specifies a file descriptor of a zip file"); 113 UsageError(" containing a classes.dex file to compile."); 114 UsageError(" Example: --zip-fd=5"); 115 UsageError(""); 116 UsageError(" --zip-location=<zip-location>: specifies a symbolic name for the file"); 117 UsageError(" corresponding to the file descriptor specified by --zip-fd."); 118 UsageError(" Example: --zip-location=/system/app/Calculator.apk"); 119 UsageError(""); 120 UsageError(" --oat-file=<file.oat>: specifies the oat output destination via a filename."); 121 UsageError(" Example: --oat-file=/system/framework/boot.oat"); 122 UsageError(""); 123 UsageError(" --oat-fd=<number>: specifies the oat output destination via a file descriptor."); 124 UsageError(" Example: --oat-fd=6"); 125 UsageError(""); 126 UsageError(" --oat-location=<oat-name>: specifies a symbolic name for the file corresponding"); 127 UsageError(" to the file descriptor specified by --oat-fd."); 128 UsageError(" Example: --oat-location=/data/dalvik-cache/system@app@Calculator.apk.oat"); 129 UsageError(""); 130 UsageError(" --oat-symbols=<file.oat>: specifies the oat output destination with full symbols."); 131 UsageError(" Example: --oat-symbols=/symbols/system/framework/boot.oat"); 132 UsageError(""); 133 UsageError(" --bitcode=<file.bc>: specifies the optional bitcode filename."); 134 UsageError(" Example: --bitcode=/system/framework/boot.bc"); 135 UsageError(""); 136 UsageError(" --image=<file.art>: specifies the output image filename."); 137 UsageError(" Example: --image=/system/framework/boot.art"); 138 UsageError(""); 139 UsageError(" --image-classes=<classname-file>: specifies classes to include in an image."); 140 UsageError(" Example: --image=frameworks/base/preloaded-classes"); 141 UsageError(""); 142 UsageError(" --base=<hex-address>: specifies the base address when creating a boot image."); 143 UsageError(" Example: --base=0x50000000"); 144 UsageError(""); 145 UsageError(" --boot-image=<file.art>: provide the image file for the boot class path."); 146 UsageError(" Example: --boot-image=/system/framework/boot.art"); 147 UsageError(" Default: $ANDROID_ROOT/system/framework/boot.art"); 148 UsageError(""); 149 UsageError(" --android-root=<path>: used to locate libraries for portable linking."); 150 UsageError(" Example: --android-root=out/host/linux-x86"); 151 UsageError(" Default: $ANDROID_ROOT"); 152 UsageError(""); 153 UsageError(" --instruction-set=(arm|arm64|mips|x86|x86_64): compile for a particular"); 154 UsageError(" instruction set."); 155 UsageError(" Example: --instruction-set=x86"); 156 UsageError(" Default: arm"); 157 UsageError(""); 158 UsageError(" --instruction-set-features=...,: Specify instruction set features"); 159 UsageError(" Example: --instruction-set-features=div"); 160 UsageError(" Default: default"); 161 UsageError(""); 162 UsageError(" --compile-pic: Force indirect use of code, methods, and classes"); 163 UsageError(" Default: disabled"); 164 UsageError(""); 165 UsageError(" --compiler-backend=(Quick|Optimizing|Portable): select compiler backend"); 166 UsageError(" set."); 167 UsageError(" Example: --compiler-backend=Portable"); 168 UsageError(" Default: Quick"); 169 UsageError(""); 170 UsageError(" --compiler-filter=(verify-none|interpret-only|space|balanced|speed|everything):"); 171 UsageError(" select compiler filter."); 172 UsageError(" Example: --compiler-filter=everything"); 173#if ART_SMALL_MODE 174 UsageError(" Default: interpret-only"); 175#else 176 UsageError(" Default: speed"); 177#endif 178 UsageError(""); 179 UsageError(" --huge-method-max=<method-instruction-count>: the threshold size for a huge"); 180 UsageError(" method for compiler filter tuning."); 181 UsageError(" Example: --huge-method-max=%d", CompilerOptions::kDefaultHugeMethodThreshold); 182 UsageError(" Default: %d", CompilerOptions::kDefaultHugeMethodThreshold); 183 UsageError(""); 184 UsageError(" --huge-method-max=<method-instruction-count>: threshold size for a huge"); 185 UsageError(" method for compiler filter tuning."); 186 UsageError(" Example: --huge-method-max=%d", CompilerOptions::kDefaultHugeMethodThreshold); 187 UsageError(" Default: %d", CompilerOptions::kDefaultHugeMethodThreshold); 188 UsageError(""); 189 UsageError(" --large-method-max=<method-instruction-count>: threshold size for a large"); 190 UsageError(" method for compiler filter tuning."); 191 UsageError(" Example: --large-method-max=%d", CompilerOptions::kDefaultLargeMethodThreshold); 192 UsageError(" Default: %d", CompilerOptions::kDefaultLargeMethodThreshold); 193 UsageError(""); 194 UsageError(" --small-method-max=<method-instruction-count>: threshold size for a small"); 195 UsageError(" method for compiler filter tuning."); 196 UsageError(" Example: --small-method-max=%d", CompilerOptions::kDefaultSmallMethodThreshold); 197 UsageError(" Default: %d", CompilerOptions::kDefaultSmallMethodThreshold); 198 UsageError(""); 199 UsageError(" --tiny-method-max=<method-instruction-count>: threshold size for a tiny"); 200 UsageError(" method for compiler filter tuning."); 201 UsageError(" Example: --tiny-method-max=%d", CompilerOptions::kDefaultTinyMethodThreshold); 202 UsageError(" Default: %d", CompilerOptions::kDefaultTinyMethodThreshold); 203 UsageError(""); 204 UsageError(" --num-dex-methods=<method-count>: threshold size for a small dex file for"); 205 UsageError(" compiler filter tuning. If the input has fewer than this many methods"); 206 UsageError(" and the filter is not interpret-only or verify-none, overrides the"); 207 UsageError(" filter to use speed"); 208 UsageError(" Example: --num-dex-method=%d", CompilerOptions::kDefaultNumDexMethodsThreshold); 209 UsageError(" Default: %d", CompilerOptions::kDefaultNumDexMethodsThreshold); 210 UsageError(""); 211 UsageError(" --host: used with Portable backend to link against host runtime libraries"); 212 UsageError(""); 213 UsageError(" --dump-timing: display a breakdown of where time was spent"); 214 UsageError(""); 215 UsageError(" --include-patch-information: Include patching information so the generated code"); 216 UsageError(" can have its base address moved without full recompilation."); 217 UsageError(""); 218 UsageError(" --no-include-patch-information: Do not include patching information."); 219 UsageError(""); 220 UsageError(" --include-debug-symbols: Include ELF symbols in this oat file"); 221 UsageError(""); 222 UsageError(" --no-include-debug-symbols: Do not include ELF symbols in this oat file"); 223 UsageError(""); 224 UsageError(" --runtime-arg <argument>: used to specify various arguments for the runtime,"); 225 UsageError(" such as initial heap size, maximum heap size, and verbose output."); 226 UsageError(" Use a separate --runtime-arg switch for each argument."); 227 UsageError(" Example: --runtime-arg -Xms256m"); 228 UsageError(""); 229 UsageError(" --profile-file=<filename>: specify profiler output file to use for compilation."); 230 UsageError(""); 231 UsageError(" --print-pass-names: print a list of pass names"); 232 UsageError(""); 233 UsageError(" --disable-passes=<pass-names>: disable one or more passes separated by comma."); 234 UsageError(" Example: --disable-passes=UseCount,BBOptimizations"); 235 UsageError(""); 236 std::cerr << "See log for usage error information\n"; 237 exit(EXIT_FAILURE); 238} 239 240class Dex2Oat { 241 public: 242 static bool Create(Dex2Oat** p_dex2oat, 243 const RuntimeOptions& runtime_options, 244 const CompilerOptions& compiler_options, 245 Compiler::Kind compiler_kind, 246 InstructionSet instruction_set, 247 InstructionSetFeatures instruction_set_features, 248 VerificationResults* verification_results, 249 DexFileToMethodInlinerMap* method_inliner_map, 250 size_t thread_count) 251 SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_) { 252 CHECK(verification_results != nullptr); 253 CHECK(method_inliner_map != nullptr); 254 std::unique_ptr<Dex2Oat> dex2oat(new Dex2Oat(&compiler_options, 255 compiler_kind, 256 instruction_set, 257 instruction_set_features, 258 verification_results, 259 method_inliner_map, 260 thread_count)); 261 if (!dex2oat->CreateRuntime(runtime_options, instruction_set)) { 262 *p_dex2oat = nullptr; 263 return false; 264 } 265 *p_dex2oat = dex2oat.release(); 266 return true; 267 } 268 269 ~Dex2Oat() { 270 delete runtime_; 271 } 272 273 void LogCompletionTime(const CompilerDriver* compiler) { 274 std::ostringstream mallinfostr; 275#ifdef HAVE_MALLOC_H 276 struct mallinfo info = mallinfo(); 277 const size_t allocated_space = static_cast<size_t>(info.uordblks); 278 const size_t free_space = static_cast<size_t>(info.fordblks); 279 mallinfostr << " native alloc=" << PrettySize(allocated_space) << " free=" 280 << PrettySize(free_space); 281#endif 282 const ArenaPool* arena_pool = compiler->GetArenaPool(); 283 gc::Heap* heap = Runtime::Current()->GetHeap(); 284 LOG(INFO) << "dex2oat took " << PrettyDuration(NanoTime() - start_ns_) 285 << " (threads: " << thread_count_ << ")" 286 << " arena alloc=" << PrettySize(arena_pool->GetBytesAllocated()) 287 << " java alloc=" << PrettySize(heap->GetBytesAllocated()) << mallinfostr.str(); 288 } 289 290 291 // Reads the class names (java.lang.Object) and returns a set of descriptors (Ljava/lang/Object;) 292 std::set<std::string>* ReadImageClassesFromFile(const char* image_classes_filename) { 293 std::unique_ptr<std::ifstream> image_classes_file(new std::ifstream(image_classes_filename, 294 std::ifstream::in)); 295 if (image_classes_file.get() == nullptr) { 296 LOG(ERROR) << "Failed to open image classes file " << image_classes_filename; 297 return nullptr; 298 } 299 std::unique_ptr<std::set<std::string>> result(ReadImageClasses(*image_classes_file)); 300 image_classes_file->close(); 301 return result.release(); 302 } 303 304 std::set<std::string>* ReadImageClasses(std::istream& image_classes_stream) { 305 std::unique_ptr<std::set<std::string>> image_classes(new std::set<std::string>); 306 while (image_classes_stream.good()) { 307 std::string dot; 308 std::getline(image_classes_stream, dot); 309 if (StartsWith(dot, "#") || dot.empty()) { 310 continue; 311 } 312 std::string descriptor(DotToDescriptor(dot.c_str())); 313 image_classes->insert(descriptor); 314 } 315 return image_classes.release(); 316 } 317 318 // Reads the class names (java.lang.Object) and returns a set of descriptors (Ljava/lang/Object;) 319 std::set<std::string>* ReadImageClassesFromZip(const char* zip_filename, 320 const char* image_classes_filename, 321 std::string* error_msg) { 322 std::unique_ptr<ZipArchive> zip_archive(ZipArchive::Open(zip_filename, error_msg)); 323 if (zip_archive.get() == nullptr) { 324 return nullptr; 325 } 326 std::unique_ptr<ZipEntry> zip_entry(zip_archive->Find(image_classes_filename, error_msg)); 327 if (zip_entry.get() == nullptr) { 328 *error_msg = StringPrintf("Failed to find '%s' within '%s': %s", image_classes_filename, 329 zip_filename, error_msg->c_str()); 330 return nullptr; 331 } 332 std::unique_ptr<MemMap> image_classes_file(zip_entry->ExtractToMemMap(zip_filename, 333 image_classes_filename, 334 error_msg)); 335 if (image_classes_file.get() == nullptr) { 336 *error_msg = StringPrintf("Failed to extract '%s' from '%s': %s", image_classes_filename, 337 zip_filename, error_msg->c_str()); 338 return nullptr; 339 } 340 const std::string image_classes_string(reinterpret_cast<char*>(image_classes_file->Begin()), 341 image_classes_file->Size()); 342 std::istringstream image_classes_stream(image_classes_string); 343 return ReadImageClasses(image_classes_stream); 344 } 345 346 bool PatchOatCode(const CompilerDriver* compiler_driver, File* oat_file, 347 const std::string& oat_location, std::string* error_msg) { 348 // We asked to include patch information but we are not making an image. We need to fix 349 // everything up manually. 350 std::unique_ptr<ElfFile> elf_file(ElfFile::Open(oat_file, PROT_READ|PROT_WRITE, 351 MAP_SHARED, error_msg)); 352 if (elf_file.get() == NULL) { 353 LOG(ERROR) << error_msg; 354 return false; 355 } 356 { 357 ReaderMutexLock mu(Thread::Current(), *Locks::mutator_lock_); 358 return ElfPatcher::Patch(compiler_driver, elf_file.get(), oat_location, error_msg); 359 } 360 } 361 362 const CompilerDriver* CreateOatFile(const std::string& boot_image_option, 363 const std::string& android_root, 364 bool is_host, 365 const std::vector<const DexFile*>& dex_files, 366 File* oat_file, 367 const std::string& oat_location, 368 const std::string& bitcode_filename, 369 bool image, 370 std::unique_ptr<std::set<std::string>>& image_classes, 371 std::unique_ptr<std::set<std::string>>& compiled_classes, 372 bool dump_stats, 373 bool dump_passes, 374 TimingLogger& timings, 375 CumulativeLogger& compiler_phases_timings, 376 std::string profile_file, 377 SafeMap<std::string, std::string>* key_value_store) { 378 CHECK(key_value_store != nullptr); 379 380 // Handle and ClassLoader creation needs to come after Runtime::Create 381 jobject class_loader = nullptr; 382 Thread* self = Thread::Current(); 383 if (!boot_image_option.empty()) { 384 ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); 385 std::vector<const DexFile*> class_path_files(dex_files); 386 OpenClassPathFiles(runtime_->GetClassPathString(), class_path_files); 387 ScopedObjectAccess soa(self); 388 for (size_t i = 0; i < class_path_files.size(); i++) { 389 class_linker->RegisterDexFile(*class_path_files[i]); 390 } 391 soa.Env()->AllocObject(WellKnownClasses::dalvik_system_PathClassLoader); 392 ScopedLocalRef<jobject> class_loader_local(soa.Env(), 393 soa.Env()->AllocObject(WellKnownClasses::dalvik_system_PathClassLoader)); 394 class_loader = soa.Env()->NewGlobalRef(class_loader_local.get()); 395 Runtime::Current()->SetCompileTimeClassPath(class_loader, class_path_files); 396 } 397 398 std::unique_ptr<CompilerDriver> driver(new CompilerDriver(compiler_options_, 399 verification_results_, 400 method_inliner_map_, 401 compiler_kind_, 402 instruction_set_, 403 instruction_set_features_, 404 image, 405 image_classes.release(), 406 compiled_classes.release(), 407 thread_count_, 408 dump_stats, 409 dump_passes, 410 &compiler_phases_timings, 411 profile_file)); 412 413 driver->GetCompiler()->SetBitcodeFileName(*driver.get(), bitcode_filename); 414 415 driver->CompileAll(class_loader, dex_files, &timings); 416 417 TimingLogger::ScopedTiming t2("dex2oat OatWriter", &timings); 418 std::string image_file_location; 419 uint32_t image_file_location_oat_checksum = 0; 420 uintptr_t image_file_location_oat_data_begin = 0; 421 int32_t image_patch_delta = 0; 422 if (!driver->IsImage()) { 423 TimingLogger::ScopedTiming t3("Loading image checksum", &timings); 424 gc::space::ImageSpace* image_space = Runtime::Current()->GetHeap()->GetImageSpace(); 425 image_file_location_oat_checksum = image_space->GetImageHeader().GetOatChecksum(); 426 image_file_location_oat_data_begin = 427 reinterpret_cast<uintptr_t>(image_space->GetImageHeader().GetOatDataBegin()); 428 image_file_location = image_space->GetImageFilename(); 429 image_patch_delta = image_space->GetImageHeader().GetPatchDelta(); 430 } 431 432 if (!image_file_location.empty()) { 433 key_value_store->Put(OatHeader::kImageLocationKey, image_file_location); 434 } 435 436 OatWriter oat_writer(dex_files, image_file_location_oat_checksum, 437 image_file_location_oat_data_begin, 438 image_patch_delta, 439 driver.get(), 440 &timings, 441 key_value_store); 442 443 t2.NewTiming("Writing ELF"); 444 if (!driver->WriteElf(android_root, is_host, dex_files, &oat_writer, oat_file)) { 445 LOG(ERROR) << "Failed to write ELF file " << oat_file->GetPath(); 446 return nullptr; 447 } 448 449 // Flush result to disk. Patching code will re-open the file (mmap), so ensure that our view 450 // of the file already made it there and won't be re-ordered with writes from PatchOat or 451 // image patching. 452 if (oat_file->Flush() != 0) { 453 PLOG(ERROR) << "Failed flushing oat file " << oat_file->GetPath(); 454 oat_file->Erase(); 455 return nullptr; 456 } 457 458 if (!driver->IsImage() && driver->GetCompilerOptions().GetIncludePatchInformation()) { 459 t2.NewTiming("Patching ELF"); 460 std::string error_msg; 461 if (!PatchOatCode(driver.get(), oat_file, oat_location, &error_msg)) { 462 LOG(ERROR) << "Failed to fixup ELF file " << oat_file->GetPath() << ": " << error_msg; 463 return nullptr; 464 } 465 } 466 467 return driver.release(); 468 } 469 470 bool CreateImageFile(const std::string& image_filename, 471 uintptr_t image_base, 472 const std::string& oat_filename, 473 const std::string& oat_location, 474 const CompilerDriver& compiler) 475 LOCKS_EXCLUDED(Locks::mutator_lock_) { 476 uintptr_t oat_data_begin; 477 { 478 // ImageWriter is scoped so it can free memory before doing FixupElf 479 ImageWriter image_writer(compiler); 480 if (!image_writer.Write(image_filename, image_base, oat_filename, oat_location, 481 compiler_options_->GetCompilePic())) { 482 LOG(ERROR) << "Failed to create image file " << image_filename; 483 return false; 484 } 485 oat_data_begin = image_writer.GetOatDataBegin(); 486 } 487 488 489 // Do not fix up the ELF file if we are --compile-pic 490 if (!compiler_options_->GetCompilePic()) { 491 std::unique_ptr<File> oat_file(OS::OpenFileReadWrite(oat_filename.c_str())); 492 if (oat_file.get() == nullptr) { 493 PLOG(ERROR) << "Failed to open ELF file: " << oat_filename; 494 return false; 495 } 496 497 if (!ElfFixup::Fixup(oat_file.get(), oat_data_begin)) { 498 LOG(ERROR) << "Failed to fixup ELF file " << oat_file->GetPath(); 499 oat_file->Erase(); 500 return false; 501 } 502 503 if (oat_file->FlushCloseOrErase() != 0) { 504 PLOG(ERROR) << "Failed to flush and close patched oat file " << oat_filename; 505 return false; 506 } 507 } 508 509 return true; 510 } 511 512 private: 513 explicit Dex2Oat(const CompilerOptions* compiler_options, 514 Compiler::Kind compiler_kind, 515 InstructionSet instruction_set, 516 InstructionSetFeatures instruction_set_features, 517 VerificationResults* verification_results, 518 DexFileToMethodInlinerMap* method_inliner_map, 519 size_t thread_count) 520 : compiler_options_(compiler_options), 521 compiler_kind_(compiler_kind), 522 instruction_set_(instruction_set), 523 instruction_set_features_(instruction_set_features), 524 verification_results_(verification_results), 525 method_inliner_map_(method_inliner_map), 526 runtime_(nullptr), 527 thread_count_(thread_count), 528 start_ns_(NanoTime()) { 529 CHECK(compiler_options != nullptr); 530 CHECK(verification_results != nullptr); 531 CHECK(method_inliner_map != nullptr); 532 } 533 534 bool CreateRuntime(const RuntimeOptions& runtime_options, InstructionSet instruction_set) 535 SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_) { 536 if (!Runtime::Create(runtime_options, false)) { 537 LOG(ERROR) << "Failed to create runtime"; 538 return false; 539 } 540 Runtime* runtime = Runtime::Current(); 541 runtime->SetInstructionSet(instruction_set); 542 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { 543 Runtime::CalleeSaveType type = Runtime::CalleeSaveType(i); 544 if (!runtime->HasCalleeSaveMethod(type)) { 545 runtime->SetCalleeSaveMethod(runtime->CreateCalleeSaveMethod(type), type); 546 } 547 } 548 runtime->GetClassLinker()->FixupDexCaches(runtime->GetResolutionMethod()); 549 runtime->GetClassLinker()->RunRootClinits(); 550 runtime_ = runtime; 551 return true; 552 } 553 554 // Appends to dex_files any elements of class_path that it doesn't already 555 // contain. This will open those dex files as necessary. 556 static void OpenClassPathFiles(const std::string& class_path, 557 std::vector<const DexFile*>& dex_files) { 558 std::vector<std::string> parsed; 559 Split(class_path, ':', parsed); 560 // Take Locks::mutator_lock_ so that lock ordering on the ClassLinker::dex_lock_ is maintained. 561 ScopedObjectAccess soa(Thread::Current()); 562 for (size_t i = 0; i < parsed.size(); ++i) { 563 if (DexFilesContains(dex_files, parsed[i])) { 564 continue; 565 } 566 std::string error_msg; 567 if (!DexFile::Open(parsed[i].c_str(), parsed[i].c_str(), &error_msg, &dex_files)) { 568 LOG(WARNING) << "Failed to open dex file '" << parsed[i] << "': " << error_msg; 569 } 570 } 571 } 572 573 // Returns true if dex_files has a dex with the named location. 574 static bool DexFilesContains(const std::vector<const DexFile*>& dex_files, 575 const std::string& location) { 576 for (size_t i = 0; i < dex_files.size(); ++i) { 577 if (dex_files[i]->GetLocation() == location) { 578 return true; 579 } 580 } 581 return false; 582 } 583 584 const CompilerOptions* const compiler_options_; 585 const Compiler::Kind compiler_kind_; 586 587 const InstructionSet instruction_set_; 588 const InstructionSetFeatures instruction_set_features_; 589 590 VerificationResults* const verification_results_; 591 DexFileToMethodInlinerMap* const method_inliner_map_; 592 Runtime* runtime_; 593 size_t thread_count_; 594 uint64_t start_ns_; 595 596 DISALLOW_IMPLICIT_CONSTRUCTORS(Dex2Oat); 597}; 598 599static size_t OpenDexFiles(const std::vector<const char*>& dex_filenames, 600 const std::vector<const char*>& dex_locations, 601 std::vector<const DexFile*>& dex_files) { 602 size_t failure_count = 0; 603 for (size_t i = 0; i < dex_filenames.size(); i++) { 604 const char* dex_filename = dex_filenames[i]; 605 const char* dex_location = dex_locations[i]; 606 ATRACE_BEGIN(StringPrintf("Opening dex file '%s'", dex_filenames[i]).c_str()); 607 std::string error_msg; 608 if (!OS::FileExists(dex_filename)) { 609 LOG(WARNING) << "Skipping non-existent dex file '" << dex_filename << "'"; 610 continue; 611 } 612 if (!DexFile::Open(dex_filename, dex_location, &error_msg, &dex_files)) { 613 LOG(WARNING) << "Failed to open .dex from file '" << dex_filename << "': " << error_msg; 614 ++failure_count; 615 } 616 ATRACE_END(); 617 } 618 return failure_count; 619} 620 621// The primary goal of the watchdog is to prevent stuck build servers 622// during development when fatal aborts lead to a cascade of failures 623// that result in a deadlock. 624class WatchDog { 625// WatchDog defines its own CHECK_PTHREAD_CALL to avoid using Log which uses locks 626#undef CHECK_PTHREAD_CALL 627#define CHECK_WATCH_DOG_PTHREAD_CALL(call, args, what) \ 628 do { \ 629 int rc = call args; \ 630 if (rc != 0) { \ 631 errno = rc; \ 632 std::string message(# call); \ 633 message += " failed for "; \ 634 message += reason; \ 635 Fatal(message); \ 636 } \ 637 } while (false) 638 639 public: 640 explicit WatchDog(bool is_watch_dog_enabled) { 641 is_watch_dog_enabled_ = is_watch_dog_enabled; 642 if (!is_watch_dog_enabled_) { 643 return; 644 } 645 shutting_down_ = false; 646 const char* reason = "dex2oat watch dog thread startup"; 647 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_mutex_init, (&mutex_, nullptr), reason); 648 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_cond_init, (&cond_, nullptr), reason); 649 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_attr_init, (&attr_), reason); 650 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_create, (&pthread_, &attr_, &CallBack, this), reason); 651 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_attr_destroy, (&attr_), reason); 652 } 653 ~WatchDog() { 654 if (!is_watch_dog_enabled_) { 655 return; 656 } 657 const char* reason = "dex2oat watch dog thread shutdown"; 658 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_mutex_lock, (&mutex_), reason); 659 shutting_down_ = true; 660 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_cond_signal, (&cond_), reason); 661 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_mutex_unlock, (&mutex_), reason); 662 663 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_join, (pthread_, nullptr), reason); 664 665 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_cond_destroy, (&cond_), reason); 666 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_mutex_destroy, (&mutex_), reason); 667 } 668 669 private: 670 static void* CallBack(void* arg) { 671 WatchDog* self = reinterpret_cast<WatchDog*>(arg); 672 ::art::SetThreadName("dex2oat watch dog"); 673 self->Wait(); 674 return nullptr; 675 } 676 677 static void Message(char severity, const std::string& message) { 678 // TODO: Remove when we switch to LOG when we can guarantee it won't prevent shutdown in error 679 // cases. 680 fprintf(stderr, "dex2oat%s %c %d %d %s\n", 681 kIsDebugBuild ? "d" : "", 682 severity, 683 getpid(), 684 GetTid(), 685 message.c_str()); 686 } 687 688 static void Warn(const std::string& message) { 689 Message('W', message); 690 } 691 692 static void Fatal(const std::string& message) { 693 Message('F', message); 694 exit(1); 695 } 696 697 void Wait() { 698 bool warning = true; 699 CHECK_GT(kWatchDogTimeoutSeconds, kWatchDogWarningSeconds); 700 // TODO: tune the multiplier for GC verification, the following is just to make the timeout 701 // large. 702 int64_t multiplier = kVerifyObjectSupport > kVerifyObjectModeFast ? 100 : 1; 703 timespec warning_ts; 704 InitTimeSpec(true, CLOCK_REALTIME, multiplier * kWatchDogWarningSeconds * 1000, 0, &warning_ts); 705 timespec timeout_ts; 706 InitTimeSpec(true, CLOCK_REALTIME, multiplier * kWatchDogTimeoutSeconds * 1000, 0, &timeout_ts); 707 const char* reason = "dex2oat watch dog thread waiting"; 708 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_mutex_lock, (&mutex_), reason); 709 while (!shutting_down_) { 710 int rc = TEMP_FAILURE_RETRY(pthread_cond_timedwait(&cond_, &mutex_, 711 warning ? &warning_ts 712 : &timeout_ts)); 713 if (rc == ETIMEDOUT) { 714 std::string message(StringPrintf("dex2oat did not finish after %d seconds", 715 warning ? kWatchDogWarningSeconds 716 : kWatchDogTimeoutSeconds)); 717 if (warning) { 718 Warn(message.c_str()); 719 warning = false; 720 } else { 721 Fatal(message.c_str()); 722 } 723 } else if (rc != 0) { 724 std::string message(StringPrintf("pthread_cond_timedwait failed: %s", 725 strerror(errno))); 726 Fatal(message.c_str()); 727 } 728 } 729 CHECK_WATCH_DOG_PTHREAD_CALL(pthread_mutex_unlock, (&mutex_), reason); 730 } 731 732 // When setting timeouts, keep in mind that the build server may not be as fast as your desktop. 733 // Debug builds are slower so they have larger timeouts. 734 static const unsigned int kSlowdownFactor = kIsDebugBuild ? 5U : 1U; 735#if ART_USE_PORTABLE_COMPILER 736 // 2 minutes scaled by kSlowdownFactor. 737 static const unsigned int kWatchDogWarningSeconds = kSlowdownFactor * 2 * 60; 738 // 30 minutes scaled by kSlowdownFactor. 739 static const unsigned int kWatchDogTimeoutSeconds = kSlowdownFactor * 30 * 60; 740#else 741 // 1 minutes scaled by kSlowdownFactor. 742 static const unsigned int kWatchDogWarningSeconds = kSlowdownFactor * 1 * 60; 743 // 6 minutes scaled by kSlowdownFactor. 744 static const unsigned int kWatchDogTimeoutSeconds = kSlowdownFactor * 6 * 60; 745#endif 746 747 bool is_watch_dog_enabled_; 748 bool shutting_down_; 749 // TODO: Switch to Mutex when we can guarantee it won't prevent shutdown in error cases. 750 pthread_mutex_t mutex_; 751 pthread_cond_t cond_; 752 pthread_attr_t attr_; 753 pthread_t pthread_; 754}; 755const unsigned int WatchDog::kWatchDogWarningSeconds; 756const unsigned int WatchDog::kWatchDogTimeoutSeconds; 757 758// Given a set of instruction features from the build, parse it. The 759// input 'str' is a comma separated list of feature names. Parse it and 760// return the InstructionSetFeatures object. 761static InstructionSetFeatures ParseFeatureList(std::string str) { 762 InstructionSetFeatures result; 763 typedef std::vector<std::string> FeatureList; 764 FeatureList features; 765 Split(str, ',', features); 766 for (FeatureList::iterator i = features.begin(); i != features.end(); i++) { 767 std::string feature = Trim(*i); 768 if (feature == "default") { 769 // Nothing to do. 770 } else if (feature == "div") { 771 // Supports divide instruction. 772 result.SetHasDivideInstruction(true); 773 } else if (feature == "nodiv") { 774 // Turn off support for divide instruction. 775 result.SetHasDivideInstruction(false); 776 } else if (feature == "lpae") { 777 // Supports Large Physical Address Extension. 778 result.SetHasLpae(true); 779 } else if (feature == "nolpae") { 780 // Turn off support for Large Physical Address Extension. 781 result.SetHasLpae(false); 782 } else { 783 Usage("Unknown instruction set feature: '%s'", feature.c_str()); 784 } 785 } 786 // others... 787 return result; 788} 789 790void ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) { 791 std::string::size_type colon = s.find(c); 792 if (colon == std::string::npos) { 793 Usage("Missing char %c in option %s\n", c, s.c_str()); 794 } 795 // Add one to remove the char we were trimming until. 796 *parsed_value = s.substr(colon + 1); 797} 798 799void ParseDouble(const std::string& option, char after_char, 800 double min, double max, double* parsed_value) { 801 std::string substring; 802 ParseStringAfterChar(option, after_char, &substring); 803 bool sane_val = true; 804 double value; 805 if (false) { 806 // TODO: this doesn't seem to work on the emulator. b/15114595 807 std::stringstream iss(substring); 808 iss >> value; 809 // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range. 810 sane_val = iss.eof() && (value >= min) && (value <= max); 811 } else { 812 char* end = nullptr; 813 value = strtod(substring.c_str(), &end); 814 sane_val = *end == '\0' && value >= min && value <= max; 815 } 816 if (!sane_val) { 817 Usage("Invalid double value %s for option %s\n", substring.c_str(), option.c_str()); 818 } 819 *parsed_value = value; 820} 821 822static void b13564922() { 823#if defined(__linux__) && defined(__arm__) 824 int major, minor; 825 struct utsname uts; 826 if (uname(&uts) != -1 && 827 sscanf(uts.release, "%d.%d", &major, &minor) == 2 && 828 ((major < 3) || ((major == 3) && (minor < 4)))) { 829 // Kernels before 3.4 don't handle the ASLR well and we can run out of address 830 // space (http://b/13564922). Work around the issue by inhibiting further mmap() randomization. 831 int old_personality = personality(0xffffffff); 832 if ((old_personality & ADDR_NO_RANDOMIZE) == 0) { 833 int new_personality = personality(old_personality | ADDR_NO_RANDOMIZE); 834 if (new_personality == -1) { 835 LOG(WARNING) << "personality(. | ADDR_NO_RANDOMIZE) failed."; 836 } 837 } 838 } 839#endif 840} 841 842static int dex2oat(int argc, char** argv) { 843 b13564922(); 844 845 original_argc = argc; 846 original_argv = argv; 847 848 TimingLogger timings("compiler", false, false); 849 CumulativeLogger compiler_phases_timings("compilation times"); 850 851 InitLogging(argv); 852 853 // Skip over argv[0]. 854 argv++; 855 argc--; 856 857 if (argc == 0) { 858 Usage("No arguments specified"); 859 } 860 861 std::vector<const char*> dex_filenames; 862 std::vector<const char*> dex_locations; 863 int zip_fd = -1; 864 std::string zip_location; 865 std::string oat_filename; 866 std::string oat_symbols; 867 std::string oat_location; 868 int oat_fd = -1; 869 std::string bitcode_filename; 870 const char* image_classes_zip_filename = nullptr; 871 const char* image_classes_filename = nullptr; 872 const char* compiled_classes_zip_filename = nullptr; 873 const char* compiled_classes_filename = nullptr; 874 std::string image_filename; 875 std::string boot_image_filename; 876 uintptr_t image_base = 0; 877 std::string android_root; 878 std::vector<const char*> runtime_args; 879 int thread_count = sysconf(_SC_NPROCESSORS_CONF); 880 Compiler::Kind compiler_kind = kUsePortableCompiler 881 ? Compiler::kPortable 882 : Compiler::kQuick; 883 const char* compiler_filter_string = nullptr; 884 bool compile_pic = false; 885 int huge_method_threshold = CompilerOptions::kDefaultHugeMethodThreshold; 886 int large_method_threshold = CompilerOptions::kDefaultLargeMethodThreshold; 887 int small_method_threshold = CompilerOptions::kDefaultSmallMethodThreshold; 888 int tiny_method_threshold = CompilerOptions::kDefaultTinyMethodThreshold; 889 int num_dex_methods_threshold = CompilerOptions::kDefaultNumDexMethodsThreshold; 890 891 // Take the default set of instruction features from the build. 892 InstructionSetFeatures instruction_set_features = 893 ParseFeatureList(Runtime::GetDefaultInstructionSetFeatures()); 894 895 InstructionSet instruction_set = kRuntimeISA; 896 897 // Profile file to use 898 std::string profile_file; 899 double top_k_profile_threshold = CompilerOptions::kDefaultTopKProfileThreshold; 900 901 bool is_host = false; 902 bool dump_stats = false; 903 bool dump_timing = false; 904 bool dump_passes = false; 905 bool include_patch_information = CompilerOptions::kDefaultIncludePatchInformation; 906 bool include_debug_symbols = kIsDebugBuild; 907 bool dump_slow_timing = kIsDebugBuild; 908 bool watch_dog_enabled = true; 909 bool generate_gdb_information = kIsDebugBuild; 910 911 // Checks are all explicit until we know the architecture. 912 bool implicit_null_checks = false; 913 bool implicit_so_checks = false; 914 bool implicit_suspend_checks = false; 915 916 for (int i = 0; i < argc; i++) { 917 const StringPiece option(argv[i]); 918 const bool log_options = false; 919 if (log_options) { 920 LOG(INFO) << "dex2oat: option[" << i << "]=" << argv[i]; 921 } 922 if (option.starts_with("--dex-file=")) { 923 dex_filenames.push_back(option.substr(strlen("--dex-file=")).data()); 924 } else if (option.starts_with("--dex-location=")) { 925 dex_locations.push_back(option.substr(strlen("--dex-location=")).data()); 926 } else if (option.starts_with("--zip-fd=")) { 927 const char* zip_fd_str = option.substr(strlen("--zip-fd=")).data(); 928 if (!ParseInt(zip_fd_str, &zip_fd)) { 929 Usage("Failed to parse --zip-fd argument '%s' as an integer", zip_fd_str); 930 } 931 if (zip_fd < 0) { 932 Usage("--zip-fd passed a negative value %d", zip_fd); 933 } 934 } else if (option.starts_with("--zip-location=")) { 935 zip_location = option.substr(strlen("--zip-location=")).data(); 936 } else if (option.starts_with("--oat-file=")) { 937 oat_filename = option.substr(strlen("--oat-file=")).data(); 938 } else if (option.starts_with("--oat-symbols=")) { 939 oat_symbols = option.substr(strlen("--oat-symbols=")).data(); 940 } else if (option.starts_with("--oat-fd=")) { 941 const char* oat_fd_str = option.substr(strlen("--oat-fd=")).data(); 942 if (!ParseInt(oat_fd_str, &oat_fd)) { 943 Usage("Failed to parse --oat-fd argument '%s' as an integer", oat_fd_str); 944 } 945 if (oat_fd < 0) { 946 Usage("--oat-fd passed a negative value %d", oat_fd); 947 } 948 } else if (option == "--watch-dog") { 949 watch_dog_enabled = true; 950 } else if (option == "--no-watch-dog") { 951 watch_dog_enabled = false; 952 } else if (option == "--gen-gdb-info") { 953 generate_gdb_information = true; 954 // Debug symbols are needed for gdb information. 955 include_debug_symbols = true; 956 } else if (option == "--no-gen-gdb-info") { 957 generate_gdb_information = false; 958 } else if (option.starts_with("-j")) { 959 const char* thread_count_str = option.substr(strlen("-j")).data(); 960 if (!ParseInt(thread_count_str, &thread_count)) { 961 Usage("Failed to parse -j argument '%s' as an integer", thread_count_str); 962 } 963 } else if (option.starts_with("--oat-location=")) { 964 oat_location = option.substr(strlen("--oat-location=")).data(); 965 } else if (option.starts_with("--bitcode=")) { 966 bitcode_filename = option.substr(strlen("--bitcode=")).data(); 967 } else if (option.starts_with("--image=")) { 968 image_filename = option.substr(strlen("--image=")).data(); 969 } else if (option.starts_with("--image-classes=")) { 970 image_classes_filename = option.substr(strlen("--image-classes=")).data(); 971 } else if (option.starts_with("--image-classes-zip=")) { 972 image_classes_zip_filename = option.substr(strlen("--image-classes-zip=")).data(); 973 } else if (option.starts_with("--compiled-classes=")) { 974 compiled_classes_filename = option.substr(strlen("--compiled-classes=")).data(); 975 } else if (option.starts_with("--compiled-classes-zip=")) { 976 compiled_classes_zip_filename = option.substr(strlen("--compiled-classes-zip=")).data(); 977 } else if (option.starts_with("--base=")) { 978 const char* image_base_str = option.substr(strlen("--base=")).data(); 979 char* end; 980 image_base = strtoul(image_base_str, &end, 16); 981 if (end == image_base_str || *end != '\0') { 982 Usage("Failed to parse hexadecimal value for option %s", option.data()); 983 } 984 } else if (option.starts_with("--boot-image=")) { 985 boot_image_filename = option.substr(strlen("--boot-image=")).data(); 986 } else if (option.starts_with("--android-root=")) { 987 android_root = option.substr(strlen("--android-root=")).data(); 988 } else if (option.starts_with("--instruction-set=")) { 989 StringPiece instruction_set_str = option.substr(strlen("--instruction-set=")).data(); 990 if (instruction_set_str == "arm") { 991 instruction_set = kThumb2; 992 } else if (instruction_set_str == "arm64") { 993 instruction_set = kArm64; 994 } else if (instruction_set_str == "mips") { 995 instruction_set = kMips; 996 } else if (instruction_set_str == "x86") { 997 instruction_set = kX86; 998 } else if (instruction_set_str == "x86_64") { 999 instruction_set = kX86_64; 1000 } 1001 } else if (option.starts_with("--instruction-set-features=")) { 1002 StringPiece str = option.substr(strlen("--instruction-set-features=")).data(); 1003 instruction_set_features = ParseFeatureList(str.as_string()); 1004 } else if (option.starts_with("--compiler-backend=")) { 1005 StringPiece backend_str = option.substr(strlen("--compiler-backend=")).data(); 1006 if (backend_str == "Quick") { 1007 compiler_kind = Compiler::kQuick; 1008 } else if (backend_str == "Optimizing") { 1009 compiler_kind = Compiler::kOptimizing; 1010 } else if (backend_str == "Portable") { 1011 compiler_kind = Compiler::kPortable; 1012 } 1013 } else if (option.starts_with("--compiler-filter=")) { 1014 compiler_filter_string = option.substr(strlen("--compiler-filter=")).data(); 1015 } else if (option == "--compile-pic") { 1016 compile_pic = true; 1017 } else if (option.starts_with("--huge-method-max=")) { 1018 const char* threshold = option.substr(strlen("--huge-method-max=")).data(); 1019 if (!ParseInt(threshold, &huge_method_threshold)) { 1020 Usage("Failed to parse --huge-method-max '%s' as an integer", threshold); 1021 } 1022 if (huge_method_threshold < 0) { 1023 Usage("--huge-method-max passed a negative value %s", huge_method_threshold); 1024 } 1025 } else if (option.starts_with("--large-method-max=")) { 1026 const char* threshold = option.substr(strlen("--large-method-max=")).data(); 1027 if (!ParseInt(threshold, &large_method_threshold)) { 1028 Usage("Failed to parse --large-method-max '%s' as an integer", threshold); 1029 } 1030 if (large_method_threshold < 0) { 1031 Usage("--large-method-max passed a negative value %s", large_method_threshold); 1032 } 1033 } else if (option.starts_with("--small-method-max=")) { 1034 const char* threshold = option.substr(strlen("--small-method-max=")).data(); 1035 if (!ParseInt(threshold, &small_method_threshold)) { 1036 Usage("Failed to parse --small-method-max '%s' as an integer", threshold); 1037 } 1038 if (small_method_threshold < 0) { 1039 Usage("--small-method-max passed a negative value %s", small_method_threshold); 1040 } 1041 } else if (option.starts_with("--tiny-method-max=")) { 1042 const char* threshold = option.substr(strlen("--tiny-method-max=")).data(); 1043 if (!ParseInt(threshold, &tiny_method_threshold)) { 1044 Usage("Failed to parse --tiny-method-max '%s' as an integer", threshold); 1045 } 1046 if (tiny_method_threshold < 0) { 1047 Usage("--tiny-method-max passed a negative value %s", tiny_method_threshold); 1048 } 1049 } else if (option.starts_with("--num-dex-methods=")) { 1050 const char* threshold = option.substr(strlen("--num-dex-methods=")).data(); 1051 if (!ParseInt(threshold, &num_dex_methods_threshold)) { 1052 Usage("Failed to parse --num-dex-methods '%s' as an integer", threshold); 1053 } 1054 if (num_dex_methods_threshold < 0) { 1055 Usage("--num-dex-methods passed a negative value %s", num_dex_methods_threshold); 1056 } 1057 } else if (option == "--host") { 1058 is_host = true; 1059 } else if (option == "--runtime-arg") { 1060 if (++i >= argc) { 1061 Usage("Missing required argument for --runtime-arg"); 1062 } 1063 if (log_options) { 1064 LOG(INFO) << "dex2oat: option[" << i << "]=" << argv[i]; 1065 } 1066 runtime_args.push_back(argv[i]); 1067 } else if (option == "--dump-timing") { 1068 dump_timing = true; 1069 } else if (option == "--dump-passes") { 1070 dump_passes = true; 1071 } else if (option == "--dump-stats") { 1072 dump_stats = true; 1073 } else if (option == "--include-debug-symbols" || option == "--no-strip-symbols") { 1074 include_debug_symbols = true; 1075 } else if (option == "--no-include-debug-symbols" || option == "--strip-symbols") { 1076 include_debug_symbols = false; 1077 generate_gdb_information = false; // Depends on debug symbols, see above. 1078 } else if (option.starts_with("--profile-file=")) { 1079 profile_file = option.substr(strlen("--profile-file=")).data(); 1080 VLOG(compiler) << "dex2oat: profile file is " << profile_file; 1081 } else if (option == "--no-profile-file") { 1082 // No profile 1083 } else if (option.starts_with("--top-k-profile-threshold=")) { 1084 ParseDouble(option.data(), '=', 0.0, 100.0, &top_k_profile_threshold); 1085 } else if (option == "--print-pass-names") { 1086 PassDriverMEOpts::PrintPassNames(); 1087 } else if (option.starts_with("--disable-passes=")) { 1088 std::string disable_passes = option.substr(strlen("--disable-passes=")).data(); 1089 PassDriverMEOpts::CreateDefaultPassList(disable_passes); 1090 } else if (option.starts_with("--print-passes=")) { 1091 std::string print_passes = option.substr(strlen("--print-passes=")).data(); 1092 PassDriverMEOpts::SetPrintPassList(print_passes); 1093 } else if (option == "--print-all-passes") { 1094 PassDriverMEOpts::SetPrintAllPasses(); 1095 } else if (option.starts_with("--dump-cfg-passes=")) { 1096 std::string dump_passes = option.substr(strlen("--dump-cfg-passes=")).data(); 1097 PassDriverMEOpts::SetDumpPassList(dump_passes); 1098 } else if (option == "--include-patch-information") { 1099 include_patch_information = true; 1100 } else if (option == "--no-include-patch-information") { 1101 include_patch_information = false; 1102 } else { 1103 Usage("Unknown argument %s", option.data()); 1104 } 1105 } 1106 1107 if (oat_filename.empty() && oat_fd == -1) { 1108 Usage("Output must be supplied with either --oat-file or --oat-fd"); 1109 } 1110 1111 if (!oat_filename.empty() && oat_fd != -1) { 1112 Usage("--oat-file should not be used with --oat-fd"); 1113 } 1114 1115 if (!oat_symbols.empty() && oat_fd != -1) { 1116 Usage("--oat-symbols should not be used with --oat-fd"); 1117 } 1118 1119 if (!oat_symbols.empty() && is_host) { 1120 Usage("--oat-symbols should not be used with --host"); 1121 } 1122 1123 if (oat_fd != -1 && !image_filename.empty()) { 1124 Usage("--oat-fd should not be used with --image"); 1125 } 1126 1127 if (android_root.empty()) { 1128 const char* android_root_env_var = getenv("ANDROID_ROOT"); 1129 if (android_root_env_var == nullptr) { 1130 Usage("--android-root unspecified and ANDROID_ROOT not set"); 1131 } 1132 android_root += android_root_env_var; 1133 } 1134 1135 bool image = (!image_filename.empty()); 1136 if (!image && boot_image_filename.empty()) { 1137 boot_image_filename += android_root; 1138 boot_image_filename += "/framework/boot.art"; 1139 } 1140 std::string boot_image_option; 1141 if (!boot_image_filename.empty()) { 1142 boot_image_option += "-Ximage:"; 1143 boot_image_option += boot_image_filename; 1144 } 1145 1146 if (image_classes_filename != nullptr && !image) { 1147 Usage("--image-classes should only be used with --image"); 1148 } 1149 1150 if (image_classes_filename != nullptr && !boot_image_option.empty()) { 1151 Usage("--image-classes should not be used with --boot-image"); 1152 } 1153 1154 if (image_classes_zip_filename != nullptr && image_classes_filename == nullptr) { 1155 Usage("--image-classes-zip should be used with --image-classes"); 1156 } 1157 1158 if (compiled_classes_filename != nullptr && !image) { 1159 Usage("--compiled-classes should only be used with --image"); 1160 } 1161 1162 if (compiled_classes_filename != nullptr && !boot_image_option.empty()) { 1163 Usage("--compiled-classes should not be used with --boot-image"); 1164 } 1165 1166 if (compiled_classes_zip_filename != nullptr && compiled_classes_filename == nullptr) { 1167 Usage("--compiled-classes-zip should be used with --compiled-classes"); 1168 } 1169 1170 if (dex_filenames.empty() && zip_fd == -1) { 1171 Usage("Input must be supplied with either --dex-file or --zip-fd"); 1172 } 1173 1174 if (!dex_filenames.empty() && zip_fd != -1) { 1175 Usage("--dex-file should not be used with --zip-fd"); 1176 } 1177 1178 if (!dex_filenames.empty() && !zip_location.empty()) { 1179 Usage("--dex-file should not be used with --zip-location"); 1180 } 1181 1182 if (dex_locations.empty()) { 1183 for (size_t i = 0; i < dex_filenames.size(); i++) { 1184 dex_locations.push_back(dex_filenames[i]); 1185 } 1186 } else if (dex_locations.size() != dex_filenames.size()) { 1187 Usage("--dex-location arguments do not match --dex-file arguments"); 1188 } 1189 1190 if (zip_fd != -1 && zip_location.empty()) { 1191 Usage("--zip-location should be supplied with --zip-fd"); 1192 } 1193 1194 if (boot_image_option.empty()) { 1195 if (image_base == 0) { 1196 Usage("Non-zero --base not specified"); 1197 } 1198 } 1199 1200 std::string oat_stripped(oat_filename); 1201 std::string oat_unstripped; 1202 if (!oat_symbols.empty()) { 1203 oat_unstripped += oat_symbols; 1204 } else { 1205 oat_unstripped += oat_filename; 1206 } 1207 1208 if (compiler_filter_string == nullptr) { 1209 if (instruction_set == kMips64) { 1210 // TODO: fix compiler for Mips64. 1211 compiler_filter_string = "interpret-only"; 1212 } else if (image) { 1213 compiler_filter_string = "speed"; 1214 } else { 1215#if ART_SMALL_MODE 1216 compiler_filter_string = "interpret-only"; 1217#else 1218 compiler_filter_string = "speed"; 1219#endif 1220 } 1221 } 1222 CHECK(compiler_filter_string != nullptr); 1223 CompilerOptions::CompilerFilter compiler_filter = CompilerOptions::kDefaultCompilerFilter; 1224 if (strcmp(compiler_filter_string, "verify-none") == 0) { 1225 compiler_filter = CompilerOptions::kVerifyNone; 1226 } else if (strcmp(compiler_filter_string, "interpret-only") == 0) { 1227 compiler_filter = CompilerOptions::kInterpretOnly; 1228 } else if (strcmp(compiler_filter_string, "space") == 0) { 1229 compiler_filter = CompilerOptions::kSpace; 1230 } else if (strcmp(compiler_filter_string, "balanced") == 0) { 1231 compiler_filter = CompilerOptions::kBalanced; 1232 } else if (strcmp(compiler_filter_string, "speed") == 0) { 1233 compiler_filter = CompilerOptions::kSpeed; 1234 } else if (strcmp(compiler_filter_string, "everything") == 0) { 1235 compiler_filter = CompilerOptions::kEverything; 1236 } else { 1237 Usage("Unknown --compiler-filter value %s", compiler_filter_string); 1238 } 1239 1240 // Set the compilation target's implicit checks options. 1241 switch (instruction_set) { 1242 case kArm: 1243 case kThumb2: 1244 case kArm64: 1245 case kX86: 1246 case kX86_64: 1247 implicit_null_checks = true; 1248 implicit_so_checks = true; 1249 break; 1250 1251 default: 1252 // Defaults are correct. 1253 break; 1254 } 1255 1256 std::unique_ptr<CompilerOptions> compiler_options(new CompilerOptions(compiler_filter, 1257 huge_method_threshold, 1258 large_method_threshold, 1259 small_method_threshold, 1260 tiny_method_threshold, 1261 num_dex_methods_threshold, 1262 generate_gdb_information, 1263 include_patch_information, 1264 top_k_profile_threshold, 1265 include_debug_symbols, 1266 implicit_null_checks, 1267 implicit_so_checks, 1268 implicit_suspend_checks, 1269 compile_pic 1270#ifdef ART_SEA_IR_MODE 1271 , compiler_options.sea_ir_ = 1272 true; 1273#endif 1274 )); // NOLINT(whitespace/parens) 1275 1276 // Done with usage checks, enable watchdog if requested 1277 WatchDog watch_dog(watch_dog_enabled); 1278 1279 // Check early that the result of compilation can be written 1280 std::unique_ptr<File> oat_file; 1281 bool create_file = !oat_unstripped.empty(); // as opposed to using open file descriptor 1282 if (create_file) { 1283 oat_file.reset(OS::CreateEmptyFile(oat_unstripped.c_str())); 1284 if (oat_location.empty()) { 1285 oat_location = oat_filename; 1286 } 1287 } else { 1288 oat_file.reset(new File(oat_fd, oat_location, true)); 1289 oat_file->DisableAutoClose(); 1290 if (oat_file->SetLength(0)) { // Only warn for truncation error. 1291 PLOG(WARNING) << "Truncating oat file " << oat_location << " failed."; 1292 } 1293 } 1294 if (oat_file.get() == nullptr) { 1295 PLOG(ERROR) << "Failed to create oat file: " << oat_location; 1296 return EXIT_FAILURE; 1297 } 1298 if (create_file && fchmod(oat_file->Fd(), 0644) != 0) { 1299 PLOG(ERROR) << "Failed to make oat file world readable: " << oat_location; 1300 return EXIT_FAILURE; 1301 } 1302 1303 timings.StartTiming("dex2oat Setup"); 1304 LOG(INFO) << CommandLine(); 1305 1306 RuntimeOptions runtime_options; 1307 std::vector<const DexFile*> boot_class_path; 1308 art::MemMap::Init(); // For ZipEntry::ExtractToMemMap. 1309 if (boot_image_option.empty()) { 1310 size_t failure_count = OpenDexFiles(dex_filenames, dex_locations, boot_class_path); 1311 if (failure_count > 0) { 1312 LOG(ERROR) << "Failed to open some dex files: " << failure_count; 1313 return EXIT_FAILURE; 1314 } 1315 runtime_options.push_back(std::make_pair("bootclasspath", &boot_class_path)); 1316 } else { 1317 runtime_options.push_back(std::make_pair(boot_image_option.c_str(), nullptr)); 1318 } 1319 for (size_t i = 0; i < runtime_args.size(); i++) { 1320 runtime_options.push_back(std::make_pair(runtime_args[i], nullptr)); 1321 } 1322 1323 std::unique_ptr<VerificationResults> verification_results(new VerificationResults( 1324 compiler_options.get())); 1325 DexFileToMethodInlinerMap method_inliner_map; 1326 QuickCompilerCallbacks callbacks(verification_results.get(), &method_inliner_map); 1327 runtime_options.push_back(std::make_pair("compilercallbacks", &callbacks)); 1328 runtime_options.push_back( 1329 std::make_pair("imageinstructionset", 1330 reinterpret_cast<const void*>(GetInstructionSetString(instruction_set)))); 1331 1332 Dex2Oat* p_dex2oat; 1333 if (!Dex2Oat::Create(&p_dex2oat, 1334 runtime_options, 1335 *compiler_options, 1336 compiler_kind, 1337 instruction_set, 1338 instruction_set_features, 1339 verification_results.get(), 1340 &method_inliner_map, 1341 thread_count)) { 1342 LOG(ERROR) << "Failed to create dex2oat"; 1343 timings.EndTiming(); 1344 return EXIT_FAILURE; 1345 } 1346 std::unique_ptr<Dex2Oat> dex2oat(p_dex2oat); 1347 1348 // Runtime::Create acquired the mutator_lock_ that is normally given away when we Runtime::Start, 1349 // give it away now so that we don't starve GC. 1350 Thread* self = Thread::Current(); 1351 self->TransitionFromRunnableToSuspended(kNative); 1352 // If we're doing the image, override the compiler filter to force full compilation. Must be 1353 // done ahead of WellKnownClasses::Init that causes verification. Note: doesn't force 1354 // compilation of class initializers. 1355 // Whilst we're in native take the opportunity to initialize well known classes. 1356 WellKnownClasses::Init(self->GetJniEnv()); 1357 1358 // If --image-classes was specified, calculate the full list of classes to include in the image 1359 std::unique_ptr<std::set<std::string>> image_classes(nullptr); 1360 if (image_classes_filename != nullptr) { 1361 std::string error_msg; 1362 if (image_classes_zip_filename != nullptr) { 1363 image_classes.reset(dex2oat->ReadImageClassesFromZip(image_classes_zip_filename, 1364 image_classes_filename, 1365 &error_msg)); 1366 } else { 1367 image_classes.reset(dex2oat->ReadImageClassesFromFile(image_classes_filename)); 1368 } 1369 if (image_classes.get() == nullptr) { 1370 LOG(ERROR) << "Failed to create list of image classes from '" << image_classes_filename << 1371 "': " << error_msg; 1372 timings.EndTiming(); 1373 return EXIT_FAILURE; 1374 } 1375 } else if (image) { 1376 image_classes.reset(new std::set<std::string>); 1377 } 1378 // If --compiled-classes was specified, calculate the full list of classes to compile in the 1379 // image. 1380 std::unique_ptr<std::set<std::string>> compiled_classes(nullptr); 1381 if (compiled_classes_filename != nullptr) { 1382 std::string error_msg; 1383 if (compiled_classes_zip_filename != nullptr) { 1384 compiled_classes.reset(dex2oat->ReadImageClassesFromZip(compiled_classes_zip_filename, 1385 compiled_classes_filename, 1386 &error_msg)); 1387 } else { 1388 compiled_classes.reset(dex2oat->ReadImageClassesFromFile(compiled_classes_filename)); 1389 } 1390 if (compiled_classes.get() == nullptr) { 1391 LOG(ERROR) << "Failed to create list of compiled classes from '" << compiled_classes_filename 1392 << "': " << error_msg; 1393 timings.EndTiming(); 1394 return EXIT_FAILURE; 1395 } 1396 } else if (image) { 1397 compiled_classes.reset(nullptr); // By default compile everything. 1398 } 1399 1400 std::vector<const DexFile*> dex_files; 1401 if (boot_image_option.empty()) { 1402 dex_files = Runtime::Current()->GetClassLinker()->GetBootClassPath(); 1403 } else { 1404 if (dex_filenames.empty()) { 1405 ATRACE_BEGIN("Opening zip archive from file descriptor"); 1406 std::string error_msg; 1407 std::unique_ptr<ZipArchive> zip_archive(ZipArchive::OpenFromFd(zip_fd, zip_location.c_str(), 1408 &error_msg)); 1409 if (zip_archive.get() == nullptr) { 1410 LOG(ERROR) << "Failed to open zip from file descriptor for '" << zip_location << "': " 1411 << error_msg; 1412 timings.EndTiming(); 1413 return EXIT_FAILURE; 1414 } 1415 if (!DexFile::OpenFromZip(*zip_archive.get(), zip_location, &error_msg, &dex_files)) { 1416 LOG(ERROR) << "Failed to open dex from file descriptor for zip file '" << zip_location 1417 << "': " << error_msg; 1418 timings.EndTiming(); 1419 return EXIT_FAILURE; 1420 } 1421 ATRACE_END(); 1422 } else { 1423 size_t failure_count = OpenDexFiles(dex_filenames, dex_locations, dex_files); 1424 if (failure_count > 0) { 1425 LOG(ERROR) << "Failed to open some dex files: " << failure_count; 1426 timings.EndTiming(); 1427 return EXIT_FAILURE; 1428 } 1429 } 1430 1431 const bool kSaveDexInput = false; 1432 if (kSaveDexInput) { 1433 for (size_t i = 0; i < dex_files.size(); ++i) { 1434 const DexFile* dex_file = dex_files[i]; 1435 std::string tmp_file_name(StringPrintf("/data/local/tmp/dex2oat.%d.%zd.dex", getpid(), i)); 1436 std::unique_ptr<File> tmp_file(OS::CreateEmptyFile(tmp_file_name.c_str())); 1437 if (tmp_file.get() == nullptr) { 1438 PLOG(ERROR) << "Failed to open file " << tmp_file_name 1439 << ". Try: adb shell chmod 777 /data/local/tmp"; 1440 continue; 1441 } 1442 // This is just dumping files for debugging. Ignore errors, and leave remnants. 1443 UNUSED(tmp_file->WriteFully(dex_file->Begin(), dex_file->Size())); 1444 UNUSED(tmp_file->Flush()); 1445 UNUSED(tmp_file->Close()); 1446 LOG(INFO) << "Wrote input to " << tmp_file_name; 1447 } 1448 } 1449 } 1450 // Ensure opened dex files are writable for dex-to-dex transformations. 1451 for (const auto& dex_file : dex_files) { 1452 if (!dex_file->EnableWrite()) { 1453 PLOG(ERROR) << "Failed to make .dex file writeable '" << dex_file->GetLocation() << "'\n"; 1454 } 1455 } 1456 1457 /* 1458 * If we're not in interpret-only or verify-none mode, go ahead and compile small applications. 1459 * Don't bother to check if we're doing the image. 1460 */ 1461 if (!image && compiler_options->IsCompilationEnabled()) { 1462 size_t num_methods = 0; 1463 for (size_t i = 0; i != dex_files.size(); ++i) { 1464 const DexFile* dex_file = dex_files[i]; 1465 CHECK(dex_file != nullptr); 1466 num_methods += dex_file->NumMethodIds(); 1467 } 1468 if (num_methods <= compiler_options->GetNumDexMethodsThreshold()) { 1469 compiler_options->SetCompilerFilter(CompilerOptions::kSpeed); 1470 VLOG(compiler) << "Below method threshold, compiling anyways"; 1471 } 1472 } 1473 1474 // Fill some values into the key-value store for the oat header. 1475 std::unique_ptr<SafeMap<std::string, std::string> > key_value_store( 1476 new SafeMap<std::string, std::string>()); 1477 1478 // Insert some compiler things. 1479 { 1480 std::ostringstream oss; 1481 for (int i = 0; i < argc; ++i) { 1482 if (i > 0) { 1483 oss << ' '; 1484 } 1485 oss << argv[i]; 1486 } 1487 key_value_store->Put(OatHeader::kDex2OatCmdLineKey, oss.str()); 1488 oss.str(""); // Reset. 1489 oss << kRuntimeISA; 1490 key_value_store->Put(OatHeader::kDex2OatHostKey, oss.str()); 1491 key_value_store->Put(OatHeader::kPicKey, compile_pic ? "true" : "false"); 1492 } 1493 1494 std::unique_ptr<const CompilerDriver> compiler(dex2oat->CreateOatFile(boot_image_option, 1495 android_root, 1496 is_host, 1497 dex_files, 1498 oat_file.get(), 1499 oat_location, 1500 bitcode_filename, 1501 image, 1502 image_classes, 1503 compiled_classes, 1504 dump_stats, 1505 dump_passes, 1506 timings, 1507 compiler_phases_timings, 1508 profile_file, 1509 key_value_store.get())); 1510 if (compiler.get() == nullptr) { 1511 LOG(ERROR) << "Failed to create oat file: " << oat_location; 1512 timings.EndTiming(); 1513 return EXIT_FAILURE; 1514 } 1515 1516 if (!kUsePortableCompiler) { 1517 if (oat_file->FlushCloseOrErase() != 0) { 1518 PLOG(ERROR) << "Failed to flush and close oat file: " << oat_location; 1519 timings.EndTiming(); 1520 return EXIT_FAILURE; 1521 } 1522 oat_file.reset(); 1523 } 1524 1525 VLOG(compiler) << "Oat file written successfully (unstripped): " << oat_location; 1526 // Notes on the interleaving of creating the image and oat file to 1527 // ensure the references between the two are correct. 1528 // 1529 // Currently we have a memory layout that looks something like this: 1530 // 1531 // +--------------+ 1532 // | image | 1533 // +--------------+ 1534 // | boot oat | 1535 // +--------------+ 1536 // | alloc spaces | 1537 // +--------------+ 1538 // 1539 // There are several constraints on the loading of the image and boot.oat. 1540 // 1541 // 1. The image is expected to be loaded at an absolute address and 1542 // contains Objects with absolute pointers within the image. 1543 // 1544 // 2. There are absolute pointers from Methods in the image to their 1545 // code in the oat. 1546 // 1547 // 3. There are absolute pointers from the code in the oat to Methods 1548 // in the image. 1549 // 1550 // 4. There are absolute pointers from code in the oat to other code 1551 // in the oat. 1552 // 1553 // To get this all correct, we go through several steps. 1554 // 1555 // 1. We have already created that oat file above with 1556 // CreateOatFile. Originally this was just our own proprietary file 1557 // but now it is contained within an ELF dynamic object (aka an .so 1558 // file). The Compiler returned by CreateOatFile provides 1559 // PatchInformation for references to oat code and Methods that need 1560 // to be update once we know where the oat file will be located 1561 // after the image. 1562 // 1563 // 2. We create the image file. It needs to know where the oat file 1564 // will be loaded after itself. Originally when oat file was simply 1565 // memory mapped so we could predict where its contents were based 1566 // on the file size. Now that it is an ELF file, we need to inspect 1567 // the ELF file to understand the in memory segment layout including 1568 // where the oat header is located within. ElfPatcher's Patch method 1569 // uses the PatchInformation from the Compiler to touch up absolute 1570 // references in the oat file. 1571 // 1572 // 3. We fixup the ELF program headers so that dlopen will try to 1573 // load the .so at the desired location at runtime by offsetting the 1574 // Elf32_Phdr.p_vaddr values by the desired base address. 1575 // 1576 if (image) { 1577 TimingLogger::ScopedTiming t("dex2oat ImageWriter", &timings); 1578 bool image_creation_success = dex2oat->CreateImageFile(image_filename, 1579 image_base, 1580 oat_unstripped, 1581 oat_location, 1582 *compiler.get()); 1583 if (!image_creation_success) { 1584 timings.EndTiming(); 1585 return EXIT_FAILURE; 1586 } 1587 VLOG(compiler) << "Image written successfully: " << image_filename; 1588 } 1589 1590 if (is_host) { 1591 timings.EndTiming(); 1592 if (dump_timing || (dump_slow_timing && timings.GetTotalNs() > MsToNs(1000))) { 1593 LOG(INFO) << Dumpable<TimingLogger>(timings); 1594 } 1595 if (dump_passes) { 1596 LOG(INFO) << Dumpable<CumulativeLogger>(*compiler.get()->GetTimingsLogger()); 1597 } 1598 return EXIT_SUCCESS; 1599 } 1600 1601 // If we don't want to strip in place, copy from unstripped location to stripped location. 1602 // We need to strip after image creation because FixupElf needs to use .strtab. 1603 if (oat_unstripped != oat_stripped) { 1604 TimingLogger::ScopedTiming t("dex2oat OatFile copy", &timings); 1605 if (kUsePortableCompiler) { 1606 if (oat_file->FlushCloseOrErase() != 0) { 1607 PLOG(ERROR) << "Failed to flush and close oat file: " << oat_location; 1608 return EXIT_FAILURE; 1609 } 1610 oat_file.reset(); 1611 } 1612 std::unique_ptr<File> in(OS::OpenFileForReading(oat_unstripped.c_str())); 1613 std::unique_ptr<File> out(OS::CreateEmptyFile(oat_stripped.c_str())); 1614 size_t buffer_size = 8192; 1615 std::unique_ptr<uint8_t> buffer(new uint8_t[buffer_size]); 1616 while (true) { 1617 int bytes_read = TEMP_FAILURE_RETRY(read(in->Fd(), buffer.get(), buffer_size)); 1618 if (bytes_read <= 0) { 1619 break; 1620 } 1621 bool write_ok = out->WriteFully(buffer.get(), bytes_read); 1622 CHECK(write_ok); 1623 } 1624 oat_file.reset(out.release()); 1625 VLOG(compiler) << "Oat file copied successfully (stripped): " << oat_stripped; 1626 } 1627 1628 if (kUsePortableCompiler) { 1629 if (!compiler_options->GetIncludeDebugSymbols()) { 1630 timings.NewTiming("dex2oat ElfStripper"); 1631 // Strip unneeded sections for target 1632 off_t seek_actual = lseek(oat_file->Fd(), 0, SEEK_SET); 1633 CHECK_EQ(0, seek_actual); 1634 std::string error_msg; 1635 CHECK(ElfStripper::Strip(oat_file.get(), &error_msg)) << error_msg; 1636 1637 1638 // We wrote the oat file successfully, and want to keep it. 1639 VLOG(compiler) << "Oat file written successfully (stripped): " << oat_location; 1640 } else { 1641 VLOG(compiler) << "Oat file written successfully without stripping: " << oat_location; 1642 } 1643 if (oat_file->FlushCloseOrErase() != 0) { 1644 LOG(ERROR) << "Failed to flush and close oat file: " << oat_location; 1645 return EXIT_FAILURE; 1646 } 1647 oat_file.reset(nullptr); 1648 } 1649 1650 if (oat_file.get() != nullptr) { 1651 if (oat_file->FlushCloseOrErase() != 0) { 1652 PLOG(ERROR) << "Failed to flush and close oat file: " << oat_location << "/" << oat_filename; 1653 return EXIT_FAILURE; 1654 } 1655 } 1656 1657 timings.EndTiming(); 1658 1659 if (dump_timing || (dump_slow_timing && timings.GetTotalNs() > MsToNs(1000))) { 1660 LOG(INFO) << Dumpable<TimingLogger>(timings); 1661 } 1662 if (dump_passes) { 1663 LOG(INFO) << Dumpable<CumulativeLogger>(compiler_phases_timings); 1664 } 1665 1666 dex2oat->LogCompletionTime(compiler.get()); 1667 // Everything was successfully written, do an explicit exit here to avoid running Runtime 1668 // destructors that take time (bug 10645725) unless we're a debug build or running on valgrind. 1669 if (!kIsDebugBuild && (RUNNING_ON_VALGRIND == 0)) { 1670 exit(EXIT_SUCCESS); 1671 } 1672 1673 return EXIT_SUCCESS; 1674} // NOLINT(readability/fn_size) 1675} // namespace art 1676 1677int main(int argc, char** argv) { 1678 return art::dex2oat(argc, argv); 1679} 1680