runtime.h revision 0de9f73afe3e835b63f2ee0c1416930656449f3f
12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/*
22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2011 The Android Open Source Project
32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License.
62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at
72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software
112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and
142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License.
152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */
167b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro
17fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#ifndef ART_RUNTIME_RUNTIME_H_
18fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#define ART_RUNTIME_RUNTIME_H_
196b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapiro
20a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes#include <jni.h>
21c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughes#include <stdio.h>
22c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughes
23e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes#include <iosfwd>
246ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom#include <string>
25fc322c72d7a89a6f7a05c8bdc232d780aecd9232Carl Shapiro#include <utility>
266ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom#include <vector>
27578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom
28761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes#include "base/macros.h"
29e222ee0b794f941af4fb1b32fb8224e32942ea7bElliott Hughes#include "base/stringpiece.h"
300de9f73afe3e835b63f2ee0c1416930656449f3fMathieu Chartier#include "gc/collector_type.h"
311d54e73444e017d3a65234e0f193846f3e27472bIan Rogers#include "gc/heap.h"
32a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes#include "globals.h"
330f3c55331439970e01af67f80ac117c473bc04cfElliott Hughes#include "instruction_set.h"
3462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers#include "instrumentation.h"
3500f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers#include "jobject_comparator.h"
36120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers#include "locks.h"
372dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "root_visitor.h"
389d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes#include "runtime_stats.h"
39a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes#include "safe_map.h"
40b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro
416b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapironamespace art {
427b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro
431d54e73444e017d3a65234e0f193846f3e27472bIan Rogersnamespace gc {
441d54e73444e017d3a65234e0f193846f3e27472bIan Rogers  class Heap;
451d54e73444e017d3a65234e0f193846f3e27472bIan Rogers}
462dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogersnamespace mirror {
47ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  class ArtMethod;
481d54e73444e017d3a65234e0f193846f3e27472bIan Rogers  class ClassLoader;
4988474b416eb257078e590bf9bc7957cee604a186Jeff Hao  template<class T> class ObjectArray;
501d54e73444e017d3a65234e0f193846f3e27472bIan Rogers  template<class T> class PrimitiveArray;
511d54e73444e017d3a65234e0f193846f3e27472bIan Rogers  typedef PrimitiveArray<int8_t> ByteArray;
521d54e73444e017d3a65234e0f193846f3e27472bIan Rogers  class String;
531d54e73444e017d3a65234e0f193846f3e27472bIan Rogers  class Throwable;
542dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers}  // namespace mirror
5561e019d291583029c01b61b93bea750f2b663c37Carl Shapiroclass ClassLinker;
56fc322c72d7a89a6f7a05c8bdc232d780aecd9232Carl Shapiroclass DexFile;
57cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughesclass InternTable;
581b09b094a85e03f6ef5f687f58bb91c433273ba1Ian Rogersstruct JavaVMExt;
59c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughesclass MonitorList;
60e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughesclass SignalCatcher;
6161e019d291583029c01b61b93bea750f2b663c37Carl Shapiroclass ThreadList;
622692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhaoclass Trace;
6361e019d291583029c01b61b93bea750f2b663c37Carl Shapiro
641fb8620309a4e94d11879aabc33364acfa733904Carl Shapiroclass Runtime {
657b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro public:
66f1a5adc87760f938b01df26d906295063546b259Elliott Hughes  typedef std::vector<std::pair<std::string, const void*> > Options;
678a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom
68a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  enum CompilerFilter {
69a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    kInterpretOnly,       // Compile nothing.
70a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    kSpace,               // Maximize space savings.
71a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    kBalanced,            // Try to get the best performance return on compilation investment.
72fe9ca4028f379688ecba6132ac3738171176b3e4buzbee    kSpeed,               // Maximize runtime performance.
73fe9ca4028f379688ecba6132ac3738171176b3e4buzbee    kEverything           // Force compilation (Note: excludes compilaton of class initializers).
74a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  };
75c44f68fb6a6d55c0df28dd05b93d8906ec20bd08Anwar Ghuloum
76a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  // Guide heuristics to determine whether to compile method if profile data not available.
77a024a0686c3b0fea13f362bff70d65981e5febc5buzbee#if ART_SMALL_MODE
78a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  static const CompilerFilter kDefaultCompilerFilter = kInterpretOnly;
79a024a0686c3b0fea13f362bff70d65981e5febc5buzbee#else
80a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  static const CompilerFilter kDefaultCompilerFilter = kSpeed;
81a024a0686c3b0fea13f362bff70d65981e5febc5buzbee#endif
82fe9ca4028f379688ecba6132ac3738171176b3e4buzbee  static const size_t kDefaultHugeMethodThreshold = 10000;
83fe9ca4028f379688ecba6132ac3738171176b3e4buzbee  static const size_t kDefaultLargeMethodThreshold = 600;
84fe9ca4028f379688ecba6132ac3738171176b3e4buzbee  static const size_t kDefaultSmallMethodThreshold = 60;
85fe9ca4028f379688ecba6132ac3738171176b3e4buzbee  static const size_t kDefaultTinyMethodThreshold = 20;
86a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  static const size_t kDefaultNumDexMethodsThreshold = 900;
878447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum
888a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom  class ParsedOptions {
898a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom   public:
906ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom    // returns null if problem parsing and ignore_unrecognized is false
916ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom    static ParsedOptions* Create(const Options& options, bool ignore_unrecognized);
928a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom
93a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom    const std::vector<const DexFile*>* boot_class_path_;
94a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom    std::string boot_class_path_string_;
95a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom    std::string class_path_string_;
9658ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom    std::string host_prefix_;
97223f20fa939c386c695977263780dea2195093dbBrian Carlstrom    std::string image_;
98515a5bc89282d6f910cae4d5852bb77124a47825Elliott Hughes    bool check_jni_;
99a09576416788b916095739e43a16917e7948f3a4Elliott Hughes    std::string jni_trace_;
100d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes    bool is_compiler_;
1019ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes    bool is_zygote_;
10250ffee20ced9c0c7ac68889c86be8844cf120cf2Ian Rogers    bool interpreter_only_;
1038718359763aa3dcd0033a2d2e67e0cb145fb9c53Anwar Ghuloum    bool is_explicit_gc_disabled_;
1042775ee4f82dff260663ca16adddc0b15327aaa42Mathieu Chartier    size_t long_pause_log_threshold_;
1052775ee4f82dff260663ca16adddc0b15327aaa42Mathieu Chartier    size_t long_gc_log_threshold_;
106ff3b24aa929a9db79daeef7c0b0522da099700a9Mathieu Chartier    bool dump_gc_performance_on_shutdown_;
1072775ee4f82dff260663ca16adddc0b15327aaa42Mathieu Chartier    bool ignore_max_footprint_;
1088a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom    size_t heap_initial_size_;
1098a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom    size_t heap_maximum_size_;
110c11607024d2e7a52ca690b8339306cab040e6653jeffhao    size_t heap_growth_limit_;
1110051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier    size_t heap_min_free_;
1120051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier    size_t heap_max_free_;
1130051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier    double heap_target_utilization_;
1142775ee4f82dff260663ca16adddc0b15327aaa42Mathieu Chartier    size_t parallel_gc_threads_;
1152775ee4f82dff260663ca16adddc0b15327aaa42Mathieu Chartier    size_t conc_gc_threads_;
1160de9f73afe3e835b63f2ee0c1416930656449f3fMathieu Chartier    gc::CollectorType collector_type_;
117f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom    size_t stack_size_;
118d9c4fc94fa618617f94e1de9af5f034549100753Ian Rogers    size_t max_spins_before_thin_lock_inflation_;
119e0a53e99e2a01f8668d6616c3cec7e2f5a711286Mathieu Chartier    bool low_memory_mode_;
120bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes    size_t lock_profiling_threshold_;
12194ce37a3919a0bdb8855a3d3264a50df1dbc41beElliott Hughes    std::string stack_trace_file_;
122b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao    bool method_trace_;
123b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao    std::string method_trace_file_;
124b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao    size_t method_trace_file_size_;
125fc86162ce2a3467acb690e18cc8bd9b3daafc606Elliott Hughes    bool (*hook_is_sensitive_thread_)();
1266ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom    jint (*hook_vfprintf_)(FILE* stream, const char* format, va_list ap);
1276ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom    void (*hook_exit_)(jint status);
1286ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom    void (*hook_abort_)();
1296ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom    std::vector<std::string> properties_;
130a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    CompilerFilter compiler_filter_;
131a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    size_t huge_method_threshold_;
132a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    size_t large_method_threshold_;
133a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    size_t small_method_threshold_;
134a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    size_t tiny_method_threshold_;
135a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    size_t num_dex_methods_threshold_;
1367467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea    bool sea_ir_mode_;
1377467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea
1386ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom   private:
1390cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers    ParsedOptions() {}
1408a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom  };
1412ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro
14261e019d291583029c01b61b93bea750f2b663c37Carl Shapiro  // Creates and initializes a new runtime.
14300f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  static bool Create(const Options& options, bool ignore_unrecognized)
144b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_);
14569b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom
146d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes  bool IsCompiler() const {
147d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes    return is_compiler_;
148d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes  }
149d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes
150caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom  bool IsZygote() const {
151caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom    return is_zygote_;
152caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom  }
153caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom
1548718359763aa3dcd0033a2d2e67e0cb145fb9c53Anwar Ghuloum  bool IsExplicitGcDisabled() const {
1558718359763aa3dcd0033a2d2e67e0cb145fb9c53Anwar Ghuloum    return is_explicit_gc_disabled_;
1568718359763aa3dcd0033a2d2e67e0cb145fb9c53Anwar Ghuloum  }
1578718359763aa3dcd0033a2d2e67e0cb145fb9c53Anwar Ghuloum
15851c2467e8771b56e25ae4f17f66522f979f57a7eBrian Carlstrom#ifdef ART_SEA_IR_MODE
1597467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea  bool IsSeaIRMode() const {
1607467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea    return sea_ir_mode_;
1617467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea  }
16251c2467e8771b56e25ae4f17f66522f979f57a7eBrian Carlstrom#endif
1637467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea
1647467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea  void SetSeaIRMode(bool sea_ir_mode) {
1657467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea    sea_ir_mode_ = sea_ir_mode;
1667467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea  }
1677467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea
168a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  CompilerFilter GetCompilerFilter() const {
169a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    return compiler_filter_;
1708447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum  }
1718447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum
172a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  void SetCompilerFilter(CompilerFilter compiler_filter) {
173a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    compiler_filter_ = compiler_filter;
174a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  }
175a024a0686c3b0fea13f362bff70d65981e5febc5buzbee
176a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  size_t GetHugeMethodThreshold() const {
177a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    return huge_method_threshold_;
178a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  }
179a024a0686c3b0fea13f362bff70d65981e5febc5buzbee
180a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  size_t GetLargeMethodThreshold() const {
181a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    return large_method_threshold_;
182a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  }
1838447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum
184a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  size_t GetSmallMethodThreshold() const {
185a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    return small_method_threshold_;
1868447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum  }
1878447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum
188a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  size_t GetTinyMethodThreshold() const {
189a024a0686c3b0fea13f362bff70d65981e5febc5buzbee    return tiny_method_threshold_;
1908447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum  }
1918447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum
192a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  size_t GetNumDexMethodsThreshold() const {
193a024a0686c3b0fea13f362bff70d65981e5febc5buzbee      return num_dex_methods_threshold_;
1948447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum  }
1958447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum
19658ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  const std::string& GetHostPrefix() const {
197307f75d6bcf7c32db7e1b43124dead628cc7ce96Elliott Hughes    DCHECK(!IsStarted());
19858ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom    return host_prefix_;
19958ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  }
20058ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom
20169b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom  // Starts a runtime, which may cause threads to be started and code to run.
202bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom  bool Start() UNLOCK_FUNCTION(Locks::mutator_lock_);
2032ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro
204590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier  bool IsShuttingDown(Thread* self);
205590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier  bool IsShuttingDownLocked() const EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_) {
2069af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return shutting_down_;
2079af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
2089af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
209120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  size_t NumberOfThreadsBeingBorn() const EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_) {
210120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers    return threads_being_born_;
211120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  }
212120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
213120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  void StartThreadBirth() EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_) {
214120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers    threads_being_born_++;
215120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  }
216120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
217120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  void EndThreadBirth() EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_);
218120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
2199af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  bool IsStarted() const {
2209af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return started_;
2219af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
222dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes
2237664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier  bool IsFinishedStarting() const {
2247664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier    return finished_starting_;
2257664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier  }
2267664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier
2272ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro  static Runtime* Current() {
2282ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro    return instance_;
2292ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro  }
23061e019d291583029c01b61b93bea750f2b663c37Carl Shapiro
231ffe6736397d17457188727510f0a2953f69a383aElliott Hughes  // Aborts semi-cleanly. Used in the implementation of LOG(FATAL), which most
232ffe6736397d17457188727510f0a2953f69a383aElliott Hughes  // callers should prefer.
233ffe6736397d17457188727510f0a2953f69a383aElliott Hughes  // This isn't marked ((noreturn)) because then gcc will merge multiple calls
234ffe6736397d17457188727510f0a2953f69a383aElliott Hughes  // in a single function together. This reduces code size slightly, but means
235ffe6736397d17457188727510f0a2953f69a383aElliott Hughes  // that the native stack trace we get may point at the wrong call site.
236b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers  static void Abort() LOCKS_EXCLUDED(Locks::abort_lock_);
237ffe6736397d17457188727510f0a2953f69a383aElliott Hughes
238365c10235438607541fa2259a5fec48061b90bd8Ian Rogers  // Returns the "main" ThreadGroup, used when attaching user threads.
239034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom  jobject GetMainThreadGroup() const;
240365c10235438607541fa2259a5fec48061b90bd8Ian Rogers
241365c10235438607541fa2259a5fec48061b90bd8Ian Rogers  // Returns the "system" ThreadGroup, used when attaching our internal threads.
242034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom  jobject GetSystemThreadGroup() const;
243365c10235438607541fa2259a5fec48061b90bd8Ian Rogers
244ce88853ab316c70ef7b598978a3609611db60552Brian Carlstrom  // Returns the system ClassLoader which represents the CLASSPATH.
245ce88853ab316c70ef7b598978a3609611db60552Brian Carlstrom  jobject GetSystemClassLoader() const;
246ce88853ab316c70ef7b598978a3609611db60552Brian Carlstrom
247462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes  // Attaches the calling native thread to the runtime.
248664bebf92eb2151b9b570ccd42ac4b6056c3ea9cMathieu Chartier  bool AttachCurrentThread(const char* thread_name, bool as_daemon, jobject thread_group,
249664bebf92eb2151b9b570ccd42ac4b6056c3ea9cMathieu Chartier                           bool create_peer);
250b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro
251bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes  void CallExitHook(jint status);
252bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes
25361e019d291583029c01b61b93bea750f2b663c37Carl Shapiro  // Detaches the current native thread from the runtime.
254b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers  void DetachCurrentThread() LOCKS_EXCLUDED(Locks::mutator_lock_);
25561e019d291583029c01b61b93bea750f2b663c37Carl Shapiro
25600f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  void DumpForSigQuit(std::ostream& os)
257b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
25821a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughes  void DumpLockHolders(std::ostream& os);
259e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes
26061e019d291583029c01b61b93bea750f2b663c37Carl Shapiro  ~Runtime();
261b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro
262a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom  const std::string& GetBootClassPathString() const {
263a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom    return boot_class_path_string_;
264b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom  }
265b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom
266a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom  const std::string& GetClassPathString() const {
267a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom    return class_path_string_;
2687a90959d4ef7a69f3bcb7b8763f646e12d9267d3Carl Shapiro  }
2697a90959d4ef7a69f3bcb7b8763f646e12d9267d3Carl Shapiro
270a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom  ClassLinker* GetClassLinker() const {
271a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom    return class_linker_;
2727ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes  }
2737ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes
2747ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes  size_t GetDefaultStackSize() const {
2757ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes    return default_stack_size_;
2767ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes  }
2777ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes
2781d54e73444e017d3a65234e0f193846f3e27472bIan Rogers  gc::Heap* GetHeap() const {
279b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes    return heap_;
280b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  }
281b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes
282cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes  InternTable* GetInternTable() const {
283e810452722ac83b294d1f7aa80bdd88e547d5af0Brian Carlstrom    DCHECK(intern_table_ != NULL);
284cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes    return intern_table_;
285cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes  }
286cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes
2870af5543f8ea20c3e655b2d748a1b7dcf283792feElliott Hughes  JavaVMExt* GetJavaVM() const {
288c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughes    return java_vm_;
289f2682d5a6ce0f7de58da8fd4ec8aec200c43b92eElliott Hughes  }
290f2682d5a6ce0f7de58da8fd4ec8aec200c43b92eElliott Hughes
291d9c4fc94fa618617f94e1de9af5f034549100753Ian Rogers  size_t GetMaxSpinsBeforeThinkLockInflation() const {
292d9c4fc94fa618617f94e1de9af5f034549100753Ian Rogers    return max_spins_before_thin_lock_inflation_;
293d9c4fc94fa618617f94e1de9af5f034549100753Ian Rogers  }
294d9c4fc94fa618617f94e1de9af5f034549100753Ian Rogers
295c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes  MonitorList* GetMonitorList() const {
296c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes    return monitor_list_;
297c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes  }
298c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes
299a436fde2762664a3ecdda5eefcadd20b2e104f59Ian Rogers  mirror::Throwable* GetPreAllocatedOutOfMemoryError() const
300a436fde2762664a3ecdda5eefcadd20b2e104f59Ian Rogers    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
301225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes
302225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes  const std::vector<std::string>& GetProperties() const {
303225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes    return properties_;
304225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes  }
305225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes
306d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes  ThreadList* GetThreadList() const {
307d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes    return thread_list_;
308d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes  }
309d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes
3107ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes  const char* GetVersion() const {
3117ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes    return "2.0.0";
3127ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes  }
3137ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes
314c11d9b8870de5f860b13c84003ade7b3f3125a52Mathieu Chartier  void DisallowNewSystemWeaks() EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
315c11d9b8870de5f860b13c84003ade7b3f3125a52Mathieu Chartier  void AllowNewSystemWeaks() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
316c11d9b8870de5f860b13c84003ade7b3f3125a52Mathieu Chartier
3171d54e73444e017d3a65234e0f193846f3e27472bIan Rogers  // Visit all the roots. If only_dirty is true then non-dirty roots won't be visited. If
3181d54e73444e017d3a65234e0f193846f3e27472bIan Rogers  // clean_dirty is true then dirty roots will be marked as non-dirty after visiting.
3191d54e73444e017d3a65234e0f193846f3e27472bIan Rogers  void VisitRoots(RootVisitor* visitor, void* arg, bool only_dirty, bool clean_dirty)
3201d54e73444e017d3a65234e0f193846f3e27472bIan Rogers      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
3211f87008b165d26541d832ff805250afdc89c253dBrian Carlstrom
3229ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier  // Visit all of the roots we can do safely do concurrently.
3231d54e73444e017d3a65234e0f193846f3e27472bIan Rogers  void VisitConcurrentRoots(RootVisitor* visitor, void* arg, bool only_dirty, bool clean_dirty);
3249ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier
325858f1c5fd5e528d0b16040ced74d4636046a42d8Mathieu Chartier  // Visit all of the non thread roots, we can do this with mutators unpaused.
3262dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers  void VisitNonThreadRoots(RootVisitor* visitor, void* arg);
327858f1c5fd5e528d0b16040ced74d4636046a42d8Mathieu Chartier
3289ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier  // Visit all other roots which must be done with mutators suspended.
3292dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers  void VisitNonConcurrentRoots(RootVisitor* visitor, void* arg)
3309ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
3319ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier
3326aa3df965395566ed6a4fec4af37c2b7577992e9Mathieu Chartier  // Sweep system weaks, the system weak is deleted if the visitor return nullptr. Otherwise, the
3336aa3df965395566ed6a4fec4af37c2b7577992e9Mathieu Chartier  // system weak is updated to be the visitor's returned value.
334ad2541a59c00c2c69e8973088891a2b5257c9780Mathieu Chartier  void SweepSystemWeaks(RootVisitor* visitor, void* arg)
335ad2541a59c00c2c69e8973088891a2b5257c9780Mathieu Chartier      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
3366aa3df965395566ed6a4fec4af37c2b7577992e9Mathieu Chartier
3379af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  // Returns a special method that calls into a trampoline for runtime method resolution
338ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  mirror::ArtMethod* GetResolutionMethod() const {
3399af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    CHECK(HasResolutionMethod());
3409af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return resolution_method_;
3419af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
3429af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
3439af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  bool HasResolutionMethod() const {
3449af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return resolution_method_ != NULL;
3459af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
3469af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
347ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  void SetResolutionMethod(mirror::ArtMethod* method) {
3489af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    resolution_method_ = method;
3499af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
3509af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
351ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  mirror::ArtMethod* CreateResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
3521984651929744dd603fd082e23eacd877b9bc177Ian Rogers
35388474b416eb257078e590bf9bc7957cee604a186Jeff Hao  // Returns a special method that calls into a trampoline for runtime imt conflicts
35488474b416eb257078e590bf9bc7957cee604a186Jeff Hao  mirror::ArtMethod* GetImtConflictMethod() const {
35588474b416eb257078e590bf9bc7957cee604a186Jeff Hao    CHECK(HasImtConflictMethod());
35688474b416eb257078e590bf9bc7957cee604a186Jeff Hao    return imt_conflict_method_;
35788474b416eb257078e590bf9bc7957cee604a186Jeff Hao  }
35888474b416eb257078e590bf9bc7957cee604a186Jeff Hao
35988474b416eb257078e590bf9bc7957cee604a186Jeff Hao  bool HasImtConflictMethod() const {
36088474b416eb257078e590bf9bc7957cee604a186Jeff Hao    return imt_conflict_method_ != NULL;
36188474b416eb257078e590bf9bc7957cee604a186Jeff Hao  }
36288474b416eb257078e590bf9bc7957cee604a186Jeff Hao
36388474b416eb257078e590bf9bc7957cee604a186Jeff Hao  void SetImtConflictMethod(mirror::ArtMethod* method) {
36488474b416eb257078e590bf9bc7957cee604a186Jeff Hao    imt_conflict_method_ = method;
36588474b416eb257078e590bf9bc7957cee604a186Jeff Hao  }
36688474b416eb257078e590bf9bc7957cee604a186Jeff Hao
36788474b416eb257078e590bf9bc7957cee604a186Jeff Hao  mirror::ArtMethod* CreateImtConflictMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
36888474b416eb257078e590bf9bc7957cee604a186Jeff Hao
36988474b416eb257078e590bf9bc7957cee604a186Jeff Hao  // Returns an imt with every entry set to conflict, used as default imt for all classes.
37088474b416eb257078e590bf9bc7957cee604a186Jeff Hao  mirror::ObjectArray<mirror::ArtMethod>* GetDefaultImt() const {
37188474b416eb257078e590bf9bc7957cee604a186Jeff Hao    CHECK(HasDefaultImt());
37288474b416eb257078e590bf9bc7957cee604a186Jeff Hao    return default_imt_;
37388474b416eb257078e590bf9bc7957cee604a186Jeff Hao  }
37488474b416eb257078e590bf9bc7957cee604a186Jeff Hao
37588474b416eb257078e590bf9bc7957cee604a186Jeff Hao  bool HasDefaultImt() const {
37688474b416eb257078e590bf9bc7957cee604a186Jeff Hao    return default_imt_ != NULL;
37788474b416eb257078e590bf9bc7957cee604a186Jeff Hao  }
37888474b416eb257078e590bf9bc7957cee604a186Jeff Hao
37988474b416eb257078e590bf9bc7957cee604a186Jeff Hao  void SetDefaultImt(mirror::ObjectArray<mirror::ArtMethod>* imt) {
38088474b416eb257078e590bf9bc7957cee604a186Jeff Hao    default_imt_ = imt;
38188474b416eb257078e590bf9bc7957cee604a186Jeff Hao  }
38288474b416eb257078e590bf9bc7957cee604a186Jeff Hao
38388474b416eb257078e590bf9bc7957cee604a186Jeff Hao  mirror::ObjectArray<mirror::ArtMethod>* CreateDefaultImt(ClassLinker* cl)
38488474b416eb257078e590bf9bc7957cee604a186Jeff Hao      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
38588474b416eb257078e590bf9bc7957cee604a186Jeff Hao
386ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers  // Returns a special method that describes all callee saves being spilled to the stack.
3874f0d07c783afef89703dce32c94440fc8621a29bIan Rogers  enum CalleeSaveType {
3884f0d07c783afef89703dce32c94440fc8621a29bIan Rogers    kSaveAll,
3894f0d07c783afef89703dce32c94440fc8621a29bIan Rogers    kRefsOnly,
3904f0d07c783afef89703dce32c94440fc8621a29bIan Rogers    kRefsAndArgs,
3914f0d07c783afef89703dce32c94440fc8621a29bIan Rogers    kLastCalleeSaveType  // Value used for iteration
3924f0d07c783afef89703dce32c94440fc8621a29bIan Rogers  };
3939af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
3949af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  bool HasCalleeSaveMethod(CalleeSaveType type) const {
395225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes    return callee_save_methods_[type] != NULL;
3969af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
3979af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
398ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  mirror::ArtMethod* GetCalleeSaveMethod(CalleeSaveType type) const {
399df1ce91ba97bc79a0637e5504b39318fb1c9f577Ian Rogers    DCHECK(HasCalleeSaveMethod(type));
400225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes    return callee_save_methods_[type];
4019af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
4029af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
403ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  void SetCalleeSaveMethod(mirror::ArtMethod* method, CalleeSaveType type);
4044f0d07c783afef89703dce32c94440fc8621a29bIan Rogers
405ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  mirror::ArtMethod* CreateCalleeSaveMethod(InstructionSet instruction_set,
4062dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers                                                 CalleeSaveType type)
407b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
4089af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
409ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  mirror::ArtMethod* CreateRefOnlyCalleeSaveMethod(InstructionSet instruction_set)
410b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
41100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers
412ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  mirror::ArtMethod* CreateRefAndArgsCalleeSaveMethod(InstructionSet instruction_set)
413b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
414ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers
4159d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  int32_t GetStat(int kind);
4169d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes
4179af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  RuntimeStats* GetStats() {
4189af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return &stats_;
4199af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
4209d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes
4219d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  bool HasStatsEnabled() const {
4229d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes    return stats_enabled_;
4239d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  }
4249d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes
4259d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  void ResetStats(int kinds);
4269d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes
4279d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  void SetStatsEnabled(bool new_state);
4289d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes
429cc236d74772dda5a4161d9bc5f497fd3d956eb87Mathieu Chartier  bool PreZygoteFork();
430bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom  bool InitZygote();
431bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom  void DidForkFromZygote();
432caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom
43362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  instrumentation::Instrumentation* GetInstrumentation() {
43462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    return &instrumentation_;
43562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
4362692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhao
437b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  bool UseCompileTimeClassPath() const {
438b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes    return use_compile_time_class_path_;
439b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  }
4409af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
44100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  const std::vector<const DexFile*>& GetCompileTimeClassPath(jobject class_loader);
44200f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  void SetCompileTimeClassPath(jobject class_loader, std::vector<const DexFile*>& class_path);
443b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes
444b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro private:
445457005c557b8762475db3220ce5a747d629f975bElliott Hughes  static void InitPlatformSignalHandlers();
446ffe6736397d17457188727510f0a2953f69a383aElliott Hughes
447dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes  Runtime();
44861e019d291583029c01b61b93bea750f2b663c37Carl Shapiro
449c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes  void BlockSignals();
450c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes
45100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  bool Init(const Options& options, bool ignore_unrecognized)
452b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_);
453b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers  void InitNativeMethods() LOCKS_EXCLUDED(Locks::mutator_lock_);
454365c10235438607541fa2259a5fec48061b90bd8Ian Rogers  void InitThreadGroups(Thread* self);
455ff17f1fd3ff32f93e45588eb2b158832d73f9afaElliott Hughes  void RegisterRuntimeNativeMethods(JNIEnv* env);
456d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes
45785d1545e985ac689db4bad7849880e843707c862Elliott Hughes  void StartDaemonThreads();
458d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes  void StartSignalCatcher();
45961e019d291583029c01b61b93bea750f2b663c37Carl Shapiro
460b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  // A pointer to the active runtime or NULL.
461b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  static Runtime* instance_;
462b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes
463d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes  bool is_compiler_;
4649ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes  bool is_zygote_;
465069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier  bool is_concurrent_gc_enabled_;
4668718359763aa3dcd0033a2d2e67e0cb145fb9c53Anwar Ghuloum  bool is_explicit_gc_disabled_;
4670a5b14de5115f51e0ed2dd6c3fcc5b84bbce690eBrian Carlstrom
468a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  CompilerFilter compiler_filter_;
469a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  size_t huge_method_threshold_;
470a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  size_t large_method_threshold_;
471a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  size_t small_method_threshold_;
472a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  size_t tiny_method_threshold_;
473a024a0686c3b0fea13f362bff70d65981e5febc5buzbee  size_t num_dex_methods_threshold_;
4748447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum
4757467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea  bool sea_ir_mode_;
4767467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea
47758ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // The host prefix is used during cross compilation. It is removed
47858ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // from the start of host paths such as:
47929e7ac74a3f9aec192099fec381baadaa55730adBrian Carlstrom  //    $ANDROID_PRODUCT_OUT/system/framework/boot.oat
48034f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom  // to produce target paths such as
48147a0d5a6f221066c3daf7f67f2122ed9c9cd217cBrian Carlstrom  //    /system/framework/boot.oat
48258ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // Similarly it is prepended to target paths to arrive back at a
48358ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // host past. In both cases this is necessary because image and oat
48458ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // files embedded expect paths of dependent files (an image points
48558ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // to an oat file and an oat files to one or more dex files). These
48658ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // files contain the expected target path.
48758ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  std::string host_prefix_;
48858ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom
489a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom  std::string boot_class_path_string_;
490a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom  std::string class_path_string_;
4917ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes  std::vector<std::string> properties_;
4927ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes
493b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom  // The default stack size for managed threads created by the runtime.
494be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes  size_t default_stack_size_;
495b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom
4961d54e73444e017d3a65234e0f193846f3e27472bIan Rogers  gc::Heap* heap_;
497b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes
498d9c4fc94fa618617f94e1de9af5f034549100753Ian Rogers  // The number of spins that are done before thread suspension is used to forcibly inflate.
499d9c4fc94fa618617f94e1de9af5f034549100753Ian Rogers  size_t max_spins_before_thin_lock_inflation_;
500c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes  MonitorList* monitor_list_;
501c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes
502b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro  ThreadList* thread_list_;
50361e019d291583029c01b61b93bea750f2b663c37Carl Shapiro
504cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes  InternTable* intern_table_;
505cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes
506b0460eaa2cb131f1dbdd5a7217bd36b9a9f1b995Brian Carlstrom  ClassLinker* class_linker_;
507b0460eaa2cb131f1dbdd5a7217bd36b9a9f1b995Brian Carlstrom
508e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes  SignalCatcher* signal_catcher_;
50994ce37a3919a0bdb8855a3d3264a50df1dbc41beElliott Hughes  std::string stack_trace_file_;
510e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes
511c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughes  JavaVMExt* java_vm_;
512f2682d5a6ce0f7de58da8fd4ec8aec200c43b92eElliott Hughes
5132dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers  mirror::Throwable* pre_allocated_OutOfMemoryError_;
514225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes
515ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  mirror::ArtMethod* callee_save_methods_[kLastCalleeSaveType];
516ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers
517ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  mirror::ArtMethod* resolution_method_;
5181984651929744dd603fd082e23eacd877b9bc177Ian Rogers
51988474b416eb257078e590bf9bc7957cee604a186Jeff Hao  mirror::ArtMethod* imt_conflict_method_;
52088474b416eb257078e590bf9bc7957cee604a186Jeff Hao
52188474b416eb257078e590bf9bc7957cee604a186Jeff Hao  mirror::ObjectArray<mirror::ArtMethod>* default_imt_;
52288474b416eb257078e590bf9bc7957cee604a186Jeff Hao
523120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  // A non-zero value indicates that a thread has been created but not yet initialized. Guarded by
524120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  // the shutdown lock so that threads aren't born while we're shutting down.
525120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  size_t threads_being_born_ GUARDED_BY(Locks::runtime_shutdown_lock_);
526120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
527120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  // Waited upon until no threads are being born.
528120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  UniquePtr<ConditionVariable> shutdown_cond_ GUARDED_BY(Locks::runtime_shutdown_lock_);
529120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
530120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  // Set when runtime shutdown is past the point that new threads may attach.
531120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  bool shutting_down_ GUARDED_BY(Locks::runtime_shutdown_lock_);
532120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
533120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  // The runtime is starting to shutdown but is blocked waiting on shutdown_cond_.
534120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  bool shutting_down_started_ GUARDED_BY(Locks::runtime_shutdown_lock_);
535120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
536dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes  bool started_;
537dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes
5387664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier  // New flag added which tells us if the runtime has finished starting. If
5397664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier  // this flag is set then the Daemon threads are created and the class loader
5407664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier  // is created. This flag is needed for knowing if its safe to request CMS.
5417664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier  bool finished_starting_;
5427664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier
5436ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom  // Hooks supported by JNI_CreateJavaVM
5446ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom  jint (*vfprintf_)(FILE* stream, const char* format, va_list ap);
5456ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom  void (*exit_)(jint status);
5466ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom  void (*abort_)();
5476ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom
5489d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  bool stats_enabled_;
5499d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  RuntimeStats stats_;
5509d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes
551b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao  bool method_trace_;
552b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao  std::string method_trace_file_;
553b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao  size_t method_trace_file_size_;
55462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  instrumentation::Instrumentation instrumentation_;
5552692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhao
55600f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  typedef SafeMap<jobject, std::vector<const DexFile*>, JobjectComparator> CompileTimeClassPaths;
557b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  CompileTimeClassPaths compile_time_class_paths_;
558b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  bool use_compile_time_class_path_;
559131aef8c94292cc530da2fd91ee98d1432352959Elliott Hughes
560365c10235438607541fa2259a5fec48061b90bd8Ian Rogers  jobject main_thread_group_;
561365c10235438607541fa2259a5fec48061b90bd8Ian Rogers  jobject system_thread_group_;
562365c10235438607541fa2259a5fec48061b90bd8Ian Rogers
563ce88853ab316c70ef7b598978a3609611db60552Brian Carlstrom  // As returned by ClassLoader.getSystemClassLoader().
564ce88853ab316c70ef7b598978a3609611db60552Brian Carlstrom  jobject system_class_loader_;
565ce88853ab316c70ef7b598978a3609611db60552Brian Carlstrom
5662e899a92439dc6bdaaa67b8230933006284aa600Hiroshi Yamauchi  // If true, then we dump the GC cumulative timings on shutdown.
5672e899a92439dc6bdaaa67b8230933006284aa600Hiroshi Yamauchi  bool dump_gc_performance_on_shutdown_;
5682e899a92439dc6bdaaa67b8230933006284aa600Hiroshi Yamauchi
56961e019d291583029c01b61b93bea750f2b663c37Carl Shapiro  DISALLOW_COPY_AND_ASSIGN(Runtime);
5707b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro};
5717b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro
5726b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapiro}  // namespace art
5737b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro
574fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif  // ART_RUNTIME_RUNTIME_H_
575