runtime.h revision df1ce91ba97bc79a0637e5504b39318fb1c9f577
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
171fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro#ifndef ART_SRC_RUNTIME_H_
181fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro#define ART_SRC_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
28a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes#include "globals.h"
291f87008b165d26541d832ff805250afdc89c253dBrian Carlstrom#include "heap.h"
300f3c55331439970e01af67f80ac117c473bc04cfElliott Hughes#include "instruction_set.h"
3100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers#include "jobject_comparator.h"
32578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "macros.h"
33120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers#include "locks.h"
349d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes#include "runtime_stats.h"
35a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes#include "safe_map.h"
36578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "stringpiece.h"
37b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro
38971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien#if defined(ART_USE_LLVM_COMPILER)
39971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien#include "compiler_llvm/procedure_linkage_table.h"
40971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien#endif
41971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien
426b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapironamespace art {
437b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro
44161928613d3f097108319de60494fab1aab8d48aBrian Carlstromtemplate<class T> class PrimitiveArray;
45161928613d3f097108319de60494fab1aab8d48aBrian Carlstromtypedef PrimitiveArray<int8_t> ByteArray;
4661e019d291583029c01b61b93bea750f2b663c37Carl Shapiroclass ClassLinker;
47aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstromclass ClassLoader;
48fc322c72d7a89a6f7a05c8bdc232d780aecd9232Carl Shapiroclass DexFile;
4961e019d291583029c01b61b93bea750f2b663c37Carl Shapiroclass Heap;
50725a957985171d712d5c048cc3d00ff14968784bjeffhaoclass Instrumentation;
51cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughesclass InternTable;
521b09b094a85e03f6ef5f687f58bb91c433273ba1Ian Rogersstruct JavaVMExt;
5366f19258f9728d4ffe026074d8fd429d639802faMathieu Chartierclass AbstractMethod;
54c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughesclass MonitorList;
55e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughesclass SignalCatcher;
566ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstromclass String;
5761e019d291583029c01b61b93bea750f2b663c37Carl Shapiroclass ThreadList;
58225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughesclass Throwable;
592692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhaoclass Trace;
6061e019d291583029c01b61b93bea750f2b663c37Carl Shapiro
611fb8620309a4e94d11879aabc33364acfa733904Carl Shapiroclass Runtime {
627b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro public:
63f1a5adc87760f938b01df26d906295063546b259Elliott Hughes  typedef std::vector<std::pair<std::string, const void*> > Options;
648a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom
658a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom  class ParsedOptions {
668a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom   public:
676ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom    // returns null if problem parsing and ignore_unrecognized is false
686ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom    static ParsedOptions* Create(const Options& options, bool ignore_unrecognized);
698a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom
70a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom    const std::vector<const DexFile*>* boot_class_path_;
71a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom    std::string boot_class_path_string_;
72a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom    std::string class_path_string_;
7358ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom    std::string host_prefix_;
74223f20fa939c386c695977263780dea2195093dbBrian Carlstrom    std::string image_;
75515a5bc89282d6f910cae4d5852bb77124a47825Elliott Hughes    bool check_jni_;
76a09576416788b916095739e43a16917e7948f3a4Elliott Hughes    std::string jni_trace_;
77d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes    bool is_compiler_;
789ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes    bool is_zygote_;
7950ffee20ced9c0c7ac68889c86be8844cf120cf2Ian Rogers    bool interpreter_only_;
80069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier    bool is_concurrent_gc_enabled_;
818a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom    size_t heap_initial_size_;
828a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom    size_t heap_maximum_size_;
83c11607024d2e7a52ca690b8339306cab040e6653jeffhao    size_t heap_growth_limit_;
840051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier    size_t heap_min_free_;
850051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier    size_t heap_max_free_;
860051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier    double heap_target_utilization_;
87f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom    size_t stack_size_;
88bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes    size_t jni_globals_max_;
89bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes    size_t lock_profiling_threshold_;
9094ce37a3919a0bdb8855a3d3264a50df1dbc41beElliott Hughes    std::string stack_trace_file_;
91b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao    bool method_trace_;
92b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao    std::string method_trace_file_;
93b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao    size_t method_trace_file_size_;
94fc86162ce2a3467acb690e18cc8bd9b3daafc606Elliott Hughes    bool (*hook_is_sensitive_thread_)();
956ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom    jint (*hook_vfprintf_)(FILE* stream, const char* format, va_list ap);
966ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom    void (*hook_exit_)(jint status);
976ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom    void (*hook_abort_)();
986ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom    std::vector<std::string> properties_;
996ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom
1006ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom   private:
1010cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers    ParsedOptions() {}
1028a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom  };
1032ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro
10461e019d291583029c01b61b93bea750f2b663c37Carl Shapiro  // Creates and initializes a new runtime.
10500f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  static bool Create(const Options& options, bool ignore_unrecognized)
106b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_);
10769b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom
108d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes  bool IsCompiler() const {
109d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes    return is_compiler_;
110d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes  }
111d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes
112caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom  bool IsZygote() const {
113caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom    return is_zygote_;
114caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom  }
115caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom
11650ffee20ced9c0c7ac68889c86be8844cf120cf2Ian Rogers  bool InterpreterOnly() const {
11750ffee20ced9c0c7ac68889c86be8844cf120cf2Ian Rogers    return interpreter_only_;
11850ffee20ced9c0c7ac68889c86be8844cf120cf2Ian Rogers  }
11950ffee20ced9c0c7ac68889c86be8844cf120cf2Ian Rogers
120069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier  bool IsConcurrentGcEnabled() const {
121069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier    return is_concurrent_gc_enabled_;
122069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier  }
123069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier
12458ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  const std::string& GetHostPrefix() const {
125307f75d6bcf7c32db7e1b43124dead628cc7ce96Elliott Hughes    DCHECK(!IsStarted());
12658ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom    return host_prefix_;
12758ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  }
12858ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom
12969b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom  // Starts a runtime, which may cause threads to be started and code to run.
130b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers  void Start() UNLOCK_FUNCTION(Locks::mutator_lock_);
1312ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro
132120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  bool IsShuttingDown() const EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_) {
1339af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return shutting_down_;
1349af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
1359af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
136120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  size_t NumberOfThreadsBeingBorn() const EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_) {
137120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers    return threads_being_born_;
138120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  }
139120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
140120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  void StartThreadBirth() EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_) {
141120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers    threads_being_born_++;
142120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  }
143120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
144120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  void EndThreadBirth() EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_);
145120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
1469af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  bool IsStarted() const {
1479af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return started_;
1489af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
149dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes
1507664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier  bool IsFinishedStarting() const {
1517664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier    return finished_starting_;
1527664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier  }
1537664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier
1542ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro  static Runtime* Current() {
1552ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro    return instance_;
1562ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro  }
15761e019d291583029c01b61b93bea750f2b663c37Carl Shapiro
158ffe6736397d17457188727510f0a2953f69a383aElliott Hughes  // Aborts semi-cleanly. Used in the implementation of LOG(FATAL), which most
159ffe6736397d17457188727510f0a2953f69a383aElliott Hughes  // callers should prefer.
160ffe6736397d17457188727510f0a2953f69a383aElliott Hughes  // This isn't marked ((noreturn)) because then gcc will merge multiple calls
161ffe6736397d17457188727510f0a2953f69a383aElliott Hughes  // in a single function together. This reduces code size slightly, but means
162ffe6736397d17457188727510f0a2953f69a383aElliott Hughes  // that the native stack trace we get may point at the wrong call site.
163b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers  static void Abort() LOCKS_EXCLUDED(Locks::abort_lock_);
164ffe6736397d17457188727510f0a2953f69a383aElliott Hughes
165365c10235438607541fa2259a5fec48061b90bd8Ian Rogers  // Returns the "main" ThreadGroup, used when attaching user threads.
166034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom  jobject GetMainThreadGroup() const;
167365c10235438607541fa2259a5fec48061b90bd8Ian Rogers
168365c10235438607541fa2259a5fec48061b90bd8Ian Rogers  // Returns the "system" ThreadGroup, used when attaching our internal threads.
169034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom  jobject GetSystemThreadGroup() const;
170365c10235438607541fa2259a5fec48061b90bd8Ian Rogers
171462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes  // Attaches the calling native thread to the runtime.
172664bebf92eb2151b9b570ccd42ac4b6056c3ea9cMathieu Chartier  bool AttachCurrentThread(const char* thread_name, bool as_daemon, jobject thread_group,
173664bebf92eb2151b9b570ccd42ac4b6056c3ea9cMathieu Chartier                           bool create_peer);
174b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro
175bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes  void CallExitHook(jint status);
176bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes
17761e019d291583029c01b61b93bea750f2b663c37Carl Shapiro  // Detaches the current native thread from the runtime.
178b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers  void DetachCurrentThread() LOCKS_EXCLUDED(Locks::mutator_lock_);
17961e019d291583029c01b61b93bea750f2b663c37Carl Shapiro
18000f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  void DumpForSigQuit(std::ostream& os)
181b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
18221a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughes  void DumpLockHolders(std::ostream& os);
183e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes
18461e019d291583029c01b61b93bea750f2b663c37Carl Shapiro  ~Runtime();
185b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro
186a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom  const std::string& GetBootClassPathString() const {
187a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom    return boot_class_path_string_;
188b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom  }
189b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom
190a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom  const std::string& GetClassPathString() const {
191a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom    return class_path_string_;
1927a90959d4ef7a69f3bcb7b8763f646e12d9267d3Carl Shapiro  }
1937a90959d4ef7a69f3bcb7b8763f646e12d9267d3Carl Shapiro
194a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom  ClassLinker* GetClassLinker() const {
195a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom    return class_linker_;
1967ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes  }
1977ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes
1987ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes  size_t GetDefaultStackSize() const {
1997ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes    return default_stack_size_;
2007ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes  }
2017ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes
202b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  Heap* GetHeap() const {
203b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes    return heap_;
204b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  }
205b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes
206cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes  InternTable* GetInternTable() const {
207cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes    return intern_table_;
208cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes  }
209cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes
2100af5543f8ea20c3e655b2d748a1b7dcf283792feElliott Hughes  JavaVMExt* GetJavaVM() const {
211c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughes    return java_vm_;
212f2682d5a6ce0f7de58da8fd4ec8aec200c43b92eElliott Hughes  }
213f2682d5a6ce0f7de58da8fd4ec8aec200c43b92eElliott Hughes
214c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes  MonitorList* GetMonitorList() const {
215c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes    return monitor_list_;
216c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes  }
217c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes
218225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes  Throwable* GetPreAllocatedOutOfMemoryError() {
219225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes    return pre_allocated_OutOfMemoryError_;
220225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes  }
221225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes
222225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes  const std::vector<std::string>& GetProperties() const {
223225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes    return properties_;
224225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes  }
225225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes
226d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes  ThreadList* GetThreadList() const {
227d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes    return thread_list_;
228d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes  }
229d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes
2307ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes  const char* GetVersion() const {
2317ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes    return "2.0.0";
2327ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes  }
2337ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes
2349ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier  // Force all the roots which can be marked concurrently to be dirty.
2359ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier  void DirtyRoots();
2369ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier
2379ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier  // Visit all the roots.
2389ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier  void VisitRoots(Heap::RootVisitor* visitor, void* arg)
239b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
2401f87008b165d26541d832ff805250afdc89c253dBrian Carlstrom
2419ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier  // Visit all of the roots we can do safely do concurrently.
2429ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier  void VisitConcurrentRoots(Heap::RootVisitor* visitor, void* arg);
2439ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier
244858f1c5fd5e528d0b16040ced74d4636046a42d8Mathieu Chartier  // Visit all of the non thread roots, we can do this with mutators unpaused.
245858f1c5fd5e528d0b16040ced74d4636046a42d8Mathieu Chartier  void VisitNonThreadRoots(Heap::RootVisitor* visitor, void* arg);
246858f1c5fd5e528d0b16040ced74d4636046a42d8Mathieu Chartier
2479ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier  // Visit all other roots which must be done with mutators suspended.
2489ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier  void VisitNonConcurrentRoots(Heap::RootVisitor* visitor, void* arg)
2499ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
2509ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier
2519af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  bool HasJniDlsymLookupStub() const {
2529af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return jni_stub_array_ != NULL;
2539af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
2549af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
2559af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  ByteArray* GetJniDlsymLookupStub() const {
2569af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    CHECK(HasJniDlsymLookupStub());
2579af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return jni_stub_array_;
2589af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
2599af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
260169c9a7f46776b235d0a37d5e0ff27682deffe06Ian Rogers  void SetJniDlsymLookupStub(ByteArray* jni_stub_array);
261ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers
2629af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  bool HasAbstractMethodErrorStubArray() const {
2639af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return abstract_method_error_stub_array_ != NULL;
2649af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
2659af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
2669af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  ByteArray* GetAbstractMethodErrorStubArray() const {
2679af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    CHECK(abstract_method_error_stub_array_ != NULL);
2689af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return abstract_method_error_stub_array_;
2699af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
2709af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
271e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  void SetAbstractMethodErrorStubArray(ByteArray* abstract_method_error_stub_array);
272ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers
2731cb0a1dfc32531c79a968aeac26ccb5525862497Ian Rogers  enum TrampolineType {
2741cb0a1dfc32531c79a968aeac26ccb5525862497Ian Rogers    kStaticMethod,
2751cb0a1dfc32531c79a968aeac26ccb5525862497Ian Rogers    kUnknownMethod,
2764f0d07c783afef89703dce32c94440fc8621a29bIan Rogers    kLastTrampolineMethodType  // Value used for iteration
2771cb0a1dfc32531c79a968aeac26ccb5525862497Ian Rogers  };
2789af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
2799af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  bool HasResolutionStubArray(TrampolineType type) const {
2809af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return resolution_stub_array_[type] != NULL;
2819af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
2829af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
2839af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  ByteArray* GetResolutionStubArray(TrampolineType type) const {
2849af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    CHECK(HasResolutionStubArray(type));
2859af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastTrampolineMethodType));
2869af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return resolution_stub_array_[type];
2879af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
2889af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
2891cb0a1dfc32531c79a968aeac26ccb5525862497Ian Rogers  void SetResolutionStubArray(ByteArray* resolution_stub_array, TrampolineType type);
290ad25ac568407ceb14334e8551dd1c4dd0fd6993cIan Rogers
2919af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  // Returns a special method that calls into a trampoline for runtime method resolution
29266f19258f9728d4ffe026074d8fd429d639802faMathieu Chartier  AbstractMethod* GetResolutionMethod() const {
2939af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    CHECK(HasResolutionMethod());
2949af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return resolution_method_;
2959af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
2969af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
2979af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  bool HasResolutionMethod() const {
2989af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return resolution_method_ != NULL;
2999af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
3009af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
30166f19258f9728d4ffe026074d8fd429d639802faMathieu Chartier  void SetResolutionMethod(AbstractMethod* method) {
3029af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    resolution_method_ = method;
3039af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
3049af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
30566f19258f9728d4ffe026074d8fd429d639802faMathieu Chartier  AbstractMethod* CreateResolutionMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
3061984651929744dd603fd082e23eacd877b9bc177Ian Rogers
307ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers  // Returns a special method that describes all callee saves being spilled to the stack.
3084f0d07c783afef89703dce32c94440fc8621a29bIan Rogers  enum CalleeSaveType {
3094f0d07c783afef89703dce32c94440fc8621a29bIan Rogers    kSaveAll,
3104f0d07c783afef89703dce32c94440fc8621a29bIan Rogers    kRefsOnly,
3114f0d07c783afef89703dce32c94440fc8621a29bIan Rogers    kRefsAndArgs,
3124f0d07c783afef89703dce32c94440fc8621a29bIan Rogers    kLastCalleeSaveType  // Value used for iteration
3134f0d07c783afef89703dce32c94440fc8621a29bIan Rogers  };
3149af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
3159af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  bool HasCalleeSaveMethod(CalleeSaveType type) const {
316225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes    return callee_save_methods_[type] != NULL;
3179af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
3189af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
31966f19258f9728d4ffe026074d8fd429d639802faMathieu Chartier  AbstractMethod* GetCalleeSaveMethod(CalleeSaveType type) const {
320df1ce91ba97bc79a0637e5504b39318fb1c9f577Ian Rogers    DCHECK(HasCalleeSaveMethod(type));
321225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes    return callee_save_methods_[type];
3229af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
3239af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
32466f19258f9728d4ffe026074d8fd429d639802faMathieu Chartier  void SetCalleeSaveMethod(AbstractMethod* method, CalleeSaveType type);
3254f0d07c783afef89703dce32c94440fc8621a29bIan Rogers
32666f19258f9728d4ffe026074d8fd429d639802faMathieu Chartier  AbstractMethod* CreateCalleeSaveMethod(InstructionSet instruction_set, CalleeSaveType type)
327b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
3289af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
32966f19258f9728d4ffe026074d8fd429d639802faMathieu Chartier  AbstractMethod* CreateRefOnlyCalleeSaveMethod(InstructionSet instruction_set)
330b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
33100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers
33266f19258f9728d4ffe026074d8fd429d639802faMathieu Chartier  AbstractMethod* CreateRefAndArgsCalleeSaveMethod(InstructionSet instruction_set)
333b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
334ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers
3359d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  int32_t GetStat(int kind);
3369d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes
3379af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  RuntimeStats* GetStats() {
3389af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers    return &stats_;
3399af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers  }
3409d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes
3419d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  bool HasStatsEnabled() const {
3429d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes    return stats_enabled_;
3439d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  }
3449d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes
3459d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  void ResetStats(int kinds);
3469d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes
3479d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  void SetStatsEnabled(bool new_state);
3489d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes
349caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom  void DidForkFromZygote();
350cc236d74772dda5a4161d9bc5f497fd3d956eb87Mathieu Chartier  bool PreZygoteFork();
351caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom
352725a957985171d712d5c048cc3d00ff14968784bjeffhao  void EnableMethodTracing(Trace* trace);
3532692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhao  void DisableMethodTracing();
354725a957985171d712d5c048cc3d00ff14968784bjeffhao  bool IsMethodTracingActive() const;
355725a957985171d712d5c048cc3d00ff14968784bjeffhao  Instrumentation* GetInstrumentation() const;
3562692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhao
357b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  bool UseCompileTimeClassPath() const {
358b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes    return use_compile_time_class_path_;
359b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  }
3609af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers
36100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  const std::vector<const DexFile*>& GetCompileTimeClassPath(jobject class_loader);
36200f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  void SetCompileTimeClassPath(jobject class_loader, std::vector<const DexFile*>& class_path);
363b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes
364b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro private:
365457005c557b8762475db3220ce5a747d629f975bElliott Hughes  static void InitPlatformSignalHandlers();
366ffe6736397d17457188727510f0a2953f69a383aElliott Hughes
367dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes  Runtime();
36861e019d291583029c01b61b93bea750f2b663c37Carl Shapiro
369c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes  void BlockSignals();
370c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes
37100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  bool Init(const Options& options, bool ignore_unrecognized)
372b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers      SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_);
373b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers  void InitNativeMethods() LOCKS_EXCLUDED(Locks::mutator_lock_);
374365c10235438607541fa2259a5fec48061b90bd8Ian Rogers  void InitThreadGroups(Thread* self);
375ff17f1fd3ff32f93e45588eb2b158832d73f9afaElliott Hughes  void RegisterRuntimeNativeMethods(JNIEnv* env);
376d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes
37785d1545e985ac689db4bad7849880e843707c862Elliott Hughes  void StartDaemonThreads();
378d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes  void StartSignalCatcher();
37961e019d291583029c01b61b93bea750f2b663c37Carl Shapiro
380b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  // A pointer to the active runtime or NULL.
381b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  static Runtime* instance_;
382b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes
383d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes  bool is_compiler_;
3849ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes  bool is_zygote_;
38550ffee20ced9c0c7ac68889c86be8844cf120cf2Ian Rogers  bool interpreter_only_;
386069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier  bool is_concurrent_gc_enabled_;
3870a5b14de5115f51e0ed2dd6c3fcc5b84bbce690eBrian Carlstrom
38858ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // The host prefix is used during cross compilation. It is removed
38958ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // from the start of host paths such as:
39029e7ac74a3f9aec192099fec381baadaa55730adBrian Carlstrom  //    $ANDROID_PRODUCT_OUT/system/framework/boot.oat
39134f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom  // to produce target paths such as
39247a0d5a6f221066c3daf7f67f2122ed9c9cd217cBrian Carlstrom  //    /system/framework/boot.oat
39358ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // Similarly it is prepended to target paths to arrive back at a
39458ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // host past. In both cases this is necessary because image and oat
39558ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // files embedded expect paths of dependent files (an image points
39658ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // to an oat file and an oat files to one or more dex files). These
39758ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  // files contain the expected target path.
39858ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom  std::string host_prefix_;
39958ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom
400a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom  std::string boot_class_path_string_;
401a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom  std::string class_path_string_;
4027ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes  std::vector<std::string> properties_;
4037ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes
404b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom  // The default stack size for managed threads created by the runtime.
405be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes  size_t default_stack_size_;
406b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom
407b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  Heap* heap_;
408b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes
409c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes  MonitorList* monitor_list_;
410c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes
411b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro  ThreadList* thread_list_;
41261e019d291583029c01b61b93bea750f2b663c37Carl Shapiro
413cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes  InternTable* intern_table_;
414cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes
415b0460eaa2cb131f1dbdd5a7217bd36b9a9f1b995Brian Carlstrom  ClassLinker* class_linker_;
416b0460eaa2cb131f1dbdd5a7217bd36b9a9f1b995Brian Carlstrom
417e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes  SignalCatcher* signal_catcher_;
41894ce37a3919a0bdb8855a3d3264a50df1dbc41beElliott Hughes  std::string stack_trace_file_;
419e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes
420c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughes  JavaVMExt* java_vm_;
421f2682d5a6ce0f7de58da8fd4ec8aec200c43b92eElliott Hughes
422225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes  Throwable* pre_allocated_OutOfMemoryError_;
423225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes
424161928613d3f097108319de60494fab1aab8d48aBrian Carlstrom  ByteArray* jni_stub_array_;
425161928613d3f097108319de60494fab1aab8d48aBrian Carlstrom
426e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  ByteArray* abstract_method_error_stub_array_;
427e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
4284f0d07c783afef89703dce32c94440fc8621a29bIan Rogers  ByteArray* resolution_stub_array_[kLastTrampolineMethodType];
429ad25ac568407ceb14334e8551dd1c4dd0fd6993cIan Rogers
43066f19258f9728d4ffe026074d8fd429d639802faMathieu Chartier  AbstractMethod* callee_save_methods_[kLastCalleeSaveType];
431ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers
43266f19258f9728d4ffe026074d8fd429d639802faMathieu Chartier  AbstractMethod* resolution_method_;
4331984651929744dd603fd082e23eacd877b9bc177Ian Rogers
434aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom  // As returned by ClassLoader.getSystemClassLoader()
435aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom  ClassLoader* system_class_loader_;
436aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom
437120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  // A non-zero value indicates that a thread has been created but not yet initialized. Guarded by
438120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  // the shutdown lock so that threads aren't born while we're shutting down.
439120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  size_t threads_being_born_ GUARDED_BY(Locks::runtime_shutdown_lock_);
440120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
441120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  // Waited upon until no threads are being born.
442120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  UniquePtr<ConditionVariable> shutdown_cond_ GUARDED_BY(Locks::runtime_shutdown_lock_);
443120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
444120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  // Set when runtime shutdown is past the point that new threads may attach.
445120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  bool shutting_down_ GUARDED_BY(Locks::runtime_shutdown_lock_);
446120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
447120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  // The runtime is starting to shutdown but is blocked waiting on shutdown_cond_.
448120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers  bool shutting_down_started_ GUARDED_BY(Locks::runtime_shutdown_lock_);
449120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers
450dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes  bool started_;
451dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes
4527664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier  // New flag added which tells us if the runtime has finished starting. If
4537664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier  // this flag is set then the Daemon threads are created and the class loader
4547664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier  // is created. This flag is needed for knowing if its safe to request CMS.
4557664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier  bool finished_starting_;
4567664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier
4576ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom  // Hooks supported by JNI_CreateJavaVM
4586ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom  jint (*vfprintf_)(FILE* stream, const char* format, va_list ap);
4596ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom  void (*exit_)(jint status);
4606ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom  void (*abort_)();
4616ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom
4629d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  bool stats_enabled_;
4639d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes  RuntimeStats stats_;
4649d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes
465b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao  bool method_trace_;
466b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao  std::string method_trace_file_;
467b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao  size_t method_trace_file_size_;
468725a957985171d712d5c048cc3d00ff14968784bjeffhao  Instrumentation* instrumentation_;
4692692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhao
47000f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  typedef SafeMap<jobject, std::vector<const DexFile*>, JobjectComparator> CompileTimeClassPaths;
471b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  CompileTimeClassPaths compile_time_class_paths_;
472b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes  bool use_compile_time_class_path_;
473131aef8c94292cc530da2fd91ee98d1432352959Elliott Hughes
474365c10235438607541fa2259a5fec48061b90bd8Ian Rogers  jobject main_thread_group_;
475365c10235438607541fa2259a5fec48061b90bd8Ian Rogers  jobject system_thread_group_;
476971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien#if defined(ART_USE_LLVM_COMPILER)
477971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien  compiler_llvm::ProcedureLinkageTable plt_;
478971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien#endif
479365c10235438607541fa2259a5fec48061b90bd8Ian Rogers
48061e019d291583029c01b61b93bea750f2b663c37Carl Shapiro  DISALLOW_COPY_AND_ASSIGN(Runtime);
4817b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro};
4827b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro
4836b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapiro}  // namespace art
4847b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro
4851fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro#endif  // ART_SRC_RUNTIME_H_
486