blob: b7a2b66277f4c7354ff7fdb3228569d3b2f74427 [file] [log] [blame]
Brian Carlstrom491ca9e2014-03-02 18:24:38 -08001/*
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 Rogers576ca0c2014-06-06 15:58:22 -070018
Yi Kongc57c6802018-10-29 14:28:56 -070019#include <memory>
Ian Rogersc7dd2952014-10-21 23:31:19 -070020#include <sstream>
21
Andreas Gampe57943812017-12-06 21:39:13 -080022#include <android-base/logging.h>
Vladimir Marko91f10322018-12-07 18:04:10 +000023#include <android-base/strings.h>
Andreas Gampe57943812017-12-06 21:39:13 -080024
David Sehr891a50e2017-10-27 17:01:07 -070025#include "base/file_utils.h"
Alex Lighteb9da9e2020-07-13 16:10:03 -070026#include "base/indenter.h"
Andreas Gampe57943812017-12-06 21:39:13 -080027#include "base/macros.h"
David Sehrc431b9d2018-03-02 12:01:51 -080028#include "base/utils.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080029#include "debugger.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070030#include "gc/heap.h"
Alex Lightf3677472019-06-26 16:31:53 -070031#include "jni_id_type.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080032#include "monitor.h"
Ian Rogerse63db272014-07-15 15:36:11 -070033#include "runtime.h"
Alex Light7233c7e2016-07-28 10:07:45 -070034#include "ti/agent.h"
Ian Rogerse63db272014-07-15 15:36:11 -070035#include "trace.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080036
Igor Murashkinaaebaa02015-01-26 10:55:53 -080037#include "cmdline_parser.h"
38#include "runtime_options.h"
39
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080040namespace art {
41
Igor Murashkinaaebaa02015-01-26 10:55:53 -080042using MemoryKiB = Memory<1024>;
43
Andreas Gampe313f4032014-08-29 16:01:25 -070044ParsedOptions::ParsedOptions()
Igor Murashkinaaebaa02015-01-26 10:55:53 -080045 : hook_is_sensitive_thread_(nullptr),
Andreas Gampe313f4032014-08-29 16:01:25 -070046 hook_vfprintf_(vfprintf),
47 hook_exit_(exit),
Igor Murashkinaaebaa02015-01-26 10:55:53 -080048 hook_abort_(nullptr) { // We don't call abort(3) by default; see
49 // Runtime::Abort
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080050}
Andreas Gampe313f4032014-08-29 16:01:25 -070051
Vladimir Marko88b2b802015-12-04 14:19:04 +000052bool ParsedOptions::Parse(const RuntimeOptions& options,
53 bool ignore_unrecognized,
54 RuntimeArgumentMap* runtime_options) {
Igor Murashkinb1d8c312015-08-04 11:18:43 -070055 CHECK(runtime_options != nullptr);
56
Vladimir Marko88b2b802015-12-04 14:19:04 +000057 ParsedOptions parser;
58 return parser.DoParse(options, ignore_unrecognized, runtime_options);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080059}
60
Igor Murashkinaaebaa02015-01-26 10:55:53 -080061using RuntimeParser = CmdlineParser<RuntimeArgumentMap, RuntimeArgumentMap::Key>;
David Brazdil6dfdfef2019-04-11 17:39:11 +010062using HiddenapiPolicyValueMap =
63 std::initializer_list<std::pair<const char*, hiddenapi::EnforcementPolicy>>;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080064
Igor Murashkinaaebaa02015-01-26 10:55:53 -080065// 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
71std::unique_ptr<RuntimeParser> ParsedOptions::MakeParser(bool ignore_unrecognized) {
72 using M = RuntimeArgumentMap;
73
74 std::unique_ptr<RuntimeParser::Builder> parser_builder =
Yi Kongc57c6802018-10-29 14:28:56 -070075 std::make_unique<RuntimeParser::Builder>();
Igor Murashkinaaebaa02015-01-26 10:55:53 -080076
David Brazdil6dfdfef2019-04-11 17:39:11 +010077 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 Murashkinaaebaa02015-01-26 10:55:53 -080084 parser_builder->
Alex Lighteb9da9e2020-07-13 16:10:03 -070085 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 Murashkinaaebaa02015-01-26 10:55:53 -080099 .IntoKey(M::Help)
100 .Define("-showversion")
101 .IntoKey(M::ShowVersion)
Alex Light7233c7e2016-07-28 10:07:45 -0700102 // 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 Lighteb9da9e2020-07-13 16:10:03 -0700107 .WithHelp("Load native agents.")
Andreas Gampeaadcbc62017-12-28 14:05:42 -0800108 .WithType<std::list<ti::AgentSpec>>().AppendValues()
Alex Light7233c7e2016-07-28 10:07:45 -0700109 .IntoKey(M::AgentPath)
Alex Lighteb9da9e2020-07-13 16:10:03 -0700110 .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 Murashkinaaebaa02015-01-26 10:55:53 -0800116 .Define("-Xms_")
117 .WithType<MemoryKiB>()
118 .IntoKey(M::MemoryInitialSize)
119 .Define("-Xmx_")
120 .WithType<MemoryKiB>()
121 .IntoKey(M::MemoryMaximumSize)
Alex Lighteb9da9e2020-07-13 16:10:03 -0700122 .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 Murashkinaaebaa02015-01-26 10:55:53 -0800138 .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 Chartier11c273d2017-10-15 20:54:45 -0700154 .WithType<double>().WithRange(0.1, 5.0)
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800155 .IntoKey(M::ForegroundHeapGrowthMultiplier)
Alex Lighteb9da9e2020-07-13 16:10:03 -0700156 .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 Lighteb9da9e2020-07-13 16:10:03 -0700176 .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 Murashkinaaebaa02015-01-26 10:55:53 -0800189 .Define("-XX:ParallelGCThreads=_")
190 .WithType<unsigned int>()
191 .IntoKey(M::ParallelGCThreads)
192 .Define("-XX:ConcGCThreads=_")
193 .WithType<unsigned int>()
194 .IntoKey(M::ConcGCThreads)
Hans Boehmb2155572019-03-27 14:25:53 -0700195 .Define("-XX:FinalizerTimeoutMs=_")
196 .WithType<unsigned int>()
197 .IntoKey(M::FinalizerTimeoutMs)
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800198 .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 Yangde94ea72018-11-16 10:15:49 +0000209 .Define("-XX:DumpRegionInfoBeforeGC")
210 .IntoKey(M::DumpRegionInfoBeforeGC)
211 .Define("-XX:DumpRegionInfoAfterGC")
212 .IntoKey(M::DumpRegionInfoAfterGC)
Mathieu Chartiera4885cb2015-03-09 15:38:54 -0700213 .Define("-XX:DumpJITInfoOnShutdown")
214 .IntoKey(M::DumpJITInfoOnShutdown)
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800215 .Define("-XX:IgnoreMaxFootprint")
216 .IntoKey(M::IgnoreMaxFootprint)
Alex Lightb5a0e912020-07-23 10:54:47 -0700217 .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 Murashkinaaebaa02015-01-26 10:55:53 -0800222 .Define("-XX:UseTLAB")
Hiroshi Yamauchif360ad02015-02-20 11:28:03 -0800223 .WithValue(true)
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800224 .IntoKey(M::UseTLAB)
225 .Define({"-XX:EnableHSpaceCompactForOOM", "-XX:DisableHSpaceCompactForOOM"})
226 .WithValues({true, false})
227 .IntoKey(M::EnableHSpaceCompactForOOM)
Nicolas Geoffray6ee49712018-03-30 14:39:05 +0000228 .Define("-XX:DumpNativeStackOnSigQuit:_")
229 .WithType<bool>()
230 .WithValueMap({{"false", false}, {"true", true}})
231 .IntoKey(M::DumpNativeStackOnSigQuit)
Mathieu Chartierc42cb0e2017-10-13 11:35:00 -0700232 .Define("-XX:MadviseRandomAccess:_")
233 .WithType<bool>()
234 .WithValueMap({{"false", false}, {"true", true}})
235 .IntoKey(M::MadviseRandomAccess)
Mathieu Chartier1972a8e2015-03-05 17:12:54 -0800236 .Define("-Xusejit:_")
237 .WithType<bool>()
238 .WithValueMap({{"false", false}, {"true", true}})
Calin Juravleffc87072016-04-20 14:22:09 +0100239 .IntoKey(M::UseJitCompilation)
Nicolas Geoffray4bf753d2020-12-14 20:33:53 +0000240 .Define("-Xuseprofiledjit:_")
241 .WithType<bool>()
242 .WithValueMap({{"false", false}, {"true", true}})
243 .IntoKey(M::UseProfiledJitCompilation)
Nicolas Geoffray56782292015-11-19 14:25:43 +0000244 .Define("-Xjitinitialsize:_")
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800245 .WithType<MemoryKiB>()
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000246 .IntoKey(M::JITCodeCacheInitialCapacity)
Nicolas Geoffray56782292015-11-19 14:25:43 +0000247 .Define("-Xjitmaxsize:_")
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000248 .WithType<MemoryKiB>()
249 .IntoKey(M::JITCodeCacheMaxCapacity)
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100250 .Define("-Xjitwarmupthreshold:_")
251 .WithType<unsigned int>()
252 .IntoKey(M::JITWarmupThreshold)
Nicolas Geoffray83f080a2016-03-08 16:50:21 +0000253 .Define("-Xjitosrthreshold:_")
254 .WithType<unsigned int>()
255 .IntoKey(M::JITOsrThreshold)
Calin Juravleb2771b42016-04-07 17:09:25 +0100256 .Define("-Xjitprithreadweight:_")
257 .WithType<unsigned int>()
258 .IntoKey(M::JITPriorityThreadWeight)
Calin Juravle155ff3d2016-04-27 14:14:58 +0100259 .Define("-Xjittransitionweight:_")
260 .WithType<unsigned int>()
261 .IntoKey(M::JITInvokeTransitionWeight)
Nicolas Geoffray47b95802018-05-16 15:42:17 +0100262 .Define("-Xjitpthreadpriority:_")
263 .WithType<int>()
264 .IntoKey(M::JITPoolThreadPthreadPriority)
Nicolas Geoffray4bf753d2020-12-14 20:33:53 +0000265 .Define("-Xjitzygotepthreadpriority:_")
266 .WithType<int>()
267 .IntoKey(M::JITZygotePoolThreadPthreadPriority)
Calin Juravle31f2c152015-10-23 17:56:15 +0100268 .Define("-Xjitsaveprofilinginfo")
Calin Juravle138dbff2016-06-28 19:36:58 +0100269 .WithType<ProfileSaverOptions>()
270 .AppendValues()
271 .IntoKey(M::ProfileSaverOpts)
Alex Lighteb9da9e2020-07-13 16:10:03 -0700272 // .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 Juravle138dbff2016-06-28 19:36:58 +0100290 .WithType<ProfileSaverOptions>()
291 .AppendValues()
292 .IntoKey(M::ProfileSaverOpts) // NOTE: Appends into same key as -Xjitsaveprofilinginfo
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800293 .Define("-XX:HspaceCompactForOOMMinIntervalMs=_") // in ms
294 .WithType<MillisecondsToNanoseconds>() // store as ns
295 .IntoKey(M::HSpaceCompactForOOMMinIntervalsMs)
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800296 .Define({"-Xrelocate", "-Xnorelocate"})
297 .WithValues({true, false})
298 .IntoKey(M::Relocate)
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800299 .Define({"-Ximage-dex2oat", "-Xnoimage-dex2oat"})
300 .WithValues({true, false})
301 .IntoKey(M::ImageDex2Oat)
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800302 .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 Murashkinaaebaa02015-01-26 10:55:53 -0800316 .Define("-Xlockprofthreshold:_")
317 .WithType<unsigned int>()
318 .IntoKey(M::LockProfThreshold)
Andreas Gamped0210e52017-06-23 13:38:09 -0700319 .Define("-Xstackdumplockprofthreshold:_")
320 .WithType<unsigned int>()
321 .IntoKey(M::StackDumpLockProfThreshold)
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800322 .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 Gampe40da2862015-02-27 12:49:04 -0800330 .Define("-Xmethod-trace-stream")
331 .IntoKey(M::MethodTraceStreaming)
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800332 .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 Murashkin7617abd2015-07-10 18:27:47 -0700344 .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 Murashkinaaebaa02015-01-26 10:55:53 -0800349 .IntoKey(M::Verify)
350 .Define("-XX:NativeBridge=_")
351 .WithType<std::string>()
352 .IntoKey(M::NativeBridge)
Andreas Gampe9106e522015-03-31 14:54:03 -0700353 .Define("-Xzygote-max-boot-retry=_")
Narayan Kamath5a2be3f2015-02-16 13:51:51 +0000354 .WithType<unsigned int>()
355 .IntoKey(M::ZygoteMaxFailedBoots)
Calin Juravle01aaf6e2015-06-19 22:05:39 +0100356 .Define("-Xno-sig-chain")
357 .IntoKey(M::NoSigChain)
Dmitriy Ivanov785049f2014-07-18 10:08:57 -0700358 .Define("--cpu-abilist=_")
359 .WithType<std::string>()
360 .IntoKey(M::CpuAbiList)
Andreas Gampedd671252015-07-23 14:37:18 -0700361 .Define("-Xfingerprint:_")
362 .WithType<std::string>()
363 .IntoKey(M::Fingerprint)
Alex Lighteb7c1442015-08-31 13:17:42 -0700364 .Define("-Xexperimental:_")
365 .WithType<ExperimentalFlags>()
366 .AppendValues()
367 .IntoKey(M::Experimental)
Calin Juravled3e7c6c2016-02-04 19:07:51 +0000368 .Define("-Xforce-nb-testing")
369 .IntoKey(M::ForceNativeBridge)
Alex Light185d1342016-08-11 10:48:03 -0700370 .Define("-Xplugin:_")
Alex Lighteb9da9e2020-07-13 16:10:03 -0700371 .WithHelp("Load and initialize the specified art-plugin.")
Alex Light185d1342016-08-11 10:48:03 -0700372 .WithType<std::vector<Plugin>>().AppendValues()
373 .IntoKey(M::Plugins)
Mathieu Chartier3fceaf52017-01-22 13:33:40 -0800374 .Define("-XX:ThreadSuspendTimeout=_") // in ms
375 .WithType<MillisecondsToNanoseconds>() // store as ns
376 .IntoKey(M::ThreadSuspendTimeout)
Andreas Gampe1b35b462017-09-29 18:52:15 -0700377 .Define("-XX:GlobalRefAllocStackTraceLimit=_") // Number of free slots to enable tracing.
378 .WithType<unsigned int>()
379 .IntoKey(M::GlobalRefAllocStackTraceLimit)
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700380 .Define("-XX:SlowDebug=_")
381 .WithType<bool>()
382 .WithValueMap({{"false", false}, {"true", true}})
383 .IntoKey(M::SlowDebug)
David Brazdila7db0262018-01-16 17:13:35 +0000384 .Define("-Xtarget-sdk-version:_")
David Brazdil2bb2fbd2018-11-13 18:24:26 +0000385 .WithType<unsigned int>()
David Brazdila7db0262018-01-16 17:13:35 +0000386 .IntoKey(M::TargetSdkVersion)
David Brazdil6dfdfef2019-04-11 17:39:11 +0100387 .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 Gampe25419b52018-02-08 21:30:26 -0800395 .Define("-Xuse-stderr-logger")
396 .IntoKey(M::UseStderrLogger)
Eric Holkdf69bd72021-02-23 11:36:21 -0800397 .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 Geoffray66ff8a82018-02-28 13:27:55 +0000411 .Define("-Xonly-use-system-oat-files")
412 .IntoKey(M::OnlyUseSystemOatFiles)
Andreas Gampe0b0ffc12018-08-01 14:41:27 -0700413 .Define("-Xverifier-logging-threshold=_")
414 .WithType<unsigned int>()
415 .IntoKey(M::VerifierLoggingThreshold)
Andreas Gampe87658f32019-04-18 18:39:02 +0000416 .Define("-XX:FastClassNotFoundException=_")
417 .WithType<bool>()
418 .WithValueMap({{"false", false}, {"true", true}})
419 .IntoKey(M::FastClassNotFoundException)
Alex Light79d6c802019-06-27 15:50:11 +0000420 .Define("-Xopaque-jni-ids:_")
Alex Lighteb9da9e2020-07-13 16:10:03 -0700421 .WithHelp("Control the representation of jmethodID and jfieldID values")
Alex Lightf3677472019-06-26 16:31:53 -0700422 .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 Light79d6c802019-06-27 15:50:11 +0000429 .IntoKey(M::OpaqueJniIds)
Alex Light4ca2f482019-11-25 16:07:22 -0800430 .Define("-Xauto-promote-opaque-jni-ids:_")
431 .WithType<bool>()
432 .WithValueMap({{"true", true}, {"false", false}})
433 .IntoKey(M::AutoPromoteOpaqueJniIds)
Andreas Gamped84794d2019-07-18 13:40:03 -0700434 .Define("-XX:VerifierMissingKThrowFatal=_")
435 .WithType<bool>()
436 .WithValueMap({{"false", false}, {"true", true}})
437 .IntoKey(M::VerifierMissingKThrowFatal)
Florian Mayer0972d082020-05-15 14:07:31 +0200438 .Define("-XX:PerfettoHprof=_")
439 .WithType<bool>()
440 .WithValueMap({{"false", false}, {"true", true}})
441 .IntoKey(M::PerfettoHprof)
Wessam Hassaneinb5a10be2020-11-11 16:42:52 -0800442 .Define("-XX:PerfettoJavaHeapStackProf=_")
443 .WithType<bool>()
444 .WithValueMap({{"false", false}, {"true", true}})
Eric Holkdf69bd72021-02-23 11:36:21 -0800445 .IntoKey(M::PerfettoJavaHeapStackProf)
446 .Ignore({
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800447 "-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 Lighteb9da9e2020-07-13 16:10:03 -0700451 "-Xincludeselectedmethod",
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800452 "-Xjitblocking", "-Xjitmethod:_", "-Xjitclass:_", "-Xjitoffset:_",
453 "-Xjitconfig:_", "-Xjitcheckcg", "-Xjitverbose", "-Xjitprofile",
454 "-Xjitdisableopt", "-Xjitsuspendpoll", "-XX:mainThreadStackSize=_"})
Alex Lighteb9da9e2020-07-13 16:10:03 -0700455 .IgnoreUnrecognized(ignore_unrecognized)
456 .OrderCategories({"standard", "extended", "Dalvik", "ART"});
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800457
458 // TODO: Move Usage information into this DSL.
459
Yi Kongc57c6802018-10-29 14:28:56 -0700460 return std::make_unique<RuntimeParser>(parser_builder->Build());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800461}
462
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800463#pragma GCC diagnostic pop
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800464
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800465// 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.
468bool 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 Marko9bdf1082016-01-21 12:15:52 +0000479 auto boot_class_path = static_cast<std::vector<std::unique_ptr<const DexFile>>*>(
480 const_cast<void*>(options[i].second));
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800481
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 Marko33bff252017-11-01 14:35:42 +0000494 if (image_isa == InstructionSet::kNone) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800495 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 Chartier2cebb242015-04-21 16:50:40 -0700511 Usage("vfprintf argument was nullptr");
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800512 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 Chartier2cebb242015-04-21 16:50:40 -0700524 Usage("exit argument was nullptr");
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800525 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 Chartier2cebb242015-04-21 16:50:40 -0700535 Usage("abort was nullptr\n");
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800536 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 Chartier6f365cc2014-04-23 12:42:27 -0700543 } else {
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800544 // 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 Chartier6f365cc2014-04-23 12:42:27 -0700549 }
550 }
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800551
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700552 return true;
553}
554
Sebastien Hertzbba348e2015-06-01 08:28:18 +0200555// Intended for local changes only.
556static void MaybeOverrideVerbosity() {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800557 // gLogVerbosity.class_linker = true; // TODO: don't check this in!
Mathieu Chartier66a55392016-02-19 10:25:39 -0800558 // gLogVerbosity.collector = true; // TODO: don't check this in!
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800559 // gLogVerbosity.compiler = true; // TODO: don't check this in!
Sebastien Hertzbba348e2015-06-01 08:28:18 +0200560 // gLogVerbosity.deopt = true; // TODO: don't check this in!
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800561 // gLogVerbosity.gc = true; // TODO: don't check this in!
562 // gLogVerbosity.heap = true; // TODO: don't check this in!
Orion Hodson2b945722021-02-10 13:57:45 +0000563 // gLogVerbosity.image = true; // TODO: don't check this in!
Mathieu Chartier765b2a02019-05-02 11:04:13 -0700564 // gLogVerbosity.interpreter = true; // TODO: don't check this in!
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800565 // 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 Hertzbba348e2015-06-01 08:28:18 +0200569 // gLogVerbosity.oat = true; // TODO: don't check this in!
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800570 // gLogVerbosity.profiler = true; // TODO: don't check this in!
571 // gLogVerbosity.signals = true; // TODO: don't check this in!
Phil Wang751beff2015-08-28 15:17:15 +0800572 // gLogVerbosity.simulator = true; // TODO: don't check this in!
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800573 // 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 Hertzbba348e2015-06-01 08:28:18 +0200577}
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800578
Vladimir Marko88b2b802015-12-04 14:19:04 +0000579bool ParsedOptions::DoParse(const RuntimeOptions& options,
580 bool ignore_unrecognized,
581 RuntimeArgumentMap* runtime_options) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800582 for (size_t i = 0; i < options.size(); ++i) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800583 if (true && options[0].first == "-Xzygote") {
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800584 LOG(INFO) << "option[" << i << "]=" << options[i].first;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800585 }
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800586 }
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800587
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 Murashkinb1d8c312015-08-04 11:18:43 -0700592 if (!ProcessSpecialOptions(options, nullptr, &argv_list)) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800593 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 Carlstrom491ca9e2014-03-02 18:24:38 -0800602 Exit(0);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800603 } else if (parse_result.GetStatus() == CmdlineResult::kUnknown && !ignore_unrecognized) {
604 Usage("%s\n", parse_result.GetMessage().c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800605 return false;
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800606 } else {
607 Usage("%s\n", parse_result.GetMessage().c_str());
608 Exit(0);
609 }
610
611 UNREACHABLE();
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800612 }
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 Juravle4707af82017-04-13 16:35:42 -0700622 UsageMessage(stdout,
623 "ART version %s %s\n",
624 Runtime::GetVersion(),
625 GetInstructionSetString(kRuntimeISA));
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800626 Exit(0);
627 } else if (args.Exists(M::BootClassPath)) {
Vladimir Marko91f10322018-12-07 18:04:10 +0000628 LOG(INFO) << "setting boot class path to " << args.Get(M::BootClassPath)->Join();
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800629 }
630
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100631 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 Juravleaf36e492016-04-27 18:50:45 +0100637 }
638
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800639 // Set a default boot class path if we didn't get an explicit one via command line.
Vladimir Marko91f10322018-12-07 18:04:10 +0000640 const char* env_bcp = getenv("BOOTCLASSPATH");
641 if (env_bcp != nullptr) {
642 args.SetIfMissing(M::BootClassPath, ParseStringList<':'>::Split(env_bcp));
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800643 }
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 Chartier10d68862015-04-15 14:21:33 -0700651 args.SetIfMissing(M::ParallelGCThreads, gc::Heap::kDefaultEnableParallelGC ?
652 static_cast<unsigned int>(sysconf(_SC_NPROCESSORS_CONF) - 1u) : 0u);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800653
Igor Murashkin9d4b6da2016-07-29 09:51:58 -0700654 // -verbose:
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800655 {
656 LogVerbosity *log_verbosity = args.Get(M::Verbose);
657 if (log_verbosity != nullptr) {
658 gLogVerbosity = *log_verbosity;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800659 }
660 }
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800661
Sebastien Hertzbba348e2015-06-01 08:28:18 +0200662 MaybeOverrideVerbosity();
663
Andreas Gampe7c5acbb2018-09-20 13:54:52 -0700664 SetRuntimeDebugFlagsEnabled(args.GetOrDefault(M::SlowDebug));
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700665
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800666 // -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 Murashkinaaebaa02015-01-26 10:55:53 -0800675 // If not low memory mode, semispace otherwise.
676
677 gc::CollectorType background_collector_type_;
Igor Murashkin5573c372017-11-16 13:34:30 -0800678 gc::CollectorType collector_type_ = (XGcOption{}).collector_type_;
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800679 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 Chartierf75dce42019-04-08 09:36:23 -0700690 background_collector_type_ = low_memory_mode_ ?
691 gc::kCollectorTypeSS : gc::kCollectorTypeHomogeneousSpaceCompact;
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800692 }
693
694 args.Set(M::BackgroundGc, BackgroundGcOption { background_collector_type_ });
Mathieu Chartier6b2352b2014-08-20 14:13:18 -0700695 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800696
Vladimir Marko91f10322018-12-07 18:04:10 +0000697 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 Uhlerc2752592015-01-02 13:28:22 -0800711 }
712 }
713
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800714 if (!args.Exists(M::CompilerCallbacksPtr) && !args.Exists(M::Image)) {
Nicolas Geoffrayde1b2a22019-02-27 09:10:57 +0000715 std::string image = GetDefaultBootImageLocation(GetAndroidRoot());
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800716 args.Set(M::Image, image);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800717 }
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800718
Lin Zang8cd63ab2015-11-06 14:08:51 +0800719 // 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 Murashkinaaebaa02015-01-26 10:55:53 -0800722 args.Set(M::HeapGrowthLimit, args.GetOrDefault(M::MemoryMaximumSize));
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800723 }
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800724
725 *runtime_options = std::move(args);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800726 return true;
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800727}
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800728
729void ParsedOptions::Exit(int status) {
730 hook_exit_(status);
731}
732
733void ParsedOptions::Abort() {
734 hook_abort_();
735}
736
737void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700738 hook_vfprintf_(stream, fmt, ap);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800739}
740
741void 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
748void 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 Carlstrom491ca9e2014-03-02 18:24:38 -0800762
Alex Lighteb9da9e2020-07-13 16:10:03 -0700763 std::stringstream oss;
764 VariableIndentationOutputStream vios(&oss);
765 auto parser = MakeParser(false);
766 parser->DumpHelp(vios);
767 UsageMessage(stream, oss.str().c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800768 Exit((error) ? 1 : 0);
769}
770
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800771} // namespace art