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