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