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