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