runtime.cc revision 68d8b42ddec39ec0174162d90d4abaa004d1983e
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> 33#include <vector> 34#include <fcntl.h> 35 36#include "arch/arm/quick_method_frame_info_arm.h" 37#include "arch/arm/registers_arm.h" 38#include "arch/arm64/quick_method_frame_info_arm64.h" 39#include "arch/arm64/registers_arm64.h" 40#include "arch/mips/quick_method_frame_info_mips.h" 41#include "arch/mips/registers_mips.h" 42#include "arch/x86/quick_method_frame_info_x86.h" 43#include "arch/x86/registers_x86.h" 44#include "arch/x86_64/quick_method_frame_info_x86_64.h" 45#include "arch/x86_64/registers_x86_64.h" 46#include "atomic.h" 47#include "class_linker.h" 48#include "debugger.h" 49#include "fault_handler.h" 50#include "gc/accounting/card_table-inl.h" 51#include "gc/heap.h" 52#include "gc/space/image_space.h" 53#include "gc/space/space.h" 54#include "image.h" 55#include "instrumentation.h" 56#include "intern_table.h" 57#include "jni_internal.h" 58#include "mirror/art_field-inl.h" 59#include "mirror/art_method-inl.h" 60#include "mirror/array.h" 61#include "mirror/class-inl.h" 62#include "mirror/class_loader.h" 63#include "mirror/stack_trace_element.h" 64#include "mirror/throwable.h" 65#include "monitor.h" 66#include "native_bridge.h" 67#include "parsed_options.h" 68#include "oat_file.h" 69#include "quick/quick_method_frame_info.h" 70#include "reflection.h" 71#include "ScopedLocalRef.h" 72#include "scoped_thread_state_change.h" 73#include "signal_catcher.h" 74#include "signal_set.h" 75#include "handle_scope-inl.h" 76#include "thread.h" 77#include "thread_list.h" 78#include "trace.h" 79#include "transaction.h" 80#include "profiler.h" 81#include "verifier/method_verifier.h" 82#include "well_known_classes.h" 83 84#include "JniConstants.h" // Last to avoid LOG redefinition in ics-mr1-plus-art. 85 86#ifdef HAVE_ANDROID_OS 87#include "cutils/properties.h" 88#endif 89 90namespace art { 91 92static constexpr bool kEnableJavaStackTraceHandler = true; 93const char* Runtime::kDefaultInstructionSetFeatures = 94 STRINGIFY(ART_DEFAULT_INSTRUCTION_SET_FEATURES); 95Runtime* Runtime::instance_ = NULL; 96 97Runtime::Runtime() 98 : instruction_set_(kNone), 99 compiler_callbacks_(nullptr), 100 is_zygote_(false), 101 must_relocate_(false), 102 is_concurrent_gc_enabled_(true), 103 is_explicit_gc_disabled_(false), 104 default_stack_size_(0), 105 heap_(nullptr), 106 max_spins_before_thin_lock_inflation_(Monitor::kDefaultMaxSpinsBeforeThinLockInflation), 107 monitor_list_(nullptr), 108 monitor_pool_(nullptr), 109 thread_list_(nullptr), 110 intern_table_(nullptr), 111 class_linker_(nullptr), 112 signal_catcher_(nullptr), 113 java_vm_(nullptr), 114 fault_message_lock_("Fault message lock"), 115 fault_message_(""), 116 method_verifier_lock_("Method verifiers lock"), 117 threads_being_born_(0), 118 shutdown_cond_(new ConditionVariable("Runtime shutdown", *Locks::runtime_shutdown_lock_)), 119 shutting_down_(false), 120 shutting_down_started_(false), 121 started_(false), 122 finished_starting_(false), 123 vfprintf_(nullptr), 124 exit_(nullptr), 125 abort_(nullptr), 126 stats_enabled_(false), 127 running_on_valgrind_(RUNNING_ON_VALGRIND > 0), 128 profiler_started_(false), 129 method_trace_(false), 130 method_trace_file_size_(0), 131 instrumentation_(), 132 use_compile_time_class_path_(false), 133 main_thread_group_(nullptr), 134 system_thread_group_(nullptr), 135 system_class_loader_(nullptr), 136 dump_gc_performance_on_shutdown_(false), 137 preinitialization_transaction_(nullptr), 138 null_pointer_handler_(nullptr), 139 suspend_handler_(nullptr), 140 stack_overflow_handler_(nullptr), 141 verify_(false), 142 target_sdk_version_(0), 143 implicit_null_checks_(false), 144 implicit_so_checks_(false), 145 implicit_suspend_checks_(false) { 146} 147 148Runtime::~Runtime() { 149 if (dump_gc_performance_on_shutdown_) { 150 // This can't be called from the Heap destructor below because it 151 // could call RosAlloc::InspectAll() which needs the thread_list 152 // to be still alive. 153 heap_->DumpGcPerformanceInfo(LOG(INFO)); 154 } 155 156 Thread* self = Thread::Current(); 157 { 158 MutexLock mu(self, *Locks::runtime_shutdown_lock_); 159 shutting_down_started_ = true; 160 while (threads_being_born_ > 0) { 161 shutdown_cond_->Wait(self); 162 } 163 shutting_down_ = true; 164 } 165 // Shut down background profiler before the runtime exits. 166 if (profiler_started_) { 167 BackgroundMethodSamplingProfiler::Shutdown(); 168 } 169 170 Trace::Shutdown(); 171 172 // Make sure to let the GC complete if it is running. 173 heap_->WaitForGcToComplete(gc::kGcCauseBackground, self); 174 heap_->DeleteThreadPool(); 175 176 // Make sure our internal threads are dead before we start tearing down things they're using. 177 Dbg::StopJdwp(); 178 delete signal_catcher_; 179 180 // Make sure all other non-daemon threads have terminated, and all daemon threads are suspended. 181 delete thread_list_; 182 delete monitor_list_; 183 delete monitor_pool_; 184 delete class_linker_; 185 delete heap_; 186 delete intern_table_; 187 delete java_vm_; 188 Thread::Shutdown(); 189 QuasiAtomic::Shutdown(); 190 verifier::MethodVerifier::Shutdown(); 191 // TODO: acquire a static mutex on Runtime to avoid racing. 192 CHECK(instance_ == nullptr || instance_ == this); 193 instance_ = nullptr; 194 195 delete null_pointer_handler_; 196 delete suspend_handler_; 197 delete stack_overflow_handler_; 198} 199 200struct AbortState { 201 void Dump(std::ostream& os) NO_THREAD_SAFETY_ANALYSIS { 202 if (gAborting > 1) { 203 os << "Runtime aborting --- recursively, so no thread-specific detail!\n"; 204 return; 205 } 206 gAborting++; 207 os << "Runtime aborting...\n"; 208 if (Runtime::Current() == NULL) { 209 os << "(Runtime does not yet exist!)\n"; 210 return; 211 } 212 Thread* self = Thread::Current(); 213 if (self == nullptr) { 214 os << "(Aborting thread was not attached to runtime!)\n"; 215 DumpKernelStack(os, GetTid(), " kernel: ", false); 216 DumpNativeStack(os, GetTid(), " native: ", nullptr); 217 } else { 218 os << "Aborting thread:\n"; 219 if (Locks::mutator_lock_->IsExclusiveHeld(self) || Locks::mutator_lock_->IsSharedHeld(self)) { 220 DumpThread(os, self); 221 } else { 222 if (Locks::mutator_lock_->SharedTryLock(self)) { 223 DumpThread(os, self); 224 Locks::mutator_lock_->SharedUnlock(self); 225 } 226 } 227 } 228 DumpAllThreads(os, self); 229 } 230 231 void DumpThread(std::ostream& os, Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 232 self->Dump(os); 233 if (self->IsExceptionPending()) { 234 ThrowLocation throw_location; 235 mirror::Throwable* exception = self->GetException(&throw_location); 236 os << "Pending exception " << PrettyTypeOf(exception) 237 << " thrown by '" << throw_location.Dump() << "'\n" 238 << exception->Dump(); 239 } 240 } 241 242 void DumpAllThreads(std::ostream& os, Thread* self) NO_THREAD_SAFETY_ANALYSIS { 243 Runtime* runtime = Runtime::Current(); 244 if (runtime != nullptr) { 245 ThreadList* thread_list = runtime->GetThreadList(); 246 if (thread_list != nullptr) { 247 bool tll_already_held = Locks::thread_list_lock_->IsExclusiveHeld(self); 248 bool ml_already_held = Locks::mutator_lock_->IsSharedHeld(self); 249 if (!tll_already_held || !ml_already_held) { 250 os << "Dumping all threads without appropriate locks held:" 251 << (!tll_already_held ? " thread list lock" : "") 252 << (!ml_already_held ? " mutator lock" : "") 253 << "\n"; 254 } 255 os << "All threads:\n"; 256 thread_list->DumpLocked(os); 257 } 258 } 259 } 260}; 261 262void Runtime::Abort() { 263 gAborting++; // set before taking any locks 264 265 // Ensure that we don't have multiple threads trying to abort at once, 266 // which would result in significantly worse diagnostics. 267 MutexLock mu(Thread::Current(), *Locks::abort_lock_); 268 269 // Get any pending output out of the way. 270 fflush(NULL); 271 272 // Many people have difficulty distinguish aborts from crashes, 273 // so be explicit. 274 AbortState state; 275 LOG(INTERNAL_FATAL) << Dumpable<AbortState>(state); 276 277 // Call the abort hook if we have one. 278 if (Runtime::Current() != NULL && Runtime::Current()->abort_ != NULL) { 279 LOG(INTERNAL_FATAL) << "Calling abort hook..."; 280 Runtime::Current()->abort_(); 281 // notreached 282 LOG(INTERNAL_FATAL) << "Unexpectedly returned from abort hook!"; 283 } 284 285#if defined(__GLIBC__) 286 // TODO: we ought to be able to use pthread_kill(3) here (or abort(3), 287 // which POSIX defines in terms of raise(3), which POSIX defines in terms 288 // of pthread_kill(3)). On Linux, though, libcorkscrew can't unwind through 289 // libpthread, which means the stacks we dump would be useless. Calling 290 // tgkill(2) directly avoids that. 291 syscall(__NR_tgkill, getpid(), GetTid(), SIGABRT); 292 // TODO: LLVM installs it's own SIGABRT handler so exit to be safe... Can we disable that in LLVM? 293 // If not, we could use sigaction(3) before calling tgkill(2) and lose this call to exit(3). 294 exit(1); 295#else 296 abort(); 297#endif 298 // notreached 299} 300 301void Runtime::PreZygoteFork() { 302 heap_->PreZygoteFork(); 303} 304 305void Runtime::CallExitHook(jint status) { 306 if (exit_ != NULL) { 307 ScopedThreadStateChange tsc(Thread::Current(), kNative); 308 exit_(status); 309 LOG(WARNING) << "Exit hook returned instead of exiting!"; 310 } 311} 312 313void Runtime::SweepSystemWeaks(IsMarkedCallback* visitor, void* arg) { 314 GetInternTable()->SweepInternTableWeaks(visitor, arg); 315 GetMonitorList()->SweepMonitorList(visitor, arg); 316 GetJavaVM()->SweepJniWeakGlobals(visitor, arg); 317} 318 319bool Runtime::Create(const RuntimeOptions& options, bool ignore_unrecognized) { 320 // TODO: acquire a static mutex on Runtime to avoid racing. 321 if (Runtime::instance_ != NULL) { 322 return false; 323 } 324 InitLogging(NULL); // Calls Locks::Init() as a side effect. 325 instance_ = new Runtime; 326 if (!instance_->Init(options, ignore_unrecognized)) { 327 delete instance_; 328 instance_ = NULL; 329 return false; 330 } 331 return true; 332} 333 334jobject CreateSystemClassLoader() { 335 if (Runtime::Current()->UseCompileTimeClassPath()) { 336 return NULL; 337 } 338 339 ScopedObjectAccess soa(Thread::Current()); 340 ClassLinker* cl = Runtime::Current()->GetClassLinker(); 341 342 StackHandleScope<2> hs(soa.Self()); 343 Handle<mirror::Class> class_loader_class( 344 hs.NewHandle(soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_ClassLoader))); 345 CHECK(cl->EnsureInitialized(class_loader_class, true, true)); 346 347 mirror::ArtMethod* getSystemClassLoader = 348 class_loader_class->FindDirectMethod("getSystemClassLoader", "()Ljava/lang/ClassLoader;"); 349 CHECK(getSystemClassLoader != NULL); 350 351 JValue result = InvokeWithJValues(soa, nullptr, soa.EncodeMethod(getSystemClassLoader), nullptr); 352 JNIEnv* env = soa.Self()->GetJniEnv(); 353 ScopedLocalRef<jobject> system_class_loader(env, 354 soa.AddLocalReference<jobject>(result.GetL())); 355 CHECK(system_class_loader.get() != nullptr); 356 357 soa.Self()->SetClassLoaderOverride(system_class_loader.get()); 358 359 Handle<mirror::Class> thread_class( 360 hs.NewHandle(soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_Thread))); 361 CHECK(cl->EnsureInitialized(thread_class, true, true)); 362 363 mirror::ArtField* contextClassLoader = 364 thread_class->FindDeclaredInstanceField("contextClassLoader", "Ljava/lang/ClassLoader;"); 365 CHECK(contextClassLoader != NULL); 366 367 // We can't run in a transaction yet. 368 contextClassLoader->SetObject<false>(soa.Self()->GetPeer(), 369 soa.Decode<mirror::ClassLoader*>(system_class_loader.get())); 370 371 return env->NewGlobalRef(system_class_loader.get()); 372} 373 374std::string Runtime::GetPatchoatExecutable() const { 375 if (!patchoat_executable_.empty()) { 376 return patchoat_executable_; 377 } 378 std::string patchoat_executable_(GetAndroidRoot()); 379 patchoat_executable_ += (kIsDebugBuild ? "/bin/patchoatd" : "/bin/patchoat"); 380 return patchoat_executable_; 381} 382 383std::string Runtime::GetCompilerExecutable() const { 384 if (!compiler_executable_.empty()) { 385 return compiler_executable_; 386 } 387 std::string compiler_executable(GetAndroidRoot()); 388 compiler_executable += (kIsDebugBuild ? "/bin/dex2oatd" : "/bin/dex2oat"); 389 return compiler_executable; 390} 391 392bool Runtime::Start() { 393 VLOG(startup) << "Runtime::Start entering"; 394 395 // Restore main thread state to kNative as expected by native code. 396 Thread* self = Thread::Current(); 397 self->TransitionFromRunnableToSuspended(kNative); 398 399 started_ = true; 400 401 // InitNativeMethods needs to be after started_ so that the classes 402 // it touches will have methods linked to the oat file if necessary. 403 InitNativeMethods(); 404 405 // Initialize well known thread group values that may be accessed threads while attaching. 406 InitThreadGroups(self); 407 408 Thread::FinishStartup(); 409 410 if (is_zygote_) { 411 if (!InitZygote()) { 412 return false; 413 } 414 } else { 415 DidForkFromZygote(); 416 } 417 418 StartDaemonThreads(); 419 420 system_class_loader_ = CreateSystemClassLoader(); 421 422 { 423 ScopedObjectAccess soa(self); 424 self->GetJniEnv()->locals.AssertEmpty(); 425 } 426 427 VLOG(startup) << "Runtime::Start exiting"; 428 finished_starting_ = true; 429 430 if (profiler_options_.IsEnabled() && !profile_output_filename_.empty()) { 431 // User has asked for a profile using -Xenable-profiler. 432 // Create the profile file if it doesn't exist. 433 int fd = open(profile_output_filename_.c_str(), O_RDWR|O_CREAT|O_EXCL, 0660); 434 if (fd >= 0) { 435 close(fd); 436 } else if (errno != EEXIST) { 437 LOG(INFO) << "Failed to access the profile file. Profiler disabled."; 438 return true; 439 } 440 StartProfiler(profile_output_filename_.c_str()); 441 } 442 443 return true; 444} 445 446void Runtime::EndThreadBirth() EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_) { 447 DCHECK_GT(threads_being_born_, 0U); 448 threads_being_born_--; 449 if (shutting_down_started_ && threads_being_born_ == 0) { 450 shutdown_cond_->Broadcast(Thread::Current()); 451 } 452} 453 454// Do zygote-mode-only initialization. 455bool Runtime::InitZygote() { 456#ifdef __linux__ 457 // zygote goes into its own process group 458 setpgid(0, 0); 459 460 // See storage config details at http://source.android.com/tech/storage/ 461 // Create private mount namespace shared by all children 462 if (unshare(CLONE_NEWNS) == -1) { 463 PLOG(WARNING) << "Failed to unshare()"; 464 return false; 465 } 466 467 // Mark rootfs as being a slave so that changes from default 468 // namespace only flow into our children. 469 if (mount("rootfs", "/", NULL, (MS_SLAVE | MS_REC), NULL) == -1) { 470 PLOG(WARNING) << "Failed to mount() rootfs as MS_SLAVE"; 471 return false; 472 } 473 474 // Create a staging tmpfs that is shared by our children; they will 475 // bind mount storage into their respective private namespaces, which 476 // are isolated from each other. 477 const char* target_base = getenv("EMULATED_STORAGE_TARGET"); 478 if (target_base != NULL) { 479 if (mount("tmpfs", target_base, "tmpfs", MS_NOSUID | MS_NODEV, 480 "uid=0,gid=1028,mode=0751") == -1) { 481 LOG(WARNING) << "Failed to mount tmpfs to " << target_base; 482 return false; 483 } 484 } 485 486 return true; 487#else 488 UNIMPLEMENTED(FATAL); 489 return false; 490#endif 491} 492 493void Runtime::DidForkFromZygote() { 494 is_zygote_ = false; 495 496 // Create the thread pool. 497 heap_->CreateThreadPool(); 498 499 StartSignalCatcher(); 500 501 // Start the JDWP thread. If the command-line debugger flags specified "suspend=y", 502 // this will pause the runtime, so we probably want this to come last. 503 Dbg::StartJdwp(); 504} 505 506void Runtime::StartSignalCatcher() { 507 if (!is_zygote_) { 508 signal_catcher_ = new SignalCatcher(stack_trace_file_); 509 } 510} 511 512bool Runtime::IsShuttingDown(Thread* self) { 513 MutexLock mu(self, *Locks::runtime_shutdown_lock_); 514 return IsShuttingDownLocked(); 515} 516 517void Runtime::StartDaemonThreads() { 518 VLOG(startup) << "Runtime::StartDaemonThreads entering"; 519 520 Thread* self = Thread::Current(); 521 522 // Must be in the kNative state for calling native methods. 523 CHECK_EQ(self->GetState(), kNative); 524 525 JNIEnv* env = self->GetJniEnv(); 526 env->CallStaticVoidMethod(WellKnownClasses::java_lang_Daemons, 527 WellKnownClasses::java_lang_Daemons_start); 528 if (env->ExceptionCheck()) { 529 env->ExceptionDescribe(); 530 LOG(FATAL) << "Error starting java.lang.Daemons"; 531 } 532 533 VLOG(startup) << "Runtime::StartDaemonThreads exiting"; 534} 535 536bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized) { 537 CHECK_EQ(sysconf(_SC_PAGE_SIZE), kPageSize); 538 539 std::unique_ptr<ParsedOptions> options(ParsedOptions::Create(raw_options, ignore_unrecognized)); 540 if (options.get() == NULL) { 541 LOG(ERROR) << "Failed to parse options"; 542 return false; 543 } 544 VLOG(startup) << "Runtime::Init -verbose:startup enabled"; 545 546 QuasiAtomic::Startup(); 547 548 Monitor::Init(options->lock_profiling_threshold_, options->hook_is_sensitive_thread_); 549 550 boot_class_path_string_ = options->boot_class_path_string_; 551 class_path_string_ = options->class_path_string_; 552 properties_ = options->properties_; 553 554 compiler_callbacks_ = options->compiler_callbacks_; 555 patchoat_executable_ = options->patchoat_executable_; 556 must_relocate_ = options->must_relocate_; 557 is_zygote_ = options->is_zygote_; 558 is_explicit_gc_disabled_ = options->is_explicit_gc_disabled_; 559 560 vfprintf_ = options->hook_vfprintf_; 561 exit_ = options->hook_exit_; 562 abort_ = options->hook_abort_; 563 564 default_stack_size_ = options->stack_size_; 565 stack_trace_file_ = options->stack_trace_file_; 566 567 compiler_executable_ = options->compiler_executable_; 568 compiler_options_ = options->compiler_options_; 569 image_compiler_options_ = options->image_compiler_options_; 570 571 max_spins_before_thin_lock_inflation_ = options->max_spins_before_thin_lock_inflation_; 572 573 monitor_list_ = new MonitorList; 574 monitor_pool_ = MonitorPool::Create(); 575 thread_list_ = new ThreadList; 576 intern_table_ = new InternTable; 577 578 verify_ = options->verify_; 579 580 if (options->interpreter_only_) { 581 GetInstrumentation()->ForceInterpretOnly(); 582 } 583 584 heap_ = new gc::Heap(options->heap_initial_size_, 585 options->heap_growth_limit_, 586 options->heap_min_free_, 587 options->heap_max_free_, 588 options->heap_target_utilization_, 589 options->foreground_heap_growth_multiplier_, 590 options->heap_maximum_size_, 591 options->image_, 592 options->image_isa_, 593 options->collector_type_, 594 options->background_collector_type_, 595 options->parallel_gc_threads_, 596 options->conc_gc_threads_, 597 options->low_memory_mode_, 598 options->long_pause_log_threshold_, 599 options->long_gc_log_threshold_, 600 options->ignore_max_footprint_, 601 options->use_tlab_, 602 options->verify_pre_gc_heap_, 603 options->verify_pre_sweeping_heap_, 604 options->verify_post_gc_heap_, 605 options->verify_pre_gc_rosalloc_, 606 options->verify_pre_sweeping_rosalloc_, 607 options->verify_post_gc_rosalloc_, 608 options->use_homogeneous_space_compaction_for_oom_, 609 options->min_interval_homogeneous_space_compaction_by_oom_); 610 611 dump_gc_performance_on_shutdown_ = options->dump_gc_performance_on_shutdown_; 612 613 BlockSignals(); 614 InitPlatformSignalHandlers(); 615 616 // Change the implicit checks flags based on runtime architecture. 617 switch (kRuntimeISA) { 618 case kArm: 619 case kThumb2: 620 case kX86: 621 case kArm64: 622 case kX86_64: 623 implicit_null_checks_ = true; 624 implicit_so_checks_ = true; 625 break; 626 default: 627 // Keep the defaults. 628 break; 629 } 630 631 if (implicit_null_checks_ || implicit_so_checks_ || implicit_suspend_checks_) { 632 fault_manager.Init(); 633 634 // These need to be in a specific order. The null point check handler must be 635 // after the suspend check and stack overflow check handlers. 636 if (implicit_suspend_checks_) { 637 suspend_handler_ = new SuspensionHandler(&fault_manager); 638 } 639 640 if (implicit_so_checks_) { 641 stack_overflow_handler_ = new StackOverflowHandler(&fault_manager); 642 } 643 644 if (implicit_null_checks_) { 645 null_pointer_handler_ = new NullPointerHandler(&fault_manager); 646 } 647 648 if (kEnableJavaStackTraceHandler) { 649 new JavaStackTraceHandler(&fault_manager); 650 } 651 } 652 653 java_vm_ = new JavaVMExt(this, options.get()); 654 655 Thread::Startup(); 656 657 // ClassLinker needs an attached thread, but we can't fully attach a thread without creating 658 // objects. We can't supply a thread group yet; it will be fixed later. Since we are the main 659 // thread, we do not get a java peer. 660 Thread* self = Thread::Attach("main", false, NULL, false); 661 CHECK_EQ(self->GetThreadId(), ThreadList::kMainThreadId); 662 CHECK(self != NULL); 663 664 // Set us to runnable so tools using a runtime can allocate and GC by default 665 self->TransitionFromSuspendedToRunnable(); 666 667 // Now we're attached, we can take the heap locks and validate the heap. 668 GetHeap()->EnableObjectValidation(); 669 670 CHECK_GE(GetHeap()->GetContinuousSpaces().size(), 1U); 671 class_linker_ = new ClassLinker(intern_table_); 672 if (GetHeap()->HasImageSpace()) { 673 class_linker_->InitFromImage(); 674 if (kIsDebugBuild) { 675 GetHeap()->GetImageSpace()->VerifyImageAllocations(); 676 } 677 } else { 678 CHECK(options->boot_class_path_ != NULL); 679 CHECK_NE(options->boot_class_path_->size(), 0U); 680 class_linker_->InitFromCompiler(*options->boot_class_path_); 681 } 682 CHECK(class_linker_ != NULL); 683 verifier::MethodVerifier::Init(); 684 685 method_trace_ = options->method_trace_; 686 method_trace_file_ = options->method_trace_file_; 687 method_trace_file_size_ = options->method_trace_file_size_; 688 689 profile_output_filename_ = options->profile_output_filename_; 690 profiler_options_ = options->profiler_options_; 691 692 // TODO: move this to just be an Trace::Start argument 693 Trace::SetDefaultClockSource(options->profile_clock_source_); 694 695 if (options->method_trace_) { 696 ScopedThreadStateChange tsc(self, kWaitingForMethodTracingStart); 697 Trace::Start(options->method_trace_file_.c_str(), -1, options->method_trace_file_size_, 0, 698 false, false, 0); 699 } 700 701 // Pre-allocate an OutOfMemoryError for the double-OOME case. 702 self->ThrowNewException(ThrowLocation(), "Ljava/lang/OutOfMemoryError;", 703 "OutOfMemoryError thrown while trying to throw OutOfMemoryError; " 704 "no stack available"); 705 pre_allocated_OutOfMemoryError_ = GcRoot<mirror::Throwable>(self->GetException(NULL)); 706 self->ClearException(); 707 708 // Look for a native bridge. 709 SetNativeBridgeLibraryString(options->native_bridge_library_string_); 710 711 VLOG(startup) << "Runtime::Init exiting"; 712 return true; 713} 714 715void Runtime::InitNativeMethods() { 716 VLOG(startup) << "Runtime::InitNativeMethods entering"; 717 Thread* self = Thread::Current(); 718 JNIEnv* env = self->GetJniEnv(); 719 720 // Must be in the kNative state for calling native methods (JNI_OnLoad code). 721 CHECK_EQ(self->GetState(), kNative); 722 723 // First set up JniConstants, which is used by both the runtime's built-in native 724 // methods and libcore. 725 JniConstants::init(env); 726 WellKnownClasses::Init(env); 727 728 // Then set up the native methods provided by the runtime itself. 729 RegisterRuntimeNativeMethods(env); 730 731 // Then set up libcore, which is just a regular JNI library with a regular JNI_OnLoad. 732 // Most JNI libraries can just use System.loadLibrary, but libcore can't because it's 733 // the library that implements System.loadLibrary! 734 { 735 std::string mapped_name(StringPrintf(OS_SHARED_LIB_FORMAT_STR, "javacore")); 736 std::string reason; 737 if (!instance_->java_vm_->LoadNativeLibrary(env, mapped_name, nullptr, &reason)) { 738 LOG(FATAL) << "LoadNativeLibrary failed for \"" << mapped_name << "\": " << reason; 739 } 740 } 741 742 // Initialize well known classes that may invoke runtime native methods. 743 WellKnownClasses::LateInit(env); 744 745 VLOG(startup) << "Runtime::InitNativeMethods exiting"; 746} 747 748void Runtime::InitThreadGroups(Thread* self) { 749 JNIEnvExt* env = self->GetJniEnv(); 750 ScopedJniEnvLocalRefState env_state(env); 751 main_thread_group_ = 752 env->NewGlobalRef(env->GetStaticObjectField( 753 WellKnownClasses::java_lang_ThreadGroup, 754 WellKnownClasses::java_lang_ThreadGroup_mainThreadGroup)); 755 CHECK(main_thread_group_ != NULL || IsCompiler()); 756 system_thread_group_ = 757 env->NewGlobalRef(env->GetStaticObjectField( 758 WellKnownClasses::java_lang_ThreadGroup, 759 WellKnownClasses::java_lang_ThreadGroup_systemThreadGroup)); 760 CHECK(system_thread_group_ != NULL || IsCompiler()); 761} 762 763jobject Runtime::GetMainThreadGroup() const { 764 CHECK(main_thread_group_ != NULL || IsCompiler()); 765 return main_thread_group_; 766} 767 768jobject Runtime::GetSystemThreadGroup() const { 769 CHECK(system_thread_group_ != NULL || IsCompiler()); 770 return system_thread_group_; 771} 772 773jobject Runtime::GetSystemClassLoader() const { 774 CHECK(system_class_loader_ != NULL || IsCompiler()); 775 return system_class_loader_; 776} 777 778void Runtime::RegisterRuntimeNativeMethods(JNIEnv* env) { 779#define REGISTER(FN) extern void FN(JNIEnv*); FN(env) 780 // Register Throwable first so that registration of other native methods can throw exceptions 781 REGISTER(register_java_lang_Throwable); 782 REGISTER(register_dalvik_system_DexFile); 783 REGISTER(register_dalvik_system_VMDebug); 784 REGISTER(register_dalvik_system_VMRuntime); 785 REGISTER(register_dalvik_system_VMStack); 786 REGISTER(register_dalvik_system_ZygoteHooks); 787 REGISTER(register_java_lang_Class); 788 REGISTER(register_java_lang_DexCache); 789 REGISTER(register_java_lang_Object); 790 REGISTER(register_java_lang_Runtime); 791 REGISTER(register_java_lang_String); 792 REGISTER(register_java_lang_System); 793 REGISTER(register_java_lang_Thread); 794 REGISTER(register_java_lang_VMClassLoader); 795 REGISTER(register_java_lang_ref_Reference); 796 REGISTER(register_java_lang_reflect_Array); 797 REGISTER(register_java_lang_reflect_Constructor); 798 REGISTER(register_java_lang_reflect_Field); 799 REGISTER(register_java_lang_reflect_Method); 800 REGISTER(register_java_lang_reflect_Proxy); 801 REGISTER(register_java_util_concurrent_atomic_AtomicLong); 802 REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmServer); 803 REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmVmInternal); 804 REGISTER(register_sun_misc_Unsafe); 805#undef REGISTER 806} 807 808void Runtime::DumpForSigQuit(std::ostream& os) { 809 GetClassLinker()->DumpForSigQuit(os); 810 GetInternTable()->DumpForSigQuit(os); 811 GetJavaVM()->DumpForSigQuit(os); 812 GetHeap()->DumpForSigQuit(os); 813 os << "\n"; 814 815 thread_list_->DumpForSigQuit(os); 816 BaseMutex::DumpAll(os); 817} 818 819void Runtime::DumpLockHolders(std::ostream& os) { 820 uint64_t mutator_lock_owner = Locks::mutator_lock_->GetExclusiveOwnerTid(); 821 pid_t thread_list_lock_owner = GetThreadList()->GetLockOwner(); 822 pid_t classes_lock_owner = GetClassLinker()->GetClassesLockOwner(); 823 pid_t dex_lock_owner = GetClassLinker()->GetDexLockOwner(); 824 if ((thread_list_lock_owner | classes_lock_owner | dex_lock_owner) != 0) { 825 os << "Mutator lock exclusive owner tid: " << mutator_lock_owner << "\n" 826 << "ThreadList lock owner tid: " << thread_list_lock_owner << "\n" 827 << "ClassLinker classes lock owner tid: " << classes_lock_owner << "\n" 828 << "ClassLinker dex lock owner tid: " << dex_lock_owner << "\n"; 829 } 830} 831 832void Runtime::SetStatsEnabled(bool new_state) { 833 if (new_state == true) { 834 GetStats()->Clear(~0); 835 // TODO: wouldn't it make more sense to clear _all_ threads' stats? 836 Thread::Current()->GetStats()->Clear(~0); 837 GetInstrumentation()->InstrumentQuickAllocEntryPoints(); 838 } else { 839 GetInstrumentation()->UninstrumentQuickAllocEntryPoints(); 840 } 841 stats_enabled_ = new_state; 842} 843 844void Runtime::ResetStats(int kinds) { 845 GetStats()->Clear(kinds & 0xffff); 846 // TODO: wouldn't it make more sense to clear _all_ threads' stats? 847 Thread::Current()->GetStats()->Clear(kinds >> 16); 848} 849 850int32_t Runtime::GetStat(int kind) { 851 RuntimeStats* stats; 852 if (kind < (1<<16)) { 853 stats = GetStats(); 854 } else { 855 stats = Thread::Current()->GetStats(); 856 kind >>= 16; 857 } 858 switch (kind) { 859 case KIND_ALLOCATED_OBJECTS: 860 return stats->allocated_objects; 861 case KIND_ALLOCATED_BYTES: 862 return stats->allocated_bytes; 863 case KIND_FREED_OBJECTS: 864 return stats->freed_objects; 865 case KIND_FREED_BYTES: 866 return stats->freed_bytes; 867 case KIND_GC_INVOCATIONS: 868 return stats->gc_for_alloc_count; 869 case KIND_CLASS_INIT_COUNT: 870 return stats->class_init_count; 871 case KIND_CLASS_INIT_TIME: 872 // Convert ns to us, reduce to 32 bits. 873 return static_cast<int>(stats->class_init_time_ns / 1000); 874 case KIND_EXT_ALLOCATED_OBJECTS: 875 case KIND_EXT_ALLOCATED_BYTES: 876 case KIND_EXT_FREED_OBJECTS: 877 case KIND_EXT_FREED_BYTES: 878 return 0; // backward compatibility 879 default: 880 LOG(FATAL) << "Unknown statistic " << kind; 881 return -1; // unreachable 882 } 883} 884 885void Runtime::BlockSignals() { 886 SignalSet signals; 887 signals.Add(SIGPIPE); 888 // SIGQUIT is used to dump the runtime's state (including stack traces). 889 signals.Add(SIGQUIT); 890 // SIGUSR1 is used to initiate a GC. 891 signals.Add(SIGUSR1); 892 signals.Block(); 893} 894 895bool Runtime::AttachCurrentThread(const char* thread_name, bool as_daemon, jobject thread_group, 896 bool create_peer) { 897 bool success = Thread::Attach(thread_name, as_daemon, thread_group, create_peer) != NULL; 898 if (thread_name == NULL) { 899 LOG(WARNING) << *Thread::Current() << " attached without supplying a name"; 900 } 901 return success; 902} 903 904void Runtime::DetachCurrentThread() { 905 Thread* self = Thread::Current(); 906 if (self == NULL) { 907 LOG(FATAL) << "attempting to detach thread that is not attached"; 908 } 909 if (self->HasManagedStack()) { 910 LOG(FATAL) << *Thread::Current() << " attempting to detach while still running code"; 911 } 912 thread_list_->Unregister(self); 913} 914 915mirror::Throwable* Runtime::GetPreAllocatedOutOfMemoryError() { 916 mirror::Throwable* oome = pre_allocated_OutOfMemoryError_.Read(); 917 if (oome == NULL) { 918 LOG(ERROR) << "Failed to return pre-allocated OOME"; 919 } 920 return oome; 921} 922 923void Runtime::VisitConstantRoots(RootCallback* callback, void* arg) { 924 // Visit the classes held as static in mirror classes, these can be visited concurrently and only 925 // need to be visited once per GC since they never change. 926 mirror::ArtField::VisitRoots(callback, arg); 927 mirror::ArtMethod::VisitRoots(callback, arg); 928 mirror::Class::VisitRoots(callback, arg); 929 mirror::Reference::VisitRoots(callback, arg); 930 mirror::StackTraceElement::VisitRoots(callback, arg); 931 mirror::String::VisitRoots(callback, arg); 932 mirror::Throwable::VisitRoots(callback, arg); 933 // Visit all the primitive array types classes. 934 mirror::PrimitiveArray<uint8_t>::VisitRoots(callback, arg); // BooleanArray 935 mirror::PrimitiveArray<int8_t>::VisitRoots(callback, arg); // ByteArray 936 mirror::PrimitiveArray<uint16_t>::VisitRoots(callback, arg); // CharArray 937 mirror::PrimitiveArray<double>::VisitRoots(callback, arg); // DoubleArray 938 mirror::PrimitiveArray<float>::VisitRoots(callback, arg); // FloatArray 939 mirror::PrimitiveArray<int32_t>::VisitRoots(callback, arg); // IntArray 940 mirror::PrimitiveArray<int64_t>::VisitRoots(callback, arg); // LongArray 941 mirror::PrimitiveArray<int16_t>::VisitRoots(callback, arg); // ShortArray 942} 943 944void Runtime::VisitConcurrentRoots(RootCallback* callback, void* arg, VisitRootFlags flags) { 945 intern_table_->VisitRoots(callback, arg, flags); 946 class_linker_->VisitRoots(callback, arg, flags); 947 if ((flags & kVisitRootFlagNewRoots) == 0) { 948 // Guaranteed to have no new roots in the constant roots. 949 VisitConstantRoots(callback, arg); 950 } 951} 952 953void Runtime::VisitNonThreadRoots(RootCallback* callback, void* arg) { 954 java_vm_->VisitRoots(callback, arg); 955 if (!pre_allocated_OutOfMemoryError_.IsNull()) { 956 pre_allocated_OutOfMemoryError_.VisitRoot(callback, arg, 0, kRootVMInternal); 957 DCHECK(!pre_allocated_OutOfMemoryError_.IsNull()); 958 } 959 resolution_method_.VisitRoot(callback, arg, 0, kRootVMInternal); 960 DCHECK(!resolution_method_.IsNull()); 961 if (HasImtConflictMethod()) { 962 imt_conflict_method_.VisitRoot(callback, arg, 0, kRootVMInternal); 963 } 964 if (HasDefaultImt()) { 965 default_imt_.VisitRoot(callback, arg, 0, kRootVMInternal); 966 } 967 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { 968 if (!callee_save_methods_[i].IsNull()) { 969 callee_save_methods_[i].VisitRoot(callback, arg, 0, kRootVMInternal); 970 } 971 } 972 { 973 MutexLock mu(Thread::Current(), method_verifier_lock_); 974 for (verifier::MethodVerifier* verifier : method_verifiers_) { 975 verifier->VisitRoots(callback, arg); 976 } 977 } 978 if (preinitialization_transaction_ != nullptr) { 979 preinitialization_transaction_->VisitRoots(callback, arg); 980 } 981 instrumentation_.VisitRoots(callback, arg); 982} 983 984void Runtime::VisitNonConcurrentRoots(RootCallback* callback, void* arg) { 985 thread_list_->VisitRoots(callback, arg); 986 VisitNonThreadRoots(callback, arg); 987} 988 989void Runtime::VisitRoots(RootCallback* callback, void* arg, VisitRootFlags flags) { 990 VisitNonConcurrentRoots(callback, arg); 991 VisitConcurrentRoots(callback, arg, flags); 992} 993 994mirror::ObjectArray<mirror::ArtMethod>* Runtime::CreateDefaultImt(ClassLinker* cl) { 995 Thread* self = Thread::Current(); 996 StackHandleScope<1> hs(self); 997 Handle<mirror::ObjectArray<mirror::ArtMethod>> imtable( 998 hs.NewHandle(cl->AllocArtMethodArray(self, 64))); 999 mirror::ArtMethod* imt_conflict_method = Runtime::Current()->GetImtConflictMethod(); 1000 for (size_t i = 0; i < static_cast<size_t>(imtable->GetLength()); i++) { 1001 imtable->Set<false>(i, imt_conflict_method); 1002 } 1003 return imtable.Get(); 1004} 1005 1006mirror::ArtMethod* Runtime::CreateImtConflictMethod() { 1007 Thread* self = Thread::Current(); 1008 Runtime* runtime = Runtime::Current(); 1009 ClassLinker* class_linker = runtime->GetClassLinker(); 1010 StackHandleScope<1> hs(self); 1011 Handle<mirror::ArtMethod> method(hs.NewHandle(class_linker->AllocArtMethod(self))); 1012 method->SetDeclaringClass(mirror::ArtMethod::GetJavaLangReflectArtMethod()); 1013 // TODO: use a special method for imt conflict method saves. 1014 method->SetDexMethodIndex(DexFile::kDexNoIndex); 1015 // When compiling, the code pointer will get set later when the image is loaded. 1016 if (runtime->IsCompiler()) { 1017 method->SetEntryPointFromPortableCompiledCode(nullptr); 1018 method->SetEntryPointFromQuickCompiledCode(nullptr); 1019 } else { 1020 method->SetEntryPointFromPortableCompiledCode(class_linker->GetPortableImtConflictTrampoline()); 1021 method->SetEntryPointFromQuickCompiledCode(class_linker->GetQuickImtConflictTrampoline()); 1022 } 1023 return method.Get(); 1024} 1025 1026mirror::ArtMethod* Runtime::CreateResolutionMethod() { 1027 Thread* self = Thread::Current(); 1028 Runtime* runtime = Runtime::Current(); 1029 ClassLinker* class_linker = runtime->GetClassLinker(); 1030 StackHandleScope<1> hs(self); 1031 Handle<mirror::ArtMethod> method(hs.NewHandle(class_linker->AllocArtMethod(self))); 1032 method->SetDeclaringClass(mirror::ArtMethod::GetJavaLangReflectArtMethod()); 1033 // TODO: use a special method for resolution method saves 1034 method->SetDexMethodIndex(DexFile::kDexNoIndex); 1035 // When compiling, the code pointer will get set later when the image is loaded. 1036 if (runtime->IsCompiler()) { 1037 method->SetEntryPointFromPortableCompiledCode(nullptr); 1038 method->SetEntryPointFromQuickCompiledCode(nullptr); 1039 } else { 1040 method->SetEntryPointFromPortableCompiledCode(class_linker->GetPortableResolutionTrampoline()); 1041 method->SetEntryPointFromQuickCompiledCode(class_linker->GetQuickResolutionTrampoline()); 1042 } 1043 return method.Get(); 1044} 1045 1046mirror::ArtMethod* Runtime::CreateCalleeSaveMethod(CalleeSaveType type) { 1047 Thread* self = Thread::Current(); 1048 Runtime* runtime = Runtime::Current(); 1049 ClassLinker* class_linker = runtime->GetClassLinker(); 1050 StackHandleScope<1> hs(self); 1051 Handle<mirror::ArtMethod> method(hs.NewHandle(class_linker->AllocArtMethod(self))); 1052 method->SetDeclaringClass(mirror::ArtMethod::GetJavaLangReflectArtMethod()); 1053 // TODO: use a special method for callee saves 1054 method->SetDexMethodIndex(DexFile::kDexNoIndex); 1055 method->SetEntryPointFromPortableCompiledCode(nullptr); 1056 method->SetEntryPointFromQuickCompiledCode(nullptr); 1057 DCHECK_NE(instruction_set_, kNone); 1058 return method.Get(); 1059} 1060 1061void Runtime::DisallowNewSystemWeaks() { 1062 monitor_list_->DisallowNewMonitors(); 1063 intern_table_->DisallowNewInterns(); 1064 java_vm_->DisallowNewWeakGlobals(); 1065} 1066 1067void Runtime::AllowNewSystemWeaks() { 1068 monitor_list_->AllowNewMonitors(); 1069 intern_table_->AllowNewInterns(); 1070 java_vm_->AllowNewWeakGlobals(); 1071} 1072 1073void Runtime::SetInstructionSet(InstructionSet instruction_set) { 1074 instruction_set_ = instruction_set; 1075 if ((instruction_set_ == kThumb2) || (instruction_set_ == kArm)) { 1076 for (int i = 0; i != kLastCalleeSaveType; ++i) { 1077 CalleeSaveType type = static_cast<CalleeSaveType>(i); 1078 callee_save_method_frame_infos_[i] = arm::ArmCalleeSaveMethodFrameInfo(type); 1079 } 1080 } else if (instruction_set_ == kMips) { 1081 for (int i = 0; i != kLastCalleeSaveType; ++i) { 1082 CalleeSaveType type = static_cast<CalleeSaveType>(i); 1083 callee_save_method_frame_infos_[i] = mips::MipsCalleeSaveMethodFrameInfo(type); 1084 } 1085 } else if (instruction_set_ == kX86) { 1086 for (int i = 0; i != kLastCalleeSaveType; ++i) { 1087 CalleeSaveType type = static_cast<CalleeSaveType>(i); 1088 callee_save_method_frame_infos_[i] = x86::X86CalleeSaveMethodFrameInfo(type); 1089 } 1090 } else if (instruction_set_ == kX86_64) { 1091 for (int i = 0; i != kLastCalleeSaveType; ++i) { 1092 CalleeSaveType type = static_cast<CalleeSaveType>(i); 1093 callee_save_method_frame_infos_[i] = x86_64::X86_64CalleeSaveMethodFrameInfo(type); 1094 } 1095 } else if (instruction_set_ == kArm64) { 1096 for (int i = 0; i != kLastCalleeSaveType; ++i) { 1097 CalleeSaveType type = static_cast<CalleeSaveType>(i); 1098 callee_save_method_frame_infos_[i] = arm64::Arm64CalleeSaveMethodFrameInfo(type); 1099 } 1100 } else { 1101 UNIMPLEMENTED(FATAL) << instruction_set_; 1102 } 1103} 1104 1105void Runtime::SetCalleeSaveMethod(mirror::ArtMethod* method, CalleeSaveType type) { 1106 DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastCalleeSaveType)); 1107 callee_save_methods_[type] = GcRoot<mirror::ArtMethod>(method); 1108} 1109 1110const std::vector<const DexFile*>& Runtime::GetCompileTimeClassPath(jobject class_loader) { 1111 if (class_loader == NULL) { 1112 return GetClassLinker()->GetBootClassPath(); 1113 } 1114 CHECK(UseCompileTimeClassPath()); 1115 CompileTimeClassPaths::const_iterator it = compile_time_class_paths_.find(class_loader); 1116 CHECK(it != compile_time_class_paths_.end()); 1117 return it->second; 1118} 1119 1120void Runtime::SetCompileTimeClassPath(jobject class_loader, 1121 std::vector<const DexFile*>& class_path) { 1122 CHECK(!IsStarted()); 1123 use_compile_time_class_path_ = true; 1124 compile_time_class_paths_.Put(class_loader, class_path); 1125} 1126 1127void Runtime::AddMethodVerifier(verifier::MethodVerifier* verifier) { 1128 DCHECK(verifier != nullptr); 1129 MutexLock mu(Thread::Current(), method_verifier_lock_); 1130 method_verifiers_.insert(verifier); 1131} 1132 1133void Runtime::RemoveMethodVerifier(verifier::MethodVerifier* verifier) { 1134 DCHECK(verifier != nullptr); 1135 MutexLock mu(Thread::Current(), method_verifier_lock_); 1136 auto it = method_verifiers_.find(verifier); 1137 CHECK(it != method_verifiers_.end()); 1138 method_verifiers_.erase(it); 1139} 1140 1141void Runtime::StartProfiler(const char* profile_output_filename) { 1142 profile_output_filename_ = profile_output_filename; 1143 profiler_started_ = 1144 BackgroundMethodSamplingProfiler::Start(profile_output_filename_, profiler_options_); 1145} 1146 1147// Transaction support. 1148void Runtime::EnterTransactionMode(Transaction* transaction) { 1149 DCHECK(IsCompiler()); 1150 DCHECK(transaction != nullptr); 1151 DCHECK(!IsActiveTransaction()); 1152 preinitialization_transaction_ = transaction; 1153} 1154 1155void Runtime::ExitTransactionMode() { 1156 DCHECK(IsCompiler()); 1157 DCHECK(IsActiveTransaction()); 1158 preinitialization_transaction_ = nullptr; 1159} 1160 1161void Runtime::RecordWriteField32(mirror::Object* obj, MemberOffset field_offset, 1162 uint32_t value, bool is_volatile) const { 1163 DCHECK(IsCompiler()); 1164 DCHECK(IsActiveTransaction()); 1165 preinitialization_transaction_->RecordWriteField32(obj, field_offset, value, is_volatile); 1166} 1167 1168void Runtime::RecordWriteField64(mirror::Object* obj, MemberOffset field_offset, 1169 uint64_t value, bool is_volatile) const { 1170 DCHECK(IsCompiler()); 1171 DCHECK(IsActiveTransaction()); 1172 preinitialization_transaction_->RecordWriteField64(obj, field_offset, value, is_volatile); 1173} 1174 1175void Runtime::RecordWriteFieldReference(mirror::Object* obj, MemberOffset field_offset, 1176 mirror::Object* value, bool is_volatile) const { 1177 DCHECK(IsCompiler()); 1178 DCHECK(IsActiveTransaction()); 1179 preinitialization_transaction_->RecordWriteFieldReference(obj, field_offset, value, is_volatile); 1180} 1181 1182void Runtime::RecordWriteArray(mirror::Array* array, size_t index, uint64_t value) const { 1183 DCHECK(IsCompiler()); 1184 DCHECK(IsActiveTransaction()); 1185 preinitialization_transaction_->RecordWriteArray(array, index, value); 1186} 1187 1188void Runtime::RecordStrongStringInsertion(mirror::String* s, uint32_t hash_code) const { 1189 DCHECK(IsCompiler()); 1190 DCHECK(IsActiveTransaction()); 1191 preinitialization_transaction_->RecordStrongStringInsertion(s, hash_code); 1192} 1193 1194void Runtime::RecordWeakStringInsertion(mirror::String* s, uint32_t hash_code) const { 1195 DCHECK(IsCompiler()); 1196 DCHECK(IsActiveTransaction()); 1197 preinitialization_transaction_->RecordWeakStringInsertion(s, hash_code); 1198} 1199 1200void Runtime::RecordStrongStringRemoval(mirror::String* s, uint32_t hash_code) const { 1201 DCHECK(IsCompiler()); 1202 DCHECK(IsActiveTransaction()); 1203 preinitialization_transaction_->RecordStrongStringRemoval(s, hash_code); 1204} 1205 1206void Runtime::RecordWeakStringRemoval(mirror::String* s, uint32_t hash_code) const { 1207 DCHECK(IsCompiler()); 1208 DCHECK(IsActiveTransaction()); 1209 preinitialization_transaction_->RecordWeakStringRemoval(s, hash_code); 1210} 1211 1212void Runtime::SetFaultMessage(const std::string& message) { 1213 MutexLock mu(Thread::Current(), fault_message_lock_); 1214 fault_message_ = message; 1215} 1216 1217void Runtime::AddCurrentRuntimeFeaturesAsDex2OatArguments(std::vector<std::string>* argv) 1218 const { 1219 if (GetInstrumentation()->InterpretOnly()) { 1220 argv->push_back("--compiler-filter=interpret-only"); 1221 } 1222 1223 // Make the dex2oat instruction set match that of the launching runtime. If we have multiple 1224 // architecture support, dex2oat may be compiled as a different instruction-set than that 1225 // currently being executed. 1226 std::string instruction_set("--instruction-set="); 1227 instruction_set += GetInstructionSetString(kRuntimeISA); 1228 argv->push_back(instruction_set); 1229 1230 std::string features("--instruction-set-features="); 1231 features += GetDefaultInstructionSetFeatures(); 1232 argv->push_back(features); 1233} 1234 1235void Runtime::UpdateProfilerState(int state) { 1236 VLOG(profiler) << "Profiler state updated to " << state; 1237} 1238} // namespace art 1239