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