Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "parsed_options.h" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 18 | |
Yi Kong | c57c680 | 2018-10-29 14:28:56 -0700 | [diff] [blame] | 19 | #include <memory> |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 20 | #include <sstream> |
| 21 | |
Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 22 | #include <android-base/logging.h> |
Vladimir Marko | 91f1032 | 2018-12-07 18:04:10 +0000 | [diff] [blame] | 23 | #include <android-base/strings.h> |
Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 24 | |
David Sehr | 891a50e | 2017-10-27 17:01:07 -0700 | [diff] [blame] | 25 | #include "base/file_utils.h" |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 26 | #include "base/indenter.h" |
Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 27 | #include "base/macros.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 28 | #include "base/utils.h" |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 29 | #include "debugger.h" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 30 | #include "gc/heap.h" |
Alex Light | f367747 | 2019-06-26 16:31:53 -0700 | [diff] [blame] | 31 | #include "jni_id_type.h" |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 32 | #include "monitor.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 33 | #include "runtime.h" |
Alex Light | 7233c7e | 2016-07-28 10:07:45 -0700 | [diff] [blame] | 34 | #include "ti/agent.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 35 | #include "trace.h" |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 36 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 37 | #include "cmdline_parser.h" |
| 38 | #include "runtime_options.h" |
| 39 | |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 40 | namespace art { |
| 41 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 42 | using MemoryKiB = Memory<1024>; |
| 43 | |
Andreas Gampe | 313f403 | 2014-08-29 16:01:25 -0700 | [diff] [blame] | 44 | ParsedOptions::ParsedOptions() |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 45 | : hook_is_sensitive_thread_(nullptr), |
Andreas Gampe | 313f403 | 2014-08-29 16:01:25 -0700 | [diff] [blame] | 46 | hook_vfprintf_(vfprintf), |
| 47 | hook_exit_(exit), |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 48 | hook_abort_(nullptr) { // We don't call abort(3) by default; see |
| 49 | // Runtime::Abort |
Hiroshi Yamauchi | 2cd334a | 2015-01-09 14:03:35 -0800 | [diff] [blame] | 50 | } |
Andreas Gampe | 313f403 | 2014-08-29 16:01:25 -0700 | [diff] [blame] | 51 | |
Vladimir Marko | 88b2b80 | 2015-12-04 14:19:04 +0000 | [diff] [blame] | 52 | bool ParsedOptions::Parse(const RuntimeOptions& options, |
| 53 | bool ignore_unrecognized, |
| 54 | RuntimeArgumentMap* runtime_options) { |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 55 | CHECK(runtime_options != nullptr); |
| 56 | |
Vladimir Marko | 88b2b80 | 2015-12-04 14:19:04 +0000 | [diff] [blame] | 57 | ParsedOptions parser; |
| 58 | return parser.DoParse(options, ignore_unrecognized, runtime_options); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 61 | using RuntimeParser = CmdlineParser<RuntimeArgumentMap, RuntimeArgumentMap::Key>; |
David Brazdil | 6dfdfef | 2019-04-11 17:39:11 +0100 | [diff] [blame] | 62 | using HiddenapiPolicyValueMap = |
| 63 | std::initializer_list<std::pair<const char*, hiddenapi::EnforcementPolicy>>; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 64 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 65 | // Yes, the stack frame is huge. But we get called super early on (and just once) |
| 66 | // to pass the command line arguments, so we'll probably be ok. |
| 67 | // Ideas to avoid suppressing this diagnostic are welcome! |
| 68 | #pragma GCC diagnostic push |
| 69 | #pragma GCC diagnostic ignored "-Wframe-larger-than=" |
| 70 | |
| 71 | std::unique_ptr<RuntimeParser> ParsedOptions::MakeParser(bool ignore_unrecognized) { |
| 72 | using M = RuntimeArgumentMap; |
| 73 | |
| 74 | std::unique_ptr<RuntimeParser::Builder> parser_builder = |
Yi Kong | c57c680 | 2018-10-29 14:28:56 -0700 | [diff] [blame] | 75 | std::make_unique<RuntimeParser::Builder>(); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 76 | |
David Brazdil | 6dfdfef | 2019-04-11 17:39:11 +0100 | [diff] [blame] | 77 | HiddenapiPolicyValueMap hiddenapi_policy_valuemap = |
| 78 | {{"disabled", hiddenapi::EnforcementPolicy::kDisabled}, |
| 79 | {"just-warn", hiddenapi::EnforcementPolicy::kJustWarn}, |
| 80 | {"enabled", hiddenapi::EnforcementPolicy::kEnabled}}; |
| 81 | DCHECK_EQ(hiddenapi_policy_valuemap.size(), |
| 82 | static_cast<size_t>(hiddenapi::EnforcementPolicy::kMax) + 1); |
| 83 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 84 | parser_builder-> |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 85 | SetCategory("standard") |
| 86 | .Define({"-classpath _", "-cp _"}) |
| 87 | .WithHelp("The classpath, separated by ':'") |
| 88 | .WithType<std::string>() |
| 89 | .IntoKey(M::ClassPath) |
| 90 | .Define("-D_") |
| 91 | .WithType<std::vector<std::string>>().AppendValues() |
| 92 | .IntoKey(M::PropertiesList) |
| 93 | .Define("-verbose:_") |
| 94 | .WithHelp("Switches for advanced logging. Multiple categories can be enabled separated by ','. Eg: -verbose:class,deopt") |
| 95 | .WithType<LogVerbosity>() |
| 96 | .IntoKey(M::Verbose) |
| 97 | .Define({"-help", "-h"}) |
| 98 | .WithHelp("Print this help text.") |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 99 | .IntoKey(M::Help) |
| 100 | .Define("-showversion") |
| 101 | .IntoKey(M::ShowVersion) |
Alex Light | 7233c7e | 2016-07-28 10:07:45 -0700 | [diff] [blame] | 102 | // TODO Re-enable -agentlib: once I have a good way to transform the values. |
| 103 | // .Define("-agentlib:_") |
| 104 | // .WithType<std::vector<ti::Agent>>().AppendValues() |
| 105 | // .IntoKey(M::AgentLib) |
| 106 | .Define("-agentpath:_") |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 107 | .WithHelp("Load native agents.") |
Andreas Gampe | aadcbc6 | 2017-12-28 14:05:42 -0800 | [diff] [blame] | 108 | .WithType<std::list<ti::AgentSpec>>().AppendValues() |
Alex Light | 7233c7e | 2016-07-28 10:07:45 -0700 | [diff] [blame] | 109 | .IntoKey(M::AgentPath) |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 110 | .SetCategory("extended") |
| 111 | .Define("-Xbootclasspath:_") |
| 112 | .WithType<ParseStringList<':'>>() // std::vector<std::string>, split by : |
| 113 | .IntoKey(M::BootClassPath) |
| 114 | .Define("-Xcheck:jni") |
| 115 | .IntoKey(M::CheckJni) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 116 | .Define("-Xms_") |
| 117 | .WithType<MemoryKiB>() |
| 118 | .IntoKey(M::MemoryInitialSize) |
| 119 | .Define("-Xmx_") |
| 120 | .WithType<MemoryKiB>() |
| 121 | .IntoKey(M::MemoryMaximumSize) |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 122 | .Define("-Xss_") |
| 123 | .WithType<Memory<1>>() |
| 124 | .IntoKey(M::StackSize) |
| 125 | .Define("-Xint") |
| 126 | .WithValue(true) |
| 127 | .IntoKey(M::Interpret) |
| 128 | .SetCategory("Dalvik") |
| 129 | .Define("-Xzygote") |
| 130 | .WithHelp("Start as zygote") |
| 131 | .IntoKey(M::Zygote) |
| 132 | .Define("-Xjnitrace:_") |
| 133 | .WithType<std::string>() |
| 134 | .IntoKey(M::JniTrace) |
| 135 | .Define("-Xgc:_") |
| 136 | .WithType<XGcOption>() |
| 137 | .IntoKey(M::GcOption) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 138 | .Define("-XX:HeapGrowthLimit=_") |
| 139 | .WithType<MemoryKiB>() |
| 140 | .IntoKey(M::HeapGrowthLimit) |
| 141 | .Define("-XX:HeapMinFree=_") |
| 142 | .WithType<MemoryKiB>() |
| 143 | .IntoKey(M::HeapMinFree) |
| 144 | .Define("-XX:HeapMaxFree=_") |
| 145 | .WithType<MemoryKiB>() |
| 146 | .IntoKey(M::HeapMaxFree) |
| 147 | .Define("-XX:NonMovingSpaceCapacity=_") |
| 148 | .WithType<MemoryKiB>() |
| 149 | .IntoKey(M::NonMovingSpaceCapacity) |
| 150 | .Define("-XX:HeapTargetUtilization=_") |
| 151 | .WithType<double>().WithRange(0.1, 0.9) |
| 152 | .IntoKey(M::HeapTargetUtilization) |
| 153 | .Define("-XX:ForegroundHeapGrowthMultiplier=_") |
Mathieu Chartier | 11c273d | 2017-10-15 20:54:45 -0700 | [diff] [blame] | 154 | .WithType<double>().WithRange(0.1, 5.0) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 155 | .IntoKey(M::ForegroundHeapGrowthMultiplier) |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 156 | .Define("-XX:LowMemoryMode") |
| 157 | .IntoKey(M::LowMemoryMode) |
| 158 | .Define("-Xprofile:_") |
| 159 | .WithType<TraceClockSource>() |
| 160 | .WithValueMap({{"threadcpuclock", TraceClockSource::kThreadCpu}, |
| 161 | {"wallclock", TraceClockSource::kWall}, |
| 162 | {"dualclock", TraceClockSource::kDual}}) |
| 163 | .IntoKey(M::ProfileClock) |
| 164 | .Define("-Xjitthreshold:_") |
| 165 | .WithType<unsigned int>() |
| 166 | .IntoKey(M::JITCompileThreshold) |
| 167 | .SetCategory("ART") |
| 168 | .Define("-Ximage:_") |
| 169 | .WithType<std::string>() |
| 170 | .IntoKey(M::Image) |
| 171 | .Define("-Xprimaryzygote") |
| 172 | .IntoKey(M::PrimaryZygote) |
| 173 | .Define("-Xbootclasspath-locations:_") |
| 174 | .WithType<ParseStringList<':'>>() // std::vector<std::string>, split by : |
| 175 | .IntoKey(M::BootClassPathLocations) |
| 176 | .Define("-Ximage-load-order:_") |
| 177 | .WithType<gc::space::ImageSpaceLoadingOrder>() |
| 178 | .WithValueMap({{"system", gc::space::ImageSpaceLoadingOrder::kSystemFirst}, |
| 179 | {"data", gc::space::ImageSpaceLoadingOrder::kDataFirst}}) |
| 180 | .IntoKey(M::ImageSpaceLoadingOrder) |
| 181 | .Define("-Xjniopts:forcecopy") |
| 182 | .IntoKey(M::JniOptsForceCopy) |
| 183 | .Define("-XjdwpProvider:_") |
| 184 | .WithType<JdwpProvider>() |
| 185 | .IntoKey(M::JdwpProvider) |
| 186 | .Define("-XjdwpOptions:_") |
| 187 | .WithMetavar("OPTION[,OPTION...]") |
| 188 | .WithHelp("JDWP options. Eg suspend=n,server=y.") |
| 189 | .WithType<std::string>() |
| 190 | .IntoKey(M::JdwpOptions) |
| 191 | .Define("-XX:StopForNativeAllocs=_") |
| 192 | .WithType<MemoryKiB>() |
| 193 | .IntoKey(M::StopForNativeAllocs) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 194 | .Define("-XX:ParallelGCThreads=_") |
| 195 | .WithType<unsigned int>() |
| 196 | .IntoKey(M::ParallelGCThreads) |
| 197 | .Define("-XX:ConcGCThreads=_") |
| 198 | .WithType<unsigned int>() |
| 199 | .IntoKey(M::ConcGCThreads) |
Hans Boehm | b215557 | 2019-03-27 14:25:53 -0700 | [diff] [blame] | 200 | .Define("-XX:FinalizerTimeoutMs=_") |
| 201 | .WithType<unsigned int>() |
| 202 | .IntoKey(M::FinalizerTimeoutMs) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 203 | .Define("-XX:MaxSpinsBeforeThinLockInflation=_") |
| 204 | .WithType<unsigned int>() |
| 205 | .IntoKey(M::MaxSpinsBeforeThinLockInflation) |
| 206 | .Define("-XX:LongPauseLogThreshold=_") // in ms |
| 207 | .WithType<MillisecondsToNanoseconds>() // store as ns |
| 208 | .IntoKey(M::LongPauseLogThreshold) |
| 209 | .Define("-XX:LongGCLogThreshold=_") // in ms |
| 210 | .WithType<MillisecondsToNanoseconds>() // store as ns |
| 211 | .IntoKey(M::LongGCLogThreshold) |
| 212 | .Define("-XX:DumpGCPerformanceOnShutdown") |
| 213 | .IntoKey(M::DumpGCPerformanceOnShutdown) |
Albert Mingkun Yang | de94ea7 | 2018-11-16 10:15:49 +0000 | [diff] [blame] | 214 | .Define("-XX:DumpRegionInfoBeforeGC") |
| 215 | .IntoKey(M::DumpRegionInfoBeforeGC) |
| 216 | .Define("-XX:DumpRegionInfoAfterGC") |
| 217 | .IntoKey(M::DumpRegionInfoAfterGC) |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 218 | .Define("-XX:DumpJITInfoOnShutdown") |
| 219 | .IntoKey(M::DumpJITInfoOnShutdown) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 220 | .Define("-XX:IgnoreMaxFootprint") |
| 221 | .IntoKey(M::IgnoreMaxFootprint) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 222 | .Define("-XX:UseTLAB") |
Hiroshi Yamauchi | f360ad0 | 2015-02-20 11:28:03 -0800 | [diff] [blame] | 223 | .WithValue(true) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 224 | .IntoKey(M::UseTLAB) |
| 225 | .Define({"-XX:EnableHSpaceCompactForOOM", "-XX:DisableHSpaceCompactForOOM"}) |
| 226 | .WithValues({true, false}) |
| 227 | .IntoKey(M::EnableHSpaceCompactForOOM) |
Nicolas Geoffray | 6ee4971 | 2018-03-30 14:39:05 +0000 | [diff] [blame] | 228 | .Define("-XX:DumpNativeStackOnSigQuit:_") |
| 229 | .WithType<bool>() |
| 230 | .WithValueMap({{"false", false}, {"true", true}}) |
| 231 | .IntoKey(M::DumpNativeStackOnSigQuit) |
Mathieu Chartier | c42cb0e | 2017-10-13 11:35:00 -0700 | [diff] [blame] | 232 | .Define("-XX:MadviseRandomAccess:_") |
| 233 | .WithType<bool>() |
| 234 | .WithValueMap({{"false", false}, {"true", true}}) |
| 235 | .IntoKey(M::MadviseRandomAccess) |
Mathieu Chartier | 1972a8e | 2015-03-05 17:12:54 -0800 | [diff] [blame] | 236 | .Define("-Xusejit:_") |
| 237 | .WithType<bool>() |
| 238 | .WithValueMap({{"false", false}, {"true", true}}) |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 239 | .IntoKey(M::UseJitCompilation) |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 240 | .Define("-Xusetieredjit:_") |
| 241 | .WithType<bool>() |
| 242 | .WithValueMap({{"false", false}, {"true", true}}) |
| 243 | .IntoKey(M::UseTieredJitCompilation) |
Nicolas Geoffray | 5678229 | 2015-11-19 14:25:43 +0000 | [diff] [blame] | 244 | .Define("-Xjitinitialsize:_") |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 245 | .WithType<MemoryKiB>() |
Nicolas Geoffray | 0a3be16 | 2015-11-18 11:15:22 +0000 | [diff] [blame] | 246 | .IntoKey(M::JITCodeCacheInitialCapacity) |
Nicolas Geoffray | 5678229 | 2015-11-19 14:25:43 +0000 | [diff] [blame] | 247 | .Define("-Xjitmaxsize:_") |
Nicolas Geoffray | 0a3be16 | 2015-11-18 11:15:22 +0000 | [diff] [blame] | 248 | .WithType<MemoryKiB>() |
| 249 | .IntoKey(M::JITCodeCacheMaxCapacity) |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 250 | .Define("-Xjitwarmupthreshold:_") |
| 251 | .WithType<unsigned int>() |
| 252 | .IntoKey(M::JITWarmupThreshold) |
Nicolas Geoffray | 83f080a | 2016-03-08 16:50:21 +0000 | [diff] [blame] | 253 | .Define("-Xjitosrthreshold:_") |
| 254 | .WithType<unsigned int>() |
| 255 | .IntoKey(M::JITOsrThreshold) |
Calin Juravle | b2771b4 | 2016-04-07 17:09:25 +0100 | [diff] [blame] | 256 | .Define("-Xjitprithreadweight:_") |
| 257 | .WithType<unsigned int>() |
| 258 | .IntoKey(M::JITPriorityThreadWeight) |
Calin Juravle | 155ff3d | 2016-04-27 14:14:58 +0100 | [diff] [blame] | 259 | .Define("-Xjittransitionweight:_") |
| 260 | .WithType<unsigned int>() |
| 261 | .IntoKey(M::JITInvokeTransitionWeight) |
Nicolas Geoffray | 47b9580 | 2018-05-16 15:42:17 +0100 | [diff] [blame] | 262 | .Define("-Xjitpthreadpriority:_") |
| 263 | .WithType<int>() |
| 264 | .IntoKey(M::JITPoolThreadPthreadPriority) |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 265 | .Define("-Xjitsaveprofilinginfo") |
Calin Juravle | 138dbff | 2016-06-28 19:36:58 +0100 | [diff] [blame] | 266 | .WithType<ProfileSaverOptions>() |
| 267 | .AppendValues() |
| 268 | .IntoKey(M::ProfileSaverOpts) |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 269 | // .Define("-Xps-_") // profile saver options -Xps-<key>:<value> |
| 270 | // .WithType<ProfileSaverOptions>() |
| 271 | // .AppendValues() |
| 272 | // .IntoKey(M::ProfileSaverOpts) // NOTE: Appends into same key as -Xjitsaveprofilinginfo |
| 273 | // profile saver options -Xps-<key>:<value> but are split-out for better help messages. |
| 274 | // The order of these is important. We want the wildcard one to be the |
| 275 | // only one actually matched so it needs to be first. |
| 276 | // TODO This should be redone. |
| 277 | .Define({"-Xps-_", |
| 278 | "-Xps-min-save-period-ms:_", |
| 279 | "-Xps-save-resolved-classes-delayed-ms:_", |
| 280 | "-Xps-hot-startup-method-samples:_", |
| 281 | "-Xps-min-methods-to-save:_", |
| 282 | "-Xps-min-classes-to-save:_", |
| 283 | "-Xps-min-notification-before-wake:_", |
| 284 | "-Xps-max-notification-before-wake:_", |
| 285 | "-Xps-profile-path:_"}) |
| 286 | .WithHelp("profile-saver options -Xps-<key>:<value>") |
Calin Juravle | 138dbff | 2016-06-28 19:36:58 +0100 | [diff] [blame] | 287 | .WithType<ProfileSaverOptions>() |
| 288 | .AppendValues() |
| 289 | .IntoKey(M::ProfileSaverOpts) // NOTE: Appends into same key as -Xjitsaveprofilinginfo |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 290 | .Define("-XX:HspaceCompactForOOMMinIntervalMs=_") // in ms |
| 291 | .WithType<MillisecondsToNanoseconds>() // store as ns |
| 292 | .IntoKey(M::HSpaceCompactForOOMMinIntervalsMs) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 293 | .Define({"-Xrelocate", "-Xnorelocate"}) |
| 294 | .WithValues({true, false}) |
| 295 | .IntoKey(M::Relocate) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 296 | .Define({"-Ximage-dex2oat", "-Xnoimage-dex2oat"}) |
| 297 | .WithValues({true, false}) |
| 298 | .IntoKey(M::ImageDex2Oat) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 299 | .Define("-XX:LargeObjectSpace=_") |
| 300 | .WithType<gc::space::LargeObjectSpaceType>() |
| 301 | .WithValueMap({{"disabled", gc::space::LargeObjectSpaceType::kDisabled}, |
| 302 | {"freelist", gc::space::LargeObjectSpaceType::kFreeList}, |
| 303 | {"map", gc::space::LargeObjectSpaceType::kMap}}) |
| 304 | .IntoKey(M::LargeObjectSpace) |
| 305 | .Define("-XX:LargeObjectThreshold=_") |
| 306 | .WithType<Memory<1>>() |
| 307 | .IntoKey(M::LargeObjectThreshold) |
| 308 | .Define("-XX:BackgroundGC=_") |
| 309 | .WithType<BackgroundGcOption>() |
| 310 | .IntoKey(M::BackgroundGc) |
| 311 | .Define("-XX:+DisableExplicitGC") |
| 312 | .IntoKey(M::DisableExplicitGC) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 313 | .Define("-Xlockprofthreshold:_") |
| 314 | .WithType<unsigned int>() |
| 315 | .IntoKey(M::LockProfThreshold) |
Andreas Gampe | d0210e5 | 2017-06-23 13:38:09 -0700 | [diff] [blame] | 316 | .Define("-Xstackdumplockprofthreshold:_") |
| 317 | .WithType<unsigned int>() |
| 318 | .IntoKey(M::StackDumpLockProfThreshold) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 319 | .Define("-Xmethod-trace") |
| 320 | .IntoKey(M::MethodTrace) |
| 321 | .Define("-Xmethod-trace-file:_") |
| 322 | .WithType<std::string>() |
| 323 | .IntoKey(M::MethodTraceFile) |
| 324 | .Define("-Xmethod-trace-file-size:_") |
| 325 | .WithType<unsigned int>() |
| 326 | .IntoKey(M::MethodTraceFileSize) |
Andreas Gampe | 40da286 | 2015-02-27 12:49:04 -0800 | [diff] [blame] | 327 | .Define("-Xmethod-trace-stream") |
| 328 | .IntoKey(M::MethodTraceStreaming) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 329 | .Define("-Xcompiler:_") |
| 330 | .WithType<std::string>() |
| 331 | .IntoKey(M::Compiler) |
| 332 | .Define("-Xcompiler-option _") |
| 333 | .WithType<std::vector<std::string>>() |
| 334 | .AppendValues() |
| 335 | .IntoKey(M::CompilerOptions) |
| 336 | .Define("-Ximage-compiler-option _") |
| 337 | .WithType<std::vector<std::string>>() |
| 338 | .AppendValues() |
| 339 | .IntoKey(M::ImageCompilerOptions) |
| 340 | .Define("-Xverify:_") |
Igor Murashkin | 7617abd | 2015-07-10 18:27:47 -0700 | [diff] [blame] | 341 | .WithType<verifier::VerifyMode>() |
| 342 | .WithValueMap({{"none", verifier::VerifyMode::kNone}, |
| 343 | {"remote", verifier::VerifyMode::kEnable}, |
| 344 | {"all", verifier::VerifyMode::kEnable}, |
| 345 | {"softfail", verifier::VerifyMode::kSoftFail}}) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 346 | .IntoKey(M::Verify) |
| 347 | .Define("-XX:NativeBridge=_") |
| 348 | .WithType<std::string>() |
| 349 | .IntoKey(M::NativeBridge) |
Andreas Gampe | 9106e52 | 2015-03-31 14:54:03 -0700 | [diff] [blame] | 350 | .Define("-Xzygote-max-boot-retry=_") |
Narayan Kamath | 5a2be3f | 2015-02-16 13:51:51 +0000 | [diff] [blame] | 351 | .WithType<unsigned int>() |
| 352 | .IntoKey(M::ZygoteMaxFailedBoots) |
Calin Juravle | 01aaf6e | 2015-06-19 22:05:39 +0100 | [diff] [blame] | 353 | .Define("-Xno-sig-chain") |
| 354 | .IntoKey(M::NoSigChain) |
Dmitriy Ivanov | 785049f | 2014-07-18 10:08:57 -0700 | [diff] [blame] | 355 | .Define("--cpu-abilist=_") |
| 356 | .WithType<std::string>() |
| 357 | .IntoKey(M::CpuAbiList) |
Andreas Gampe | dd67125 | 2015-07-23 14:37:18 -0700 | [diff] [blame] | 358 | .Define("-Xfingerprint:_") |
| 359 | .WithType<std::string>() |
| 360 | .IntoKey(M::Fingerprint) |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 361 | .Define("-Xexperimental:_") |
| 362 | .WithType<ExperimentalFlags>() |
| 363 | .AppendValues() |
| 364 | .IntoKey(M::Experimental) |
Calin Juravle | d3e7c6c | 2016-02-04 19:07:51 +0000 | [diff] [blame] | 365 | .Define("-Xforce-nb-testing") |
| 366 | .IntoKey(M::ForceNativeBridge) |
Alex Light | 185d134 | 2016-08-11 10:48:03 -0700 | [diff] [blame] | 367 | .Define("-Xplugin:_") |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 368 | .WithHelp("Load and initialize the specified art-plugin.") |
Alex Light | 185d134 | 2016-08-11 10:48:03 -0700 | [diff] [blame] | 369 | .WithType<std::vector<Plugin>>().AppendValues() |
| 370 | .IntoKey(M::Plugins) |
Mathieu Chartier | 3fceaf5 | 2017-01-22 13:33:40 -0800 | [diff] [blame] | 371 | .Define("-XX:ThreadSuspendTimeout=_") // in ms |
| 372 | .WithType<MillisecondsToNanoseconds>() // store as ns |
| 373 | .IntoKey(M::ThreadSuspendTimeout) |
Andreas Gampe | 1b35b46 | 2017-09-29 18:52:15 -0700 | [diff] [blame] | 374 | .Define("-XX:GlobalRefAllocStackTraceLimit=_") // Number of free slots to enable tracing. |
| 375 | .WithType<unsigned int>() |
| 376 | .IntoKey(M::GlobalRefAllocStackTraceLimit) |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 377 | .Define("-XX:SlowDebug=_") |
| 378 | .WithType<bool>() |
| 379 | .WithValueMap({{"false", false}, {"true", true}}) |
| 380 | .IntoKey(M::SlowDebug) |
David Brazdil | a7db026 | 2018-01-16 17:13:35 +0000 | [diff] [blame] | 381 | .Define("-Xtarget-sdk-version:_") |
David Brazdil | 2bb2fbd | 2018-11-13 18:24:26 +0000 | [diff] [blame] | 382 | .WithType<unsigned int>() |
David Brazdil | a7db026 | 2018-01-16 17:13:35 +0000 | [diff] [blame] | 383 | .IntoKey(M::TargetSdkVersion) |
David Brazdil | 6dfdfef | 2019-04-11 17:39:11 +0100 | [diff] [blame] | 384 | .Define("-Xhidden-api-policy:_") |
| 385 | .WithType<hiddenapi::EnforcementPolicy>() |
| 386 | .WithValueMap(hiddenapi_policy_valuemap) |
| 387 | .IntoKey(M::HiddenApiPolicy) |
| 388 | .Define("-Xcore-platform-api-policy:_") |
| 389 | .WithType<hiddenapi::EnforcementPolicy>() |
| 390 | .WithValueMap(hiddenapi_policy_valuemap) |
| 391 | .IntoKey(M::CorePlatformApiPolicy) |
Andreas Gampe | 25419b5 | 2018-02-08 21:30:26 -0800 | [diff] [blame] | 392 | .Define("-Xuse-stderr-logger") |
| 393 | .IntoKey(M::UseStderrLogger) |
Nicolas Geoffray | 66ff8a8 | 2018-02-28 13:27:55 +0000 | [diff] [blame] | 394 | .Define("-Xonly-use-system-oat-files") |
| 395 | .IntoKey(M::OnlyUseSystemOatFiles) |
Andreas Gampe | 0b0ffc1 | 2018-08-01 14:41:27 -0700 | [diff] [blame] | 396 | .Define("-Xverifier-logging-threshold=_") |
| 397 | .WithType<unsigned int>() |
| 398 | .IntoKey(M::VerifierLoggingThreshold) |
Andreas Gampe | 87658f3 | 2019-04-18 18:39:02 +0000 | [diff] [blame] | 399 | .Define("-XX:FastClassNotFoundException=_") |
| 400 | .WithType<bool>() |
| 401 | .WithValueMap({{"false", false}, {"true", true}}) |
| 402 | .IntoKey(M::FastClassNotFoundException) |
Alex Light | 79d6c80 | 2019-06-27 15:50:11 +0000 | [diff] [blame] | 403 | .Define("-Xopaque-jni-ids:_") |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 404 | .WithHelp("Control the representation of jmethodID and jfieldID values") |
Alex Light | f367747 | 2019-06-26 16:31:53 -0700 | [diff] [blame] | 405 | .WithType<JniIdType>() |
| 406 | .WithValueMap({{"true", JniIdType::kIndices}, |
| 407 | {"false", JniIdType::kPointer}, |
| 408 | {"swapable", JniIdType::kSwapablePointer}, |
| 409 | {"pointer", JniIdType::kPointer}, |
| 410 | {"indices", JniIdType::kIndices}, |
| 411 | {"default", JniIdType::kDefault}}) |
Alex Light | 79d6c80 | 2019-06-27 15:50:11 +0000 | [diff] [blame] | 412 | .IntoKey(M::OpaqueJniIds) |
Alex Light | 4ca2f48 | 2019-11-25 16:07:22 -0800 | [diff] [blame] | 413 | .Define("-Xauto-promote-opaque-jni-ids:_") |
| 414 | .WithType<bool>() |
| 415 | .WithValueMap({{"true", true}, {"false", false}}) |
| 416 | .IntoKey(M::AutoPromoteOpaqueJniIds) |
Andreas Gampe | d84794d | 2019-07-18 13:40:03 -0700 | [diff] [blame] | 417 | .Define("-XX:VerifierMissingKThrowFatal=_") |
| 418 | .WithType<bool>() |
| 419 | .WithValueMap({{"false", false}, {"true", true}}) |
| 420 | .IntoKey(M::VerifierMissingKThrowFatal) |
Florian Mayer | 0972d08 | 2020-05-15 14:07:31 +0200 | [diff] [blame] | 421 | .Define("-XX:PerfettoHprof=_") |
| 422 | .WithType<bool>() |
| 423 | .WithValueMap({{"false", false}, {"true", true}}) |
| 424 | .IntoKey(M::PerfettoHprof) |
Ulyana Trafimovich | e886d68 | 2020-07-16 15:09:38 +0000 | [diff] [blame^] | 425 | .Define("--simulate-isa=_") |
| 426 | .WithType<InstructionSet>() |
| 427 | .WithValueMap({{"none", InstructionSet::kNone}, |
| 428 | {"arm64", InstructionSet::kArm64}}) |
| 429 | .IntoKey(M::SimulateInstructionSet) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 430 | .Ignore({ |
| 431 | "-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa", |
| 432 | "-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:_", |
| 433 | "-Xdexopt:_", "-Xnoquithandler", "-Xjnigreflimit:_", "-Xgenregmap", "-Xnogenregmap", |
| 434 | "-Xverifyopt:_", "-Xcheckdexsum", "-Xincludeselectedop", "-Xjitop:_", |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 435 | "-Xincludeselectedmethod", |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 436 | "-Xjitblocking", "-Xjitmethod:_", "-Xjitclass:_", "-Xjitoffset:_", |
| 437 | "-Xjitconfig:_", "-Xjitcheckcg", "-Xjitverbose", "-Xjitprofile", |
| 438 | "-Xjitdisableopt", "-Xjitsuspendpoll", "-XX:mainThreadStackSize=_"}) |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 439 | .IgnoreUnrecognized(ignore_unrecognized) |
| 440 | .OrderCategories({"standard", "extended", "Dalvik", "ART"}); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 441 | |
| 442 | // TODO: Move Usage information into this DSL. |
| 443 | |
Yi Kong | c57c680 | 2018-10-29 14:28:56 -0700 | [diff] [blame] | 444 | return std::make_unique<RuntimeParser>(parser_builder->Build()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 447 | #pragma GCC diagnostic pop |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 448 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 449 | // Remove all the special options that have something in the void* part of the option. |
| 450 | // If runtime_options is not null, put the options in there. |
| 451 | // As a side-effect, populate the hooks from options. |
| 452 | bool ParsedOptions::ProcessSpecialOptions(const RuntimeOptions& options, |
| 453 | RuntimeArgumentMap* runtime_options, |
| 454 | std::vector<std::string>* out_options) { |
| 455 | using M = RuntimeArgumentMap; |
| 456 | |
| 457 | // TODO: Move the below loop into JNI |
| 458 | // Handle special options that set up hooks |
| 459 | for (size_t i = 0; i < options.size(); ++i) { |
| 460 | const std::string option(options[i].first); |
| 461 | // TODO: support -Djava.class.path |
| 462 | if (option == "bootclasspath") { |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 463 | auto boot_class_path = static_cast<std::vector<std::unique_ptr<const DexFile>>*>( |
| 464 | const_cast<void*>(options[i].second)); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 465 | |
| 466 | if (runtime_options != nullptr) { |
| 467 | runtime_options->Set(M::BootClassPathDexList, boot_class_path); |
| 468 | } |
| 469 | } else if (option == "compilercallbacks") { |
| 470 | CompilerCallbacks* compiler_callbacks = |
| 471 | reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second)); |
| 472 | if (runtime_options != nullptr) { |
| 473 | runtime_options->Set(M::CompilerCallbacksPtr, compiler_callbacks); |
| 474 | } |
| 475 | } else if (option == "imageinstructionset") { |
| 476 | const char* isa_str = reinterpret_cast<const char*>(options[i].second); |
| 477 | auto&& image_isa = GetInstructionSetFromString(isa_str); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 478 | if (image_isa == InstructionSet::kNone) { |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 479 | Usage("%s is not a valid instruction set.", isa_str); |
| 480 | return false; |
| 481 | } |
| 482 | if (runtime_options != nullptr) { |
| 483 | runtime_options->Set(M::ImageInstructionSet, image_isa); |
| 484 | } |
| 485 | } else if (option == "sensitiveThread") { |
| 486 | const void* hook = options[i].second; |
| 487 | bool (*hook_is_sensitive_thread)() = reinterpret_cast<bool (*)()>(const_cast<void*>(hook)); |
| 488 | |
| 489 | if (runtime_options != nullptr) { |
| 490 | runtime_options->Set(M::HookIsSensitiveThread, hook_is_sensitive_thread); |
| 491 | } |
| 492 | } else if (option == "vfprintf") { |
| 493 | const void* hook = options[i].second; |
| 494 | if (hook == nullptr) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 495 | Usage("vfprintf argument was nullptr"); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 496 | return false; |
| 497 | } |
| 498 | int (*hook_vfprintf)(FILE *, const char*, va_list) = |
| 499 | reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook)); |
| 500 | |
| 501 | if (runtime_options != nullptr) { |
| 502 | runtime_options->Set(M::HookVfprintf, hook_vfprintf); |
| 503 | } |
| 504 | hook_vfprintf_ = hook_vfprintf; |
| 505 | } else if (option == "exit") { |
| 506 | const void* hook = options[i].second; |
| 507 | if (hook == nullptr) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 508 | Usage("exit argument was nullptr"); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 509 | return false; |
| 510 | } |
| 511 | void(*hook_exit)(jint) = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook)); |
| 512 | if (runtime_options != nullptr) { |
| 513 | runtime_options->Set(M::HookExit, hook_exit); |
| 514 | } |
| 515 | hook_exit_ = hook_exit; |
| 516 | } else if (option == "abort") { |
| 517 | const void* hook = options[i].second; |
| 518 | if (hook == nullptr) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 519 | Usage("abort was nullptr\n"); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 520 | return false; |
| 521 | } |
| 522 | void(*hook_abort)() = reinterpret_cast<void(*)()>(const_cast<void*>(hook)); |
| 523 | if (runtime_options != nullptr) { |
| 524 | runtime_options->Set(M::HookAbort, hook_abort); |
| 525 | } |
| 526 | hook_abort_ = hook_abort; |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 527 | } else { |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 528 | // It is a regular option, that doesn't have a known 'second' value. |
| 529 | // Push it on to the regular options which will be parsed by our parser. |
| 530 | if (out_options != nullptr) { |
| 531 | out_options->push_back(option); |
| 532 | } |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 535 | |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 536 | return true; |
| 537 | } |
| 538 | |
Sebastien Hertz | bba348e | 2015-06-01 08:28:18 +0200 | [diff] [blame] | 539 | // Intended for local changes only. |
| 540 | static void MaybeOverrideVerbosity() { |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 541 | // gLogVerbosity.class_linker = true; // TODO: don't check this in! |
Mathieu Chartier | 66a5539 | 2016-02-19 10:25:39 -0800 | [diff] [blame] | 542 | // gLogVerbosity.collector = true; // TODO: don't check this in! |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 543 | // gLogVerbosity.compiler = true; // TODO: don't check this in! |
Sebastien Hertz | bba348e | 2015-06-01 08:28:18 +0200 | [diff] [blame] | 544 | // gLogVerbosity.deopt = true; // TODO: don't check this in! |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 545 | // gLogVerbosity.gc = true; // TODO: don't check this in! |
| 546 | // gLogVerbosity.heap = true; // TODO: don't check this in! |
Mathieu Chartier | 765b2a0 | 2019-05-02 11:04:13 -0700 | [diff] [blame] | 547 | // gLogVerbosity.interpreter = true; // TODO: don't check this in! |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 548 | // gLogVerbosity.jdwp = true; // TODO: don't check this in! |
| 549 | // gLogVerbosity.jit = true; // TODO: don't check this in! |
| 550 | // gLogVerbosity.jni = true; // TODO: don't check this in! |
| 551 | // gLogVerbosity.monitor = true; // TODO: don't check this in! |
Sebastien Hertz | bba348e | 2015-06-01 08:28:18 +0200 | [diff] [blame] | 552 | // gLogVerbosity.oat = true; // TODO: don't check this in! |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 553 | // gLogVerbosity.profiler = true; // TODO: don't check this in! |
| 554 | // gLogVerbosity.signals = true; // TODO: don't check this in! |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 555 | // gLogVerbosity.simulator = true; // TODO: don't check this in! |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 556 | // gLogVerbosity.startup = true; // TODO: don't check this in! |
| 557 | // gLogVerbosity.third_party_jni = true; // TODO: don't check this in! |
| 558 | // gLogVerbosity.threads = true; // TODO: don't check this in! |
| 559 | // gLogVerbosity.verifier = true; // TODO: don't check this in! |
Sebastien Hertz | bba348e | 2015-06-01 08:28:18 +0200 | [diff] [blame] | 560 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 561 | |
Vladimir Marko | 88b2b80 | 2015-12-04 14:19:04 +0000 | [diff] [blame] | 562 | bool ParsedOptions::DoParse(const RuntimeOptions& options, |
| 563 | bool ignore_unrecognized, |
| 564 | RuntimeArgumentMap* runtime_options) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 565 | for (size_t i = 0; i < options.size(); ++i) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 566 | if (true && options[0].first == "-Xzygote") { |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 567 | LOG(INFO) << "option[" << i << "]=" << options[i].first; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 568 | } |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 569 | } |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 570 | |
| 571 | auto parser = MakeParser(ignore_unrecognized); |
| 572 | |
| 573 | // Convert to a simple string list (without the magic pointer options) |
| 574 | std::vector<std::string> argv_list; |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 575 | if (!ProcessSpecialOptions(options, nullptr, &argv_list)) { |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 576 | return false; |
| 577 | } |
| 578 | |
| 579 | CmdlineResult parse_result = parser->Parse(argv_list); |
| 580 | |
| 581 | // Handle parse errors by displaying the usage and potentially exiting. |
| 582 | if (parse_result.IsError()) { |
| 583 | if (parse_result.GetStatus() == CmdlineResult::kUsage) { |
| 584 | UsageMessage(stdout, "%s\n", parse_result.GetMessage().c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 585 | Exit(0); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 586 | } else if (parse_result.GetStatus() == CmdlineResult::kUnknown && !ignore_unrecognized) { |
| 587 | Usage("%s\n", parse_result.GetMessage().c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 588 | return false; |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 589 | } else { |
| 590 | Usage("%s\n", parse_result.GetMessage().c_str()); |
| 591 | Exit(0); |
| 592 | } |
| 593 | |
| 594 | UNREACHABLE(); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | using M = RuntimeArgumentMap; |
| 598 | RuntimeArgumentMap args = parser->ReleaseArgumentsMap(); |
| 599 | |
| 600 | // -help, -showversion, etc. |
| 601 | if (args.Exists(M::Help)) { |
| 602 | Usage(nullptr); |
| 603 | return false; |
| 604 | } else if (args.Exists(M::ShowVersion)) { |
Calin Juravle | 4707af8 | 2017-04-13 16:35:42 -0700 | [diff] [blame] | 605 | UsageMessage(stdout, |
| 606 | "ART version %s %s\n", |
| 607 | Runtime::GetVersion(), |
| 608 | GetInstructionSetString(kRuntimeISA)); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 609 | Exit(0); |
| 610 | } else if (args.Exists(M::BootClassPath)) { |
Vladimir Marko | 91f1032 | 2018-12-07 18:04:10 +0000 | [diff] [blame] | 611 | LOG(INFO) << "setting boot class path to " << args.Get(M::BootClassPath)->Join(); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 612 | } |
| 613 | |
Nicolas Geoffray | a5ca8eb | 2018-08-24 13:39:13 +0100 | [diff] [blame] | 614 | if (args.GetOrDefault(M::Interpret)) { |
| 615 | if (args.Exists(M::UseJitCompilation) && *args.Get(M::UseJitCompilation)) { |
| 616 | Usage("-Xusejit:true and -Xint cannot be specified together\n"); |
| 617 | Exit(0); |
| 618 | } |
| 619 | args.Set(M::UseJitCompilation, false); |
Calin Juravle | af36e49 | 2016-04-27 18:50:45 +0100 | [diff] [blame] | 620 | } |
| 621 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 622 | // Set a default boot class path if we didn't get an explicit one via command line. |
Vladimir Marko | 91f1032 | 2018-12-07 18:04:10 +0000 | [diff] [blame] | 623 | const char* env_bcp = getenv("BOOTCLASSPATH"); |
| 624 | if (env_bcp != nullptr) { |
| 625 | args.SetIfMissing(M::BootClassPath, ParseStringList<':'>::Split(env_bcp)); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | // Set a default class path if we didn't get an explicit one via command line. |
| 629 | if (getenv("CLASSPATH") != nullptr) { |
| 630 | args.SetIfMissing(M::ClassPath, std::string(getenv("CLASSPATH"))); |
| 631 | } |
| 632 | |
| 633 | // Default to number of processors minus one since the main GC thread also does work. |
Mathieu Chartier | 10d6886 | 2015-04-15 14:21:33 -0700 | [diff] [blame] | 634 | args.SetIfMissing(M::ParallelGCThreads, gc::Heap::kDefaultEnableParallelGC ? |
| 635 | static_cast<unsigned int>(sysconf(_SC_NPROCESSORS_CONF) - 1u) : 0u); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 636 | |
Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 637 | // -verbose: |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 638 | { |
| 639 | LogVerbosity *log_verbosity = args.Get(M::Verbose); |
| 640 | if (log_verbosity != nullptr) { |
| 641 | gLogVerbosity = *log_verbosity; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 642 | } |
| 643 | } |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 644 | |
Sebastien Hertz | bba348e | 2015-06-01 08:28:18 +0200 | [diff] [blame] | 645 | MaybeOverrideVerbosity(); |
| 646 | |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 647 | SetRuntimeDebugFlagsEnabled(args.GetOrDefault(M::SlowDebug)); |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 648 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 649 | // -Xprofile: |
| 650 | Trace::SetDefaultClockSource(args.GetOrDefault(M::ProfileClock)); |
| 651 | |
| 652 | if (!ProcessSpecialOptions(options, &args, nullptr)) { |
| 653 | return false; |
| 654 | } |
| 655 | |
| 656 | { |
| 657 | // If not set, background collector type defaults to homogeneous compaction. |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 658 | // If not low memory mode, semispace otherwise. |
| 659 | |
| 660 | gc::CollectorType background_collector_type_; |
Igor Murashkin | 5573c37 | 2017-11-16 13:34:30 -0800 | [diff] [blame] | 661 | gc::CollectorType collector_type_ = (XGcOption{}).collector_type_; |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 662 | bool low_memory_mode_ = args.Exists(M::LowMemoryMode); |
| 663 | |
| 664 | background_collector_type_ = args.GetOrDefault(M::BackgroundGc); |
| 665 | { |
| 666 | XGcOption* xgc = args.Get(M::GcOption); |
| 667 | if (xgc != nullptr && xgc->collector_type_ != gc::kCollectorTypeNone) { |
| 668 | collector_type_ = xgc->collector_type_; |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | if (background_collector_type_ == gc::kCollectorTypeNone) { |
Mathieu Chartier | f75dce4 | 2019-04-08 09:36:23 -0700 | [diff] [blame] | 673 | background_collector_type_ = low_memory_mode_ ? |
| 674 | gc::kCollectorTypeSS : gc::kCollectorTypeHomogeneousSpaceCompact; |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | args.Set(M::BackgroundGc, BackgroundGcOption { background_collector_type_ }); |
Mathieu Chartier | 6b2352b | 2014-08-20 14:13:18 -0700 | [diff] [blame] | 678 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 679 | |
Vladimir Marko | 91f1032 | 2018-12-07 18:04:10 +0000 | [diff] [blame] | 680 | const ParseStringList<':'>* boot_class_path_locations = args.Get(M::BootClassPathLocations); |
| 681 | if (boot_class_path_locations != nullptr && boot_class_path_locations->Size() != 0u) { |
| 682 | const ParseStringList<':'>* boot_class_path = args.Get(M::BootClassPath); |
| 683 | if (boot_class_path == nullptr || |
| 684 | boot_class_path_locations->Size() != boot_class_path->Size()) { |
| 685 | Usage("The number of boot class path files does not match" |
| 686 | " the number of boot class path locations given\n" |
| 687 | " boot class path files (%zu): %s\n" |
| 688 | " boot class path locations (%zu): %s\n", |
| 689 | (boot_class_path != nullptr) ? boot_class_path->Size() : 0u, |
| 690 | (boot_class_path != nullptr) ? boot_class_path->Join().c_str() : "<nil>", |
| 691 | boot_class_path_locations->Size(), |
| 692 | boot_class_path_locations->Join().c_str()); |
| 693 | return false; |
Richard Uhler | c275259 | 2015-01-02 13:28:22 -0800 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 697 | if (!args.Exists(M::CompilerCallbacksPtr) && !args.Exists(M::Image)) { |
Nicolas Geoffray | de1b2a2 | 2019-02-27 09:10:57 +0000 | [diff] [blame] | 698 | std::string image = GetDefaultBootImageLocation(GetAndroidRoot()); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 699 | args.Set(M::Image, image); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 700 | } |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 701 | |
Lin Zang | 8cd63ab | 2015-11-06 14:08:51 +0800 | [diff] [blame] | 702 | // 0 means no growth limit, and growth limit should be always <= heap size |
| 703 | if (args.GetOrDefault(M::HeapGrowthLimit) <= 0u || |
| 704 | args.GetOrDefault(M::HeapGrowthLimit) > args.GetOrDefault(M::MemoryMaximumSize)) { |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 705 | args.Set(M::HeapGrowthLimit, args.GetOrDefault(M::MemoryMaximumSize)); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 706 | } |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 707 | |
| 708 | *runtime_options = std::move(args); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 709 | return true; |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 710 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 711 | |
| 712 | void ParsedOptions::Exit(int status) { |
| 713 | hook_exit_(status); |
| 714 | } |
| 715 | |
| 716 | void ParsedOptions::Abort() { |
| 717 | hook_abort_(); |
| 718 | } |
| 719 | |
| 720 | void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 721 | hook_vfprintf_(stream, fmt, ap); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) { |
| 725 | va_list ap; |
| 726 | va_start(ap, fmt); |
| 727 | UsageMessageV(stream, fmt, ap); |
| 728 | va_end(ap); |
| 729 | } |
| 730 | |
| 731 | void ParsedOptions::Usage(const char* fmt, ...) { |
| 732 | bool error = (fmt != nullptr); |
| 733 | FILE* stream = error ? stderr : stdout; |
| 734 | |
| 735 | if (fmt != nullptr) { |
| 736 | va_list ap; |
| 737 | va_start(ap, fmt); |
| 738 | UsageMessageV(stream, fmt, ap); |
| 739 | va_end(ap); |
| 740 | } |
| 741 | |
| 742 | const char* program = "dalvikvm"; |
| 743 | UsageMessage(stream, "%s: [options] class [argument ...]\n", program); |
| 744 | UsageMessage(stream, "\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 745 | |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 746 | std::stringstream oss; |
| 747 | VariableIndentationOutputStream vios(&oss); |
| 748 | auto parser = MakeParser(false); |
| 749 | parser->DumpHelp(vios); |
| 750 | UsageMessage(stream, oss.str().c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 751 | Exit((error) ? 1 : 0); |
| 752 | } |
| 753 | |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 754 | } // namespace art |