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