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