blob: 30fb4ded960b4a85c39dc6e369a846cbca85edc0 [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 Carlstrom58ae9412011-10-04 00:56:06 -0700192 const char* boot_class_path = getenv("BOOTCLASSPATH");
193 if (boot_class_path != NULL) {
194 parsed->boot_class_path_ = getenv("BOOTCLASSPATH");
195 }
196 const char* class_path = getenv("CLASSPATH");
197 if (class_path != NULL) {
198 parsed->class_path_ = getenv("CLASSPATH");
199 }
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700200#ifdef NDEBUG
Elliott Hughes5174fe62011-08-23 15:12:35 -0700201 // -Xcheck:jni is off by default for regular builds...
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700202 parsed->check_jni_ = false;
203#else
204 // ...but on by default in debug builds.
205 parsed->check_jni_ = true;
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700206#endif
Elliott Hughes85d15452011-09-16 17:33:01 -0700207
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700208 parsed->heap_initial_size_ = Heap::kInitialSize;
209 parsed->heap_maximum_size_ = Heap::kMaximumSize;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700210 parsed->stack_size_ = Thread::kDefaultStackSize;
211
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700212 parsed->is_zygote_ = false;
213
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700214 parsed->hook_vfprintf_ = vfprintf;
215 parsed->hook_exit_ = exit;
216 parsed->hook_abort_ = abort;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700217
218 for (size_t i = 0; i < options.size(); ++i) {
219 const StringPiece& option = options[i].first;
Brian Carlstrom0796af02011-10-12 14:31:45 -0700220 if (true && options[0].first == "-Xzygote") {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700221 LOG(INFO) << "option[" << i << "]=" << option;
222 }
Brian Carlstrom8a436592011-08-15 21:27:23 -0700223 if (option.starts_with("-Xbootclasspath:")) {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700224 parsed->boot_class_path_ = option.substr(strlen("-Xbootclasspath:")).data();
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700225 } else if (option == "-classpath" || option == "-cp") {
226 // TODO: support -Djava.class.path
227 i++;
228 if (i == options.size()) {
229 // TODO: usage
230 LOG(FATAL) << "Missing required class path value for " << option;
231 return NULL;
232 }
233 const StringPiece& value = options[i].first;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700234 parsed->class_path_ = value.data();
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700235 } else if (option.starts_with("-Ximage:")) {
236 parsed->images_.push_back(option.substr(strlen("-Ximage:")).data());
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700237 } else if (option.starts_with("-Xcheck:jni")) {
238 parsed->check_jni_ = true;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700239 } else if (option.starts_with("-Xms")) {
Brian Carlstromf734cf52011-08-17 16:28:14 -0700240 size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).data(), 1024);
241 if (size == 0) {
242 if (ignore_unrecognized) {
243 continue;
244 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700245 // TODO: usage
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700246 LOG(FATAL) << "Failed to parse " << option;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700247 return NULL;
248 }
249 parsed->heap_initial_size_ = size;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700250 } else if (option.starts_with("-Xmx")) {
Brian Carlstromf734cf52011-08-17 16:28:14 -0700251 size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).data(), 1024);
252 if (size == 0) {
253 if (ignore_unrecognized) {
254 continue;
255 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700256 // TODO: usage
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700257 LOG(FATAL) << "Failed to parse " << option;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700258 return NULL;
259 }
260 parsed->heap_maximum_size_ = size;
261 } else if (option.starts_with("-Xss")) {
262 size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).data(), 1);
263 if (size == 0) {
264 if (ignore_unrecognized) {
265 continue;
266 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700267 // TODO: usage
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700268 LOG(FATAL) << "Failed to parse " << option;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700269 return NULL;
270 }
271 parsed->stack_size_ = size;
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700272 } else if (option.starts_with("-D")) {
273 parsed->properties_.push_back(option.substr(strlen("-D")).data());
Elliott Hughesa0957642011-09-02 14:27:33 -0700274 } else if (option.starts_with("-Xjnitrace:")) {
275 parsed->jni_trace_ = option.substr(strlen("-Xjnitrace:")).data();
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700276 } else if (option == "-Xzygote") {
277 parsed->is_zygote_ = true;
Brian Carlstrom0796af02011-10-12 14:31:45 -0700278 parsed->images_.push_back("/system/framework/boot.art");
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700279 } else if (option.starts_with("-verbose:")) {
Elliott Hughes0af55432011-08-17 18:37:28 -0700280 std::vector<std::string> verbose_options;
Elliott Hughes34023802011-08-30 12:06:17 -0700281 Split(option.substr(strlen("-verbose:")).data(), ',', verbose_options);
Elliott Hughes0af55432011-08-17 18:37:28 -0700282 for (size_t i = 0; i < verbose_options.size(); ++i) {
283 parsed->verbose_.insert(verbose_options[i]);
284 }
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700285 } else if (option == "vfprintf") {
286 parsed->hook_vfprintf_ = reinterpret_cast<int (*)(FILE *, const char*, va_list)>(options[i].second);
287 } else if (option == "exit") {
288 parsed->hook_exit_ = reinterpret_cast<void(*)(jint)>(options[i].second);
289 } else if (option == "abort") {
290 parsed->hook_abort_ = reinterpret_cast<void(*)()>(options[i].second);
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700291 } else if (option == "host-prefix") {
292 parsed->host_prefix_ = reinterpret_cast<const char*>(options[i].second);
Brian Carlstrom8a436592011-08-15 21:27:23 -0700293 } else {
294 if (!ignore_unrecognized) {
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700295 // TODO: print usage via vfprintf
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700296 LOG(ERROR) << "Unrecognized option " << option;
297 // TODO: this should exit, but for now tolerate unknown options
298 //return NULL;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700299 }
300 }
301 }
302
Elliott Hughes85d15452011-09-16 17:33:01 -0700303 LOG(INFO) << "CheckJNI is " << (parsed->check_jni_ ? "on" : "off");
304
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700305 return parsed.release();
Brian Carlstrom8a436592011-08-15 21:27:23 -0700306}
307
308Runtime* Runtime::Create(const Options& options, bool ignore_unrecognized) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -0700309 // TODO: acquire a static mutex on Runtime to avoid racing.
310 if (Runtime::instance_ != NULL) {
311 return NULL;
312 }
Elliott Hughesdcc24742011-09-07 14:02:44 -0700313 instance_ = new Runtime;
314 if (!instance_->Init(options, ignore_unrecognized)) {
315 delete instance_;
316 instance_ = NULL;
Carl Shapiro61e019d2011-07-14 16:53:09 -0700317 }
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700318 return instance_;
319}
Elliott Hughes0af55432011-08-17 18:37:28 -0700320
Brian Carlstromaded5f72011-10-07 17:15:04 -0700321void CreateSystemClassLoader() {
322 if (ClassLoader::UseCompileTimeClassPath()) {
323 return;
324 }
325
326 Thread* self = Thread::Current();
327
328 // Must be in the kNative state for calling native methods.
329 CHECK_EQ(self->GetState(), Thread::kNative);
330
331 JNIEnv* env = self->GetJniEnv();
Brian Carlstromdf143242011-10-10 18:05:34 -0700332 ScopedLocalRef<jclass> ClassLoader_class(env, env->FindClass("java/lang/ClassLoader"));
333 CHECK(ClassLoader_class.get() != NULL);
334 jmethodID getSystemClassLoader = env->GetStaticMethodID(ClassLoader_class.get(),
335 "getSystemClassLoader",
336 "()Ljava/lang/ClassLoader;");
337 CHECK(getSystemClassLoader != NULL);
338 ScopedLocalRef<jobject> class_loader(env, env->CallStaticObjectMethod(ClassLoader_class.get(),
339 getSystemClassLoader));
340 CHECK(class_loader.get() != NULL);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700341
Brian Carlstromdf143242011-10-10 18:05:34 -0700342 Thread::Current()->SetClassLoaderOverride(Decode<ClassLoader*>(env, class_loader.get()));
Brian Carlstromaded5f72011-10-07 17:15:04 -0700343}
344
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700345void Runtime::Start() {
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700346 if (IsVerboseStartup()) {
347 LOG(INFO) << "Runtime::Start entering";
348 }
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700349
350 CHECK(host_prefix_.empty()) << host_prefix_;
351
Elliott Hughes038a8062011-09-18 14:12:41 -0700352 InitNativeMethods();
Elliott Hughes85d15452011-09-16 17:33:01 -0700353
Elliott Hughes038a8062011-09-18 14:12:41 -0700354 Thread::FinishStartup();
Elliott Hughes85d15452011-09-16 17:33:01 -0700355
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700356 class_linker_->RunRootClinits();
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700357
Brian Carlstrom5d40f182011-09-26 22:29:18 -0700358 // Class::AllocObject asserts that all objects allocated better be
359 // initialized after Runtime::IsStarted is true, so this needs to
360 // come after ClassLinker::RunRootClinits.
361 started_ = true;
362
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700363 StartSignalCatcher();
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700364
Elliott Hughes85d15452011-09-16 17:33:01 -0700365 StartDaemonThreads();
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700366
Brian Carlstromaded5f72011-10-07 17:15:04 -0700367 CreateSystemClassLoader();
368
Elliott Hughes726079d2011-10-07 18:43:44 -0700369 Thread::Current()->GetJniEnv()->locals.AssertEmpty();
370
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700371 if (IsVerboseStartup()) {
372 LOG(INFO) << "Runtime::Start exiting";
373 }
Elliott Hughes85d15452011-09-16 17:33:01 -0700374}
375
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700376void Runtime::DidForkFromZygote() {
377 CHECK(is_zygote_);
378 is_zygote_ = false;
379 StartSignalCatcher();
380}
381
382void Runtime::StartSignalCatcher() {
383 if (!is_zygote_) {
384 signal_catcher_ = new SignalCatcher;
385 }
386}
387
Elliott Hughes85d15452011-09-16 17:33:01 -0700388void Runtime::StartDaemonThreads() {
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700389 if (IsVerboseStartup()) {
390 LOG(INFO) << "Runtime::StartDaemonThreads entering";
391 }
Elliott Hughes85d15452011-09-16 17:33:01 -0700392
Elliott Hughes719b3232011-09-25 17:42:19 -0700393 Thread* self = Thread::Current();
Brian Carlstromaded5f72011-10-07 17:15:04 -0700394
395 // Must be in the kNative state for calling native methods.
396 CHECK_EQ(self->GetState(), Thread::kNative);
397
Elliott Hughes719b3232011-09-25 17:42:19 -0700398 JNIEnv* env = self->GetJniEnv();
Elliott Hughes726079d2011-10-07 18:43:44 -0700399 ScopedLocalRef<jclass> c(env, env->FindClass("java/lang/Daemons"));
400 CHECK(c.get() != NULL);
401 jmethodID mid = env->GetStaticMethodID(c.get(), "start", "()V");
Elliott Hughes719b3232011-09-25 17:42:19 -0700402 CHECK(mid != NULL);
Elliott Hughes726079d2011-10-07 18:43:44 -0700403 env->CallStaticVoidMethod(c.get(), mid);
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700404
405 if (IsVerboseStartup()) {
406 LOG(INFO) << "Runtime::StartDaemonThreads exiting";
407 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700408}
409
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700410bool Runtime::IsStarted() const {
Elliott Hughesdcc24742011-09-07 14:02:44 -0700411 return started_;
412}
413
Elliott Hughes0af55432011-08-17 18:37:28 -0700414bool Runtime::Init(const Options& raw_options, bool ignore_unrecognized) {
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700415 CHECK_EQ(sysconf(_SC_PAGE_SIZE), kPageSize);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700416
Elliott Hughes90a33692011-08-30 13:27:07 -0700417 UniquePtr<ParsedOptions> options(ParsedOptions::Create(raw_options, ignore_unrecognized));
418 if (options.get() == NULL) {
Brian Carlstrome24fa612011-09-29 00:53:55 -0700419 LOG(ERROR) << "Failed to parse options";
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700420 return false;
421 }
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700422 verbose_startup_ = options->IsVerbose("startup");
423 if (IsVerboseStartup()) {
424 LOG(INFO) << "Runtime::Init -verbose:startup enabled";
425 }
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700426
Elliott Hughes32d6e1e2011-10-11 14:47:44 -0700427 Monitor::SetVerbose(options->IsVerbose("monitor"));
428
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700429 host_prefix_ = options->host_prefix_;
430 boot_class_path_ = options->boot_class_path_;
431 class_path_ = options->class_path_;
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700432 properties_ = options->properties_;
433
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700434 is_zygote_ = options->is_zygote_;
435
Elliott Hughes0af55432011-08-17 18:37:28 -0700436 vfprintf_ = options->hook_vfprintf_;
437 exit_ = options->hook_exit_;
438 abort_ = options->hook_abort_;
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700439
Elliott Hughesbe759c62011-09-08 19:38:21 -0700440 default_stack_size_ = options->stack_size_;
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700441
Elliott Hughesc33a32b2011-10-11 18:18:07 -0700442 monitor_list_ = new MonitorList;
Elliott Hughes14357e82011-09-26 10:42:15 -0700443 thread_list_ = new ThreadList(options->IsVerbose("thread"));
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700444 intern_table_ = new InternTable;
445
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700446 Heap::Init(options->heap_initial_size_, options->heap_maximum_size_, options->images_);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700447
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700448 BlockSignals();
449
Elliott Hughesa0957642011-09-02 14:27:33 -0700450 java_vm_ = new JavaVMExt(this, options.get());
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700451
Elliott Hughesbe759c62011-09-08 19:38:21 -0700452 Thread::Startup();
Elliott Hughesd92bec42011-09-02 17:04:36 -0700453
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700454 // ClassLinker needs an attached thread, but we can't fully attach a thread
455 // without creating objects.
456 Thread::Attach(this, "main", false);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700457
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700458 CHECK_GE(Heap::GetSpaces().size(), 1U);
459 class_linker_ = ((Heap::GetSpaces()[0]->IsImageSpace())
460 ? ClassLinker::Create(intern_table_)
461 : ClassLinker::Create(options->boot_class_path_, intern_table_));
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700462
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700463 if (IsVerboseStartup()) {
464 LOG(INFO) << "Runtime::Init exiting";
465 }
Carl Shapiro1fb86202011-06-27 17:43:13 -0700466 return true;
467}
468
Elliott Hughes038a8062011-09-18 14:12:41 -0700469void Runtime::InitNativeMethods() {
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700470 if (IsVerboseStartup()) {
471 LOG(INFO) << "Runtime::InitNativeMethods entering";
472 }
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700473 Thread* self = Thread::Current();
474 JNIEnv* env = self->GetJniEnv();
475
Elliott Hughes418d20f2011-09-22 14:00:39 -0700476 // Must be in the kNative state for calling native methods (JNI_OnLoad code).
Brian Carlstromaded5f72011-10-07 17:15:04 -0700477 CHECK_EQ(self->GetState(), Thread::kNative);
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700478
Elliott Hughes418d20f2011-09-22 14:00:39 -0700479 // First set up JniConstants, which is used by both the runtime's built-in native
480 // methods and libcore.
Elliott Hughesfea966e2011-09-22 10:26:20 -0700481 JniConstants::init(env);
482
Elliott Hughes418d20f2011-09-22 14:00:39 -0700483 // Then set up the native methods provided by the runtime itself.
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700484 RegisterRuntimeNativeMethods(env);
485
Elliott Hughes418d20f2011-09-22 14:00:39 -0700486 // Then set up libcore, which is just a regular JNI library with a regular JNI_OnLoad.
487 // Most JNI libraries can just use System.loadLibrary, but libcore can't because it's
488 // the library that implements System.loadLibrary!
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700489 LoadJniLibrary(instance_->GetJavaVM(), "javacore");
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700490 if (IsVerboseStartup()) {
491 LOG(INFO) << "Runtime::InitNativeMethods exiting";
492 }
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700493}
494
495void Runtime::RegisterRuntimeNativeMethods(JNIEnv* env) {
496#define REGISTER(FN) extern void FN(JNIEnv*); FN(env)
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700497 REGISTER(register_dalvik_system_DexFile);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700498 REGISTER(register_dalvik_system_VMDebug);
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700499 REGISTER(register_dalvik_system_VMRuntime);
Elliott Hughes8daa0922011-09-11 13:46:25 -0700500 REGISTER(register_dalvik_system_VMStack);
Elliott Hughes01158d72011-09-19 19:47:10 -0700501 REGISTER(register_dalvik_system_Zygote);
Elliott Hughesd369bb72011-09-12 14:41:14 -0700502 REGISTER(register_java_lang_Class);
Elliott Hughesbf86d042011-08-31 17:53:14 -0700503 REGISTER(register_java_lang_Object);
504 REGISTER(register_java_lang_Runtime);
505 REGISTER(register_java_lang_String);
506 REGISTER(register_java_lang_System);
Elliott Hughes8daa0922011-09-11 13:46:25 -0700507 REGISTER(register_java_lang_Thread);
Elliott Hughes1240dad2011-09-09 16:24:50 -0700508 REGISTER(register_java_lang_Throwable);
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700509 REGISTER(register_java_lang_VMClassLoader);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700510 REGISTER(register_java_lang_reflect_Array);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700511 REGISTER(register_java_lang_reflect_Constructor);
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700512 REGISTER(register_java_lang_reflect_Field);
513 REGISTER(register_java_lang_reflect_Method);
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700514 //REGISTER(register_java_lang_reflect_Proxy);
Elliott Hughesbf86d042011-08-31 17:53:14 -0700515 REGISTER(register_java_util_concurrent_atomic_AtomicLong);
Brian Carlstrom395520e2011-09-25 19:35:00 -0700516 REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmServer);
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700517 //REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmVmInternal);
Elliott Hughes5ee7a8b2011-09-13 16:40:07 -0700518 REGISTER(register_sun_misc_Unsafe);
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700519#undef REGISTER
520}
521
Elliott Hughes8daa0922011-09-11 13:46:25 -0700522void Runtime::Dump(std::ostream& os) {
Elliott Hughese27955c2011-08-26 15:21:24 -0700523 // TODO: dump other runtime statistics?
524 os << "Loaded classes: " << class_linker_->NumLoadedClasses() << "\n";
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700525 os << "Intern table size: " << GetInternTable()->Size() << "\n";
Elliott Hughese27955c2011-08-26 15:21:24 -0700526 // LOGV("VM stats: meth=%d ifld=%d sfld=%d linear=%d",
527 // gDvm.numDeclaredMethods,
528 // gDvm.numDeclaredInstFields,
529 // gDvm.numDeclaredStaticFields,
530 // gDvm.pBootLoaderAlloc->curOffset);
531 // LOGI("GC precise methods: %d", dvmPointerSetGetCount(gDvm.preciseMethods));
Elliott Hughes42ee1422011-09-06 12:33:32 -0700532 os << "\n";
Elliott Hughes8daa0922011-09-11 13:46:25 -0700533
534 thread_list_->Dump(os);
Elliott Hughese27955c2011-08-26 15:21:24 -0700535}
536
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700537void Runtime::SetStatsEnabled(bool new_state) {
538 if (new_state == true) {
539 GetStats()->Clear(~0);
540 // TODO: wouldn't it make more sense to clear _all_ threads' stats?
541 Thread::Current()->GetStats()->Clear(~0);
542 }
543 stats_enabled_ = new_state;
544}
545
546void Runtime::ResetStats(int kinds) {
547 GetStats()->Clear(kinds & 0xffff);
548 // TODO: wouldn't it make more sense to clear _all_ threads' stats?
549 Thread::Current()->GetStats()->Clear(kinds >> 16);
550}
551
552RuntimeStats* Runtime::GetStats() {
553 return &stats_;
554}
555
556int32_t Runtime::GetStat(int kind) {
557 RuntimeStats* stats;
558 if (kind < (1<<16)) {
559 stats = GetStats();
560 } else {
561 stats = Thread::Current()->GetStats();
562 kind >>= 16;
563 }
564 switch (kind) {
565 case KIND_ALLOCATED_OBJECTS:
566 return stats->allocated_objects;
567 case KIND_ALLOCATED_BYTES:
568 return stats->allocated_bytes;
569 case KIND_FREED_OBJECTS:
570 return stats->freed_objects;
571 case KIND_FREED_BYTES:
572 return stats->freed_bytes;
573 case KIND_GC_INVOCATIONS:
574 return stats->gc_for_alloc_count;
575 case KIND_CLASS_INIT_COUNT:
576 return stats->class_init_count;
577 case KIND_CLASS_INIT_TIME:
578 // Convert ns to us, reduce to 32 bits.
579 return (int) (stats->class_init_time_ns / 1000);
580 case KIND_EXT_ALLOCATED_OBJECTS:
581 case KIND_EXT_ALLOCATED_BYTES:
582 case KIND_EXT_FREED_OBJECTS:
583 case KIND_EXT_FREED_BYTES:
584 return 0; // backward compatibility
585 default:
586 CHECK(false);
587 return -1; // unreachable
588 }
589}
590
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700591void Runtime::BlockSignals() {
592 sigset_t sigset;
593 if (sigemptyset(&sigset) == -1) {
594 PLOG(FATAL) << "sigemptyset failed";
595 }
596 if (sigaddset(&sigset, SIGPIPE) == -1) {
597 PLOG(ERROR) << "sigaddset SIGPIPE failed";
598 }
599 // SIGQUIT is used to dump the runtime's state (including stack traces).
600 if (sigaddset(&sigset, SIGQUIT) == -1) {
601 PLOG(ERROR) << "sigaddset SIGQUIT failed";
602 }
603 // SIGUSR1 is used to initiate a heap dump.
604 if (sigaddset(&sigset, SIGUSR1) == -1) {
605 PLOG(ERROR) << "sigaddset SIGUSR1 failed";
606 }
607 CHECK_EQ(sigprocmask(SIG_BLOCK, &sigset, NULL), 0);
608}
609
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700610void Runtime::AttachCurrentThread(const char* name, bool as_daemon) {
611 Thread::Attach(instance_, name, as_daemon);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700612}
613
Elliott Hughesd92bec42011-09-02 17:04:36 -0700614void Runtime::DetachCurrentThread() {
Elliott Hughes038a8062011-09-18 14:12:41 -0700615 // TODO: check we're not calling DetachCurrentThread from a call stack that
616 // includes managed frames. (It's only valid if the stack is all-native.)
Elliott Hughes02b48d12011-09-07 17:15:51 -0700617 thread_list_->Unregister();
Carl Shapiro1fb86202011-06-27 17:43:13 -0700618}
619
Brian Carlstrome24fa612011-09-29 00:53:55 -0700620void Runtime::VisitRoots(Heap::RootVisitor* visitor, void* arg) const {
621 class_linker_->VisitRoots(visitor, arg);
622 intern_table_->VisitRoots(visitor, arg);
623 java_vm_->VisitRoots(visitor, arg);
624 thread_list_->VisitRoots(visitor, arg);
625 visitor(jni_stub_array_, arg);
626 visitor(abstract_method_error_stub_array_, arg);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700627 for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) {
628 visitor(resolution_stub_array_[i], arg);
629 }
630 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
631 visitor(callee_save_method_[i], arg);
632 }
Brian Carlstrome24fa612011-09-29 00:53:55 -0700633}
634
635bool Runtime::HasJniStubArray() const {
636 return jni_stub_array_ != NULL;
637}
638
639ByteArray* Runtime::GetJniStubArray() const {
640 CHECK(jni_stub_array_ != NULL);
641 return jni_stub_array_;
642}
643
644void Runtime::SetJniStubArray(ByteArray* jni_stub_array) {
Brian Carlstromaded5f72011-10-07 17:15:04 -0700645 CHECK(jni_stub_array != NULL) << " jni_stub_array=" << jni_stub_array;
646 CHECK(jni_stub_array_ == NULL || jni_stub_array_ == jni_stub_array)
647 << "jni_stub_array_=" << jni_stub_array_ << " jni_stub_array=" << jni_stub_array;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700648 jni_stub_array_ = jni_stub_array;
649}
650
651bool Runtime::HasAbstractMethodErrorStubArray() const {
652 return abstract_method_error_stub_array_ != NULL;
653}
654
655ByteArray* Runtime::GetAbstractMethodErrorStubArray() const {
656 CHECK(abstract_method_error_stub_array_ != NULL);
657 return abstract_method_error_stub_array_;
658}
659
660void Runtime::SetAbstractMethodErrorStubArray(ByteArray* abstract_method_error_stub_array) {
661 CHECK(abstract_method_error_stub_array != NULL);
662 CHECK(abstract_method_error_stub_array_ == NULL || abstract_method_error_stub_array_ == abstract_method_error_stub_array);
663 abstract_method_error_stub_array_ = abstract_method_error_stub_array;
664}
665
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700666
667Runtime::TrampolineType Runtime::GetTrampolineType(Method* method) {
668 if (method == NULL) {
669 return Runtime::kUnknownMethod;
670 } else if (method->IsStatic()) {
671 return Runtime::kStaticMethod;
672 } else {
673 return Runtime::kInstanceMethod;
674 }
Ian Rogersad25ac52011-10-04 19:13:33 -0700675}
676
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700677bool Runtime::HasResolutionStubArray(TrampolineType type) const {
678 return resolution_stub_array_[type] != NULL;
Ian Rogersad25ac52011-10-04 19:13:33 -0700679}
680
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700681ByteArray* Runtime::GetResolutionStubArray(TrampolineType type) const {
682 CHECK(HasResolutionStubArray(type));
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700683 DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastTrampolineMethodType));
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700684 return resolution_stub_array_[type];
685}
686
687void Runtime::SetResolutionStubArray(ByteArray* resolution_stub_array, TrampolineType type) {
Ian Rogersad25ac52011-10-04 19:13:33 -0700688 CHECK(resolution_stub_array != NULL);
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700689 CHECK(!HasResolutionStubArray(type) || resolution_stub_array_[type] == resolution_stub_array);
690 resolution_stub_array_[type] = resolution_stub_array;
Ian Rogersad25ac52011-10-04 19:13:33 -0700691}
692
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700693Method* Runtime::CreateCalleeSaveMethod(InstructionSet insns, CalleeSaveType type) {
Ian Rogersff1ed472011-09-20 13:46:24 -0700694 Class* method_class = Method::GetMethodClass();
695 Method* method = down_cast<Method*>(method_class->AllocObject());
696 method->SetDeclaringClass(method_class);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700697 const char* name;
698 if (type == kSaveAll) {
699 name = "$$$callee_save_method$$$";
700 } else if (type == kRefsOnly) {
701 name = "$$$refs_only_callee_save_method$$$";
702 } else {
703 DCHECK(type == kRefsAndArgs);
704 name = "$$$refs_and_args_callee_save_method$$$";
705 }
706 method->SetName(intern_table_->InternStrong(name));
Ian Rogersff1ed472011-09-20 13:46:24 -0700707 method->SetSignature(intern_table_->InternStrong("()V"));
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700708 method->SetCode(NULL);
Ian Rogersff1ed472011-09-20 13:46:24 -0700709 if ((insns == kThumb2) || (insns == kArm)) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700710 uint32_t ref_spills = (1 << art::arm::R5) | (1 << art::arm::R6) | (1 << art::arm::R7) |
711 (1 << art::arm::R8) | (1 << art::arm::R10) | (1 << art::arm::R11);
712 uint32_t arg_spills = (1 << art::arm::R1) | (1 << art::arm::R2) | (1 << art::arm::R3);
713 uint32_t all_spills = (1 << art::arm::R4) | (1 << art::arm::R9);
714 uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills :0) |
715 (type == kSaveAll ? all_spills :0) | (1 << art::arm::LR);
716 uint32_t fp_all_spills = (1 << art::arm::S0) | (1 << art::arm::S1) | (1 << art::arm::S2) |
717 (1 << art::arm::S3) | (1 << art::arm::S4) | (1 << art::arm::S5) |
718 (1 << art::arm::S6) | (1 << art::arm::S7) | (1 << art::arm::S8) |
719 (1 << art::arm::S9) | (1 << art::arm::S10) | (1 << art::arm::S11) |
720 (1 << art::arm::S12) | (1 << art::arm::S13) | (1 << art::arm::S14) |
721 (1 << art::arm::S15) | (1 << art::arm::S16) | (1 << art::arm::S17) |
722 (1 << art::arm::S18) | (1 << art::arm::S19) | (1 << art::arm::S20) |
723 (1 << art::arm::S21) | (1 << art::arm::S22) | (1 << art::arm::S23) |
724 (1 << art::arm::S24) | (1 << art::arm::S25) | (1 << art::arm::S26) |
725 (1 << art::arm::S27) | (1 << art::arm::S28) | (1 << art::arm::S29) |
726 (1 << art::arm::S30) | (1 << art::arm::S31);
727 uint32_t fp_spills = type == kSaveAll ? fp_all_spills : 0;
728 size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ +
729 __builtin_popcount(fp_spills) /* fprs */ +
730 1 /* Method* */) * kPointerSize, kStackAlignment);
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700731 method->SetFrameSizeInBytes(frame_size);
732 method->SetReturnPcOffsetInBytes(frame_size - kPointerSize);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700733 method->SetCoreSpillMask(core_spills);
734 method->SetFpSpillMask(fp_spills);
Ian Rogersff1ed472011-09-20 13:46:24 -0700735 } else if (insns == kX86) {
736 method->SetFrameSizeInBytes(32);
737 method->SetReturnPcOffsetInBytes(28);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700738 method->SetCoreSpillMask((1 << art::x86::EBX) | (1 << art::x86::EBP) | (1 << art::x86::ESI) |
Ian Rogersff1ed472011-09-20 13:46:24 -0700739 (1 << art::x86::EDI));
740 method->SetFpSpillMask(0);
741 } else {
742 UNIMPLEMENTED(FATAL);
743 }
744 return method;
745}
746
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700747bool Runtime::HasCalleeSaveMethod(CalleeSaveType type) const {
748 return callee_save_method_[type] != NULL;
Brian Carlstrom1f870082011-08-23 16:02:11 -0700749}
750
Brian Carlstrome24fa612011-09-29 00:53:55 -0700751// Returns a special method that describes all callee saves being spilled to the stack.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700752Method* Runtime::GetCalleeSaveMethod(CalleeSaveType type) const {
753 CHECK(HasCalleeSaveMethod(type));
754 return callee_save_method_[type];
Brian Carlstrome24fa612011-09-29 00:53:55 -0700755}
756
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700757void Runtime::SetCalleeSaveMethod(Method* method, CalleeSaveType type) {
758 DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastCalleeSaveType));
759 callee_save_method_[type] = method;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700760}
761
Carl Shapiro1fb86202011-06-27 17:43:13 -0700762} // namespace art