runtime.cc revision 785049f8083e56e88dfeab5ff74fb3817f9854e3
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 "runtime.h" 18 19// sys/mount.h has to come before linux/fs.h due to redefinition of MS_RDONLY, MS_BIND, etc 20#include <sys/mount.h> 21#ifdef __linux__ 22#include <linux/fs.h> 23#endif 24 25#include <signal.h> 26#include <sys/syscall.h> 27#include <valgrind.h> 28 29#include <cstdio> 30#include <cstdlib> 31#include <limits> 32#include <memory_representation.h> 33#include <vector> 34#include <fcntl.h> 35 36#include "JniConstants.h" 37#include "ScopedLocalRef.h" 38#include "arch/arm/quick_method_frame_info_arm.h" 39#include "arch/arm/registers_arm.h" 40#include "arch/arm64/quick_method_frame_info_arm64.h" 41#include "arch/arm64/registers_arm64.h" 42#include "arch/instruction_set_features.h" 43#include "arch/mips/quick_method_frame_info_mips.h" 44#include "arch/mips/registers_mips.h" 45#include "arch/mips64/quick_method_frame_info_mips64.h" 46#include "arch/mips64/registers_mips64.h" 47#include "arch/x86/quick_method_frame_info_x86.h" 48#include "arch/x86/registers_x86.h" 49#include "arch/x86_64/quick_method_frame_info_x86_64.h" 50#include "arch/x86_64/registers_x86_64.h" 51#include "asm_support.h" 52#include "atomic.h" 53#include "base/dumpable.h" 54#include "base/unix_file/fd_file.h" 55#include "class_linker.h" 56#include "debugger.h" 57#include "elf_file.h" 58#include "entrypoints/runtime_asm_entrypoints.h" 59#include "fault_handler.h" 60#include "gc/accounting/card_table-inl.h" 61#include "gc/heap.h" 62#include "gc/space/image_space.h" 63#include "gc/space/space.h" 64#include "handle_scope-inl.h" 65#include "image.h" 66#include "instrumentation.h" 67#include "intern_table.h" 68#include "interpreter/interpreter.h" 69#include "jit/jit.h" 70#include "jni_internal.h" 71#include "mirror/array.h" 72#include "mirror/art_field-inl.h" 73#include "mirror/art_method-inl.h" 74#include "mirror/class-inl.h" 75#include "mirror/class_loader.h" 76#include "mirror/stack_trace_element.h" 77#include "mirror/throwable.h" 78#include "monitor.h" 79#include "native/dalvik_system_DexFile.h" 80#include "native/dalvik_system_VMDebug.h" 81#include "native/dalvik_system_VMRuntime.h" 82#include "native/dalvik_system_VMStack.h" 83#include "native/dalvik_system_ZygoteHooks.h" 84#include "native/java_lang_Class.h" 85#include "native/java_lang_DexCache.h" 86#include "native/java_lang_Object.h" 87#include "native/java_lang_Runtime.h" 88#include "native/java_lang_String.h" 89#include "native/java_lang_System.h" 90#include "native/java_lang_Thread.h" 91#include "native/java_lang_Throwable.h" 92#include "native/java_lang_VMClassLoader.h" 93#include "native/java_lang_ref_FinalizerReference.h" 94#include "native/java_lang_ref_Reference.h" 95#include "native/java_lang_reflect_Array.h" 96#include "native/java_lang_reflect_Constructor.h" 97#include "native/java_lang_reflect_Field.h" 98#include "native/java_lang_reflect_Method.h" 99#include "native/java_lang_reflect_Proxy.h" 100#include "native/java_util_concurrent_atomic_AtomicLong.h" 101#include "native/org_apache_harmony_dalvik_ddmc_DdmServer.h" 102#include "native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.h" 103#include "native/sun_misc_Unsafe.h" 104#include "native_bridge_art_interface.h" 105#include "oat_file.h" 106#include "os.h" 107#include "parsed_options.h" 108#include "profiler.h" 109#include "quick/quick_method_frame_info.h" 110#include "reflection.h" 111#include "runtime_options.h" 112#include "ScopedLocalRef.h" 113#include "scoped_thread_state_change.h" 114#include "sigchain.h" 115#include "signal_catcher.h" 116#include "signal_set.h" 117#include "thread.h" 118#include "thread_list.h" 119#include "trace.h" 120#include "transaction.h" 121#include "verifier/method_verifier.h" 122#include "well_known_classes.h" 123 124namespace art { 125 126// If a signal isn't handled properly, enable a handler that attempts to dump the Java stack. 127static constexpr bool kEnableJavaStackTraceHandler = false; 128Runtime* Runtime::instance_ = nullptr; 129 130Runtime::Runtime() 131 : instruction_set_(kNone), 132 compiler_callbacks_(nullptr), 133 is_zygote_(false), 134 must_relocate_(false), 135 is_concurrent_gc_enabled_(true), 136 is_explicit_gc_disabled_(false), 137 dex2oat_enabled_(true), 138 image_dex2oat_enabled_(true), 139 default_stack_size_(0), 140 heap_(nullptr), 141 max_spins_before_thin_lock_inflation_(Monitor::kDefaultMaxSpinsBeforeThinLockInflation), 142 monitor_list_(nullptr), 143 monitor_pool_(nullptr), 144 thread_list_(nullptr), 145 intern_table_(nullptr), 146 class_linker_(nullptr), 147 signal_catcher_(nullptr), 148 java_vm_(nullptr), 149 fault_message_lock_("Fault message lock"), 150 fault_message_(""), 151 threads_being_born_(0), 152 shutdown_cond_(new ConditionVariable("Runtime shutdown", *Locks::runtime_shutdown_lock_)), 153 shutting_down_(false), 154 shutting_down_started_(false), 155 started_(false), 156 finished_starting_(false), 157 vfprintf_(nullptr), 158 exit_(nullptr), 159 abort_(nullptr), 160 stats_enabled_(false), 161 running_on_valgrind_(RUNNING_ON_VALGRIND > 0), 162 profiler_started_(false), 163 method_trace_(false), 164 method_trace_file_size_(0), 165 instrumentation_(), 166 use_compile_time_class_path_(false), 167 main_thread_group_(nullptr), 168 system_thread_group_(nullptr), 169 system_class_loader_(nullptr), 170 dump_gc_performance_on_shutdown_(false), 171 preinitialization_transaction_(nullptr), 172 verify_(false), 173 allow_dex_file_fallback_(true), 174 target_sdk_version_(0), 175 implicit_null_checks_(false), 176 implicit_so_checks_(false), 177 implicit_suspend_checks_(false), 178 is_native_bridge_loaded_(false), 179 zygote_max_failed_boots_(0) { 180 CheckAsmSupportOffsetsAndSizes(); 181} 182 183Runtime::~Runtime() { 184 if (is_native_bridge_loaded_) { 185 UnloadNativeBridge(); 186 } 187 if (dump_gc_performance_on_shutdown_) { 188 // This can't be called from the Heap destructor below because it 189 // could call RosAlloc::InspectAll() which needs the thread_list 190 // to be still alive. 191 heap_->DumpGcPerformanceInfo(LOG(INFO)); 192 } 193 194 Thread* self = Thread::Current(); 195 const bool attach_shutdown_thread = self == nullptr; 196 if (attach_shutdown_thread) { 197 CHECK(AttachCurrentThread("Shutdown thread", false, nullptr, false)); 198 self = Thread::Current(); 199 } else { 200 LOG(WARNING) << "Current thread not detached in Runtime shutdown"; 201 } 202 203 { 204 MutexLock mu(self, *Locks::runtime_shutdown_lock_); 205 shutting_down_started_ = true; 206 while (threads_being_born_ > 0) { 207 shutdown_cond_->Wait(self); 208 } 209 shutting_down_ = true; 210 } 211 // Shutdown and wait for the daemons. 212 CHECK(self != nullptr); 213 if (IsFinishedStarting()) { 214 self->ClearException(); 215 self->GetJniEnv()->CallStaticVoidMethod(WellKnownClasses::java_lang_Daemons, 216 WellKnownClasses::java_lang_Daemons_stop); 217 } 218 if (attach_shutdown_thread) { 219 DetachCurrentThread(); 220 self = nullptr; 221 } 222 223 // Shut down background profiler before the runtime exits. 224 if (profiler_started_) { 225 BackgroundMethodSamplingProfiler::Shutdown(); 226 } 227 228 Trace::Shutdown(); 229 230 // Make sure to let the GC complete if it is running. 231 heap_->WaitForGcToComplete(gc::kGcCauseBackground, self); 232 heap_->DeleteThreadPool(); 233 if (jit_.get() != nullptr) { 234 VLOG(jit) << "Deleting jit thread pool"; 235 // Delete thread pool before the thread list since we don't want to wait forever on the 236 // JIT compiler threads. 237 jit_->DeleteThreadPool(); 238 } 239 240 // Make sure our internal threads are dead before we start tearing down things they're using. 241 Dbg::StopJdwp(); 242 delete signal_catcher_; 243 244 // Make sure all other non-daemon threads have terminated, and all daemon threads are suspended. 245 delete thread_list_; 246 247 // Delete the JIT after thread list to ensure that there is no remaining threads which could be 248 // accessing the instrumentation when we delete it. 249 if (jit_.get() != nullptr) { 250 VLOG(jit) << "Deleting jit"; 251 jit_.reset(nullptr); 252 } 253 arena_pool_.reset(); 254 255 // Shutdown the fault manager if it was initialized. 256 fault_manager.Shutdown(); 257 258 delete monitor_list_; 259 delete monitor_pool_; 260 delete class_linker_; 261 delete heap_; 262 delete intern_table_; 263 delete java_vm_; 264 Thread::Shutdown(); 265 QuasiAtomic::Shutdown(); 266 verifier::MethodVerifier::Shutdown(); 267 MemMap::Shutdown(); 268 // TODO: acquire a static mutex on Runtime to avoid racing. 269 CHECK(instance_ == nullptr || instance_ == this); 270 instance_ = nullptr; 271} 272 273struct AbortState { 274 void Dump(std::ostream& os) const { 275 if (gAborting > 1) { 276 os << "Runtime aborting --- recursively, so no thread-specific detail!\n"; 277 return; 278 } 279 gAborting++; 280 os << "Runtime aborting...\n"; 281 if (Runtime::Current() == NULL) { 282 os << "(Runtime does not yet exist!)\n"; 283 return; 284 } 285 Thread* self = Thread::Current(); 286 if (self == nullptr) { 287 os << "(Aborting thread was not attached to runtime!)\n"; 288 DumpKernelStack(os, GetTid(), " kernel: ", false); 289 DumpNativeStack(os, GetTid(), " native: ", nullptr); 290 } else { 291 os << "Aborting thread:\n"; 292 if (Locks::mutator_lock_->IsExclusiveHeld(self) || Locks::mutator_lock_->IsSharedHeld(self)) { 293 DumpThread(os, self); 294 } else { 295 if (Locks::mutator_lock_->SharedTryLock(self)) { 296 DumpThread(os, self); 297 Locks::mutator_lock_->SharedUnlock(self); 298 } 299 } 300 } 301 DumpAllThreads(os, self); 302 } 303 304 // No thread-safety analysis as we do explicitly test for holding the mutator lock. 305 void DumpThread(std::ostream& os, Thread* self) const NO_THREAD_SAFETY_ANALYSIS { 306 DCHECK(Locks::mutator_lock_->IsExclusiveHeld(self) || Locks::mutator_lock_->IsSharedHeld(self)); 307 self->Dump(os); 308 if (self->IsExceptionPending()) { 309 mirror::Throwable* exception = self->GetException(); 310 os << "Pending exception " << exception->Dump(); 311 } 312 } 313 314 void DumpAllThreads(std::ostream& os, Thread* self) const { 315 Runtime* runtime = Runtime::Current(); 316 if (runtime != nullptr) { 317 ThreadList* thread_list = runtime->GetThreadList(); 318 if (thread_list != nullptr) { 319 bool tll_already_held = Locks::thread_list_lock_->IsExclusiveHeld(self); 320 bool ml_already_held = Locks::mutator_lock_->IsSharedHeld(self); 321 if (!tll_already_held || !ml_already_held) { 322 os << "Dumping all threads without appropriate locks held:" 323 << (!tll_already_held ? " thread list lock" : "") 324 << (!ml_already_held ? " mutator lock" : "") 325 << "\n"; 326 } 327 os << "All threads:\n"; 328 thread_list->Dump(os); 329 } 330 } 331 } 332}; 333 334void Runtime::Abort() { 335 gAborting++; // set before taking any locks 336 337 // Ensure that we don't have multiple threads trying to abort at once, 338 // which would result in significantly worse diagnostics. 339 MutexLock mu(Thread::Current(), *Locks::abort_lock_); 340 341 // Get any pending output out of the way. 342 fflush(NULL); 343 344 // Many people have difficulty distinguish aborts from crashes, 345 // so be explicit. 346 AbortState state; 347 LOG(INTERNAL_FATAL) << Dumpable<AbortState>(state); 348 349 // Call the abort hook if we have one. 350 if (Runtime::Current() != NULL && Runtime::Current()->abort_ != NULL) { 351 LOG(INTERNAL_FATAL) << "Calling abort hook..."; 352 Runtime::Current()->abort_(); 353 // notreached 354 LOG(INTERNAL_FATAL) << "Unexpectedly returned from abort hook!"; 355 } 356 357#if defined(__GLIBC__) 358 // TODO: we ought to be able to use pthread_kill(3) here (or abort(3), 359 // which POSIX defines in terms of raise(3), which POSIX defines in terms 360 // of pthread_kill(3)). On Linux, though, libcorkscrew can't unwind through 361 // libpthread, which means the stacks we dump would be useless. Calling 362 // tgkill(2) directly avoids that. 363 syscall(__NR_tgkill, getpid(), GetTid(), SIGABRT); 364 // TODO: LLVM installs it's own SIGABRT handler so exit to be safe... Can we disable that in LLVM? 365 // If not, we could use sigaction(3) before calling tgkill(2) and lose this call to exit(3). 366 exit(1); 367#else 368 abort(); 369#endif 370 // notreached 371} 372 373void Runtime::PreZygoteFork() { 374 heap_->PreZygoteFork(); 375} 376 377void Runtime::CallExitHook(jint status) { 378 if (exit_ != NULL) { 379 ScopedThreadStateChange tsc(Thread::Current(), kNative); 380 exit_(status); 381 LOG(WARNING) << "Exit hook returned instead of exiting!"; 382 } 383} 384 385void Runtime::SweepSystemWeaks(IsMarkedCallback* visitor, void* arg) { 386 GetInternTable()->SweepInternTableWeaks(visitor, arg); 387 GetMonitorList()->SweepMonitorList(visitor, arg); 388 GetJavaVM()->SweepJniWeakGlobals(visitor, arg); 389} 390 391bool Runtime::Create(const RuntimeOptions& options, bool ignore_unrecognized) { 392 // TODO: acquire a static mutex on Runtime to avoid racing. 393 if (Runtime::instance_ != NULL) { 394 return false; 395 } 396 InitLogging(NULL); // Calls Locks::Init() as a side effect. 397 instance_ = new Runtime; 398 if (!instance_->Init(options, ignore_unrecognized)) { 399 // TODO: Currently deleting the instance will abort the runtime on destruction. Now This will 400 // leak memory, instead. Fix the destructor. b/19100793. 401 // delete instance_; 402 instance_ = NULL; 403 return false; 404 } 405 return true; 406} 407 408static jobject CreateSystemClassLoader() { 409 if (Runtime::Current()->UseCompileTimeClassPath()) { 410 return NULL; 411 } 412 413 ScopedObjectAccess soa(Thread::Current()); 414 ClassLinker* cl = Runtime::Current()->GetClassLinker(); 415 416 StackHandleScope<2> hs(soa.Self()); 417 Handle<mirror::Class> class_loader_class( 418 hs.NewHandle(soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_ClassLoader))); 419 CHECK(cl->EnsureInitialized(soa.Self(), class_loader_class, true, true)); 420 421 mirror::ArtMethod* getSystemClassLoader = 422 class_loader_class->FindDirectMethod("getSystemClassLoader", "()Ljava/lang/ClassLoader;"); 423 CHECK(getSystemClassLoader != NULL); 424 425 JValue result = InvokeWithJValues(soa, nullptr, soa.EncodeMethod(getSystemClassLoader), nullptr); 426 JNIEnv* env = soa.Self()->GetJniEnv(); 427 ScopedLocalRef<jobject> system_class_loader(env, 428 soa.AddLocalReference<jobject>(result.GetL())); 429 CHECK(system_class_loader.get() != nullptr); 430 431 soa.Self()->SetClassLoaderOverride(system_class_loader.get()); 432 433 Handle<mirror::Class> thread_class( 434 hs.NewHandle(soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_Thread))); 435 CHECK(cl->EnsureInitialized(soa.Self(), thread_class, true, true)); 436 437 mirror::ArtField* contextClassLoader = 438 thread_class->FindDeclaredInstanceField("contextClassLoader", "Ljava/lang/ClassLoader;"); 439 CHECK(contextClassLoader != NULL); 440 441 // We can't run in a transaction yet. 442 contextClassLoader->SetObject<false>(soa.Self()->GetPeer(), 443 soa.Decode<mirror::ClassLoader*>(system_class_loader.get())); 444 445 return env->NewGlobalRef(system_class_loader.get()); 446} 447 448std::string Runtime::GetPatchoatExecutable() const { 449 if (!patchoat_executable_.empty()) { 450 return patchoat_executable_; 451 } 452 std::string patchoat_executable(GetAndroidRoot()); 453 patchoat_executable += (kIsDebugBuild ? "/bin/patchoatd" : "/bin/patchoat"); 454 return patchoat_executable; 455} 456 457std::string Runtime::GetCompilerExecutable() const { 458 if (!compiler_executable_.empty()) { 459 return compiler_executable_; 460 } 461 std::string compiler_executable(GetAndroidRoot()); 462 compiler_executable += (kIsDebugBuild ? "/bin/dex2oatd" : "/bin/dex2oat"); 463 return compiler_executable; 464} 465 466bool Runtime::Start() { 467 VLOG(startup) << "Runtime::Start entering"; 468 469 // Restore main thread state to kNative as expected by native code. 470 Thread* self = Thread::Current(); 471 472 self->TransitionFromRunnableToSuspended(kNative); 473 474 started_ = true; 475 476 // Use !IsAotCompiler so that we get test coverage, tests are never the zygote. 477 if (!IsAotCompiler()) { 478 ScopedObjectAccess soa(self); 479 gc::space::ImageSpace* image_space = heap_->GetImageSpace(); 480 if (image_space != nullptr) { 481 GetInternTable()->AddImageStringsToTable(image_space); 482 GetClassLinker()->MoveImageClassesToClassTable(); 483 } 484 } 485 486 // If we are the zygote then we need to wait until after forking to create the code cache 487 // due to SELinux restrictions on r/w/x memory regions. 488 if (!IsZygote() && jit_options_->UseJIT()) { 489 CreateJit(); 490 } 491 492 if (!IsImageDex2OatEnabled() || !GetHeap()->HasImageSpace()) { 493 ScopedObjectAccess soa(self); 494 StackHandleScope<1> hs(soa.Self()); 495 auto klass(hs.NewHandle<mirror::Class>(mirror::Class::GetJavaLangClass())); 496 class_linker_->EnsureInitialized(soa.Self(), klass, true, true); 497 } 498 499 // InitNativeMethods needs to be after started_ so that the classes 500 // it touches will have methods linked to the oat file if necessary. 501 InitNativeMethods(); 502 503 // Initialize well known thread group values that may be accessed threads while attaching. 504 InitThreadGroups(self); 505 506 Thread::FinishStartup(); 507 508 system_class_loader_ = CreateSystemClassLoader(); 509 510 if (is_zygote_) { 511 if (!InitZygote()) { 512 return false; 513 } 514 } else { 515 if (is_native_bridge_loaded_) { 516 PreInitializeNativeBridge("."); 517 } 518 DidForkFromZygote(self->GetJniEnv(), NativeBridgeAction::kInitialize, 519 GetInstructionSetString(kRuntimeISA)); 520 } 521 522 StartDaemonThreads(); 523 524 { 525 ScopedObjectAccess soa(self); 526 self->GetJniEnv()->locals.AssertEmpty(); 527 } 528 529 VLOG(startup) << "Runtime::Start exiting"; 530 finished_starting_ = true; 531 532 if (profiler_options_.IsEnabled() && !profile_output_filename_.empty()) { 533 // User has asked for a profile using -Xenable-profiler. 534 // Create the profile file if it doesn't exist. 535 int fd = open(profile_output_filename_.c_str(), O_RDWR|O_CREAT|O_EXCL, 0660); 536 if (fd >= 0) { 537 close(fd); 538 } else if (errno != EEXIST) { 539 LOG(INFO) << "Failed to access the profile file. Profiler disabled."; 540 return true; 541 } 542 StartProfiler(profile_output_filename_.c_str()); 543 } 544 545 return true; 546} 547 548void Runtime::EndThreadBirth() EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_) { 549 DCHECK_GT(threads_being_born_, 0U); 550 threads_being_born_--; 551 if (shutting_down_started_ && threads_being_born_ == 0) { 552 shutdown_cond_->Broadcast(Thread::Current()); 553 } 554} 555 556// Do zygote-mode-only initialization. 557bool Runtime::InitZygote() { 558#ifdef __linux__ 559 // zygote goes into its own process group 560 setpgid(0, 0); 561 562 // See storage config details at http://source.android.com/tech/storage/ 563 // Create private mount namespace shared by all children 564 if (unshare(CLONE_NEWNS) == -1) { 565 PLOG(WARNING) << "Failed to unshare()"; 566 return false; 567 } 568 569 // Mark rootfs as being a slave so that changes from default 570 // namespace only flow into our children. 571 if (mount("rootfs", "/", NULL, (MS_SLAVE | MS_REC), NULL) == -1) { 572 PLOG(WARNING) << "Failed to mount() rootfs as MS_SLAVE"; 573 return false; 574 } 575 576 // Create a staging tmpfs that is shared by our children; they will 577 // bind mount storage into their respective private namespaces, which 578 // are isolated from each other. 579 const char* target_base = getenv("EMULATED_STORAGE_TARGET"); 580 if (target_base != NULL) { 581 if (mount("tmpfs", target_base, "tmpfs", MS_NOSUID | MS_NODEV, 582 "uid=0,gid=1028,mode=0751") == -1) { 583 LOG(WARNING) << "Failed to mount tmpfs to " << target_base; 584 return false; 585 } 586 } 587 588 return true; 589#else 590 UNIMPLEMENTED(FATAL); 591 return false; 592#endif 593} 594 595void Runtime::DidForkFromZygote(JNIEnv* env, NativeBridgeAction action, const char* isa) { 596 is_zygote_ = false; 597 598 if (is_native_bridge_loaded_) { 599 switch (action) { 600 case NativeBridgeAction::kUnload: 601 UnloadNativeBridge(); 602 is_native_bridge_loaded_ = false; 603 break; 604 605 case NativeBridgeAction::kInitialize: 606 InitializeNativeBridge(env, isa); 607 break; 608 } 609 } 610 611 // Create the thread pools. 612 heap_->CreateThreadPool(); 613 if (jit_.get() == nullptr && jit_options_->UseJIT()) { 614 // Create the JIT if the flag is set and we haven't already create it (happens for run-tests). 615 CreateJit(); 616 } 617 618 StartSignalCatcher(); 619 620 // Start the JDWP thread. If the command-line debugger flags specified "suspend=y", 621 // this will pause the runtime, so we probably want this to come last. 622 Dbg::StartJdwp(); 623} 624 625void Runtime::StartSignalCatcher() { 626 if (!is_zygote_) { 627 signal_catcher_ = new SignalCatcher(stack_trace_file_); 628 } 629} 630 631bool Runtime::IsShuttingDown(Thread* self) { 632 MutexLock mu(self, *Locks::runtime_shutdown_lock_); 633 return IsShuttingDownLocked(); 634} 635 636void Runtime::StartDaemonThreads() { 637 VLOG(startup) << "Runtime::StartDaemonThreads entering"; 638 639 Thread* self = Thread::Current(); 640 641 // Must be in the kNative state for calling native methods. 642 CHECK_EQ(self->GetState(), kNative); 643 644 JNIEnv* env = self->GetJniEnv(); 645 env->CallStaticVoidMethod(WellKnownClasses::java_lang_Daemons, 646 WellKnownClasses::java_lang_Daemons_start); 647 if (env->ExceptionCheck()) { 648 env->ExceptionDescribe(); 649 LOG(FATAL) << "Error starting java.lang.Daemons"; 650 } 651 652 VLOG(startup) << "Runtime::StartDaemonThreads exiting"; 653} 654 655static bool OpenDexFilesFromImage(const std::string& image_location, 656 std::vector<std::unique_ptr<const DexFile>>* dex_files, 657 size_t* failures) { 658 DCHECK(dex_files != nullptr) << "OpenDexFilesFromImage: out-param is NULL"; 659 std::string system_filename; 660 bool has_system = false; 661 std::string cache_filename_unused; 662 bool dalvik_cache_exists_unused; 663 bool has_cache_unused; 664 bool is_global_cache_unused; 665 bool found_image = gc::space::ImageSpace::FindImageFilename(image_location.c_str(), 666 kRuntimeISA, 667 &system_filename, 668 &has_system, 669 &cache_filename_unused, 670 &dalvik_cache_exists_unused, 671 &has_cache_unused, 672 &is_global_cache_unused); 673 *failures = 0; 674 if (!found_image || !has_system) { 675 return false; 676 } 677 std::string error_msg; 678 // We are falling back to non-executable use of the oat file because patching failed, presumably 679 // due to lack of space. 680 std::string oat_filename = ImageHeader::GetOatLocationFromImageLocation(system_filename.c_str()); 681 std::string oat_location = ImageHeader::GetOatLocationFromImageLocation(image_location.c_str()); 682 std::unique_ptr<File> file(OS::OpenFileForReading(oat_filename.c_str())); 683 if (file.get() == nullptr) { 684 return false; 685 } 686 std::unique_ptr<ElfFile> elf_file(ElfFile::Open(file.release(), false, false, &error_msg)); 687 if (elf_file.get() == nullptr) { 688 return false; 689 } 690 std::unique_ptr<OatFile> oat_file(OatFile::OpenWithElfFile(elf_file.release(), oat_location, 691 &error_msg)); 692 if (oat_file.get() == nullptr) { 693 LOG(INFO) << "Unable to use '" << oat_filename << "' because " << error_msg; 694 return false; 695 } 696 697 for (const OatFile::OatDexFile* oat_dex_file : oat_file->GetOatDexFiles()) { 698 if (oat_dex_file == nullptr) { 699 *failures += 1; 700 continue; 701 } 702 std::unique_ptr<const DexFile> dex_file = oat_dex_file->OpenDexFile(&error_msg); 703 if (dex_file.get() == nullptr) { 704 *failures += 1; 705 } else { 706 dex_files->push_back(std::move(dex_file)); 707 } 708 } 709 Runtime::Current()->GetClassLinker()->RegisterOatFile(oat_file.release()); 710 return true; 711} 712 713 714static size_t OpenDexFiles(const std::vector<std::string>& dex_filenames, 715 const std::vector<std::string>& dex_locations, 716 const std::string& image_location, 717 std::vector<std::unique_ptr<const DexFile>>* dex_files) { 718 DCHECK(dex_files != nullptr) << "OpenDexFiles: out-param is NULL"; 719 size_t failure_count = 0; 720 if (!image_location.empty() && OpenDexFilesFromImage(image_location, dex_files, &failure_count)) { 721 return failure_count; 722 } 723 failure_count = 0; 724 for (size_t i = 0; i < dex_filenames.size(); i++) { 725 const char* dex_filename = dex_filenames[i].c_str(); 726 const char* dex_location = dex_locations[i].c_str(); 727 std::string error_msg; 728 if (!OS::FileExists(dex_filename)) { 729 LOG(WARNING) << "Skipping non-existent dex file '" << dex_filename << "'"; 730 continue; 731 } 732 if (!DexFile::Open(dex_filename, dex_location, &error_msg, dex_files)) { 733 LOG(WARNING) << "Failed to open .dex from file '" << dex_filename << "': " << error_msg; 734 ++failure_count; 735 } 736 } 737 return failure_count; 738} 739 740bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized) { 741 CHECK_EQ(sysconf(_SC_PAGE_SIZE), kPageSize); 742 743 MemMap::Init(); 744 745 using Opt = RuntimeArgumentMap; 746 RuntimeArgumentMap runtime_options; 747 std::unique_ptr<ParsedOptions> parsed_options( 748 ParsedOptions::Create(raw_options, ignore_unrecognized, &runtime_options)); 749 if (parsed_options.get() == nullptr) { 750 LOG(ERROR) << "Failed to parse options"; 751 return false; 752 } 753 VLOG(startup) << "Runtime::Init -verbose:startup enabled"; 754 755 QuasiAtomic::Startup(); 756 757 Monitor::Init(runtime_options.GetOrDefault(Opt::LockProfThreshold), 758 runtime_options.GetOrDefault(Opt::HookIsSensitiveThread)); 759 760 boot_class_path_string_ = runtime_options.ReleaseOrDefault(Opt::BootClassPath); 761 class_path_string_ = runtime_options.ReleaseOrDefault(Opt::ClassPath); 762 properties_ = runtime_options.ReleaseOrDefault(Opt::PropertiesList); 763 764 compiler_callbacks_ = runtime_options.GetOrDefault(Opt::CompilerCallbacksPtr); 765 patchoat_executable_ = runtime_options.ReleaseOrDefault(Opt::PatchOat); 766 must_relocate_ = runtime_options.GetOrDefault(Opt::Relocate); 767 is_zygote_ = runtime_options.Exists(Opt::Zygote); 768 is_explicit_gc_disabled_ = runtime_options.Exists(Opt::DisableExplicitGC); 769 dex2oat_enabled_ = runtime_options.GetOrDefault(Opt::Dex2Oat); 770 image_dex2oat_enabled_ = runtime_options.GetOrDefault(Opt::ImageDex2Oat); 771 772 vfprintf_ = runtime_options.GetOrDefault(Opt::HookVfprintf); 773 exit_ = runtime_options.GetOrDefault(Opt::HookExit); 774 abort_ = runtime_options.GetOrDefault(Opt::HookAbort); 775 776 default_stack_size_ = runtime_options.GetOrDefault(Opt::StackSize); 777 stack_trace_file_ = runtime_options.ReleaseOrDefault(Opt::StackTraceFile); 778 779 compiler_executable_ = runtime_options.ReleaseOrDefault(Opt::Compiler); 780 compiler_options_ = runtime_options.ReleaseOrDefault(Opt::CompilerOptions); 781 image_compiler_options_ = runtime_options.ReleaseOrDefault(Opt::ImageCompilerOptions); 782 image_location_ = runtime_options.GetOrDefault(Opt::Image); 783 784 max_spins_before_thin_lock_inflation_ = 785 runtime_options.GetOrDefault(Opt::MaxSpinsBeforeThinLockInflation); 786 787 monitor_list_ = new MonitorList; 788 monitor_pool_ = MonitorPool::Create(); 789 thread_list_ = new ThreadList; 790 intern_table_ = new InternTable; 791 792 verify_ = runtime_options.GetOrDefault(Opt::Verify); 793 allow_dex_file_fallback_ = !runtime_options.Exists(Opt::NoDexFileFallback); 794 795 Split(runtime_options.GetOrDefault(Opt::CpuAbiList), ',', &cpu_abilist_); 796 797 if (runtime_options.GetOrDefault(Opt::Interpret)) { 798 GetInstrumentation()->ForceInterpretOnly(); 799 } 800 801 zygote_max_failed_boots_ = runtime_options.GetOrDefault(Opt::ZygoteMaxFailedBoots); 802 803 XGcOption xgc_option = runtime_options.GetOrDefault(Opt::GcOption); 804 heap_ = new gc::Heap(runtime_options.GetOrDefault(Opt::MemoryInitialSize), 805 runtime_options.GetOrDefault(Opt::HeapGrowthLimit), 806 runtime_options.GetOrDefault(Opt::HeapMinFree), 807 runtime_options.GetOrDefault(Opt::HeapMaxFree), 808 runtime_options.GetOrDefault(Opt::HeapTargetUtilization), 809 runtime_options.GetOrDefault(Opt::ForegroundHeapGrowthMultiplier), 810 runtime_options.GetOrDefault(Opt::MemoryMaximumSize), 811 runtime_options.GetOrDefault(Opt::NonMovingSpaceCapacity), 812 runtime_options.GetOrDefault(Opt::Image), 813 runtime_options.GetOrDefault(Opt::ImageInstructionSet), 814 xgc_option.collector_type_, 815 runtime_options.GetOrDefault(Opt::BackgroundGc), 816 runtime_options.GetOrDefault(Opt::LargeObjectSpace), 817 runtime_options.GetOrDefault(Opt::LargeObjectThreshold), 818 runtime_options.GetOrDefault(Opt::ParallelGCThreads), 819 runtime_options.GetOrDefault(Opt::ConcGCThreads), 820 runtime_options.Exists(Opt::LowMemoryMode), 821 runtime_options.GetOrDefault(Opt::LongPauseLogThreshold), 822 runtime_options.GetOrDefault(Opt::LongGCLogThreshold), 823 runtime_options.Exists(Opt::IgnoreMaxFootprint), 824 runtime_options.GetOrDefault(Opt::UseTLAB), 825 xgc_option.verify_pre_gc_heap_, 826 xgc_option.verify_pre_sweeping_heap_, 827 xgc_option.verify_post_gc_heap_, 828 xgc_option.verify_pre_gc_rosalloc_, 829 xgc_option.verify_pre_sweeping_rosalloc_, 830 xgc_option.verify_post_gc_rosalloc_, 831 runtime_options.GetOrDefault(Opt::EnableHSpaceCompactForOOM), 832 runtime_options.GetOrDefault(Opt::HSpaceCompactForOOMMinIntervalsMs)); 833 834 if (heap_->GetImageSpace() == nullptr && !allow_dex_file_fallback_) { 835 LOG(ERROR) << "Dex file fallback disabled, cannot continue without image."; 836 return false; 837 } 838 839 dump_gc_performance_on_shutdown_ = runtime_options.Exists(Opt::DumpGCPerformanceOnShutdown); 840 841 if (runtime_options.Exists(Opt::JdwpOptions)) { 842 Dbg::ConfigureJdwp(runtime_options.GetOrDefault(Opt::JdwpOptions)); 843 } 844 845 jit_options_.reset(jit::JitOptions::CreateFromRuntimeArguments(runtime_options)); 846 bool use_jit = jit_options_->UseJIT(); 847 if (IsAotCompiler()) { 848 // If we are already the compiler at this point, we must be dex2oat. Don't create the jit in 849 // this case. 850 // If runtime_options doesn't have UseJIT set to true then CreateFromRuntimeArguments returns 851 // nullptr and we don't create the jit. 852 use_jit = false; 853 } 854 855 // Use MemMap arena pool for jit, malloc otherwise. Malloc arenas are faster to allocate but 856 // can't be trimmed as easily. 857 const bool use_malloc = !use_jit; 858 arena_pool_.reset(new ArenaPool(use_malloc)); 859 860 BlockSignals(); 861 InitPlatformSignalHandlers(); 862 863 // Change the implicit checks flags based on runtime architecture. 864 switch (kRuntimeISA) { 865 case kArm: 866 case kThumb2: 867 case kX86: 868 case kArm64: 869 case kX86_64: 870 implicit_null_checks_ = true; 871 // Installing stack protection does not play well with valgrind. 872 implicit_so_checks_ = (RUNNING_ON_VALGRIND == 0); 873 break; 874 default: 875 // Keep the defaults. 876 break; 877 } 878 879 // Always initialize the signal chain so that any calls to sigaction get 880 // correctly routed to the next in the chain regardless of whether we 881 // have claimed the signal or not. 882 InitializeSignalChain(); 883 884 if (implicit_null_checks_ || implicit_so_checks_ || implicit_suspend_checks_) { 885 fault_manager.Init(); 886 887 // These need to be in a specific order. The null point check handler must be 888 // after the suspend check and stack overflow check handlers. 889 // 890 // Note: the instances attach themselves to the fault manager and are handled by it. The manager 891 // will delete the instance on Shutdown(). 892 if (implicit_suspend_checks_) { 893 new SuspensionHandler(&fault_manager); 894 } 895 896 if (implicit_so_checks_) { 897 new StackOverflowHandler(&fault_manager); 898 } 899 900 if (implicit_null_checks_) { 901 new NullPointerHandler(&fault_manager); 902 } 903 904 if (kEnableJavaStackTraceHandler) { 905 new JavaStackTraceHandler(&fault_manager); 906 } 907 } 908 909 java_vm_ = new JavaVMExt(this, runtime_options); 910 911 Thread::Startup(); 912 913 // ClassLinker needs an attached thread, but we can't fully attach a thread without creating 914 // objects. We can't supply a thread group yet; it will be fixed later. Since we are the main 915 // thread, we do not get a java peer. 916 Thread* self = Thread::Attach("main", false, nullptr, false); 917 CHECK_EQ(self->GetThreadId(), ThreadList::kMainThreadId); 918 CHECK(self != nullptr); 919 920 // Set us to runnable so tools using a runtime can allocate and GC by default 921 self->TransitionFromSuspendedToRunnable(); 922 923 // Now we're attached, we can take the heap locks and validate the heap. 924 GetHeap()->EnableObjectValidation(); 925 926 CHECK_GE(GetHeap()->GetContinuousSpaces().size(), 1U); 927 class_linker_ = new ClassLinker(intern_table_); 928 if (GetHeap()->HasImageSpace()) { 929 class_linker_->InitFromImage(); 930 if (kIsDebugBuild) { 931 GetHeap()->GetImageSpace()->VerifyImageAllocations(); 932 } 933 if (boot_class_path_string_.empty()) { 934 // The bootclasspath is not explicitly specified: construct it from the loaded dex files. 935 const std::vector<const DexFile*>& boot_class_path = GetClassLinker()->GetBootClassPath(); 936 std::vector<std::string> dex_locations; 937 dex_locations.reserve(boot_class_path.size()); 938 for (const DexFile* dex_file : boot_class_path) { 939 dex_locations.push_back(dex_file->GetLocation()); 940 } 941 boot_class_path_string_ = Join(dex_locations, ':'); 942 } 943 } else { 944 std::vector<std::string> dex_filenames; 945 Split(boot_class_path_string_, ':', &dex_filenames); 946 947 std::vector<std::string> dex_locations; 948 if (!runtime_options.Exists(Opt::BootClassPathLocations)) { 949 dex_locations = dex_filenames; 950 } else { 951 dex_locations = runtime_options.GetOrDefault(Opt::BootClassPathLocations); 952 CHECK_EQ(dex_filenames.size(), dex_locations.size()); 953 } 954 955 std::vector<std::unique_ptr<const DexFile>> boot_class_path; 956 OpenDexFiles(dex_filenames, 957 dex_locations, 958 runtime_options.GetOrDefault(Opt::Image), 959 &boot_class_path); 960 instruction_set_ = runtime_options.GetOrDefault(Opt::ImageInstructionSet); 961 class_linker_->InitWithoutImage(std::move(boot_class_path)); 962 963 // TODO: Should we move the following to InitWithoutImage? 964 SetInstructionSet(instruction_set_); 965 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { 966 Runtime::CalleeSaveType type = Runtime::CalleeSaveType(i); 967 if (!HasCalleeSaveMethod(type)) { 968 SetCalleeSaveMethod(CreateCalleeSaveMethod(), type); 969 } 970 } 971 } 972 973 CHECK(class_linker_ != nullptr); 974 975 // Initialize the special sentinel_ value early. 976 sentinel_ = GcRoot<mirror::Object>(class_linker_->AllocObject(self)); 977 CHECK(sentinel_.Read() != nullptr); 978 979 verifier::MethodVerifier::Init(); 980 981 method_trace_ = runtime_options.Exists(Opt::MethodTrace); 982 method_trace_file_ = runtime_options.ReleaseOrDefault(Opt::MethodTraceFile); 983 method_trace_file_size_ = runtime_options.ReleaseOrDefault(Opt::MethodTraceFileSize); 984 985 { 986 auto&& profiler_options = runtime_options.ReleaseOrDefault(Opt::ProfilerOpts); 987 profile_output_filename_ = profiler_options.output_file_name_; 988 989 // TODO: Don't do this, just change ProfilerOptions to include the output file name? 990 ProfilerOptions other_options( 991 profiler_options.enabled_, 992 profiler_options.period_s_, 993 profiler_options.duration_s_, 994 profiler_options.interval_us_, 995 profiler_options.backoff_coefficient_, 996 profiler_options.start_immediately_, 997 profiler_options.top_k_threshold_, 998 profiler_options.top_k_change_threshold_, 999 profiler_options.profile_type_, 1000 profiler_options.max_stack_depth_); 1001 1002 profiler_options_ = other_options; 1003 } 1004 1005 // TODO: move this to just be an Trace::Start argument 1006 Trace::SetDefaultClockSource(runtime_options.GetOrDefault(Opt::ProfileClock)); 1007 1008 if (method_trace_) { 1009 ScopedThreadStateChange tsc(self, kWaitingForMethodTracingStart); 1010 Trace::Start(method_trace_file_.c_str(), 1011 -1, 1012 static_cast<int>(method_trace_file_size_), 1013 0, 1014 false, 1015 false, 1016 0); 1017 } 1018 1019 // Pre-allocate an OutOfMemoryError for the double-OOME case. 1020 self->ThrowNewException("Ljava/lang/OutOfMemoryError;", 1021 "OutOfMemoryError thrown while trying to throw OutOfMemoryError; " 1022 "no stack trace available"); 1023 pre_allocated_OutOfMemoryError_ = GcRoot<mirror::Throwable>(self->GetException()); 1024 self->ClearException(); 1025 1026 // Pre-allocate a NoClassDefFoundError for the common case of failing to find a system class 1027 // ahead of checking the application's class loader. 1028 self->ThrowNewException("Ljava/lang/NoClassDefFoundError;", 1029 "Class not found using the boot class loader; no stack trace available"); 1030 pre_allocated_NoClassDefFoundError_ = GcRoot<mirror::Throwable>(self->GetException()); 1031 self->ClearException(); 1032 1033 // Look for a native bridge. 1034 // 1035 // The intended flow here is, in the case of a running system: 1036 // 1037 // Runtime::Init() (zygote): 1038 // LoadNativeBridge -> dlopen from cmd line parameter. 1039 // | 1040 // V 1041 // Runtime::Start() (zygote): 1042 // No-op wrt native bridge. 1043 // | 1044 // | start app 1045 // V 1046 // DidForkFromZygote(action) 1047 // action = kUnload -> dlclose native bridge. 1048 // action = kInitialize -> initialize library 1049 // 1050 // 1051 // The intended flow here is, in the case of a simple dalvikvm call: 1052 // 1053 // Runtime::Init(): 1054 // LoadNativeBridge -> dlopen from cmd line parameter. 1055 // | 1056 // V 1057 // Runtime::Start(): 1058 // DidForkFromZygote(kInitialize) -> try to initialize any native bridge given. 1059 // No-op wrt native bridge. 1060 { 1061 std::string native_bridge_file_name = runtime_options.ReleaseOrDefault(Opt::NativeBridge); 1062 is_native_bridge_loaded_ = LoadNativeBridge(native_bridge_file_name); 1063 } 1064 1065 VLOG(startup) << "Runtime::Init exiting"; 1066 return true; 1067} 1068 1069void Runtime::InitNativeMethods() { 1070 VLOG(startup) << "Runtime::InitNativeMethods entering"; 1071 Thread* self = Thread::Current(); 1072 JNIEnv* env = self->GetJniEnv(); 1073 1074 // Must be in the kNative state for calling native methods (JNI_OnLoad code). 1075 CHECK_EQ(self->GetState(), kNative); 1076 1077 // First set up JniConstants, which is used by both the runtime's built-in native 1078 // methods and libcore. 1079 JniConstants::init(env); 1080 WellKnownClasses::Init(env); 1081 1082 // Then set up the native methods provided by the runtime itself. 1083 RegisterRuntimeNativeMethods(env); 1084 1085 // Then set up libcore, which is just a regular JNI library with a regular JNI_OnLoad. 1086 // Most JNI libraries can just use System.loadLibrary, but libcore can't because it's 1087 // the library that implements System.loadLibrary! 1088 { 1089 std::string reason; 1090 if (!java_vm_->LoadNativeLibrary(env, "libjavacore.so", nullptr, &reason)) { 1091 LOG(FATAL) << "LoadNativeLibrary failed for \"libjavacore.so\": " << reason; 1092 } 1093 } 1094 1095 // Initialize well known classes that may invoke runtime native methods. 1096 WellKnownClasses::LateInit(env); 1097 1098 VLOG(startup) << "Runtime::InitNativeMethods exiting"; 1099} 1100 1101void Runtime::InitThreadGroups(Thread* self) { 1102 JNIEnvExt* env = self->GetJniEnv(); 1103 ScopedJniEnvLocalRefState env_state(env); 1104 main_thread_group_ = 1105 env->NewGlobalRef(env->GetStaticObjectField( 1106 WellKnownClasses::java_lang_ThreadGroup, 1107 WellKnownClasses::java_lang_ThreadGroup_mainThreadGroup)); 1108 CHECK(main_thread_group_ != NULL || IsAotCompiler()); 1109 system_thread_group_ = 1110 env->NewGlobalRef(env->GetStaticObjectField( 1111 WellKnownClasses::java_lang_ThreadGroup, 1112 WellKnownClasses::java_lang_ThreadGroup_systemThreadGroup)); 1113 CHECK(system_thread_group_ != NULL || IsAotCompiler()); 1114} 1115 1116jobject Runtime::GetMainThreadGroup() const { 1117 CHECK(main_thread_group_ != NULL || IsAotCompiler()); 1118 return main_thread_group_; 1119} 1120 1121jobject Runtime::GetSystemThreadGroup() const { 1122 CHECK(system_thread_group_ != NULL || IsAotCompiler()); 1123 return system_thread_group_; 1124} 1125 1126jobject Runtime::GetSystemClassLoader() const { 1127 CHECK(system_class_loader_ != NULL || IsAotCompiler()); 1128 return system_class_loader_; 1129} 1130 1131void Runtime::RegisterRuntimeNativeMethods(JNIEnv* env) { 1132 register_dalvik_system_DexFile(env); 1133 register_dalvik_system_VMDebug(env); 1134 register_dalvik_system_VMRuntime(env); 1135 register_dalvik_system_VMStack(env); 1136 register_dalvik_system_ZygoteHooks(env); 1137 register_java_lang_Class(env); 1138 register_java_lang_DexCache(env); 1139 register_java_lang_Object(env); 1140 register_java_lang_ref_FinalizerReference(env); 1141 register_java_lang_reflect_Array(env); 1142 register_java_lang_reflect_Constructor(env); 1143 register_java_lang_reflect_Field(env); 1144 register_java_lang_reflect_Method(env); 1145 register_java_lang_reflect_Proxy(env); 1146 register_java_lang_ref_Reference(env); 1147 register_java_lang_Runtime(env); 1148 register_java_lang_String(env); 1149 register_java_lang_System(env); 1150 register_java_lang_Thread(env); 1151 register_java_lang_Throwable(env); 1152 register_java_lang_VMClassLoader(env); 1153 register_java_util_concurrent_atomic_AtomicLong(env); 1154 register_org_apache_harmony_dalvik_ddmc_DdmServer(env); 1155 register_org_apache_harmony_dalvik_ddmc_DdmVmInternal(env); 1156 register_sun_misc_Unsafe(env); 1157} 1158 1159void Runtime::DumpForSigQuit(std::ostream& os) { 1160 GetClassLinker()->DumpForSigQuit(os); 1161 GetInternTable()->DumpForSigQuit(os); 1162 GetJavaVM()->DumpForSigQuit(os); 1163 GetHeap()->DumpForSigQuit(os); 1164 TrackedAllocators::Dump(os); 1165 os << "\n"; 1166 1167 thread_list_->DumpForSigQuit(os); 1168 BaseMutex::DumpAll(os); 1169} 1170 1171void Runtime::DumpLockHolders(std::ostream& os) { 1172 uint64_t mutator_lock_owner = Locks::mutator_lock_->GetExclusiveOwnerTid(); 1173 pid_t thread_list_lock_owner = GetThreadList()->GetLockOwner(); 1174 pid_t classes_lock_owner = GetClassLinker()->GetClassesLockOwner(); 1175 pid_t dex_lock_owner = GetClassLinker()->GetDexLockOwner(); 1176 if ((thread_list_lock_owner | classes_lock_owner | dex_lock_owner) != 0) { 1177 os << "Mutator lock exclusive owner tid: " << mutator_lock_owner << "\n" 1178 << "ThreadList lock owner tid: " << thread_list_lock_owner << "\n" 1179 << "ClassLinker classes lock owner tid: " << classes_lock_owner << "\n" 1180 << "ClassLinker dex lock owner tid: " << dex_lock_owner << "\n"; 1181 } 1182} 1183 1184void Runtime::SetStatsEnabled(bool new_state) { 1185 Thread* self = Thread::Current(); 1186 MutexLock mu(self, *Locks::instrument_entrypoints_lock_); 1187 if (new_state == true) { 1188 GetStats()->Clear(~0); 1189 // TODO: wouldn't it make more sense to clear _all_ threads' stats? 1190 self->GetStats()->Clear(~0); 1191 if (stats_enabled_ != new_state) { 1192 GetInstrumentation()->InstrumentQuickAllocEntryPointsLocked(); 1193 } 1194 } else if (stats_enabled_ != new_state) { 1195 GetInstrumentation()->UninstrumentQuickAllocEntryPointsLocked(); 1196 } 1197 stats_enabled_ = new_state; 1198} 1199 1200void Runtime::ResetStats(int kinds) { 1201 GetStats()->Clear(kinds & 0xffff); 1202 // TODO: wouldn't it make more sense to clear _all_ threads' stats? 1203 Thread::Current()->GetStats()->Clear(kinds >> 16); 1204} 1205 1206int32_t Runtime::GetStat(int kind) { 1207 RuntimeStats* stats; 1208 if (kind < (1<<16)) { 1209 stats = GetStats(); 1210 } else { 1211 stats = Thread::Current()->GetStats(); 1212 kind >>= 16; 1213 } 1214 switch (kind) { 1215 case KIND_ALLOCATED_OBJECTS: 1216 return stats->allocated_objects; 1217 case KIND_ALLOCATED_BYTES: 1218 return stats->allocated_bytes; 1219 case KIND_FREED_OBJECTS: 1220 return stats->freed_objects; 1221 case KIND_FREED_BYTES: 1222 return stats->freed_bytes; 1223 case KIND_GC_INVOCATIONS: 1224 return stats->gc_for_alloc_count; 1225 case KIND_CLASS_INIT_COUNT: 1226 return stats->class_init_count; 1227 case KIND_CLASS_INIT_TIME: 1228 // Convert ns to us, reduce to 32 bits. 1229 return static_cast<int>(stats->class_init_time_ns / 1000); 1230 case KIND_EXT_ALLOCATED_OBJECTS: 1231 case KIND_EXT_ALLOCATED_BYTES: 1232 case KIND_EXT_FREED_OBJECTS: 1233 case KIND_EXT_FREED_BYTES: 1234 return 0; // backward compatibility 1235 default: 1236 LOG(FATAL) << "Unknown statistic " << kind; 1237 return -1; // unreachable 1238 } 1239} 1240 1241void Runtime::BlockSignals() { 1242 SignalSet signals; 1243 signals.Add(SIGPIPE); 1244 // SIGQUIT is used to dump the runtime's state (including stack traces). 1245 signals.Add(SIGQUIT); 1246 // SIGUSR1 is used to initiate a GC. 1247 signals.Add(SIGUSR1); 1248 signals.Block(); 1249} 1250 1251bool Runtime::AttachCurrentThread(const char* thread_name, bool as_daemon, jobject thread_group, 1252 bool create_peer) { 1253 return Thread::Attach(thread_name, as_daemon, thread_group, create_peer) != NULL; 1254} 1255 1256void Runtime::DetachCurrentThread() { 1257 Thread* self = Thread::Current(); 1258 if (self == NULL) { 1259 LOG(FATAL) << "attempting to detach thread that is not attached"; 1260 } 1261 if (self->HasManagedStack()) { 1262 LOG(FATAL) << *Thread::Current() << " attempting to detach while still running code"; 1263 } 1264 thread_list_->Unregister(self); 1265} 1266 1267mirror::Throwable* Runtime::GetPreAllocatedOutOfMemoryError() { 1268 mirror::Throwable* oome = pre_allocated_OutOfMemoryError_.Read(); 1269 if (oome == nullptr) { 1270 LOG(ERROR) << "Failed to return pre-allocated OOME"; 1271 } 1272 return oome; 1273} 1274 1275mirror::Throwable* Runtime::GetPreAllocatedNoClassDefFoundError() { 1276 mirror::Throwable* ncdfe = pre_allocated_NoClassDefFoundError_.Read(); 1277 if (ncdfe == nullptr) { 1278 LOG(ERROR) << "Failed to return pre-allocated NoClassDefFoundError"; 1279 } 1280 return ncdfe; 1281} 1282 1283void Runtime::VisitConstantRoots(RootCallback* callback, void* arg) { 1284 // Visit the classes held as static in mirror classes, these can be visited concurrently and only 1285 // need to be visited once per GC since they never change. 1286 mirror::ArtField::VisitRoots(callback, arg); 1287 mirror::ArtMethod::VisitRoots(callback, arg); 1288 mirror::Class::VisitRoots(callback, arg); 1289 mirror::Reference::VisitRoots(callback, arg); 1290 mirror::StackTraceElement::VisitRoots(callback, arg); 1291 mirror::String::VisitRoots(callback, arg); 1292 mirror::Throwable::VisitRoots(callback, arg); 1293 // Visit all the primitive array types classes. 1294 mirror::PrimitiveArray<uint8_t>::VisitRoots(callback, arg); // BooleanArray 1295 mirror::PrimitiveArray<int8_t>::VisitRoots(callback, arg); // ByteArray 1296 mirror::PrimitiveArray<uint16_t>::VisitRoots(callback, arg); // CharArray 1297 mirror::PrimitiveArray<double>::VisitRoots(callback, arg); // DoubleArray 1298 mirror::PrimitiveArray<float>::VisitRoots(callback, arg); // FloatArray 1299 mirror::PrimitiveArray<int32_t>::VisitRoots(callback, arg); // IntArray 1300 mirror::PrimitiveArray<int64_t>::VisitRoots(callback, arg); // LongArray 1301 mirror::PrimitiveArray<int16_t>::VisitRoots(callback, arg); // ShortArray 1302} 1303 1304void Runtime::VisitConcurrentRoots(RootCallback* callback, void* arg, VisitRootFlags flags) { 1305 intern_table_->VisitRoots(callback, arg, flags); 1306 class_linker_->VisitRoots(callback, arg, flags); 1307 if ((flags & kVisitRootFlagNewRoots) == 0) { 1308 // Guaranteed to have no new roots in the constant roots. 1309 VisitConstantRoots(callback, arg); 1310 } 1311} 1312 1313void Runtime::VisitTransactionRoots(RootCallback* callback, void* arg) { 1314 if (preinitialization_transaction_ != nullptr) { 1315 preinitialization_transaction_->VisitRoots(callback, arg); 1316 } 1317} 1318 1319void Runtime::VisitNonThreadRoots(RootCallback* callback, void* arg) { 1320 java_vm_->VisitRoots(callback, arg); 1321 sentinel_.VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal)); 1322 pre_allocated_OutOfMemoryError_.VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal)); 1323 resolution_method_.VisitRoot(callback, arg, RootInfo(kRootVMInternal)); 1324 pre_allocated_NoClassDefFoundError_.VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal)); 1325 imt_conflict_method_.VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal)); 1326 imt_unimplemented_method_.VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal)); 1327 default_imt_.VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal)); 1328 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { 1329 callee_save_methods_[i].VisitRootIfNonNull(callback, arg, RootInfo(kRootVMInternal)); 1330 } 1331 verifier::MethodVerifier::VisitStaticRoots(callback, arg); 1332 VisitTransactionRoots(callback, arg); 1333 instrumentation_.VisitRoots(callback, arg); 1334} 1335 1336void Runtime::VisitNonConcurrentRoots(RootCallback* callback, void* arg) { 1337 thread_list_->VisitRoots(callback, arg); 1338 VisitNonThreadRoots(callback, arg); 1339} 1340 1341void Runtime::VisitThreadRoots(RootCallback* callback, void* arg) { 1342 thread_list_->VisitRoots(callback, arg); 1343} 1344 1345size_t Runtime::FlipThreadRoots(Closure* thread_flip_visitor, Closure* flip_callback, 1346 gc::collector::GarbageCollector* collector) { 1347 return thread_list_->FlipThreadRoots(thread_flip_visitor, flip_callback, collector); 1348} 1349 1350void Runtime::VisitRoots(RootCallback* callback, void* arg, VisitRootFlags flags) { 1351 VisitNonConcurrentRoots(callback, arg); 1352 VisitConcurrentRoots(callback, arg, flags); 1353} 1354 1355mirror::ObjectArray<mirror::ArtMethod>* Runtime::CreateDefaultImt(ClassLinker* cl) { 1356 Thread* self = Thread::Current(); 1357 StackHandleScope<1> hs(self); 1358 Handle<mirror::ObjectArray<mirror::ArtMethod>> imtable( 1359 hs.NewHandle(cl->AllocArtMethodArray(self, 64))); 1360 mirror::ArtMethod* imt_conflict_method = Runtime::Current()->GetImtConflictMethod(); 1361 for (size_t i = 0; i < static_cast<size_t>(imtable->GetLength()); i++) { 1362 imtable->Set<false>(i, imt_conflict_method); 1363 } 1364 return imtable.Get(); 1365} 1366 1367mirror::ArtMethod* Runtime::CreateImtConflictMethod() { 1368 Thread* self = Thread::Current(); 1369 Runtime* runtime = Runtime::Current(); 1370 ClassLinker* class_linker = runtime->GetClassLinker(); 1371 StackHandleScope<1> hs(self); 1372 Handle<mirror::ArtMethod> method(hs.NewHandle(class_linker->AllocArtMethod(self))); 1373 method->SetDeclaringClass(mirror::ArtMethod::GetJavaLangReflectArtMethod()); 1374 // TODO: use a special method for imt conflict method saves. 1375 method->SetDexMethodIndex(DexFile::kDexNoIndex); 1376 // When compiling, the code pointer will get set later when the image is loaded. 1377 if (runtime->IsAotCompiler()) { 1378 size_t pointer_size = GetInstructionSetPointerSize(instruction_set_); 1379 method->SetEntryPointFromQuickCompiledCodePtrSize(nullptr, pointer_size); 1380 } else { 1381 method->SetEntryPointFromQuickCompiledCode(GetQuickImtConflictStub()); 1382 } 1383 return method.Get(); 1384} 1385 1386void Runtime::SetImtConflictMethod(mirror::ArtMethod* method) { 1387 imt_conflict_method_ = GcRoot<mirror::ArtMethod>(method); 1388} 1389 1390mirror::ArtMethod* Runtime::CreateResolutionMethod() { 1391 Thread* self = Thread::Current(); 1392 Runtime* runtime = Runtime::Current(); 1393 ClassLinker* class_linker = runtime->GetClassLinker(); 1394 StackHandleScope<1> hs(self); 1395 Handle<mirror::ArtMethod> method(hs.NewHandle(class_linker->AllocArtMethod(self))); 1396 method->SetDeclaringClass(mirror::ArtMethod::GetJavaLangReflectArtMethod()); 1397 // TODO: use a special method for resolution method saves 1398 method->SetDexMethodIndex(DexFile::kDexNoIndex); 1399 // When compiling, the code pointer will get set later when the image is loaded. 1400 if (runtime->IsAotCompiler()) { 1401 size_t pointer_size = GetInstructionSetPointerSize(instruction_set_); 1402 method->SetEntryPointFromQuickCompiledCodePtrSize(nullptr, pointer_size); 1403 } else { 1404 method->SetEntryPointFromQuickCompiledCode(GetQuickResolutionStub()); 1405 } 1406 return method.Get(); 1407} 1408 1409mirror::ArtMethod* Runtime::CreateCalleeSaveMethod() { 1410 Thread* self = Thread::Current(); 1411 Runtime* runtime = Runtime::Current(); 1412 ClassLinker* class_linker = runtime->GetClassLinker(); 1413 StackHandleScope<1> hs(self); 1414 Handle<mirror::ArtMethod> method(hs.NewHandle(class_linker->AllocArtMethod(self))); 1415 method->SetDeclaringClass(mirror::ArtMethod::GetJavaLangReflectArtMethod()); 1416 // TODO: use a special method for callee saves 1417 method->SetDexMethodIndex(DexFile::kDexNoIndex); 1418 size_t pointer_size = GetInstructionSetPointerSize(instruction_set_); 1419 method->SetEntryPointFromQuickCompiledCodePtrSize(nullptr, pointer_size); 1420 DCHECK_NE(instruction_set_, kNone); 1421 return method.Get(); 1422} 1423 1424void Runtime::DisallowNewSystemWeaks() { 1425 monitor_list_->DisallowNewMonitors(); 1426 intern_table_->DisallowNewInterns(); 1427 java_vm_->DisallowNewWeakGlobals(); 1428} 1429 1430void Runtime::AllowNewSystemWeaks() { 1431 monitor_list_->AllowNewMonitors(); 1432 intern_table_->AllowNewInterns(); 1433 java_vm_->AllowNewWeakGlobals(); 1434} 1435 1436void Runtime::EnsureNewSystemWeaksDisallowed() { 1437 // Lock and unlock the system weak locks once to ensure that no 1438 // threads are still in the middle of adding new system weaks. 1439 monitor_list_->EnsureNewMonitorsDisallowed(); 1440 intern_table_->EnsureNewInternsDisallowed(); 1441 java_vm_->EnsureNewWeakGlobalsDisallowed(); 1442} 1443 1444void Runtime::SetInstructionSet(InstructionSet instruction_set) { 1445 instruction_set_ = instruction_set; 1446 if ((instruction_set_ == kThumb2) || (instruction_set_ == kArm)) { 1447 for (int i = 0; i != kLastCalleeSaveType; ++i) { 1448 CalleeSaveType type = static_cast<CalleeSaveType>(i); 1449 callee_save_method_frame_infos_[i] = arm::ArmCalleeSaveMethodFrameInfo(type); 1450 } 1451 } else if (instruction_set_ == kMips) { 1452 for (int i = 0; i != kLastCalleeSaveType; ++i) { 1453 CalleeSaveType type = static_cast<CalleeSaveType>(i); 1454 callee_save_method_frame_infos_[i] = mips::MipsCalleeSaveMethodFrameInfo(type); 1455 } 1456 } else if (instruction_set_ == kMips64) { 1457 for (int i = 0; i != kLastCalleeSaveType; ++i) { 1458 CalleeSaveType type = static_cast<CalleeSaveType>(i); 1459 callee_save_method_frame_infos_[i] = mips64::Mips64CalleeSaveMethodFrameInfo(type); 1460 } 1461 } else if (instruction_set_ == kX86) { 1462 for (int i = 0; i != kLastCalleeSaveType; ++i) { 1463 CalleeSaveType type = static_cast<CalleeSaveType>(i); 1464 callee_save_method_frame_infos_[i] = x86::X86CalleeSaveMethodFrameInfo(type); 1465 } 1466 } else if (instruction_set_ == kX86_64) { 1467 for (int i = 0; i != kLastCalleeSaveType; ++i) { 1468 CalleeSaveType type = static_cast<CalleeSaveType>(i); 1469 callee_save_method_frame_infos_[i] = x86_64::X86_64CalleeSaveMethodFrameInfo(type); 1470 } 1471 } else if (instruction_set_ == kArm64) { 1472 for (int i = 0; i != kLastCalleeSaveType; ++i) { 1473 CalleeSaveType type = static_cast<CalleeSaveType>(i); 1474 callee_save_method_frame_infos_[i] = arm64::Arm64CalleeSaveMethodFrameInfo(type); 1475 } 1476 } else { 1477 UNIMPLEMENTED(FATAL) << instruction_set_; 1478 } 1479} 1480 1481void Runtime::SetCalleeSaveMethod(mirror::ArtMethod* method, CalleeSaveType type) { 1482 DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastCalleeSaveType)); 1483 callee_save_methods_[type] = GcRoot<mirror::ArtMethod>(method); 1484} 1485 1486const std::vector<const DexFile*>& Runtime::GetCompileTimeClassPath(jobject class_loader) { 1487 if (class_loader == NULL) { 1488 return GetClassLinker()->GetBootClassPath(); 1489 } 1490 CHECK(UseCompileTimeClassPath()); 1491 CompileTimeClassPaths::const_iterator it = compile_time_class_paths_.find(class_loader); 1492 CHECK(it != compile_time_class_paths_.end()); 1493 return it->second; 1494} 1495 1496void Runtime::SetCompileTimeClassPath(jobject class_loader, 1497 std::vector<const DexFile*>& class_path) { 1498 CHECK(!IsStarted()); 1499 use_compile_time_class_path_ = true; 1500 compile_time_class_paths_.Put(class_loader, class_path); 1501} 1502 1503void Runtime::StartProfiler(const char* profile_output_filename) { 1504 profile_output_filename_ = profile_output_filename; 1505 profiler_started_ = 1506 BackgroundMethodSamplingProfiler::Start(profile_output_filename_, profiler_options_); 1507} 1508 1509// Transaction support. 1510void Runtime::EnterTransactionMode(Transaction* transaction) { 1511 DCHECK(IsAotCompiler()); 1512 DCHECK(transaction != nullptr); 1513 DCHECK(!IsActiveTransaction()); 1514 preinitialization_transaction_ = transaction; 1515} 1516 1517void Runtime::ExitTransactionMode() { 1518 DCHECK(IsAotCompiler()); 1519 DCHECK(IsActiveTransaction()); 1520 preinitialization_transaction_ = nullptr; 1521} 1522 1523 1524bool Runtime::IsTransactionAborted() const { 1525 if (!IsActiveTransaction()) { 1526 return false; 1527 } else { 1528 DCHECK(IsAotCompiler()); 1529 return preinitialization_transaction_->IsAborted(); 1530 } 1531} 1532 1533void Runtime::AbortTransactionAndThrowInternalError(Thread* self, 1534 const std::string& abort_message) { 1535 DCHECK(IsAotCompiler()); 1536 DCHECK(IsActiveTransaction()); 1537 // Throwing an exception may cause its class initialization. If we mark the transaction 1538 // aborted before that, we may warn with a false alarm. Throwing the exception before 1539 // marking the transaction aborted avoids that. 1540 preinitialization_transaction_->ThrowInternalError(self, false); 1541 preinitialization_transaction_->Abort(abort_message); 1542} 1543 1544void Runtime::ThrowInternalErrorForAbortedTransaction(Thread* self) { 1545 DCHECK(IsAotCompiler()); 1546 DCHECK(IsActiveTransaction()); 1547 preinitialization_transaction_->ThrowInternalError(self, true); 1548} 1549 1550void Runtime::RecordWriteFieldBoolean(mirror::Object* obj, MemberOffset field_offset, 1551 uint8_t value, bool is_volatile) const { 1552 DCHECK(IsAotCompiler()); 1553 DCHECK(IsActiveTransaction()); 1554 preinitialization_transaction_->RecordWriteFieldBoolean(obj, field_offset, value, is_volatile); 1555} 1556 1557void Runtime::RecordWriteFieldByte(mirror::Object* obj, MemberOffset field_offset, 1558 int8_t value, bool is_volatile) const { 1559 DCHECK(IsAotCompiler()); 1560 DCHECK(IsActiveTransaction()); 1561 preinitialization_transaction_->RecordWriteFieldByte(obj, field_offset, value, is_volatile); 1562} 1563 1564void Runtime::RecordWriteFieldChar(mirror::Object* obj, MemberOffset field_offset, 1565 uint16_t value, bool is_volatile) const { 1566 DCHECK(IsAotCompiler()); 1567 DCHECK(IsActiveTransaction()); 1568 preinitialization_transaction_->RecordWriteFieldChar(obj, field_offset, value, is_volatile); 1569} 1570 1571void Runtime::RecordWriteFieldShort(mirror::Object* obj, MemberOffset field_offset, 1572 int16_t value, bool is_volatile) const { 1573 DCHECK(IsAotCompiler()); 1574 DCHECK(IsActiveTransaction()); 1575 preinitialization_transaction_->RecordWriteFieldShort(obj, field_offset, value, is_volatile); 1576} 1577 1578void Runtime::RecordWriteField32(mirror::Object* obj, MemberOffset field_offset, 1579 uint32_t value, bool is_volatile) const { 1580 DCHECK(IsAotCompiler()); 1581 DCHECK(IsActiveTransaction()); 1582 preinitialization_transaction_->RecordWriteField32(obj, field_offset, value, is_volatile); 1583} 1584 1585void Runtime::RecordWriteField64(mirror::Object* obj, MemberOffset field_offset, 1586 uint64_t value, bool is_volatile) const { 1587 DCHECK(IsAotCompiler()); 1588 DCHECK(IsActiveTransaction()); 1589 preinitialization_transaction_->RecordWriteField64(obj, field_offset, value, is_volatile); 1590} 1591 1592void Runtime::RecordWriteFieldReference(mirror::Object* obj, MemberOffset field_offset, 1593 mirror::Object* value, bool is_volatile) const { 1594 DCHECK(IsAotCompiler()); 1595 DCHECK(IsActiveTransaction()); 1596 preinitialization_transaction_->RecordWriteFieldReference(obj, field_offset, value, is_volatile); 1597} 1598 1599void Runtime::RecordWriteArray(mirror::Array* array, size_t index, uint64_t value) const { 1600 DCHECK(IsAotCompiler()); 1601 DCHECK(IsActiveTransaction()); 1602 preinitialization_transaction_->RecordWriteArray(array, index, value); 1603} 1604 1605void Runtime::RecordStrongStringInsertion(mirror::String* s) const { 1606 DCHECK(IsAotCompiler()); 1607 DCHECK(IsActiveTransaction()); 1608 preinitialization_transaction_->RecordStrongStringInsertion(s); 1609} 1610 1611void Runtime::RecordWeakStringInsertion(mirror::String* s) const { 1612 DCHECK(IsAotCompiler()); 1613 DCHECK(IsActiveTransaction()); 1614 preinitialization_transaction_->RecordWeakStringInsertion(s); 1615} 1616 1617void Runtime::RecordStrongStringRemoval(mirror::String* s) const { 1618 DCHECK(IsAotCompiler()); 1619 DCHECK(IsActiveTransaction()); 1620 preinitialization_transaction_->RecordStrongStringRemoval(s); 1621} 1622 1623void Runtime::RecordWeakStringRemoval(mirror::String* s) const { 1624 DCHECK(IsAotCompiler()); 1625 DCHECK(IsActiveTransaction()); 1626 preinitialization_transaction_->RecordWeakStringRemoval(s); 1627} 1628 1629void Runtime::SetFaultMessage(const std::string& message) { 1630 MutexLock mu(Thread::Current(), fault_message_lock_); 1631 fault_message_ = message; 1632} 1633 1634void Runtime::AddCurrentRuntimeFeaturesAsDex2OatArguments(std::vector<std::string>* argv) 1635 const { 1636 if (GetInstrumentation()->InterpretOnly() || UseJit()) { 1637 argv->push_back("--compiler-filter=interpret-only"); 1638 } 1639 1640 // Make the dex2oat instruction set match that of the launching runtime. If we have multiple 1641 // architecture support, dex2oat may be compiled as a different instruction-set than that 1642 // currently being executed. 1643 std::string instruction_set("--instruction-set="); 1644 instruction_set += GetInstructionSetString(kRuntimeISA); 1645 argv->push_back(instruction_set); 1646 1647 std::unique_ptr<const InstructionSetFeatures> features(InstructionSetFeatures::FromCppDefines()); 1648 std::string feature_string("--instruction-set-features="); 1649 feature_string += features->GetFeatureString(); 1650 argv->push_back(feature_string); 1651 1652 if (Dbg::IsJdwpConfigured()) { 1653 argv->push_back("--debuggable"); 1654 } 1655} 1656 1657void Runtime::UpdateProfilerState(int state) { 1658 VLOG(profiler) << "Profiler state updated to " << state; 1659} 1660 1661void Runtime::CreateJit() { 1662 CHECK(!IsAotCompiler()); 1663 std::string error_msg; 1664 jit_.reset(jit::Jit::Create(jit_options_.get(), &error_msg)); 1665 if (jit_.get() != nullptr) { 1666 compiler_callbacks_ = jit_->GetCompilerCallbacks(); 1667 jit_->CreateInstrumentationCache(jit_options_->GetCompileThreshold()); 1668 jit_->CreateThreadPool(); 1669 } else { 1670 LOG(WARNING) << "Failed to create JIT " << error_msg; 1671 } 1672} 1673 1674} // namespace art 1675