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 <memory> 28 #include <vector> 29 30 #include "base/locks.h" 31 #include "base/macros.h" 32 #include "base/mem_map.h" 33 #include "base/string_view_cpp20.h" 34 #include "deoptimization_kind.h" 35 #include "dex/dex_file_types.h" 36 #include "experimental_flags.h" 37 #include "gc/space/image_space_loading_order.h" 38 #include "gc_root.h" 39 #include "instrumentation.h" 40 #include "jdwp_provider.h" 41 #include "jni/jni_id_manager.h" 42 #include "jni_id_type.h" 43 #include "obj_ptr.h" 44 #include "offsets.h" 45 #include "process_state.h" 46 #include "quick/quick_method_frame_info.h" 47 #include "reflective_value_visitor.h" 48 #include "runtime_stats.h" 49 50 namespace art { 51 52 namespace gc { 53 class AbstractSystemWeakHolder; 54 class Heap; 55 } // namespace gc 56 57 namespace hiddenapi { 58 enum class EnforcementPolicy; 59 } // namespace hiddenapi 60 61 namespace jit { 62 class Jit; 63 class JitCodeCache; 64 class JitOptions; 65 } // namespace jit 66 67 namespace mirror { 68 class Array; 69 class ClassLoader; 70 class DexCache; 71 template<class T> class ObjectArray; 72 template<class T> class PrimitiveArray; 73 typedef PrimitiveArray<int8_t> ByteArray; 74 class String; 75 class Throwable; 76 } // namespace mirror 77 namespace ti { 78 class Agent; 79 class AgentSpec; 80 } // namespace ti 81 namespace verifier { 82 class MethodVerifier; 83 enum class VerifyMode : int8_t; 84 } // namespace verifier 85 class ArenaPool; 86 class ArtMethod; 87 enum class CalleeSaveType: uint32_t; 88 class ClassLinker; 89 class CompilerCallbacks; 90 class Dex2oatImageTest; 91 class DexFile; 92 enum class InstructionSet; 93 class InternTable; 94 class IsMarkedVisitor; 95 class JavaVMExt; 96 class LinearAlloc; 97 class MonitorList; 98 class MonitorPool; 99 class NullPointerHandler; 100 class OatFileAssistantTest; 101 class OatFileManager; 102 class Plugin; 103 struct RuntimeArgumentMap; 104 class RuntimeCallbacks; 105 class SignalCatcher; 106 class StackOverflowHandler; 107 class SuspensionHandler; 108 class ThreadList; 109 class ThreadPool; 110 class Trace; 111 struct TraceConfig; 112 class Transaction; 113 114 typedef std::vector<std::pair<std::string, const void*>> RuntimeOptions; 115 116 class Runtime { 117 public: 118 // Parse raw runtime options. 119 static bool ParseOptions(const RuntimeOptions& raw_options, 120 bool ignore_unrecognized, 121 RuntimeArgumentMap* runtime_options); 122 123 // Creates and initializes a new runtime. 124 static bool Create(RuntimeArgumentMap&& runtime_options) 125 SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_); 126 127 // Creates and initializes a new runtime. 128 static bool Create(const RuntimeOptions& raw_options, bool ignore_unrecognized) 129 SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_); 130 131 bool EnsurePluginLoaded(const char* plugin_name, std::string* error_msg); 132 bool EnsurePerfettoPlugin(std::string* error_msg); 133 134 // IsAotCompiler for compilers that don't have a running runtime. Only dex2oat currently. IsAotCompiler()135 bool IsAotCompiler() const { 136 return !UseJitCompilation() && IsCompiler(); 137 } 138 139 // IsCompiler is any runtime which has a running compiler, either dex2oat or JIT. IsCompiler()140 bool IsCompiler() const { 141 return compiler_callbacks_ != nullptr; 142 } 143 144 // If a compiler, are we compiling a boot image? 145 bool IsCompilingBootImage() const; 146 147 bool CanRelocate() const; 148 ShouldRelocate()149 bool ShouldRelocate() const { 150 return must_relocate_ && CanRelocate(); 151 } 152 MustRelocateIfPossible()153 bool MustRelocateIfPossible() const { 154 return must_relocate_; 155 } 156 IsImageDex2OatEnabled()157 bool IsImageDex2OatEnabled() const { 158 return image_dex2oat_enabled_; 159 } 160 GetCompilerCallbacks()161 CompilerCallbacks* GetCompilerCallbacks() { 162 return compiler_callbacks_; 163 } 164 SetCompilerCallbacks(CompilerCallbacks * callbacks)165 void SetCompilerCallbacks(CompilerCallbacks* callbacks) { 166 CHECK(callbacks != nullptr); 167 compiler_callbacks_ = callbacks; 168 } 169 IsZygote()170 bool IsZygote() const { 171 return is_zygote_; 172 } 173 IsPrimaryZygote()174 bool IsPrimaryZygote() const { 175 return is_primary_zygote_; 176 } 177 IsSystemServer()178 bool IsSystemServer() const { 179 return is_system_server_; 180 } 181 SetAsSystemServer()182 void SetAsSystemServer() { 183 is_system_server_ = true; 184 is_zygote_ = false; 185 is_primary_zygote_ = false; 186 } 187 SetAsZygoteChild(bool is_system_server,bool is_zygote)188 void SetAsZygoteChild(bool is_system_server, bool is_zygote) { 189 // System server should have been set earlier in SetAsSystemServer. 190 CHECK_EQ(is_system_server_, is_system_server); 191 is_zygote_ = is_zygote; 192 is_primary_zygote_ = false; 193 } 194 IsExplicitGcDisabled()195 bool IsExplicitGcDisabled() const { 196 return is_explicit_gc_disabled_; 197 } 198 199 std::string GetCompilerExecutable() const; 200 GetCompilerOptions()201 const std::vector<std::string>& GetCompilerOptions() const { 202 return compiler_options_; 203 } 204 AddCompilerOption(const std::string & option)205 void AddCompilerOption(const std::string& option) { 206 compiler_options_.push_back(option); 207 } 208 GetImageCompilerOptions()209 const std::vector<std::string>& GetImageCompilerOptions() const { 210 return image_compiler_options_; 211 } 212 GetImageLocation()213 const std::string& GetImageLocation() const { 214 return image_location_; 215 } 216 217 // Starts a runtime, which may cause threads to be started and code to run. 218 bool Start() UNLOCK_FUNCTION(Locks::mutator_lock_); 219 220 bool IsShuttingDown(Thread* self); IsShuttingDownLocked()221 bool IsShuttingDownLocked() const REQUIRES(Locks::runtime_shutdown_lock_) { 222 return shutting_down_; 223 } 224 NumberOfThreadsBeingBorn()225 size_t NumberOfThreadsBeingBorn() const REQUIRES(Locks::runtime_shutdown_lock_) { 226 return threads_being_born_; 227 } 228 StartThreadBirth()229 void StartThreadBirth() REQUIRES(Locks::runtime_shutdown_lock_) { 230 threads_being_born_++; 231 } 232 233 void EndThreadBirth() REQUIRES(Locks::runtime_shutdown_lock_); 234 IsStarted()235 bool IsStarted() const { 236 return started_; 237 } 238 IsFinishedStarting()239 bool IsFinishedStarting() const { 240 return finished_starting_; 241 } 242 243 void RunRootClinits(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_); 244 Current()245 static Runtime* Current() { 246 return instance_; 247 } 248 249 // Aborts semi-cleanly. Used in the implementation of LOG(FATAL), which most 250 // callers should prefer. 251 NO_RETURN static void Abort(const char* msg) REQUIRES(!Locks::abort_lock_); 252 253 // Returns the "main" ThreadGroup, used when attaching user threads. 254 jobject GetMainThreadGroup() const; 255 256 // Returns the "system" ThreadGroup, used when attaching our internal threads. 257 jobject GetSystemThreadGroup() const; 258 259 // Returns the system ClassLoader which represents the CLASSPATH. 260 jobject GetSystemClassLoader() const; 261 262 // Attaches the calling native thread to the runtime. 263 bool AttachCurrentThread(const char* thread_name, bool as_daemon, jobject thread_group, 264 bool create_peer); 265 266 void CallExitHook(jint status); 267 268 // Detaches the current native thread from the runtime. 269 void DetachCurrentThread() REQUIRES(!Locks::mutator_lock_); 270 271 void DumpDeoptimizations(std::ostream& os); 272 void DumpForSigQuit(std::ostream& os); 273 void DumpLockHolders(std::ostream& os); 274 275 ~Runtime(); 276 GetBootClassPath()277 const std::vector<std::string>& GetBootClassPath() const { 278 return boot_class_path_; 279 } 280 GetBootClassPathLocations()281 const std::vector<std::string>& GetBootClassPathLocations() const { 282 DCHECK(boot_class_path_locations_.empty() || 283 boot_class_path_locations_.size() == boot_class_path_.size()); 284 return boot_class_path_locations_.empty() ? boot_class_path_ : boot_class_path_locations_; 285 } 286 GetClassPathString()287 const std::string& GetClassPathString() const { 288 return class_path_string_; 289 } 290 GetClassLinker()291 ClassLinker* GetClassLinker() const { 292 return class_linker_; 293 } 294 GetJniIdManager()295 jni::JniIdManager* GetJniIdManager() const { 296 return jni_id_manager_.get(); 297 } 298 GetDefaultStackSize()299 size_t GetDefaultStackSize() const { 300 return default_stack_size_; 301 } 302 GetFinalizerTimeoutMs()303 unsigned int GetFinalizerTimeoutMs() const { 304 return finalizer_timeout_ms_; 305 } 306 GetHeap()307 gc::Heap* GetHeap() const { 308 return heap_; 309 } 310 GetInternTable()311 InternTable* GetInternTable() const { 312 DCHECK(intern_table_ != nullptr); 313 return intern_table_; 314 } 315 GetJavaVM()316 JavaVMExt* GetJavaVM() const { 317 return java_vm_.get(); 318 } 319 GetMaxSpinsBeforeThinLockInflation()320 size_t GetMaxSpinsBeforeThinLockInflation() const { 321 return max_spins_before_thin_lock_inflation_; 322 } 323 GetMonitorList()324 MonitorList* GetMonitorList() const { 325 return monitor_list_; 326 } 327 GetMonitorPool()328 MonitorPool* GetMonitorPool() const { 329 return monitor_pool_; 330 } 331 332 // Is the given object the special object used to mark a cleared JNI weak global? 333 bool IsClearedJniWeakGlobal(ObjPtr<mirror::Object> obj) REQUIRES_SHARED(Locks::mutator_lock_); 334 335 // Get the special object used to mark a cleared JNI weak global. 336 mirror::Object* GetClearedJniWeakGlobal() REQUIRES_SHARED(Locks::mutator_lock_); 337 338 mirror::Throwable* GetPreAllocatedOutOfMemoryErrorWhenThrowingException() 339 REQUIRES_SHARED(Locks::mutator_lock_); 340 mirror::Throwable* GetPreAllocatedOutOfMemoryErrorWhenThrowingOOME() 341 REQUIRES_SHARED(Locks::mutator_lock_); 342 mirror::Throwable* GetPreAllocatedOutOfMemoryErrorWhenHandlingStackOverflow() 343 REQUIRES_SHARED(Locks::mutator_lock_); 344 345 mirror::Throwable* GetPreAllocatedNoClassDefFoundError() 346 REQUIRES_SHARED(Locks::mutator_lock_); 347 GetProperties()348 const std::vector<std::string>& GetProperties() const { 349 return properties_; 350 } 351 GetThreadList()352 ThreadList* GetThreadList() const { 353 return thread_list_; 354 } 355 GetVersion()356 static const char* GetVersion() { 357 return "2.1.0"; 358 } 359 IsMethodHandlesEnabled()360 bool IsMethodHandlesEnabled() const { 361 return true; 362 } 363 364 void DisallowNewSystemWeaks() REQUIRES_SHARED(Locks::mutator_lock_); 365 void AllowNewSystemWeaks() REQUIRES_SHARED(Locks::mutator_lock_); 366 // broadcast_for_checkpoint is true when we broadcast for making blocking threads to respond to 367 // checkpoint requests. It's false when we broadcast to unblock blocking threads after system weak 368 // access is reenabled. 369 void BroadcastForNewSystemWeaks(bool broadcast_for_checkpoint = false); 370 371 // Visit all the roots. If only_dirty is true then non-dirty roots won't be visited. If 372 // clean_dirty is true then dirty roots will be marked as non-dirty after visiting. 373 void VisitRoots(RootVisitor* visitor, VisitRootFlags flags = kVisitRootFlagAllRoots) 374 REQUIRES(!Locks::classlinker_classes_lock_, !Locks::trace_lock_) 375 REQUIRES_SHARED(Locks::mutator_lock_); 376 377 // Visit image roots, only used for hprof since the GC uses the image space mod union table 378 // instead. 379 void VisitImageRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_); 380 381 // Visit all of the roots we can safely visit concurrently. 382 void VisitConcurrentRoots(RootVisitor* visitor, 383 VisitRootFlags flags = kVisitRootFlagAllRoots) 384 REQUIRES(!Locks::classlinker_classes_lock_, !Locks::trace_lock_) 385 REQUIRES_SHARED(Locks::mutator_lock_); 386 387 // Visit all of the non thread roots, we can do this with mutators unpaused. 388 void VisitNonThreadRoots(RootVisitor* visitor) 389 REQUIRES_SHARED(Locks::mutator_lock_); 390 391 void VisitTransactionRoots(RootVisitor* visitor) 392 REQUIRES_SHARED(Locks::mutator_lock_); 393 394 // Sweep system weaks, the system weak is deleted if the visitor return null. Otherwise, the 395 // system weak is updated to be the visitor's returned value. 396 void SweepSystemWeaks(IsMarkedVisitor* visitor) 397 REQUIRES_SHARED(Locks::mutator_lock_); 398 399 // Walk all reflective objects and visit their targets as well as any method/fields held by the 400 // runtime threads that are marked as being reflective. 401 void VisitReflectiveTargets(ReflectiveValueVisitor* visitor) REQUIRES(Locks::mutator_lock_); 402 // Helper for visiting reflective targets with lambdas for both field and method reflective 403 // targets. 404 template <typename FieldVis, typename MethodVis> VisitReflectiveTargets(FieldVis && fv,MethodVis && mv)405 void VisitReflectiveTargets(FieldVis&& fv, MethodVis&& mv) REQUIRES(Locks::mutator_lock_) { 406 FunctionReflectiveValueVisitor frvv(fv, mv); 407 VisitReflectiveTargets(&frvv); 408 } 409 410 // Returns a special method that calls into a trampoline for runtime method resolution 411 ArtMethod* GetResolutionMethod(); 412 HasResolutionMethod()413 bool HasResolutionMethod() const { 414 return resolution_method_ != nullptr; 415 } 416 417 void SetResolutionMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); ClearResolutionMethod()418 void ClearResolutionMethod() { 419 resolution_method_ = nullptr; 420 } 421 422 ArtMethod* CreateResolutionMethod() REQUIRES_SHARED(Locks::mutator_lock_); 423 424 // Returns a special method that calls into a trampoline for runtime imt conflicts. 425 ArtMethod* GetImtConflictMethod(); 426 ArtMethod* GetImtUnimplementedMethod(); 427 HasImtConflictMethod()428 bool HasImtConflictMethod() const { 429 return imt_conflict_method_ != nullptr; 430 } 431 ClearImtConflictMethod()432 void ClearImtConflictMethod() { 433 imt_conflict_method_ = nullptr; 434 } 435 436 void FixupConflictTables() REQUIRES_SHARED(Locks::mutator_lock_); 437 void SetImtConflictMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); 438 void SetImtUnimplementedMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); 439 440 ArtMethod* CreateImtConflictMethod(LinearAlloc* linear_alloc) 441 REQUIRES_SHARED(Locks::mutator_lock_); 442 ClearImtUnimplementedMethod()443 void ClearImtUnimplementedMethod() { 444 imt_unimplemented_method_ = nullptr; 445 } 446 HasCalleeSaveMethod(CalleeSaveType type)447 bool HasCalleeSaveMethod(CalleeSaveType type) const { 448 return callee_save_methods_[static_cast<size_t>(type)] != 0u; 449 } 450 451 ArtMethod* GetCalleeSaveMethod(CalleeSaveType type) 452 REQUIRES_SHARED(Locks::mutator_lock_); 453 454 ArtMethod* GetCalleeSaveMethodUnchecked(CalleeSaveType type) 455 REQUIRES_SHARED(Locks::mutator_lock_); 456 457 QuickMethodFrameInfo GetRuntimeMethodFrameInfo(ArtMethod* method) 458 REQUIRES_SHARED(Locks::mutator_lock_); 459 GetCalleeSaveMethodOffset(CalleeSaveType type)460 static constexpr size_t GetCalleeSaveMethodOffset(CalleeSaveType type) { 461 return OFFSETOF_MEMBER(Runtime, callee_save_methods_[static_cast<size_t>(type)]); 462 } 463 GetInstructionSet()464 InstructionSet GetInstructionSet() const { 465 return instruction_set_; 466 } 467 468 void SetInstructionSet(InstructionSet instruction_set); 469 void ClearInstructionSet(); 470 471 void SetCalleeSaveMethod(ArtMethod* method, CalleeSaveType type); 472 void ClearCalleeSaveMethods(); 473 474 ArtMethod* CreateCalleeSaveMethod() REQUIRES_SHARED(Locks::mutator_lock_); 475 476 uint64_t GetStat(int kind); 477 GetStats()478 RuntimeStats* GetStats() { 479 return &stats_; 480 } 481 HasStatsEnabled()482 bool HasStatsEnabled() const { 483 return stats_enabled_; 484 } 485 486 void ResetStats(int kinds); 487 488 void SetStatsEnabled(bool new_state) 489 REQUIRES(!Locks::instrument_entrypoints_lock_, !Locks::mutator_lock_); 490 491 enum class NativeBridgeAction { // private 492 kUnload, 493 kInitialize 494 }; 495 GetJit()496 jit::Jit* GetJit() const { 497 return jit_.get(); 498 } 499 GetJitCodeCache()500 jit::JitCodeCache* GetJitCodeCache() const { 501 return jit_code_cache_.get(); 502 } 503 504 // Returns true if JIT compilations are enabled. GetJit() will be not null in this case. 505 bool UseJitCompilation() const; 506 507 void PreZygoteFork(); 508 void PostZygoteFork(); 509 void InitNonZygoteOrPostFork( 510 JNIEnv* env, 511 bool is_system_server, 512 bool is_child_zygote, 513 NativeBridgeAction action, 514 const char* isa, 515 bool profile_system_server = false); 516 GetInstrumentation()517 const instrumentation::Instrumentation* GetInstrumentation() const { 518 return &instrumentation_; 519 } 520 GetInstrumentation()521 instrumentation::Instrumentation* GetInstrumentation() { 522 return &instrumentation_; 523 } 524 525 void RegisterAppInfo(const std::vector<std::string>& code_paths, 526 const std::string& profile_output_filename); 527 528 // Transaction support. 529 bool IsActiveTransaction() const; 530 void EnterTransactionMode(bool strict, mirror::Class* root); 531 void ExitTransactionMode(); 532 void RollbackAllTransactions() REQUIRES_SHARED(Locks::mutator_lock_); 533 // Transaction rollback and exit transaction are always done together, it's convenience to 534 // do them in one function. 535 void RollbackAndExitTransactionMode() REQUIRES_SHARED(Locks::mutator_lock_); 536 bool IsTransactionAborted() const; 537 const std::unique_ptr<Transaction>& GetTransaction() const; 538 bool IsActiveStrictTransactionMode() const; 539 540 void AbortTransactionAndThrowAbortError(Thread* self, const std::string& abort_message) 541 REQUIRES_SHARED(Locks::mutator_lock_); 542 void ThrowTransactionAbortError(Thread* self) 543 REQUIRES_SHARED(Locks::mutator_lock_); 544 545 void RecordWriteFieldBoolean(mirror::Object* obj, MemberOffset field_offset, uint8_t value, 546 bool is_volatile) const; 547 void RecordWriteFieldByte(mirror::Object* obj, MemberOffset field_offset, int8_t value, 548 bool is_volatile) const; 549 void RecordWriteFieldChar(mirror::Object* obj, MemberOffset field_offset, uint16_t value, 550 bool is_volatile) const; 551 void RecordWriteFieldShort(mirror::Object* obj, MemberOffset field_offset, int16_t value, 552 bool is_volatile) const; 553 void RecordWriteField32(mirror::Object* obj, MemberOffset field_offset, uint32_t value, 554 bool is_volatile) const; 555 void RecordWriteField64(mirror::Object* obj, MemberOffset field_offset, uint64_t value, 556 bool is_volatile) const; 557 void RecordWriteFieldReference(mirror::Object* obj, 558 MemberOffset field_offset, 559 ObjPtr<mirror::Object> value, 560 bool is_volatile) const 561 REQUIRES_SHARED(Locks::mutator_lock_); 562 void RecordWriteArray(mirror::Array* array, size_t index, uint64_t value) const 563 REQUIRES_SHARED(Locks::mutator_lock_); 564 void RecordStrongStringInsertion(ObjPtr<mirror::String> s) const 565 REQUIRES(Locks::intern_table_lock_); 566 void RecordWeakStringInsertion(ObjPtr<mirror::String> s) const 567 REQUIRES(Locks::intern_table_lock_); 568 void RecordStrongStringRemoval(ObjPtr<mirror::String> s) const 569 REQUIRES(Locks::intern_table_lock_); 570 void RecordWeakStringRemoval(ObjPtr<mirror::String> s) const 571 REQUIRES(Locks::intern_table_lock_); 572 void RecordResolveString(ObjPtr<mirror::DexCache> dex_cache, dex::StringIndex string_idx) const 573 REQUIRES_SHARED(Locks::mutator_lock_); 574 575 void SetFaultMessage(const std::string& message); 576 577 void AddCurrentRuntimeFeaturesAsDex2OatArguments(std::vector<std::string>* arg_vector) const; 578 ExplicitStackOverflowChecks()579 bool ExplicitStackOverflowChecks() const { 580 return !implicit_so_checks_; 581 } 582 583 void DisableVerifier(); 584 bool IsVerificationEnabled() const; 585 bool IsVerificationSoftFail() const; 586 SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy policy)587 void SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy policy) { 588 hidden_api_policy_ = policy; 589 } 590 GetHiddenApiEnforcementPolicy()591 hiddenapi::EnforcementPolicy GetHiddenApiEnforcementPolicy() const { 592 return hidden_api_policy_; 593 } 594 SetCorePlatformApiEnforcementPolicy(hiddenapi::EnforcementPolicy policy)595 void SetCorePlatformApiEnforcementPolicy(hiddenapi::EnforcementPolicy policy) { 596 core_platform_api_policy_ = policy; 597 } 598 GetCorePlatformApiEnforcementPolicy()599 hiddenapi::EnforcementPolicy GetCorePlatformApiEnforcementPolicy() const { 600 return core_platform_api_policy_; 601 } 602 SetTestApiEnforcementPolicy(hiddenapi::EnforcementPolicy policy)603 void SetTestApiEnforcementPolicy(hiddenapi::EnforcementPolicy policy) { 604 test_api_policy_ = policy; 605 } 606 GetTestApiEnforcementPolicy()607 hiddenapi::EnforcementPolicy GetTestApiEnforcementPolicy() const { 608 return test_api_policy_; 609 } 610 SetHiddenApiExemptions(const std::vector<std::string> & exemptions)611 void SetHiddenApiExemptions(const std::vector<std::string>& exemptions) { 612 hidden_api_exemptions_ = exemptions; 613 } 614 GetHiddenApiExemptions()615 const std::vector<std::string>& GetHiddenApiExemptions() { 616 return hidden_api_exemptions_; 617 } 618 SetDedupeHiddenApiWarnings(bool value)619 void SetDedupeHiddenApiWarnings(bool value) { 620 dedupe_hidden_api_warnings_ = value; 621 } 622 ShouldDedupeHiddenApiWarnings()623 bool ShouldDedupeHiddenApiWarnings() { 624 return dedupe_hidden_api_warnings_; 625 } 626 SetHiddenApiEventLogSampleRate(uint32_t rate)627 void SetHiddenApiEventLogSampleRate(uint32_t rate) { 628 hidden_api_access_event_log_rate_ = rate; 629 } 630 GetHiddenApiEventLogSampleRate()631 uint32_t GetHiddenApiEventLogSampleRate() const { 632 return hidden_api_access_event_log_rate_; 633 } 634 GetProcessPackageName()635 const std::string& GetProcessPackageName() const { 636 return process_package_name_; 637 } 638 SetProcessPackageName(const char * package_name)639 void SetProcessPackageName(const char* package_name) { 640 if (package_name == nullptr) { 641 process_package_name_.clear(); 642 } else { 643 process_package_name_ = package_name; 644 } 645 } 646 GetProcessDataDirectory()647 const std::string& GetProcessDataDirectory() const { 648 return process_data_directory_; 649 } 650 SetProcessDataDirectory(const char * data_dir)651 void SetProcessDataDirectory(const char* data_dir) { 652 if (data_dir == nullptr) { 653 process_data_directory_.clear(); 654 } else { 655 process_data_directory_ = data_dir; 656 } 657 } 658 IsDexFileFallbackEnabled()659 bool IsDexFileFallbackEnabled() const { 660 return allow_dex_file_fallback_; 661 } 662 GetCpuAbilist()663 const std::vector<std::string>& GetCpuAbilist() const { 664 return cpu_abilist_; 665 } 666 IsRunningOnMemoryTool()667 bool IsRunningOnMemoryTool() const { 668 return is_running_on_memory_tool_; 669 } 670 SetTargetSdkVersion(uint32_t version)671 void SetTargetSdkVersion(uint32_t version) { 672 target_sdk_version_ = version; 673 } 674 GetTargetSdkVersion()675 uint32_t GetTargetSdkVersion() const { 676 return target_sdk_version_; 677 } 678 SetDisabledCompatChanges(const std::set<uint64_t> & disabled_changes)679 void SetDisabledCompatChanges(const std::set<uint64_t>& disabled_changes) { 680 disabled_compat_changes_ = disabled_changes; 681 } 682 GetDisabledCompatChanges()683 std::set<uint64_t> GetDisabledCompatChanges() const { 684 return disabled_compat_changes_; 685 } 686 isChangeEnabled(uint64_t change_id)687 bool isChangeEnabled(uint64_t change_id) const { 688 // TODO(145743810): add an up call to java to log to statsd 689 return disabled_compat_changes_.count(change_id) == 0; 690 } 691 GetZygoteMaxFailedBoots()692 uint32_t GetZygoteMaxFailedBoots() const { 693 return zygote_max_failed_boots_; 694 } 695 AreExperimentalFlagsEnabled(ExperimentalFlags flags)696 bool AreExperimentalFlagsEnabled(ExperimentalFlags flags) { 697 return (experimental_flags_ & flags) != ExperimentalFlags::kNone; 698 } 699 700 void CreateJitCodeCache(bool rwx_memory_allowed); 701 702 // Create the JIT and instrumentation and code cache. 703 void CreateJit(); 704 GetArenaPool()705 ArenaPool* GetArenaPool() { 706 return arena_pool_.get(); 707 } GetJitArenaPool()708 ArenaPool* GetJitArenaPool() { 709 return jit_arena_pool_.get(); 710 } GetArenaPool()711 const ArenaPool* GetArenaPool() const { 712 return arena_pool_.get(); 713 } 714 715 void ReclaimArenaPoolMemory(); 716 GetLinearAlloc()717 LinearAlloc* GetLinearAlloc() { 718 return linear_alloc_.get(); 719 } 720 GetJITOptions()721 jit::JitOptions* GetJITOptions() { 722 return jit_options_.get(); 723 } 724 IsJavaDebuggable()725 bool IsJavaDebuggable() const { 726 return is_java_debuggable_; 727 } 728 SetProfileableFromShell(bool value)729 void SetProfileableFromShell(bool value) { 730 is_profileable_from_shell_ = value; 731 } 732 IsProfileableFromShell()733 bool IsProfileableFromShell() const { 734 return is_profileable_from_shell_; 735 } 736 737 void SetJavaDebuggable(bool value); 738 739 // Deoptimize the boot image, called for Java debuggable apps. 740 void DeoptimizeBootImage() REQUIRES(Locks::mutator_lock_); 741 IsNativeDebuggable()742 bool IsNativeDebuggable() const { 743 return is_native_debuggable_; 744 } 745 SetNativeDebuggable(bool value)746 void SetNativeDebuggable(bool value) { 747 is_native_debuggable_ = value; 748 } 749 750 void SetSignalHookDebuggable(bool value); 751 AreNonStandardExitsEnabled()752 bool AreNonStandardExitsEnabled() const { 753 return non_standard_exits_enabled_; 754 } 755 SetNonStandardExitsEnabled()756 void SetNonStandardExitsEnabled() { 757 DoAndMaybeSwitchInterpreter([=](){ non_standard_exits_enabled_ = true; }); 758 } 759 AreAsyncExceptionsThrown()760 bool AreAsyncExceptionsThrown() const { 761 return async_exceptions_thrown_; 762 } 763 SetAsyncExceptionsThrown()764 void SetAsyncExceptionsThrown() { 765 DoAndMaybeSwitchInterpreter([=](){ async_exceptions_thrown_ = true; }); 766 } 767 768 // Change state and re-check which interpreter should be used. 769 // 770 // This must be called whenever there is an event that forces 771 // us to use different interpreter (e.g. debugger is attached). 772 // 773 // Changing the state using the lamda gives us some multihreading safety. 774 // It ensures that two calls do not interfere with each other and 775 // it makes it possible to DCHECK that thread local flag is correct. 776 template<typename Action> 777 static void DoAndMaybeSwitchInterpreter(Action lamda); 778 779 // Returns the build fingerprint, if set. Otherwise an empty string is returned. GetFingerprint()780 std::string GetFingerprint() { 781 return fingerprint_; 782 } 783 784 // Called from class linker. 785 void SetSentinel(ObjPtr<mirror::Object> sentinel) REQUIRES_SHARED(Locks::mutator_lock_); 786 // For testing purpose only. 787 // TODO: Remove this when this is no longer needed (b/116087961). 788 GcRoot<mirror::Object> GetSentinel() REQUIRES_SHARED(Locks::mutator_lock_); 789 790 791 // Use a sentinel for marking entries in a table that have been cleared. 792 // This helps diagnosing in case code tries to wrongly access such 793 // entries. GetWeakClassSentinel()794 static mirror::Class* GetWeakClassSentinel() { 795 return reinterpret_cast<mirror::Class*>(0xebadbeef); 796 } 797 798 // Helper for the GC to process a weak class in a table. 799 static void ProcessWeakClass(GcRoot<mirror::Class>* root_ptr, 800 IsMarkedVisitor* visitor, 801 mirror::Class* update) 802 REQUIRES_SHARED(Locks::mutator_lock_); 803 804 // Create a normal LinearAlloc or low 4gb version if we are 64 bit AOT compiler. 805 LinearAlloc* CreateLinearAlloc(); 806 GetOatFileManager()807 OatFileManager& GetOatFileManager() const { 808 DCHECK(oat_file_manager_ != nullptr); 809 return *oat_file_manager_; 810 } 811 812 double GetHashTableMinLoadFactor() const; 813 double GetHashTableMaxLoadFactor() const; 814 IsSafeMode()815 bool IsSafeMode() const { 816 return safe_mode_; 817 } 818 SetSafeMode(bool mode)819 void SetSafeMode(bool mode) { 820 safe_mode_ = mode; 821 } 822 GetDumpNativeStackOnSigQuit()823 bool GetDumpNativeStackOnSigQuit() const { 824 return dump_native_stack_on_sig_quit_; 825 } 826 GetPrunedDalvikCache()827 bool GetPrunedDalvikCache() const { 828 return pruned_dalvik_cache_; 829 } 830 SetPrunedDalvikCache(bool pruned)831 void SetPrunedDalvikCache(bool pruned) { 832 pruned_dalvik_cache_ = pruned; 833 } 834 835 void UpdateProcessState(ProcessState process_state); 836 837 // Returns true if we currently care about long mutator pause. InJankPerceptibleProcessState()838 bool InJankPerceptibleProcessState() const { 839 return process_state_ == kProcessStateJankPerceptible; 840 } 841 842 void RegisterSensitiveThread() const; 843 SetZygoteNoThreadSection(bool val)844 void SetZygoteNoThreadSection(bool val) { 845 zygote_no_threads_ = val; 846 } 847 IsZygoteNoThreadSection()848 bool IsZygoteNoThreadSection() const { 849 return zygote_no_threads_; 850 } 851 852 // Returns if the code can be deoptimized asynchronously. Code may be compiled with some 853 // optimization that makes it impossible to deoptimize. 854 bool IsAsyncDeoptimizeable(uintptr_t code) const REQUIRES_SHARED(Locks::mutator_lock_); 855 856 // Returns a saved copy of the environment (getenv/setenv values). 857 // Used by Fork to protect against overwriting LD_LIBRARY_PATH, etc. GetEnvSnapshot()858 char** GetEnvSnapshot() const { 859 return env_snapshot_.GetSnapshot(); 860 } 861 862 void AddSystemWeakHolder(gc::AbstractSystemWeakHolder* holder); 863 void RemoveSystemWeakHolder(gc::AbstractSystemWeakHolder* holder); 864 865 void AttachAgent(JNIEnv* env, const std::string& agent_arg, jobject class_loader); 866 GetAgents()867 const std::list<std::unique_ptr<ti::Agent>>& GetAgents() const { 868 return agents_; 869 } 870 871 RuntimeCallbacks* GetRuntimeCallbacks(); 872 HasLoadedPlugins()873 bool HasLoadedPlugins() const { 874 return !plugins_.empty(); 875 } 876 877 void InitThreadGroups(Thread* self); 878 SetDumpGCPerformanceOnShutdown(bool value)879 void SetDumpGCPerformanceOnShutdown(bool value) { 880 dump_gc_performance_on_shutdown_ = value; 881 } 882 GetDumpGCPerformanceOnShutdown()883 bool GetDumpGCPerformanceOnShutdown() const { 884 return dump_gc_performance_on_shutdown_; 885 } 886 IncrementDeoptimizationCount(DeoptimizationKind kind)887 void IncrementDeoptimizationCount(DeoptimizationKind kind) { 888 DCHECK_LE(kind, DeoptimizationKind::kLast); 889 deoptimization_counts_[static_cast<size_t>(kind)]++; 890 } 891 GetNumberOfDeoptimizations()892 uint32_t GetNumberOfDeoptimizations() const { 893 uint32_t result = 0; 894 for (size_t i = 0; i <= static_cast<size_t>(DeoptimizationKind::kLast); ++i) { 895 result += deoptimization_counts_[i]; 896 } 897 return result; 898 } 899 900 // Whether or not we use MADV_RANDOM on files that are thought to have random access patterns. 901 // This is beneficial for low RAM devices since it reduces page cache thrashing. MAdviseRandomAccess()902 bool MAdviseRandomAccess() const { 903 return madvise_random_access_; 904 } 905 GetJdwpOptions()906 const std::string& GetJdwpOptions() { 907 return jdwp_options_; 908 } 909 GetJdwpProvider()910 JdwpProvider GetJdwpProvider() const { 911 return jdwp_provider_; 912 } 913 GetJniIdType()914 JniIdType GetJniIdType() const { 915 return jni_ids_indirection_; 916 } 917 CanSetJniIdType()918 bool CanSetJniIdType() const { 919 return GetJniIdType() == JniIdType::kSwapablePointer; 920 } 921 922 // Changes the JniIdType to the given type. Only allowed if CanSetJniIdType(). All threads must be 923 // suspended to call this function. 924 void SetJniIdType(JniIdType t); 925 GetVerifierLoggingThresholdMs()926 uint32_t GetVerifierLoggingThresholdMs() const { 927 return verifier_logging_threshold_ms_; 928 } 929 930 // Atomically delete the thread pool if the reference count is 0. 931 bool DeleteThreadPool() REQUIRES(!Locks::runtime_thread_pool_lock_); 932 933 // Wait for all the thread workers to be attached. 934 void WaitForThreadPoolWorkersToStart() REQUIRES(!Locks::runtime_thread_pool_lock_); 935 936 // Scoped usage of the runtime thread pool. Prevents the pool from being 937 // deleted. Note that the thread pool is only for startup and gets deleted after. 938 class ScopedThreadPoolUsage { 939 public: 940 ScopedThreadPoolUsage(); 941 ~ScopedThreadPoolUsage(); 942 943 // Return the thread pool. GetThreadPool()944 ThreadPool* GetThreadPool() const { 945 return thread_pool_; 946 } 947 948 private: 949 ThreadPool* const thread_pool_; 950 }; 951 LoadAppImageStartupCache()952 bool LoadAppImageStartupCache() const { 953 return load_app_image_startup_cache_; 954 } 955 SetLoadAppImageStartupCacheEnabled(bool enabled)956 void SetLoadAppImageStartupCacheEnabled(bool enabled) { 957 load_app_image_startup_cache_ = enabled; 958 } 959 960 // Reset the startup completed status so that we can call NotifyStartupCompleted again. Should 961 // only be used for testing. 962 void ResetStartupCompleted(); 963 964 // Notify the runtime that application startup is considered completed. Only has effect for the 965 // first call. 966 void NotifyStartupCompleted(); 967 968 // Return true if startup is already completed. 969 bool GetStartupCompleted() const; 970 GetImageSpaceLoadingOrder()971 gc::space::ImageSpaceLoadingOrder GetImageSpaceLoadingOrder() const { 972 return image_space_loading_order_; 973 } 974 IsVerifierMissingKThrowFatal()975 bool IsVerifierMissingKThrowFatal() const { 976 return verifier_missing_kthrow_fatal_; 977 } 978 IsPerfettoHprofEnabled()979 bool IsPerfettoHprofEnabled() const { 980 return perfetto_hprof_enabled_; 981 } 982 983 // Return true if we should load oat files as executable or not. 984 bool GetOatFilesExecutable() const; 985 986 private: 987 static void InitPlatformSignalHandlers(); 988 989 Runtime(); 990 991 void BlockSignals(); 992 993 bool Init(RuntimeArgumentMap&& runtime_options) 994 SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_); 995 void InitNativeMethods() REQUIRES(!Locks::mutator_lock_); 996 void RegisterRuntimeNativeMethods(JNIEnv* env); 997 998 void StartDaemonThreads(); 999 void StartSignalCatcher(); 1000 1001 void MaybeSaveJitProfilingInfo(); 1002 1003 // Visit all of the thread roots. 1004 void VisitThreadRoots(RootVisitor* visitor, VisitRootFlags flags) 1005 REQUIRES_SHARED(Locks::mutator_lock_); 1006 1007 // Visit all other roots which must be done with mutators suspended. 1008 void VisitNonConcurrentRoots(RootVisitor* visitor, VisitRootFlags flags) 1009 REQUIRES_SHARED(Locks::mutator_lock_); 1010 1011 // Constant roots are the roots which never change after the runtime is initialized, they only 1012 // need to be visited once per GC cycle. 1013 void VisitConstantRoots(RootVisitor* visitor) 1014 REQUIRES_SHARED(Locks::mutator_lock_); 1015 1016 // Note: To be lock-free, GetFaultMessage temporarily replaces the lock message with null. 1017 // As such, there is a window where a call will return an empty string. In general, 1018 // only aborting code should retrieve this data (via GetFaultMessageForAbortLogging 1019 // friend). 1020 std::string GetFaultMessage(); 1021 1022 ThreadPool* AcquireThreadPool() REQUIRES(!Locks::runtime_thread_pool_lock_); 1023 void ReleaseThreadPool() REQUIRES(!Locks::runtime_thread_pool_lock_); 1024 1025 // A pointer to the active runtime or null. 1026 static Runtime* instance_; 1027 1028 // NOTE: these must match the gc::ProcessState values as they come directly from the framework. 1029 static constexpr int kProfileForground = 0; 1030 static constexpr int kProfileBackground = 1; 1031 1032 static constexpr uint32_t kCalleeSaveSize = 6u; 1033 1034 // 64 bit so that we can share the same asm offsets for both 32 and 64 bits. 1035 uint64_t callee_save_methods_[kCalleeSaveSize]; 1036 // Pre-allocated exceptions (see Runtime::Init). 1037 GcRoot<mirror::Throwable> pre_allocated_OutOfMemoryError_when_throwing_exception_; 1038 GcRoot<mirror::Throwable> pre_allocated_OutOfMemoryError_when_throwing_oome_; 1039 GcRoot<mirror::Throwable> pre_allocated_OutOfMemoryError_when_handling_stack_overflow_; 1040 GcRoot<mirror::Throwable> pre_allocated_NoClassDefFoundError_; 1041 ArtMethod* resolution_method_; 1042 ArtMethod* imt_conflict_method_; 1043 // Unresolved method has the same behavior as the conflict method, it is used by the class linker 1044 // for differentiating between unfilled imt slots vs conflict slots in superclasses. 1045 ArtMethod* imt_unimplemented_method_; 1046 1047 // Special sentinel object used to invalid conditions in JNI (cleared weak references) and 1048 // JDWP (invalid references). 1049 GcRoot<mirror::Object> sentinel_; 1050 1051 InstructionSet instruction_set_; 1052 1053 CompilerCallbacks* compiler_callbacks_; 1054 bool is_zygote_; 1055 bool is_primary_zygote_; 1056 bool is_system_server_; 1057 bool must_relocate_; 1058 bool is_concurrent_gc_enabled_; 1059 bool is_explicit_gc_disabled_; 1060 bool image_dex2oat_enabled_; 1061 1062 std::string compiler_executable_; 1063 std::vector<std::string> compiler_options_; 1064 std::vector<std::string> image_compiler_options_; 1065 std::string image_location_; 1066 1067 std::vector<std::string> boot_class_path_; 1068 std::vector<std::string> boot_class_path_locations_; 1069 std::string class_path_string_; 1070 std::vector<std::string> properties_; 1071 1072 std::list<ti::AgentSpec> agent_specs_; 1073 std::list<std::unique_ptr<ti::Agent>> agents_; 1074 std::vector<Plugin> plugins_; 1075 1076 // The default stack size for managed threads created by the runtime. 1077 size_t default_stack_size_; 1078 1079 // Finalizers running for longer than this many milliseconds abort the runtime. 1080 unsigned int finalizer_timeout_ms_; 1081 1082 gc::Heap* heap_; 1083 1084 std::unique_ptr<ArenaPool> jit_arena_pool_; 1085 std::unique_ptr<ArenaPool> arena_pool_; 1086 // Special low 4gb pool for compiler linear alloc. We need ArtFields to be in low 4gb if we are 1087 // compiling using a 32 bit image on a 64 bit compiler in case we resolve things in the image 1088 // since the field arrays are int arrays in this case. 1089 std::unique_ptr<ArenaPool> low_4gb_arena_pool_; 1090 1091 // Shared linear alloc for now. 1092 std::unique_ptr<LinearAlloc> linear_alloc_; 1093 1094 // The number of spins that are done before thread suspension is used to forcibly inflate. 1095 size_t max_spins_before_thin_lock_inflation_; 1096 MonitorList* monitor_list_; 1097 MonitorPool* monitor_pool_; 1098 1099 ThreadList* thread_list_; 1100 1101 InternTable* intern_table_; 1102 1103 ClassLinker* class_linker_; 1104 1105 SignalCatcher* signal_catcher_; 1106 1107 std::unique_ptr<jni::JniIdManager> jni_id_manager_; 1108 1109 std::unique_ptr<JavaVMExt> java_vm_; 1110 1111 std::unique_ptr<jit::Jit> jit_; 1112 std::unique_ptr<jit::JitCodeCache> jit_code_cache_; 1113 std::unique_ptr<jit::JitOptions> jit_options_; 1114 1115 // Runtime thread pool. The pool is only for startup and gets deleted after. 1116 std::unique_ptr<ThreadPool> thread_pool_ GUARDED_BY(Locks::runtime_thread_pool_lock_); 1117 size_t thread_pool_ref_count_ GUARDED_BY(Locks::runtime_thread_pool_lock_); 1118 1119 // Fault message, printed when we get a SIGSEGV. Stored as a native-heap object and accessed 1120 // lock-free, so needs to be atomic. 1121 std::atomic<std::string*> fault_message_; 1122 1123 // A non-zero value indicates that a thread has been created but not yet initialized. Guarded by 1124 // the shutdown lock so that threads aren't born while we're shutting down. 1125 size_t threads_being_born_ GUARDED_BY(Locks::runtime_shutdown_lock_); 1126 1127 // Waited upon until no threads are being born. 1128 std::unique_ptr<ConditionVariable> shutdown_cond_ GUARDED_BY(Locks::runtime_shutdown_lock_); 1129 1130 // Set when runtime shutdown is past the point that new threads may attach. 1131 bool shutting_down_ GUARDED_BY(Locks::runtime_shutdown_lock_); 1132 1133 // The runtime is starting to shutdown but is blocked waiting on shutdown_cond_. 1134 bool shutting_down_started_ GUARDED_BY(Locks::runtime_shutdown_lock_); 1135 1136 bool started_; 1137 1138 // New flag added which tells us if the runtime has finished starting. If 1139 // this flag is set then the Daemon threads are created and the class loader 1140 // is created. This flag is needed for knowing if its safe to request CMS. 1141 bool finished_starting_; 1142 1143 // Hooks supported by JNI_CreateJavaVM 1144 jint (*vfprintf_)(FILE* stream, const char* format, va_list ap); 1145 void (*exit_)(jint status); 1146 void (*abort_)(); 1147 1148 bool stats_enabled_; 1149 RuntimeStats stats_; 1150 1151 const bool is_running_on_memory_tool_; 1152 1153 std::unique_ptr<TraceConfig> trace_config_; 1154 1155 instrumentation::Instrumentation instrumentation_; 1156 1157 jobject main_thread_group_; 1158 jobject system_thread_group_; 1159 1160 // As returned by ClassLoader.getSystemClassLoader(). 1161 jobject system_class_loader_; 1162 1163 // If true, then we dump the GC cumulative timings on shutdown. 1164 bool dump_gc_performance_on_shutdown_; 1165 1166 // Transactions used for pre-initializing classes at compilation time. 1167 // Support nested transactions, maintain a list containing all transactions. Transactions are 1168 // handled under a stack discipline. Because GC needs to go over all transactions, we choose list 1169 // as substantial data structure instead of stack. 1170 std::list<std::unique_ptr<Transaction>> preinitialization_transactions_; 1171 1172 // If kNone, verification is disabled. kEnable by default. 1173 verifier::VerifyMode verify_; 1174 1175 // If true, the runtime may use dex files directly with the interpreter if an oat file is not 1176 // available/usable. 1177 bool allow_dex_file_fallback_; 1178 1179 // List of supported cpu abis. 1180 std::vector<std::string> cpu_abilist_; 1181 1182 // Specifies target SDK version to allow workarounds for certain API levels. 1183 uint32_t target_sdk_version_; 1184 1185 // A set of disabled compat changes for the running app, all other changes are enabled. 1186 std::set<uint64_t> disabled_compat_changes_; 1187 1188 // Implicit checks flags. 1189 bool implicit_null_checks_; // NullPointer checks are implicit. 1190 bool implicit_so_checks_; // StackOverflow checks are implicit. 1191 bool implicit_suspend_checks_; // Thread suspension checks are implicit. 1192 1193 // Whether or not the sig chain (and implicitly the fault handler) should be 1194 // disabled. Tools like dex2oat don't need them. This enables 1195 // building a statically link version of dex2oat. 1196 bool no_sig_chain_; 1197 1198 // Force the use of native bridge even if the app ISA matches the runtime ISA. 1199 bool force_native_bridge_; 1200 1201 // Whether or not a native bridge has been loaded. 1202 // 1203 // The native bridge allows running native code compiled for a foreign ISA. The way it works is, 1204 // if standard dlopen fails to load native library associated with native activity, it calls to 1205 // the native bridge to load it and then gets the trampoline for the entry to native activity. 1206 // 1207 // The option 'native_bridge_library_filename' specifies the name of the native bridge. 1208 // When non-empty the native bridge will be loaded from the given file. An empty value means 1209 // that there's no native bridge. 1210 bool is_native_bridge_loaded_; 1211 1212 // Whether we are running under native debugger. 1213 bool is_native_debuggable_; 1214 1215 // whether or not any async exceptions have ever been thrown. This is used to speed up the 1216 // MterpShouldSwitchInterpreters function. 1217 bool async_exceptions_thrown_; 1218 1219 // Whether anything is going to be using the shadow-frame APIs to force a function to return 1220 // early. Doing this requires that (1) we be debuggable and (2) that mterp is exited. 1221 bool non_standard_exits_enabled_; 1222 1223 // Whether Java code needs to be debuggable. 1224 bool is_java_debuggable_; 1225 1226 bool is_profileable_from_shell_ = false; 1227 1228 // The maximum number of failed boots we allow before pruning the dalvik cache 1229 // and trying again. This option is only inspected when we're running as a 1230 // zygote. 1231 uint32_t zygote_max_failed_boots_; 1232 1233 // Enable experimental opcodes that aren't fully specified yet. The intent is to 1234 // eventually publish them as public-usable opcodes, but they aren't ready yet. 1235 // 1236 // Experimental opcodes should not be used by other production code. 1237 ExperimentalFlags experimental_flags_; 1238 1239 // Contains the build fingerprint, if given as a parameter. 1240 std::string fingerprint_; 1241 1242 // Oat file manager, keeps track of what oat files are open. 1243 OatFileManager* oat_file_manager_; 1244 1245 // Whether or not we are on a low RAM device. 1246 bool is_low_memory_mode_; 1247 1248 // Whether or not we use MADV_RANDOM on files that are thought to have random access patterns. 1249 // This is beneficial for low RAM devices since it reduces page cache thrashing. 1250 bool madvise_random_access_; 1251 1252 // Whether the application should run in safe mode, that is, interpreter only. 1253 bool safe_mode_; 1254 1255 // Whether access checks on hidden API should be performed. 1256 hiddenapi::EnforcementPolicy hidden_api_policy_; 1257 1258 // Whether access checks on core platform API should be performed. 1259 hiddenapi::EnforcementPolicy core_platform_api_policy_; 1260 1261 // Whether access checks on test API should be performed. 1262 hiddenapi::EnforcementPolicy test_api_policy_; 1263 1264 // List of signature prefixes of methods that have been removed from the blacklist, and treated 1265 // as if whitelisted. 1266 std::vector<std::string> hidden_api_exemptions_; 1267 1268 // Do not warn about the same hidden API access violation twice. 1269 // This is only used for testing. 1270 bool dedupe_hidden_api_warnings_; 1271 1272 // How often to log hidden API access to the event log. An integer between 0 1273 // (never) and 0x10000 (always). 1274 uint32_t hidden_api_access_event_log_rate_; 1275 1276 // The package of the app running in this process. 1277 std::string process_package_name_; 1278 1279 // The data directory of the app running in this process. 1280 std::string process_data_directory_; 1281 1282 // Whether threads should dump their native stack on SIGQUIT. 1283 bool dump_native_stack_on_sig_quit_; 1284 1285 // Whether the dalvik cache was pruned when initializing the runtime. 1286 bool pruned_dalvik_cache_; 1287 1288 // Whether or not we currently care about pause times. 1289 ProcessState process_state_; 1290 1291 // Whether zygote code is in a section that should not start threads. 1292 bool zygote_no_threads_; 1293 1294 // The string containing requested jdwp options 1295 std::string jdwp_options_; 1296 1297 // The jdwp provider we were configured with. 1298 JdwpProvider jdwp_provider_; 1299 1300 // True if jmethodID and jfieldID are opaque Indices. When false (the default) these are simply 1301 // pointers. This is set by -Xopaque-jni-ids:{true,false}. 1302 JniIdType jni_ids_indirection_; 1303 1304 // Set to false in cases where we want to directly control when jni-id 1305 // indirection is changed. This is intended only for testing JNI id swapping. 1306 bool automatically_set_jni_ids_indirection_; 1307 1308 // Saved environment. 1309 class EnvSnapshot { 1310 public: 1311 EnvSnapshot() = default; 1312 void TakeSnapshot(); 1313 char** GetSnapshot() const; 1314 1315 private: 1316 std::unique_ptr<char*[]> c_env_vector_; 1317 std::vector<std::unique_ptr<std::string>> name_value_pairs_; 1318 1319 DISALLOW_COPY_AND_ASSIGN(EnvSnapshot); 1320 } env_snapshot_; 1321 1322 // Generic system-weak holders. 1323 std::vector<gc::AbstractSystemWeakHolder*> system_weak_holders_; 1324 1325 std::unique_ptr<RuntimeCallbacks> callbacks_; 1326 1327 std::atomic<uint32_t> deoptimization_counts_[ 1328 static_cast<uint32_t>(DeoptimizationKind::kLast) + 1]; 1329 1330 MemMap protected_fault_page_; 1331 1332 uint32_t verifier_logging_threshold_ms_; 1333 1334 bool load_app_image_startup_cache_ = false; 1335 1336 // If startup has completed, must happen at most once. 1337 std::atomic<bool> startup_completed_ = false; 1338 1339 gc::space::ImageSpaceLoadingOrder image_space_loading_order_ = 1340 gc::space::ImageSpaceLoadingOrder::kSystemFirst; 1341 1342 bool verifier_missing_kthrow_fatal_; 1343 bool perfetto_hprof_enabled_; 1344 1345 // Note: See comments on GetFaultMessage. 1346 friend std::string GetFaultMessageForAbortLogging(); 1347 friend class Dex2oatImageTest; 1348 friend class ScopedThreadPoolUsage; 1349 friend class OatFileAssistantTest; 1350 class NotifyStartupCompletedTask; 1351 1352 DISALLOW_COPY_AND_ASSIGN(Runtime); 1353 }; 1354 1355 } // namespace art 1356 1357 #endif // ART_RUNTIME_RUNTIME_H_ 1358