runtime.h revision bcea58374cbd1447c2c7f2ffdc08e10e8accb721
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#ifndef ART_RUNTIME_RUNTIME_H_ 18#define ART_RUNTIME_RUNTIME_H_ 19 20#include <jni.h> 21#include <stdio.h> 22 23#include <iosfwd> 24#include <set> 25#include <string> 26#include <utility> 27#include <vector> 28 29#include "arch/instruction_set.h" 30#include "base/macros.h" 31#include "base/mutex.h" 32#include "dex_file_types.h" 33#include "experimental_flags.h" 34#include "gc_root.h" 35#include "instrumentation.h" 36#include "jobject_comparator.h" 37#include "method_reference.h" 38#include "obj_ptr.h" 39#include "object_callbacks.h" 40#include "offsets.h" 41#include "process_state.h" 42#include "quick/quick_method_frame_info.h" 43#include "runtime_stats.h" 44 45namespace art { 46 47namespace gc { 48 class AbstractSystemWeakHolder; 49 class Heap; 50 namespace collector { 51 class GarbageCollector; 52 } // namespace collector 53} // namespace gc 54 55namespace jit { 56 class Jit; 57 class JitOptions; 58} // namespace jit 59 60namespace mirror { 61 class Array; 62 class ClassLoader; 63 class DexCache; 64 template<class T> class ObjectArray; 65 template<class T> class PrimitiveArray; 66 typedef PrimitiveArray<int8_t> ByteArray; 67 class String; 68 class Throwable; 69} // namespace mirror 70namespace ti { 71 class Agent; 72} // namespace ti 73namespace verifier { 74 class MethodVerifier; 75 enum class VerifyMode : int8_t; 76} // namespace verifier 77class ArenaPool; 78class ArtMethod; 79class ClassHierarchyAnalysis; 80class ClassLinker; 81class Closure; 82class CompilerCallbacks; 83class DexFile; 84class InternTable; 85class JavaVMExt; 86class LinearAlloc; 87class MonitorList; 88class MonitorPool; 89class NullPointerHandler; 90class OatFileManager; 91class Plugin; 92struct RuntimeArgumentMap; 93class RuntimeCallbacks; 94class SignalCatcher; 95class StackOverflowHandler; 96class SuspensionHandler; 97class ThreadList; 98class Trace; 99struct TraceConfig; 100class Transaction; 101 102typedef std::vector<std::pair<std::string, const void*>> RuntimeOptions; 103 104class Runtime { 105 public: 106 // Parse raw runtime options. 107 static bool ParseOptions(const RuntimeOptions& raw_options, 108 bool ignore_unrecognized, 109 RuntimeArgumentMap* runtime_options); 110 111 // Creates and initializes a new runtime. 112 static bool Create(RuntimeArgumentMap&& runtime_options) 113 SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_); 114 115 // Creates and initializes a new runtime. 116 static bool Create(const RuntimeOptions& raw_options, bool ignore_unrecognized) 117 SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_); 118 119 // IsAotCompiler for compilers that don't have a running runtime. Only dex2oat currently. 120 bool IsAotCompiler() const { 121 return !UseJitCompilation() && IsCompiler(); 122 } 123 124 // IsCompiler is any runtime which has a running compiler, either dex2oat or JIT. 125 bool IsCompiler() const { 126 return compiler_callbacks_ != nullptr; 127 } 128 129 // If a compiler, are we compiling a boot image? 130 bool IsCompilingBootImage() const; 131 132 bool CanRelocate() const; 133 134 bool ShouldRelocate() const { 135 return must_relocate_ && CanRelocate(); 136 } 137 138 bool MustRelocateIfPossible() const { 139 return must_relocate_; 140 } 141 142 bool IsDex2OatEnabled() const { 143 return dex2oat_enabled_ && IsImageDex2OatEnabled(); 144 } 145 146 bool IsImageDex2OatEnabled() const { 147 return image_dex2oat_enabled_; 148 } 149 150 CompilerCallbacks* GetCompilerCallbacks() { 151 return compiler_callbacks_; 152 } 153 154 void SetCompilerCallbacks(CompilerCallbacks* callbacks) { 155 CHECK(callbacks != nullptr); 156 compiler_callbacks_ = callbacks; 157 } 158 159 bool IsZygote() const { 160 return is_zygote_; 161 } 162 163 bool IsExplicitGcDisabled() const { 164 return is_explicit_gc_disabled_; 165 } 166 167 std::string GetCompilerExecutable() const; 168 std::string GetPatchoatExecutable() const; 169 170 const std::vector<std::string>& GetCompilerOptions() const { 171 return compiler_options_; 172 } 173 174 void AddCompilerOption(const std::string& option) { 175 compiler_options_.push_back(option); 176 } 177 178 const std::vector<std::string>& GetImageCompilerOptions() const { 179 return image_compiler_options_; 180 } 181 182 const std::string& GetImageLocation() const { 183 return image_location_; 184 } 185 186 // Starts a runtime, which may cause threads to be started and code to run. 187 bool Start() UNLOCK_FUNCTION(Locks::mutator_lock_); 188 189 bool IsShuttingDown(Thread* self); 190 bool IsShuttingDownLocked() const REQUIRES(Locks::runtime_shutdown_lock_) { 191 return shutting_down_; 192 } 193 194 size_t NumberOfThreadsBeingBorn() const REQUIRES(Locks::runtime_shutdown_lock_) { 195 return threads_being_born_; 196 } 197 198 void StartThreadBirth() REQUIRES(Locks::runtime_shutdown_lock_) { 199 threads_being_born_++; 200 } 201 202 void EndThreadBirth() REQUIRES(Locks::runtime_shutdown_lock_); 203 204 bool IsStarted() const { 205 return started_; 206 } 207 208 bool IsFinishedStarting() const { 209 return finished_starting_; 210 } 211 212 static Runtime* Current() { 213 return instance_; 214 } 215 216 // Aborts semi-cleanly. Used in the implementation of LOG(FATAL), which most 217 // callers should prefer. 218 NO_RETURN static void Abort(const char* msg) REQUIRES(!Locks::abort_lock_); 219 220 // Returns the "main" ThreadGroup, used when attaching user threads. 221 jobject GetMainThreadGroup() const; 222 223 // Returns the "system" ThreadGroup, used when attaching our internal threads. 224 jobject GetSystemThreadGroup() const; 225 226 // Returns the system ClassLoader which represents the CLASSPATH. 227 jobject GetSystemClassLoader() const; 228 229 // Attaches the calling native thread to the runtime. 230 bool AttachCurrentThread(const char* thread_name, bool as_daemon, jobject thread_group, 231 bool create_peer); 232 233 void CallExitHook(jint status); 234 235 // Detaches the current native thread from the runtime. 236 void DetachCurrentThread() REQUIRES(!Locks::mutator_lock_); 237 238 void DumpForSigQuit(std::ostream& os); 239 void DumpLockHolders(std::ostream& os); 240 241 ~Runtime(); 242 243 const std::string& GetBootClassPathString() const { 244 return boot_class_path_string_; 245 } 246 247 const std::string& GetClassPathString() const { 248 return class_path_string_; 249 } 250 251 ClassLinker* GetClassLinker() const { 252 return class_linker_; 253 } 254 255 size_t GetDefaultStackSize() const { 256 return default_stack_size_; 257 } 258 259 gc::Heap* GetHeap() const { 260 return heap_; 261 } 262 263 InternTable* GetInternTable() const { 264 DCHECK(intern_table_ != nullptr); 265 return intern_table_; 266 } 267 268 JavaVMExt* GetJavaVM() const { 269 return java_vm_.get(); 270 } 271 272 size_t GetMaxSpinsBeforeThinLockInflation() const { 273 return max_spins_before_thin_lock_inflation_; 274 } 275 276 MonitorList* GetMonitorList() const { 277 return monitor_list_; 278 } 279 280 MonitorPool* GetMonitorPool() const { 281 return monitor_pool_; 282 } 283 284 // Is the given object the special object used to mark a cleared JNI weak global? 285 bool IsClearedJniWeakGlobal(ObjPtr<mirror::Object> obj) REQUIRES_SHARED(Locks::mutator_lock_); 286 287 // Get the special object used to mark a cleared JNI weak global. 288 mirror::Object* GetClearedJniWeakGlobal() REQUIRES_SHARED(Locks::mutator_lock_); 289 290 mirror::Throwable* GetPreAllocatedOutOfMemoryError() REQUIRES_SHARED(Locks::mutator_lock_); 291 292 mirror::Throwable* GetPreAllocatedNoClassDefFoundError() 293 REQUIRES_SHARED(Locks::mutator_lock_); 294 295 const std::vector<std::string>& GetProperties() const { 296 return properties_; 297 } 298 299 ThreadList* GetThreadList() const { 300 return thread_list_; 301 } 302 303 static const char* GetVersion() { 304 return "2.1.0"; 305 } 306 307 bool IsMethodHandlesEnabled() const { 308 return true; 309 } 310 311 void DisallowNewSystemWeaks() REQUIRES_SHARED(Locks::mutator_lock_); 312 void AllowNewSystemWeaks() REQUIRES_SHARED(Locks::mutator_lock_); 313 // broadcast_for_checkpoint is true when we broadcast for making blocking threads to respond to 314 // checkpoint requests. It's false when we broadcast to unblock blocking threads after system weak 315 // access is reenabled. 316 void BroadcastForNewSystemWeaks(bool broadcast_for_checkpoint = false); 317 318 // Visit all the roots. If only_dirty is true then non-dirty roots won't be visited. If 319 // clean_dirty is true then dirty roots will be marked as non-dirty after visiting. 320 void VisitRoots(RootVisitor* visitor, VisitRootFlags flags = kVisitRootFlagAllRoots) 321 REQUIRES(!Locks::classlinker_classes_lock_, !Locks::trace_lock_) 322 REQUIRES_SHARED(Locks::mutator_lock_); 323 324 // Visit image roots, only used for hprof since the GC uses the image space mod union table 325 // instead. 326 void VisitImageRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_); 327 328 // Visit all of the roots we can do safely do concurrently. 329 void VisitConcurrentRoots(RootVisitor* visitor, 330 VisitRootFlags flags = kVisitRootFlagAllRoots) 331 REQUIRES(!Locks::classlinker_classes_lock_, !Locks::trace_lock_) 332 REQUIRES_SHARED(Locks::mutator_lock_); 333 334 // Visit all of the non thread roots, we can do this with mutators unpaused. 335 void VisitNonThreadRoots(RootVisitor* visitor) 336 REQUIRES_SHARED(Locks::mutator_lock_); 337 338 void VisitTransactionRoots(RootVisitor* visitor) 339 REQUIRES_SHARED(Locks::mutator_lock_); 340 341 // Flip thread roots from from-space refs to to-space refs. 342 size_t FlipThreadRoots(Closure* thread_flip_visitor, Closure* flip_callback, 343 gc::collector::GarbageCollector* collector) 344 REQUIRES(!Locks::mutator_lock_); 345 346 // Sweep system weaks, the system weak is deleted if the visitor return null. Otherwise, the 347 // system weak is updated to be the visitor's returned value. 348 void SweepSystemWeaks(IsMarkedVisitor* visitor) 349 REQUIRES_SHARED(Locks::mutator_lock_); 350 351 // Returns a special method that calls into a trampoline for runtime method resolution 352 ArtMethod* GetResolutionMethod(); 353 354 bool HasResolutionMethod() const { 355 return resolution_method_ != nullptr; 356 } 357 358 void SetResolutionMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); 359 void ClearResolutionMethod() { 360 resolution_method_ = nullptr; 361 } 362 363 ArtMethod* CreateResolutionMethod() REQUIRES_SHARED(Locks::mutator_lock_); 364 365 // Returns a special method that calls into a trampoline for runtime imt conflicts. 366 ArtMethod* GetImtConflictMethod(); 367 ArtMethod* GetImtUnimplementedMethod(); 368 369 bool HasImtConflictMethod() const { 370 return imt_conflict_method_ != nullptr; 371 } 372 373 void ClearImtConflictMethod() { 374 imt_conflict_method_ = nullptr; 375 } 376 377 void FixupConflictTables(); 378 void SetImtConflictMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); 379 void SetImtUnimplementedMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); 380 381 ArtMethod* CreateImtConflictMethod(LinearAlloc* linear_alloc) 382 REQUIRES_SHARED(Locks::mutator_lock_); 383 384 void ClearImtUnimplementedMethod() { 385 imt_unimplemented_method_ = nullptr; 386 } 387 388 // Returns a special method that describes all callee saves being spilled to the stack. 389 enum CalleeSaveType { 390 kSaveAllCalleeSaves, // All callee-save registers. 391 kSaveRefsOnly, // Only those callee-save registers that can hold references. 392 kSaveRefsAndArgs, // References (see above) and arguments (usually caller-save registers). 393 kSaveEverything, // All registers, including both callee-save and caller-save. 394 kLastCalleeSaveType // Value used for iteration 395 }; 396 397 bool HasCalleeSaveMethod(CalleeSaveType type) const { 398 return callee_save_methods_[type] != 0u; 399 } 400 401 ArtMethod* GetCalleeSaveMethod(CalleeSaveType type) 402 REQUIRES_SHARED(Locks::mutator_lock_); 403 404 ArtMethod* GetCalleeSaveMethodUnchecked(CalleeSaveType type) 405 REQUIRES_SHARED(Locks::mutator_lock_); 406 407 QuickMethodFrameInfo GetCalleeSaveMethodFrameInfo(CalleeSaveType type) const { 408 return callee_save_method_frame_infos_[type]; 409 } 410 411 QuickMethodFrameInfo GetRuntimeMethodFrameInfo(ArtMethod* method) 412 REQUIRES_SHARED(Locks::mutator_lock_); 413 414 static size_t GetCalleeSaveMethodOffset(CalleeSaveType type) { 415 return OFFSETOF_MEMBER(Runtime, callee_save_methods_[type]); 416 } 417 418 InstructionSet GetInstructionSet() const { 419 return instruction_set_; 420 } 421 422 void SetInstructionSet(InstructionSet instruction_set); 423 void ClearInstructionSet(); 424 425 void SetCalleeSaveMethod(ArtMethod* method, CalleeSaveType type); 426 void ClearCalleeSaveMethods(); 427 428 ArtMethod* CreateCalleeSaveMethod() REQUIRES_SHARED(Locks::mutator_lock_); 429 430 int32_t GetStat(int kind); 431 432 RuntimeStats* GetStats() { 433 return &stats_; 434 } 435 436 bool HasStatsEnabled() const { 437 return stats_enabled_; 438 } 439 440 void ResetStats(int kinds); 441 442 void SetStatsEnabled(bool new_state) 443 REQUIRES(!Locks::instrument_entrypoints_lock_, !Locks::mutator_lock_); 444 445 enum class NativeBridgeAction { // private 446 kUnload, 447 kInitialize 448 }; 449 450 jit::Jit* GetJit() const { 451 return jit_.get(); 452 } 453 454 // Returns true if JIT compilations are enabled. GetJit() will be not null in this case. 455 bool UseJitCompilation() const; 456 457 void PreZygoteFork(); 458 void InitNonZygoteOrPostFork( 459 JNIEnv* env, bool is_system_server, NativeBridgeAction action, const char* isa); 460 461 const instrumentation::Instrumentation* GetInstrumentation() const { 462 return &instrumentation_; 463 } 464 465 instrumentation::Instrumentation* GetInstrumentation() { 466 return &instrumentation_; 467 } 468 469 void RegisterAppInfo(const std::vector<std::string>& code_paths, 470 const std::string& profile_output_filename); 471 472 // Transaction support. 473 bool IsActiveTransaction() const { 474 return preinitialization_transaction_ != nullptr; 475 } 476 void EnterTransactionMode(Transaction* transaction); 477 void ExitTransactionMode(); 478 bool IsTransactionAborted() const; 479 480 void AbortTransactionAndThrowAbortError(Thread* self, const std::string& abort_message) 481 REQUIRES_SHARED(Locks::mutator_lock_); 482 void ThrowTransactionAbortError(Thread* self) 483 REQUIRES_SHARED(Locks::mutator_lock_); 484 485 void RecordWriteFieldBoolean(mirror::Object* obj, MemberOffset field_offset, uint8_t value, 486 bool is_volatile) const; 487 void RecordWriteFieldByte(mirror::Object* obj, MemberOffset field_offset, int8_t value, 488 bool is_volatile) const; 489 void RecordWriteFieldChar(mirror::Object* obj, MemberOffset field_offset, uint16_t value, 490 bool is_volatile) const; 491 void RecordWriteFieldShort(mirror::Object* obj, MemberOffset field_offset, int16_t value, 492 bool is_volatile) const; 493 void RecordWriteField32(mirror::Object* obj, MemberOffset field_offset, uint32_t value, 494 bool is_volatile) const; 495 void RecordWriteField64(mirror::Object* obj, MemberOffset field_offset, uint64_t value, 496 bool is_volatile) const; 497 void RecordWriteFieldReference(mirror::Object* obj, 498 MemberOffset field_offset, 499 ObjPtr<mirror::Object> value, 500 bool is_volatile) const 501 REQUIRES_SHARED(Locks::mutator_lock_); 502 void RecordWriteArray(mirror::Array* array, size_t index, uint64_t value) const 503 REQUIRES_SHARED(Locks::mutator_lock_); 504 void RecordStrongStringInsertion(ObjPtr<mirror::String> s) const 505 REQUIRES(Locks::intern_table_lock_); 506 void RecordWeakStringInsertion(ObjPtr<mirror::String> s) const 507 REQUIRES(Locks::intern_table_lock_); 508 void RecordStrongStringRemoval(ObjPtr<mirror::String> s) const 509 REQUIRES(Locks::intern_table_lock_); 510 void RecordWeakStringRemoval(ObjPtr<mirror::String> s) const 511 REQUIRES(Locks::intern_table_lock_); 512 void RecordResolveString(ObjPtr<mirror::DexCache> dex_cache, dex::StringIndex string_idx) const 513 REQUIRES_SHARED(Locks::mutator_lock_); 514 515 void SetFaultMessage(const std::string& message) REQUIRES(!fault_message_lock_); 516 // Only read by the signal handler, NO_THREAD_SAFETY_ANALYSIS to prevent lock order violations 517 // with the unexpected_signal_lock_. 518 const std::string& GetFaultMessage() NO_THREAD_SAFETY_ANALYSIS { 519 return fault_message_; 520 } 521 522 void AddCurrentRuntimeFeaturesAsDex2OatArguments(std::vector<std::string>* arg_vector) const; 523 524 bool ExplicitStackOverflowChecks() const { 525 return !implicit_so_checks_; 526 } 527 528 bool IsVerificationEnabled() const; 529 bool IsVerificationSoftFail() const; 530 531 bool IsDexFileFallbackEnabled() const { 532 return allow_dex_file_fallback_; 533 } 534 535 const std::vector<std::string>& GetCpuAbilist() const { 536 return cpu_abilist_; 537 } 538 539 bool IsRunningOnMemoryTool() const { 540 return is_running_on_memory_tool_; 541 } 542 543 void SetTargetSdkVersion(int32_t version) { 544 target_sdk_version_ = version; 545 } 546 547 int32_t GetTargetSdkVersion() const { 548 return target_sdk_version_; 549 } 550 551 uint32_t GetZygoteMaxFailedBoots() const { 552 return zygote_max_failed_boots_; 553 } 554 555 bool AreExperimentalFlagsEnabled(ExperimentalFlags flags) { 556 return (experimental_flags_ & flags) != ExperimentalFlags::kNone; 557 } 558 559 // Create the JIT and instrumentation and code cache. 560 void CreateJit(); 561 562 ArenaPool* GetArenaPool() { 563 return arena_pool_.get(); 564 } 565 ArenaPool* GetJitArenaPool() { 566 return jit_arena_pool_.get(); 567 } 568 const ArenaPool* GetArenaPool() const { 569 return arena_pool_.get(); 570 } 571 572 void ReclaimArenaPoolMemory(); 573 574 LinearAlloc* GetLinearAlloc() { 575 return linear_alloc_.get(); 576 } 577 578 jit::JitOptions* GetJITOptions() { 579 return jit_options_.get(); 580 } 581 582 bool IsJavaDebuggable() const { 583 return is_java_debuggable_; 584 } 585 586 void SetJavaDebuggable(bool value); 587 588 // Deoptimize the boot image, called for Java debuggable apps. 589 void DeoptimizeBootImage(); 590 591 bool IsNativeDebuggable() const { 592 return is_native_debuggable_; 593 } 594 595 void SetNativeDebuggable(bool value) { 596 is_native_debuggable_ = value; 597 } 598 599 // Returns the build fingerprint, if set. Otherwise an empty string is returned. 600 std::string GetFingerprint() { 601 return fingerprint_; 602 } 603 604 // Called from class linker. 605 void SetSentinel(mirror::Object* sentinel) REQUIRES_SHARED(Locks::mutator_lock_); 606 607 // Create a normal LinearAlloc or low 4gb version if we are 64 bit AOT compiler. 608 LinearAlloc* CreateLinearAlloc(); 609 610 OatFileManager& GetOatFileManager() const { 611 DCHECK(oat_file_manager_ != nullptr); 612 return *oat_file_manager_; 613 } 614 615 double GetHashTableMinLoadFactor() const; 616 double GetHashTableMaxLoadFactor() const; 617 618 void SetSafeMode(bool mode) { 619 safe_mode_ = mode; 620 } 621 622 bool GetDumpNativeStackOnSigQuit() const { 623 return dump_native_stack_on_sig_quit_; 624 } 625 626 bool GetPrunedDalvikCache() const { 627 return pruned_dalvik_cache_; 628 } 629 630 void SetPrunedDalvikCache(bool pruned) { 631 pruned_dalvik_cache_ = pruned; 632 } 633 634 void UpdateProcessState(ProcessState process_state); 635 636 // Returns true if we currently care about long mutator pause. 637 bool InJankPerceptibleProcessState() const { 638 return process_state_ == kProcessStateJankPerceptible; 639 } 640 641 void RegisterSensitiveThread() const; 642 643 void SetZygoteNoThreadSection(bool val) { 644 zygote_no_threads_ = val; 645 } 646 647 bool IsZygoteNoThreadSection() const { 648 return zygote_no_threads_; 649 } 650 651 // Returns if the code can be deoptimized asynchronously. Code may be compiled with some 652 // optimization that makes it impossible to deoptimize. 653 bool IsAsyncDeoptimizeable(uintptr_t code) const REQUIRES_SHARED(Locks::mutator_lock_); 654 655 // Returns a saved copy of the environment (getenv/setenv values). 656 // Used by Fork to protect against overwriting LD_LIBRARY_PATH, etc. 657 char** GetEnvSnapshot() const { 658 return env_snapshot_.GetSnapshot(); 659 } 660 661 void AddSystemWeakHolder(gc::AbstractSystemWeakHolder* holder); 662 void RemoveSystemWeakHolder(gc::AbstractSystemWeakHolder* holder); 663 664 ClassHierarchyAnalysis* GetClassHierarchyAnalysis() { 665 return cha_; 666 } 667 668 NO_RETURN 669 static void Aborter(const char* abort_message); 670 671 void AttachAgent(const std::string& agent_arg); 672 673 const std::list<ti::Agent>& GetAgents() const { 674 return agents_; 675 } 676 677 RuntimeCallbacks* GetRuntimeCallbacks(); 678 679 void InitThreadGroups(Thread* self); 680 681 void SetDumpGCPerformanceOnShutdown(bool value) { 682 dump_gc_performance_on_shutdown_ = value; 683 } 684 685 private: 686 static void InitPlatformSignalHandlers(); 687 688 Runtime(); 689 690 void BlockSignals(); 691 692 bool Init(RuntimeArgumentMap&& runtime_options) 693 SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_); 694 void InitNativeMethods() REQUIRES(!Locks::mutator_lock_); 695 void RegisterRuntimeNativeMethods(JNIEnv* env); 696 697 void StartDaemonThreads(); 698 void StartSignalCatcher(); 699 700 void MaybeSaveJitProfilingInfo(); 701 702 // Visit all of the thread roots. 703 void VisitThreadRoots(RootVisitor* visitor, VisitRootFlags flags) 704 REQUIRES_SHARED(Locks::mutator_lock_); 705 706 // Visit all other roots which must be done with mutators suspended. 707 void VisitNonConcurrentRoots(RootVisitor* visitor, VisitRootFlags flags) 708 REQUIRES_SHARED(Locks::mutator_lock_); 709 710 // Constant roots are the roots which never change after the runtime is initialized, they only 711 // need to be visited once per GC cycle. 712 void VisitConstantRoots(RootVisitor* visitor) 713 REQUIRES_SHARED(Locks::mutator_lock_); 714 715 // A pointer to the active runtime or null. 716 static Runtime* instance_; 717 718 // NOTE: these must match the gc::ProcessState values as they come directly from the framework. 719 static constexpr int kProfileForground = 0; 720 static constexpr int kProfileBackground = 1; 721 722 // 64 bit so that we can share the same asm offsets for both 32 and 64 bits. 723 uint64_t callee_save_methods_[kLastCalleeSaveType]; 724 GcRoot<mirror::Throwable> pre_allocated_OutOfMemoryError_; 725 GcRoot<mirror::Throwable> pre_allocated_NoClassDefFoundError_; 726 ArtMethod* resolution_method_; 727 ArtMethod* imt_conflict_method_; 728 // Unresolved method has the same behavior as the conflict method, it is used by the class linker 729 // for differentiating between unfilled imt slots vs conflict slots in superclasses. 730 ArtMethod* imt_unimplemented_method_; 731 732 // Special sentinel object used to invalid conditions in JNI (cleared weak references) and 733 // JDWP (invalid references). 734 GcRoot<mirror::Object> sentinel_; 735 736 InstructionSet instruction_set_; 737 QuickMethodFrameInfo callee_save_method_frame_infos_[kLastCalleeSaveType]; 738 739 CompilerCallbacks* compiler_callbacks_; 740 bool is_zygote_; 741 bool must_relocate_; 742 bool is_concurrent_gc_enabled_; 743 bool is_explicit_gc_disabled_; 744 bool dex2oat_enabled_; 745 bool image_dex2oat_enabled_; 746 747 std::string compiler_executable_; 748 std::string patchoat_executable_; 749 std::vector<std::string> compiler_options_; 750 std::vector<std::string> image_compiler_options_; 751 std::string image_location_; 752 753 std::string boot_class_path_string_; 754 std::string class_path_string_; 755 std::vector<std::string> properties_; 756 757 std::list<ti::Agent> agents_; 758 std::vector<Plugin> plugins_; 759 760 // The default stack size for managed threads created by the runtime. 761 size_t default_stack_size_; 762 763 gc::Heap* heap_; 764 765 std::unique_ptr<ArenaPool> jit_arena_pool_; 766 std::unique_ptr<ArenaPool> arena_pool_; 767 // Special low 4gb pool for compiler linear alloc. We need ArtFields to be in low 4gb if we are 768 // compiling using a 32 bit image on a 64 bit compiler in case we resolve things in the image 769 // since the field arrays are int arrays in this case. 770 std::unique_ptr<ArenaPool> low_4gb_arena_pool_; 771 772 // Shared linear alloc for now. 773 std::unique_ptr<LinearAlloc> linear_alloc_; 774 775 // The number of spins that are done before thread suspension is used to forcibly inflate. 776 size_t max_spins_before_thin_lock_inflation_; 777 MonitorList* monitor_list_; 778 MonitorPool* monitor_pool_; 779 780 ThreadList* thread_list_; 781 782 InternTable* intern_table_; 783 784 ClassLinker* class_linker_; 785 786 SignalCatcher* signal_catcher_; 787 std::string stack_trace_file_; 788 789 std::unique_ptr<JavaVMExt> java_vm_; 790 791 std::unique_ptr<jit::Jit> jit_; 792 std::unique_ptr<jit::JitOptions> jit_options_; 793 794 // Fault message, printed when we get a SIGSEGV. 795 Mutex fault_message_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; 796 std::string fault_message_ GUARDED_BY(fault_message_lock_); 797 798 // A non-zero value indicates that a thread has been created but not yet initialized. Guarded by 799 // the shutdown lock so that threads aren't born while we're shutting down. 800 size_t threads_being_born_ GUARDED_BY(Locks::runtime_shutdown_lock_); 801 802 // Waited upon until no threads are being born. 803 std::unique_ptr<ConditionVariable> shutdown_cond_ GUARDED_BY(Locks::runtime_shutdown_lock_); 804 805 // Set when runtime shutdown is past the point that new threads may attach. 806 bool shutting_down_ GUARDED_BY(Locks::runtime_shutdown_lock_); 807 808 // The runtime is starting to shutdown but is blocked waiting on shutdown_cond_. 809 bool shutting_down_started_ GUARDED_BY(Locks::runtime_shutdown_lock_); 810 811 bool started_; 812 813 // New flag added which tells us if the runtime has finished starting. If 814 // this flag is set then the Daemon threads are created and the class loader 815 // is created. This flag is needed for knowing if its safe to request CMS. 816 bool finished_starting_; 817 818 // Hooks supported by JNI_CreateJavaVM 819 jint (*vfprintf_)(FILE* stream, const char* format, va_list ap); 820 void (*exit_)(jint status); 821 void (*abort_)(); 822 823 bool stats_enabled_; 824 RuntimeStats stats_; 825 826 const bool is_running_on_memory_tool_; 827 828 std::unique_ptr<TraceConfig> trace_config_; 829 830 instrumentation::Instrumentation instrumentation_; 831 832 jobject main_thread_group_; 833 jobject system_thread_group_; 834 835 // As returned by ClassLoader.getSystemClassLoader(). 836 jobject system_class_loader_; 837 838 // If true, then we dump the GC cumulative timings on shutdown. 839 bool dump_gc_performance_on_shutdown_; 840 841 // Transaction used for pre-initializing classes at compilation time. 842 Transaction* preinitialization_transaction_; 843 844 // If kNone, verification is disabled. kEnable by default. 845 verifier::VerifyMode verify_; 846 847 // If true, the runtime may use dex files directly with the interpreter if an oat file is not 848 // available/usable. 849 bool allow_dex_file_fallback_; 850 851 // List of supported cpu abis. 852 std::vector<std::string> cpu_abilist_; 853 854 // Specifies target SDK version to allow workarounds for certain API levels. 855 int32_t target_sdk_version_; 856 857 // Implicit checks flags. 858 bool implicit_null_checks_; // NullPointer checks are implicit. 859 bool implicit_so_checks_; // StackOverflow checks are implicit. 860 bool implicit_suspend_checks_; // Thread suspension checks are implicit. 861 862 // Whether or not the sig chain (and implicitly the fault handler) should be 863 // disabled. Tools like dex2oat or patchoat don't need them. This enables 864 // building a statically link version of dex2oat. 865 bool no_sig_chain_; 866 867 // Force the use of native bridge even if the app ISA matches the runtime ISA. 868 bool force_native_bridge_; 869 870 // Whether or not a native bridge has been loaded. 871 // 872 // The native bridge allows running native code compiled for a foreign ISA. The way it works is, 873 // if standard dlopen fails to load native library associated with native activity, it calls to 874 // the native bridge to load it and then gets the trampoline for the entry to native activity. 875 // 876 // The option 'native_bridge_library_filename' specifies the name of the native bridge. 877 // When non-empty the native bridge will be loaded from the given file. An empty value means 878 // that there's no native bridge. 879 bool is_native_bridge_loaded_; 880 881 // Whether we are running under native debugger. 882 bool is_native_debuggable_; 883 884 // Whether Java code needs to be debuggable. 885 bool is_java_debuggable_; 886 887 // The maximum number of failed boots we allow before pruning the dalvik cache 888 // and trying again. This option is only inspected when we're running as a 889 // zygote. 890 uint32_t zygote_max_failed_boots_; 891 892 // Enable experimental opcodes that aren't fully specified yet. The intent is to 893 // eventually publish them as public-usable opcodes, but they aren't ready yet. 894 // 895 // Experimental opcodes should not be used by other production code. 896 ExperimentalFlags experimental_flags_; 897 898 // Contains the build fingerprint, if given as a parameter. 899 std::string fingerprint_; 900 901 // Oat file manager, keeps track of what oat files are open. 902 OatFileManager* oat_file_manager_; 903 904 // Whether or not we are on a low RAM device. 905 bool is_low_memory_mode_; 906 907 // Whether the application should run in safe mode, that is, interpreter only. 908 bool safe_mode_; 909 910 // Whether threads should dump their native stack on SIGQUIT. 911 bool dump_native_stack_on_sig_quit_; 912 913 // Whether the dalvik cache was pruned when initializing the runtime. 914 bool pruned_dalvik_cache_; 915 916 // Whether or not we currently care about pause times. 917 ProcessState process_state_; 918 919 // Whether zygote code is in a section that should not start threads. 920 bool zygote_no_threads_; 921 922 // Saved environment. 923 class EnvSnapshot { 924 public: 925 EnvSnapshot() = default; 926 void TakeSnapshot(); 927 char** GetSnapshot() const; 928 929 private: 930 std::unique_ptr<char*[]> c_env_vector_; 931 std::vector<std::unique_ptr<std::string>> name_value_pairs_; 932 933 DISALLOW_COPY_AND_ASSIGN(EnvSnapshot); 934 } env_snapshot_; 935 936 // Generic system-weak holders. 937 std::vector<gc::AbstractSystemWeakHolder*> system_weak_holders_; 938 939 ClassHierarchyAnalysis* cha_; 940 941 std::unique_ptr<RuntimeCallbacks> callbacks_; 942 943 DISALLOW_COPY_AND_ASSIGN(Runtime); 944}; 945std::ostream& operator<<(std::ostream& os, const Runtime::CalleeSaveType& rhs); 946 947} // namespace art 948 949#endif // ART_RUNTIME_RUNTIME_H_ 950