Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "runtime.h" |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 18 | |
Brian Carlstrom | dbf05b7 | 2011-12-15 00:55:24 -0800 | [diff] [blame] | 19 | #include <signal.h> |
| 20 | |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 21 | #include <cstdio> |
| 22 | #include <cstdlib> |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 23 | #include <limits> |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 24 | #include <vector> |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 25 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 26 | #include "class_linker.h" |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 27 | #include "class_loader.h" |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 28 | #include "constants_arm.h" |
| 29 | #include "constants_x86.h" |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 30 | #include "debugger.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 31 | #include "heap.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 32 | #include "image.h" |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 33 | #include "intern_table.h" |
Elliott Hughes | c5f7c91 | 2011-08-18 14:00:42 -0700 | [diff] [blame] | 34 | #include "jni_internal.h" |
Elliott Hughes | 32d6e1e | 2011-10-11 14:47:44 -0700 | [diff] [blame] | 35 | #include "monitor.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 36 | #include "oat_file.h" |
Elliott Hughes | 726079d | 2011-10-07 18:43:44 -0700 | [diff] [blame] | 37 | #include "ScopedLocalRef.h" |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 38 | #include "signal_catcher.h" |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 39 | #include "signal_set.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 40 | #include "space.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 41 | #include "thread.h" |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 42 | #include "thread_list.h" |
jeffhao | b5e8185 | 2012-03-12 11:15:45 -0700 | [diff] [blame] | 43 | #include "trace.h" |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 44 | #include "UniquePtr.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 45 | #include "verifier/method_verifier.h" |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 46 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 47 | // TODO: this drags in cutil/log.h, which conflicts with our logging.h. |
| 48 | #include "JniConstants.h" |
| 49 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 50 | namespace art { |
| 51 | |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 52 | Runtime* Runtime::instance_ = NULL; |
| 53 | |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 54 | Runtime::Runtime() |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 55 | : is_compiler_(false), |
| 56 | is_zygote_(false), |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 57 | default_stack_size_(Thread::kDefaultStackSize), |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 58 | heap_(NULL), |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 59 | monitor_list_(NULL), |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 60 | thread_list_(NULL), |
| 61 | intern_table_(NULL), |
| 62 | class_linker_(NULL), |
| 63 | signal_catcher_(NULL), |
| 64 | java_vm_(NULL), |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 65 | jni_stub_array_(NULL), |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 66 | abstract_method_error_stub_array_(NULL), |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 67 | resolution_method_(NULL), |
Ian Rogers | 7c3757f | 2012-02-15 17:18:53 -0800 | [diff] [blame] | 68 | system_class_loader_(NULL), |
Elliott Hughes | 6b35575 | 2012-01-13 16:49:08 -0800 | [diff] [blame] | 69 | shutting_down_(false), |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 70 | started_(false), |
| 71 | vfprintf_(NULL), |
| 72 | exit_(NULL), |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 73 | abort_(NULL), |
jeffhao | 2692b57 | 2011-12-16 15:42:28 -0800 | [diff] [blame] | 74 | stats_enabled_(false), |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 75 | method_trace_(0), |
| 76 | method_trace_file_size_(0), |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 77 | tracer_(NULL), |
| 78 | use_compile_time_class_path_(false) { |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 79 | for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) { |
| 80 | resolution_stub_array_[i] = NULL; |
| 81 | } |
| 82 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 83 | callee_save_method_[i] = NULL; |
| 84 | } |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 87 | Runtime::~Runtime() { |
Elliott Hughes | 6b35575 | 2012-01-13 16:49:08 -0800 | [diff] [blame] | 88 | shutting_down_ = true; |
| 89 | |
jeffhao | b5e8185 | 2012-03-12 11:15:45 -0700 | [diff] [blame] | 90 | if (IsMethodTracingActive()) { |
| 91 | Trace::Shutdown(); |
| 92 | } |
| 93 | |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 94 | // Make sure our internal threads are dead before we start tearing down things they're using. |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 95 | Dbg::StopJdwp(); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 96 | delete signal_catcher_; |
| 97 | |
Elliott Hughes | 038a806 | 2011-09-18 14:12:41 -0700 | [diff] [blame] | 98 | // 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] | 99 | delete thread_list_; |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 100 | delete monitor_list_; |
Elliott Hughes | 93e74e8 | 2011-09-13 11:07:03 -0700 | [diff] [blame] | 101 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 102 | delete class_linker_; |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 103 | delete heap_; |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 104 | #if defined(ART_USE_LLVM_COMPILER) |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 105 | verifier::MethodVerifier::DeleteInferredRegCategoryMaps(); |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 106 | #endif |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 107 | verifier::MethodVerifier::DeleteGcMaps(); |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 108 | delete intern_table_; |
Elliott Hughes | c5f7c91 | 2011-08-18 14:00:42 -0700 | [diff] [blame] | 109 | delete java_vm_; |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 110 | Thread::Shutdown(); |
Elliott Hughes | 7c6169d | 2012-05-02 16:11:48 -0700 | [diff] [blame^] | 111 | QuasiAtomic::Shutdown(); |
| 112 | |
Carl Shapiro | 4acf464 | 2011-07-26 18:54:13 -0700 | [diff] [blame] | 113 | // TODO: acquire a static mutex on Runtime to avoid racing. |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 114 | CHECK(instance_ == NULL || instance_ == this); |
Carl Shapiro | 4acf464 | 2011-07-26 18:54:13 -0700 | [diff] [blame] | 115 | instance_ = NULL; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Elliott Hughes | cac6cc7 | 2011-11-03 20:31:21 -0700 | [diff] [blame] | 118 | static bool gAborting = false; |
| 119 | |
Elliott Hughes | e091855 | 2011-10-28 17:18:29 -0700 | [diff] [blame] | 120 | struct AbortState { |
| 121 | void Dump(std::ostream& os) { |
Elliott Hughes | cac6cc7 | 2011-11-03 20:31:21 -0700 | [diff] [blame] | 122 | if (gAborting) { |
| 123 | os << "Runtime aborting --- recursively, so no thread-specific detail!\n"; |
| 124 | return; |
| 125 | } |
| 126 | gAborting = true; |
Elliott Hughes | e091855 | 2011-10-28 17:18:29 -0700 | [diff] [blame] | 127 | os << "Runtime aborting...\n"; |
Elliott Hughes | 6c7d244 | 2012-02-01 18:40:47 -0800 | [diff] [blame] | 128 | if (Runtime::Current() == NULL) { |
| 129 | os << "(Runtime does not yet exist!)\n"; |
| 130 | return; |
| 131 | } |
Elliott Hughes | e091855 | 2011-10-28 17:18:29 -0700 | [diff] [blame] | 132 | Thread* self = Thread::Current(); |
| 133 | if (self == NULL) { |
| 134 | os << "(Aborting thread was not attached to runtime!)\n"; |
| 135 | } else { |
Elliott Hughes | 899e789 | 2012-01-24 14:57:32 -0800 | [diff] [blame] | 136 | self->Dump(os); |
| 137 | if (self->IsExceptionPending()) { |
| 138 | os << "Pending " << PrettyTypeOf(self->GetException()) << " on thread:\n" |
| 139 | << self->GetException()->Dump(); |
| 140 | } |
Elliott Hughes | e091855 | 2011-10-28 17:18:29 -0700 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | }; |
| 144 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 145 | static Mutex& GetAbortLock() { |
| 146 | static Mutex abort_lock("abort lock"); |
| 147 | return abort_lock; |
| 148 | } |
| 149 | |
Elliott Hughes | 8593fdb | 2012-04-21 20:53:44 -0700 | [diff] [blame] | 150 | void Runtime::Abort() { |
Elliott Hughes | 131aef8 | 2012-01-27 11:53:35 -0800 | [diff] [blame] | 151 | // Ensure that we don't have multiple threads trying to abort at once, |
| 152 | // which would result in significantly worse diagnostics. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 153 | MutexLock mu(GetAbortLock()); |
Elliott Hughes | 131aef8 | 2012-01-27 11:53:35 -0800 | [diff] [blame] | 154 | |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 155 | // Get any pending output out of the way. |
| 156 | fflush(NULL); |
| 157 | |
| 158 | // Many people have difficulty distinguish aborts from crashes, |
| 159 | // so be explicit. |
Elliott Hughes | e091855 | 2011-10-28 17:18:29 -0700 | [diff] [blame] | 160 | AbortState state; |
Elliott Hughes | 9ee5f9c | 2012-02-03 18:33:16 -0800 | [diff] [blame] | 161 | LOG(INTERNAL_FATAL) << Dumpable<AbortState>(state); |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 162 | |
Elliott Hughes | 8593fdb | 2012-04-21 20:53:44 -0700 | [diff] [blame] | 163 | // Call the abort hook if we have one. |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 164 | if (Runtime::Current() != NULL && Runtime::Current()->abort_ != NULL) { |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 165 | LOG(INTERNAL_FATAL) << "Calling abort hook..."; |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 166 | Runtime::Current()->abort_(); |
| 167 | // notreached |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 168 | LOG(INTERNAL_FATAL) << "Unexpectedly returned from abort hook!"; |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 171 | // TODO: finish merging patches to fix abort(3) in bionic, then lose this! |
| 172 | // Bionic doesn't implement POSIX semantics for abort(3) in a multi-threaded |
| 173 | // process, so 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] | 174 | // receive SIGABRT. debuggerd dumps the stack trace of the main |
| 175 | // thread, whether or not that was the thread that failed. By |
| 176 | // stuffing a value into a bogus address, we cause a segmentation |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 177 | // fault in the current thread, and get a useful log from debuggerd. |
Elliott Hughes | 81ff318 | 2012-03-23 20:35:56 -0700 | [diff] [blame] | 178 | // We can also trivially tell the difference between a crash and |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 179 | // a deliberate abort by looking at the fault address. |
| 180 | *reinterpret_cast<char*>(0xdeadd00d) = 38; |
| 181 | abort(); |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 182 | // notreached |
| 183 | } |
| 184 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 185 | void Runtime::CallExitHook(jint status) { |
| 186 | if (exit_ != NULL) { |
Elliott Hughes | 34e0696 | 2012-04-09 13:55:55 -0700 | [diff] [blame] | 187 | ScopedThreadStateChange tsc(Thread::Current(), kNative); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 188 | exit_(status); |
| 189 | LOG(WARNING) << "Exit hook returned instead of exiting!"; |
| 190 | } |
| 191 | } |
| 192 | |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 193 | // Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify |
| 194 | // memory sizes. [kK] indicates kilobytes, [mM] megabytes, and |
| 195 | // [gG] gigabytes. |
| 196 | // |
| 197 | // "s" should point just past the "-Xm?" part of the string. |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 198 | // "div" specifies a divisor, e.g. 1024 if the value must be a multiple |
| 199 | // of 1024. |
| 200 | // |
| 201 | // The spec says the -Xmx and -Xms options must be multiples of 1024. It |
| 202 | // doesn't say anything about -Xss. |
| 203 | // |
| 204 | // Returns 0 (a useless size) if "s" is malformed or specifies a low or |
| 205 | // non-evenly-divisible value. |
| 206 | // |
Elliott Hughes | c1f143d | 2011-12-01 17:31:10 -0800 | [diff] [blame] | 207 | size_t ParseMemoryOption(const char* s, size_t div) { |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 208 | // strtoul accepts a leading [+-], which we don't want, |
| 209 | // so make sure our string starts with a decimal digit. |
| 210 | if (isdigit(*s)) { |
Elliott Hughes | 398f64b | 2012-03-26 18:05:48 -0700 | [diff] [blame] | 211 | char* s2; |
| 212 | size_t val = strtoul(s, &s2, 10); |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 213 | if (s2 != s) { |
| 214 | // s2 should be pointing just after the number. |
| 215 | // If this is the end of the string, the user |
| 216 | // has specified a number of bytes. Otherwise, |
| 217 | // there should be exactly one more character |
| 218 | // that specifies a multiplier. |
| 219 | if (*s2 != '\0') { |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 220 | // The remainder of the string is either a single multiplier |
| 221 | // character, or nothing to indicate that the value is in |
| 222 | // bytes. |
| 223 | char c = *s2++; |
| 224 | if (*s2 == '\0') { |
| 225 | size_t mul; |
| 226 | if (c == '\0') { |
| 227 | mul = 1; |
| 228 | } else if (c == 'k' || c == 'K') { |
| 229 | mul = KB; |
| 230 | } else if (c == 'm' || c == 'M') { |
| 231 | mul = MB; |
| 232 | } else if (c == 'g' || c == 'G') { |
| 233 | mul = GB; |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 234 | } else { |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 235 | // Unknown multiplier character. |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 236 | return 0; |
| 237 | } |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 238 | |
| 239 | if (val <= std::numeric_limits<size_t>::max() / mul) { |
| 240 | val *= mul; |
| 241 | } else { |
| 242 | // Clamp to a multiple of 1024. |
| 243 | val = std::numeric_limits<size_t>::max() & ~(1024-1); |
| 244 | } |
| 245 | } else { |
| 246 | // There's more than one character after the numeric part. |
| 247 | return 0; |
| 248 | } |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 249 | } |
| 250 | // The man page says that a -Xm value must be a multiple of 1024. |
| 251 | if (val % div == 0) { |
| 252 | return val; |
| 253 | } |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 256 | return 0; |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 259 | size_t ParseIntegerOrDie(const std::string& s) { |
| 260 | std::string::size_type colon = s.find(':'); |
| 261 | if (colon == std::string::npos) { |
Elliott Hughes | bb1e8f0 | 2011-10-18 14:14:25 -0700 | [diff] [blame] | 262 | LOG(FATAL) << "Missing integer: " << s; |
| 263 | } |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 264 | const char* begin = &s[colon + 1]; |
Elliott Hughes | bb1e8f0 | 2011-10-18 14:14:25 -0700 | [diff] [blame] | 265 | char* end; |
| 266 | size_t result = strtoul(begin, &end, 10); |
| 267 | if (begin == end || *end != '\0') { |
| 268 | LOG(FATAL) << "Failed to parse integer in: " << s; |
| 269 | } |
| 270 | return result; |
| 271 | } |
| 272 | |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 273 | void LoadJniLibrary(JavaVMExt* vm, const char* name) { |
Elliott Hughes | 6cc332e | 2012-01-20 22:59:20 -0800 | [diff] [blame] | 274 | std::string mapped_name(StringPrintf(OS_SHARED_LIB_FORMAT_STR, name)); |
Elliott Hughes | 7577075 | 2011-08-24 17:52:38 -0700 | [diff] [blame] | 275 | std::string reason; |
| 276 | if (!vm->LoadNativeLibrary(mapped_name, NULL, reason)) { |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 277 | LOG(FATAL) << "LoadNativeLibrary failed for \"" << mapped_name << "\": " |
| 278 | << reason; |
| 279 | } |
| 280 | } |
| 281 | |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 282 | Runtime::ParsedOptions* Runtime::ParsedOptions::Create(const Options& options, bool ignore_unrecognized) { |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 283 | UniquePtr<ParsedOptions> parsed(new ParsedOptions()); |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 284 | const char* boot_class_path_string = getenv("BOOTCLASSPATH"); |
| 285 | if (boot_class_path_string != NULL) { |
| 286 | parsed->boot_class_path_string_ = boot_class_path_string; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 287 | } |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 288 | const char* class_path_string = getenv("CLASSPATH"); |
| 289 | if (class_path_string != NULL) { |
| 290 | parsed->class_path_string_ = class_path_string; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 291 | } |
Elliott Hughes | 67d9200 | 2012-03-26 15:08:51 -0700 | [diff] [blame] | 292 | // -Xcheck:jni is off by default for regular builds but on by default in debug builds. |
| 293 | parsed->check_jni_ = kIsDebugBuild; |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 294 | |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 295 | parsed->heap_initial_size_ = Heap::kInitialSize; |
| 296 | parsed->heap_maximum_size_ = Heap::kMaximumSize; |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 297 | parsed->heap_growth_limit_ = 0; // 0 means no growth limit |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 298 | parsed->stack_size_ = Thread::kDefaultStackSize; |
| 299 | |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 300 | parsed->is_compiler_ = false; |
Elliott Hughes | 9ca7a1f | 2011-10-11 14:29:52 -0700 | [diff] [blame] | 301 | parsed->is_zygote_ = false; |
| 302 | |
Elliott Hughes | bb1e8f0 | 2011-10-18 14:14:25 -0700 | [diff] [blame] | 303 | parsed->jni_globals_max_ = 0; |
Elliott Hughes | fc86162 | 2011-10-17 17:57:47 -0700 | [diff] [blame] | 304 | parsed->lock_profiling_threshold_ = 0; |
| 305 | parsed->hook_is_sensitive_thread_ = NULL; |
| 306 | |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 307 | parsed->hook_vfprintf_ = vfprintf; |
| 308 | parsed->hook_exit_ = exit; |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 309 | parsed->hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort. |
| 310 | #if defined(__APPLE__) |
| 311 | parsed->hook_abort_ = abort; // On the Mac, abort(3) gives better results; see Runtime::InitPlatformSignalHandlers. |
| 312 | #endif |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 313 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 314 | // gLogVerbosity.class_linker = true; // TODO: don't check this in! |
| 315 | // gLogVerbosity.compiler = true; // TODO: don't check this in! |
| 316 | // gLogVerbosity.heap = true; // TODO: don't check this in! |
| 317 | // gLogVerbosity.gc = true; // TODO: don't check this in! |
| 318 | // gLogVerbosity.jdwp = true; // TODO: don't check this in! |
| 319 | // gLogVerbosity.jni = true; // TODO: don't check this in! |
| 320 | // gLogVerbosity.monitor = true; // TODO: don't check this in! |
| 321 | // gLogVerbosity.startup = true; // TODO: don't check this in! |
| 322 | // gLogVerbosity.third_party_jni = true; // TODO: don't check this in! |
| 323 | // gLogVerbosity.threads = true; // TODO: don't check this in! |
| 324 | |
jeffhao | b5e8185 | 2012-03-12 11:15:45 -0700 | [diff] [blame] | 325 | parsed->method_trace_ = false; |
| 326 | parsed->method_trace_file_ = "/data/method-trace-file.bin"; |
| 327 | parsed->method_trace_file_size_ = 10 * MB; |
| 328 | |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 329 | for (size_t i = 0; i < options.size(); ++i) { |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 330 | const std::string option(options[i].first); |
Brian Carlstrom | 0796af0 | 2011-10-12 14:31:45 -0700 | [diff] [blame] | 331 | if (true && options[0].first == "-Xzygote") { |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 332 | LOG(INFO) << "option[" << i << "]=" << option; |
| 333 | } |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 334 | if (StartsWith(option, "-Xbootclasspath:")) { |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 335 | parsed->boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data(); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 336 | } else if (option == "-classpath" || option == "-cp") { |
| 337 | // TODO: support -Djava.class.path |
| 338 | i++; |
| 339 | if (i == options.size()) { |
| 340 | // TODO: usage |
| 341 | LOG(FATAL) << "Missing required class path value for " << option; |
| 342 | return NULL; |
| 343 | } |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 344 | const StringPiece& value = options[i].first; |
| 345 | parsed->class_path_string_ = value.data(); |
| 346 | } else if (option == "bootclasspath") { |
| 347 | parsed->boot_class_path_ |
| 348 | = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second); |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 349 | } else if (StartsWith(option, "-Ximage:")) { |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 350 | parsed->image_ = option.substr(strlen("-Ximage:")).data(); |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 351 | } else if (StartsWith(option, "-Xcheck:jni")) { |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 352 | parsed->check_jni_ = true; |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 353 | } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) { |
| 354 | std::string tail(option.substr(option[1] == 'X' ? 10 : 15)); |
Elliott Hughes | 3bb8156 | 2011-10-21 18:52:59 -0700 | [diff] [blame] | 355 | if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) { |
| 356 | LOG(FATAL) << "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n" |
| 357 | << "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n"; |
| 358 | return NULL; |
| 359 | } |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 360 | } else if (StartsWith(option, "-Xms")) { |
| 361 | size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024); |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 362 | if (size == 0) { |
| 363 | if (ignore_unrecognized) { |
| 364 | continue; |
| 365 | } |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 366 | // TODO: usage |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 367 | LOG(FATAL) << "Failed to parse " << option; |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 368 | return NULL; |
| 369 | } |
| 370 | parsed->heap_initial_size_ = size; |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 371 | } else if (StartsWith(option, "-Xmx")) { |
| 372 | size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024); |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 373 | if (size == 0) { |
| 374 | if (ignore_unrecognized) { |
| 375 | continue; |
| 376 | } |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 377 | // TODO: usage |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 378 | LOG(FATAL) << "Failed to parse " << option; |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 379 | return NULL; |
| 380 | } |
| 381 | parsed->heap_maximum_size_ = size; |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 382 | } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) { |
| 383 | size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024); |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 384 | if (size == 0) { |
| 385 | if (ignore_unrecognized) { |
| 386 | continue; |
| 387 | } |
| 388 | // TODO: usage |
| 389 | LOG(FATAL) << "Failed to parse " << option; |
| 390 | return NULL; |
| 391 | } |
| 392 | parsed->heap_growth_limit_ = size; |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 393 | } else if (StartsWith(option, "-Xss")) { |
| 394 | size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1); |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 395 | if (size == 0) { |
| 396 | if (ignore_unrecognized) { |
| 397 | continue; |
| 398 | } |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 399 | // TODO: usage |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 400 | LOG(FATAL) << "Failed to parse " << option; |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 401 | return NULL; |
| 402 | } |
| 403 | parsed->stack_size_ = size; |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 404 | } else if (StartsWith(option, "-D")) { |
| 405 | parsed->properties_.push_back(option.substr(strlen("-D"))); |
| 406 | } else if (StartsWith(option, "-Xjnitrace:")) { |
| 407 | parsed->jni_trace_ = option.substr(strlen("-Xjnitrace:")); |
Brian Carlstrom | 5de8fe5 | 2011-10-16 14:10:09 -0700 | [diff] [blame] | 408 | } else if (option == "compiler") { |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 409 | parsed->is_compiler_ = true; |
Elliott Hughes | 9ca7a1f | 2011-10-11 14:29:52 -0700 | [diff] [blame] | 410 | } else if (option == "-Xzygote") { |
| 411 | parsed->is_zygote_ = true; |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 412 | } else if (StartsWith(option, "-verbose:")) { |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 413 | std::vector<std::string> verbose_options; |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 414 | Split(option.substr(strlen("-verbose:")), ',', verbose_options); |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 415 | for (size_t i = 0; i < verbose_options.size(); ++i) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 416 | if (verbose_options[i] == "class") { |
| 417 | gLogVerbosity.class_linker = true; |
| 418 | } else if (verbose_options[i] == "compiler") { |
| 419 | gLogVerbosity.compiler = true; |
| 420 | } else if (verbose_options[i] == "heap") { |
| 421 | gLogVerbosity.heap = true; |
| 422 | } else if (verbose_options[i] == "gc") { |
| 423 | gLogVerbosity.gc = true; |
| 424 | } else if (verbose_options[i] == "jdwp") { |
| 425 | gLogVerbosity.jdwp = true; |
| 426 | } else if (verbose_options[i] == "jni") { |
| 427 | gLogVerbosity.jni = true; |
| 428 | } else if (verbose_options[i] == "monitor") { |
| 429 | gLogVerbosity.monitor = true; |
| 430 | } else if (verbose_options[i] == "startup") { |
| 431 | gLogVerbosity.startup = true; |
| 432 | } else if (verbose_options[i] == "third-party-jni") { |
| 433 | gLogVerbosity.third_party_jni = true; |
| 434 | } else if (verbose_options[i] == "threads") { |
| 435 | gLogVerbosity.threads = true; |
| 436 | } else { |
| 437 | LOG(WARNING) << "Ignoring unknown -verbose option: " << verbose_options[i]; |
| 438 | } |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 439 | } |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 440 | } else if (StartsWith(option, "-Xjnigreflimit:")) { |
Elliott Hughes | bb1e8f0 | 2011-10-18 14:14:25 -0700 | [diff] [blame] | 441 | parsed->jni_globals_max_ = ParseIntegerOrDie(option); |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 442 | } else if (StartsWith(option, "-Xlockprofthreshold:")) { |
Elliott Hughes | bb1e8f0 | 2011-10-18 14:14:25 -0700 | [diff] [blame] | 443 | parsed->lock_profiling_threshold_ = ParseIntegerOrDie(option); |
Elliott Hughes | f1a5adc | 2012-02-10 18:09:35 -0800 | [diff] [blame] | 444 | } else if (StartsWith(option, "-Xstacktracefile:")) { |
Elliott Hughes | 67d9200 | 2012-03-26 15:08:51 -0700 | [diff] [blame] | 445 | if (kIsDebugBuild) { |
| 446 | // Ignore the zygote and always show stack traces in debug builds. |
| 447 | } else { |
| 448 | parsed->stack_trace_file_ = option.substr(strlen("-Xstacktracefile:")); |
| 449 | } |
Elliott Hughes | fc86162 | 2011-10-17 17:57:47 -0700 | [diff] [blame] | 450 | } else if (option == "sensitiveThread") { |
| 451 | parsed->hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(options[i].second); |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 452 | } else if (option == "vfprintf") { |
| 453 | parsed->hook_vfprintf_ = reinterpret_cast<int (*)(FILE *, const char*, va_list)>(options[i].second); |
| 454 | } else if (option == "exit") { |
| 455 | parsed->hook_exit_ = reinterpret_cast<void(*)(jint)>(options[i].second); |
| 456 | } else if (option == "abort") { |
| 457 | parsed->hook_abort_ = reinterpret_cast<void(*)()>(options[i].second); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 458 | } else if (option == "host-prefix") { |
| 459 | parsed->host_prefix_ = reinterpret_cast<const char*>(options[i].second); |
Elliott Hughes | b3e66df | 2012-01-12 14:49:18 -0800 | [diff] [blame] | 460 | } else if (option == "-Xgenregmap" || option == "-Xgc:precise") { |
| 461 | // We silently ignore these for backwards compatibility. |
jeffhao | b5e8185 | 2012-03-12 11:15:45 -0700 | [diff] [blame] | 462 | } else if (option == "-Xmethod-trace") { |
| 463 | parsed->method_trace_ = true; |
| 464 | } else if (StartsWith(option, "-Xmethod-trace-file:")) { |
| 465 | parsed->method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:")); |
| 466 | } else if (StartsWith(option, "-Xmethod-trace-file-size:")) { |
| 467 | parsed->method_trace_file_size_ = ParseIntegerOrDie(option); |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 468 | } else { |
| 469 | if (!ignore_unrecognized) { |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 470 | // TODO: print usage via vfprintf |
Brian Carlstrom | 27ec961 | 2011-09-19 20:20:38 -0700 | [diff] [blame] | 471 | LOG(ERROR) << "Unrecognized option " << option; |
| 472 | // TODO: this should exit, but for now tolerate unknown options |
| 473 | //return NULL; |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
Brian Carlstrom | 223f20f | 2012-02-04 23:06:55 -0800 | [diff] [blame] | 478 | if (!parsed->is_compiler_ && parsed->image_.empty()) { |
| 479 | parsed->image_ += GetAndroidRoot(); |
| 480 | parsed->image_ += "/framework/boot.art"; |
Brian Carlstrom | 5de8fe5 | 2011-10-16 14:10:09 -0700 | [diff] [blame] | 481 | } |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 482 | if (parsed->heap_growth_limit_ == 0) { |
| 483 | parsed->heap_growth_limit_ = parsed->heap_maximum_size_; |
| 484 | } |
Brian Carlstrom | 5de8fe5 | 2011-10-16 14:10:09 -0700 | [diff] [blame] | 485 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 486 | return parsed.release(); |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | Runtime* Runtime::Create(const Options& options, bool ignore_unrecognized) { |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 490 | // TODO: acquire a static mutex on Runtime to avoid racing. |
| 491 | if (Runtime::instance_ != NULL) { |
| 492 | return NULL; |
| 493 | } |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 494 | instance_ = new Runtime; |
| 495 | if (!instance_->Init(options, ignore_unrecognized)) { |
| 496 | delete instance_; |
| 497 | instance_ = NULL; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 498 | } |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 499 | return instance_; |
| 500 | } |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 501 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 502 | void CreateSystemClassLoader() { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 503 | if (Runtime::Current()->UseCompileTimeClassPath()) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 504 | return; |
| 505 | } |
| 506 | |
| 507 | Thread* self = Thread::Current(); |
| 508 | |
| 509 | // Must be in the kNative state for calling native methods. |
Elliott Hughes | 34e0696 | 2012-04-09 13:55:55 -0700 | [diff] [blame] | 510 | CHECK_EQ(self->GetState(), kNative); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 511 | |
| 512 | JNIEnv* env = self->GetJniEnv(); |
Brian Carlstrom | df14324 | 2011-10-10 18:05:34 -0700 | [diff] [blame] | 513 | ScopedLocalRef<jclass> ClassLoader_class(env, env->FindClass("java/lang/ClassLoader")); |
| 514 | CHECK(ClassLoader_class.get() != NULL); |
| 515 | jmethodID getSystemClassLoader = env->GetStaticMethodID(ClassLoader_class.get(), |
| 516 | "getSystemClassLoader", |
| 517 | "()Ljava/lang/ClassLoader;"); |
| 518 | CHECK(getSystemClassLoader != NULL); |
| 519 | ScopedLocalRef<jobject> class_loader(env, env->CallStaticObjectMethod(ClassLoader_class.get(), |
| 520 | getSystemClassLoader)); |
| 521 | CHECK(class_loader.get() != NULL); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 522 | |
Brian Carlstrom | df14324 | 2011-10-10 18:05:34 -0700 | [diff] [blame] | 523 | Thread::Current()->SetClassLoaderOverride(Decode<ClassLoader*>(env, class_loader.get())); |
Jesse Wilson | 1b2b2f2 | 2011-11-22 11:47:44 -0500 | [diff] [blame] | 524 | |
| 525 | ScopedLocalRef<jclass> Thread_class(env, env->FindClass("java/lang/Thread")); |
| 526 | CHECK(Thread_class.get() != NULL); |
| 527 | jfieldID contextClassLoader = env->GetFieldID(Thread_class.get(), |
| 528 | "contextClassLoader", |
| 529 | "Ljava/lang/ClassLoader;"); |
| 530 | CHECK(contextClassLoader != NULL); |
| 531 | ScopedLocalRef<jobject> self_jobject(env, AddLocalReference<jobject>(env, self->GetPeer())); |
| 532 | env->SetObjectField(self_jobject.get(), contextClassLoader, class_loader.get()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 535 | void Runtime::Start() { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 536 | VLOG(startup) << "Runtime::Start entering"; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 537 | |
| 538 | CHECK(host_prefix_.empty()) << host_prefix_; |
| 539 | |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 540 | // Relocate the OatFiles (ELF images) |
| 541 | class_linker_->RelocateExecutable(); |
| 542 | |
Brian Carlstrom | f28bc5b | 2011-10-26 01:15:03 -0700 | [diff] [blame] | 543 | // Restore main thread state to kNative as expected by native code |
Elliott Hughes | 34e0696 | 2012-04-09 13:55:55 -0700 | [diff] [blame] | 544 | Thread::Current()->SetState(kNative); |
Brian Carlstrom | f28bc5b | 2011-10-26 01:15:03 -0700 | [diff] [blame] | 545 | |
Brian Carlstrom | 5d40f18 | 2011-09-26 22:29:18 -0700 | [diff] [blame] | 546 | started_ = true; |
| 547 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 548 | // InitNativeMethods needs to be after started_ so that the classes |
| 549 | // it touches will have methods linked to the oat file if necessary. |
| 550 | InitNativeMethods(); |
| 551 | |
Jesse Wilson | 9a6bae8 | 2011-11-14 14:57:30 -0500 | [diff] [blame] | 552 | Thread::FinishStartup(); |
| 553 | |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 554 | if (!is_zygote_) { |
| 555 | DidForkFromZygote(); |
| 556 | } |
Elliott Hughes | 9ca7a1f | 2011-10-11 14:29:52 -0700 | [diff] [blame] | 557 | |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 558 | StartDaemonThreads(); |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 559 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 560 | CreateSystemClassLoader(); |
| 561 | |
Elliott Hughes | 726079d | 2011-10-07 18:43:44 -0700 | [diff] [blame] | 562 | Thread::Current()->GetJniEnv()->locals.AssertEmpty(); |
| 563 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 564 | VLOG(startup) << "Runtime::Start exiting"; |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Brian Carlstrom | caabb1b | 2011-10-11 18:09:13 -0700 | [diff] [blame] | 567 | void Runtime::DidForkFromZygote() { |
Brian Carlstrom | caabb1b | 2011-10-11 18:09:13 -0700 | [diff] [blame] | 568 | is_zygote_ = false; |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 569 | |
Brian Carlstrom | caabb1b | 2011-10-11 18:09:13 -0700 | [diff] [blame] | 570 | StartSignalCatcher(); |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 571 | |
| 572 | // Start the JDWP thread. If the command-line debugger flags specified "suspend=y", |
| 573 | // this will pause the runtime, so we probably want this to come last. |
| 574 | Dbg::StartJdwp(); |
Brian Carlstrom | caabb1b | 2011-10-11 18:09:13 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | void Runtime::StartSignalCatcher() { |
| 578 | if (!is_zygote_) { |
Elliott Hughes | 94ce37a | 2011-10-18 15:07:48 -0700 | [diff] [blame] | 579 | signal_catcher_ = new SignalCatcher(stack_trace_file_); |
Brian Carlstrom | caabb1b | 2011-10-11 18:09:13 -0700 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 583 | void Runtime::StartDaemonThreads() { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 584 | VLOG(startup) << "Runtime::StartDaemonThreads entering"; |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 585 | |
Elliott Hughes | 719b323 | 2011-09-25 17:42:19 -0700 | [diff] [blame] | 586 | Thread* self = Thread::Current(); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 587 | |
| 588 | // Must be in the kNative state for calling native methods. |
Elliott Hughes | 34e0696 | 2012-04-09 13:55:55 -0700 | [diff] [blame] | 589 | CHECK_EQ(self->GetState(), kNative); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 590 | |
Elliott Hughes | 719b323 | 2011-09-25 17:42:19 -0700 | [diff] [blame] | 591 | JNIEnv* env = self->GetJniEnv(); |
Elliott Hughes | 726079d | 2011-10-07 18:43:44 -0700 | [diff] [blame] | 592 | ScopedLocalRef<jclass> c(env, env->FindClass("java/lang/Daemons")); |
| 593 | CHECK(c.get() != NULL); |
| 594 | jmethodID mid = env->GetStaticMethodID(c.get(), "start", "()V"); |
Elliott Hughes | 719b323 | 2011-09-25 17:42:19 -0700 | [diff] [blame] | 595 | CHECK(mid != NULL); |
Elliott Hughes | 726079d | 2011-10-07 18:43:44 -0700 | [diff] [blame] | 596 | env->CallStaticVoidMethod(c.get(), mid); |
Elliott Hughes | 8cf5bc0 | 2012-02-02 16:32:16 -0800 | [diff] [blame] | 597 | CHECK(!env->ExceptionCheck()); |
Elliott Hughes | 9ca7a1f | 2011-10-11 14:29:52 -0700 | [diff] [blame] | 598 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 599 | VLOG(startup) << "Runtime::StartDaemonThreads exiting"; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Elliott Hughes | 6b35575 | 2012-01-13 16:49:08 -0800 | [diff] [blame] | 602 | bool Runtime::IsShuttingDown() const { |
| 603 | return shutting_down_; |
| 604 | } |
| 605 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 606 | bool Runtime::IsStarted() const { |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 607 | return started_; |
| 608 | } |
| 609 | |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 610 | bool Runtime::Init(const Options& raw_options, bool ignore_unrecognized) { |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 611 | CHECK_EQ(sysconf(_SC_PAGE_SIZE), kPageSize); |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 612 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 613 | UniquePtr<ParsedOptions> options(ParsedOptions::Create(raw_options, ignore_unrecognized)); |
| 614 | if (options.get() == NULL) { |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 615 | LOG(ERROR) << "Failed to parse options"; |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 616 | return false; |
| 617 | } |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 618 | VLOG(startup) << "Runtime::Init -verbose:startup enabled"; |
Elliott Hughes | 7ede61e | 2011-09-14 18:18:06 -0700 | [diff] [blame] | 619 | |
Elliott Hughes | 7c6169d | 2012-05-02 16:11:48 -0700 | [diff] [blame^] | 620 | QuasiAtomic::Startup(); |
| 621 | |
Elliott Hughes | bb1e8f0 | 2011-10-18 14:14:25 -0700 | [diff] [blame] | 622 | SetJniGlobalsMax(options->jni_globals_max_); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 623 | Monitor::Init(options->lock_profiling_threshold_, options->hook_is_sensitive_thread_); |
Elliott Hughes | 32d6e1e | 2011-10-11 14:47:44 -0700 | [diff] [blame] | 624 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 625 | host_prefix_ = options->host_prefix_; |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 626 | boot_class_path_string_ = options->boot_class_path_string_; |
| 627 | class_path_string_ = options->class_path_string_; |
Elliott Hughes | 7ede61e | 2011-09-14 18:18:06 -0700 | [diff] [blame] | 628 | properties_ = options->properties_; |
| 629 | |
Elliott Hughes | d9c67be | 2012-02-02 19:54:06 -0800 | [diff] [blame] | 630 | is_compiler_ = options->is_compiler_; |
Elliott Hughes | 9ca7a1f | 2011-10-11 14:29:52 -0700 | [diff] [blame] | 631 | is_zygote_ = options->is_zygote_; |
| 632 | |
Elliott Hughes | 0af5543 | 2011-08-17 18:37:28 -0700 | [diff] [blame] | 633 | vfprintf_ = options->hook_vfprintf_; |
| 634 | exit_ = options->hook_exit_; |
| 635 | abort_ = options->hook_abort_; |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 636 | |
Elliott Hughes | be759c6 | 2011-09-08 19:38:21 -0700 | [diff] [blame] | 637 | default_stack_size_ = options->stack_size_; |
Elliott Hughes | 94ce37a | 2011-10-18 15:07:48 -0700 | [diff] [blame] | 638 | stack_trace_file_ = options->stack_trace_file_; |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 639 | |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 640 | monitor_list_ = new MonitorList; |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 641 | thread_list_ = new ThreadList; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 642 | intern_table_ = new InternTable; |
| 643 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 644 | verifier::MethodVerifier::InitGcMaps(); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 645 | |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 646 | #if defined(ART_USE_LLVM_COMPILER) |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 647 | verifier::MethodVerifier::InitInferredRegCategoryMaps(); |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 648 | #endif |
| 649 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 650 | heap_ = new Heap(options->heap_initial_size_, |
| 651 | options->heap_growth_limit_, |
| 652 | options->heap_maximum_size_, |
| 653 | options->image_); |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 654 | |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 655 | BlockSignals(); |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 656 | InitPlatformSignalHandlers(); |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 657 | |
Elliott Hughes | a095764 | 2011-09-02 14:27:33 -0700 | [diff] [blame] | 658 | java_vm_ = new JavaVMExt(this, options.get()); |
Elliott Hughes | 515a5bc | 2011-08-17 11:08:34 -0700 | [diff] [blame] | 659 | |
Elliott Hughes | be759c6 | 2011-09-08 19:38:21 -0700 | [diff] [blame] | 660 | Thread::Startup(); |
Elliott Hughes | d92bec4 | 2011-09-02 17:04:36 -0700 | [diff] [blame] | 661 | |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 662 | // ClassLinker needs an attached thread, but we can't fully attach a thread |
Elliott Hughes | 462c944 | 2012-03-23 18:47:50 -0700 | [diff] [blame] | 663 | // without creating objects. We can't supply a thread group yet; it will be fixed later. |
| 664 | Thread::Attach("main", false, NULL); |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 665 | |
Brian Carlstrom | f28bc5b | 2011-10-26 01:15:03 -0700 | [diff] [blame] | 666 | // Set us to runnable so tools using a runtime can allocate and GC by default |
Elliott Hughes | 34e0696 | 2012-04-09 13:55:55 -0700 | [diff] [blame] | 667 | Thread::Current()->SetState(kRunnable); |
Brian Carlstrom | f28bc5b | 2011-10-26 01:15:03 -0700 | [diff] [blame] | 668 | |
Ian Rogers | 141d622 | 2012-04-05 12:23:06 -0700 | [diff] [blame] | 669 | // Now we're attached, we can take the heap lock and validate the heap. |
| 670 | GetHeap()->EnableObjectValidation(); |
| 671 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 672 | CHECK_GE(GetHeap()->GetSpaces().size(), 1U); |
| 673 | if (GetHeap()->GetSpaces()[0]->IsImageSpace()) { |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 674 | class_linker_ = ClassLinker::CreateFromImage(intern_table_); |
| 675 | } else { |
| 676 | CHECK(options->boot_class_path_ != NULL); |
| 677 | CHECK_NE(options->boot_class_path_->size(), 0U); |
| 678 | class_linker_ = ClassLinker::CreateFromCompiler(*options->boot_class_path_, intern_table_); |
| 679 | } |
| 680 | CHECK(class_linker_ != NULL); |
Brian Carlstrom | 6ea095a | 2011-08-16 15:26:54 -0700 | [diff] [blame] | 681 | |
jeffhao | b5e8185 | 2012-03-12 11:15:45 -0700 | [diff] [blame] | 682 | method_trace_ = options->method_trace_; |
| 683 | method_trace_file_ = options->method_trace_file_; |
| 684 | method_trace_file_size_ = options->method_trace_file_size_; |
| 685 | |
| 686 | if (options->method_trace_) { |
| 687 | Trace::Start(options->method_trace_file_.c_str(), -1, options->method_trace_file_size_, 0, false); |
| 688 | } |
| 689 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 690 | VLOG(startup) << "Runtime::Init exiting"; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 691 | return true; |
| 692 | } |
| 693 | |
Elliott Hughes | 038a806 | 2011-09-18 14:12:41 -0700 | [diff] [blame] | 694 | void Runtime::InitNativeMethods() { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 695 | VLOG(startup) << "Runtime::InitNativeMethods entering"; |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 696 | Thread* self = Thread::Current(); |
| 697 | JNIEnv* env = self->GetJniEnv(); |
| 698 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 699 | // Must be in the kNative state for calling native methods (JNI_OnLoad code). |
Elliott Hughes | 34e0696 | 2012-04-09 13:55:55 -0700 | [diff] [blame] | 700 | CHECK_EQ(self->GetState(), kNative); |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 701 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 702 | // First set up JniConstants, which is used by both the runtime's built-in native |
| 703 | // methods and libcore. |
Elliott Hughes | fea966e | 2011-09-22 10:26:20 -0700 | [diff] [blame] | 704 | JniConstants::init(env); |
| 705 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 706 | // Then set up the native methods provided by the runtime itself. |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 707 | RegisterRuntimeNativeMethods(env); |
| 708 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 709 | // Then set up libcore, which is just a regular JNI library with a regular JNI_OnLoad. |
| 710 | // Most JNI libraries can just use System.loadLibrary, but libcore can't because it's |
| 711 | // the library that implements System.loadLibrary! |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 712 | LoadJniLibrary(instance_->GetJavaVM(), "javacore"); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 713 | VLOG(startup) << "Runtime::InitNativeMethods exiting"; |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | void Runtime::RegisterRuntimeNativeMethods(JNIEnv* env) { |
| 717 | #define REGISTER(FN) extern void FN(JNIEnv*); FN(env) |
Ian Rogers | 5167c97 | 2012-02-03 10:41:20 -0800 | [diff] [blame] | 718 | // Register Throwable first so that registration of other native methods can throw exceptions |
| 719 | REGISTER(register_java_lang_Throwable); |
Brian Carlstrom | f91c8c3 | 2011-09-21 17:30:34 -0700 | [diff] [blame] | 720 | REGISTER(register_dalvik_system_DexFile); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 721 | REGISTER(register_dalvik_system_VMDebug); |
Elliott Hughes | 7ede61e | 2011-09-14 18:18:06 -0700 | [diff] [blame] | 722 | REGISTER(register_dalvik_system_VMRuntime); |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 723 | REGISTER(register_dalvik_system_VMStack); |
Elliott Hughes | 01158d7 | 2011-09-19 19:47:10 -0700 | [diff] [blame] | 724 | REGISTER(register_dalvik_system_Zygote); |
Elliott Hughes | d369bb7 | 2011-09-12 14:41:14 -0700 | [diff] [blame] | 725 | REGISTER(register_java_lang_Class); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 726 | REGISTER(register_java_lang_Object); |
| 727 | REGISTER(register_java_lang_Runtime); |
| 728 | REGISTER(register_java_lang_String); |
| 729 | REGISTER(register_java_lang_System); |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 730 | REGISTER(register_java_lang_Thread); |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 731 | REGISTER(register_java_lang_VMClassLoader); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 732 | REGISTER(register_java_lang_reflect_Array); |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 733 | REGISTER(register_java_lang_reflect_Constructor); |
Brian Carlstrom | f867b6f | 2011-09-16 12:17:25 -0700 | [diff] [blame] | 734 | REGISTER(register_java_lang_reflect_Field); |
| 735 | REGISTER(register_java_lang_reflect_Method); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 736 | REGISTER(register_java_lang_reflect_Proxy); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 737 | REGISTER(register_java_util_concurrent_atomic_AtomicLong); |
Brian Carlstrom | 395520e | 2011-09-25 19:35:00 -0700 | [diff] [blame] | 738 | REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmServer); |
Elliott Hughes | f6a1e1e | 2011-10-25 16:28:04 -0700 | [diff] [blame] | 739 | REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmVmInternal); |
Elliott Hughes | 5ee7a8b | 2011-09-13 16:40:07 -0700 | [diff] [blame] | 740 | REGISTER(register_sun_misc_Unsafe); |
Elliott Hughes | ad7c2a3 | 2011-08-31 11:58:10 -0700 | [diff] [blame] | 741 | #undef REGISTER |
| 742 | } |
| 743 | |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 744 | void Runtime::DumpForSigQuit(std::ostream& os) { |
Elliott Hughes | cac6cc7 | 2011-11-03 20:31:21 -0700 | [diff] [blame] | 745 | GetClassLinker()->DumpForSigQuit(os); |
| 746 | GetInternTable()->DumpForSigQuit(os); |
Elliott Hughes | ae80b49 | 2012-04-24 10:43:17 -0700 | [diff] [blame] | 747 | GetJavaVM()->DumpForSigQuit(os); |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 748 | GetHeap()->DumpForSigQuit(os); |
Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 749 | os << "\n"; |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 750 | |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 751 | thread_list_->DumpForSigQuit(os); |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Elliott Hughes | 21a5bf2 | 2011-12-07 14:35:20 -0800 | [diff] [blame] | 754 | void Runtime::DumpLockHolders(std::ostream& os) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 755 | pid_t heap_lock_owner = GetHeap()->GetLockOwner(); |
Elliott Hughes | 21a5bf2 | 2011-12-07 14:35:20 -0800 | [diff] [blame] | 756 | pid_t thread_list_lock_owner = GetThreadList()->GetLockOwner(); |
| 757 | pid_t classes_lock_owner = GetClassLinker()->GetClassesLockOwner(); |
| 758 | pid_t dex_lock_owner = GetClassLinker()->GetDexLockOwner(); |
| 759 | if ((heap_lock_owner | thread_list_lock_owner | classes_lock_owner | dex_lock_owner) != 0) { |
| 760 | os << "Heap lock owner tid: " << heap_lock_owner << "\n" |
| 761 | << "ThreadList lock owner tid: " << thread_list_lock_owner << "\n" |
| 762 | << "ClassLinker classes lock owner tid: " << classes_lock_owner << "\n" |
| 763 | << "ClassLinker dex lock owner tid: " << dex_lock_owner << "\n"; |
| 764 | } |
| 765 | } |
| 766 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 767 | void Runtime::SetStatsEnabled(bool new_state) { |
| 768 | if (new_state == true) { |
| 769 | GetStats()->Clear(~0); |
| 770 | // TODO: wouldn't it make more sense to clear _all_ threads' stats? |
| 771 | Thread::Current()->GetStats()->Clear(~0); |
| 772 | } |
| 773 | stats_enabled_ = new_state; |
| 774 | } |
| 775 | |
| 776 | void Runtime::ResetStats(int kinds) { |
| 777 | GetStats()->Clear(kinds & 0xffff); |
| 778 | // TODO: wouldn't it make more sense to clear _all_ threads' stats? |
| 779 | Thread::Current()->GetStats()->Clear(kinds >> 16); |
| 780 | } |
| 781 | |
| 782 | RuntimeStats* Runtime::GetStats() { |
| 783 | return &stats_; |
| 784 | } |
| 785 | |
| 786 | int32_t Runtime::GetStat(int kind) { |
| 787 | RuntimeStats* stats; |
| 788 | if (kind < (1<<16)) { |
| 789 | stats = GetStats(); |
| 790 | } else { |
| 791 | stats = Thread::Current()->GetStats(); |
| 792 | kind >>= 16; |
| 793 | } |
| 794 | switch (kind) { |
| 795 | case KIND_ALLOCATED_OBJECTS: |
| 796 | return stats->allocated_objects; |
| 797 | case KIND_ALLOCATED_BYTES: |
| 798 | return stats->allocated_bytes; |
| 799 | case KIND_FREED_OBJECTS: |
| 800 | return stats->freed_objects; |
| 801 | case KIND_FREED_BYTES: |
| 802 | return stats->freed_bytes; |
| 803 | case KIND_GC_INVOCATIONS: |
| 804 | return stats->gc_for_alloc_count; |
| 805 | case KIND_CLASS_INIT_COUNT: |
| 806 | return stats->class_init_count; |
| 807 | case KIND_CLASS_INIT_TIME: |
| 808 | // Convert ns to us, reduce to 32 bits. |
Elliott Hughes | 398f64b | 2012-03-26 18:05:48 -0700 | [diff] [blame] | 809 | return static_cast<int>(stats->class_init_time_ns / 1000); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 810 | case KIND_EXT_ALLOCATED_OBJECTS: |
| 811 | case KIND_EXT_ALLOCATED_BYTES: |
| 812 | case KIND_EXT_FREED_OBJECTS: |
| 813 | case KIND_EXT_FREED_BYTES: |
| 814 | return 0; // backward compatibility |
| 815 | default: |
Elliott Hughes | 7b9d996 | 2012-04-20 18:48:18 -0700 | [diff] [blame] | 816 | LOG(FATAL) << "Unknown statistic " << kind; |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 817 | return -1; // unreachable |
| 818 | } |
| 819 | } |
| 820 | |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 821 | void Runtime::BlockSignals() { |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 822 | SignalSet signals; |
| 823 | signals.Add(SIGPIPE); |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 824 | // SIGQUIT is used to dump the runtime's state (including stack traces). |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 825 | signals.Add(SIGQUIT); |
Elliott Hughes | 0879504 | 2012-04-03 14:48:52 -0700 | [diff] [blame] | 826 | // SIGUSR1 is used to initiate a GC. |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 827 | signals.Add(SIGUSR1); |
| 828 | signals.Block(); |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 829 | } |
| 830 | |
Elliott Hughes | 462c944 | 2012-03-23 18:47:50 -0700 | [diff] [blame] | 831 | void Runtime::AttachCurrentThread(const char* thread_name, bool as_daemon, Object* thread_group) { |
| 832 | Thread::Attach(thread_name, as_daemon, thread_group); |
Elliott Hughes | 22869a9 | 2012-03-27 14:08:24 -0700 | [diff] [blame] | 833 | if (thread_name == NULL) { |
| 834 | LOG(WARNING) << *Thread::Current() << " attached without supplying a name"; |
| 835 | } |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Elliott Hughes | d92bec4 | 2011-09-02 17:04:36 -0700 | [diff] [blame] | 838 | void Runtime::DetachCurrentThread() { |
Elliott Hughes | 22869a9 | 2012-03-27 14:08:24 -0700 | [diff] [blame] | 839 | if (Thread::Current()->GetTopOfStack().GetSP() != NULL) { |
| 840 | LOG(FATAL) << *Thread::Current() << " attempting to detach while still running code"; |
| 841 | } |
Elliott Hughes | 02b48d1 | 2011-09-07 17:15:51 -0700 | [diff] [blame] | 842 | thread_list_->Unregister(); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 845 | void Runtime::VisitRoots(Heap::RootVisitor* visitor, void* arg) const { |
Elliott Hughes | bfe487b | 2011-10-26 15:48:55 -0700 | [diff] [blame] | 846 | Dbg::VisitRoots(visitor, arg); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 847 | class_linker_->VisitRoots(visitor, arg); |
| 848 | intern_table_->VisitRoots(visitor, arg); |
| 849 | java_vm_->VisitRoots(visitor, arg); |
| 850 | thread_list_->VisitRoots(visitor, arg); |
| 851 | visitor(jni_stub_array_, arg); |
| 852 | visitor(abstract_method_error_stub_array_, arg); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 853 | for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) { |
| 854 | visitor(resolution_stub_array_[i], arg); |
| 855 | } |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 856 | visitor(resolution_method_, arg); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 857 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 858 | visitor(callee_save_method_[i], arg); |
| 859 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 860 | } |
| 861 | |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 862 | bool Runtime::HasJniDlsymLookupStub() const { |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 863 | return jni_stub_array_ != NULL; |
| 864 | } |
| 865 | |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 866 | ByteArray* Runtime::GetJniDlsymLookupStub() const { |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 867 | CHECK(jni_stub_array_ != NULL); |
| 868 | return jni_stub_array_; |
| 869 | } |
| 870 | |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 871 | void Runtime::SetJniDlsymLookupStub(ByteArray* jni_stub_array) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 872 | CHECK(jni_stub_array != NULL) << " jni_stub_array=" << jni_stub_array; |
| 873 | CHECK(jni_stub_array_ == NULL || jni_stub_array_ == jni_stub_array) |
| 874 | << "jni_stub_array_=" << jni_stub_array_ << " jni_stub_array=" << jni_stub_array; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 875 | jni_stub_array_ = jni_stub_array; |
| 876 | } |
| 877 | |
| 878 | bool Runtime::HasAbstractMethodErrorStubArray() const { |
| 879 | return abstract_method_error_stub_array_ != NULL; |
| 880 | } |
| 881 | |
| 882 | ByteArray* Runtime::GetAbstractMethodErrorStubArray() const { |
| 883 | CHECK(abstract_method_error_stub_array_ != NULL); |
| 884 | return abstract_method_error_stub_array_; |
| 885 | } |
| 886 | |
| 887 | void Runtime::SetAbstractMethodErrorStubArray(ByteArray* abstract_method_error_stub_array) { |
| 888 | CHECK(abstract_method_error_stub_array != NULL); |
| 889 | CHECK(abstract_method_error_stub_array_ == NULL || abstract_method_error_stub_array_ == abstract_method_error_stub_array); |
| 890 | abstract_method_error_stub_array_ = abstract_method_error_stub_array; |
| 891 | } |
| 892 | |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 893 | |
| 894 | Runtime::TrampolineType Runtime::GetTrampolineType(Method* method) { |
| 895 | if (method == NULL) { |
| 896 | return Runtime::kUnknownMethod; |
| 897 | } else if (method->IsStatic()) { |
| 898 | return Runtime::kStaticMethod; |
| 899 | } else { |
Ian Rogers | fb6adba | 2012-03-04 21:51:51 -0800 | [diff] [blame] | 900 | return Runtime::kUnknownMethod; |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 901 | } |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 904 | bool Runtime::HasResolutionStubArray(TrampolineType type) const { |
| 905 | return resolution_stub_array_[type] != NULL; |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 908 | ByteArray* Runtime::GetResolutionStubArray(TrampolineType type) const { |
| 909 | CHECK(HasResolutionStubArray(type)); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 910 | DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastTrampolineMethodType)); |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 911 | return resolution_stub_array_[type]; |
| 912 | } |
| 913 | |
| 914 | void Runtime::SetResolutionStubArray(ByteArray* resolution_stub_array, TrampolineType type) { |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 915 | CHECK(resolution_stub_array != NULL); |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 916 | CHECK(!HasResolutionStubArray(type) || resolution_stub_array_[type] == resolution_stub_array); |
| 917 | resolution_stub_array_[type] = resolution_stub_array; |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 920 | Method* Runtime::CreateResolutionMethod() { |
| 921 | Class* method_class = Method::GetMethodClass(); |
| 922 | SirtRef<Method> method(down_cast<Method*>(method_class->AllocObject())); |
| 923 | method->SetDeclaringClass(method_class); |
| 924 | // TODO: use a special method for resolution method saves |
| 925 | method->SetDexMethodIndex(DexFile::kDexNoIndex16); |
| 926 | ByteArray* unknown_resolution_stub = GetResolutionStubArray(kUnknownMethod); |
| 927 | CHECK(unknown_resolution_stub != NULL); |
| 928 | method->SetCode(unknown_resolution_stub->GetData()); |
| 929 | return method.get(); |
| 930 | } |
| 931 | |
| 932 | bool Runtime::HasResolutionMethod() const { |
| 933 | return resolution_method_ != NULL; |
| 934 | } |
| 935 | |
| 936 | // Returns a special method that calls into a trampoline for runtime method resolution |
| 937 | Method* Runtime::GetResolutionMethod() const { |
| 938 | CHECK(HasResolutionMethod()); |
| 939 | return resolution_method_; |
| 940 | } |
| 941 | |
| 942 | void Runtime::SetResolutionMethod(Method* method) { |
| 943 | resolution_method_ = method; |
| 944 | } |
| 945 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 946 | Method* Runtime::CreateCalleeSaveMethod(InstructionSet instruction_set, CalleeSaveType type) { |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 947 | Class* method_class = Method::GetMethodClass(); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 948 | SirtRef<Method> method(down_cast<Method*>(method_class->AllocObject())); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 949 | method->SetDeclaringClass(method_class); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 950 | // TODO: use a special method for callee saves |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 951 | method->SetDexMethodIndex(DexFile::kDexNoIndex16); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 952 | method->SetCode(NULL); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 953 | if ((instruction_set == kThumb2) || (instruction_set == kArm)) { |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 954 | uint32_t ref_spills = (1 << art::arm::R5) | (1 << art::arm::R6) | (1 << art::arm::R7) | |
| 955 | (1 << art::arm::R8) | (1 << art::arm::R10) | (1 << art::arm::R11); |
| 956 | uint32_t arg_spills = (1 << art::arm::R1) | (1 << art::arm::R2) | (1 << art::arm::R3); |
| 957 | uint32_t all_spills = (1 << art::arm::R4) | (1 << art::arm::R9); |
| 958 | uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills :0) | |
| 959 | (type == kSaveAll ? all_spills :0) | (1 << art::arm::LR); |
| 960 | uint32_t fp_all_spills = (1 << art::arm::S0) | (1 << art::arm::S1) | (1 << art::arm::S2) | |
| 961 | (1 << art::arm::S3) | (1 << art::arm::S4) | (1 << art::arm::S5) | |
| 962 | (1 << art::arm::S6) | (1 << art::arm::S7) | (1 << art::arm::S8) | |
| 963 | (1 << art::arm::S9) | (1 << art::arm::S10) | (1 << art::arm::S11) | |
| 964 | (1 << art::arm::S12) | (1 << art::arm::S13) | (1 << art::arm::S14) | |
| 965 | (1 << art::arm::S15) | (1 << art::arm::S16) | (1 << art::arm::S17) | |
| 966 | (1 << art::arm::S18) | (1 << art::arm::S19) | (1 << art::arm::S20) | |
| 967 | (1 << art::arm::S21) | (1 << art::arm::S22) | (1 << art::arm::S23) | |
| 968 | (1 << art::arm::S24) | (1 << art::arm::S25) | (1 << art::arm::S26) | |
| 969 | (1 << art::arm::S27) | (1 << art::arm::S28) | (1 << art::arm::S29) | |
| 970 | (1 << art::arm::S30) | (1 << art::arm::S31); |
| 971 | uint32_t fp_spills = type == kSaveAll ? fp_all_spills : 0; |
| 972 | size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ + |
| 973 | __builtin_popcount(fp_spills) /* fprs */ + |
| 974 | 1 /* Method* */) * kPointerSize, kStackAlignment); |
Ian Rogers | 15fdb8c | 2011-09-25 15:45:07 -0700 | [diff] [blame] | 975 | method->SetFrameSizeInBytes(frame_size); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 976 | method->SetCoreSpillMask(core_spills); |
| 977 | method->SetFpSpillMask(fp_spills); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 978 | } else if (instruction_set == kX86) { |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 979 | uint32_t ref_spills = (1 << art::x86::EBP) | (1 << art::x86::ESI) | (1 << art::x86::EDI); |
| 980 | uint32_t arg_spills = (1 << art::x86::ECX) | (1 << art::x86::EDX) | (1 << art::x86::EBX); |
| 981 | uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills : 0) | |
| 982 | (1 << art::x86::kNumberOfCpuRegisters); // fake return address callee save |
| 983 | size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ + |
| 984 | 1 /* Method* */) * kPointerSize, kStackAlignment); |
| 985 | method->SetFrameSizeInBytes(frame_size); |
| 986 | method->SetCoreSpillMask(core_spills); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 987 | method->SetFpSpillMask(0); |
| 988 | } else { |
| 989 | UNIMPLEMENTED(FATAL); |
| 990 | } |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 991 | return method.get(); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 992 | } |
| 993 | |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 994 | bool Runtime::HasCalleeSaveMethod(CalleeSaveType type) const { |
| 995 | return callee_save_method_[type] != NULL; |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 998 | // Returns a special method that describes all callee saves being spilled to the stack. |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 999 | Method* Runtime::GetCalleeSaveMethod(CalleeSaveType type) const { |
| 1000 | CHECK(HasCalleeSaveMethod(type)); |
| 1001 | return callee_save_method_[type]; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 1004 | void Runtime::SetCalleeSaveMethod(Method* method, CalleeSaveType type) { |
| 1005 | DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastCalleeSaveType)); |
| 1006 | callee_save_method_[type] = method; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
jeffhao | 2692b57 | 2011-12-16 15:42:28 -0800 | [diff] [blame] | 1009 | void Runtime::EnableMethodTracing(Trace* tracer) { |
| 1010 | CHECK(!IsMethodTracingActive()); |
| 1011 | tracer_ = tracer; |
| 1012 | } |
| 1013 | |
| 1014 | void Runtime::DisableMethodTracing() { |
| 1015 | CHECK(IsMethodTracingActive()); |
| 1016 | delete tracer_; |
| 1017 | tracer_ = NULL; |
| 1018 | } |
| 1019 | |
| 1020 | bool Runtime::IsMethodTracingActive() const { |
| 1021 | return (tracer_ != NULL); |
| 1022 | } |
| 1023 | |
| 1024 | Trace* Runtime::GetTracer() const { |
| 1025 | CHECK(IsMethodTracingActive()); |
| 1026 | return tracer_; |
| 1027 | } |
| 1028 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1029 | const std::vector<const DexFile*>& Runtime::GetCompileTimeClassPath(const ClassLoader* class_loader) { |
| 1030 | if (class_loader == NULL) { |
| 1031 | return GetClassLinker()->GetBootClassPath(); |
| 1032 | } |
| 1033 | CHECK(UseCompileTimeClassPath()); |
| 1034 | CompileTimeClassPaths::const_iterator it = compile_time_class_paths_.find(class_loader); |
| 1035 | CHECK(it != compile_time_class_paths_.end()); |
| 1036 | return it->second; |
| 1037 | } |
| 1038 | |
| 1039 | void Runtime::SetCompileTimeClassPath(const ClassLoader* class_loader, std::vector<const DexFile*>& class_path) { |
| 1040 | CHECK(!IsStarted()); |
| 1041 | use_compile_time_class_path_ = true; |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 1042 | compile_time_class_paths_.Put(class_loader, class_path); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1043 | } |
| 1044 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1045 | } // namespace art |