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