Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 3 | #include "runtime.h" |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 4 | |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 5 | #include <cstdio> |
| 6 | #include <cstdlib> |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 7 | #include <limits> |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 8 | #include <vector> |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 9 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 10 | #include "UniquePtr.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 11 | #include "class_linker.h" |
| 12 | #include "heap.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 13 | #include "image.h" |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 14 | #include "intern_table.h" |
Elliott Hughes | c5f7c91 | 2011-08-18 14:00:42 -0700 | [diff] [blame] | 15 | #include "jni_internal.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 16 | #include "oat_file.h" |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 17 | #include "signal_catcher.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 18 | #include "space.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 19 | #include "thread.h" |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 20 | #include "thread_list.h" |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 21 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 22 | // TODO: this drags in cutil/log.h, which conflicts with our logging.h. |
| 23 | #include "JniConstants.h" |
| 24 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 25 | namespace art { |
| 26 | |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 27 | Runtime* Runtime::instance_ = NULL; |
| 28 | |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 29 | Runtime::Runtime() |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 30 | : verbose_startup_(false), |
| 31 | default_stack_size_(Thread::kDefaultStackSize), |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 32 | thread_list_(NULL), |
| 33 | intern_table_(NULL), |
| 34 | class_linker_(NULL), |
| 35 | signal_catcher_(NULL), |
| 36 | java_vm_(NULL), |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 37 | jni_stub_array_(NULL), |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 38 | abstract_method_error_stub_array_(NULL), |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 39 | callee_save_method_(NULL), |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 40 | started_(false), |
| 41 | vfprintf_(NULL), |
| 42 | exit_(NULL), |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 43 | abort_(NULL), |
| 44 | stats_enabled_(false) { |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 47 | Runtime::~Runtime() { |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 48 | // Make sure our internal threads are dead before we start tearing down things they're using. |
| 49 | delete signal_catcher_; |
Elliott Hughes | 038a806 | 2011-09-18 14:12:41 -0700 | [diff] [blame] | 50 | // TODO: GC thread. |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 51 | |
Elliott Hughes | 038a806 | 2011-09-18 14:12:41 -0700 | [diff] [blame] | 52 | // Make sure all other non-daemon threads have terminated, and all daemon threads are suspended. |
Elliott Hughes | 93e74e8 | 2011-09-13 11:07:03 -0700 | [diff] [blame] | 53 | delete thread_list_; |
| 54 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 55 | delete class_linker_; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 56 | Heap::Destroy(); |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 57 | delete intern_table_; |
Elliott Hughes | c5f7c91 | 2011-08-18 14:00:42 -0700 | [diff] [blame] | 58 | delete java_vm_; |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 59 | Thread::Shutdown(); |
Carl Shapiro | 4acf464 | 2011-07-26 18:54:13 -0700 | [diff] [blame] | 60 | // TODO: acquire a static mutex on Runtime to avoid racing. |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 61 | CHECK(instance_ == NULL || instance_ == this); |
Carl Shapiro | 4acf464 | 2011-07-26 18:54:13 -0700 | [diff] [blame] | 62 | instance_ = NULL; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 65 | void Runtime::Abort(const char* file, int line) { |
| 66 | // Get any pending output out of the way. |
| 67 | fflush(NULL); |
| 68 | |
| 69 | // Many people have difficulty distinguish aborts from crashes, |
| 70 | // so be explicit. |
| 71 | LogMessage(file, line, ERROR, -1).stream() << "Runtime aborting..."; |
| 72 | |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 73 | // Perform any platform-specific pre-abort actions. |
| 74 | PlatformAbort(file, line); |
| 75 | |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 76 | // use abort hook if we have one |
| 77 | if (Runtime::Current() != NULL && Runtime::Current()->abort_ != NULL) { |
| 78 | Runtime::Current()->abort_(); |
| 79 | // notreached |
| 80 | } |
| 81 | |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 82 | // If we call abort(3) on a device, all threads in the process |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 83 | // receive SIGABRT. debuggerd dumps the stack trace of the main |
| 84 | // thread, whether or not that was the thread that failed. By |
| 85 | // stuffing a value into a bogus address, we cause a segmentation |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 86 | // fault in the current thread, and get a useful log from debuggerd. |
| 87 | // We can also trivially tell the difference between a VM crash and |
| 88 | // a deliberate abort by looking at the fault address. |
| 89 | *reinterpret_cast<char*>(0xdeadd00d) = 38; |
| 90 | abort(); |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 91 | // notreached |
| 92 | } |
| 93 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 94 | void Runtime::CallExitHook(jint status) { |
| 95 | if (exit_ != NULL) { |
| 96 | ScopedThreadStateChange tsc(Thread::Current(), Thread::kNative); |
| 97 | exit_(status); |
| 98 | LOG(WARNING) << "Exit hook returned instead of exiting!"; |
| 99 | } |
| 100 | } |
| 101 | |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 102 | // Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify |
| 103 | // memory sizes. [kK] indicates kilobytes, [mM] megabytes, and |
| 104 | // [gG] gigabytes. |
| 105 | // |
| 106 | // "s" should point just past the "-Xm?" part of the string. |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 107 | // "div" specifies a divisor, e.g. 1024 if the value must be a multiple |
| 108 | // of 1024. |
| 109 | // |
| 110 | // The spec says the -Xmx and -Xms options must be multiples of 1024. It |
| 111 | // doesn't say anything about -Xss. |
| 112 | // |
| 113 | // Returns 0 (a useless size) if "s" is malformed or specifies a low or |
| 114 | // non-evenly-divisible value. |
| 115 | // |
| 116 | size_t ParseMemoryOption(const char *s, size_t div) { |
| 117 | // strtoul accepts a leading [+-], which we don't want, |
| 118 | // so make sure our string starts with a decimal digit. |
| 119 | if (isdigit(*s)) { |
| 120 | const char *s2; |
| 121 | size_t val = strtoul(s, (char **)&s2, 10); |
| 122 | if (s2 != s) { |
| 123 | // s2 should be pointing just after the number. |
| 124 | // If this is the end of the string, the user |
| 125 | // has specified a number of bytes. Otherwise, |
| 126 | // there should be exactly one more character |
| 127 | // that specifies a multiplier. |
| 128 | if (*s2 != '\0') { |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 129 | // The remainder of the string is either a single multiplier |
| 130 | // character, or nothing to indicate that the value is in |
| 131 | // bytes. |
| 132 | char c = *s2++; |
| 133 | if (*s2 == '\0') { |
| 134 | size_t mul; |
| 135 | if (c == '\0') { |
| 136 | mul = 1; |
| 137 | } else if (c == 'k' || c == 'K') { |
| 138 | mul = KB; |
| 139 | } else if (c == 'm' || c == 'M') { |
| 140 | mul = MB; |
| 141 | } else if (c == 'g' || c == 'G') { |
| 142 | mul = GB; |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 143 | } else { |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 144 | // Unknown multiplier character. |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 145 | return 0; |
| 146 | } |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 147 | |
| 148 | if (val <= std::numeric_limits<size_t>::max() / mul) { |
| 149 | val *= mul; |
| 150 | } else { |
| 151 | // Clamp to a multiple of 1024. |
| 152 | val = std::numeric_limits<size_t>::max() & ~(1024-1); |
| 153 | } |
| 154 | } else { |
| 155 | // There's more than one character after the numeric part. |
| 156 | return 0; |
| 157 | } |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 158 | } |
| 159 | // The man page says that a -Xm value must be a multiple of 1024. |
| 160 | if (val % div == 0) { |
| 161 | return val; |
| 162 | } |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 165 | return 0; |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 168 | void LoadJniLibrary(JavaVMExt* vm, const char* name) { |
| 169 | // TODO: OS_SHARED_LIB_FORMAT_STR |
| 170 | std::string mapped_name(StringPrintf("lib%s.so", name)); |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 171 | std::string reason; |
| 172 | if (!vm->LoadNativeLibrary(mapped_name, NULL, reason)) { |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 173 | LOG(FATAL) << "LoadNativeLibrary failed for \"" << mapped_name << "\": " |
| 174 | << reason; |
| 175 | } |
| 176 | } |
| 177 | |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 178 | Runtime::ParsedOptions* Runtime::ParsedOptions::Create(const Options& options, bool ignore_unrecognized) { |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 179 | UniquePtr<ParsedOptions> parsed(new ParsedOptions()); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame^] | 180 | const char* boot_class_path = getenv("BOOTCLASSPATH"); |
| 181 | if (boot_class_path != NULL) { |
| 182 | parsed->boot_class_path_ = getenv("BOOTCLASSPATH"); |
| 183 | } |
| 184 | const char* class_path = getenv("CLASSPATH"); |
| 185 | if (class_path != NULL) { |
| 186 | parsed->class_path_ = getenv("CLASSPATH"); |
| 187 | } |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 188 | #ifdef NDEBUG |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 189 | // -Xcheck:jni is off by default for regular builds... |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 190 | parsed->check_jni_ = false; |
| 191 | #else |
| 192 | // ...but on by default in debug builds. |
| 193 | parsed->check_jni_ = true; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 194 | #endif |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 195 | |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 196 | parsed->heap_initial_size_ = Heap::kInitialSize; |
| 197 | parsed->heap_maximum_size_ = Heap::kMaximumSize; |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 198 | parsed->stack_size_ = Thread::kDefaultStackSize; |
| 199 | |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 200 | parsed->hook_vfprintf_ = vfprintf; |
| 201 | parsed->hook_exit_ = exit; |
| 202 | parsed->hook_abort_ = abort; |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 203 | |
| 204 | for (size_t i = 0; i < options.size(); ++i) { |
| 205 | const StringPiece& option = options[i].first; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame^] | 206 | if (false) { |
| 207 | LOG(INFO) << "option[" << i << "]=" << option; |
| 208 | } |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 209 | if (option.starts_with("-Xbootclasspath:")) { |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame^] | 210 | parsed->boot_class_path_ = option.substr(strlen("-Xbootclasspath:")).data(); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 211 | } else if (option == "-classpath" || option == "-cp") { |
| 212 | // TODO: support -Djava.class.path |
| 213 | i++; |
| 214 | if (i == options.size()) { |
| 215 | // TODO: usage |
| 216 | LOG(FATAL) << "Missing required class path value for " << option; |
| 217 | return NULL; |
| 218 | } |
| 219 | const StringPiece& value = options[i].first; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame^] | 220 | parsed->class_path_ = value.data(); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 221 | } else if (option.starts_with("-Ximage:")) { |
| 222 | parsed->images_.push_back(option.substr(strlen("-Ximage:")).data()); |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 223 | } else if (option.starts_with("-Xcheck:jni")) { |
| 224 | parsed->check_jni_ = true; |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 225 | } else if (option.starts_with("-Xms")) { |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 226 | size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).data(), 1024); |
| 227 | if (size == 0) { |
| 228 | if (ignore_unrecognized) { |
| 229 | continue; |
| 230 | } |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 231 | // TODO: usage |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 232 | LOG(FATAL) << "Failed to parse " << option; |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 233 | return NULL; |
| 234 | } |
| 235 | parsed->heap_initial_size_ = size; |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 236 | } else if (option.starts_with("-Xmx")) { |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 237 | size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).data(), 1024); |
| 238 | if (size == 0) { |
| 239 | if (ignore_unrecognized) { |
| 240 | continue; |
| 241 | } |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 242 | // TODO: usage |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 243 | LOG(FATAL) << "Failed to parse " << option; |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 244 | return NULL; |
| 245 | } |
| 246 | parsed->heap_maximum_size_ = size; |
| 247 | } else if (option.starts_with("-Xss")) { |
| 248 | size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).data(), 1); |
| 249 | if (size == 0) { |
| 250 | if (ignore_unrecognized) { |
| 251 | continue; |
| 252 | } |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 253 | // TODO: usage |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 254 | LOG(FATAL) << "Failed to parse " << option; |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 255 | return NULL; |
| 256 | } |
| 257 | parsed->stack_size_ = size; |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 258 | } else if (option.starts_with("-D")) { |
| 259 | parsed->properties_.push_back(option.substr(strlen("-D")).data()); |
Elliott Hughes | a095764 | 2011-09-02 14:27:33 -0700 | [diff] [blame] | 260 | } else if (option.starts_with("-Xjnitrace:")) { |
| 261 | parsed->jni_trace_ = option.substr(strlen("-Xjnitrace:")).data(); |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 262 | } else if (option.starts_with("-verbose:")) { |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 263 | std::vector<std::string> verbose_options; |
Elliott Hughes | 3402380 | 2011-08-30 12:06:17 -0700 | [diff] [blame] | 264 | Split(option.substr(strlen("-verbose:")).data(), ',', verbose_options); |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 265 | for (size_t i = 0; i < verbose_options.size(); ++i) { |
| 266 | parsed->verbose_.insert(verbose_options[i]); |
| 267 | } |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 268 | } else if (option == "vfprintf") { |
| 269 | parsed->hook_vfprintf_ = reinterpret_cast<int (*)(FILE *, const char*, va_list)>(options[i].second); |
| 270 | } else if (option == "exit") { |
| 271 | parsed->hook_exit_ = reinterpret_cast<void(*)(jint)>(options[i].second); |
| 272 | } else if (option == "abort") { |
| 273 | parsed->hook_abort_ = reinterpret_cast<void(*)()>(options[i].second); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame^] | 274 | } else if (option == "host-prefix") { |
| 275 | parsed->host_prefix_ = reinterpret_cast<const char*>(options[i].second); |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 276 | } else { |
| 277 | if (!ignore_unrecognized) { |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 278 | // TODO: print usage via vfprintf |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 279 | LOG(ERROR) << "Unrecognized option " << option; |
| 280 | // TODO: this should exit, but for now tolerate unknown options |
| 281 | //return NULL; |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 286 | LOG(INFO) << "CheckJNI is " << (parsed->check_jni_ ? "on" : "off"); |
| 287 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 288 | return parsed.release(); |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | Runtime* Runtime::Create(const Options& options, bool ignore_unrecognized) { |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 292 | // TODO: acquire a static mutex on Runtime to avoid racing. |
| 293 | if (Runtime::instance_ != NULL) { |
| 294 | return NULL; |
| 295 | } |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 296 | instance_ = new Runtime; |
| 297 | if (!instance_->Init(options, ignore_unrecognized)) { |
| 298 | delete instance_; |
| 299 | instance_ = NULL; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 300 | } |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 301 | return instance_; |
| 302 | } |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 303 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 304 | void Runtime::Start() { |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 305 | if (IsVerboseStartup()) { |
| 306 | LOG(INFO) << "Runtime::Start entering"; |
| 307 | } |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame^] | 308 | |
| 309 | CHECK(host_prefix_.empty()) << host_prefix_; |
| 310 | |
Elliott Hughes | 038a806 | 2011-09-18 14:12:41 -0700 | [diff] [blame] | 311 | InitNativeMethods(); |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 312 | |
Elliott Hughes | 038a806 | 2011-09-18 14:12:41 -0700 | [diff] [blame] | 313 | Thread::FinishStartup(); |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 314 | |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 315 | class_linker_->RunRootClinits(); |
Brian Carlstrom | f867b6f | 2011-09-16 12:17:25 -0700 | [diff] [blame] | 316 | |
Brian Carlstrom | 5d40f18 | 2011-09-26 22:29:18 -0700 | [diff] [blame] | 317 | // Class::AllocObject asserts that all objects allocated better be |
| 318 | // initialized after Runtime::IsStarted is true, so this needs to |
| 319 | // come after ClassLinker::RunRootClinits. |
| 320 | started_ = true; |
| 321 | |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 322 | StartDaemonThreads(); |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 323 | |
| 324 | if (IsVerboseStartup()) { |
| 325 | LOG(INFO) << "Runtime::Start exiting"; |
| 326 | } |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | void Runtime::StartDaemonThreads() { |
| 330 | signal_catcher_ = new SignalCatcher; |
| 331 | |
Elliott Hughes | 719b323 | 2011-09-25 17:42:19 -0700 | [diff] [blame] | 332 | Thread* self = Thread::Current(); |
| 333 | JNIEnv* env = self->GetJniEnv(); |
| 334 | jclass c = env->FindClass("java/lang/Daemons"); |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 335 | CHECK(c != NULL); |
Elliott Hughes | 719b323 | 2011-09-25 17:42:19 -0700 | [diff] [blame] | 336 | jmethodID mid = env->GetStaticMethodID(c, "start", "()V"); |
| 337 | CHECK(mid != NULL); |
| 338 | env->CallStaticVoidMethod(c, mid); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame^] | 341 | bool Runtime::IsStarted() const { |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 342 | return started_; |
| 343 | } |
| 344 | |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 345 | bool Runtime::Init(const Options& raw_options, bool ignore_unrecognized) { |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 346 | CHECK_EQ(sysconf(_SC_PAGE_SIZE), kPageSize); |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 347 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 348 | UniquePtr<ParsedOptions> options(ParsedOptions::Create(raw_options, ignore_unrecognized)); |
| 349 | if (options.get() == NULL) { |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 350 | LOG(ERROR) << "Failed to parse options"; |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 351 | return false; |
| 352 | } |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 353 | verbose_startup_ = options->IsVerbose("startup"); |
| 354 | if (IsVerboseStartup()) { |
| 355 | LOG(INFO) << "Runtime::Init -verbose:startup enabled"; |
| 356 | } |
Elliott Hughes | 7ede61e | 2011-09-14 18:18:06 -0700 | [diff] [blame] | 357 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame^] | 358 | host_prefix_ = options->host_prefix_; |
| 359 | boot_class_path_ = options->boot_class_path_; |
| 360 | class_path_ = options->class_path_; |
Elliott Hughes | 7ede61e | 2011-09-14 18:18:06 -0700 | [diff] [blame] | 361 | properties_ = options->properties_; |
| 362 | |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 363 | vfprintf_ = options->hook_vfprintf_; |
| 364 | exit_ = options->hook_exit_; |
| 365 | abort_ = options->hook_abort_; |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 366 | |
Elliott Hughes | be759c6 | 2011-09-08 19:38:21 -0700 | [diff] [blame] | 367 | default_stack_size_ = options->stack_size_; |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 368 | |
Elliott Hughes | 14357e8 | 2011-09-26 10:42:15 -0700 | [diff] [blame] | 369 | thread_list_ = new ThreadList(options->IsVerbose("thread")); |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 370 | intern_table_ = new InternTable; |
| 371 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame^] | 372 | Heap::Init(options->heap_initial_size_, options->heap_maximum_size_, options->images_); |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 373 | |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 374 | BlockSignals(); |
| 375 | |
Elliott Hughes | a095764 | 2011-09-02 14:27:33 -0700 | [diff] [blame] | 376 | java_vm_ = new JavaVMExt(this, options.get()); |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 377 | |
Elliott Hughes | be759c6 | 2011-09-08 19:38:21 -0700 | [diff] [blame] | 378 | Thread::Startup(); |
Elliott Hughes | d92bec4 | 2011-09-02 17:04:36 -0700 | [diff] [blame] | 379 | |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 380 | // ClassLinker needs an attached thread, but we can't fully attach a thread |
| 381 | // without creating objects. |
| 382 | Thread::Attach(this, "main", false); |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 383 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame^] | 384 | CHECK_GE(Heap::GetSpaces().size(), 1U); |
| 385 | class_linker_ = ((Heap::GetSpaces()[0]->IsImageSpace()) |
| 386 | ? ClassLinker::Create(intern_table_) |
| 387 | : ClassLinker::Create(options->boot_class_path_, intern_table_)); |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 388 | |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 389 | if (IsVerboseStartup()) { |
| 390 | LOG(INFO) << "Runtime::Init exiting"; |
| 391 | } |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 392 | return true; |
| 393 | } |
| 394 | |
Elliott Hughes | 038a806 | 2011-09-18 14:12:41 -0700 | [diff] [blame] | 395 | void Runtime::InitNativeMethods() { |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 396 | if (IsVerboseStartup()) { |
| 397 | LOG(INFO) << "Runtime::InitNativeMethods entering"; |
| 398 | } |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 399 | Thread* self = Thread::Current(); |
| 400 | JNIEnv* env = self->GetJniEnv(); |
| 401 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 402 | // Must be in the kNative state for calling native methods (JNI_OnLoad code). |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 403 | ScopedThreadStateChange tsc(self, Thread::kNative); |
| 404 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 405 | // First set up JniConstants, which is used by both the runtime's built-in native |
| 406 | // methods and libcore. |
Elliott Hughes | fea966e | 2011-09-22 10:26:20 -0700 | [diff] [blame] | 407 | JniConstants::init(env); |
| 408 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 409 | // Then set up the native methods provided by the runtime itself. |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 410 | RegisterRuntimeNativeMethods(env); |
| 411 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 412 | // Then set up libcore, which is just a regular JNI library with a regular JNI_OnLoad. |
| 413 | // Most JNI libraries can just use System.loadLibrary, but libcore can't because it's |
| 414 | // the library that implements System.loadLibrary! |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 415 | LoadJniLibrary(instance_->GetJavaVM(), "javacore"); |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 416 | if (IsVerboseStartup()) { |
| 417 | LOG(INFO) << "Runtime::InitNativeMethods exiting"; |
| 418 | } |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | void Runtime::RegisterRuntimeNativeMethods(JNIEnv* env) { |
| 422 | #define REGISTER(FN) extern void FN(JNIEnv*); FN(env) |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 423 | REGISTER(register_dalvik_system_DexFile); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 424 | REGISTER(register_dalvik_system_VMDebug); |
Elliott Hughes | 7ede61e | 2011-09-14 18:18:06 -0700 | [diff] [blame] | 425 | REGISTER(register_dalvik_system_VMRuntime); |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 426 | REGISTER(register_dalvik_system_VMStack); |
Elliott Hughes | 01158d7 | 2011-09-19 19:47:10 -0700 | [diff] [blame] | 427 | REGISTER(register_dalvik_system_Zygote); |
Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 428 | REGISTER(register_java_lang_Class); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 429 | REGISTER(register_java_lang_Object); |
| 430 | REGISTER(register_java_lang_Runtime); |
| 431 | REGISTER(register_java_lang_String); |
| 432 | REGISTER(register_java_lang_System); |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 433 | REGISTER(register_java_lang_Thread); |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 434 | REGISTER(register_java_lang_Throwable); |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 435 | REGISTER(register_java_lang_VMClassLoader); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 436 | REGISTER(register_java_lang_reflect_Array); |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 437 | REGISTER(register_java_lang_reflect_Constructor); |
Brian Carlstrom | f867b6f | 2011-09-16 12:17:25 -0700 | [diff] [blame] | 438 | REGISTER(register_java_lang_reflect_Field); |
| 439 | REGISTER(register_java_lang_reflect_Method); |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 440 | //REGISTER(register_java_lang_reflect_Proxy); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 441 | REGISTER(register_java_util_concurrent_atomic_AtomicLong); |
Brian Carlstrom | 395520e | 2011-09-25 19:35:00 -0700 | [diff] [blame] | 442 | REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmServer); |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 443 | //REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmVmInternal); |
Elliott Hughes | 5ee7a8b | 2011-09-13 16:40:07 -0700 | [diff] [blame] | 444 | REGISTER(register_sun_misc_Unsafe); |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 445 | #undef REGISTER |
| 446 | } |
| 447 | |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 448 | void Runtime::Dump(std::ostream& os) { |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 449 | // TODO: dump other runtime statistics? |
| 450 | os << "Loaded classes: " << class_linker_->NumLoadedClasses() << "\n"; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 451 | os << "Intern table size: " << GetInternTable()->Size() << "\n"; |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 452 | // LOGV("VM stats: meth=%d ifld=%d sfld=%d linear=%d", |
| 453 | // gDvm.numDeclaredMethods, |
| 454 | // gDvm.numDeclaredInstFields, |
| 455 | // gDvm.numDeclaredStaticFields, |
| 456 | // gDvm.pBootLoaderAlloc->curOffset); |
| 457 | // LOGI("GC precise methods: %d", dvmPointerSetGetCount(gDvm.preciseMethods)); |
Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 458 | os << "\n"; |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 459 | |
| 460 | thread_list_->Dump(os); |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 463 | void Runtime::SetStatsEnabled(bool new_state) { |
| 464 | if (new_state == true) { |
| 465 | GetStats()->Clear(~0); |
| 466 | // TODO: wouldn't it make more sense to clear _all_ threads' stats? |
| 467 | Thread::Current()->GetStats()->Clear(~0); |
| 468 | } |
| 469 | stats_enabled_ = new_state; |
| 470 | } |
| 471 | |
| 472 | void Runtime::ResetStats(int kinds) { |
| 473 | GetStats()->Clear(kinds & 0xffff); |
| 474 | // TODO: wouldn't it make more sense to clear _all_ threads' stats? |
| 475 | Thread::Current()->GetStats()->Clear(kinds >> 16); |
| 476 | } |
| 477 | |
| 478 | RuntimeStats* Runtime::GetStats() { |
| 479 | return &stats_; |
| 480 | } |
| 481 | |
| 482 | int32_t Runtime::GetStat(int kind) { |
| 483 | RuntimeStats* stats; |
| 484 | if (kind < (1<<16)) { |
| 485 | stats = GetStats(); |
| 486 | } else { |
| 487 | stats = Thread::Current()->GetStats(); |
| 488 | kind >>= 16; |
| 489 | } |
| 490 | switch (kind) { |
| 491 | case KIND_ALLOCATED_OBJECTS: |
| 492 | return stats->allocated_objects; |
| 493 | case KIND_ALLOCATED_BYTES: |
| 494 | return stats->allocated_bytes; |
| 495 | case KIND_FREED_OBJECTS: |
| 496 | return stats->freed_objects; |
| 497 | case KIND_FREED_BYTES: |
| 498 | return stats->freed_bytes; |
| 499 | case KIND_GC_INVOCATIONS: |
| 500 | return stats->gc_for_alloc_count; |
| 501 | case KIND_CLASS_INIT_COUNT: |
| 502 | return stats->class_init_count; |
| 503 | case KIND_CLASS_INIT_TIME: |
| 504 | // Convert ns to us, reduce to 32 bits. |
| 505 | return (int) (stats->class_init_time_ns / 1000); |
| 506 | case KIND_EXT_ALLOCATED_OBJECTS: |
| 507 | case KIND_EXT_ALLOCATED_BYTES: |
| 508 | case KIND_EXT_FREED_OBJECTS: |
| 509 | case KIND_EXT_FREED_BYTES: |
| 510 | return 0; // backward compatibility |
| 511 | default: |
| 512 | CHECK(false); |
| 513 | return -1; // unreachable |
| 514 | } |
| 515 | } |
| 516 | |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 517 | void Runtime::BlockSignals() { |
| 518 | sigset_t sigset; |
| 519 | if (sigemptyset(&sigset) == -1) { |
| 520 | PLOG(FATAL) << "sigemptyset failed"; |
| 521 | } |
| 522 | if (sigaddset(&sigset, SIGPIPE) == -1) { |
| 523 | PLOG(ERROR) << "sigaddset SIGPIPE failed"; |
| 524 | } |
| 525 | // SIGQUIT is used to dump the runtime's state (including stack traces). |
| 526 | if (sigaddset(&sigset, SIGQUIT) == -1) { |
| 527 | PLOG(ERROR) << "sigaddset SIGQUIT failed"; |
| 528 | } |
| 529 | // SIGUSR1 is used to initiate a heap dump. |
| 530 | if (sigaddset(&sigset, SIGUSR1) == -1) { |
| 531 | PLOG(ERROR) << "sigaddset SIGUSR1 failed"; |
| 532 | } |
| 533 | CHECK_EQ(sigprocmask(SIG_BLOCK, &sigset, NULL), 0); |
| 534 | } |
| 535 | |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 536 | void Runtime::AttachCurrentThread(const char* name, bool as_daemon) { |
| 537 | Thread::Attach(instance_, name, as_daemon); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Elliott Hughes | d92bec4 | 2011-09-02 17:04:36 -0700 | [diff] [blame] | 540 | void Runtime::DetachCurrentThread() { |
Elliott Hughes | 038a806 | 2011-09-18 14:12:41 -0700 | [diff] [blame] | 541 | // TODO: check we're not calling DetachCurrentThread from a call stack that |
| 542 | // includes managed frames. (It's only valid if the stack is all-native.) |
Elliott Hughes | 02b48d1 | 2011-09-07 17:15:51 -0700 | [diff] [blame] | 543 | thread_list_->Unregister(); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 546 | void Runtime::VisitRoots(Heap::RootVisitor* visitor, void* arg) const { |
| 547 | class_linker_->VisitRoots(visitor, arg); |
| 548 | intern_table_->VisitRoots(visitor, arg); |
| 549 | java_vm_->VisitRoots(visitor, arg); |
| 550 | thread_list_->VisitRoots(visitor, arg); |
| 551 | visitor(jni_stub_array_, arg); |
| 552 | visitor(abstract_method_error_stub_array_, arg); |
| 553 | visitor(callee_save_method_, arg); |
| 554 | |
| 555 | //(*visitor)(&gDvm.outOfMemoryObj, 0, ROOT_VM_INTERNAL, arg); |
| 556 | //(*visitor)(&gDvm.internalErrorObj, 0, ROOT_VM_INTERNAL, arg); |
| 557 | //(*visitor)(&gDvm.noClassDefFoundErrorObj, 0, ROOT_VM_INTERNAL, arg); |
| 558 | UNIMPLEMENTED(WARNING) << "some roots not marked"; |
| 559 | } |
| 560 | |
| 561 | bool Runtime::HasJniStubArray() const { |
| 562 | return jni_stub_array_ != NULL; |
| 563 | } |
| 564 | |
| 565 | ByteArray* Runtime::GetJniStubArray() const { |
| 566 | CHECK(jni_stub_array_ != NULL); |
| 567 | return jni_stub_array_; |
| 568 | } |
| 569 | |
| 570 | void Runtime::SetJniStubArray(ByteArray* jni_stub_array) { |
| 571 | CHECK(jni_stub_array != NULL); |
| 572 | CHECK(jni_stub_array_ == NULL || jni_stub_array_ == jni_stub_array); |
| 573 | jni_stub_array_ = jni_stub_array; |
| 574 | } |
| 575 | |
| 576 | bool Runtime::HasAbstractMethodErrorStubArray() const { |
| 577 | return abstract_method_error_stub_array_ != NULL; |
| 578 | } |
| 579 | |
| 580 | ByteArray* Runtime::GetAbstractMethodErrorStubArray() const { |
| 581 | CHECK(abstract_method_error_stub_array_ != NULL); |
| 582 | return abstract_method_error_stub_array_; |
| 583 | } |
| 584 | |
| 585 | void Runtime::SetAbstractMethodErrorStubArray(ByteArray* abstract_method_error_stub_array) { |
| 586 | CHECK(abstract_method_error_stub_array != NULL); |
| 587 | CHECK(abstract_method_error_stub_array_ == NULL || abstract_method_error_stub_array_ == abstract_method_error_stub_array); |
| 588 | abstract_method_error_stub_array_ = abstract_method_error_stub_array; |
| 589 | } |
| 590 | |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 591 | Method* Runtime::CreateCalleeSaveMethod(InstructionSet insns) { |
| 592 | Class* method_class = Method::GetMethodClass(); |
| 593 | Method* method = down_cast<Method*>(method_class->AllocObject()); |
| 594 | method->SetDeclaringClass(method_class); |
| 595 | method->SetName(intern_table_->InternStrong("$$$callee_save_method$$$")); |
| 596 | method->SetSignature(intern_table_->InternStrong("()V")); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 597 | method->SetCodeArray(NULL, insns); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 598 | if ((insns == kThumb2) || (insns == kArm)) { |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 599 | size_t frame_size = (12 /* gprs */ + 32 /* fprs */ + 4 /* data */) * kPointerSize; |
| 600 | method->SetFrameSizeInBytes(frame_size); |
| 601 | method->SetReturnPcOffsetInBytes(frame_size - kPointerSize); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 602 | method->SetCoreSpillMask((1 << art::arm::R1) | |
| 603 | (1 << art::arm::R2) | |
| 604 | (1 << art::arm::R3) | |
| 605 | (1 << art::arm::R4) | |
| 606 | (1 << art::arm::R5) | |
| 607 | (1 << art::arm::R6) | |
| 608 | (1 << art::arm::R7) | |
| 609 | (1 << art::arm::R8) | |
| 610 | (1 << art::arm::R9) | |
| 611 | (1 << art::arm::R10) | |
| 612 | (1 << art::arm::R11) | |
| 613 | (1 << art::arm::LR)); |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 614 | method->SetFpSpillMask((1 << art::arm::S0) | |
| 615 | (1 << art::arm::S1) | |
| 616 | (1 << art::arm::S2) | |
| 617 | (1 << art::arm::S3) | |
| 618 | (1 << art::arm::S4) | |
| 619 | (1 << art::arm::S5) | |
| 620 | (1 << art::arm::S6) | |
| 621 | (1 << art::arm::S7) | |
| 622 | (1 << art::arm::S8) | |
| 623 | (1 << art::arm::S9) | |
| 624 | (1 << art::arm::S10) | |
| 625 | (1 << art::arm::S11) | |
| 626 | (1 << art::arm::S12) | |
| 627 | (1 << art::arm::S13) | |
| 628 | (1 << art::arm::S14) | |
| 629 | (1 << art::arm::S15) | |
| 630 | (1 << art::arm::S16) | |
| 631 | (1 << art::arm::S17) | |
| 632 | (1 << art::arm::S18) | |
| 633 | (1 << art::arm::S19) | |
| 634 | (1 << art::arm::S20) | |
| 635 | (1 << art::arm::S21) | |
| 636 | (1 << art::arm::S22) | |
| 637 | (1 << art::arm::S23) | |
| 638 | (1 << art::arm::S24) | |
| 639 | (1 << art::arm::S25) | |
| 640 | (1 << art::arm::S26) | |
| 641 | (1 << art::arm::S27) | |
| 642 | (1 << art::arm::S28) | |
| 643 | (1 << art::arm::S29) | |
| 644 | (1 << art::arm::S30) | |
| 645 | (1 << art::arm::S31)); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 646 | } else if (insns == kX86) { |
| 647 | method->SetFrameSizeInBytes(32); |
| 648 | method->SetReturnPcOffsetInBytes(28); |
| 649 | method->SetCoreSpillMask((1 << art::x86::EBX) | |
| 650 | (1 << art::x86::EBP) | |
| 651 | (1 << art::x86::ESI) | |
| 652 | (1 << art::x86::EDI)); |
| 653 | method->SetFpSpillMask(0); |
| 654 | } else { |
| 655 | UNIMPLEMENTED(FATAL); |
| 656 | } |
| 657 | return method; |
| 658 | } |
| 659 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 660 | bool Runtime::HasCalleeSaveMethod() const { |
| 661 | return callee_save_method_ != NULL; |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 664 | // Returns a special method that describes all callee saves being spilled to the stack. |
| 665 | Method* Runtime::GetCalleeSaveMethod() const { |
| 666 | CHECK(callee_save_method_ != NULL); |
| 667 | return callee_save_method_; |
| 668 | } |
| 669 | |
| 670 | void Runtime::SetCalleeSaveMethod(Method* method) { |
| 671 | callee_save_method_ = method; |
| 672 | } |
| 673 | |
| 674 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 675 | } // namespace art |