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