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