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