Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 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 | */ |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 16 | |
| 17 | #ifndef ART_SRC_RUNTIME_H_ |
| 18 | #define ART_SRC_RUNTIME_H_ |
| 19 | |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 20 | #include <jni.h> |
Elliott Hughes | c5f7c91 | 2011-08-18 14:00:42 -0700 | [diff] [blame] | 21 | #include <stdio.h> |
| 22 | |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 23 | #include <iosfwd> |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 24 | #include <string> |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 25 | #include <utility> |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 26 | #include <vector> |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 27 | |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 28 | #include "globals.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 29 | #include "heap.h" |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 30 | #include "instruction_set.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 31 | #include "macros.h" |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 32 | #include "runtime_stats.h" |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 33 | #include "safe_map.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 34 | #include "stringpiece.h" |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 35 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 36 | namespace art { |
| 37 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 38 | template<class T> class PrimitiveArray; |
| 39 | typedef PrimitiveArray<int8_t> ByteArray; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 40 | class ClassLinker; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 41 | class ClassLoader; |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 42 | class DexFile; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 43 | class Heap; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 44 | class InternTable; |
Elliott Hughes | c5f7c91 | 2011-08-18 14:00:42 -0700 | [diff] [blame] | 45 | class JavaVMExt; |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 46 | class Method; |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 47 | class MonitorList; |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 48 | class SignalCatcher; |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 49 | class String; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 50 | class ThreadList; |
Elliott Hughes | 225f5a1 | 2012-06-11 11:23:48 -0700 | [diff] [blame] | 51 | class Throwable; |
jeffhao | 2692b57 | 2011-12-16 15:42:28 -0800 | [diff] [blame] | 52 | class Trace; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 53 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 54 | class Runtime { |
| 55 | public: |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 56 | typedef std::vector<std::pair<std::string, const void*> > Options; |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 57 | |
| 58 | class ParsedOptions { |
| 59 | public: |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 60 | // returns null if problem parsing and ignore_unrecognized is false |
| 61 | static ParsedOptions* Create(const Options& options, bool ignore_unrecognized); |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 62 | |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 63 | const std::vector<const DexFile*>* boot_class_path_; |
| 64 | std::string boot_class_path_string_; |
| 65 | std::string class_path_string_; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 66 | std::string host_prefix_; |
Brian Carlstrom | 223f20f | 2012-02-04 23:06:55 -0800 | [diff] [blame] | 67 | std::string image_; |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 68 | bool check_jni_; |
Elliott Hughes | a095764 | 2011-09-02 14:27:33 -0700 | [diff] [blame] | 69 | std::string jni_trace_; |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 70 | bool is_compiler_; |
Elliott Hughes | 9ca7a1f | 2011-10-11 14:29:52 -0700 | [diff] [blame] | 71 | bool is_zygote_; |
Mathieu Chartier | 069387a | 2012-06-18 12:01:01 -0700 | [diff] [blame] | 72 | bool is_concurrent_gc_enabled_; |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 73 | size_t heap_initial_size_; |
| 74 | size_t heap_maximum_size_; |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 75 | size_t heap_growth_limit_; |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 76 | size_t stack_size_; |
Elliott Hughes | bb1e8f0 | 2011-10-18 14:14:25 -0700 | [diff] [blame] | 77 | size_t jni_globals_max_; |
| 78 | size_t lock_profiling_threshold_; |
Elliott Hughes | 94ce37a | 2011-10-18 15:07:48 -0700 | [diff] [blame] | 79 | std::string stack_trace_file_; |
jeffhao | b5e8185 | 2012-03-12 11:15:45 -0700 | [diff] [blame] | 80 | bool method_trace_; |
| 81 | std::string method_trace_file_; |
| 82 | size_t method_trace_file_size_; |
Elliott Hughes | fc86162 | 2011-10-17 17:57:47 -0700 | [diff] [blame] | 83 | bool (*hook_is_sensitive_thread_)(); |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 84 | jint (*hook_vfprintf_)(FILE* stream, const char* format, va_list ap); |
| 85 | void (*hook_exit_)(jint status); |
| 86 | void (*hook_abort_)(); |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 87 | std::vector<std::string> properties_; |
| 88 | |
| 89 | private: |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 90 | ParsedOptions() {} |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 91 | }; |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 92 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 93 | // Creates and initializes a new runtime. |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 94 | static Runtime* Create(const Options& options, bool ignore_unrecognized); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 95 | |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 96 | bool IsCompiler() const { |
| 97 | return is_compiler_; |
| 98 | } |
| 99 | |
Brian Carlstrom | caabb1b | 2011-10-11 18:09:13 -0700 | [diff] [blame] | 100 | bool IsZygote() const { |
| 101 | return is_zygote_; |
| 102 | } |
| 103 | |
Mathieu Chartier | 069387a | 2012-06-18 12:01:01 -0700 | [diff] [blame] | 104 | bool IsConcurrentGcEnabled() const { |
| 105 | return is_concurrent_gc_enabled_; |
| 106 | } |
| 107 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 108 | const std::string& GetHostPrefix() const { |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 109 | DCHECK(!IsStarted()); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 110 | return host_prefix_; |
| 111 | } |
| 112 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 113 | // Starts a runtime, which may cause threads to be started and code to run. |
| 114 | void Start(); |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 115 | |
Ian Rogers | 9af209c | 2012-06-03 20:50:30 -0700 | [diff] [blame] | 116 | bool IsShuttingDown() const { |
| 117 | return shutting_down_; |
| 118 | } |
| 119 | |
| 120 | bool IsStarted() const { |
| 121 | return started_; |
| 122 | } |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 123 | |
Mathieu Chartier | 7664f5c | 2012-06-08 18:15:32 -0700 | [diff] [blame] | 124 | bool IsFinishedStarting() const { |
| 125 | return finished_starting_; |
| 126 | } |
| 127 | |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 128 | static Runtime* Current() { |
| 129 | return instance_; |
| 130 | } |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 131 | |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 132 | // Aborts semi-cleanly. Used in the implementation of LOG(FATAL), which most |
| 133 | // callers should prefer. |
| 134 | // This isn't marked ((noreturn)) because then gcc will merge multiple calls |
| 135 | // in a single function together. This reduces code size slightly, but means |
| 136 | // that the native stack trace we get may point at the wrong call site. |
Elliott Hughes | 8593fdb | 2012-04-21 20:53:44 -0700 | [diff] [blame] | 137 | static void Abort(); |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 138 | |
Ian Rogers | 365c102 | 2012-06-22 15:05:28 -0700 | [diff] [blame^] | 139 | // Returns the "main" ThreadGroup, used when attaching user threads. |
| 140 | jobject GetMainThreadGroup() const { |
| 141 | return main_thread_group_; |
| 142 | } |
| 143 | |
| 144 | // Returns the "system" ThreadGroup, used when attaching our internal threads. |
| 145 | jobject GetSystemThreadGroup() const { |
| 146 | return system_thread_group_; |
| 147 | } |
| 148 | |
Elliott Hughes | 462c944 | 2012-03-23 18:47:50 -0700 | [diff] [blame] | 149 | // Attaches the calling native thread to the runtime. |
Ian Rogers | 365c102 | 2012-06-22 15:05:28 -0700 | [diff] [blame^] | 150 | void AttachCurrentThread(const char* thread_name, bool as_daemon, jobject thread_group); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 151 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 152 | void CallExitHook(jint status); |
| 153 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 154 | // Detaches the current native thread from the runtime. |
Elliott Hughes | d92bec4 | 2011-09-02 17:04:36 -0700 | [diff] [blame] | 155 | void DetachCurrentThread(); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 156 | |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 157 | void DumpForSigQuit(std::ostream& os); |
Elliott Hughes | 21a5bf2 | 2011-12-07 14:35:20 -0800 | [diff] [blame] | 158 | void DumpLockHolders(std::ostream& os); |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 159 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 160 | ~Runtime(); |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 161 | |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 162 | const std::string& GetBootClassPathString() const { |
| 163 | return boot_class_path_string_; |
| 164 | } |
| 165 | |
| 166 | const std::string& GetClassPathString() const { |
| 167 | return class_path_string_; |
Brian Carlstrom | b765be0 | 2011-08-17 23:54:10 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | ClassLinker* GetClassLinker() const { |
Carl Shapiro | 7a90959 | 2011-07-24 19:21:59 -0700 | [diff] [blame] | 171 | return class_linker_; |
| 172 | } |
| 173 | |
Elliott Hughes | 7ede61e | 2011-09-14 18:18:06 -0700 | [diff] [blame] | 174 | size_t GetDefaultStackSize() const { |
| 175 | return default_stack_size_; |
| 176 | } |
| 177 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 178 | Heap* GetHeap() const { |
| 179 | return heap_; |
| 180 | } |
| 181 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 182 | InternTable* GetInternTable() const { |
| 183 | return intern_table_; |
| 184 | } |
| 185 | |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 186 | JavaVMExt* GetJavaVM() const { |
Elliott Hughes | c5f7c91 | 2011-08-18 14:00:42 -0700 | [diff] [blame] | 187 | return java_vm_; |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 190 | MonitorList* GetMonitorList() const { |
| 191 | return monitor_list_; |
| 192 | } |
| 193 | |
Elliott Hughes | 225f5a1 | 2012-06-11 11:23:48 -0700 | [diff] [blame] | 194 | Throwable* GetPreAllocatedOutOfMemoryError() { |
| 195 | return pre_allocated_OutOfMemoryError_; |
| 196 | } |
| 197 | |
| 198 | const std::vector<std::string>& GetProperties() const { |
| 199 | return properties_; |
| 200 | } |
| 201 | |
Elliott Hughes | d92bec4 | 2011-09-02 17:04:36 -0700 | [diff] [blame] | 202 | ThreadList* GetThreadList() const { |
| 203 | return thread_list_; |
| 204 | } |
| 205 | |
Elliott Hughes | 7ede61e | 2011-09-14 18:18:06 -0700 | [diff] [blame] | 206 | const char* GetVersion() const { |
| 207 | return "2.0.0"; |
| 208 | } |
| 209 | |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 210 | void VisitRoots(Heap::RootVisitor* visitor, void* arg) const; |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 211 | |
Ian Rogers | 9af209c | 2012-06-03 20:50:30 -0700 | [diff] [blame] | 212 | bool HasJniDlsymLookupStub() const { |
| 213 | return jni_stub_array_ != NULL; |
| 214 | } |
| 215 | |
| 216 | ByteArray* GetJniDlsymLookupStub() const { |
| 217 | CHECK(HasJniDlsymLookupStub()); |
| 218 | return jni_stub_array_; |
| 219 | } |
| 220 | |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 221 | void SetJniDlsymLookupStub(ByteArray* jni_stub_array); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 222 | |
Ian Rogers | 9af209c | 2012-06-03 20:50:30 -0700 | [diff] [blame] | 223 | bool HasAbstractMethodErrorStubArray() const { |
| 224 | return abstract_method_error_stub_array_ != NULL; |
| 225 | } |
| 226 | |
| 227 | ByteArray* GetAbstractMethodErrorStubArray() const { |
| 228 | CHECK(abstract_method_error_stub_array_ != NULL); |
| 229 | return abstract_method_error_stub_array_; |
| 230 | } |
| 231 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 232 | void SetAbstractMethodErrorStubArray(ByteArray* abstract_method_error_stub_array); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 233 | |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 234 | enum TrampolineType { |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 235 | kStaticMethod, |
| 236 | kUnknownMethod, |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 237 | kLastTrampolineMethodType // Value used for iteration |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 238 | }; |
Ian Rogers | 9af209c | 2012-06-03 20:50:30 -0700 | [diff] [blame] | 239 | |
| 240 | bool HasResolutionStubArray(TrampolineType type) const { |
| 241 | return resolution_stub_array_[type] != NULL; |
| 242 | } |
| 243 | |
| 244 | ByteArray* GetResolutionStubArray(TrampolineType type) const { |
| 245 | CHECK(HasResolutionStubArray(type)); |
| 246 | DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastTrampolineMethodType)); |
| 247 | return resolution_stub_array_[type]; |
| 248 | } |
| 249 | |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 250 | void SetResolutionStubArray(ByteArray* resolution_stub_array, TrampolineType type); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 251 | |
Ian Rogers | 9af209c | 2012-06-03 20:50:30 -0700 | [diff] [blame] | 252 | // Returns a special method that calls into a trampoline for runtime method resolution |
| 253 | Method* GetResolutionMethod() const { |
| 254 | CHECK(HasResolutionMethod()); |
| 255 | return resolution_method_; |
| 256 | } |
| 257 | |
| 258 | bool HasResolutionMethod() const { |
| 259 | return resolution_method_ != NULL; |
| 260 | } |
| 261 | |
| 262 | void SetResolutionMethod(Method* method) { |
| 263 | resolution_method_ = method; |
| 264 | } |
| 265 | |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 266 | Method* CreateResolutionMethod(); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 267 | |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 268 | // Returns a special method that describes all callee saves being spilled to the stack. |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 269 | enum CalleeSaveType { |
| 270 | kSaveAll, |
| 271 | kRefsOnly, |
| 272 | kRefsAndArgs, |
| 273 | kLastCalleeSaveType // Value used for iteration |
| 274 | }; |
Ian Rogers | 9af209c | 2012-06-03 20:50:30 -0700 | [diff] [blame] | 275 | |
| 276 | bool HasCalleeSaveMethod(CalleeSaveType type) const { |
Elliott Hughes | 225f5a1 | 2012-06-11 11:23:48 -0700 | [diff] [blame] | 277 | return callee_save_methods_[type] != NULL; |
Ian Rogers | 9af209c | 2012-06-03 20:50:30 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | Method* GetCalleeSaveMethod(CalleeSaveType type) const { |
| 281 | CHECK(HasCalleeSaveMethod(type)); |
Elliott Hughes | 225f5a1 | 2012-06-11 11:23:48 -0700 | [diff] [blame] | 282 | return callee_save_methods_[type]; |
Ian Rogers | 9af209c | 2012-06-03 20:50:30 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 285 | void SetCalleeSaveMethod(Method* method, CalleeSaveType type); |
| 286 | |
Ian Rogers | 9af209c | 2012-06-03 20:50:30 -0700 | [diff] [blame] | 287 | Method* CreateCalleeSaveMethod(InstructionSet instruction_set, CalleeSaveType type); |
| 288 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 289 | Method* CreateRefOnlyCalleeSaveMethod(InstructionSet instruction_set); |
| 290 | Method* CreateRefAndArgsCalleeSaveMethod(InstructionSet instruction_set); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 291 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 292 | int32_t GetStat(int kind); |
| 293 | |
Ian Rogers | 9af209c | 2012-06-03 20:50:30 -0700 | [diff] [blame] | 294 | RuntimeStats* GetStats() { |
| 295 | return &stats_; |
| 296 | } |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 297 | |
| 298 | bool HasStatsEnabled() const { |
| 299 | return stats_enabled_; |
| 300 | } |
| 301 | |
| 302 | void ResetStats(int kinds); |
| 303 | |
| 304 | void SetStatsEnabled(bool new_state); |
| 305 | |
Brian Carlstrom | caabb1b | 2011-10-11 18:09:13 -0700 | [diff] [blame] | 306 | void DidForkFromZygote(); |
| 307 | |
jeffhao | 2692b57 | 2011-12-16 15:42:28 -0800 | [diff] [blame] | 308 | void EnableMethodTracing(Trace* tracer); |
| 309 | void DisableMethodTracing(); |
Ian Rogers | 9af209c | 2012-06-03 20:50:30 -0700 | [diff] [blame] | 310 | |
| 311 | bool IsMethodTracingActive() const { |
| 312 | return tracer_ != NULL; |
| 313 | } |
| 314 | |
| 315 | Trace* GetTracer() const { |
| 316 | CHECK(IsMethodTracingActive()); |
| 317 | return tracer_; |
| 318 | } |
jeffhao | 2692b57 | 2011-12-16 15:42:28 -0800 | [diff] [blame] | 319 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 320 | bool UseCompileTimeClassPath() const { |
| 321 | return use_compile_time_class_path_; |
| 322 | } |
Ian Rogers | 9af209c | 2012-06-03 20:50:30 -0700 | [diff] [blame] | 323 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 324 | const std::vector<const DexFile*>& GetCompileTimeClassPath(const ClassLoader* class_loader); |
| 325 | void SetCompileTimeClassPath(const ClassLoader* class_loader, std::vector<const DexFile*>& class_path); |
| 326 | |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 327 | private: |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 328 | static void InitPlatformSignalHandlers(); |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 329 | |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 330 | Runtime(); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 331 | |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 332 | void BlockSignals(); |
| 333 | |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 334 | bool Init(const Options& options, bool ignore_unrecognized); |
Elliott Hughes | 038a806 | 2011-09-18 14:12:41 -0700 | [diff] [blame] | 335 | void InitNativeMethods(); |
Ian Rogers | 365c102 | 2012-06-22 15:05:28 -0700 | [diff] [blame^] | 336 | void InitThreadGroups(Thread* self); |
Elliott Hughes | ff17f1f | 2012-01-24 18:12:29 -0800 | [diff] [blame] | 337 | void RegisterRuntimeNativeMethods(JNIEnv* env); |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 338 | |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 339 | void StartDaemonThreads(); |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 340 | void StartSignalCatcher(); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 341 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 342 | // A pointer to the active runtime or NULL. |
| 343 | static Runtime* instance_; |
| 344 | |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 345 | bool is_compiler_; |
Elliott Hughes | 9ca7a1f | 2011-10-11 14:29:52 -0700 | [diff] [blame] | 346 | bool is_zygote_; |
Mathieu Chartier | 069387a | 2012-06-18 12:01:01 -0700 | [diff] [blame] | 347 | bool is_concurrent_gc_enabled_; |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 348 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 349 | // The host prefix is used during cross compilation. It is removed |
| 350 | // from the start of host paths such as: |
Brian Carlstrom | 29e7ac7 | 2011-12-05 23:42:57 -0800 | [diff] [blame] | 351 | // $ANDROID_PRODUCT_OUT/system/framework/boot.oat |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 352 | // to produce target paths such as |
Brian Carlstrom | 47a0d5a | 2011-10-12 21:20:05 -0700 | [diff] [blame] | 353 | // /system/framework/boot.oat |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 354 | // Similarly it is prepended to target paths to arrive back at a |
| 355 | // host past. In both cases this is necessary because image and oat |
| 356 | // files embedded expect paths of dependent files (an image points |
| 357 | // to an oat file and an oat files to one or more dex files). These |
| 358 | // files contain the expected target path. |
| 359 | std::string host_prefix_; |
| 360 | |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 361 | std::string boot_class_path_string_; |
| 362 | std::string class_path_string_; |
Elliott Hughes | 7ede61e | 2011-09-14 18:18:06 -0700 | [diff] [blame] | 363 | std::vector<std::string> properties_; |
| 364 | |
Brian Carlstrom | b765be0 | 2011-08-17 23:54:10 -0700 | [diff] [blame] | 365 | // The default stack size for managed threads created by the runtime. |
Elliott Hughes | be759c6 | 2011-09-08 19:38:21 -0700 | [diff] [blame] | 366 | size_t default_stack_size_; |
Brian Carlstrom | b765be0 | 2011-08-17 23:54:10 -0700 | [diff] [blame] | 367 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 368 | Heap* heap_; |
| 369 | |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 370 | MonitorList* monitor_list_; |
| 371 | |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 372 | ThreadList* thread_list_; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 373 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 374 | InternTable* intern_table_; |
| 375 | |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 376 | ClassLinker* class_linker_; |
| 377 | |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 378 | SignalCatcher* signal_catcher_; |
Elliott Hughes | 94ce37a | 2011-10-18 15:07:48 -0700 | [diff] [blame] | 379 | std::string stack_trace_file_; |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 380 | |
Elliott Hughes | c5f7c91 | 2011-08-18 14:00:42 -0700 | [diff] [blame] | 381 | JavaVMExt* java_vm_; |
Elliott Hughes | f2682d5 | 2011-08-15 16:37:04 -0700 | [diff] [blame] | 382 | |
Elliott Hughes | 225f5a1 | 2012-06-11 11:23:48 -0700 | [diff] [blame] | 383 | Throwable* pre_allocated_OutOfMemoryError_; |
| 384 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 385 | ByteArray* jni_stub_array_; |
| 386 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 387 | ByteArray* abstract_method_error_stub_array_; |
| 388 | |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 389 | ByteArray* resolution_stub_array_[kLastTrampolineMethodType]; |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 390 | |
Elliott Hughes | 225f5a1 | 2012-06-11 11:23:48 -0700 | [diff] [blame] | 391 | Method* callee_save_methods_[kLastCalleeSaveType]; |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 392 | |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 393 | Method* resolution_method_; |
| 394 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 395 | // As returned by ClassLoader.getSystemClassLoader() |
| 396 | ClassLoader* system_class_loader_; |
| 397 | |
Elliott Hughes | 6b35575 | 2012-01-13 16:49:08 -0800 | [diff] [blame] | 398 | bool shutting_down_; |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 399 | bool started_; |
| 400 | |
Mathieu Chartier | 7664f5c | 2012-06-08 18:15:32 -0700 | [diff] [blame] | 401 | // New flag added which tells us if the runtime has finished starting. If |
| 402 | // this flag is set then the Daemon threads are created and the class loader |
| 403 | // is created. This flag is needed for knowing if its safe to request CMS. |
| 404 | bool finished_starting_; |
| 405 | |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 406 | // Hooks supported by JNI_CreateJavaVM |
| 407 | jint (*vfprintf_)(FILE* stream, const char* format, va_list ap); |
| 408 | void (*exit_)(jint status); |
| 409 | void (*abort_)(); |
| 410 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 411 | bool stats_enabled_; |
| 412 | RuntimeStats stats_; |
| 413 | |
jeffhao | b5e8185 | 2012-03-12 11:15:45 -0700 | [diff] [blame] | 414 | bool method_trace_; |
| 415 | std::string method_trace_file_; |
| 416 | size_t method_trace_file_size_; |
jeffhao | 2692b57 | 2011-12-16 15:42:28 -0800 | [diff] [blame] | 417 | Trace* tracer_; |
| 418 | |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 419 | typedef SafeMap<const ClassLoader*, std::vector<const DexFile*> > CompileTimeClassPaths; |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 420 | CompileTimeClassPaths compile_time_class_paths_; |
| 421 | bool use_compile_time_class_path_; |
Elliott Hughes | 131aef8 | 2012-01-27 11:53:35 -0800 | [diff] [blame] | 422 | |
Ian Rogers | 365c102 | 2012-06-22 15:05:28 -0700 | [diff] [blame^] | 423 | jobject main_thread_group_; |
| 424 | jobject system_thread_group_; |
| 425 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 426 | DISALLOW_COPY_AND_ASSIGN(Runtime); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 427 | }; |
| 428 | |
| 429 | } // namespace art |
| 430 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 431 | #endif // ART_SRC_RUNTIME_H_ |