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) |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 176 | .Define("-Xjniopts:forcecopy") |
| 177 | .IntoKey(M::JniOptsForceCopy) |
| 178 | .Define("-XjdwpProvider:_") |
| 179 | .WithType<JdwpProvider>() |
| 180 | .IntoKey(M::JdwpProvider) |
| 181 | .Define("-XjdwpOptions:_") |
| 182 | .WithMetavar("OPTION[,OPTION...]") |
| 183 | .WithHelp("JDWP options. Eg suspend=n,server=y.") |
| 184 | .WithType<std::string>() |
| 185 | .IntoKey(M::JdwpOptions) |
| 186 | .Define("-XX:StopForNativeAllocs=_") |
| 187 | .WithType<MemoryKiB>() |
| 188 | .IntoKey(M::StopForNativeAllocs) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 189 | .Define("-XX:ParallelGCThreads=_") |
| 190 | .WithType<unsigned int>() |
| 191 | .IntoKey(M::ParallelGCThreads) |
| 192 | .Define("-XX:ConcGCThreads=_") |
| 193 | .WithType<unsigned int>() |
| 194 | .IntoKey(M::ConcGCThreads) |
Hans Boehm | b215557 | 2019-03-27 14:25:53 -0700 | [diff] [blame] | 195 | .Define("-XX:FinalizerTimeoutMs=_") |
| 196 | .WithType<unsigned int>() |
| 197 | .IntoKey(M::FinalizerTimeoutMs) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 198 | .Define("-XX:MaxSpinsBeforeThinLockInflation=_") |
| 199 | .WithType<unsigned int>() |
| 200 | .IntoKey(M::MaxSpinsBeforeThinLockInflation) |
| 201 | .Define("-XX:LongPauseLogThreshold=_") // in ms |
| 202 | .WithType<MillisecondsToNanoseconds>() // store as ns |
| 203 | .IntoKey(M::LongPauseLogThreshold) |
| 204 | .Define("-XX:LongGCLogThreshold=_") // in ms |
| 205 | .WithType<MillisecondsToNanoseconds>() // store as ns |
| 206 | .IntoKey(M::LongGCLogThreshold) |
| 207 | .Define("-XX:DumpGCPerformanceOnShutdown") |
| 208 | .IntoKey(M::DumpGCPerformanceOnShutdown) |
Albert Mingkun Yang | de94ea7 | 2018-11-16 10:15:49 +0000 | [diff] [blame] | 209 | .Define("-XX:DumpRegionInfoBeforeGC") |
| 210 | .IntoKey(M::DumpRegionInfoBeforeGC) |
| 211 | .Define("-XX:DumpRegionInfoAfterGC") |
| 212 | .IntoKey(M::DumpRegionInfoAfterGC) |
Mathieu Chartier | a4885cb | 2015-03-09 15:38:54 -0700 | [diff] [blame] | 213 | .Define("-XX:DumpJITInfoOnShutdown") |
| 214 | .IntoKey(M::DumpJITInfoOnShutdown) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 215 | .Define("-XX:IgnoreMaxFootprint") |
| 216 | .IntoKey(M::IgnoreMaxFootprint) |
Alex Light | b5a0e91 | 2020-07-23 10:54:47 -0700 | [diff] [blame] | 217 | .Define("-XX:AlwaysLogExplicitGcs:_") |
| 218 | .WithHelp("Allows one to control the logging of explicit GCs. Defaults to 'true'") |
| 219 | .WithType<bool>() |
| 220 | .WithValueMap({{"false", false}, {"true", true}}) |
| 221 | .IntoKey(M::AlwaysLogExplicitGcs) |
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 | 4bf753d | 2020-12-14 20:33:53 +0000 | [diff] [blame] | 240 | .Define("-Xuseprofiledjit:_") |
| 241 | .WithType<bool>() |
| 242 | .WithValueMap({{"false", false}, {"true", true}}) |
| 243 | .IntoKey(M::UseProfiledJitCompilation) |
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) |
Nicolas Geoffray | 4bf753d | 2020-12-14 20:33:53 +0000 | [diff] [blame] | 265 | .Define("-Xjitzygotepthreadpriority:_") |
| 266 | .WithType<int>() |
| 267 | .IntoKey(M::JITZygotePoolThreadPthreadPriority) |
Calin Juravle | 31f2c15 | 2015-10-23 17:56:15 +0100 | [diff] [blame] | 268 | .Define("-Xjitsaveprofilinginfo") |
Calin Juravle | 138dbff | 2016-06-28 19:36:58 +0100 | [diff] [blame] | 269 | .WithType<ProfileSaverOptions>() |
| 270 | .AppendValues() |
| 271 | .IntoKey(M::ProfileSaverOpts) |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 272 | // .Define("-Xps-_") // profile saver options -Xps-<key>:<value> |
| 273 | // .WithType<ProfileSaverOptions>() |
| 274 | // .AppendValues() |
| 275 | // .IntoKey(M::ProfileSaverOpts) // NOTE: Appends into same key as -Xjitsaveprofilinginfo |
| 276 | // profile saver options -Xps-<key>:<value> but are split-out for better help messages. |
| 277 | // The order of these is important. We want the wildcard one to be the |
| 278 | // only one actually matched so it needs to be first. |
| 279 | // TODO This should be redone. |
| 280 | .Define({"-Xps-_", |
| 281 | "-Xps-min-save-period-ms:_", |
| 282 | "-Xps-save-resolved-classes-delayed-ms:_", |
| 283 | "-Xps-hot-startup-method-samples:_", |
| 284 | "-Xps-min-methods-to-save:_", |
| 285 | "-Xps-min-classes-to-save:_", |
| 286 | "-Xps-min-notification-before-wake:_", |
| 287 | "-Xps-max-notification-before-wake:_", |
| 288 | "-Xps-profile-path:_"}) |
| 289 | .WithHelp("profile-saver options -Xps-<key>:<value>") |
Calin Juravle | 138dbff | 2016-06-28 19:36:58 +0100 | [diff] [blame] | 290 | .WithType<ProfileSaverOptions>() |
| 291 | .AppendValues() |
| 292 | .IntoKey(M::ProfileSaverOpts) // NOTE: Appends into same key as -Xjitsaveprofilinginfo |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 293 | .Define("-XX:HspaceCompactForOOMMinIntervalMs=_") // in ms |
| 294 | .WithType<MillisecondsToNanoseconds>() // store as ns |
| 295 | .IntoKey(M::HSpaceCompactForOOMMinIntervalsMs) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 296 | .Define({"-Xrelocate", "-Xnorelocate"}) |
| 297 | .WithValues({true, false}) |
| 298 | .IntoKey(M::Relocate) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 299 | .Define({"-Ximage-dex2oat", "-Xnoimage-dex2oat"}) |
| 300 | .WithValues({true, false}) |
| 301 | .IntoKey(M::ImageDex2Oat) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 302 | .Define("-XX:LargeObjectSpace=_") |
| 303 | .WithType<gc::space::LargeObjectSpaceType>() |
| 304 | .WithValueMap({{"disabled", gc::space::LargeObjectSpaceType::kDisabled}, |
| 305 | {"freelist", gc::space::LargeObjectSpaceType::kFreeList}, |
| 306 | {"map", gc::space::LargeObjectSpaceType::kMap}}) |
| 307 | .IntoKey(M::LargeObjectSpace) |
| 308 | .Define("-XX:LargeObjectThreshold=_") |
| 309 | .WithType<Memory<1>>() |
| 310 | .IntoKey(M::LargeObjectThreshold) |
| 311 | .Define("-XX:BackgroundGC=_") |
| 312 | .WithType<BackgroundGcOption>() |
| 313 | .IntoKey(M::BackgroundGc) |
| 314 | .Define("-XX:+DisableExplicitGC") |
| 315 | .IntoKey(M::DisableExplicitGC) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 316 | .Define("-Xlockprofthreshold:_") |
| 317 | .WithType<unsigned int>() |
| 318 | .IntoKey(M::LockProfThreshold) |
Andreas Gampe | d0210e5 | 2017-06-23 13:38:09 -0700 | [diff] [blame] | 319 | .Define("-Xstackdumplockprofthreshold:_") |
| 320 | .WithType<unsigned int>() |
| 321 | .IntoKey(M::StackDumpLockProfThreshold) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 322 | .Define("-Xmethod-trace") |
| 323 | .IntoKey(M::MethodTrace) |
| 324 | .Define("-Xmethod-trace-file:_") |
| 325 | .WithType<std::string>() |
| 326 | .IntoKey(M::MethodTraceFile) |
| 327 | .Define("-Xmethod-trace-file-size:_") |
| 328 | .WithType<unsigned int>() |
| 329 | .IntoKey(M::MethodTraceFileSize) |
Andreas Gampe | 40da286 | 2015-02-27 12:49:04 -0800 | [diff] [blame] | 330 | .Define("-Xmethod-trace-stream") |
| 331 | .IntoKey(M::MethodTraceStreaming) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 332 | .Define("-Xcompiler:_") |
| 333 | .WithType<std::string>() |
| 334 | .IntoKey(M::Compiler) |
| 335 | .Define("-Xcompiler-option _") |
| 336 | .WithType<std::vector<std::string>>() |
| 337 | .AppendValues() |
| 338 | .IntoKey(M::CompilerOptions) |
| 339 | .Define("-Ximage-compiler-option _") |
| 340 | .WithType<std::vector<std::string>>() |
| 341 | .AppendValues() |
| 342 | .IntoKey(M::ImageCompilerOptions) |
| 343 | .Define("-Xverify:_") |
Igor Murashkin | 7617abd | 2015-07-10 18:27:47 -0700 | [diff] [blame] | 344 | .WithType<verifier::VerifyMode>() |
| 345 | .WithValueMap({{"none", verifier::VerifyMode::kNone}, |
| 346 | {"remote", verifier::VerifyMode::kEnable}, |
| 347 | {"all", verifier::VerifyMode::kEnable}, |
| 348 | {"softfail", verifier::VerifyMode::kSoftFail}}) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 349 | .IntoKey(M::Verify) |
| 350 | .Define("-XX:NativeBridge=_") |
| 351 | .WithType<std::string>() |
| 352 | .IntoKey(M::NativeBridge) |
Andreas Gampe | 9106e52 | 2015-03-31 14:54:03 -0700 | [diff] [blame] | 353 | .Define("-Xzygote-max-boot-retry=_") |
Narayan Kamath | 5a2be3f | 2015-02-16 13:51:51 +0000 | [diff] [blame] | 354 | .WithType<unsigned int>() |
| 355 | .IntoKey(M::ZygoteMaxFailedBoots) |
Calin Juravle | 01aaf6e | 2015-06-19 22:05:39 +0100 | [diff] [blame] | 356 | .Define("-Xno-sig-chain") |
| 357 | .IntoKey(M::NoSigChain) |
Dmitriy Ivanov | 785049f | 2014-07-18 10:08:57 -0700 | [diff] [blame] | 358 | .Define("--cpu-abilist=_") |
| 359 | .WithType<std::string>() |
| 360 | .IntoKey(M::CpuAbiList) |
Andreas Gampe | dd67125 | 2015-07-23 14:37:18 -0700 | [diff] [blame] | 361 | .Define("-Xfingerprint:_") |
| 362 | .WithType<std::string>() |
| 363 | .IntoKey(M::Fingerprint) |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 364 | .Define("-Xexperimental:_") |
| 365 | .WithType<ExperimentalFlags>() |
| 366 | .AppendValues() |
| 367 | .IntoKey(M::Experimental) |
Calin Juravle | d3e7c6c | 2016-02-04 19:07:51 +0000 | [diff] [blame] | 368 | .Define("-Xforce-nb-testing") |
| 369 | .IntoKey(M::ForceNativeBridge) |
Alex Light | 185d134 | 2016-08-11 10:48:03 -0700 | [diff] [blame] | 370 | .Define("-Xplugin:_") |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 371 | .WithHelp("Load and initialize the specified art-plugin.") |
Alex Light | 185d134 | 2016-08-11 10:48:03 -0700 | [diff] [blame] | 372 | .WithType<std::vector<Plugin>>().AppendValues() |
| 373 | .IntoKey(M::Plugins) |
Mathieu Chartier | 3fceaf5 | 2017-01-22 13:33:40 -0800 | [diff] [blame] | 374 | .Define("-XX:ThreadSuspendTimeout=_") // in ms |
| 375 | .WithType<MillisecondsToNanoseconds>() // store as ns |
| 376 | .IntoKey(M::ThreadSuspendTimeout) |
Andreas Gampe | 1b35b46 | 2017-09-29 18:52:15 -0700 | [diff] [blame] | 377 | .Define("-XX:GlobalRefAllocStackTraceLimit=_") // Number of free slots to enable tracing. |
| 378 | .WithType<unsigned int>() |
| 379 | .IntoKey(M::GlobalRefAllocStackTraceLimit) |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 380 | .Define("-XX:SlowDebug=_") |
| 381 | .WithType<bool>() |
| 382 | .WithValueMap({{"false", false}, {"true", true}}) |
| 383 | .IntoKey(M::SlowDebug) |
David Brazdil | a7db026 | 2018-01-16 17:13:35 +0000 | [diff] [blame] | 384 | .Define("-Xtarget-sdk-version:_") |
David Brazdil | 2bb2fbd | 2018-11-13 18:24:26 +0000 | [diff] [blame] | 385 | .WithType<unsigned int>() |
David Brazdil | a7db026 | 2018-01-16 17:13:35 +0000 | [diff] [blame] | 386 | .IntoKey(M::TargetSdkVersion) |
David Brazdil | 6dfdfef | 2019-04-11 17:39:11 +0100 | [diff] [blame] | 387 | .Define("-Xhidden-api-policy:_") |
| 388 | .WithType<hiddenapi::EnforcementPolicy>() |
| 389 | .WithValueMap(hiddenapi_policy_valuemap) |
| 390 | .IntoKey(M::HiddenApiPolicy) |
| 391 | .Define("-Xcore-platform-api-policy:_") |
| 392 | .WithType<hiddenapi::EnforcementPolicy>() |
| 393 | .WithValueMap(hiddenapi_policy_valuemap) |
| 394 | .IntoKey(M::CorePlatformApiPolicy) |
Andreas Gampe | 25419b5 | 2018-02-08 21:30:26 -0800 | [diff] [blame] | 395 | .Define("-Xuse-stderr-logger") |
| 396 | .IntoKey(M::UseStderrLogger) |
Eric Holk | df69bd7 | 2021-02-23 11:36:21 -0800 | [diff] [blame] | 397 | .Define("-Xwrite-metrics-to-log") |
| 398 | .WithHelp("Enables writing ART metrics to logcat") |
| 399 | .IntoKey(M::WriteMetricsToLog) |
| 400 | .Define("-Xwrite-metrics-to-file=_") |
| 401 | .WithHelp("Enables writing ART metrics to the given file") |
| 402 | .WithType<std::string>() |
| 403 | .IntoKey(M::WriteMetricsToFile) |
| 404 | .Define("-Xdisable-final-metrics-report") |
| 405 | .WithHelp("Disables reporting metrics when ART shuts down") |
| 406 | .IntoKey(M::DisableFinalMetricsReport) |
| 407 | .Define("-Xmetrics-reporting-period=_") |
| 408 | .WithHelp("The time in seconds between metrics reports") |
| 409 | .WithType<unsigned int>() |
| 410 | .IntoKey(M::MetricsReportingPeriod) |
Nicolas Geoffray | 66ff8a8 | 2018-02-28 13:27:55 +0000 | [diff] [blame] | 411 | .Define("-Xonly-use-system-oat-files") |
| 412 | .IntoKey(M::OnlyUseSystemOatFiles) |
Andreas Gampe | 0b0ffc1 | 2018-08-01 14:41:27 -0700 | [diff] [blame] | 413 | .Define("-Xverifier-logging-threshold=_") |
| 414 | .WithType<unsigned int>() |
| 415 | .IntoKey(M::VerifierLoggingThreshold) |
Andreas Gampe | 87658f3 | 2019-04-18 18:39:02 +0000 | [diff] [blame] | 416 | .Define("-XX:FastClassNotFoundException=_") |
| 417 | .WithType<bool>() |
| 418 | .WithValueMap({{"false", false}, {"true", true}}) |
| 419 | .IntoKey(M::FastClassNotFoundException) |
Alex Light | 79d6c80 | 2019-06-27 15:50:11 +0000 | [diff] [blame] | 420 | .Define("-Xopaque-jni-ids:_") |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 421 | .WithHelp("Control the representation of jmethodID and jfieldID values") |
Alex Light | f367747 | 2019-06-26 16:31:53 -0700 | [diff] [blame] | 422 | .WithType<JniIdType>() |
| 423 | .WithValueMap({{"true", JniIdType::kIndices}, |
| 424 | {"false", JniIdType::kPointer}, |
| 425 | {"swapable", JniIdType::kSwapablePointer}, |
| 426 | {"pointer", JniIdType::kPointer}, |
| 427 | {"indices", JniIdType::kIndices}, |
| 428 | {"default", JniIdType::kDefault}}) |
Alex Light | 79d6c80 | 2019-06-27 15:50:11 +0000 | [diff] [blame] | 429 | .IntoKey(M::OpaqueJniIds) |
Alex Light | 4ca2f48 | 2019-11-25 16:07:22 -0800 | [diff] [blame] | 430 | .Define("-Xauto-promote-opaque-jni-ids:_") |
| 431 | .WithType<bool>() |
| 432 | .WithValueMap({{"true", true}, {"false", false}}) |
| 433 | .IntoKey(M::AutoPromoteOpaqueJniIds) |
Andreas Gampe | d84794d | 2019-07-18 13:40:03 -0700 | [diff] [blame] | 434 | .Define("-XX:VerifierMissingKThrowFatal=_") |
| 435 | .WithType<bool>() |
| 436 | .WithValueMap({{"false", false}, {"true", true}}) |
| 437 | .IntoKey(M::VerifierMissingKThrowFatal) |
Florian Mayer | 0972d08 | 2020-05-15 14:07:31 +0200 | [diff] [blame] | 438 | .Define("-XX:PerfettoHprof=_") |
| 439 | .WithType<bool>() |
| 440 | .WithValueMap({{"false", false}, {"true", true}}) |
| 441 | .IntoKey(M::PerfettoHprof) |
Wessam Hassanein | b5a10be | 2020-11-11 16:42:52 -0800 | [diff] [blame] | 442 | .Define("-XX:PerfettoJavaHeapStackProf=_") |
| 443 | .WithType<bool>() |
| 444 | .WithValueMap({{"false", false}, {"true", true}}) |
Eric Holk | df69bd7 | 2021-02-23 11:36:21 -0800 | [diff] [blame] | 445 | .IntoKey(M::PerfettoJavaHeapStackProf) |
| 446 | .Ignore({ |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 447 | "-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa", |
| 448 | "-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:_", |
| 449 | "-Xdexopt:_", "-Xnoquithandler", "-Xjnigreflimit:_", "-Xgenregmap", "-Xnogenregmap", |
| 450 | "-Xverifyopt:_", "-Xcheckdexsum", "-Xincludeselectedop", "-Xjitop:_", |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 451 | "-Xincludeselectedmethod", |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 452 | "-Xjitblocking", "-Xjitmethod:_", "-Xjitclass:_", "-Xjitoffset:_", |
| 453 | "-Xjitconfig:_", "-Xjitcheckcg", "-Xjitverbose", "-Xjitprofile", |
| 454 | "-Xjitdisableopt", "-Xjitsuspendpoll", "-XX:mainThreadStackSize=_"}) |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 455 | .IgnoreUnrecognized(ignore_unrecognized) |
| 456 | .OrderCategories({"standard", "extended", "Dalvik", "ART"}); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 457 | |
| 458 | // TODO: Move Usage information into this DSL. |
| 459 | |
Yi Kong | c57c680 | 2018-10-29 14:28:56 -0700 | [diff] [blame] | 460 | return std::make_unique<RuntimeParser>(parser_builder->Build()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 461 | } |
| 462 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 463 | #pragma GCC diagnostic pop |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 464 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 465 | // Remove all the special options that have something in the void* part of the option. |
| 466 | // If runtime_options is not null, put the options in there. |
| 467 | // As a side-effect, populate the hooks from options. |
| 468 | bool ParsedOptions::ProcessSpecialOptions(const RuntimeOptions& options, |
| 469 | RuntimeArgumentMap* runtime_options, |
| 470 | std::vector<std::string>* out_options) { |
| 471 | using M = RuntimeArgumentMap; |
| 472 | |
| 473 | // TODO: Move the below loop into JNI |
| 474 | // Handle special options that set up hooks |
| 475 | for (size_t i = 0; i < options.size(); ++i) { |
| 476 | const std::string option(options[i].first); |
| 477 | // TODO: support -Djava.class.path |
| 478 | if (option == "bootclasspath") { |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 479 | auto boot_class_path = static_cast<std::vector<std::unique_ptr<const DexFile>>*>( |
| 480 | const_cast<void*>(options[i].second)); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 481 | |
| 482 | if (runtime_options != nullptr) { |
| 483 | runtime_options->Set(M::BootClassPathDexList, boot_class_path); |
| 484 | } |
| 485 | } else if (option == "compilercallbacks") { |
| 486 | CompilerCallbacks* compiler_callbacks = |
| 487 | reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second)); |
| 488 | if (runtime_options != nullptr) { |
| 489 | runtime_options->Set(M::CompilerCallbacksPtr, compiler_callbacks); |
| 490 | } |
| 491 | } else if (option == "imageinstructionset") { |
| 492 | const char* isa_str = reinterpret_cast<const char*>(options[i].second); |
| 493 | auto&& image_isa = GetInstructionSetFromString(isa_str); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 494 | if (image_isa == InstructionSet::kNone) { |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 495 | Usage("%s is not a valid instruction set.", isa_str); |
| 496 | return false; |
| 497 | } |
| 498 | if (runtime_options != nullptr) { |
| 499 | runtime_options->Set(M::ImageInstructionSet, image_isa); |
| 500 | } |
| 501 | } else if (option == "sensitiveThread") { |
| 502 | const void* hook = options[i].second; |
| 503 | bool (*hook_is_sensitive_thread)() = reinterpret_cast<bool (*)()>(const_cast<void*>(hook)); |
| 504 | |
| 505 | if (runtime_options != nullptr) { |
| 506 | runtime_options->Set(M::HookIsSensitiveThread, hook_is_sensitive_thread); |
| 507 | } |
| 508 | } else if (option == "vfprintf") { |
| 509 | const void* hook = options[i].second; |
| 510 | if (hook == nullptr) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 511 | Usage("vfprintf argument was nullptr"); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 512 | return false; |
| 513 | } |
| 514 | int (*hook_vfprintf)(FILE *, const char*, va_list) = |
| 515 | reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook)); |
| 516 | |
| 517 | if (runtime_options != nullptr) { |
| 518 | runtime_options->Set(M::HookVfprintf, hook_vfprintf); |
| 519 | } |
| 520 | hook_vfprintf_ = hook_vfprintf; |
| 521 | } else if (option == "exit") { |
| 522 | const void* hook = options[i].second; |
| 523 | if (hook == nullptr) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 524 | Usage("exit argument was nullptr"); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 525 | return false; |
| 526 | } |
| 527 | void(*hook_exit)(jint) = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook)); |
| 528 | if (runtime_options != nullptr) { |
| 529 | runtime_options->Set(M::HookExit, hook_exit); |
| 530 | } |
| 531 | hook_exit_ = hook_exit; |
| 532 | } else if (option == "abort") { |
| 533 | const void* hook = options[i].second; |
| 534 | if (hook == nullptr) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 535 | Usage("abort was nullptr\n"); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 536 | return false; |
| 537 | } |
| 538 | void(*hook_abort)() = reinterpret_cast<void(*)()>(const_cast<void*>(hook)); |
| 539 | if (runtime_options != nullptr) { |
| 540 | runtime_options->Set(M::HookAbort, hook_abort); |
| 541 | } |
| 542 | hook_abort_ = hook_abort; |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 543 | } else { |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 544 | // It is a regular option, that doesn't have a known 'second' value. |
| 545 | // Push it on to the regular options which will be parsed by our parser. |
| 546 | if (out_options != nullptr) { |
| 547 | out_options->push_back(option); |
| 548 | } |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 549 | } |
| 550 | } |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 551 | |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 552 | return true; |
| 553 | } |
| 554 | |
Sebastien Hertz | bba348e | 2015-06-01 08:28:18 +0200 | [diff] [blame] | 555 | // Intended for local changes only. |
| 556 | static void MaybeOverrideVerbosity() { |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 557 | // gLogVerbosity.class_linker = true; // TODO: don't check this in! |
Mathieu Chartier | 66a5539 | 2016-02-19 10:25:39 -0800 | [diff] [blame] | 558 | // gLogVerbosity.collector = true; // TODO: don't check this in! |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 559 | // gLogVerbosity.compiler = true; // TODO: don't check this in! |
Sebastien Hertz | bba348e | 2015-06-01 08:28:18 +0200 | [diff] [blame] | 560 | // gLogVerbosity.deopt = true; // TODO: don't check this in! |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 561 | // gLogVerbosity.gc = true; // TODO: don't check this in! |
| 562 | // gLogVerbosity.heap = true; // TODO: don't check this in! |
Orion Hodson | 2b94572 | 2021-02-10 13:57:45 +0000 | [diff] [blame] | 563 | // gLogVerbosity.image = true; // TODO: don't check this in! |
Mathieu Chartier | 765b2a0 | 2019-05-02 11:04:13 -0700 | [diff] [blame] | 564 | // gLogVerbosity.interpreter = true; // TODO: don't check this in! |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 565 | // gLogVerbosity.jdwp = true; // TODO: don't check this in! |
| 566 | // gLogVerbosity.jit = true; // TODO: don't check this in! |
| 567 | // gLogVerbosity.jni = true; // TODO: don't check this in! |
| 568 | // gLogVerbosity.monitor = true; // TODO: don't check this in! |
Sebastien Hertz | bba348e | 2015-06-01 08:28:18 +0200 | [diff] [blame] | 569 | // gLogVerbosity.oat = true; // TODO: don't check this in! |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 570 | // gLogVerbosity.profiler = true; // TODO: don't check this in! |
| 571 | // gLogVerbosity.signals = true; // TODO: don't check this in! |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 572 | // gLogVerbosity.simulator = true; // TODO: don't check this in! |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 573 | // gLogVerbosity.startup = true; // TODO: don't check this in! |
| 574 | // gLogVerbosity.third_party_jni = true; // TODO: don't check this in! |
| 575 | // gLogVerbosity.threads = true; // TODO: don't check this in! |
| 576 | // gLogVerbosity.verifier = true; // TODO: don't check this in! |
Sebastien Hertz | bba348e | 2015-06-01 08:28:18 +0200 | [diff] [blame] | 577 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 578 | |
Vladimir Marko | 88b2b80 | 2015-12-04 14:19:04 +0000 | [diff] [blame] | 579 | bool ParsedOptions::DoParse(const RuntimeOptions& options, |
| 580 | bool ignore_unrecognized, |
| 581 | RuntimeArgumentMap* runtime_options) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 582 | for (size_t i = 0; i < options.size(); ++i) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 583 | if (true && options[0].first == "-Xzygote") { |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 584 | LOG(INFO) << "option[" << i << "]=" << options[i].first; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 585 | } |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 586 | } |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 587 | |
| 588 | auto parser = MakeParser(ignore_unrecognized); |
| 589 | |
| 590 | // Convert to a simple string list (without the magic pointer options) |
| 591 | std::vector<std::string> argv_list; |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 592 | if (!ProcessSpecialOptions(options, nullptr, &argv_list)) { |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 593 | return false; |
| 594 | } |
| 595 | |
| 596 | CmdlineResult parse_result = parser->Parse(argv_list); |
| 597 | |
| 598 | // Handle parse errors by displaying the usage and potentially exiting. |
| 599 | if (parse_result.IsError()) { |
| 600 | if (parse_result.GetStatus() == CmdlineResult::kUsage) { |
| 601 | UsageMessage(stdout, "%s\n", parse_result.GetMessage().c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 602 | Exit(0); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 603 | } else if (parse_result.GetStatus() == CmdlineResult::kUnknown && !ignore_unrecognized) { |
| 604 | Usage("%s\n", parse_result.GetMessage().c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 605 | return false; |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 606 | } else { |
| 607 | Usage("%s\n", parse_result.GetMessage().c_str()); |
| 608 | Exit(0); |
| 609 | } |
| 610 | |
| 611 | UNREACHABLE(); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | using M = RuntimeArgumentMap; |
| 615 | RuntimeArgumentMap args = parser->ReleaseArgumentsMap(); |
| 616 | |
| 617 | // -help, -showversion, etc. |
| 618 | if (args.Exists(M::Help)) { |
| 619 | Usage(nullptr); |
| 620 | return false; |
| 621 | } else if (args.Exists(M::ShowVersion)) { |
Calin Juravle | 4707af8 | 2017-04-13 16:35:42 -0700 | [diff] [blame] | 622 | UsageMessage(stdout, |
| 623 | "ART version %s %s\n", |
| 624 | Runtime::GetVersion(), |
| 625 | GetInstructionSetString(kRuntimeISA)); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 626 | Exit(0); |
| 627 | } else if (args.Exists(M::BootClassPath)) { |
Vladimir Marko | 91f1032 | 2018-12-07 18:04:10 +0000 | [diff] [blame] | 628 | LOG(INFO) << "setting boot class path to " << args.Get(M::BootClassPath)->Join(); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 629 | } |
| 630 | |
Nicolas Geoffray | a5ca8eb | 2018-08-24 13:39:13 +0100 | [diff] [blame] | 631 | if (args.GetOrDefault(M::Interpret)) { |
| 632 | if (args.Exists(M::UseJitCompilation) && *args.Get(M::UseJitCompilation)) { |
| 633 | Usage("-Xusejit:true and -Xint cannot be specified together\n"); |
| 634 | Exit(0); |
| 635 | } |
| 636 | args.Set(M::UseJitCompilation, false); |
Calin Juravle | af36e49 | 2016-04-27 18:50:45 +0100 | [diff] [blame] | 637 | } |
| 638 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 639 | // 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] | 640 | const char* env_bcp = getenv("BOOTCLASSPATH"); |
| 641 | if (env_bcp != nullptr) { |
| 642 | args.SetIfMissing(M::BootClassPath, ParseStringList<':'>::Split(env_bcp)); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | // Set a default class path if we didn't get an explicit one via command line. |
| 646 | if (getenv("CLASSPATH") != nullptr) { |
| 647 | args.SetIfMissing(M::ClassPath, std::string(getenv("CLASSPATH"))); |
| 648 | } |
| 649 | |
| 650 | // 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] | 651 | args.SetIfMissing(M::ParallelGCThreads, gc::Heap::kDefaultEnableParallelGC ? |
| 652 | static_cast<unsigned int>(sysconf(_SC_NPROCESSORS_CONF) - 1u) : 0u); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 653 | |
Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 654 | // -verbose: |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 655 | { |
| 656 | LogVerbosity *log_verbosity = args.Get(M::Verbose); |
| 657 | if (log_verbosity != nullptr) { |
| 658 | gLogVerbosity = *log_verbosity; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 659 | } |
| 660 | } |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 661 | |
Sebastien Hertz | bba348e | 2015-06-01 08:28:18 +0200 | [diff] [blame] | 662 | MaybeOverrideVerbosity(); |
| 663 | |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 664 | SetRuntimeDebugFlagsEnabled(args.GetOrDefault(M::SlowDebug)); |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 665 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 666 | // -Xprofile: |
| 667 | Trace::SetDefaultClockSource(args.GetOrDefault(M::ProfileClock)); |
| 668 | |
| 669 | if (!ProcessSpecialOptions(options, &args, nullptr)) { |
| 670 | return false; |
| 671 | } |
| 672 | |
| 673 | { |
| 674 | // If not set, background collector type defaults to homogeneous compaction. |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 675 | // If not low memory mode, semispace otherwise. |
| 676 | |
| 677 | gc::CollectorType background_collector_type_; |
Igor Murashkin | 5573c37 | 2017-11-16 13:34:30 -0800 | [diff] [blame] | 678 | gc::CollectorType collector_type_ = (XGcOption{}).collector_type_; |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 679 | bool low_memory_mode_ = args.Exists(M::LowMemoryMode); |
| 680 | |
| 681 | background_collector_type_ = args.GetOrDefault(M::BackgroundGc); |
| 682 | { |
| 683 | XGcOption* xgc = args.Get(M::GcOption); |
| 684 | if (xgc != nullptr && xgc->collector_type_ != gc::kCollectorTypeNone) { |
| 685 | collector_type_ = xgc->collector_type_; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | if (background_collector_type_ == gc::kCollectorTypeNone) { |
Mathieu Chartier | f75dce4 | 2019-04-08 09:36:23 -0700 | [diff] [blame] | 690 | background_collector_type_ = low_memory_mode_ ? |
| 691 | gc::kCollectorTypeSS : gc::kCollectorTypeHomogeneousSpaceCompact; |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | args.Set(M::BackgroundGc, BackgroundGcOption { background_collector_type_ }); |
Mathieu Chartier | 6b2352b | 2014-08-20 14:13:18 -0700 | [diff] [blame] | 695 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 696 | |
Vladimir Marko | 91f1032 | 2018-12-07 18:04:10 +0000 | [diff] [blame] | 697 | const ParseStringList<':'>* boot_class_path_locations = args.Get(M::BootClassPathLocations); |
| 698 | if (boot_class_path_locations != nullptr && boot_class_path_locations->Size() != 0u) { |
| 699 | const ParseStringList<':'>* boot_class_path = args.Get(M::BootClassPath); |
| 700 | if (boot_class_path == nullptr || |
| 701 | boot_class_path_locations->Size() != boot_class_path->Size()) { |
| 702 | Usage("The number of boot class path files does not match" |
| 703 | " the number of boot class path locations given\n" |
| 704 | " boot class path files (%zu): %s\n" |
| 705 | " boot class path locations (%zu): %s\n", |
| 706 | (boot_class_path != nullptr) ? boot_class_path->Size() : 0u, |
| 707 | (boot_class_path != nullptr) ? boot_class_path->Join().c_str() : "<nil>", |
| 708 | boot_class_path_locations->Size(), |
| 709 | boot_class_path_locations->Join().c_str()); |
| 710 | return false; |
Richard Uhler | c275259 | 2015-01-02 13:28:22 -0800 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 714 | if (!args.Exists(M::CompilerCallbacksPtr) && !args.Exists(M::Image)) { |
Nicolas Geoffray | de1b2a2 | 2019-02-27 09:10:57 +0000 | [diff] [blame] | 715 | std::string image = GetDefaultBootImageLocation(GetAndroidRoot()); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 716 | args.Set(M::Image, image); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 717 | } |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 718 | |
Lin Zang | 8cd63ab | 2015-11-06 14:08:51 +0800 | [diff] [blame] | 719 | // 0 means no growth limit, and growth limit should be always <= heap size |
| 720 | if (args.GetOrDefault(M::HeapGrowthLimit) <= 0u || |
| 721 | args.GetOrDefault(M::HeapGrowthLimit) > args.GetOrDefault(M::MemoryMaximumSize)) { |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 722 | args.Set(M::HeapGrowthLimit, args.GetOrDefault(M::MemoryMaximumSize)); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 723 | } |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 724 | |
| 725 | *runtime_options = std::move(args); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 726 | return true; |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 727 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 728 | |
| 729 | void ParsedOptions::Exit(int status) { |
| 730 | hook_exit_(status); |
| 731 | } |
| 732 | |
| 733 | void ParsedOptions::Abort() { |
| 734 | hook_abort_(); |
| 735 | } |
| 736 | |
| 737 | void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 738 | hook_vfprintf_(stream, fmt, ap); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) { |
| 742 | va_list ap; |
| 743 | va_start(ap, fmt); |
| 744 | UsageMessageV(stream, fmt, ap); |
| 745 | va_end(ap); |
| 746 | } |
| 747 | |
| 748 | void ParsedOptions::Usage(const char* fmt, ...) { |
| 749 | bool error = (fmt != nullptr); |
| 750 | FILE* stream = error ? stderr : stdout; |
| 751 | |
| 752 | if (fmt != nullptr) { |
| 753 | va_list ap; |
| 754 | va_start(ap, fmt); |
| 755 | UsageMessageV(stream, fmt, ap); |
| 756 | va_end(ap); |
| 757 | } |
| 758 | |
| 759 | const char* program = "dalvikvm"; |
| 760 | UsageMessage(stream, "%s: [options] class [argument ...]\n", program); |
| 761 | UsageMessage(stream, "\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 762 | |
Alex Light | eb9da9e | 2020-07-13 16:10:03 -0700 | [diff] [blame] | 763 | std::stringstream oss; |
| 764 | VariableIndentationOutputStream vios(&oss); |
| 765 | auto parser = MakeParser(false); |
| 766 | parser->DumpHelp(vios); |
| 767 | UsageMessage(stream, oss.str().c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 768 | Exit((error) ? 1 : 0); |
| 769 | } |
| 770 | |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 771 | } // namespace art |