blob: fd9cc8c23bb100aff6dd15237792d12cb8fd366e [file] [log] [blame]
Carl Shapiro1fb86202011-06-27 17:43:13 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07003#include "runtime.h"
Carl Shapiro1fb86202011-06-27 17:43:13 -07004
Elliott Hughesffe67362011-07-17 12:09:27 -07005#include <cstdio>
6#include <cstdlib>
Brian Carlstrom8a436592011-08-15 21:27:23 -07007#include <limits>
Carl Shapiro2ed144c2011-07-26 16:52:08 -07008#include <vector>
Elliott Hughesffe67362011-07-17 12:09:27 -07009
Brian Carlstromaded5f72011-10-07 17:15:04 -070010#include "ScopedLocalRef.h"
Elliott Hughes90a33692011-08-30 13:27:07 -070011#include "UniquePtr.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070012#include "class_linker.h"
Brian Carlstromaded5f72011-10-07 17:15:04 -070013#include "class_loader.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070014#include "heap.h"
Brian Carlstrome24fa612011-09-29 00:53:55 -070015#include "image.h"
Elliott Hughescf4c6c42011-09-01 15:16:42 -070016#include "intern_table.h"
Elliott Hughesc5f7c912011-08-18 14:00:42 -070017#include "jni_internal.h"
Elliott Hughes32d6e1e2011-10-11 14:47:44 -070018#include "monitor.h"
Brian Carlstrome24fa612011-09-29 00:53:55 -070019#include "oat_file.h"
Elliott Hughes726079d2011-10-07 18:43:44 -070020#include "ScopedLocalRef.h"
Elliott Hughese27955c2011-08-26 15:21:24 -070021#include "signal_catcher.h"
Brian Carlstrome24fa612011-09-29 00:53:55 -070022#include "space.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070023#include "thread.h"
Elliott Hughes8daa0922011-09-11 13:46:25 -070024#include "thread_list.h"
Carl Shapiro61e019d2011-07-14 16:53:09 -070025
Elliott Hughes90a33692011-08-30 13:27:07 -070026// TODO: this drags in cutil/log.h, which conflicts with our logging.h.
27#include "JniConstants.h"
28
Carl Shapiro1fb86202011-06-27 17:43:13 -070029namespace art {
30
Carl Shapiro2ed144c2011-07-26 16:52:08 -070031Runtime* Runtime::instance_ = NULL;
32
Elliott Hughesdcc24742011-09-07 14:02:44 -070033Runtime::Runtime()
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -070034 : verbose_startup_(false),
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -070035 is_zygote_(false),
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -070036 default_stack_size_(Thread::kDefaultStackSize),
Elliott Hughesc33a32b2011-10-11 18:18:07 -070037 monitor_list_(NULL),
Elliott Hughesdcc24742011-09-07 14:02:44 -070038 thread_list_(NULL),
39 intern_table_(NULL),
40 class_linker_(NULL),
41 signal_catcher_(NULL),
42 java_vm_(NULL),
Brian Carlstrom16192862011-09-12 17:50:06 -070043 jni_stub_array_(NULL),
Brian Carlstrome24fa612011-09-29 00:53:55 -070044 abstract_method_error_stub_array_(NULL),
Elliott Hughesdcc24742011-09-07 14:02:44 -070045 started_(false),
46 vfprintf_(NULL),
47 exit_(NULL),
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070048 abort_(NULL),
49 stats_enabled_(false) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -070050 for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) {
51 resolution_stub_array_[i] = NULL;
52 }
53 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
54 callee_save_method_[i] = NULL;
55 }
Elliott Hughesdcc24742011-09-07 14:02:44 -070056}
57
Carl Shapiro61e019d2011-07-14 16:53:09 -070058Runtime::~Runtime() {
Elliott Hughes5fe594f2011-09-08 12:33:17 -070059 // Make sure our internal threads are dead before we start tearing down things they're using.
60 delete signal_catcher_;
Elliott Hughes038a8062011-09-18 14:12:41 -070061 // TODO: GC thread.
Elliott Hughes5fe594f2011-09-08 12:33:17 -070062
Elliott Hughes038a8062011-09-18 14:12:41 -070063 // Make sure all other non-daemon threads have terminated, and all daemon threads are suspended.
Elliott Hughes93e74e82011-09-13 11:07:03 -070064 delete thread_list_;
Elliott Hughesc33a32b2011-10-11 18:18:07 -070065 delete monitor_list_;
Elliott Hughes93e74e82011-09-13 11:07:03 -070066
Carl Shapiro61e019d2011-07-14 16:53:09 -070067 delete class_linker_;
Carl Shapiro69759ea2011-07-21 18:13:35 -070068 Heap::Destroy();
Elliott Hughescf4c6c42011-09-01 15:16:42 -070069 delete intern_table_;
Elliott Hughesc5f7c912011-08-18 14:00:42 -070070 delete java_vm_;
Elliott Hughesc1674ed2011-08-25 18:09:09 -070071 Thread::Shutdown();
Carl Shapiro4acf4642011-07-26 18:54:13 -070072 // TODO: acquire a static mutex on Runtime to avoid racing.
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070073 CHECK(instance_ == NULL || instance_ == this);
Carl Shapiro4acf4642011-07-26 18:54:13 -070074 instance_ = NULL;
Carl Shapiro61e019d2011-07-14 16:53:09 -070075}
76
Elliott Hughesffe67362011-07-17 12:09:27 -070077void Runtime::Abort(const char* file, int line) {
78 // Get any pending output out of the way.
79 fflush(NULL);
80
81 // Many people have difficulty distinguish aborts from crashes,
82 // so be explicit.
83 LogMessage(file, line, ERROR, -1).stream() << "Runtime aborting...";
84
Elliott Hughesffe67362011-07-17 12:09:27 -070085 // Perform any platform-specific pre-abort actions.
86 PlatformAbort(file, line);
87
Brian Carlstrom6ea095a2011-08-16 15:26:54 -070088 // use abort hook if we have one
89 if (Runtime::Current() != NULL && Runtime::Current()->abort_ != NULL) {
90 Runtime::Current()->abort_();
91 // notreached
92 }
93
Elliott Hughesffe67362011-07-17 12:09:27 -070094 // If we call abort(3) on a device, all threads in the process
Carl Shapiro69759ea2011-07-21 18:13:35 -070095 // receive SIGABRT. debuggerd dumps the stack trace of the main
96 // thread, whether or not that was the thread that failed. By
97 // stuffing a value into a bogus address, we cause a segmentation
Elliott Hughesffe67362011-07-17 12:09:27 -070098 // fault in the current thread, and get a useful log from debuggerd.
99 // We can also trivially tell the difference between a VM crash and
100 // a deliberate abort by looking at the fault address.
101 *reinterpret_cast<char*>(0xdeadd00d) = 38;
102 abort();
Elliott Hughesffe67362011-07-17 12:09:27 -0700103 // notreached
104}
105
Elliott Hughesbf86d042011-08-31 17:53:14 -0700106void Runtime::CallExitHook(jint status) {
107 if (exit_ != NULL) {
108 ScopedThreadStateChange tsc(Thread::Current(), Thread::kNative);
109 exit_(status);
110 LOG(WARNING) << "Exit hook returned instead of exiting!";
111 }
112}
113
Brian Carlstrom8a436592011-08-15 21:27:23 -0700114// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
115// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
116// [gG] gigabytes.
117//
118// "s" should point just past the "-Xm?" part of the string.
Brian Carlstrom8a436592011-08-15 21:27:23 -0700119// "div" specifies a divisor, e.g. 1024 if the value must be a multiple
120// of 1024.
121//
122// The spec says the -Xmx and -Xms options must be multiples of 1024. It
123// doesn't say anything about -Xss.
124//
125// Returns 0 (a useless size) if "s" is malformed or specifies a low or
126// non-evenly-divisible value.
127//
128size_t ParseMemoryOption(const char *s, size_t div) {
129 // strtoul accepts a leading [+-], which we don't want,
130 // so make sure our string starts with a decimal digit.
131 if (isdigit(*s)) {
132 const char *s2;
133 size_t val = strtoul(s, (char **)&s2, 10);
134 if (s2 != s) {
135 // s2 should be pointing just after the number.
136 // If this is the end of the string, the user
137 // has specified a number of bytes. Otherwise,
138 // there should be exactly one more character
139 // that specifies a multiplier.
140 if (*s2 != '\0') {
Brian Carlstromf734cf52011-08-17 16:28:14 -0700141 // The remainder of the string is either a single multiplier
142 // character, or nothing to indicate that the value is in
143 // bytes.
144 char c = *s2++;
145 if (*s2 == '\0') {
146 size_t mul;
147 if (c == '\0') {
148 mul = 1;
149 } else if (c == 'k' || c == 'K') {
150 mul = KB;
151 } else if (c == 'm' || c == 'M') {
152 mul = MB;
153 } else if (c == 'g' || c == 'G') {
154 mul = GB;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700155 } else {
Brian Carlstromf734cf52011-08-17 16:28:14 -0700156 // Unknown multiplier character.
Brian Carlstrom8a436592011-08-15 21:27:23 -0700157 return 0;
158 }
Brian Carlstromf734cf52011-08-17 16:28:14 -0700159
160 if (val <= std::numeric_limits<size_t>::max() / mul) {
161 val *= mul;
162 } else {
163 // Clamp to a multiple of 1024.
164 val = std::numeric_limits<size_t>::max() & ~(1024-1);
165 }
166 } else {
167 // There's more than one character after the numeric part.
168 return 0;
169 }
Brian Carlstrom8a436592011-08-15 21:27:23 -0700170 }
171 // The man page says that a -Xm value must be a multiple of 1024.
172 if (val % div == 0) {
173 return val;
174 }
Carl Shapirofc322c72011-07-27 00:20:01 -0700175 }
176 }
Brian Carlstrom8a436592011-08-15 21:27:23 -0700177 return 0;
Carl Shapirofc322c72011-07-27 00:20:01 -0700178}
179
Elliott Hughes0af55432011-08-17 18:37:28 -0700180void LoadJniLibrary(JavaVMExt* vm, const char* name) {
181 // TODO: OS_SHARED_LIB_FORMAT_STR
182 std::string mapped_name(StringPrintf("lib%s.so", name));
Elliott Hughes75770752011-08-24 17:52:38 -0700183 std::string reason;
184 if (!vm->LoadNativeLibrary(mapped_name, NULL, reason)) {
Elliott Hughes0af55432011-08-17 18:37:28 -0700185 LOG(FATAL) << "LoadNativeLibrary failed for \"" << mapped_name << "\": "
186 << reason;
187 }
188}
189
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700190Runtime::ParsedOptions* Runtime::ParsedOptions::Create(const Options& options, bool ignore_unrecognized) {
Elliott Hughes90a33692011-08-30 13:27:07 -0700191 UniquePtr<ParsedOptions> parsed(new ParsedOptions());
Brian Carlstrom5de8fe52011-10-16 14:10:09 -0700192 bool compiler = false;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700193 const char* boot_class_path = getenv("BOOTCLASSPATH");
194 if (boot_class_path != NULL) {
195 parsed->boot_class_path_ = getenv("BOOTCLASSPATH");
196 }
197 const char* class_path = getenv("CLASSPATH");
198 if (class_path != NULL) {
199 parsed->class_path_ = getenv("CLASSPATH");
200 }
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700201#ifdef NDEBUG
Elliott Hughes5174fe62011-08-23 15:12:35 -0700202 // -Xcheck:jni is off by default for regular builds...
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700203 parsed->check_jni_ = false;
204#else
205 // ...but on by default in debug builds.
206 parsed->check_jni_ = true;
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700207#endif
Elliott Hughes85d15452011-09-16 17:33:01 -0700208
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700209 parsed->heap_initial_size_ = Heap::kInitialSize;
210 parsed->heap_maximum_size_ = Heap::kMaximumSize;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700211 parsed->stack_size_ = Thread::kDefaultStackSize;
212
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700213 parsed->is_zygote_ = false;
214
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700215 parsed->hook_vfprintf_ = vfprintf;
216 parsed->hook_exit_ = exit;
217 parsed->hook_abort_ = abort;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700218
219 for (size_t i = 0; i < options.size(); ++i) {
220 const StringPiece& option = options[i].first;
Brian Carlstrom0796af02011-10-12 14:31:45 -0700221 if (true && options[0].first == "-Xzygote") {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700222 LOG(INFO) << "option[" << i << "]=" << option;
223 }
Brian Carlstrom8a436592011-08-15 21:27:23 -0700224 if (option.starts_with("-Xbootclasspath:")) {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700225 parsed->boot_class_path_ = option.substr(strlen("-Xbootclasspath:")).data();
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700226 } else if (option == "-classpath" || option == "-cp") {
227 // TODO: support -Djava.class.path
228 i++;
229 if (i == options.size()) {
230 // TODO: usage
231 LOG(FATAL) << "Missing required class path value for " << option;
232 return NULL;
233 }
234 const StringPiece& value = options[i].first;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700235 parsed->class_path_ = value.data();
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700236 } else if (option.starts_with("-Ximage:")) {
237 parsed->images_.push_back(option.substr(strlen("-Ximage:")).data());
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700238 } else if (option.starts_with("-Xcheck:jni")) {
239 parsed->check_jni_ = true;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700240 } else if (option.starts_with("-Xms")) {
Brian Carlstromf734cf52011-08-17 16:28:14 -0700241 size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).data(), 1024);
242 if (size == 0) {
243 if (ignore_unrecognized) {
244 continue;
245 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700246 // TODO: usage
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700247 LOG(FATAL) << "Failed to parse " << option;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700248 return NULL;
249 }
250 parsed->heap_initial_size_ = size;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700251 } else if (option.starts_with("-Xmx")) {
Brian Carlstromf734cf52011-08-17 16:28:14 -0700252 size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).data(), 1024);
253 if (size == 0) {
254 if (ignore_unrecognized) {
255 continue;
256 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700257 // TODO: usage
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700258 LOG(FATAL) << "Failed to parse " << option;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700259 return NULL;
260 }
261 parsed->heap_maximum_size_ = size;
262 } else if (option.starts_with("-Xss")) {
263 size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).data(), 1);
264 if (size == 0) {
265 if (ignore_unrecognized) {
266 continue;
267 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700268 // TODO: usage
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700269 LOG(FATAL) << "Failed to parse " << option;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700270 return NULL;
271 }
272 parsed->stack_size_ = size;
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700273 } else if (option.starts_with("-D")) {
274 parsed->properties_.push_back(option.substr(strlen("-D")).data());
Elliott Hughesa0957642011-09-02 14:27:33 -0700275 } else if (option.starts_with("-Xjnitrace:")) {
276 parsed->jni_trace_ = option.substr(strlen("-Xjnitrace:")).data();
Brian Carlstrom5de8fe52011-10-16 14:10:09 -0700277 } else if (option == "compiler") {
278 compiler = true;
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700279 } else if (option == "-Xzygote") {
280 parsed->is_zygote_ = true;
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700281 } else if (option.starts_with("-verbose:")) {
Elliott Hughes0af55432011-08-17 18:37:28 -0700282 std::vector<std::string> verbose_options;
Elliott Hughes34023802011-08-30 12:06:17 -0700283 Split(option.substr(strlen("-verbose:")).data(), ',', verbose_options);
Elliott Hughes0af55432011-08-17 18:37:28 -0700284 for (size_t i = 0; i < verbose_options.size(); ++i) {
285 parsed->verbose_.insert(verbose_options[i]);
286 }
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700287 } else if (option == "vfprintf") {
288 parsed->hook_vfprintf_ = reinterpret_cast<int (*)(FILE *, const char*, va_list)>(options[i].second);
289 } else if (option == "exit") {
290 parsed->hook_exit_ = reinterpret_cast<void(*)(jint)>(options[i].second);
291 } else if (option == "abort") {
292 parsed->hook_abort_ = reinterpret_cast<void(*)()>(options[i].second);
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700293 } else if (option == "host-prefix") {
294 parsed->host_prefix_ = reinterpret_cast<const char*>(options[i].second);
Brian Carlstrom8a436592011-08-15 21:27:23 -0700295 } else {
296 if (!ignore_unrecognized) {
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700297 // TODO: print usage via vfprintf
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700298 LOG(ERROR) << "Unrecognized option " << option;
299 // TODO: this should exit, but for now tolerate unknown options
300 //return NULL;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700301 }
302 }
303 }
304
Brian Carlstrom5de8fe52011-10-16 14:10:09 -0700305 if (!compiler && parsed->images_.empty()) {
306 parsed->images_.push_back("/data/art-cache/boot.art");
307 }
308
Elliott Hughes85d15452011-09-16 17:33:01 -0700309 LOG(INFO) << "CheckJNI is " << (parsed->check_jni_ ? "on" : "off");
310
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700311 return parsed.release();
Brian Carlstrom8a436592011-08-15 21:27:23 -0700312}
313
314Runtime* Runtime::Create(const Options& options, bool ignore_unrecognized) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -0700315 // TODO: acquire a static mutex on Runtime to avoid racing.
316 if (Runtime::instance_ != NULL) {
317 return NULL;
318 }
Elliott Hughesdcc24742011-09-07 14:02:44 -0700319 instance_ = new Runtime;
320 if (!instance_->Init(options, ignore_unrecognized)) {
321 delete instance_;
322 instance_ = NULL;
Carl Shapiro61e019d2011-07-14 16:53:09 -0700323 }
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700324 return instance_;
325}
Elliott Hughes0af55432011-08-17 18:37:28 -0700326
Brian Carlstromaded5f72011-10-07 17:15:04 -0700327void CreateSystemClassLoader() {
328 if (ClassLoader::UseCompileTimeClassPath()) {
329 return;
330 }
331
332 Thread* self = Thread::Current();
333
334 // Must be in the kNative state for calling native methods.
335 CHECK_EQ(self->GetState(), Thread::kNative);
336
337 JNIEnv* env = self->GetJniEnv();
Brian Carlstromdf143242011-10-10 18:05:34 -0700338 ScopedLocalRef<jclass> ClassLoader_class(env, env->FindClass("java/lang/ClassLoader"));
339 CHECK(ClassLoader_class.get() != NULL);
340 jmethodID getSystemClassLoader = env->GetStaticMethodID(ClassLoader_class.get(),
341 "getSystemClassLoader",
342 "()Ljava/lang/ClassLoader;");
343 CHECK(getSystemClassLoader != NULL);
344 ScopedLocalRef<jobject> class_loader(env, env->CallStaticObjectMethod(ClassLoader_class.get(),
345 getSystemClassLoader));
346 CHECK(class_loader.get() != NULL);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700347
Brian Carlstromdf143242011-10-10 18:05:34 -0700348 Thread::Current()->SetClassLoaderOverride(Decode<ClassLoader*>(env, class_loader.get()));
Brian Carlstromaded5f72011-10-07 17:15:04 -0700349}
350
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700351void Runtime::Start() {
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700352 if (IsVerboseStartup()) {
353 LOG(INFO) << "Runtime::Start entering";
354 }
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700355
356 CHECK(host_prefix_.empty()) << host_prefix_;
357
Elliott Hughes038a8062011-09-18 14:12:41 -0700358 InitNativeMethods();
Elliott Hughes85d15452011-09-16 17:33:01 -0700359
Elliott Hughes038a8062011-09-18 14:12:41 -0700360 Thread::FinishStartup();
Elliott Hughes85d15452011-09-16 17:33:01 -0700361
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700362 class_linker_->RunRootClinits();
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700363
Brian Carlstrom5d40f182011-09-26 22:29:18 -0700364 // Class::AllocObject asserts that all objects allocated better be
365 // initialized after Runtime::IsStarted is true, so this needs to
366 // come after ClassLinker::RunRootClinits.
367 started_ = true;
368
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700369 StartSignalCatcher();
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700370
Elliott Hughes85d15452011-09-16 17:33:01 -0700371 StartDaemonThreads();
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700372
Brian Carlstromaded5f72011-10-07 17:15:04 -0700373 CreateSystemClassLoader();
374
Elliott Hughes726079d2011-10-07 18:43:44 -0700375 Thread::Current()->GetJniEnv()->locals.AssertEmpty();
376
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700377 if (IsVerboseStartup()) {
378 LOG(INFO) << "Runtime::Start exiting";
379 }
Elliott Hughes85d15452011-09-16 17:33:01 -0700380}
381
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700382void Runtime::DidForkFromZygote() {
383 CHECK(is_zygote_);
384 is_zygote_ = false;
385 StartSignalCatcher();
386}
387
388void Runtime::StartSignalCatcher() {
389 if (!is_zygote_) {
390 signal_catcher_ = new SignalCatcher;
391 }
392}
393
Elliott Hughes85d15452011-09-16 17:33:01 -0700394void Runtime::StartDaemonThreads() {
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700395 if (IsVerboseStartup()) {
396 LOG(INFO) << "Runtime::StartDaemonThreads entering";
397 }
Elliott Hughes85d15452011-09-16 17:33:01 -0700398
Elliott Hughes719b3232011-09-25 17:42:19 -0700399 Thread* self = Thread::Current();
Brian Carlstromaded5f72011-10-07 17:15:04 -0700400
401 // Must be in the kNative state for calling native methods.
402 CHECK_EQ(self->GetState(), Thread::kNative);
403
Elliott Hughes719b3232011-09-25 17:42:19 -0700404 JNIEnv* env = self->GetJniEnv();
Elliott Hughes726079d2011-10-07 18:43:44 -0700405 ScopedLocalRef<jclass> c(env, env->FindClass("java/lang/Daemons"));
406 CHECK(c.get() != NULL);
407 jmethodID mid = env->GetStaticMethodID(c.get(), "start", "()V");
Elliott Hughes719b3232011-09-25 17:42:19 -0700408 CHECK(mid != NULL);
Elliott Hughes726079d2011-10-07 18:43:44 -0700409 env->CallStaticVoidMethod(c.get(), mid);
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700410
411 if (IsVerboseStartup()) {
412 LOG(INFO) << "Runtime::StartDaemonThreads exiting";
413 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700414}
415
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700416bool Runtime::IsStarted() const {
Elliott Hughesdcc24742011-09-07 14:02:44 -0700417 return started_;
418}
419
Elliott Hughes0af55432011-08-17 18:37:28 -0700420bool Runtime::Init(const Options& raw_options, bool ignore_unrecognized) {
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700421 CHECK_EQ(sysconf(_SC_PAGE_SIZE), kPageSize);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700422
Elliott Hughes90a33692011-08-30 13:27:07 -0700423 UniquePtr<ParsedOptions> options(ParsedOptions::Create(raw_options, ignore_unrecognized));
424 if (options.get() == NULL) {
Brian Carlstrome24fa612011-09-29 00:53:55 -0700425 LOG(ERROR) << "Failed to parse options";
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700426 return false;
427 }
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700428 verbose_startup_ = options->IsVerbose("startup");
429 if (IsVerboseStartup()) {
430 LOG(INFO) << "Runtime::Init -verbose:startup enabled";
431 }
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700432
Elliott Hughes32d6e1e2011-10-11 14:47:44 -0700433 Monitor::SetVerbose(options->IsVerbose("monitor"));
434
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700435 host_prefix_ = options->host_prefix_;
436 boot_class_path_ = options->boot_class_path_;
437 class_path_ = options->class_path_;
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700438 properties_ = options->properties_;
439
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700440 is_zygote_ = options->is_zygote_;
441
Elliott Hughes0af55432011-08-17 18:37:28 -0700442 vfprintf_ = options->hook_vfprintf_;
443 exit_ = options->hook_exit_;
444 abort_ = options->hook_abort_;
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700445
Elliott Hughesbe759c62011-09-08 19:38:21 -0700446 default_stack_size_ = options->stack_size_;
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700447
Elliott Hughesc33a32b2011-10-11 18:18:07 -0700448 monitor_list_ = new MonitorList;
Elliott Hughes14357e82011-09-26 10:42:15 -0700449 thread_list_ = new ThreadList(options->IsVerbose("thread"));
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700450 intern_table_ = new InternTable;
451
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700452 Heap::Init(options->heap_initial_size_, options->heap_maximum_size_, options->images_);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700453
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700454 BlockSignals();
455
Elliott Hughesa0957642011-09-02 14:27:33 -0700456 java_vm_ = new JavaVMExt(this, options.get());
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700457
Elliott Hughesbe759c62011-09-08 19:38:21 -0700458 Thread::Startup();
Elliott Hughesd92bec42011-09-02 17:04:36 -0700459
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700460 // ClassLinker needs an attached thread, but we can't fully attach a thread
461 // without creating objects.
462 Thread::Attach(this, "main", false);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700463
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700464 CHECK_GE(Heap::GetSpaces().size(), 1U);
465 class_linker_ = ((Heap::GetSpaces()[0]->IsImageSpace())
466 ? ClassLinker::Create(intern_table_)
467 : ClassLinker::Create(options->boot_class_path_, intern_table_));
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700468
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700469 if (IsVerboseStartup()) {
470 LOG(INFO) << "Runtime::Init exiting";
471 }
Carl Shapiro1fb86202011-06-27 17:43:13 -0700472 return true;
473}
474
Elliott Hughes038a8062011-09-18 14:12:41 -0700475void Runtime::InitNativeMethods() {
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700476 if (IsVerboseStartup()) {
477 LOG(INFO) << "Runtime::InitNativeMethods entering";
478 }
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700479 Thread* self = Thread::Current();
480 JNIEnv* env = self->GetJniEnv();
481
Elliott Hughes418d20f2011-09-22 14:00:39 -0700482 // Must be in the kNative state for calling native methods (JNI_OnLoad code).
Brian Carlstromaded5f72011-10-07 17:15:04 -0700483 CHECK_EQ(self->GetState(), Thread::kNative);
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700484
Elliott Hughes418d20f2011-09-22 14:00:39 -0700485 // First set up JniConstants, which is used by both the runtime's built-in native
486 // methods and libcore.
Elliott Hughesfea966e2011-09-22 10:26:20 -0700487 JniConstants::init(env);
488
Elliott Hughes418d20f2011-09-22 14:00:39 -0700489 // Then set up the native methods provided by the runtime itself.
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700490 RegisterRuntimeNativeMethods(env);
491
Elliott Hughes418d20f2011-09-22 14:00:39 -0700492 // Then set up libcore, which is just a regular JNI library with a regular JNI_OnLoad.
493 // Most JNI libraries can just use System.loadLibrary, but libcore can't because it's
494 // the library that implements System.loadLibrary!
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700495 LoadJniLibrary(instance_->GetJavaVM(), "javacore");
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700496 if (IsVerboseStartup()) {
497 LOG(INFO) << "Runtime::InitNativeMethods exiting";
498 }
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700499}
500
501void Runtime::RegisterRuntimeNativeMethods(JNIEnv* env) {
502#define REGISTER(FN) extern void FN(JNIEnv*); FN(env)
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700503 REGISTER(register_dalvik_system_DexFile);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700504 REGISTER(register_dalvik_system_VMDebug);
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700505 REGISTER(register_dalvik_system_VMRuntime);
Elliott Hughes8daa0922011-09-11 13:46:25 -0700506 REGISTER(register_dalvik_system_VMStack);
Elliott Hughes01158d72011-09-19 19:47:10 -0700507 REGISTER(register_dalvik_system_Zygote);
Elliott Hughesd369bb72011-09-12 14:41:14 -0700508 REGISTER(register_java_lang_Class);
Elliott Hughesbf86d042011-08-31 17:53:14 -0700509 REGISTER(register_java_lang_Object);
510 REGISTER(register_java_lang_Runtime);
511 REGISTER(register_java_lang_String);
512 REGISTER(register_java_lang_System);
Elliott Hughes8daa0922011-09-11 13:46:25 -0700513 REGISTER(register_java_lang_Thread);
Elliott Hughes1240dad2011-09-09 16:24:50 -0700514 REGISTER(register_java_lang_Throwable);
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700515 REGISTER(register_java_lang_VMClassLoader);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700516 REGISTER(register_java_lang_reflect_Array);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700517 REGISTER(register_java_lang_reflect_Constructor);
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700518 REGISTER(register_java_lang_reflect_Field);
519 REGISTER(register_java_lang_reflect_Method);
Jesse Wilson95caa792011-10-12 18:14:17 -0400520 REGISTER(register_java_lang_reflect_Proxy);
Elliott Hughesbf86d042011-08-31 17:53:14 -0700521 REGISTER(register_java_util_concurrent_atomic_AtomicLong);
Brian Carlstrom395520e2011-09-25 19:35:00 -0700522 REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmServer);
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700523 //REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmVmInternal);
Elliott Hughes5ee7a8b2011-09-13 16:40:07 -0700524 REGISTER(register_sun_misc_Unsafe);
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700525#undef REGISTER
526}
527
Elliott Hughes8daa0922011-09-11 13:46:25 -0700528void Runtime::Dump(std::ostream& os) {
Elliott Hughese27955c2011-08-26 15:21:24 -0700529 // TODO: dump other runtime statistics?
530 os << "Loaded classes: " << class_linker_->NumLoadedClasses() << "\n";
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700531 os << "Intern table size: " << GetInternTable()->Size() << "\n";
Elliott Hughese27955c2011-08-26 15:21:24 -0700532 // LOGV("VM stats: meth=%d ifld=%d sfld=%d linear=%d",
533 // gDvm.numDeclaredMethods,
534 // gDvm.numDeclaredInstFields,
535 // gDvm.numDeclaredStaticFields,
536 // gDvm.pBootLoaderAlloc->curOffset);
537 // LOGI("GC precise methods: %d", dvmPointerSetGetCount(gDvm.preciseMethods));
Elliott Hughes42ee1422011-09-06 12:33:32 -0700538 os << "\n";
Elliott Hughes8daa0922011-09-11 13:46:25 -0700539
540 thread_list_->Dump(os);
Elliott Hughese27955c2011-08-26 15:21:24 -0700541}
542
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700543void Runtime::SetStatsEnabled(bool new_state) {
544 if (new_state == true) {
545 GetStats()->Clear(~0);
546 // TODO: wouldn't it make more sense to clear _all_ threads' stats?
547 Thread::Current()->GetStats()->Clear(~0);
548 }
549 stats_enabled_ = new_state;
550}
551
552void Runtime::ResetStats(int kinds) {
553 GetStats()->Clear(kinds & 0xffff);
554 // TODO: wouldn't it make more sense to clear _all_ threads' stats?
555 Thread::Current()->GetStats()->Clear(kinds >> 16);
556}
557
558RuntimeStats* Runtime::GetStats() {
559 return &stats_;
560}
561
562int32_t Runtime::GetStat(int kind) {
563 RuntimeStats* stats;
564 if (kind < (1<<16)) {
565 stats = GetStats();
566 } else {
567 stats = Thread::Current()->GetStats();
568 kind >>= 16;
569 }
570 switch (kind) {
571 case KIND_ALLOCATED_OBJECTS:
572 return stats->allocated_objects;
573 case KIND_ALLOCATED_BYTES:
574 return stats->allocated_bytes;
575 case KIND_FREED_OBJECTS:
576 return stats->freed_objects;
577 case KIND_FREED_BYTES:
578 return stats->freed_bytes;
579 case KIND_GC_INVOCATIONS:
580 return stats->gc_for_alloc_count;
581 case KIND_CLASS_INIT_COUNT:
582 return stats->class_init_count;
583 case KIND_CLASS_INIT_TIME:
584 // Convert ns to us, reduce to 32 bits.
585 return (int) (stats->class_init_time_ns / 1000);
586 case KIND_EXT_ALLOCATED_OBJECTS:
587 case KIND_EXT_ALLOCATED_BYTES:
588 case KIND_EXT_FREED_OBJECTS:
589 case KIND_EXT_FREED_BYTES:
590 return 0; // backward compatibility
591 default:
592 CHECK(false);
593 return -1; // unreachable
594 }
595}
596
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700597void Runtime::BlockSignals() {
598 sigset_t sigset;
599 if (sigemptyset(&sigset) == -1) {
600 PLOG(FATAL) << "sigemptyset failed";
601 }
602 if (sigaddset(&sigset, SIGPIPE) == -1) {
603 PLOG(ERROR) << "sigaddset SIGPIPE failed";
604 }
605 // SIGQUIT is used to dump the runtime's state (including stack traces).
606 if (sigaddset(&sigset, SIGQUIT) == -1) {
607 PLOG(ERROR) << "sigaddset SIGQUIT failed";
608 }
609 // SIGUSR1 is used to initiate a heap dump.
610 if (sigaddset(&sigset, SIGUSR1) == -1) {
611 PLOG(ERROR) << "sigaddset SIGUSR1 failed";
612 }
613 CHECK_EQ(sigprocmask(SIG_BLOCK, &sigset, NULL), 0);
614}
615
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700616void Runtime::AttachCurrentThread(const char* name, bool as_daemon) {
617 Thread::Attach(instance_, name, as_daemon);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700618}
619
Elliott Hughesd92bec42011-09-02 17:04:36 -0700620void Runtime::DetachCurrentThread() {
Elliott Hughes038a8062011-09-18 14:12:41 -0700621 // TODO: check we're not calling DetachCurrentThread from a call stack that
622 // includes managed frames. (It's only valid if the stack is all-native.)
Elliott Hughes02b48d12011-09-07 17:15:51 -0700623 thread_list_->Unregister();
Carl Shapiro1fb86202011-06-27 17:43:13 -0700624}
625
Brian Carlstrome24fa612011-09-29 00:53:55 -0700626void Runtime::VisitRoots(Heap::RootVisitor* visitor, void* arg) const {
627 class_linker_->VisitRoots(visitor, arg);
628 intern_table_->VisitRoots(visitor, arg);
629 java_vm_->VisitRoots(visitor, arg);
630 thread_list_->VisitRoots(visitor, arg);
631 visitor(jni_stub_array_, arg);
632 visitor(abstract_method_error_stub_array_, arg);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700633 for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) {
634 visitor(resolution_stub_array_[i], arg);
635 }
636 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
637 visitor(callee_save_method_[i], arg);
638 }
Brian Carlstrome24fa612011-09-29 00:53:55 -0700639}
640
641bool Runtime::HasJniStubArray() const {
642 return jni_stub_array_ != NULL;
643}
644
645ByteArray* Runtime::GetJniStubArray() const {
646 CHECK(jni_stub_array_ != NULL);
647 return jni_stub_array_;
648}
649
650void Runtime::SetJniStubArray(ByteArray* jni_stub_array) {
Brian Carlstromaded5f72011-10-07 17:15:04 -0700651 CHECK(jni_stub_array != NULL) << " jni_stub_array=" << jni_stub_array;
652 CHECK(jni_stub_array_ == NULL || jni_stub_array_ == jni_stub_array)
653 << "jni_stub_array_=" << jni_stub_array_ << " jni_stub_array=" << jni_stub_array;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700654 jni_stub_array_ = jni_stub_array;
655}
656
657bool Runtime::HasAbstractMethodErrorStubArray() const {
658 return abstract_method_error_stub_array_ != NULL;
659}
660
661ByteArray* Runtime::GetAbstractMethodErrorStubArray() const {
662 CHECK(abstract_method_error_stub_array_ != NULL);
663 return abstract_method_error_stub_array_;
664}
665
666void Runtime::SetAbstractMethodErrorStubArray(ByteArray* abstract_method_error_stub_array) {
667 CHECK(abstract_method_error_stub_array != NULL);
668 CHECK(abstract_method_error_stub_array_ == NULL || abstract_method_error_stub_array_ == abstract_method_error_stub_array);
669 abstract_method_error_stub_array_ = abstract_method_error_stub_array;
670}
671
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700672
673Runtime::TrampolineType Runtime::GetTrampolineType(Method* method) {
674 if (method == NULL) {
675 return Runtime::kUnknownMethod;
676 } else if (method->IsStatic()) {
677 return Runtime::kStaticMethod;
678 } else {
679 return Runtime::kInstanceMethod;
680 }
Ian Rogersad25ac52011-10-04 19:13:33 -0700681}
682
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700683bool Runtime::HasResolutionStubArray(TrampolineType type) const {
684 return resolution_stub_array_[type] != NULL;
Ian Rogersad25ac52011-10-04 19:13:33 -0700685}
686
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700687ByteArray* Runtime::GetResolutionStubArray(TrampolineType type) const {
688 CHECK(HasResolutionStubArray(type));
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700689 DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastTrampolineMethodType));
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700690 return resolution_stub_array_[type];
691}
692
693void Runtime::SetResolutionStubArray(ByteArray* resolution_stub_array, TrampolineType type) {
Ian Rogersad25ac52011-10-04 19:13:33 -0700694 CHECK(resolution_stub_array != NULL);
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700695 CHECK(!HasResolutionStubArray(type) || resolution_stub_array_[type] == resolution_stub_array);
696 resolution_stub_array_[type] = resolution_stub_array;
Ian Rogersad25ac52011-10-04 19:13:33 -0700697}
698
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700699Method* Runtime::CreateCalleeSaveMethod(InstructionSet insns, CalleeSaveType type) {
Ian Rogersff1ed472011-09-20 13:46:24 -0700700 Class* method_class = Method::GetMethodClass();
701 Method* method = down_cast<Method*>(method_class->AllocObject());
702 method->SetDeclaringClass(method_class);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700703 const char* name;
704 if (type == kSaveAll) {
705 name = "$$$callee_save_method$$$";
706 } else if (type == kRefsOnly) {
707 name = "$$$refs_only_callee_save_method$$$";
708 } else {
709 DCHECK(type == kRefsAndArgs);
710 name = "$$$refs_and_args_callee_save_method$$$";
711 }
712 method->SetName(intern_table_->InternStrong(name));
Elliott Hughes30646832011-10-13 16:59:46 -0700713 CHECK(method->GetName() != NULL);
Ian Rogersff1ed472011-09-20 13:46:24 -0700714 method->SetSignature(intern_table_->InternStrong("()V"));
Elliott Hughes30646832011-10-13 16:59:46 -0700715 CHECK(method->GetSignature() != NULL);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700716 method->SetCode(NULL);
Ian Rogersff1ed472011-09-20 13:46:24 -0700717 if ((insns == kThumb2) || (insns == kArm)) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700718 uint32_t ref_spills = (1 << art::arm::R5) | (1 << art::arm::R6) | (1 << art::arm::R7) |
719 (1 << art::arm::R8) | (1 << art::arm::R10) | (1 << art::arm::R11);
720 uint32_t arg_spills = (1 << art::arm::R1) | (1 << art::arm::R2) | (1 << art::arm::R3);
721 uint32_t all_spills = (1 << art::arm::R4) | (1 << art::arm::R9);
722 uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills :0) |
723 (type == kSaveAll ? all_spills :0) | (1 << art::arm::LR);
724 uint32_t fp_all_spills = (1 << art::arm::S0) | (1 << art::arm::S1) | (1 << art::arm::S2) |
725 (1 << art::arm::S3) | (1 << art::arm::S4) | (1 << art::arm::S5) |
726 (1 << art::arm::S6) | (1 << art::arm::S7) | (1 << art::arm::S8) |
727 (1 << art::arm::S9) | (1 << art::arm::S10) | (1 << art::arm::S11) |
728 (1 << art::arm::S12) | (1 << art::arm::S13) | (1 << art::arm::S14) |
729 (1 << art::arm::S15) | (1 << art::arm::S16) | (1 << art::arm::S17) |
730 (1 << art::arm::S18) | (1 << art::arm::S19) | (1 << art::arm::S20) |
731 (1 << art::arm::S21) | (1 << art::arm::S22) | (1 << art::arm::S23) |
732 (1 << art::arm::S24) | (1 << art::arm::S25) | (1 << art::arm::S26) |
733 (1 << art::arm::S27) | (1 << art::arm::S28) | (1 << art::arm::S29) |
734 (1 << art::arm::S30) | (1 << art::arm::S31);
735 uint32_t fp_spills = type == kSaveAll ? fp_all_spills : 0;
736 size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ +
737 __builtin_popcount(fp_spills) /* fprs */ +
738 1 /* Method* */) * kPointerSize, kStackAlignment);
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700739 method->SetFrameSizeInBytes(frame_size);
740 method->SetReturnPcOffsetInBytes(frame_size - kPointerSize);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700741 method->SetCoreSpillMask(core_spills);
742 method->SetFpSpillMask(fp_spills);
Ian Rogersff1ed472011-09-20 13:46:24 -0700743 } else if (insns == kX86) {
744 method->SetFrameSizeInBytes(32);
745 method->SetReturnPcOffsetInBytes(28);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700746 method->SetCoreSpillMask((1 << art::x86::EBX) | (1 << art::x86::EBP) | (1 << art::x86::ESI) |
Ian Rogersff1ed472011-09-20 13:46:24 -0700747 (1 << art::x86::EDI));
748 method->SetFpSpillMask(0);
749 } else {
750 UNIMPLEMENTED(FATAL);
751 }
752 return method;
753}
754
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700755bool Runtime::HasCalleeSaveMethod(CalleeSaveType type) const {
756 return callee_save_method_[type] != NULL;
Brian Carlstrom1f870082011-08-23 16:02:11 -0700757}
758
Brian Carlstrome24fa612011-09-29 00:53:55 -0700759// Returns a special method that describes all callee saves being spilled to the stack.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700760Method* Runtime::GetCalleeSaveMethod(CalleeSaveType type) const {
761 CHECK(HasCalleeSaveMethod(type));
762 return callee_save_method_[type];
Brian Carlstrome24fa612011-09-29 00:53:55 -0700763}
764
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700765void Runtime::SetCalleeSaveMethod(Method* method, CalleeSaveType type) {
766 DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastCalleeSaveType));
767 callee_save_method_[type] = method;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700768}
769
Carl Shapiro1fb86202011-06-27 17:43:13 -0700770} // namespace art