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