runtime.cc revision 4d4adb1dae07bb7421e863732ab789413a3b43f0
12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/* 22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2011 The Android Open Source Project 32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License. 62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at 72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software 112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and 142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License. 152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */ 166b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapiro 17578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "runtime.h" 187b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro 19bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom// sys/mount.h has to come before linux/fs.h due to redefinition of MS_RDONLY, MS_BIND, etc 20bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom#include <sys/mount.h> 21bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom#include <linux/fs.h> 22bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom 23dbf05b722af99ba2fd2f4c4fc7eb6c3e9880e5d1Brian Carlstrom#include <signal.h> 24d06a6c7c40180c2c906d6981dd461ede2187bd99Elliott Hughes#include <sys/syscall.h> 25dbf05b722af99ba2fd2f4c4fc7eb6c3e9880e5d1Brian Carlstrom 26ffe6736397d17457188727510f0a2953f69a383aElliott Hughes#include <cstdio> 27ffe6736397d17457188727510f0a2953f69a383aElliott Hughes#include <cstdlib> 288a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom#include <limits> 292ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro#include <vector> 30ffe6736397d17457188727510f0a2953f69a383aElliott Hughes 312dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "atomic.h" 32578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "class_linker.h" 330f3c55331439970e01af67f80ac117c473bc04cfElliott Hughes#include "constants_arm.h" 347fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao#include "constants_mips.h" 350f3c55331439970e01af67f80ac117c473bc04cfElliott Hughes#include "constants_x86.h" 363bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes#include "debugger.h" 371d54e73444e017d3a65234e0f193846f3e27472bIan Rogers#include "gc/accounting/card_table-inl.h" 381d54e73444e017d3a65234e0f193846f3e27472bIan Rogers#include "gc/heap.h" 391d54e73444e017d3a65234e0f193846f3e27472bIan Rogers#include "gc/space/space.h" 40e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom#include "image.h" 41725a957985171d712d5c048cc3d00ff14968784bjeffhao#include "instrumentation.h" 42cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes#include "intern_table.h" 435d9173014c1ca09f7249a6b07629aa37778b5f8fJeff Hao#include "invoke_arg_array_builder.h" 44c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughes#include "jni_internal.h" 452dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/abstract_method-inl.h" 462dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/array.h" 4762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers#include "mirror/class-inl.h" 482dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/class_loader.h" 492dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/field.h" 50c0fa3ad44a84b7f658d16a717027bf95abc85db6Ian Rogers#include "mirror/field-inl.h" 512dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/throwable.h" 5232d6e1e5654433d7eadede89e1c770b2c839aee9Elliott Hughes#include "monitor.h" 53e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom#include "oat_file.h" 54726079d3e2e50854cd6ca4c393f4529a796dba58Elliott Hughes#include "ScopedLocalRef.h" 5500f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers#include "scoped_thread_state_change.h" 56e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes#include "signal_catcher.h" 57457005c557b8762475db3220ce5a747d629f975bElliott Hughes#include "signal_set.h" 581f5393447b9f45be7918042d9ee7b521376de866Ian Rogers#include "sirt_ref.h" 59578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "thread.h" 608daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes#include "thread_list.h" 61b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao#include "trace.h" 623bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes#include "UniquePtr.h" 63776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers#include "verifier/method_verifier.h" 64eac766769e3114a078c188ea26776a81f0edb3cfElliott Hughes#include "well_known_classes.h" 6561e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 66eac766769e3114a078c188ea26776a81f0edb3cfElliott Hughes#include "JniConstants.h" // Last to avoid LOG redefinition in ics-mr1-plus-art. 6790a3369d3b6238f1a4c9b19ca68978dab1c39bc4Elliott Hughes 686b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapironamespace art { 697b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro 702ed144c2b49ae1da6c464d7a1be0062870530802Carl ShapiroRuntime* Runtime::instance_ = NULL; 712ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro 72dcc247493fd8fb243e335c3ec08e5e625896a47cElliott HughesRuntime::Runtime() 73d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes : is_compiler_(false), 74d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes is_zygote_(false), 75069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier is_concurrent_gc_enabled_(true), 766cf23884730574ca364b357e823259f4993e6908Elliott Hughes default_stack_size_(0), 77b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes heap_(NULL), 78c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes monitor_list_(NULL), 79dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes thread_list_(NULL), 80dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes intern_table_(NULL), 81dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes class_linker_(NULL), 82dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes signal_catcher_(NULL), 83dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes java_vm_(NULL), 84225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes pre_allocated_OutOfMemoryError_(NULL), 851984651929744dd603fd082e23eacd877b9bc177Ian Rogers resolution_method_(NULL), 867c3757fb51450d0669883c82375040ece051e189Ian Rogers system_class_loader_(NULL), 87120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers threads_being_born_(0), 88c604d731730b43231f63040c8db1d58304da0cf3Ian Rogers shutdown_cond_(new ConditionVariable("Runtime shutdown", *Locks::runtime_shutdown_lock_)), 896b3557571e798b60df995f978fa01c0ca1980dfdElliott Hughes shutting_down_(false), 90120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers shutting_down_started_(false), 91dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes started_(false), 927664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier finished_starting_(false), 93dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes vfprintf_(NULL), 94dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes exit_(NULL), 959d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes abort_(NULL), 962692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhao stats_enabled_(false), 97776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers method_trace_(0), 98776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers method_trace_file_size_(0), 9962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers instrumentation_(), 100365c10235438607541fa2259a5fec48061b90bd8Ian Rogers use_compile_time_class_path_(false), 101365c10235438607541fa2259a5fec48061b90bd8Ian Rogers main_thread_group_(NULL), 102265091e581c9f643b37e7966890911f09e223269Brian Carlstrom system_thread_group_(NULL) { 1034f0d07c783afef89703dce32c94440fc8621a29bIan Rogers for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { 104225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes callee_save_methods_[i] = NULL; 1054f0d07c783afef89703dce32c94440fc8621a29bIan Rogers } 106dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes} 107dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes 10861e019d291583029c01b61b93bea750f2b663c37Carl ShapiroRuntime::~Runtime() { 109120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers Thread* self = Thread::Current(); 110120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers { 111120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers MutexLock mu(self, *Locks::runtime_shutdown_lock_); 112120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers shutting_down_started_ = true; 113120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers while (threads_being_born_ > 0) { 114c604d731730b43231f63040c8db1d58304da0cf3Ian Rogers shutdown_cond_->Wait(self); 115120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers } 116120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers shutting_down_ = true; 117120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers } 11862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers Trace::Shutdown(); 119b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao 120a6399035ee2af012e2ac898ee7a753a2f83b35abMathieu Chartier // Make sure to let the GC complete if it is running. 121120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers heap_->WaitForConcurrentGcToComplete(self); 12235883cc623fdf475a4ead1dafcba9e9becc1ed11Mathieu Chartier heap_->DeleteThreadPool(); 123a6399035ee2af012e2ac898ee7a753a2f83b35abMathieu Chartier 1245fe594f576225dd7d333835e39c448a71ea9b433Elliott Hughes // Make sure our internal threads are dead before we start tearing down things they're using. 125e52e49b32f5cf862a414da63e5dbd2eb04ad758eElliott Hughes Dbg::StopJdwp(); 1265fe594f576225dd7d333835e39c448a71ea9b433Elliott Hughes delete signal_catcher_; 1275fe594f576225dd7d333835e39c448a71ea9b433Elliott Hughes 128038a806df72f884d22283a84a31c9a1d35ba1fdfElliott Hughes // Make sure all other non-daemon threads have terminated, and all daemon threads are suspended. 12993e74e8d879270071c3aa163f8495ada8d21f42fElliott Hughes delete thread_list_; 130c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes delete monitor_list_; 13161e019d291583029c01b61b93bea750f2b663c37Carl Shapiro delete class_linker_; 132b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes delete heap_; 133cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes delete intern_table_; 134c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughes delete java_vm_; 135c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes Thread::Shutdown(); 1367c6169de901fd0a39c8e0c078874dc25207f5b59Elliott Hughes QuasiAtomic::Shutdown(); 1374d4adb1dae07bb7421e863732ab789413a3b43f0Sebastien Hertz verifier::MethodVerifier::Shutdown(); 1384acf4646fbbd6c1893cec5bb700d3c7cd09e4a26Carl Shapiro // TODO: acquire a static mutex on Runtime to avoid racing. 1394a289ed61242964b921434de7d375f46480472a1Brian Carlstrom CHECK(instance_ == NULL || instance_ == this); 1404acf4646fbbd6c1893cec5bb700d3c7cd09e4a26Carl Shapiro instance_ = NULL; 14161e019d291583029c01b61b93bea750f2b663c37Carl Shapiro} 14261e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 143e0918556e7551de638870dcad3f2023f94f85a50Elliott Hughesstruct AbortState { 144e0918556e7551de638870dcad3f2023f94f85a50Elliott Hughes void Dump(std::ostream& os) { 145f08e473519dc5c7ccb85eb2b333f9d0aff23a329Ian Rogers if (gAborting > 1) { 146cac6cc72c3331257fa6437b36a131e5d551e2f3cElliott Hughes os << "Runtime aborting --- recursively, so no thread-specific detail!\n"; 147cac6cc72c3331257fa6437b36a131e5d551e2f3cElliott Hughes return; 148cac6cc72c3331257fa6437b36a131e5d551e2f3cElliott Hughes } 149f08e473519dc5c7ccb85eb2b333f9d0aff23a329Ian Rogers gAborting++; 150e0918556e7551de638870dcad3f2023f94f85a50Elliott Hughes os << "Runtime aborting...\n"; 1516c7d244058b74cdd61533968dd6cddd7003d2671Elliott Hughes if (Runtime::Current() == NULL) { 1526c7d244058b74cdd61533968dd6cddd7003d2671Elliott Hughes os << "(Runtime does not yet exist!)\n"; 1536c7d244058b74cdd61533968dd6cddd7003d2671Elliott Hughes return; 1546c7d244058b74cdd61533968dd6cddd7003d2671Elliott Hughes } 155e0918556e7551de638870dcad3f2023f94f85a50Elliott Hughes Thread* self = Thread::Current(); 156e0918556e7551de638870dcad3f2023f94f85a50Elliott Hughes if (self == NULL) { 157e0918556e7551de638870dcad3f2023f94f85a50Elliott Hughes os << "(Aborting thread was not attached to runtime!)\n"; 158e0918556e7551de638870dcad3f2023f94f85a50Elliott Hughes } else { 15900f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers // TODO: we're aborting and the ScopedObjectAccess may attempt to acquire the mutator_lock_ 16000f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers // which may block indefinitely if there's a misbehaving thread holding it exclusively. 16100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers // The code below should be made robust to this. 16200f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers ScopedObjectAccess soa(self); 1632f7f9b6a3f0f6f334f0314b10d1dc696e5a9afa4Ian Rogers os << "Aborting thread:\n"; 164899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes self->Dump(os); 165899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes if (self->IsExceptionPending()) { 16662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers ThrowLocation throw_location; 16762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers mirror::Throwable* exception = self->GetException(&throw_location); 16862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers os << "Pending exception " << PrettyTypeOf(exception) 16962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers << " thrown by '" << throw_location.Dump() << "\n" 17062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers << exception->Dump(); 171899e789bd4741c0172268f7838ce8ab220a5f916Elliott Hughes } 172e0918556e7551de638870dcad3f2023f94f85a50Elliott Hughes } 1732f7f9b6a3f0f6f334f0314b10d1dc696e5a9afa4Ian Rogers DumpAllThreads(os, self); 1742f7f9b6a3f0f6f334f0314b10d1dc696e5a9afa4Ian Rogers } 1752f7f9b6a3f0f6f334f0314b10d1dc696e5a9afa4Ian Rogers 1762f7f9b6a3f0f6f334f0314b10d1dc696e5a9afa4Ian Rogers void DumpAllThreads(std::ostream& os, Thread* self) NO_THREAD_SAFETY_ANALYSIS { 1772f7f9b6a3f0f6f334f0314b10d1dc696e5a9afa4Ian Rogers bool tll_already_held = Locks::thread_list_lock_->IsExclusiveHeld(self); 1782f7f9b6a3f0f6f334f0314b10d1dc696e5a9afa4Ian Rogers bool ml_already_held = Locks::mutator_lock_->IsSharedHeld(self); 179fbd229147c62d8e8787e27e7c9db3b387ffe39efIan Rogers if (!tll_already_held || !ml_already_held) { 180fbd229147c62d8e8787e27e7c9db3b387ffe39efIan Rogers os << "Dumping all threads without appropriate locks held:" 181fbd229147c62d8e8787e27e7c9db3b387ffe39efIan Rogers << (!tll_already_held ? " thread list lock" : "") 1822fa6b2e2fc3d2a2fc27808ce518dc76b80ce369aIan Rogers << (!ml_already_held ? " mutator lock" : "") 1832fa6b2e2fc3d2a2fc27808ce518dc76b80ce369aIan Rogers << "\n"; 1842f7f9b6a3f0f6f334f0314b10d1dc696e5a9afa4Ian Rogers } 185fbd229147c62d8e8787e27e7c9db3b387ffe39efIan Rogers os << "All threads:\n"; 186fbd229147c62d8e8787e27e7c9db3b387ffe39efIan Rogers Runtime::Current()->GetThreadList()->DumpLocked(os); 187e0918556e7551de638870dcad3f2023f94f85a50Elliott Hughes } 188e0918556e7551de638870dcad3f2023f94f85a50Elliott Hughes}; 189e0918556e7551de638870dcad3f2023f94f85a50Elliott Hughes 1908593fdbacf97261f790ca53ea0ec416f57c987a7Elliott Hughesvoid Runtime::Abort() { 191f08e473519dc5c7ccb85eb2b333f9d0aff23a329Ian Rogers gAborting++; // set before taking any locks 19281b8871007101f42e2baabf213e1312004073eb0Brian Carlstrom 193131aef8c94292cc530da2fd91ee98d1432352959Elliott Hughes // Ensure that we don't have multiple threads trying to abort at once, 194131aef8c94292cc530da2fd91ee98d1432352959Elliott Hughes // which would result in significantly worse diagnostics. 19550b35e2fd1a68cd1240e4a9d9f363e11764957d1Ian Rogers MutexLock mu(Thread::Current(), *Locks::abort_lock_); 196131aef8c94292cc530da2fd91ee98d1432352959Elliott Hughes 197ffe6736397d17457188727510f0a2953f69a383aElliott Hughes // Get any pending output out of the way. 198ffe6736397d17457188727510f0a2953f69a383aElliott Hughes fflush(NULL); 199ffe6736397d17457188727510f0a2953f69a383aElliott Hughes 200ffe6736397d17457188727510f0a2953f69a383aElliott Hughes // Many people have difficulty distinguish aborts from crashes, 201ffe6736397d17457188727510f0a2953f69a383aElliott Hughes // so be explicit. 202e0918556e7551de638870dcad3f2023f94f85a50Elliott Hughes AbortState state; 2039ee5f9ccba015beb3ae376ed08b3363bd9df6422Elliott Hughes LOG(INTERNAL_FATAL) << Dumpable<AbortState>(state); 204ffe6736397d17457188727510f0a2953f69a383aElliott Hughes 2058593fdbacf97261f790ca53ea0ec416f57c987a7Elliott Hughes // Call the abort hook if we have one. 2066ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom if (Runtime::Current() != NULL && Runtime::Current()->abort_ != NULL) { 2076c1c69eea21cce39dd043d89368a684d250c9abeElliott Hughes LOG(INTERNAL_FATAL) << "Calling abort hook..."; 2086ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom Runtime::Current()->abort_(); 2096ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom // notreached 2106c1c69eea21cce39dd043d89368a684d250c9abeElliott Hughes LOG(INTERNAL_FATAL) << "Unexpectedly returned from abort hook!"; 2116ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom } 2126ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom 213dd623dbcb6e5c42c32382c136f16e000ab053216Elliott Hughes#if defined(__GLIBC__) 214d06a6c7c40180c2c906d6981dd461ede2187bd99Elliott Hughes // TODO: we ought to be able to use pthread_kill(3) here (or abort(3), 215d06a6c7c40180c2c906d6981dd461ede2187bd99Elliott Hughes // which POSIX defines in terms of raise(3), which POSIX defines in terms 216d06a6c7c40180c2c906d6981dd461ede2187bd99Elliott Hughes // of pthread_kill(3)). On Linux, though, libcorkscrew can't unwind through 217d06a6c7c40180c2c906d6981dd461ede2187bd99Elliott Hughes // libpthread, which means the stacks we dump would be useless. Calling 218d06a6c7c40180c2c906d6981dd461ede2187bd99Elliott Hughes // tgkill(2) directly avoids that. 219d06a6c7c40180c2c906d6981dd461ede2187bd99Elliott Hughes syscall(__NR_tgkill, getpid(), GetTid(), SIGABRT); 220dd623dbcb6e5c42c32382c136f16e000ab053216Elliott Hughes // TODO: LLVM installs it's own SIGABRT handler so exit to be safe... Can we disable that in LLVM? 221dd623dbcb6e5c42c32382c136f16e000ab053216Elliott Hughes // If not, we could use sigaction(3) before calling tgkill(2) and lose this call to exit(3). 222700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom exit(1); 223dd623dbcb6e5c42c32382c136f16e000ab053216Elliott Hughes#else 224dd623dbcb6e5c42c32382c136f16e000ab053216Elliott Hughes abort(); 225d06a6c7c40180c2c906d6981dd461ede2187bd99Elliott Hughes#endif 226ffe6736397d17457188727510f0a2953f69a383aElliott Hughes // notreached 227ffe6736397d17457188727510f0a2953f69a383aElliott Hughes} 228ffe6736397d17457188727510f0a2953f69a383aElliott Hughes 229cc236d74772dda5a4161d9bc5f497fd3d956eb87Mathieu Chartierbool Runtime::PreZygoteFork() { 230cc236d74772dda5a4161d9bc5f497fd3d956eb87Mathieu Chartier heap_->PreZygoteFork(); 231cc236d74772dda5a4161d9bc5f497fd3d956eb87Mathieu Chartier return true; 232cc236d74772dda5a4161d9bc5f497fd3d956eb87Mathieu Chartier} 233cc236d74772dda5a4161d9bc5f497fd3d956eb87Mathieu Chartier 234bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughesvoid Runtime::CallExitHook(jint status) { 235bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes if (exit_ != NULL) { 23634e069606d6f1698cd3c33b39e72b79ae27e1c7bElliott Hughes ScopedThreadStateChange tsc(Thread::Current(), kNative); 237bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes exit_(status); 238bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes LOG(WARNING) << "Exit hook returned instead of exiting!"; 239bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes } 240bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes} 241bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes 2428a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify 2438a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and 2448a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// [gG] gigabytes. 2458a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// 2468a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// "s" should point just past the "-Xm?" part of the string. 2478a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// "div" specifies a divisor, e.g. 1024 if the value must be a multiple 2488a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// of 1024. 2498a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// 2508a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// The spec says the -Xmx and -Xms options must be multiples of 1024. It 2518a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// doesn't say anything about -Xss. 2528a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// 2538a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// Returns 0 (a useless size) if "s" is malformed or specifies a low or 2548a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// non-evenly-divisible value. 2558a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom// 256c1f143de3d0370a17a4561eb83bf10a5d7908aa3Elliott Hughessize_t ParseMemoryOption(const char* s, size_t div) { 2578a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom // strtoul accepts a leading [+-], which we don't want, 2588a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom // so make sure our string starts with a decimal digit. 2598a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom if (isdigit(*s)) { 260398f64b5805246765b699839b439e18c0dfbf2eeElliott Hughes char* s2; 261398f64b5805246765b699839b439e18c0dfbf2eeElliott Hughes size_t val = strtoul(s, &s2, 10); 2628a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom if (s2 != s) { 2638a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom // s2 should be pointing just after the number. 2648a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom // If this is the end of the string, the user 2658a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom // has specified a number of bytes. Otherwise, 2668a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom // there should be exactly one more character 2678a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom // that specifies a multiplier. 2688a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom if (*s2 != '\0') { 269f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom // The remainder of the string is either a single multiplier 270f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom // character, or nothing to indicate that the value is in 271f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom // bytes. 272f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom char c = *s2++; 273f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom if (*s2 == '\0') { 274f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom size_t mul; 275f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom if (c == '\0') { 276f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom mul = 1; 277f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } else if (c == 'k' || c == 'K') { 278f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom mul = KB; 279f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } else if (c == 'm' || c == 'M') { 280f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom mul = MB; 281f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } else if (c == 'g' || c == 'G') { 282f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom mul = GB; 2838a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom } else { 284f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom // Unknown multiplier character. 2858a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom return 0; 2868a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom } 287f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom 288f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom if (val <= std::numeric_limits<size_t>::max() / mul) { 289f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom val *= mul; 290f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } else { 291f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom // Clamp to a multiple of 1024. 292f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom val = std::numeric_limits<size_t>::max() & ~(1024-1); 293f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } 294f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } else { 295f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom // There's more than one character after the numeric part. 296f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom return 0; 297f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } 2988a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom } 2998a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom // The man page says that a -Xm value must be a multiple of 1024. 3008a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom if (val % div == 0) { 3018a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom return val; 3028a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom } 303fc322c72d7a89a6f7a05c8bdc232d780aecd9232Carl Shapiro } 304fc322c72d7a89a6f7a05c8bdc232d780aecd9232Carl Shapiro } 3058a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom return 0; 306fc322c72d7a89a6f7a05c8bdc232d780aecd9232Carl Shapiro} 307fc322c72d7a89a6f7a05c8bdc232d780aecd9232Carl Shapiro 308f1a5adc87760f938b01df26d906295063546b259Elliott Hughessize_t ParseIntegerOrDie(const std::string& s) { 309f1a5adc87760f938b01df26d906295063546b259Elliott Hughes std::string::size_type colon = s.find(':'); 310f1a5adc87760f938b01df26d906295063546b259Elliott Hughes if (colon == std::string::npos) { 311bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes LOG(FATAL) << "Missing integer: " << s; 312bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes } 313f1a5adc87760f938b01df26d906295063546b259Elliott Hughes const char* begin = &s[colon + 1]; 314bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes char* end; 315bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes size_t result = strtoul(begin, &end, 10); 316bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes if (begin == end || *end != '\0') { 317bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes LOG(FATAL) << "Failed to parse integer in: " << s; 318bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes } 319bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes return result; 320bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes} 321bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes 3226ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian CarlstromRuntime::ParsedOptions* Runtime::ParsedOptions::Create(const Options& options, bool ignore_unrecognized) { 32390a3369d3b6238f1a4c9b19ca68978dab1c39bc4Elliott Hughes UniquePtr<ParsedOptions> parsed(new ParsedOptions()); 324a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom const char* boot_class_path_string = getenv("BOOTCLASSPATH"); 325a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom if (boot_class_path_string != NULL) { 326a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom parsed->boot_class_path_string_ = boot_class_path_string; 32758ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom } 328a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom const char* class_path_string = getenv("CLASSPATH"); 329a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom if (class_path_string != NULL) { 330a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom parsed->class_path_string_ = class_path_string; 33158ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom } 33267d920071fe4a0aa8b8bc339e93b18276238c320Elliott Hughes // -Xcheck:jni is off by default for regular builds but on by default in debug builds. 33367d920071fe4a0aa8b8bc339e93b18276238c320Elliott Hughes parsed->check_jni_ = kIsDebugBuild; 33485d1545e985ac689db4bad7849880e843707c862Elliott Hughes 3351d54e73444e017d3a65234e0f193846f3e27472bIan Rogers parsed->heap_initial_size_ = gc::Heap::kDefaultInitialSize; 3361d54e73444e017d3a65234e0f193846f3e27472bIan Rogers parsed->heap_maximum_size_ = gc::Heap::kDefaultMaximumSize; 3371d54e73444e017d3a65234e0f193846f3e27472bIan Rogers parsed->heap_min_free_ = gc::Heap::kDefaultMinFree; 3381d54e73444e017d3a65234e0f193846f3e27472bIan Rogers parsed->heap_max_free_ = gc::Heap::kDefaultMaxFree; 3391d54e73444e017d3a65234e0f193846f3e27472bIan Rogers parsed->heap_target_utilization_ = gc::Heap::kDefaultTargetUtilization; 3406cf23884730574ca364b357e823259f4993e6908Elliott Hughes parsed->heap_growth_limit_ = 0; // 0 means no growth limit. 34163a54345598861030178e033ffbd72c0e231a4c9Mathieu Chartier // Default to number of processors minus one since the main GC thread also does work. 34263a54345598861030178e033ffbd72c0e231a4c9Mathieu Chartier parsed->heap_gc_threads_ = sysconf(_SC_NPROCESSORS_CONF) - 1; 3436cf23884730574ca364b357e823259f4993e6908Elliott Hughes parsed->stack_size_ = 0; // 0 means default. 344f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom 345d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes parsed->is_compiler_ = false; 3469ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes parsed->is_zygote_ = false; 34750ffee20ced9c0c7ac68889c86be8844cf120cf2Ian Rogers parsed->interpreter_only_ = false; 348069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier parsed->is_concurrent_gc_enabled_ = true; 3499ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes 350fc86162ce2a3467acb690e18cc8bd9b3daafc606Elliott Hughes parsed->lock_profiling_threshold_ = 0; 351fc86162ce2a3467acb690e18cc8bd9b3daafc606Elliott Hughes parsed->hook_is_sensitive_thread_ = NULL; 352fc86162ce2a3467acb690e18cc8bd9b3daafc606Elliott Hughes 3536ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom parsed->hook_vfprintf_ = vfprintf; 3546ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom parsed->hook_exit_ = exit; 3556c1c69eea21cce39dd043d89368a684d250c9abeElliott Hughes parsed->hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort. 3568a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom 357b3eb9eb86370791735ca4e9c1bd5bb4f3ff62069Anwar Ghuloum parsed->small_mode_ = false; 3588447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum parsed->small_mode_method_threshold_ = Runtime::kDefaultSmallModeMethodThreshold; 3598447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum parsed->small_mode_method_dex_size_limit_ = Runtime::kDefaultSmallModeMethodDexSizeLimit; 3608447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum 3617467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea parsed->sea_ir_mode_ = false; 362b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes// gLogVerbosity.class_linker = true; // TODO: don't check this in! 363b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes// gLogVerbosity.compiler = true; // TODO: don't check this in! 364b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes// gLogVerbosity.heap = true; // TODO: don't check this in! 365b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes// gLogVerbosity.gc = true; // TODO: don't check this in! 366b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes// gLogVerbosity.jdwp = true; // TODO: don't check this in! 367b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes// gLogVerbosity.jni = true; // TODO: don't check this in! 368b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes// gLogVerbosity.monitor = true; // TODO: don't check this in! 369b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes// gLogVerbosity.startup = true; // TODO: don't check this in! 370b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes// gLogVerbosity.third_party_jni = true; // TODO: don't check this in! 371b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes// gLogVerbosity.threads = true; // TODO: don't check this in! 372b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes 373b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao parsed->method_trace_ = false; 374b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao parsed->method_trace_file_ = "/data/method-trace-file.bin"; 375b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao parsed->method_trace_file_size_ = 10 * MB; 376b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao 3778a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom for (size_t i = 0; i < options.size(); ++i) { 378f1a5adc87760f938b01df26d906295063546b259Elliott Hughes const std::string option(options[i].first); 3790796af03edc06d92bb8d631f1c0c23befdae2315Brian Carlstrom if (true && options[0].first == "-Xzygote") { 38058ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom LOG(INFO) << "option[" << i << "]=" << option; 38158ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom } 382f1a5adc87760f938b01df26d906295063546b259Elliott Hughes if (StartsWith(option, "-Xbootclasspath:")) { 383a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom parsed->boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data(); 38469b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom } else if (option == "-classpath" || option == "-cp") { 38569b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom // TODO: support -Djava.class.path 38669b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom i++; 38769b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom if (i == options.size()) { 38869b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom // TODO: usage 38969b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom LOG(FATAL) << "Missing required class path value for " << option; 39069b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom return NULL; 39169b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom } 392a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom const StringPiece& value = options[i].first; 393a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom parsed->class_path_string_ = value.data(); 394a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom } else if (option == "bootclasspath") { 395a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom parsed->boot_class_path_ 396a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second); 397f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-Ximage:")) { 398a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom parsed->image_ = option.substr(strlen("-Ximage:")).data(); 399f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-Xcheck:jni")) { 400515a5bc89282d6f910cae4d5852bb77124a47825Elliott Hughes parsed->check_jni_ = true; 401f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) { 402f1a5adc87760f938b01df26d906295063546b259Elliott Hughes std::string tail(option.substr(option[1] == 'X' ? 10 : 15)); 4033bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) { 4043bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes LOG(FATAL) << "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n" 4053bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes << "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n"; 4063bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes return NULL; 4073bb81563481d02b5a6349b8ed918392454e761d8Elliott Hughes } 408f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-Xms")) { 409f1a5adc87760f938b01df26d906295063546b259Elliott Hughes size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024); 410f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom if (size == 0) { 411f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom if (ignore_unrecognized) { 412f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom continue; 413f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } 4144a289ed61242964b921434de7d375f46480472a1Brian Carlstrom // TODO: usage 41569b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom LOG(FATAL) << "Failed to parse " << option; 416f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom return NULL; 417f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } 418f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom parsed->heap_initial_size_ = size; 419f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-Xmx")) { 420f1a5adc87760f938b01df26d906295063546b259Elliott Hughes size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024); 421f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom if (size == 0) { 422f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom if (ignore_unrecognized) { 423f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom continue; 424f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } 4254a289ed61242964b921434de7d375f46480472a1Brian Carlstrom // TODO: usage 42669b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom LOG(FATAL) << "Failed to parse " << option; 427f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom return NULL; 428f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } 429f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom parsed->heap_maximum_size_ = size; 430f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) { 431f1a5adc87760f938b01df26d906295063546b259Elliott Hughes size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024); 432c11607024d2e7a52ca690b8339306cab040e6653jeffhao if (size == 0) { 433c11607024d2e7a52ca690b8339306cab040e6653jeffhao if (ignore_unrecognized) { 434c11607024d2e7a52ca690b8339306cab040e6653jeffhao continue; 435c11607024d2e7a52ca690b8339306cab040e6653jeffhao } 436c11607024d2e7a52ca690b8339306cab040e6653jeffhao // TODO: usage 437c11607024d2e7a52ca690b8339306cab040e6653jeffhao LOG(FATAL) << "Failed to parse " << option; 438c11607024d2e7a52ca690b8339306cab040e6653jeffhao return NULL; 439c11607024d2e7a52ca690b8339306cab040e6653jeffhao } 440c11607024d2e7a52ca690b8339306cab040e6653jeffhao parsed->heap_growth_limit_ = size; 4410051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier } else if (StartsWith(option, "-XX:HeapMinFree=")) { 4420051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024); 4430051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier if (size == 0) { 4440051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier if (ignore_unrecognized) { 4450051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier continue; 4460051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier } 4470051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier // TODO: usage 4480051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier LOG(FATAL) << "Failed to parse " << option; 4490051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier return NULL; 4500051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier } 4510051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier parsed->heap_min_free_ = size; 4520051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier } else if (StartsWith(option, "-XX:HeapMaxFree=")) { 4530051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024); 4540051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier if (size == 0) { 4550051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier if (ignore_unrecognized) { 4560051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier continue; 4570051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier } 4580051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier // TODO: usage 4590051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier LOG(FATAL) << "Failed to parse " << option; 4600051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier return NULL; 4610051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier } 4620051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier parsed->heap_max_free_ = size; 4630051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) { 4640051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier std::istringstream iss(option.substr(strlen("-XX:HeapTargetUtilization="))); 4650051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier double value; 4660051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier iss >> value; 4670051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range. 468bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom const bool sane_val = iss.eof() && (value >= 0.1) && (value <= 0.9); 4690051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier if (!sane_val) { 4700051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier if (ignore_unrecognized) { 4710051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier continue; 4720051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier } 4730051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier LOG(FATAL) << "Invalid option '" << option << "'"; 4740051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier return NULL; 4750051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier } 4760051be6d118c511308ed7764ef41e0d594292c49Mathieu Chartier parsed->heap_target_utilization_ = value; 47763a54345598861030178e033ffbd72c0e231a4c9Mathieu Chartier } else if (StartsWith(option, "-XX:HeapGCThreads=")) { 47863a54345598861030178e033ffbd72c0e231a4c9Mathieu Chartier parsed->heap_gc_threads_ = 47963a54345598861030178e033ffbd72c0e231a4c9Mathieu Chartier ParseMemoryOption(option.substr(strlen("-XX:HeapGCThreads=")).c_str(), 1024); 480f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-Xss")) { 481f1a5adc87760f938b01df26d906295063546b259Elliott Hughes size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1); 482f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom if (size == 0) { 483f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom if (ignore_unrecognized) { 484f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom continue; 485f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } 4864a289ed61242964b921434de7d375f46480472a1Brian Carlstrom // TODO: usage 48769b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom LOG(FATAL) << "Failed to parse " << option; 488f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom return NULL; 489f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom } 490f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom parsed->stack_size_ = size; 491f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-D")) { 492f1a5adc87760f938b01df26d906295063546b259Elliott Hughes parsed->properties_.push_back(option.substr(strlen("-D"))); 493f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-Xjnitrace:")) { 494f1a5adc87760f938b01df26d906295063546b259Elliott Hughes parsed->jni_trace_ = option.substr(strlen("-Xjnitrace:")); 4955de8fe5253ca8bd285cba0eb2e56930573ea4c7fBrian Carlstrom } else if (option == "compiler") { 496d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes parsed->is_compiler_ = true; 4979ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes } else if (option == "-Xzygote") { 4989ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes parsed->is_zygote_ = true; 49950ffee20ced9c0c7ac68889c86be8844cf120cf2Ian Rogers } else if (option == "-Xint") { 50050ffee20ced9c0c7ac68889c86be8844cf120cf2Ian Rogers parsed->interpreter_only_ = true; 501069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier } else if (StartsWith(option, "-Xgc:")) { 502069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier std::vector<std::string> gc_options; 503069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier Split(option.substr(strlen("-Xgc:")), ',', gc_options); 504069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier for (size_t i = 0; i < gc_options.size(); ++i) { 505069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier if (gc_options[i] == "noconcurrent") { 506069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier parsed->is_concurrent_gc_enabled_ = false; 507069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier } else if (gc_options[i] == "concurrent") { 508069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier parsed->is_concurrent_gc_enabled_ = true; 509069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier } else { 510069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier LOG(WARNING) << "Ignoring unknown -Xgc option: " << gc_options[i]; 511069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier } 512069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier } 513f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-verbose:")) { 5140af5543f8ea20c3e655b2d748a1b7dcf283792feElliott Hughes std::vector<std::string> verbose_options; 515f1a5adc87760f938b01df26d906295063546b259Elliott Hughes Split(option.substr(strlen("-verbose:")), ',', verbose_options); 5160af5543f8ea20c3e655b2d748a1b7dcf283792feElliott Hughes for (size_t i = 0; i < verbose_options.size(); ++i) { 5174dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes if (verbose_options[i] == "class") { 5184dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes gLogVerbosity.class_linker = true; 5194dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes } else if (verbose_options[i] == "compiler") { 5204dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes gLogVerbosity.compiler = true; 5214dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes } else if (verbose_options[i] == "heap") { 5224dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes gLogVerbosity.heap = true; 5234dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes } else if (verbose_options[i] == "gc") { 5244dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes gLogVerbosity.gc = true; 5254dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes } else if (verbose_options[i] == "jdwp") { 5264dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes gLogVerbosity.jdwp = true; 5274dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes } else if (verbose_options[i] == "jni") { 5284dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes gLogVerbosity.jni = true; 5294dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes } else if (verbose_options[i] == "monitor") { 5304dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes gLogVerbosity.monitor = true; 5314dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes } else if (verbose_options[i] == "startup") { 5324dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes gLogVerbosity.startup = true; 5334dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes } else if (verbose_options[i] == "third-party-jni") { 5344dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes gLogVerbosity.third_party_jni = true; 5354dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes } else if (verbose_options[i] == "threads") { 5364dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes gLogVerbosity.threads = true; 5374dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes } else { 5384dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes LOG(WARNING) << "Ignoring unknown -verbose option: " << verbose_options[i]; 5394dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes } 5400af5543f8ea20c3e655b2d748a1b7dcf283792feElliott Hughes } 541f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-Xjnigreflimit:")) { 5422010a6004fb083eb4109c21886fce6ee65abda33Elliott Hughes // Silently ignored for backwards compatibility. 543f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-Xlockprofthreshold:")) { 544bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes parsed->lock_profiling_threshold_ = ParseIntegerOrDie(option); 545f1a5adc87760f938b01df26d906295063546b259Elliott Hughes } else if (StartsWith(option, "-Xstacktracefile:")) { 546206c20d6b1e27d8eca843498fdde1ddd5b9daa39Elliott Hughes parsed->stack_trace_file_ = option.substr(strlen("-Xstacktracefile:")); 547fc86162ce2a3467acb690e18cc8bd9b3daafc606Elliott Hughes } else if (option == "sensitiveThread") { 5481b09b094a85e03f6ef5f687f58bb91c433273ba1Ian Rogers parsed->hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(options[i].second)); 5496ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom } else if (option == "vfprintf") { 5501b09b094a85e03f6ef5f687f58bb91c433273ba1Ian Rogers parsed->hook_vfprintf_ = 5511b09b094a85e03f6ef5f687f58bb91c433273ba1Ian Rogers reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(options[i].second)); 5526ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom } else if (option == "exit") { 5531b09b094a85e03f6ef5f687f58bb91c433273ba1Ian Rogers parsed->hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(options[i].second)); 5546ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom } else if (option == "abort") { 5551b09b094a85e03f6ef5f687f58bb91c433273ba1Ian Rogers parsed->hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(options[i].second)); 55658ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom } else if (option == "host-prefix") { 55758ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom parsed->host_prefix_ = reinterpret_cast<const char*>(options[i].second); 558b3e66dfcd069db8818cd902d787ff1d7bbca45f2Elliott Hughes } else if (option == "-Xgenregmap" || option == "-Xgc:precise") { 559b3e66dfcd069db8818cd902d787ff1d7bbca45f2Elliott Hughes // We silently ignore these for backwards compatibility. 560b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao } else if (option == "-Xmethod-trace") { 561b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao parsed->method_trace_ = true; 562b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao } else if (StartsWith(option, "-Xmethod-trace-file:")) { 563b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao parsed->method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:")); 564b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao } else if (StartsWith(option, "-Xmethod-trace-file-size:")) { 565b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao parsed->method_trace_file_size_ = ParseIntegerOrDie(option); 566e119a3623ffbd55ff856d4eaac4dc4ef0c90a089Elliott Hughes } else if (option == "-Xprofile:threadcpuclock") { 567e119a3623ffbd55ff856d4eaac4dc4ef0c90a089Elliott Hughes Trace::SetDefaultClockSource(kProfilerClockSourceThreadCpu); 568e119a3623ffbd55ff856d4eaac4dc4ef0c90a089Elliott Hughes } else if (option == "-Xprofile:wallclock") { 569e119a3623ffbd55ff856d4eaac4dc4ef0c90a089Elliott Hughes Trace::SetDefaultClockSource(kProfilerClockSourceWall); 570e119a3623ffbd55ff856d4eaac4dc4ef0c90a089Elliott Hughes } else if (option == "-Xprofile:dualclock") { 571e119a3623ffbd55ff856d4eaac4dc4ef0c90a089Elliott Hughes Trace::SetDefaultClockSource(kProfilerClockSourceDual); 5728447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum } else if (option == "-small") { 5738447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum parsed->small_mode_ = true; 5742ce745c06271d5223d57dbf08117b20d5b60694aBrian Carlstrom } else if (option == "-sea_ir") { 5757467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea parsed->sea_ir_mode_ = true; 5768447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum } else if (StartsWith(option, "-small-mode-methods-max:")) { 5778447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum parsed->small_mode_method_threshold_ = ParseIntegerOrDie(option); 5788447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum } else if (StartsWith(option, "-small-mode-methods-size-max:")) { 5798447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum parsed->small_mode_method_dex_size_limit_ = ParseIntegerOrDie(option); 5808a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom } else { 5818a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom if (!ignore_unrecognized) { 5826ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom // TODO: print usage via vfprintf 58327ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom LOG(ERROR) << "Unrecognized option " << option; 58427ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom // TODO: this should exit, but for now tolerate unknown options 58527ec961a1da540ba7f16c07a682585ab167317adBrian Carlstrom //return NULL; 5868a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom } 5878a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom } 5888a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom } 5898a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom 590fb67b724df2e3288c8573e8d72b6b6d06aff26caBrian Carlstrom // If a reference to the dalvik core.jar snuck in, replace it with 591fb67b724df2e3288c8573e8d72b6b6d06aff26caBrian Carlstrom // the art specific version. This can happen with on device 592fb67b724df2e3288c8573e8d72b6b6d06aff26caBrian Carlstrom // boot.art/boot.oat generation by GenerateImage which relies on the 593fb67b724df2e3288c8573e8d72b6b6d06aff26caBrian Carlstrom // value of BOOTCLASSPATH. 594fb67b724df2e3288c8573e8d72b6b6d06aff26caBrian Carlstrom std::string core_jar("/core.jar"); 595fb67b724df2e3288c8573e8d72b6b6d06aff26caBrian Carlstrom size_t core_jar_pos = parsed->boot_class_path_string_.find(core_jar); 596fb67b724df2e3288c8573e8d72b6b6d06aff26caBrian Carlstrom if (core_jar_pos != std::string::npos) { 597fb67b724df2e3288c8573e8d72b6b6d06aff26caBrian Carlstrom parsed->boot_class_path_string_.replace(core_jar_pos, core_jar.size(), "/core-libart.jar"); 598fb67b724df2e3288c8573e8d72b6b6d06aff26caBrian Carlstrom } 599fb67b724df2e3288c8573e8d72b6b6d06aff26caBrian Carlstrom 600223f20fa939c386c695977263780dea2195093dbBrian Carlstrom if (!parsed->is_compiler_ && parsed->image_.empty()) { 601223f20fa939c386c695977263780dea2195093dbBrian Carlstrom parsed->image_ += GetAndroidRoot(); 602223f20fa939c386c695977263780dea2195093dbBrian Carlstrom parsed->image_ += "/framework/boot.art"; 6035de8fe5253ca8bd285cba0eb2e56930573ea4c7fBrian Carlstrom } 604c11607024d2e7a52ca690b8339306cab040e6653jeffhao if (parsed->heap_growth_limit_ == 0) { 605c11607024d2e7a52ca690b8339306cab040e6653jeffhao parsed->heap_growth_limit_ = parsed->heap_maximum_size_; 606c11607024d2e7a52ca690b8339306cab040e6653jeffhao } 6075de8fe5253ca8bd285cba0eb2e56930573ea4c7fBrian Carlstrom 60869b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom return parsed.release(); 6098a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom} 6108a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom 61100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogersbool Runtime::Create(const Options& options, bool ignore_unrecognized) { 6122ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro // TODO: acquire a static mutex on Runtime to avoid racing. 6132ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro if (Runtime::instance_ != NULL) { 61400f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers return false; 6152ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro } 616fa42b4410d49134a8e63dc2196be4013d286f2d6Brian Carlstrom InitLogging(NULL); // Calls Locks::Init() as a side effect. 617dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes instance_ = new Runtime; 618dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes if (!instance_->Init(options, ignore_unrecognized)) { 619dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes delete instance_; 620dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes instance_ = NULL; 62100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers return false; 62261e019d291583029c01b61b93bea750f2b663c37Carl Shapiro } 62300f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers return true; 62469b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom} 6250af5543f8ea20c3e655b2d748a1b7dcf283792feElliott Hughes 626365c10235438607541fa2259a5fec48061b90bd8Ian Rogersstatic void CreateSystemClassLoader() { 627b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes if (Runtime::Current()->UseCompileTimeClassPath()) { 628aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom return; 629aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 630aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 63100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers ScopedObjectAccess soa(Thread::Current()); 632aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 6332dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Class* class_loader_class = 6342dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_ClassLoader); 635365c10235438607541fa2259a5fec48061b90bd8Ian Rogers CHECK(Runtime::Current()->GetClassLinker()->EnsureInitialized(class_loader_class, true, true)); 636aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 6372dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::AbstractMethod* getSystemClassLoader = 6382dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers class_loader_class->FindDirectMethod("getSystemClassLoader", "()Ljava/lang/ClassLoader;"); 639df143242f4beaad4cc9fbabebfc033b68c40964eBrian Carlstrom CHECK(getSystemClassLoader != NULL); 640df143242f4beaad4cc9fbabebfc033b68c40964eBrian Carlstrom 6415d9173014c1ca09f7249a6b07629aa37778b5f8fJeff Hao JValue result; 6425d9173014c1ca09f7249a6b07629aa37778b5f8fJeff Hao ArgArray arg_array(NULL, 0); 6436474d190d5604898354ebf767f1944b6e3e9b445Jeff Hao InvokeWithArgArray(soa, getSystemClassLoader, &arg_array, &result, 'L'); 6445d9173014c1ca09f7249a6b07629aa37778b5f8fJeff Hao mirror::ClassLoader* class_loader = down_cast<mirror::ClassLoader*>(result.GetL()); 645365c10235438607541fa2259a5fec48061b90bd8Ian Rogers CHECK(class_loader != NULL); 646365c10235438607541fa2259a5fec48061b90bd8Ian Rogers 64700f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers soa.Self()->SetClassLoaderOverride(class_loader); 6481b2b2f26c4202020d54cc7a5b9c342e6bca5b680Jesse Wilson 6492dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Class* thread_class = soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_Thread); 650365c10235438607541fa2259a5fec48061b90bd8Ian Rogers CHECK(Runtime::Current()->GetClassLinker()->EnsureInitialized(thread_class, true, true)); 651365c10235438607541fa2259a5fec48061b90bd8Ian Rogers 6522dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Field* contextClassLoader = thread_class->FindDeclaredInstanceField("contextClassLoader", 6532dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers "Ljava/lang/ClassLoader;"); 6541b2b2f26c4202020d54cc7a5b9c342e6bca5b680Jesse Wilson CHECK(contextClassLoader != NULL); 655365c10235438607541fa2259a5fec48061b90bd8Ian Rogers 656cfaa455374aae0a08c8cb28b5bb306b17866d652Ian Rogers contextClassLoader->SetObject(soa.Self()->GetPeer(), class_loader); 657aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom} 658aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 659bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrombool Runtime::Start() { 6604dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes VLOG(startup) << "Runtime::Start entering"; 66158ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom 66258ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom CHECK(host_prefix_.empty()) << host_prefix_; 66358ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom 664225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes // Pre-allocate an OutOfMemoryError for the double-OOME case. 66500f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers Thread* self = Thread::Current(); 66662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers self->ThrowNewException(ThrowLocation(), "Ljava/lang/OutOfMemoryError;", 667225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes "OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack available"); 66862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers pre_allocated_OutOfMemoryError_ = self->GetException(NULL); 669225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes self->ClearException(); 670f28bc5b6df6edb4b22aeca360ff102a95f3155e1Brian Carlstrom 67100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers // Restore main thread state to kNative as expected by native code. 67200f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers self->TransitionFromRunnableToSuspended(kNative); 67300f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers 6745d40f182181488eb39ccd19ffd306bb1fb9740c9Brian Carlstrom started_ = true; 6755d40f182181488eb39ccd19ffd306bb1fb9740c9Brian Carlstrom 676ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom // InitNativeMethods needs to be after started_ so that the classes 677ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom // it touches will have methods linked to the oat file if necessary. 678ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom InitNativeMethods(); 679ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 680365c10235438607541fa2259a5fec48061b90bd8Ian Rogers // Initialize well known thread group values that may be accessed threads while attaching. 681365c10235438607541fa2259a5fec48061b90bd8Ian Rogers InitThreadGroups(self); 682365c10235438607541fa2259a5fec48061b90bd8Ian Rogers 6839a6bae896a2f003d7216603bf29771d105c10ca4Jesse Wilson Thread::FinishStartup(); 6849a6bae896a2f003d7216603bf29771d105c10ca4Jesse Wilson 685bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom if (is_zygote_) { 686bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom if (!InitZygote()) { 687bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom return false; 688bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom } 689bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom } else { 690d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes DidForkFromZygote(); 691d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes } 6929ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes 69385d1545e985ac689db4bad7849880e843707c862Elliott Hughes StartDaemonThreads(); 6940a5b14de5115f51e0ed2dd6c3fcc5b84bbce690eBrian Carlstrom 695aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom CreateSystemClassLoader(); 696aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 697225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes self->GetJniEnv()->locals.AssertEmpty(); 698726079d3e2e50854cd6ca4c393f4529a796dba58Elliott Hughes 6994dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes VLOG(startup) << "Runtime::Start exiting"; 7007664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier 7017664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier finished_starting_ = true; 702bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom 703bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom return true; 70485d1545e985ac689db4bad7849880e843707c862Elliott Hughes} 70585d1545e985ac689db4bad7849880e843707c862Elliott Hughes 706120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogersvoid Runtime::EndThreadBirth() EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_) { 707120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers DCHECK_GT(threads_being_born_, 0U); 708120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers threads_being_born_--; 709120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers if (shutting_down_started_ && threads_being_born_ == 0) { 710c604d731730b43231f63040c8db1d58304da0cf3Ian Rogers shutdown_cond_->Broadcast(Thread::Current()); 711120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers } 712120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers} 713120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers 714bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom// Do zygote-mode-only initialization. 715bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrombool Runtime::InitZygote() { 716bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom // zygote goes into its own process group 717b1eba213afaf7fa6445de863ddc9680ab99762eaBrian Carlstrom setpgid(0, 0); 718bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom 719bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom // See storage config details at http://source.android.com/tech/storage/ 720bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom // Create private mount namespace shared by all children 721bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom if (unshare(CLONE_NEWNS) == -1) { 722bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom PLOG(WARNING) << "Failed to unshare()"; 723bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom return false; 724bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom } 725bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom 726bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom // Mark rootfs as being a slave so that changes from default 727bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom // namespace only flow into our children. 728bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom if (mount("rootfs", "/", NULL, (MS_SLAVE | MS_REC), NULL) == -1) { 729bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom PLOG(WARNING) << "Failed to mount() rootfs as MS_SLAVE"; 730bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom return false; 731bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom } 732bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom 733bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom // Create a staging tmpfs that is shared by our children; they will 734bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom // bind mount storage into their respective private namespaces, which 735bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom // are isolated from each other. 736bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom const char* target_base = getenv("EMULATED_STORAGE_TARGET"); 737bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom if (target_base != NULL) { 738bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom if (mount("tmpfs", target_base, "tmpfs", MS_NOSUID | MS_NODEV, 739bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom "uid=0,gid=1028,mode=0050") == -1) { 740bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom LOG(WARNING) << "Failed to mount tmpfs to " << target_base; 741bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom return false; 742bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom } 743bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom } 744bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom 745bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom return true; 746bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom} 747bd86bccf1b47f1151842152ee52cf5d46d6b34abBrian Carlstrom 748caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstromvoid Runtime::DidForkFromZygote() { 749caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom is_zygote_ = false; 750d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes 75102b6a78038f12c109f95eb31713cfc747f5512f1Mathieu Chartier // Create the thread pool. 75202b6a78038f12c109f95eb31713cfc747f5512f1Mathieu Chartier heap_->CreateThreadPool(); 75302b6a78038f12c109f95eb31713cfc747f5512f1Mathieu Chartier 754caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom StartSignalCatcher(); 755d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes 756d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes // Start the JDWP thread. If the command-line debugger flags specified "suspend=y", 757d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes // this will pause the runtime, so we probably want this to come last. 758d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes Dbg::StartJdwp(); 759caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom} 760caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom 761caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstromvoid Runtime::StartSignalCatcher() { 762caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom if (!is_zygote_) { 76394ce37a3919a0bdb8855a3d3264a50df1dbc41beElliott Hughes signal_catcher_ = new SignalCatcher(stack_trace_file_); 764caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom } 765caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom} 766caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom 76785d1545e985ac689db4bad7849880e843707c862Elliott Hughesvoid Runtime::StartDaemonThreads() { 7684dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes VLOG(startup) << "Runtime::StartDaemonThreads entering"; 76985d1545e985ac689db4bad7849880e843707c862Elliott Hughes 770719b323e6a290a075239ac8f4b664e23fd3190f4Elliott Hughes Thread* self = Thread::Current(); 771aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 772aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom // Must be in the kNative state for calling native methods. 77350b35e2fd1a68cd1240e4a9d9f363e11764957d1Ian Rogers CHECK_EQ(self->GetState(), kNative); 774aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 775719b323e6a290a075239ac8f4b664e23fd3190f4Elliott Hughes JNIEnv* env = self->GetJniEnv(); 7762fa6b2e2fc3d2a2fc27808ce518dc76b80ce369aIan Rogers env->CallStaticVoidMethod(WellKnownClasses::java_lang_Daemons, 7772fa6b2e2fc3d2a2fc27808ce518dc76b80ce369aIan Rogers WellKnownClasses::java_lang_Daemons_start); 7782fa6b2e2fc3d2a2fc27808ce518dc76b80ce369aIan Rogers if (env->ExceptionCheck()) { 7792fa6b2e2fc3d2a2fc27808ce518dc76b80ce369aIan Rogers env->ExceptionDescribe(); 7802fa6b2e2fc3d2a2fc27808ce518dc76b80ce369aIan Rogers LOG(FATAL) << "Error starting java.lang.Daemons"; 7812fa6b2e2fc3d2a2fc27808ce518dc76b80ce369aIan Rogers } 7829ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes 7834dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes VLOG(startup) << "Runtime::StartDaemonThreads exiting"; 78461e019d291583029c01b61b93bea750f2b663c37Carl Shapiro} 78561e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 7860af5543f8ea20c3e655b2d748a1b7dcf283792feElliott Hughesbool Runtime::Init(const Options& raw_options, bool ignore_unrecognized) { 787c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes CHECK_EQ(sysconf(_SC_PAGE_SIZE), kPageSize); 7886ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom 78990a3369d3b6238f1a4c9b19ca68978dab1c39bc4Elliott Hughes UniquePtr<ParsedOptions> options(ParsedOptions::Create(raw_options, ignore_unrecognized)); 79090a3369d3b6238f1a4c9b19ca68978dab1c39bc4Elliott Hughes if (options.get() == NULL) { 791e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom LOG(ERROR) << "Failed to parse options"; 7926ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom return false; 7936ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom } 7944dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes VLOG(startup) << "Runtime::Init -verbose:startup enabled"; 7957ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes 7967c6169de901fd0a39c8e0c078874dc25207f5b59Elliott Hughes QuasiAtomic::Startup(); 7977c6169de901fd0a39c8e0c078874dc25207f5b59Elliott Hughes 7984dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes Monitor::Init(options->lock_profiling_threshold_, options->hook_is_sensitive_thread_); 79932d6e1e5654433d7eadede89e1c770b2c839aee9Elliott Hughes 80058ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom host_prefix_ = options->host_prefix_; 801a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom boot_class_path_string_ = options->boot_class_path_string_; 802a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom class_path_string_ = options->class_path_string_; 8037ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes properties_ = options->properties_; 8047ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes 805d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes is_compiler_ = options->is_compiler_; 8069ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes is_zygote_ = options->is_zygote_; 807069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier is_concurrent_gc_enabled_ = options->is_concurrent_gc_enabled_; 8089ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes 8098447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum small_mode_ = options->small_mode_; 8108447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum small_mode_method_threshold_ = options->small_mode_method_threshold_; 8118447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum small_mode_method_dex_size_limit_ = options->small_mode_method_dex_size_limit_; 8128447d84d847d4562d7a7bce62768c27e7d20a9aaAnwar Ghuloum 8137467ee05012e1fd9834df74663c1ebda46f5636bDragos Sbirlea sea_ir_mode_ = options->sea_ir_mode_; 8140af5543f8ea20c3e655b2d748a1b7dcf283792feElliott Hughes vfprintf_ = options->hook_vfprintf_; 8150af5543f8ea20c3e655b2d748a1b7dcf283792feElliott Hughes exit_ = options->hook_exit_; 8160af5543f8ea20c3e655b2d748a1b7dcf283792feElliott Hughes abort_ = options->hook_abort_; 8176ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom 818be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes default_stack_size_ = options->stack_size_; 81994ce37a3919a0bdb8855a3d3264a50df1dbc41beElliott Hughes stack_trace_file_ = options->stack_trace_file_; 8206ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom 821c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes monitor_list_ = new MonitorList; 8224dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes thread_list_ = new ThreadList; 823cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes intern_table_ = new InternTable; 824cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes 825dd361c9eab3284e76e2d07c2e7d371b0f5269942Logan Chien 82662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers if (options->interpreter_only_) { 82762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers GetInstrumentation()->ForceInterpretOnly(); 82862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers } 82962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers 8301d54e73444e017d3a65234e0f193846f3e27472bIan Rogers heap_ = new gc::Heap(options->heap_initial_size_, 8311d54e73444e017d3a65234e0f193846f3e27472bIan Rogers options->heap_growth_limit_, 8321d54e73444e017d3a65234e0f193846f3e27472bIan Rogers options->heap_min_free_, 8331d54e73444e017d3a65234e0f193846f3e27472bIan Rogers options->heap_max_free_, 8341d54e73444e017d3a65234e0f193846f3e27472bIan Rogers options->heap_target_utilization_, 8351d54e73444e017d3a65234e0f193846f3e27472bIan Rogers options->heap_maximum_size_, 8361d54e73444e017d3a65234e0f193846f3e27472bIan Rogers options->image_, 83763a54345598861030178e033ffbd72c0e231a4c9Mathieu Chartier options->is_concurrent_gc_enabled_, 83863a54345598861030178e033ffbd72c0e231a4c9Mathieu Chartier options->heap_gc_threads_); 8396ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom 840c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes BlockSignals(); 841457005c557b8762475db3220ce5a747d629f975bElliott Hughes InitPlatformSignalHandlers(); 842c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes 843a09576416788b916095739e43a16917e7948f3a4Elliott Hughes java_vm_ = new JavaVMExt(this, options.get()); 844515a5bc89282d6f910cae4d5852bb77124a47825Elliott Hughes 845be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes Thread::Startup(); 846d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes 847664bebf92eb2151b9b570ccd42ac4b6056c3ea9cMathieu Chartier // ClassLinker needs an attached thread, but we can't fully attach a thread without creating 848664bebf92eb2151b9b570ccd42ac4b6056c3ea9cMathieu Chartier // objects. We can't supply a thread group yet; it will be fixed later. Since we are the main 849664bebf92eb2151b9b570ccd42ac4b6056c3ea9cMathieu Chartier // thread, we do not get a java peer. 850664bebf92eb2151b9b570ccd42ac4b6056c3ea9cMathieu Chartier Thread* self = Thread::Attach("main", false, NULL, false); 851664bebf92eb2151b9b570ccd42ac4b6056c3ea9cMathieu Chartier CHECK_EQ(self->thin_lock_id_, ThreadList::kMainId); 852120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers CHECK(self != NULL); 8536ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom 854f28bc5b6df6edb4b22aeca360ff102a95f3155e1Brian Carlstrom // Set us to runnable so tools using a runtime can allocate and GC by default 855120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers self->TransitionFromSuspendedToRunnable(); 856f28bc5b6df6edb4b22aeca360ff102a95f3155e1Brian Carlstrom 857141d62275f207bf68c55f583fb206fe586d857cfIan Rogers // Now we're attached, we can take the heap lock and validate the heap. 858141d62275f207bf68c55f583fb206fe586d857cfIan Rogers GetHeap()->EnableObjectValidation(); 859141d62275f207bf68c55f583fb206fe586d857cfIan Rogers 8601d54e73444e017d3a65234e0f193846f3e27472bIan Rogers CHECK_GE(GetHeap()->GetContinuousSpaces().size(), 1U); 8611d54e73444e017d3a65234e0f193846f3e27472bIan Rogers if (GetHeap()->GetContinuousSpaces()[0]->IsImageSpace()) { 862a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom class_linker_ = ClassLinker::CreateFromImage(intern_table_); 863a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom } else { 864a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom CHECK(options->boot_class_path_ != NULL); 865a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom CHECK_NE(options->boot_class_path_->size(), 0U); 866a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom class_linker_ = ClassLinker::CreateFromCompiler(*options->boot_class_path_, intern_table_); 867a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom } 868a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom CHECK(class_linker_ != NULL); 86951a5fb78d1b03b5235c2ae45414235282182bb86Sameer Abu Asal verifier::MethodVerifier::Init(); 8706ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom 871b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao method_trace_ = options->method_trace_; 872b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao method_trace_file_ = options->method_trace_file_; 873b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao method_trace_file_size_ = options->method_trace_file_size_; 874b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao 875b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao if (options->method_trace_) { 876b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao Trace::Start(options->method_trace_file_.c_str(), -1, options->method_trace_file_size_, 0, false); 877b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao } 878b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao 8794dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes VLOG(startup) << "Runtime::Init exiting"; 8807b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro return true; 8817b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro} 8827b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro 883038a806df72f884d22283a84a31c9a1d35ba1fdfElliott Hughesvoid Runtime::InitNativeMethods() { 8844dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes VLOG(startup) << "Runtime::InitNativeMethods entering"; 885ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes Thread* self = Thread::Current(); 886ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes JNIEnv* env = self->GetJniEnv(); 887ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes 888418d20fc407052d4152157f61e7453359f902383Elliott Hughes // Must be in the kNative state for calling native methods (JNI_OnLoad code). 88950b35e2fd1a68cd1240e4a9d9f363e11764957d1Ian Rogers CHECK_EQ(self->GetState(), kNative); 890ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes 891418d20fc407052d4152157f61e7453359f902383Elliott Hughes // First set up JniConstants, which is used by both the runtime's built-in native 892418d20fc407052d4152157f61e7453359f902383Elliott Hughes // methods and libcore. 893fea966e51e65f2040e1510a2e39d407baad29b2cElliott Hughes JniConstants::init(env); 894eac766769e3114a078c188ea26776a81f0edb3cfElliott Hughes WellKnownClasses::Init(env); 895fea966e51e65f2040e1510a2e39d407baad29b2cElliott Hughes 896418d20fc407052d4152157f61e7453359f902383Elliott Hughes // Then set up the native methods provided by the runtime itself. 897ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes RegisterRuntimeNativeMethods(env); 898ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes 899418d20fc407052d4152157f61e7453359f902383Elliott Hughes // Then set up libcore, which is just a regular JNI library with a regular JNI_OnLoad. 900418d20fc407052d4152157f61e7453359f902383Elliott Hughes // Most JNI libraries can just use System.loadLibrary, but libcore can't because it's 901418d20fc407052d4152157f61e7453359f902383Elliott Hughes // the library that implements System.loadLibrary! 90200f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers { 90300f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers std::string mapped_name(StringPrintf(OS_SHARED_LIB_FORMAT_STR, "javacore")); 90400f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers std::string reason; 90500f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers self->TransitionFromSuspendedToRunnable(); 90600f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers if (!instance_->java_vm_->LoadNativeLibrary(mapped_name, NULL, reason)) { 90700f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers LOG(FATAL) << "LoadNativeLibrary failed for \"" << mapped_name << "\": " << reason; 90800f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers } 90900f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers self->TransitionFromRunnableToSuspended(kNative); 91000f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers } 911ef28b14268ed0f9db0c7bbd571aa514354a360bdIan Rogers 912ef28b14268ed0f9db0c7bbd571aa514354a360bdIan Rogers // Initialize well known classes that may invoke runtime native methods. 913ef28b14268ed0f9db0c7bbd571aa514354a360bdIan Rogers WellKnownClasses::LateInit(env); 914ef28b14268ed0f9db0c7bbd571aa514354a360bdIan Rogers 9154dd9b4d95eec9db5338fb9bf132f9bb8facf6cf4Elliott Hughes VLOG(startup) << "Runtime::InitNativeMethods exiting"; 916ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes} 917ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes 918365c10235438607541fa2259a5fec48061b90bd8Ian Rogersvoid Runtime::InitThreadGroups(Thread* self) { 919365c10235438607541fa2259a5fec48061b90bd8Ian Rogers JNIEnvExt* env = self->GetJniEnv(); 920365c10235438607541fa2259a5fec48061b90bd8Ian Rogers ScopedJniEnvLocalRefState env_state(env); 921365c10235438607541fa2259a5fec48061b90bd8Ian Rogers main_thread_group_ = 922365c10235438607541fa2259a5fec48061b90bd8Ian Rogers env->NewGlobalRef(env->GetStaticObjectField(WellKnownClasses::java_lang_ThreadGroup, 923365c10235438607541fa2259a5fec48061b90bd8Ian Rogers WellKnownClasses::java_lang_ThreadGroup_mainThreadGroup)); 924034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom CHECK(main_thread_group_ != NULL || IsCompiler()); 925365c10235438607541fa2259a5fec48061b90bd8Ian Rogers system_thread_group_ = 926365c10235438607541fa2259a5fec48061b90bd8Ian Rogers env->NewGlobalRef(env->GetStaticObjectField(WellKnownClasses::java_lang_ThreadGroup, 927365c10235438607541fa2259a5fec48061b90bd8Ian Rogers WellKnownClasses::java_lang_ThreadGroup_systemThreadGroup)); 928034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom CHECK(system_thread_group_ != NULL || IsCompiler()); 929034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom} 930034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom 931034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstromjobject Runtime::GetMainThreadGroup() const { 932034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom CHECK(main_thread_group_ != NULL || IsCompiler()); 933034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom return main_thread_group_; 934034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom} 935034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom 936034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstromjobject Runtime::GetSystemThreadGroup() const { 937034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom CHECK(system_thread_group_ != NULL || IsCompiler()); 938034f76b91225bea769d6185d7dad5e243af4ffa0Brian Carlstrom return system_thread_group_; 939365c10235438607541fa2259a5fec48061b90bd8Ian Rogers} 940365c10235438607541fa2259a5fec48061b90bd8Ian Rogers 941ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughesvoid Runtime::RegisterRuntimeNativeMethods(JNIEnv* env) { 942ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes#define REGISTER(FN) extern void FN(JNIEnv*); FN(env) 9435167c97a4f672ba821453418e3943988fabbfc43Ian Rogers // Register Throwable first so that registration of other native methods can throw exceptions 9445167c97a4f672ba821453418e3943988fabbfc43Ian Rogers REGISTER(register_java_lang_Throwable); 945f91c8c328c922ecd522e1d3508d2603e78de8a7bBrian Carlstrom REGISTER(register_dalvik_system_DexFile); 9469d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes REGISTER(register_dalvik_system_VMDebug); 9477ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes REGISTER(register_dalvik_system_VMRuntime); 9488daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes REGISTER(register_dalvik_system_VMStack); 94901158d7a57c8321370667a6045220237d16e0da8Elliott Hughes REGISTER(register_dalvik_system_Zygote); 950d369bb76dee0df2d2a106e9bf7f4e6446ed6deaaElliott Hughes REGISTER(register_java_lang_Class); 951bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes REGISTER(register_java_lang_Object); 952bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes REGISTER(register_java_lang_Runtime); 953bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes REGISTER(register_java_lang_String); 954bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes REGISTER(register_java_lang_System); 9558daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes REGISTER(register_java_lang_Thread); 95664bf5a33d55aa779ef452552a466943002d39e4fElliott Hughes REGISTER(register_java_lang_VMClassLoader); 9575b8e4c810a97c9dc417142b8c6e07871ae15c797Brian Carlstrom REGISTER(register_java_lang_reflect_Array); 9582a20cfd0b7fc81099f5de0da782ebcc1cb262792Elliott Hughes REGISTER(register_java_lang_reflect_Constructor); 959f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom REGISTER(register_java_lang_reflect_Field); 960f867b6f706818c886087f61b89d1e8f5fc4653cfBrian Carlstrom REGISTER(register_java_lang_reflect_Method); 96195caa791e560da97363c0c0d22bfda4a7e7377c3Jesse Wilson REGISTER(register_java_lang_reflect_Proxy); 962bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes REGISTER(register_java_util_concurrent_atomic_AtomicLong); 963395520eaa47eca25b92e86188accf3095d60af49Brian Carlstrom REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmServer); 964f6a1e1e44b94221c4e6b063b36921c712a33910bElliott Hughes REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmVmInternal); 9655ee7a8b56dee896245e0f4ae5215f8b7376c1787Elliott Hughes REGISTER(register_sun_misc_Unsafe); 966ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes#undef REGISTER 967ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes} 968ad7c2a3b4daa2abd707375444f4b0db7d69a3838Elliott Hughes 969c967f78cd29b6019f7cfca40a02e9b677112da70Elliott Hughesvoid Runtime::DumpForSigQuit(std::ostream& os) { 970cac6cc72c3331257fa6437b36a131e5d551e2f3cElliott Hughes GetClassLinker()->DumpForSigQuit(os); 971cac6cc72c3331257fa6437b36a131e5d551e2f3cElliott Hughes GetInternTable()->DumpForSigQuit(os); 972ae80b493748c5b6ffe310a91c651e7043f4b2daeElliott Hughes GetJavaVM()->DumpForSigQuit(os); 973c967f78cd29b6019f7cfca40a02e9b677112da70Elliott Hughes GetHeap()->DumpForSigQuit(os); 97442ee14279065352a4b9a3e8028d02c567e847d05Elliott Hughes os << "\n"; 9758daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes 976c967f78cd29b6019f7cfca40a02e9b677112da70Elliott Hughes thread_list_->DumpForSigQuit(os); 97756edc432fa914f7ccfa87ce443e64f5ef475666dIan Rogers BaseMutex::DumpAll(os); 978e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes} 979e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 98021a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughesvoid Runtime::DumpLockHolders(std::ostream& os) { 981b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers uint64_t mutator_lock_owner = Locks::mutator_lock_->GetExclusiveOwnerTid(); 98221a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughes pid_t thread_list_lock_owner = GetThreadList()->GetLockOwner(); 98321a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughes pid_t classes_lock_owner = GetClassLinker()->GetClassesLockOwner(); 98421a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughes pid_t dex_lock_owner = GetClassLinker()->GetDexLockOwner(); 98500f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers if ((thread_list_lock_owner | classes_lock_owner | dex_lock_owner) != 0) { 98600f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers os << "Mutator lock exclusive owner tid: " << mutator_lock_owner << "\n" 98721a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughes << "ThreadList lock owner tid: " << thread_list_lock_owner << "\n" 98821a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughes << "ClassLinker classes lock owner tid: " << classes_lock_owner << "\n" 98921a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughes << "ClassLinker dex lock owner tid: " << dex_lock_owner << "\n"; 99021a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughes } 99121a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughes} 99221a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughes 9939d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughesvoid Runtime::SetStatsEnabled(bool new_state) { 9949d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes if (new_state == true) { 9959d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes GetStats()->Clear(~0); 9969d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes // TODO: wouldn't it make more sense to clear _all_ threads' stats? 9979d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes Thread::Current()->GetStats()->Clear(~0); 9989d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes } 9999d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes stats_enabled_ = new_state; 10009d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes} 10019d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes 10029d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughesvoid Runtime::ResetStats(int kinds) { 10039d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes GetStats()->Clear(kinds & 0xffff); 10049d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes // TODO: wouldn't it make more sense to clear _all_ threads' stats? 10059d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes Thread::Current()->GetStats()->Clear(kinds >> 16); 10069d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes} 10079d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes 10089d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughesint32_t Runtime::GetStat(int kind) { 10099d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes RuntimeStats* stats; 10109d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes if (kind < (1<<16)) { 10119d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes stats = GetStats(); 10129d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes } else { 10139d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes stats = Thread::Current()->GetStats(); 10149d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes kind >>= 16; 10159d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes } 10169d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes switch (kind) { 10179d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes case KIND_ALLOCATED_OBJECTS: 10189d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes return stats->allocated_objects; 10199d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes case KIND_ALLOCATED_BYTES: 10209d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes return stats->allocated_bytes; 10219d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes case KIND_FREED_OBJECTS: 10229d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes return stats->freed_objects; 10239d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes case KIND_FREED_BYTES: 10249d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes return stats->freed_bytes; 10259d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes case KIND_GC_INVOCATIONS: 10269d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes return stats->gc_for_alloc_count; 10279d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes case KIND_CLASS_INIT_COUNT: 10289d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes return stats->class_init_count; 10299d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes case KIND_CLASS_INIT_TIME: 10309d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes // Convert ns to us, reduce to 32 bits. 1031398f64b5805246765b699839b439e18c0dfbf2eeElliott Hughes return static_cast<int>(stats->class_init_time_ns / 1000); 10329d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes case KIND_EXT_ALLOCATED_OBJECTS: 10339d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes case KIND_EXT_ALLOCATED_BYTES: 10349d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes case KIND_EXT_FREED_OBJECTS: 10359d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes case KIND_EXT_FREED_BYTES: 10369d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes return 0; // backward compatibility 10379d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes default: 10387b9d996e4cd7d154bb1a244d67139aff0c363cf2Elliott Hughes LOG(FATAL) << "Unknown statistic " << kind; 10399d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes return -1; // unreachable 10409d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes } 10419d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes} 10429d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes 1043c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughesvoid Runtime::BlockSignals() { 1044457005c557b8762475db3220ce5a747d629f975bElliott Hughes SignalSet signals; 1045457005c557b8762475db3220ce5a747d629f975bElliott Hughes signals.Add(SIGPIPE); 1046c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes // SIGQUIT is used to dump the runtime's state (including stack traces). 1047457005c557b8762475db3220ce5a747d629f975bElliott Hughes signals.Add(SIGQUIT); 10480879504b6ac72f6d93dcccf9e1b7e1769a73b230Elliott Hughes // SIGUSR1 is used to initiate a GC. 1049457005c557b8762475db3220ce5a747d629f975bElliott Hughes signals.Add(SIGUSR1); 1050457005c557b8762475db3220ce5a747d629f975bElliott Hughes signals.Block(); 1051c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes} 1052c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes 1053664bebf92eb2151b9b570ccd42ac4b6056c3ea9cMathieu Chartierbool Runtime::AttachCurrentThread(const char* thread_name, bool as_daemon, jobject thread_group, 1054664bebf92eb2151b9b570ccd42ac4b6056c3ea9cMathieu Chartier bool create_peer) { 1055664bebf92eb2151b9b570ccd42ac4b6056c3ea9cMathieu Chartier bool success = Thread::Attach(thread_name, as_daemon, thread_group, create_peer) != NULL; 105622869a9026a08b544eca4cefd67386d347e30d2cElliott Hughes if (thread_name == NULL) { 105722869a9026a08b544eca4cefd67386d347e30d2cElliott Hughes LOG(WARNING) << *Thread::Current() << " attached without supplying a name"; 105822869a9026a08b544eca4cefd67386d347e30d2cElliott Hughes } 1059120f1c74a9768e958377b6c97897511b27ae58c8Ian Rogers return success; 106061e019d291583029c01b61b93bea750f2b663c37Carl Shapiro} 106161e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 1062d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughesvoid Runtime::DetachCurrentThread() { 10634d5714378c3433ba7e351cbf6a6713fb49c31784Brian Carlstrom Thread* self = Thread::Current(); 10644d5714378c3433ba7e351cbf6a6713fb49c31784Brian Carlstrom if (self == NULL) { 10654d5714378c3433ba7e351cbf6a6713fb49c31784Brian Carlstrom LOG(FATAL) << "attempting to detach thread that is not attached"; 10664d5714378c3433ba7e351cbf6a6713fb49c31784Brian Carlstrom } 10670399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers if (self->HasManagedStack()) { 106822869a9026a08b544eca4cefd67386d347e30d2cElliott Hughes LOG(FATAL) << *Thread::Current() << " attempting to detach while still running code"; 106922869a9026a08b544eca4cefd67386d347e30d2cElliott Hughes } 107000f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers thread_list_->Unregister(self); 10717b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro} 10727b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro 10731d54e73444e017d3a65234e0f193846f3e27472bIan Rogersvoid Runtime::VisitConcurrentRoots(RootVisitor* visitor, void* arg, bool only_dirty, 10741d54e73444e017d3a65234e0f193846f3e27472bIan Rogers bool clean_dirty) { 10751d54e73444e017d3a65234e0f193846f3e27472bIan Rogers if (!only_dirty || intern_table_->IsDirty()) { 10761d54e73444e017d3a65234e0f193846f3e27472bIan Rogers intern_table_->VisitRoots(visitor, arg, clean_dirty); 10779ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier } 10781d54e73444e017d3a65234e0f193846f3e27472bIan Rogers if (!only_dirty || class_linker_->IsDirty()) { 10791d54e73444e017d3a65234e0f193846f3e27472bIan Rogers class_linker_->VisitRoots(visitor, arg, clean_dirty); 10809ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier } 10819ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier} 10829ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier 10832dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogersvoid Runtime::VisitNonThreadRoots(RootVisitor* visitor, void* arg) { 1084e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom java_vm_->VisitRoots(visitor, arg); 1085225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes if (pre_allocated_OutOfMemoryError_ != NULL) { 1086225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes visitor(pre_allocated_OutOfMemoryError_, arg); 1087225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes } 10881984651929744dd603fd082e23eacd877b9bc177Ian Rogers visitor(resolution_method_, arg); 10894f0d07c783afef89703dce32c94440fc8621a29bIan Rogers for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { 1090225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes visitor(callee_save_methods_[i], arg); 10914f0d07c783afef89703dce32c94440fc8621a29bIan Rogers } 1092e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom} 1093e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 10942dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogersvoid Runtime::VisitNonConcurrentRoots(RootVisitor* visitor, void* arg) { 1095858f1c5fd5e528d0b16040ced74d4636046a42d8Mathieu Chartier thread_list_->VisitRoots(visitor, arg); 1096858f1c5fd5e528d0b16040ced74d4636046a42d8Mathieu Chartier VisitNonThreadRoots(visitor, arg); 1097858f1c5fd5e528d0b16040ced74d4636046a42d8Mathieu Chartier} 1098858f1c5fd5e528d0b16040ced74d4636046a42d8Mathieu Chartier 10991d54e73444e017d3a65234e0f193846f3e27472bIan Rogersvoid Runtime::VisitRoots(RootVisitor* visitor, void* arg, bool only_dirty, bool clean_dirty) { 11001d54e73444e017d3a65234e0f193846f3e27472bIan Rogers VisitConcurrentRoots(visitor, arg, only_dirty, clean_dirty); 11019ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier VisitNonConcurrentRoots(visitor, arg); 11029ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier} 11039ebae1f30b84dfd8dab4144f80eebec4f8fc8851Mathieu Chartier 11042dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogersmirror::AbstractMethod* Runtime::CreateResolutionMethod() { 11052dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Class* method_class = mirror::AbstractMethod::GetMethodClass(); 110650b35e2fd1a68cd1240e4a9d9f363e11764957d1Ian Rogers Thread* self = Thread::Current(); 11072dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers SirtRef<mirror::AbstractMethod> 11082dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers method(self, down_cast<mirror::AbstractMethod*>(method_class->AllocObject(self))); 11091984651929744dd603fd082e23eacd877b9bc177Ian Rogers method->SetDeclaringClass(method_class); 11101984651929744dd603fd082e23eacd877b9bc177Ian Rogers // TODO: use a special method for resolution method saves 11111984651929744dd603fd082e23eacd877b9bc177Ian Rogers method->SetDexMethodIndex(DexFile::kDexNoIndex16); 111258df32711162823647356afe25ae2cde04133563Jeff Hao // When compiling, the code pointer will get set later when the image is loaded. 11130aba0ba155bef7346bde19e53581200b89ae8a7aJeff Hao Runtime* r = Runtime::Current(); 11140aba0ba155bef7346bde19e53581200b89ae8a7aJeff Hao ClassLinker* cl = r->GetClassLinker(); 11150aba0ba155bef7346bde19e53581200b89ae8a7aJeff Hao method->SetEntryPointFromCompiledCode(r->IsCompiler() ? NULL : GetResolutionTrampoline(cl)); 11161984651929744dd603fd082e23eacd877b9bc177Ian Rogers return method.get(); 11171984651929744dd603fd082e23eacd877b9bc177Ian Rogers} 11181984651929744dd603fd082e23eacd877b9bc177Ian Rogers 11192dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogersmirror::AbstractMethod* Runtime::CreateCalleeSaveMethod(InstructionSet instruction_set, 11202dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers CalleeSaveType type) { 11212dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Class* method_class = mirror::AbstractMethod::GetMethodClass(); 112250b35e2fd1a68cd1240e4a9d9f363e11764957d1Ian Rogers Thread* self = Thread::Current(); 11232dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers SirtRef<mirror::AbstractMethod> 11242dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers method(self, down_cast<mirror::AbstractMethod*>(method_class->AllocObject(self))); 1125ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers method->SetDeclaringClass(method_class); 11266d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogers // TODO: use a special method for callee saves 11271984651929744dd603fd082e23eacd877b9bc177Ian Rogers method->SetDexMethodIndex(DexFile::kDexNoIndex16); 1128aa4a793d7175ceeb1efa215c2af5e52e42b22f0aJeff Hao method->SetEntryPointFromCompiledCode(NULL); 1129ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom if ((instruction_set == kThumb2) || (instruction_set == kArm)) { 11304f0d07c783afef89703dce32c94440fc8621a29bIan Rogers uint32_t ref_spills = (1 << art::arm::R5) | (1 << art::arm::R6) | (1 << art::arm::R7) | 11314f0d07c783afef89703dce32c94440fc8621a29bIan Rogers (1 << art::arm::R8) | (1 << art::arm::R10) | (1 << art::arm::R11); 11324f0d07c783afef89703dce32c94440fc8621a29bIan Rogers uint32_t arg_spills = (1 << art::arm::R1) | (1 << art::arm::R2) | (1 << art::arm::R3); 11334f0d07c783afef89703dce32c94440fc8621a29bIan Rogers uint32_t all_spills = (1 << art::arm::R4) | (1 << art::arm::R9); 1134fa147e22a73c6df166b08a2f71f9c9b52b09d17cjeffhao uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills : 0) | 1135fa147e22a73c6df166b08a2f71f9c9b52b09d17cjeffhao (type == kSaveAll ? all_spills : 0) | (1 << art::arm::LR); 11364f0d07c783afef89703dce32c94440fc8621a29bIan Rogers uint32_t fp_all_spills = (1 << art::arm::S0) | (1 << art::arm::S1) | (1 << art::arm::S2) | 11374f0d07c783afef89703dce32c94440fc8621a29bIan Rogers (1 << art::arm::S3) | (1 << art::arm::S4) | (1 << art::arm::S5) | 11384f0d07c783afef89703dce32c94440fc8621a29bIan Rogers (1 << art::arm::S6) | (1 << art::arm::S7) | (1 << art::arm::S8) | 11394f0d07c783afef89703dce32c94440fc8621a29bIan Rogers (1 << art::arm::S9) | (1 << art::arm::S10) | (1 << art::arm::S11) | 11404f0d07c783afef89703dce32c94440fc8621a29bIan Rogers (1 << art::arm::S12) | (1 << art::arm::S13) | (1 << art::arm::S14) | 11414f0d07c783afef89703dce32c94440fc8621a29bIan Rogers (1 << art::arm::S15) | (1 << art::arm::S16) | (1 << art::arm::S17) | 11424f0d07c783afef89703dce32c94440fc8621a29bIan Rogers (1 << art::arm::S18) | (1 << art::arm::S19) | (1 << art::arm::S20) | 11434f0d07c783afef89703dce32c94440fc8621a29bIan Rogers (1 << art::arm::S21) | (1 << art::arm::S22) | (1 << art::arm::S23) | 11444f0d07c783afef89703dce32c94440fc8621a29bIan Rogers (1 << art::arm::S24) | (1 << art::arm::S25) | (1 << art::arm::S26) | 11454f0d07c783afef89703dce32c94440fc8621a29bIan Rogers (1 << art::arm::S27) | (1 << art::arm::S28) | (1 << art::arm::S29) | 11464f0d07c783afef89703dce32c94440fc8621a29bIan Rogers (1 << art::arm::S30) | (1 << art::arm::S31); 11474f0d07c783afef89703dce32c94440fc8621a29bIan Rogers uint32_t fp_spills = type == kSaveAll ? fp_all_spills : 0; 11484f0d07c783afef89703dce32c94440fc8621a29bIan Rogers size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ + 11494f0d07c783afef89703dce32c94440fc8621a29bIan Rogers __builtin_popcount(fp_spills) /* fprs */ + 11507fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao 1 /* Method* */) * kPointerSize, kStackAlignment); 11517fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao method->SetFrameSizeInBytes(frame_size); 11527fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao method->SetCoreSpillMask(core_spills); 11537fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao method->SetFpSpillMask(fp_spills); 11547fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao } else if (instruction_set == kMips) { 11557fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao uint32_t ref_spills = (1 << art::mips::S2) | (1 << art::mips::S3) | (1 << art::mips::S4) | 11567fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao (1 << art::mips::S5) | (1 << art::mips::S6) | (1 << art::mips::S7) | 11571f3bc2f0f9366594379249027622ab63673b0d3bJeff Hao (1 << art::mips::GP) | (1 << art::mips::FP); 11587fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao uint32_t arg_spills = (1 << art::mips::A1) | (1 << art::mips::A2) | (1 << art::mips::A3); 1159fa147e22a73c6df166b08a2f71f9c9b52b09d17cjeffhao uint32_t all_spills = (1 << art::mips::S0) | (1 << art::mips::S1); 11607fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills : 0) | 1161fa147e22a73c6df166b08a2f71f9c9b52b09d17cjeffhao (type == kSaveAll ? all_spills : 0) | (1 << art::mips::RA); 11627fbee0731b14b5bf392a4254f5cd84685ab517dajeffhao size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ + 11631f3bc2f0f9366594379249027622ab63673b0d3bJeff Hao (type == kRefsAndArgs ? 0 : 3) + 1 /* Method* */) * 11641f3bc2f0f9366594379249027622ab63673b0d3bJeff Hao kPointerSize, kStackAlignment); 116515fdb8cfb5b2e3fc882113ec0648d492cebf852cIan Rogers method->SetFrameSizeInBytes(frame_size); 11664f0d07c783afef89703dce32c94440fc8621a29bIan Rogers method->SetCoreSpillMask(core_spills); 11670703060875166106af3d490c6c264611aea67ec8jeffhao method->SetFpSpillMask(0); 1168ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom } else if (instruction_set == kX86) { 11697caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers uint32_t ref_spills = (1 << art::x86::EBP) | (1 << art::x86::ESI) | (1 << art::x86::EDI); 11707caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers uint32_t arg_spills = (1 << art::x86::ECX) | (1 << art::x86::EDX) | (1 << art::x86::EBX); 11717caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills : 0) | 11727caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers (1 << art::x86::kNumberOfCpuRegisters); // fake return address callee save 11737caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ + 11747caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers 1 /* Method* */) * kPointerSize, kStackAlignment); 11757caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers method->SetFrameSizeInBytes(frame_size); 11767caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers method->SetCoreSpillMask(core_spills); 1177ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers method->SetFpSpillMask(0); 1178ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers } else { 1179ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers UNIMPLEMENTED(FATAL); 1180ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers } 118140381fb9dc4b4cf274f1e58b2cdf4396202c6189Brian Carlstrom return method.get(); 1182ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers} 1183ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers 11842dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogersvoid Runtime::SetCalleeSaveMethod(mirror::AbstractMethod* method, CalleeSaveType type) { 11854f0d07c783afef89703dce32c94440fc8621a29bIan Rogers DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastCalleeSaveType)); 1186225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes callee_save_methods_[type] = method; 1187e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom} 1188e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 118900f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogersconst std::vector<const DexFile*>& Runtime::GetCompileTimeClassPath(jobject class_loader) { 1190b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes if (class_loader == NULL) { 1191b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes return GetClassLinker()->GetBootClassPath(); 1192b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes } 1193b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes CHECK(UseCompileTimeClassPath()); 1194b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes CompileTimeClassPaths::const_iterator it = compile_time_class_paths_.find(class_loader); 1195b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes CHECK(it != compile_time_class_paths_.end()); 1196b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes return it->second; 1197b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes} 1198b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes 119900f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogersvoid Runtime::SetCompileTimeClassPath(jobject class_loader, std::vector<const DexFile*>& class_path) { 1200b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes CHECK(!IsStarted()); 1201b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes use_compile_time_class_path_ = true; 1202a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes compile_time_class_paths_.Put(class_loader, class_path); 1203b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes} 1204b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes 12056b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapiro} // namespace art 1206