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