runtime.h revision 1bc977cf2f8199311a97f2ba9431a184540e3e9c
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(
461      JNIEnv* env, bool is_system_server, NativeBridgeAction action, const char* isa);
462
463  const instrumentation::Instrumentation* GetInstrumentation() const {
464    return &instrumentation_;
465  }
466
467  instrumentation::Instrumentation* GetInstrumentation() {
468    return &instrumentation_;
469  }
470
471  void RegisterAppInfo(const std::vector<std::string>& code_paths,
472                       const std::string& profile_output_filename);
473
474  // Transaction support.
475  bool IsActiveTransaction() const {
476    return preinitialization_transaction_ != nullptr;
477  }
478  void EnterTransactionMode(Transaction* transaction);
479  void ExitTransactionMode();
480  bool IsTransactionAborted() const;
481
482  void AbortTransactionAndThrowAbortError(Thread* self, const std::string& abort_message)
483      SHARED_REQUIRES(Locks::mutator_lock_);
484  void ThrowTransactionAbortError(Thread* self)
485      SHARED_REQUIRES(Locks::mutator_lock_);
486
487  void RecordWriteFieldBoolean(mirror::Object* obj, MemberOffset field_offset, uint8_t value,
488                               bool is_volatile) const;
489  void RecordWriteFieldByte(mirror::Object* obj, MemberOffset field_offset, int8_t value,
490                            bool is_volatile) const;
491  void RecordWriteFieldChar(mirror::Object* obj, MemberOffset field_offset, uint16_t value,
492                            bool is_volatile) const;
493  void RecordWriteFieldShort(mirror::Object* obj, MemberOffset field_offset, int16_t value,
494                          bool is_volatile) const;
495  void RecordWriteField32(mirror::Object* obj, MemberOffset field_offset, uint32_t value,
496                          bool is_volatile) const;
497  void RecordWriteField64(mirror::Object* obj, MemberOffset field_offset, uint64_t value,
498                          bool is_volatile) const;
499  void RecordWriteFieldReference(mirror::Object* obj, MemberOffset field_offset,
500                                 mirror::Object* value, bool is_volatile) const;
501  void RecordWriteArray(mirror::Array* array, size_t index, uint64_t value) const
502      SHARED_REQUIRES(Locks::mutator_lock_);
503  void RecordStrongStringInsertion(mirror::String* s) const
504      REQUIRES(Locks::intern_table_lock_);
505  void RecordWeakStringInsertion(mirror::String* s) const
506      REQUIRES(Locks::intern_table_lock_);
507  void RecordStrongStringRemoval(mirror::String* s) const
508      REQUIRES(Locks::intern_table_lock_);
509  void RecordWeakStringRemoval(mirror::String* s) const
510      REQUIRES(Locks::intern_table_lock_);
511
512  void SetFaultMessage(const std::string& message) REQUIRES(!fault_message_lock_);
513  // Only read by the signal handler, NO_THREAD_SAFETY_ANALYSIS to prevent lock order violations
514  // with the unexpected_signal_lock_.
515  const std::string& GetFaultMessage() NO_THREAD_SAFETY_ANALYSIS {
516    return fault_message_;
517  }
518
519  void AddCurrentRuntimeFeaturesAsDex2OatArguments(std::vector<std::string>* arg_vector) const;
520
521  bool ExplicitStackOverflowChecks() const {
522    return !implicit_so_checks_;
523  }
524
525  bool IsVerificationEnabled() const;
526  bool IsVerificationSoftFail() const;
527
528  bool IsDexFileFallbackEnabled() const {
529    return allow_dex_file_fallback_;
530  }
531
532  const std::vector<std::string>& GetCpuAbilist() const {
533    return cpu_abilist_;
534  }
535
536  bool IsRunningOnMemoryTool() const {
537    return is_running_on_memory_tool_;
538  }
539
540  void SetTargetSdkVersion(int32_t version) {
541    target_sdk_version_ = version;
542  }
543
544  int32_t GetTargetSdkVersion() const {
545    return target_sdk_version_;
546  }
547
548  uint32_t GetZygoteMaxFailedBoots() const {
549    return zygote_max_failed_boots_;
550  }
551
552  bool AreExperimentalFlagsEnabled(ExperimentalFlags flags) {
553    return (experimental_flags_ & flags) != ExperimentalFlags::kNone;
554  }
555
556  lambda::BoxTable* GetLambdaBoxTable() const {
557    return lambda_box_table_.get();
558  }
559
560  // Create the JIT and instrumentation and code cache.
561  void CreateJit();
562
563  ArenaPool* GetArenaPool() {
564    return arena_pool_.get();
565  }
566  const ArenaPool* GetArenaPool() const {
567    return arena_pool_.get();
568  }
569  LinearAlloc* GetLinearAlloc() {
570    return linear_alloc_.get();
571  }
572
573  jit::JitOptions* GetJITOptions() {
574    return jit_options_.get();
575  }
576
577  MethodRefToStringInitRegMap& GetStringInitMap() {
578    return method_ref_string_init_reg_map_;
579  }
580
581  bool IsDebuggable() const;
582
583  // Returns the build fingerprint, if set. Otherwise an empty string is returned.
584  std::string GetFingerprint() {
585    return fingerprint_;
586  }
587
588  // Called from class linker.
589  void SetSentinel(mirror::Object* sentinel) SHARED_REQUIRES(Locks::mutator_lock_);
590
591  // Create a normal LinearAlloc or low 4gb version if we are 64 bit AOT compiler.
592  LinearAlloc* CreateLinearAlloc();
593
594  OatFileManager& GetOatFileManager() const {
595    DCHECK(oat_file_manager_ != nullptr);
596    return *oat_file_manager_;
597  }
598
599  double GetHashTableMinLoadFactor() const;
600  double GetHashTableMaxLoadFactor() const;
601
602  void SetSafeMode(bool mode) {
603    safe_mode_ = mode;
604  }
605
606 private:
607  static void InitPlatformSignalHandlers();
608
609  Runtime();
610
611  void BlockSignals();
612
613  bool Init(RuntimeArgumentMap&& runtime_options)
614      SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_);
615  void InitNativeMethods() REQUIRES(!Locks::mutator_lock_);
616  void InitThreadGroups(Thread* self);
617  void RegisterRuntimeNativeMethods(JNIEnv* env);
618
619  void StartDaemonThreads();
620  void StartSignalCatcher();
621
622  void MaybeSaveJitProfilingInfo();
623
624  // A pointer to the active runtime or null.
625  static Runtime* instance_;
626
627  // NOTE: these must match the gc::ProcessState values as they come directly from the framework.
628  static constexpr int kProfileForground = 0;
629  static constexpr int kProfileBackground = 1;
630
631  // 64 bit so that we can share the same asm offsets for both 32 and 64 bits.
632  uint64_t callee_save_methods_[kLastCalleeSaveType];
633  GcRoot<mirror::Throwable> pre_allocated_OutOfMemoryError_;
634  GcRoot<mirror::Throwable> pre_allocated_NoClassDefFoundError_;
635  ArtMethod* resolution_method_;
636  ArtMethod* imt_conflict_method_;
637  // Unresolved method has the same behavior as the conflict method, it is used by the class linker
638  // for differentiating between unfilled imt slots vs conflict slots in superclasses.
639  ArtMethod* imt_unimplemented_method_;
640
641  // Special sentinel object used to invalid conditions in JNI (cleared weak references) and
642  // JDWP (invalid references).
643  GcRoot<mirror::Object> sentinel_;
644
645  InstructionSet instruction_set_;
646  QuickMethodFrameInfo callee_save_method_frame_infos_[kLastCalleeSaveType];
647
648  CompilerCallbacks* compiler_callbacks_;
649  bool is_zygote_;
650  bool must_relocate_;
651  bool is_concurrent_gc_enabled_;
652  bool is_explicit_gc_disabled_;
653  bool dex2oat_enabled_;
654  bool image_dex2oat_enabled_;
655
656  std::string compiler_executable_;
657  std::string patchoat_executable_;
658  std::vector<std::string> compiler_options_;
659  std::vector<std::string> image_compiler_options_;
660  std::string image_location_;
661
662  std::string boot_class_path_string_;
663  std::string class_path_string_;
664  std::vector<std::string> properties_;
665
666  // The default stack size for managed threads created by the runtime.
667  size_t default_stack_size_;
668
669  gc::Heap* heap_;
670
671  std::unique_ptr<ArenaPool> arena_pool_;
672  // Special low 4gb pool for compiler linear alloc. We need ArtFields to be in low 4gb if we are
673  // compiling using a 32 bit image on a 64 bit compiler in case we resolve things in the image
674  // since the field arrays are int arrays in this case.
675  std::unique_ptr<ArenaPool> low_4gb_arena_pool_;
676
677  // Shared linear alloc for now.
678  std::unique_ptr<LinearAlloc> linear_alloc_;
679
680  // The number of spins that are done before thread suspension is used to forcibly inflate.
681  size_t max_spins_before_thin_lock_inflation_;
682  MonitorList* monitor_list_;
683  MonitorPool* monitor_pool_;
684
685  ThreadList* thread_list_;
686
687  InternTable* intern_table_;
688
689  ClassLinker* class_linker_;
690
691  SignalCatcher* signal_catcher_;
692  std::string stack_trace_file_;
693
694  JavaVMExt* java_vm_;
695
696  std::unique_ptr<jit::Jit> jit_;
697  std::unique_ptr<jit::JitOptions> jit_options_;
698
699  std::unique_ptr<lambda::BoxTable> lambda_box_table_;
700
701  // Fault message, printed when we get a SIGSEGV.
702  Mutex fault_message_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
703  std::string fault_message_ GUARDED_BY(fault_message_lock_);
704
705  // A non-zero value indicates that a thread has been created but not yet initialized. Guarded by
706  // the shutdown lock so that threads aren't born while we're shutting down.
707  size_t threads_being_born_ GUARDED_BY(Locks::runtime_shutdown_lock_);
708
709  // Waited upon until no threads are being born.
710  std::unique_ptr<ConditionVariable> shutdown_cond_ GUARDED_BY(Locks::runtime_shutdown_lock_);
711
712  // Set when runtime shutdown is past the point that new threads may attach.
713  bool shutting_down_ GUARDED_BY(Locks::runtime_shutdown_lock_);
714
715  // The runtime is starting to shutdown but is blocked waiting on shutdown_cond_.
716  bool shutting_down_started_ GUARDED_BY(Locks::runtime_shutdown_lock_);
717
718  bool started_;
719
720  // New flag added which tells us if the runtime has finished starting. If
721  // this flag is set then the Daemon threads are created and the class loader
722  // is created. This flag is needed for knowing if its safe to request CMS.
723  bool finished_starting_;
724
725  // Hooks supported by JNI_CreateJavaVM
726  jint (*vfprintf_)(FILE* stream, const char* format, va_list ap);
727  void (*exit_)(jint status);
728  void (*abort_)();
729
730  bool stats_enabled_;
731  RuntimeStats stats_;
732
733  const bool is_running_on_memory_tool_;
734
735  std::string profile_output_filename_;
736  ProfilerOptions profiler_options_;
737
738  std::unique_ptr<TraceConfig> trace_config_;
739
740  instrumentation::Instrumentation instrumentation_;
741
742  jobject main_thread_group_;
743  jobject system_thread_group_;
744
745  // As returned by ClassLoader.getSystemClassLoader().
746  jobject system_class_loader_;
747
748  // If true, then we dump the GC cumulative timings on shutdown.
749  bool dump_gc_performance_on_shutdown_;
750
751  // Transaction used for pre-initializing classes at compilation time.
752  Transaction* preinitialization_transaction_;
753
754  // If kNone, verification is disabled. kEnable by default.
755  verifier::VerifyMode verify_;
756
757  // If true, the runtime may use dex files directly with the interpreter if an oat file is not
758  // available/usable.
759  bool allow_dex_file_fallback_;
760
761  // List of supported cpu abis.
762  std::vector<std::string> cpu_abilist_;
763
764  // Specifies target SDK version to allow workarounds for certain API levels.
765  int32_t target_sdk_version_;
766
767  // Implicit checks flags.
768  bool implicit_null_checks_;       // NullPointer checks are implicit.
769  bool implicit_so_checks_;         // StackOverflow checks are implicit.
770  bool implicit_suspend_checks_;    // Thread suspension checks are implicit.
771
772  // Whether or not the sig chain (and implicitly the fault handler) should be
773  // disabled. Tools like dex2oat or patchoat don't need them. This enables
774  // building a statically link version of dex2oat.
775  bool no_sig_chain_;
776
777  // Whether or not a native bridge has been loaded.
778  //
779  // The native bridge allows running native code compiled for a foreign ISA. The way it works is,
780  // if standard dlopen fails to load native library associated with native activity, it calls to
781  // the native bridge to load it and then gets the trampoline for the entry to native activity.
782  //
783  // The option 'native_bridge_library_filename' specifies the name of the native bridge.
784  // When non-empty the native bridge will be loaded from the given file. An empty value means
785  // that there's no native bridge.
786  bool is_native_bridge_loaded_;
787
788  // The maximum number of failed boots we allow before pruning the dalvik cache
789  // and trying again. This option is only inspected when we're running as a
790  // zygote.
791  uint32_t zygote_max_failed_boots_;
792
793  // Enable experimental opcodes that aren't fully specified yet. The intent is to
794  // eventually publish them as public-usable opcodes, but they aren't ready yet.
795  //
796  // Experimental opcodes should not be used by other production code.
797  ExperimentalFlags experimental_flags_;
798
799  MethodRefToStringInitRegMap method_ref_string_init_reg_map_;
800
801  // Contains the build fingerprint, if given as a parameter.
802  std::string fingerprint_;
803
804  // Oat file manager, keeps track of what oat files are open.
805  OatFileManager* oat_file_manager_;
806
807  // Whether or not we are on a low RAM device.
808  bool is_low_memory_mode_;
809
810  // Whether the application should run in safe mode, that is, interpreter only.
811  bool safe_mode_;
812
813  DISALLOW_COPY_AND_ASSIGN(Runtime);
814};
815std::ostream& operator<<(std::ostream& os, const Runtime::CalleeSaveType& rhs);
816
817}  // namespace art
818
819#endif  // ART_RUNTIME_RUNTIME_H_
820