runtime.h revision 0b71357fb52be9bb06d35396a3042b4381b01041
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
42namespace art {
43
44namespace gc {
45  class Heap;
46  namespace collector {
47    class GarbageCollector;
48  }  // namespace collector
49}  // namespace gc
50
51namespace jit {
52  class Jit;
53  class JitOptions;
54}  // namespace jit
55
56namespace 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
65namespace verifier {
66  class MethodVerifier;
67}  // namespace verifier
68class ArenaPool;
69class ArtMethod;
70class ClassLinker;
71class Closure;
72class CompilerCallbacks;
73class DexFile;
74class InternTable;
75class JavaVMExt;
76class LinearAlloc;
77class MonitorList;
78class MonitorPool;
79class NullPointerHandler;
80class SignalCatcher;
81class StackOverflowHandler;
82class SuspensionHandler;
83class ThreadList;
84class Trace;
85struct TraceConfig;
86class Transaction;
87
88typedef std::vector<std::pair<std::string, const void*>> RuntimeOptions;
89typedef 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).
95enum 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
106class 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.
113  bool IsAotCompiler() const {
114    return !UseJit() && IsCompiler();
115  }
116
117  // IsCompiler is any runtime which has a running compiler, either dex2oat or JIT.
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
127  bool ShouldRelocate() const {
128    return must_relocate_ && CanRelocate();
129  }
130
131  bool MustRelocateIfPossible() const {
132    return must_relocate_;
133  }
134
135  bool IsDex2OatEnabled() const {
136    return dex2oat_enabled_ && IsImageDex2OatEnabled();
137  }
138
139  bool IsImageDex2OatEnabled() const {
140    return image_dex2oat_enabled_;
141  }
142
143  CompilerCallbacks* GetCompilerCallbacks() {
144    return compiler_callbacks_;
145  }
146
147  bool IsZygote() const {
148    return is_zygote_;
149  }
150
151  bool IsExplicitGcDisabled() const {
152    return is_explicit_gc_disabled_;
153  }
154
155  std::string GetCompilerExecutable() const;
156  std::string GetPatchoatExecutable() const;
157
158  const std::vector<std::string>& GetCompilerOptions() const {
159    return compiler_options_;
160  }
161
162  void AddCompilerOption(std::string option) {
163    compiler_options_.push_back(option);
164  }
165
166  const std::vector<std::string>& GetImageCompilerOptions() const {
167    return image_compiler_options_;
168  }
169
170  const std::string& GetImageLocation() const {
171    return image_location_;
172  }
173
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);
182  bool IsShuttingDownLocked() const EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_) {
183    return shutting_down_;
184  }
185
186  size_t NumberOfThreadsBeingBorn() const EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_) {
187    return threads_being_born_;
188  }
189
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
196  bool IsStarted() const {
197    return started_;
198  }
199
200  bool IsFinishedStarting() const {
201    return finished_starting_;
202  }
203
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
235  const std::string& GetBootClassPathString() const {
236    return boot_class_path_string_;
237  }
238
239  const std::string& GetClassPathString() const {
240    return class_path_string_;
241  }
242
243  ClassLinker* GetClassLinker() const {
244    return class_linker_;
245  }
246
247  size_t GetDefaultStackSize() const {
248    return default_stack_size_;
249  }
250
251  gc::Heap* GetHeap() const {
252    return heap_;
253  }
254
255  InternTable* GetInternTable() const {
256    DCHECK(intern_table_ != nullptr);
257    return intern_table_;
258  }
259
260  JavaVMExt* GetJavaVM() const {
261    return java_vm_;
262  }
263
264  size_t GetMaxSpinsBeforeThinkLockInflation() const {
265    return max_spins_before_thin_lock_inflation_;
266  }
267
268  MonitorList* GetMonitorList() const {
269    return monitor_list_;
270  }
271
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
287  const std::vector<std::string>& GetProperties() const {
288    return properties_;
289  }
290
291  ThreadList* GetThreadList() const {
292    return thread_list_;
293  }
294
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  void BroadcastForNewSystemWeaks() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
303
304  // Visit all the roots. If only_dirty is true then non-dirty roots won't be visited. If
305  // clean_dirty is true then dirty roots will be marked as non-dirty after visiting.
306  void VisitRoots(RootVisitor* visitor, VisitRootFlags flags = kVisitRootFlagAllRoots)
307      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
308
309  // Visit image roots, only used for hprof since the GC uses the image space mod union table
310  // instead.
311  void VisitImageRoots(RootVisitor* visitor) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
312
313  // Visit all of the roots we can do safely do concurrently.
314  void VisitConcurrentRoots(RootVisitor* visitor,
315                            VisitRootFlags flags = kVisitRootFlagAllRoots)
316      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
317
318  // Visit all of the non thread roots, we can do this with mutators unpaused.
319  void VisitNonThreadRoots(RootVisitor* visitor)
320      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
321
322  void VisitTransactionRoots(RootVisitor* visitor)
323      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
324
325  // Visit all of the thread roots.
326  void VisitThreadRoots(RootVisitor* visitor) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
327
328  // Flip thread roots from from-space refs to to-space refs.
329  size_t FlipThreadRoots(Closure* thread_flip_visitor, Closure* flip_callback,
330                         gc::collector::GarbageCollector* collector)
331      LOCKS_EXCLUDED(Locks::mutator_lock_);
332
333  // Visit all other roots which must be done with mutators suspended.
334  void VisitNonConcurrentRoots(RootVisitor* visitor)
335      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
336
337  // Sweep system weaks, the system weak is deleted if the visitor return null. Otherwise, the
338  // system weak is updated to be the visitor's returned value.
339  void SweepSystemWeaks(IsMarkedCallback* visitor, void* arg)
340      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
341
342  // Constant roots are the roots which never change after the runtime is initialized, they only
343  // need to be visited once per GC cycle.
344  void VisitConstantRoots(RootVisitor* visitor)
345      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
346
347  // Returns a special method that calls into a trampoline for runtime method resolution
348  ArtMethod* GetResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
349
350  bool HasResolutionMethod() const {
351    return resolution_method_ != nullptr;
352  }
353
354  void SetResolutionMethod(ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
355
356  ArtMethod* CreateResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
357
358  // Returns a special method that calls into a trampoline for runtime imt conflicts.
359  ArtMethod* GetImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
360  ArtMethod* GetImtUnimplementedMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
361
362  bool HasImtConflictMethod() const {
363    return imt_conflict_method_ != nullptr;
364  }
365
366  void SetImtConflictMethod(ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
367  void SetImtUnimplementedMethod(ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
368
369  ArtMethod* CreateImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
370
371  // Returns a special method that describes all callee saves being spilled to the stack.
372  enum CalleeSaveType {
373    kSaveAll,
374    kRefsOnly,
375    kRefsAndArgs,
376    kLastCalleeSaveType  // Value used for iteration
377  };
378
379  bool HasCalleeSaveMethod(CalleeSaveType type) const {
380    return callee_save_methods_[type] != 0u;
381  }
382
383  ArtMethod* GetCalleeSaveMethod(CalleeSaveType type)
384      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
385
386  ArtMethod* GetCalleeSaveMethodUnchecked(CalleeSaveType type)
387      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
388
389  QuickMethodFrameInfo GetCalleeSaveMethodFrameInfo(CalleeSaveType type) const {
390    return callee_save_method_frame_infos_[type];
391  }
392
393  QuickMethodFrameInfo GetRuntimeMethodFrameInfo(ArtMethod* method)
394      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
395
396  static size_t GetCalleeSaveMethodOffset(CalleeSaveType type) {
397    return OFFSETOF_MEMBER(Runtime, callee_save_methods_[type]);
398  }
399
400  InstructionSet GetInstructionSet() const {
401    return instruction_set_;
402  }
403
404  void SetInstructionSet(InstructionSet instruction_set);
405
406  void SetCalleeSaveMethod(ArtMethod* method, CalleeSaveType type);
407
408  ArtMethod* CreateCalleeSaveMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
409
410  int32_t GetStat(int kind);
411
412  RuntimeStats* GetStats() {
413    return &stats_;
414  }
415
416  bool HasStatsEnabled() const {
417    return stats_enabled_;
418  }
419
420  void ResetStats(int kinds);
421
422  void SetStatsEnabled(bool new_state) LOCKS_EXCLUDED(Locks::instrument_entrypoints_lock_,
423                                                      Locks::mutator_lock_);
424
425  enum class NativeBridgeAction {  // private
426    kUnload,
427    kInitialize
428  };
429
430  jit::Jit* GetJit() {
431    return jit_.get();
432  }
433  bool UseJit() const {
434    return jit_.get() != nullptr;
435  }
436
437  void PreZygoteFork();
438  bool InitZygote();
439  void DidForkFromZygote(JNIEnv* env, NativeBridgeAction action, const char* isa);
440
441  const instrumentation::Instrumentation* GetInstrumentation() const {
442    return &instrumentation_;
443  }
444
445  instrumentation::Instrumentation* GetInstrumentation() {
446    return &instrumentation_;
447  }
448
449  void StartProfiler(const char* profile_output_filename);
450  void UpdateProfilerState(int state);
451
452  // Transaction support.
453  bool IsActiveTransaction() const {
454    return preinitialization_transaction_ != nullptr;
455  }
456  void EnterTransactionMode(Transaction* transaction);
457  void ExitTransactionMode();
458  bool IsTransactionAborted() const;
459
460  void AbortTransactionAndThrowAbortError(Thread* self, const std::string& abort_message)
461      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
462  void ThrowTransactionAbortError(Thread* self)
463      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
464
465  void RecordWriteFieldBoolean(mirror::Object* obj, MemberOffset field_offset, uint8_t value,
466                               bool is_volatile) const;
467  void RecordWriteFieldByte(mirror::Object* obj, MemberOffset field_offset, int8_t value,
468                            bool is_volatile) const;
469  void RecordWriteFieldChar(mirror::Object* obj, MemberOffset field_offset, uint16_t value,
470                            bool is_volatile) const;
471  void RecordWriteFieldShort(mirror::Object* obj, MemberOffset field_offset, int16_t value,
472                          bool is_volatile) const;
473  void RecordWriteField32(mirror::Object* obj, MemberOffset field_offset, uint32_t value,
474                          bool is_volatile) const;
475  void RecordWriteField64(mirror::Object* obj, MemberOffset field_offset, uint64_t value,
476                          bool is_volatile) const;
477  void RecordWriteFieldReference(mirror::Object* obj, MemberOffset field_offset,
478                                 mirror::Object* value, bool is_volatile) const;
479  void RecordWriteArray(mirror::Array* array, size_t index, uint64_t value) const
480      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
481  void RecordStrongStringInsertion(mirror::String* s) const
482      EXCLUSIVE_LOCKS_REQUIRED(Locks::intern_table_lock_);
483  void RecordWeakStringInsertion(mirror::String* s) const
484      EXCLUSIVE_LOCKS_REQUIRED(Locks::intern_table_lock_);
485  void RecordStrongStringRemoval(mirror::String* s) const
486      EXCLUSIVE_LOCKS_REQUIRED(Locks::intern_table_lock_);
487  void RecordWeakStringRemoval(mirror::String* s) const
488      EXCLUSIVE_LOCKS_REQUIRED(Locks::intern_table_lock_);
489
490  void SetFaultMessage(const std::string& message);
491  // Only read by the signal handler, NO_THREAD_SAFETY_ANALYSIS to prevent lock order violations
492  // with the unexpected_signal_lock_.
493  const std::string& GetFaultMessage() NO_THREAD_SAFETY_ANALYSIS {
494    return fault_message_;
495  }
496
497  void AddCurrentRuntimeFeaturesAsDex2OatArguments(std::vector<std::string>* arg_vector) const;
498
499  bool ExplicitStackOverflowChecks() const {
500    return !implicit_so_checks_;
501  }
502
503  bool IsVerificationEnabled() const {
504    return verify_;
505  }
506
507  bool IsDexFileFallbackEnabled() const {
508    return allow_dex_file_fallback_;
509  }
510
511  const std::vector<std::string>& GetCpuAbilist() const {
512    return cpu_abilist_;
513  }
514
515  bool RunningOnValgrind() const {
516    return running_on_valgrind_;
517  }
518
519  void SetTargetSdkVersion(int32_t version) {
520    target_sdk_version_ = version;
521  }
522
523  int32_t GetTargetSdkVersion() const {
524    return target_sdk_version_;
525  }
526
527  uint32_t GetZygoteMaxFailedBoots() const {
528    return zygote_max_failed_boots_;
529  }
530
531  bool AreExperimentalLambdasEnabled() const {
532    return experimental_lambdas_;
533  }
534
535  // Create the JIT and instrumentation and code cache.
536  void CreateJit();
537
538  ArenaPool* GetArenaPool() {
539    return arena_pool_.get();
540  }
541  const ArenaPool* GetArenaPool() const {
542    return arena_pool_.get();
543  }
544  LinearAlloc* GetLinearAlloc() {
545    return linear_alloc_.get();
546  }
547
548  jit::JitOptions* GetJITOptions() {
549    return jit_options_.get();
550  }
551
552  MethodRefToStringInitRegMap& GetStringInitMap() {
553    return method_ref_string_init_reg_map_;
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 the sig chain (and implicitly the fault handler) should be
720  // disabled. Tools like dex2oat or patchoat don't need them. This enables
721  // building a statically link version of dex2oat.
722  bool no_sig_chain_;
723
724  // Whether or not a native bridge has been loaded.
725  //
726  // The native bridge allows running native code compiled for a foreign ISA. The way it works is,
727  // if standard dlopen fails to load native library associated with native activity, it calls to
728  // the native bridge to load it and then gets the trampoline for the entry to native activity.
729  //
730  // The option 'native_bridge_library_filename' specifies the name of the native bridge.
731  // When non-empty the native bridge will be loaded from the given file. An empty value means
732  // that there's no native bridge.
733  bool is_native_bridge_loaded_;
734
735  // The maximum number of failed boots we allow before pruning the dalvik cache
736  // and trying again. This option is only inspected when we're running as a
737  // zygote.
738  uint32_t zygote_max_failed_boots_;
739
740  // Enable experimental opcodes that aren't fully specified yet. The intent is to
741  // eventually publish them as public-usable opcodes, but they aren't ready yet.
742  //
743  // Experimental opcodes should not be used by other production code.
744  bool experimental_lambdas_;
745
746  MethodRefToStringInitRegMap method_ref_string_init_reg_map_;
747
748  DISALLOW_COPY_AND_ASSIGN(Runtime);
749};
750std::ostream& operator<<(std::ostream& os, const Runtime::CalleeSaveType& rhs);
751
752}  // namespace art
753
754#endif  // ART_RUNTIME_RUNTIME_H_
755