1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854
|
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "parsed_options.h"
#include <memory>
#include <sstream>
#include <android-base/logging.h>
#include <android-base/strings.h>
#include "base/file_utils.h"
#include "base/macros.h"
#include "base/utils.h"
#include "debugger.h"
#include "gc/heap.h"
#include "jni_id_type.h"
#include "monitor.h"
#include "runtime.h"
#include "ti/agent.h"
#include "trace.h"
#include "cmdline_parser.h"
#include "runtime_options.h"
namespace art {
using MemoryKiB = Memory<1024>;
ParsedOptions::ParsedOptions()
: hook_is_sensitive_thread_(nullptr),
hook_vfprintf_(vfprintf),
hook_exit_(exit),
hook_abort_(nullptr) { // We don't call abort(3) by default; see
// Runtime::Abort
}
bool ParsedOptions::Parse(const RuntimeOptions& options,
bool ignore_unrecognized,
RuntimeArgumentMap* runtime_options) {
CHECK(runtime_options != nullptr);
ParsedOptions parser;
return parser.DoParse(options, ignore_unrecognized, runtime_options);
}
using RuntimeParser = CmdlineParser<RuntimeArgumentMap, RuntimeArgumentMap::Key>;
using HiddenapiPolicyValueMap =
std::initializer_list<std::pair<const char*, hiddenapi::EnforcementPolicy>>;
// Yes, the stack frame is huge. But we get called super early on (and just once)
// to pass the command line arguments, so we'll probably be ok.
// Ideas to avoid suppressing this diagnostic are welcome!
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wframe-larger-than="
std::unique_ptr<RuntimeParser> ParsedOptions::MakeParser(bool ignore_unrecognized) {
using M = RuntimeArgumentMap;
std::unique_ptr<RuntimeParser::Builder> parser_builder =
std::make_unique<RuntimeParser::Builder>();
HiddenapiPolicyValueMap hiddenapi_policy_valuemap =
{{"disabled", hiddenapi::EnforcementPolicy::kDisabled},
{"just-warn", hiddenapi::EnforcementPolicy::kJustWarn},
{"enabled", hiddenapi::EnforcementPolicy::kEnabled}};
DCHECK_EQ(hiddenapi_policy_valuemap.size(),
static_cast<size_t>(hiddenapi::EnforcementPolicy::kMax) + 1);
parser_builder->
Define("-Xzygote")
.IntoKey(M::Zygote)
.Define("-Xprimaryzygote")
.IntoKey(M::PrimaryZygote)
.Define("-help")
.IntoKey(M::Help)
.Define("-showversion")
.IntoKey(M::ShowVersion)
.Define("-Xbootclasspath:_")
.WithType<ParseStringList<':'>>() // std::vector<std::string>, split by :
.IntoKey(M::BootClassPath)
.Define("-Xbootclasspath-locations:_")
.WithType<ParseStringList<':'>>() // std::vector<std::string>, split by :
.IntoKey(M::BootClassPathLocations)
.Define({"-classpath _", "-cp _"})
.WithType<std::string>()
.IntoKey(M::ClassPath)
.Define("-Ximage:_")
.WithType<std::string>()
.IntoKey(M::Image)
.Define("-Ximage-load-order:_")
.WithType<gc::space::ImageSpaceLoadingOrder>()
.WithValueMap({{"system", gc::space::ImageSpaceLoadingOrder::kSystemFirst},
{"data", gc::space::ImageSpaceLoadingOrder::kDataFirst}})
.IntoKey(M::ImageSpaceLoadingOrder)
.Define("-Xcheck:jni")
.IntoKey(M::CheckJni)
.Define("-Xjniopts:forcecopy")
.IntoKey(M::JniOptsForceCopy)
.Define("-XjdwpProvider:_")
.WithType<JdwpProvider>()
.IntoKey(M::JdwpProvider)
.Define("-XjdwpOptions:_")
.WithType<std::string>()
.IntoKey(M::JdwpOptions)
// TODO Re-enable -agentlib: once I have a good way to transform the values.
// .Define("-agentlib:_")
// .WithType<std::vector<ti::Agent>>().AppendValues()
// .IntoKey(M::AgentLib)
.Define("-agentpath:_")
.WithType<std::list<ti::AgentSpec>>().AppendValues()
.IntoKey(M::AgentPath)
.Define("-Xms_")
.WithType<MemoryKiB>()
.IntoKey(M::MemoryInitialSize)
.Define("-Xmx_")
.WithType<MemoryKiB>()
.IntoKey(M::MemoryMaximumSize)
.Define("-XX:HeapGrowthLimit=_")
.WithType<MemoryKiB>()
.IntoKey(M::HeapGrowthLimit)
.Define("-XX:HeapMinFree=_")
.WithType<MemoryKiB>()
.IntoKey(M::HeapMinFree)
.Define("-XX:HeapMaxFree=_")
.WithType<MemoryKiB>()
.IntoKey(M::HeapMaxFree)
.Define("-XX:NonMovingSpaceCapacity=_")
.WithType<MemoryKiB>()
.IntoKey(M::NonMovingSpaceCapacity)
.Define("-XX:StopForNativeAllocs=_")
.WithType<MemoryKiB>()
.IntoKey(M::StopForNativeAllocs)
.Define("-XX:HeapTargetUtilization=_")
.WithType<double>().WithRange(0.1, 0.9)
.IntoKey(M::HeapTargetUtilization)
.Define("-XX:ForegroundHeapGrowthMultiplier=_")
.WithType<double>().WithRange(0.1, 5.0)
.IntoKey(M::ForegroundHeapGrowthMultiplier)
.Define("-XX:ParallelGCThreads=_")
.WithType<unsigned int>()
.IntoKey(M::ParallelGCThreads)
.Define("-XX:ConcGCThreads=_")
.WithType<unsigned int>()
.IntoKey(M::ConcGCThreads)
.Define("-XX:FinalizerTimeoutMs=_")
.WithType<unsigned int>()
.IntoKey(M::FinalizerTimeoutMs)
.Define("-Xss_")
.WithType<Memory<1>>()
.IntoKey(M::StackSize)
.Define("-XX:MaxSpinsBeforeThinLockInflation=_")
.WithType<unsigned int>()
.IntoKey(M::MaxSpinsBeforeThinLockInflation)
.Define("-XX:LongPauseLogThreshold=_") // in ms
.WithType<MillisecondsToNanoseconds>() // store as ns
.IntoKey(M::LongPauseLogThreshold)
.Define("-XX:LongGCLogThreshold=_") // in ms
.WithType<MillisecondsToNanoseconds>() // store as ns
.IntoKey(M::LongGCLogThreshold)
.Define("-XX:DumpGCPerformanceOnShutdown")
.IntoKey(M::DumpGCPerformanceOnShutdown)
.Define("-XX:DumpRegionInfoBeforeGC")
.IntoKey(M::DumpRegionInfoBeforeGC)
.Define("-XX:DumpRegionInfoAfterGC")
.IntoKey(M::DumpRegionInfoAfterGC)
.Define("-XX:DumpJITInfoOnShutdown")
.IntoKey(M::DumpJITInfoOnShutdown)
.Define("-XX:IgnoreMaxFootprint")
.IntoKey(M::IgnoreMaxFootprint)
.Define("-XX:LowMemoryMode")
.IntoKey(M::LowMemoryMode)
.Define("-XX:UseTLAB")
.WithValue(true)
.IntoKey(M::UseTLAB)
.Define({"-XX:EnableHSpaceCompactForOOM", "-XX:DisableHSpaceCompactForOOM"})
.WithValues({true, false})
.IntoKey(M::EnableHSpaceCompactForOOM)
.Define("-XX:DumpNativeStackOnSigQuit:_")
.WithType<bool>()
.WithValueMap({{"false", false}, {"true", true}})
.IntoKey(M::DumpNativeStackOnSigQuit)
.Define("-XX:MadviseRandomAccess:_")
.WithType<bool>()
.WithValueMap({{"false", false}, {"true", true}})
.IntoKey(M::MadviseRandomAccess)
.Define("-Xusejit:_")
.WithType<bool>()
.WithValueMap({{"false", false}, {"true", true}})
.IntoKey(M::UseJitCompilation)
.Define("-Xusetieredjit:_")
.WithType<bool>()
.WithValueMap({{"false", false}, {"true", true}})
.IntoKey(M::UseTieredJitCompilation)
.Define("-Xjitinitialsize:_")
.WithType<MemoryKiB>()
.IntoKey(M::JITCodeCacheInitialCapacity)
.Define("-Xjitmaxsize:_")
.WithType<MemoryKiB>()
.IntoKey(M::JITCodeCacheMaxCapacity)
.Define("-Xjitthreshold:_")
.WithType<unsigned int>()
.IntoKey(M::JITCompileThreshold)
.Define("-Xjitwarmupthreshold:_")
.WithType<unsigned int>()
.IntoKey(M::JITWarmupThreshold)
.Define("-Xjitosrthreshold:_")
.WithType<unsigned int>()
.IntoKey(M::JITOsrThreshold)
.Define("-Xjitprithreadweight:_")
.WithType<unsigned int>()
.IntoKey(M::JITPriorityThreadWeight)
.Define("-Xjittransitionweight:_")
.WithType<unsigned int>()
.IntoKey(M::JITInvokeTransitionWeight)
.Define("-Xjitpthreadpriority:_")
.WithType<int>()
.IntoKey(M::JITPoolThreadPthreadPriority)
.Define("-Xjitsaveprofilinginfo")
.WithType<ProfileSaverOptions>()
.AppendValues()
.IntoKey(M::ProfileSaverOpts)
.Define("-Xps-_") // profile saver options -Xps-<key>:<value>
.WithType<ProfileSaverOptions>()
.AppendValues()
.IntoKey(M::ProfileSaverOpts) // NOTE: Appends into same key as -Xjitsaveprofilinginfo
.Define("-XX:HspaceCompactForOOMMinIntervalMs=_") // in ms
.WithType<MillisecondsToNanoseconds>() // store as ns
.IntoKey(M::HSpaceCompactForOOMMinIntervalsMs)
.Define("-D_")
.WithType<std::vector<std::string>>().AppendValues()
.IntoKey(M::PropertiesList)
.Define("-Xjnitrace:_")
.WithType<std::string>()
.IntoKey(M::JniTrace)
.Define({"-Xrelocate", "-Xnorelocate"})
.WithValues({true, false})
.IntoKey(M::Relocate)
.Define({"-Ximage-dex2oat", "-Xnoimage-dex2oat"})
.WithValues({true, false})
.IntoKey(M::ImageDex2Oat)
.Define("-Xint")
.WithValue(true)
.IntoKey(M::Interpret)
.Define("-Xgc:_")
.WithType<XGcOption>()
.IntoKey(M::GcOption)
.Define("-XX:LargeObjectSpace=_")
.WithType<gc::space::LargeObjectSpaceType>()
.WithValueMap({{"disabled", gc::space::LargeObjectSpaceType::kDisabled},
{"freelist", gc::space::LargeObjectSpaceType::kFreeList},
{"map", gc::space::LargeObjectSpaceType::kMap}})
.IntoKey(M::LargeObjectSpace)
.Define("-XX:LargeObjectThreshold=_")
.WithType<Memory<1>>()
.IntoKey(M::LargeObjectThreshold)
.Define("-XX:BackgroundGC=_")
.WithType<BackgroundGcOption>()
.IntoKey(M::BackgroundGc)
.Define("-XX:+DisableExplicitGC")
.IntoKey(M::DisableExplicitGC)
.Define("-verbose:_")
.WithType<LogVerbosity>()
.IntoKey(M::Verbose)
.Define("-Xlockprofthreshold:_")
.WithType<unsigned int>()
.IntoKey(M::LockProfThreshold)
.Define("-Xstackdumplockprofthreshold:_")
.WithType<unsigned int>()
.IntoKey(M::StackDumpLockProfThreshold)
.Define("-Xmethod-trace")
.IntoKey(M::MethodTrace)
.Define("-Xmethod-trace-file:_")
.WithType<std::string>()
.IntoKey(M::MethodTraceFile)
.Define("-Xmethod-trace-file-size:_")
.WithType<unsigned int>()
.IntoKey(M::MethodTraceFileSize)
.Define("-Xmethod-trace-stream")
.IntoKey(M::MethodTraceStreaming)
.Define("-Xprofile:_")
.WithType<TraceClockSource>()
.WithValueMap({{"threadcpuclock", TraceClockSource::kThreadCpu},
{"wallclock", TraceClockSource::kWall},
{"dualclock", TraceClockSource::kDual}})
.IntoKey(M::ProfileClock)
.Define("-Xcompiler:_")
.WithType<std::string>()
.IntoKey(M::Compiler)
.Define("-Xcompiler-option _")
.WithType<std::vector<std::string>>()
.AppendValues()
.IntoKey(M::CompilerOptions)
.Define("-Ximage-compiler-option _")
.WithType<std::vector<std::string>>()
.AppendValues()
.IntoKey(M::ImageCompilerOptions)
.Define("-Xverify:_")
.WithType<verifier::VerifyMode>()
.WithValueMap({{"none", verifier::VerifyMode::kNone},
{"remote", verifier::VerifyMode::kEnable},
{"all", verifier::VerifyMode::kEnable},
{"softfail", verifier::VerifyMode::kSoftFail}})
.IntoKey(M::Verify)
.Define("-XX:NativeBridge=_")
.WithType<std::string>()
.IntoKey(M::NativeBridge)
.Define("-Xzygote-max-boot-retry=_")
.WithType<unsigned int>()
.IntoKey(M::ZygoteMaxFailedBoots)
.Define("-Xno-dex-file-fallback")
.IntoKey(M::NoDexFileFallback)
.Define("-Xno-sig-chain")
.IntoKey(M::NoSigChain)
.Define("--cpu-abilist=_")
.WithType<std::string>()
.IntoKey(M::CpuAbiList)
.Define("-Xfingerprint:_")
.WithType<std::string>()
.IntoKey(M::Fingerprint)
.Define("-Xexperimental:_")
.WithType<ExperimentalFlags>()
.AppendValues()
.IntoKey(M::Experimental)
.Define("-Xforce-nb-testing")
.IntoKey(M::ForceNativeBridge)
.Define("-Xplugin:_")
.WithType<std::vector<Plugin>>().AppendValues()
.IntoKey(M::Plugins)
.Define("-XX:ThreadSuspendTimeout=_") // in ms
.WithType<MillisecondsToNanoseconds>() // store as ns
.IntoKey(M::ThreadSuspendTimeout)
.Define("-XX:GlobalRefAllocStackTraceLimit=_") // Number of free slots to enable tracing.
.WithType<unsigned int>()
.IntoKey(M::GlobalRefAllocStackTraceLimit)
.Define("-XX:SlowDebug=_")
.WithType<bool>()
.WithValueMap({{"false", false}, {"true", true}})
.IntoKey(M::SlowDebug)
.Define("-Xtarget-sdk-version:_")
.WithType<unsigned int>()
.IntoKey(M::TargetSdkVersion)
.Define("-Xhidden-api-policy:_")
.WithType<hiddenapi::EnforcementPolicy>()
.WithValueMap(hiddenapi_policy_valuemap)
.IntoKey(M::HiddenApiPolicy)
.Define("-Xcore-platform-api-policy:_")
.WithType<hiddenapi::EnforcementPolicy>()
.WithValueMap(hiddenapi_policy_valuemap)
.IntoKey(M::CorePlatformApiPolicy)
.Define("-Xuse-stderr-logger")
.IntoKey(M::UseStderrLogger)
.Define("-Xonly-use-system-oat-files")
.IntoKey(M::OnlyUseSystemOatFiles)
.Define("-Xverifier-logging-threshold=_")
.WithType<unsigned int>()
.IntoKey(M::VerifierLoggingThreshold)
.Define("-XX:FastClassNotFoundException=_")
.WithType<bool>()
.WithValueMap({{"false", false}, {"true", true}})
.IntoKey(M::FastClassNotFoundException)
.Define("-Xopaque-jni-ids:_")
.WithType<JniIdType>()
.WithValueMap({{"true", JniIdType::kIndices},
{"false", JniIdType::kPointer},
{"swapable", JniIdType::kSwapablePointer},
{"pointer", JniIdType::kPointer},
{"indices", JniIdType::kIndices},
{"default", JniIdType::kDefault}})
.IntoKey(M::OpaqueJniIds)
.Define("-Xauto-promote-opaque-jni-ids:_")
.WithType<bool>()
.WithValueMap({{"true", true}, {"false", false}})
.IntoKey(M::AutoPromoteOpaqueJniIds)
.Define("-XX:VerifierMissingKThrowFatal=_")
.WithType<bool>()
.WithValueMap({{"false", false}, {"true", true}})
.IntoKey(M::VerifierMissingKThrowFatal)
.Define("-XX:PerfettoHprof=_")
.WithType<bool>()
.WithValueMap({{"false", false}, {"true", true}})
.IntoKey(M::PerfettoHprof)
.Ignore({
"-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa",
"-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:_",
"-Xdexopt:_", "-Xnoquithandler", "-Xjnigreflimit:_", "-Xgenregmap", "-Xnogenregmap",
"-Xverifyopt:_", "-Xcheckdexsum", "-Xincludeselectedop", "-Xjitop:_",
"-Xincludeselectedmethod", "-Xjitthreshold:_",
"-Xjitblocking", "-Xjitmethod:_", "-Xjitclass:_", "-Xjitoffset:_",
"-Xjitconfig:_", "-Xjitcheckcg", "-Xjitverbose", "-Xjitprofile",
"-Xjitdisableopt", "-Xjitsuspendpoll", "-XX:mainThreadStackSize=_"})
.IgnoreUnrecognized(ignore_unrecognized);
// TODO: Move Usage information into this DSL.
return std::make_unique<RuntimeParser>(parser_builder->Build());
}
#pragma GCC diagnostic pop
// Remove all the special options that have something in the void* part of the option.
// If runtime_options is not null, put the options in there.
// As a side-effect, populate the hooks from options.
bool ParsedOptions::ProcessSpecialOptions(const RuntimeOptions& options,
RuntimeArgumentMap* runtime_options,
std::vector<std::string>* out_options) {
using M = RuntimeArgumentMap;
// TODO: Move the below loop into JNI
// Handle special options that set up hooks
for (size_t i = 0; i < options.size(); ++i) {
const std::string option(options[i].first);
// TODO: support -Djava.class.path
if (option == "bootclasspath") {
auto boot_class_path = static_cast<std::vector<std::unique_ptr<const DexFile>>*>(
const_cast<void*>(options[i].second));
if (runtime_options != nullptr) {
runtime_options->Set(M::BootClassPathDexList, boot_class_path);
}
} else if (option == "compilercallbacks") {
CompilerCallbacks* compiler_callbacks =
reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second));
if (runtime_options != nullptr) {
runtime_options->Set(M::CompilerCallbacksPtr, compiler_callbacks);
}
} else if (option == "imageinstructionset") {
const char* isa_str = reinterpret_cast<const char*>(options[i].second);
auto&& image_isa = GetInstructionSetFromString(isa_str);
if (image_isa == InstructionSet::kNone) {
Usage("%s is not a valid instruction set.", isa_str);
return false;
}
if (runtime_options != nullptr) {
runtime_options->Set(M::ImageInstructionSet, image_isa);
}
} else if (option == "sensitiveThread") {
const void* hook = options[i].second;
bool (*hook_is_sensitive_thread)() = reinterpret_cast<bool (*)()>(const_cast<void*>(hook));
if (runtime_options != nullptr) {
runtime_options->Set(M::HookIsSensitiveThread, hook_is_sensitive_thread);
}
} else if (option == "vfprintf") {
const void* hook = options[i].second;
if (hook == nullptr) {
Usage("vfprintf argument was nullptr");
return false;
}
int (*hook_vfprintf)(FILE *, const char*, va_list) =
reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook));
if (runtime_options != nullptr) {
runtime_options->Set(M::HookVfprintf, hook_vfprintf);
}
hook_vfprintf_ = hook_vfprintf;
} else if (option == "exit") {
const void* hook = options[i].second;
if (hook == nullptr) {
Usage("exit argument was nullptr");
return false;
}
void(*hook_exit)(jint) = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook));
if (runtime_options != nullptr) {
runtime_options->Set(M::HookExit, hook_exit);
}
hook_exit_ = hook_exit;
} else if (option == "abort") {
const void* hook = options[i].second;
if (hook == nullptr) {
Usage("abort was nullptr\n");
return false;
}
void(*hook_abort)() = reinterpret_cast<void(*)()>(const_cast<void*>(hook));
if (runtime_options != nullptr) {
runtime_options->Set(M::HookAbort, hook_abort);
}
hook_abort_ = hook_abort;
} else {
// It is a regular option, that doesn't have a known 'second' value.
// Push it on to the regular options which will be parsed by our parser.
if (out_options != nullptr) {
out_options->push_back(option);
}
}
}
return true;
}
// Intended for local changes only.
static void MaybeOverrideVerbosity() {
// gLogVerbosity.class_linker = true; // TODO: don't check this in!
// gLogVerbosity.collector = true; // TODO: don't check this in!
// gLogVerbosity.compiler = true; // TODO: don't check this in!
// gLogVerbosity.deopt = true; // TODO: don't check this in!
// gLogVerbosity.gc = true; // TODO: don't check this in!
// gLogVerbosity.heap = true; // TODO: don't check this in!
// gLogVerbosity.interpreter = true; // TODO: don't check this in!
// gLogVerbosity.jdwp = true; // TODO: don't check this in!
// gLogVerbosity.jit = true; // TODO: don't check this in!
// gLogVerbosity.jni = true; // TODO: don't check this in!
// gLogVerbosity.monitor = true; // TODO: don't check this in!
// gLogVerbosity.oat = true; // TODO: don't check this in!
// gLogVerbosity.profiler = true; // TODO: don't check this in!
// gLogVerbosity.signals = true; // TODO: don't check this in!
// gLogVerbosity.simulator = true; // TODO: don't check this in!
// gLogVerbosity.startup = true; // TODO: don't check this in!
// gLogVerbosity.third_party_jni = true; // TODO: don't check this in!
// gLogVerbosity.threads = true; // TODO: don't check this in!
// gLogVerbosity.verifier = true; // TODO: don't check this in!
}
bool ParsedOptions::DoParse(const RuntimeOptions& options,
bool ignore_unrecognized,
RuntimeArgumentMap* runtime_options) {
for (size_t i = 0; i < options.size(); ++i) {
if (true && options[0].first == "-Xzygote") {
LOG(INFO) << "option[" << i << "]=" << options[i].first;
}
}
auto parser = MakeParser(ignore_unrecognized);
// Convert to a simple string list (without the magic pointer options)
std::vector<std::string> argv_list;
if (!ProcessSpecialOptions(options, nullptr, &argv_list)) {
return false;
}
CmdlineResult parse_result = parser->Parse(argv_list);
// Handle parse errors by displaying the usage and potentially exiting.
if (parse_result.IsError()) {
if (parse_result.GetStatus() == CmdlineResult::kUsage) {
UsageMessage(stdout, "%s\n", parse_result.GetMessage().c_str());
Exit(0);
} else if (parse_result.GetStatus() == CmdlineResult::kUnknown && !ignore_unrecognized) {
Usage("%s\n", parse_result.GetMessage().c_str());
return false;
} else {
Usage("%s\n", parse_result.GetMessage().c_str());
Exit(0);
}
UNREACHABLE();
}
using M = RuntimeArgumentMap;
RuntimeArgumentMap args = parser->ReleaseArgumentsMap();
// -help, -showversion, etc.
if (args.Exists(M::Help)) {
Usage(nullptr);
return false;
} else if (args.Exists(M::ShowVersion)) {
UsageMessage(stdout,
"ART version %s %s\n",
Runtime::GetVersion(),
GetInstructionSetString(kRuntimeISA));
Exit(0);
} else if (args.Exists(M::BootClassPath)) {
LOG(INFO) << "setting boot class path to " << args.Get(M::BootClassPath)->Join();
}
if (args.GetOrDefault(M::Interpret)) {
if (args.Exists(M::UseJitCompilation) && *args.Get(M::UseJitCompilation)) {
Usage("-Xusejit:true and -Xint cannot be specified together\n");
Exit(0);
}
args.Set(M::UseJitCompilation, false);
}
// Set a default boot class path if we didn't get an explicit one via command line.
const char* env_bcp = getenv("BOOTCLASSPATH");
if (env_bcp != nullptr) {
args.SetIfMissing(M::BootClassPath, ParseStringList<':'>::Split(env_bcp));
}
// Set a default class path if we didn't get an explicit one via command line.
if (getenv("CLASSPATH") != nullptr) {
args.SetIfMissing(M::ClassPath, std::string(getenv("CLASSPATH")));
}
// Default to number of processors minus one since the main GC thread also does work.
args.SetIfMissing(M::ParallelGCThreads, gc::Heap::kDefaultEnableParallelGC ?
static_cast<unsigned int>(sysconf(_SC_NPROCESSORS_CONF) - 1u) : 0u);
// -verbose:
{
LogVerbosity *log_verbosity = args.Get(M::Verbose);
if (log_verbosity != nullptr) {
gLogVerbosity = *log_verbosity;
}
}
MaybeOverrideVerbosity();
SetRuntimeDebugFlagsEnabled(args.GetOrDefault(M::SlowDebug));
// -Xprofile:
Trace::SetDefaultClockSource(args.GetOrDefault(M::ProfileClock));
if (!ProcessSpecialOptions(options, &args, nullptr)) {
return false;
}
{
// If not set, background collector type defaults to homogeneous compaction.
// If not low memory mode, semispace otherwise.
gc::CollectorType background_collector_type_;
gc::CollectorType collector_type_ = (XGcOption{}).collector_type_;
bool low_memory_mode_ = args.Exists(M::LowMemoryMode);
background_collector_type_ = args.GetOrDefault(M::BackgroundGc);
{
XGcOption* xgc = args.Get(M::GcOption);
if (xgc != nullptr && xgc->collector_type_ != gc::kCollectorTypeNone) {
collector_type_ = xgc->collector_type_;
}
}
if (background_collector_type_ == gc::kCollectorTypeNone) {
background_collector_type_ = low_memory_mode_ ?
gc::kCollectorTypeSS : gc::kCollectorTypeHomogeneousSpaceCompact;
}
args.Set(M::BackgroundGc, BackgroundGcOption { background_collector_type_ });
}
const ParseStringList<':'>* boot_class_path_locations = args.Get(M::BootClassPathLocations);
if (boot_class_path_locations != nullptr && boot_class_path_locations->Size() != 0u) {
const ParseStringList<':'>* boot_class_path = args.Get(M::BootClassPath);
if (boot_class_path == nullptr ||
boot_class_path_locations->Size() != boot_class_path->Size()) {
Usage("The number of boot class path files does not match"
" the number of boot class path locations given\n"
" boot class path files (%zu): %s\n"
" boot class path locations (%zu): %s\n",
(boot_class_path != nullptr) ? boot_class_path->Size() : 0u,
(boot_class_path != nullptr) ? boot_class_path->Join().c_str() : "<nil>",
boot_class_path_locations->Size(),
boot_class_path_locations->Join().c_str());
return false;
}
}
if (!args.Exists(M::CompilerCallbacksPtr) && !args.Exists(M::Image)) {
std::string image = GetDefaultBootImageLocation(GetAndroidRoot());
args.Set(M::Image, image);
}
// 0 means no growth limit, and growth limit should be always <= heap size
if (args.GetOrDefault(M::HeapGrowthLimit) <= 0u ||
args.GetOrDefault(M::HeapGrowthLimit) > args.GetOrDefault(M::MemoryMaximumSize)) {
args.Set(M::HeapGrowthLimit, args.GetOrDefault(M::MemoryMaximumSize));
}
*runtime_options = std::move(args);
return true;
}
void ParsedOptions::Exit(int status) {
hook_exit_(status);
}
void ParsedOptions::Abort() {
hook_abort_();
}
void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) {
hook_vfprintf_(stream, fmt, ap);
}
void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
UsageMessageV(stream, fmt, ap);
va_end(ap);
}
void ParsedOptions::Usage(const char* fmt, ...) {
bool error = (fmt != nullptr);
FILE* stream = error ? stderr : stdout;
if (fmt != nullptr) {
va_list ap;
va_start(ap, fmt);
UsageMessageV(stream, fmt, ap);
va_end(ap);
}
const char* program = "dalvikvm";
UsageMessage(stream, "%s: [options] class [argument ...]\n", program);
UsageMessage(stream, "\n");
UsageMessage(stream, "The following standard options are supported:\n");
UsageMessage(stream, " -classpath classpath (-cp classpath)\n");
UsageMessage(stream, " -Dproperty=value\n");
UsageMessage(stream, " -verbose:tag[,tag...] (currently valid tags: 'agents', 'class',\n"
" 'collector', 'compiler', 'deopt', 'dex', 'gc', 'heap', 'image',\n"
" 'interpreter', 'jdwp', 'jit', 'jni', 'monitor', 'oat', 'profiler',\n"
" 'signals', 'simulator', 'startup', 'systrace-locks',\n"
" 'third-party-jni', 'threads', 'verifier', 'verifier-debug')\n");
UsageMessage(stream, " -showversion\n");
UsageMessage(stream, " -help\n");
// TODO add back in once -agentlib actually does something.
// UsageMessage(stream, " -agentlib:library=options (Experimental feature, "
// "requires -Xexperimental:agent, some features might not be supported)\n");
UsageMessage(stream, " -agentpath:library_path=options (Experimental feature, requires\n"
" -Xexperimental:agent, some features might not be supported)\n");
UsageMessage(stream, "\n");
UsageMessage(stream, "The following extended options are supported:\n");
UsageMessage(stream, " -Xbootclasspath:bootclasspath\n");
UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n");
UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n");
UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n");
UsageMessage(stream, " -XssN (stack size)\n");
UsageMessage(stream, " -Xint\n");
UsageMessage(stream, "\n");
UsageMessage(stream, "The following Dalvik options are supported:\n");
UsageMessage(stream, " -Xzygote\n");
UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n");
UsageMessage(stream, " -Xgc:[no]preverify\n");
UsageMessage(stream, " -Xgc:[no]postverify\n");
UsageMessage(stream, " -XX:HeapGrowthLimit=N\n");
UsageMessage(stream, " -XX:HeapMinFree=N\n");
UsageMessage(stream, " -XX:HeapMaxFree=N\n");
UsageMessage(stream, " -XX:NonMovingSpaceCapacity=N\n");
UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n");
UsageMessage(stream, " -XX:ForegroundHeapGrowthMultiplier=doublevalue\n");
UsageMessage(stream, " -XX:LowMemoryMode\n");
UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n");
UsageMessage(stream, " -Xjitthreshold:integervalue\n");
UsageMessage(stream, "\n");
UsageMessage(stream, "The following unique to ART options are supported:\n");
UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n");
UsageMessage(stream, " -Xgc:[no]postsweepingverify_rosalloc\n");
UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n");
UsageMessage(stream, " -Xgc:[no]presweepingverify\n");
UsageMessage(stream, " -Xgc:[no]generational_cc\n");
UsageMessage(stream, " -Ximage:filename\n");
UsageMessage(stream, " -Xbootclasspath-locations:bootclasspath\n"
" (override the dex locations of the -Xbootclasspath files)\n");
UsageMessage(stream, " -XX:+DisableExplicitGC\n");
UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n");
UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n");
UsageMessage(stream, " -XX:FinalizerTimeoutMs=integervalue\n");
UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n");
UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n");
UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n");
UsageMessage(stream, " -XX:ThreadSuspendTimeout=integervalue\n");
UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n");
UsageMessage(stream, " -XX:DumpJITInfoOnShutdown\n");
UsageMessage(stream, " -XX:IgnoreMaxFootprint\n");
UsageMessage(stream, " -XX:UseTLAB\n");
UsageMessage(stream, " -XX:BackgroundGC=none\n");
UsageMessage(stream, " -XX:LargeObjectSpace={disabled,map,freelist}\n");
UsageMessage(stream, " -XX:LargeObjectThreshold=N\n");
UsageMessage(stream, " -XX:StopForNativeAllocs=N\n");
UsageMessage(stream, " -XX:DumpNativeStackOnSigQuit=booleanvalue\n");
UsageMessage(stream, " -XX:MadviseRandomAccess:booleanvalue\n");
UsageMessage(stream, " -XX:SlowDebug={false,true}\n");
UsageMessage(stream, " -Xmethod-trace\n");
UsageMessage(stream, " -Xmethod-trace-file:filename\n");
UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n");
UsageMessage(stream, " -Xps-min-save-period-ms:integervalue\n");
UsageMessage(stream, " -Xps-save-resolved-classes-delay-ms:integervalue\n");
UsageMessage(stream, " -Xps-hot-startup-method-samples:integervalue\n");
UsageMessage(stream, " -Xps-min-methods-to-save:integervalue\n");
UsageMessage(stream, " -Xps-min-classes-to-save:integervalue\n");
UsageMessage(stream, " -Xps-min-notification-before-wake:integervalue\n");
UsageMessage(stream, " -Xps-max-notification-before-wake:integervalue\n");
UsageMessage(stream, " -Xps-profile-path:file-path\n");
UsageMessage(stream, " -Xcompiler:filename\n");
UsageMessage(stream, " -Xcompiler-option dex2oat-option\n");
UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n");
UsageMessage(stream, " -Xusejit:booleanvalue\n");
UsageMessage(stream, " -Xjitinitialsize:N\n");
UsageMessage(stream, " -Xjitmaxsize:N\n");
UsageMessage(stream, " -Xjitwarmupthreshold:integervalue\n");
UsageMessage(stream, " -Xjitosrthreshold:integervalue\n");
UsageMessage(stream, " -Xjitprithreadweight:integervalue\n");
UsageMessage(stream, " -X[no]relocate\n");
UsageMessage(stream, " -X[no]dex2oat (Whether to invoke dex2oat on the application)\n");
UsageMessage(stream, " -X[no]image-dex2oat (Whether to create and use a boot image)\n");
UsageMessage(stream, " -Xno-dex-file-fallback "
"(Don't fall back to dex files without oat files)\n");
UsageMessage(stream, " -Xplugin:<library.so> "
"(Load a runtime plugin, requires -Xexperimental:runtime-plugins)\n");
UsageMessage(stream, " -Xexperimental:runtime-plugins"
"(Enable new and experimental agent support)\n");
UsageMessage(stream, " -Xexperimental:agents"
"(Enable new and experimental agent support)\n");
UsageMessage(stream, " -Xopaque-jni-ids:{true,false,swapable}");
UsageMessage(stream, "(Use opauque integers for jni ids, yes, no or punt for later)\n");
UsageMessage(stream, "\n");
UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n");
UsageMessage(stream, " -ea[:<package name>... |:<class name>]\n");
UsageMessage(stream, " -da[:<package name>... |:<class name>]\n");
UsageMessage(stream, " (-enableassertions, -disableassertions)\n");
UsageMessage(stream, " -esa\n");
UsageMessage(stream, " -dsa\n");
UsageMessage(stream, " (-enablesystemassertions, -disablesystemassertions)\n");
UsageMessage(stream, " -Xverify:{none,remote,all,softfail}\n");
UsageMessage(stream, " -Xrs\n");
UsageMessage(stream, " -Xint:portable, -Xint:fast, -Xint:jit\n");
UsageMessage(stream, " -Xdexopt:{none,verified,all,full}\n");
UsageMessage(stream, " -Xnoquithandler\n");
UsageMessage(stream, " -Xjniopts:{warnonly,forcecopy}\n");
UsageMessage(stream, " -Xjnigreflimit:integervalue\n");
UsageMessage(stream, " -Xgc:[no]precise\n");
UsageMessage(stream, " -Xgc:[no]verifycardtable\n");
UsageMessage(stream, " -X[no]genregmap\n");
UsageMessage(stream, " -Xverifyopt:[no]checkmon\n");
UsageMessage(stream, " -Xcheckdexsum\n");
UsageMessage(stream, " -Xincludeselectedop\n");
UsageMessage(stream, " -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*\n");
UsageMessage(stream, " -Xincludeselectedmethod\n");
UsageMessage(stream, " -Xjitblocking\n");
UsageMessage(stream, " -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\\;replace)\n");
UsageMessage(stream, " -Xjitclass:classname[,classname]*\n");
UsageMessage(stream, " -Xjitcodecachesize:N\n");
UsageMessage(stream, " -Xjitoffset:offset[,offset]\n");
UsageMessage(stream, " -Xjitconfig:filename\n");
UsageMessage(stream, " -Xjitcheckcg\n");
UsageMessage(stream, " -Xjitverbose\n");
UsageMessage(stream, " -Xjitprofile\n");
UsageMessage(stream, " -Xjitdisableopt\n");
UsageMessage(stream, " -Xjitsuspendpoll\n");
UsageMessage(stream, " -XX:mainThreadStackSize=N\n");
UsageMessage(stream, "\n");
Exit((error) ? 1 : 0);
}
} // namespace art
|