blob: c5b1c4b558bca5be8f59b108b947767bc68b2cdb [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"
18
19#include "debugger.h"
20#include "monitor.h"
21
22namespace art {
23
24ParsedOptions* ParsedOptions::Create(const Runtime::Options& options, bool ignore_unrecognized) {
25 UniquePtr<ParsedOptions> parsed(new ParsedOptions());
26 if (parsed->Parse(options, ignore_unrecognized)) {
27 return parsed.release();
28 }
29 return nullptr;
30}
31
32// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
33// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
34// [gG] gigabytes.
35//
36// "s" should point just past the "-Xm?" part of the string.
37// "div" specifies a divisor, e.g. 1024 if the value must be a multiple
38// of 1024.
39//
40// The spec says the -Xmx and -Xms options must be multiples of 1024. It
41// doesn't say anything about -Xss.
42//
43// Returns 0 (a useless size) if "s" is malformed or specifies a low or
44// non-evenly-divisible value.
45//
46size_t ParseMemoryOption(const char* s, size_t div) {
47 // strtoul accepts a leading [+-], which we don't want,
48 // so make sure our string starts with a decimal digit.
49 if (isdigit(*s)) {
50 char* s2;
51 size_t val = strtoul(s, &s2, 10);
52 if (s2 != s) {
53 // s2 should be pointing just after the number.
54 // If this is the end of the string, the user
55 // has specified a number of bytes. Otherwise,
56 // there should be exactly one more character
57 // that specifies a multiplier.
58 if (*s2 != '\0') {
59 // The remainder of the string is either a single multiplier
60 // character, or nothing to indicate that the value is in
61 // bytes.
62 char c = *s2++;
63 if (*s2 == '\0') {
64 size_t mul;
65 if (c == '\0') {
66 mul = 1;
67 } else if (c == 'k' || c == 'K') {
68 mul = KB;
69 } else if (c == 'm' || c == 'M') {
70 mul = MB;
71 } else if (c == 'g' || c == 'G') {
72 mul = GB;
73 } else {
74 // Unknown multiplier character.
75 return 0;
76 }
77
78 if (val <= std::numeric_limits<size_t>::max() / mul) {
79 val *= mul;
80 } else {
81 // Clamp to a multiple of 1024.
82 val = std::numeric_limits<size_t>::max() & ~(1024-1);
83 }
84 } else {
85 // There's more than one character after the numeric part.
86 return 0;
87 }
88 }
89 // The man page says that a -Xm value must be a multiple of 1024.
90 if (val % div == 0) {
91 return val;
92 }
93 }
94 }
95 return 0;
96}
97
98static gc::CollectorType ParseCollectorType(const std::string& option) {
99 if (option == "MS" || option == "nonconcurrent") {
100 return gc::kCollectorTypeMS;
101 } else if (option == "CMS" || option == "concurrent") {
102 return gc::kCollectorTypeCMS;
103 } else if (option == "SS") {
104 return gc::kCollectorTypeSS;
105 } else if (option == "GSS") {
106 return gc::kCollectorTypeGSS;
107 } else {
108 return gc::kCollectorTypeNone;
109 }
110}
111
112bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecognized) {
113 const char* boot_class_path_string = getenv("BOOTCLASSPATH");
114 if (boot_class_path_string != NULL) {
115 boot_class_path_string_ = boot_class_path_string;
116 }
117 const char* class_path_string = getenv("CLASSPATH");
118 if (class_path_string != NULL) {
119 class_path_string_ = class_path_string;
120 }
121 // -Xcheck:jni is off by default for regular builds but on by default in debug builds.
122 check_jni_ = kIsDebugBuild;
123
124 heap_initial_size_ = gc::Heap::kDefaultInitialSize;
125 heap_maximum_size_ = gc::Heap::kDefaultMaximumSize;
126 heap_min_free_ = gc::Heap::kDefaultMinFree;
127 heap_max_free_ = gc::Heap::kDefaultMaxFree;
128 heap_target_utilization_ = gc::Heap::kDefaultTargetUtilization;
129 heap_growth_limit_ = 0; // 0 means no growth limit .
130 // Default to number of processors minus one since the main GC thread also does work.
131 parallel_gc_threads_ = sysconf(_SC_NPROCESSORS_CONF) - 1;
132 // Only the main GC thread, no workers.
133 conc_gc_threads_ = 0;
134 // Default is CMS which is Sticky + Partial + Full CMS GC.
135 collector_type_ = gc::kCollectorTypeCMS;
136 // If background_collector_type_ is kCollectorTypeNone, it defaults to the collector_type_ after
137 // parsing options.
138 background_collector_type_ = gc::kCollectorTypeNone;
139 stack_size_ = 0; // 0 means default.
140 max_spins_before_thin_lock_inflation_ = Monitor::kDefaultMaxSpinsBeforeThinLockInflation;
141 low_memory_mode_ = false;
142 use_tlab_ = false;
143 verify_pre_gc_heap_ = false;
144 verify_post_gc_heap_ = kIsDebugBuild;
145 verify_pre_gc_rosalloc_ = kIsDebugBuild;
146 verify_post_gc_rosalloc_ = false;
147
148 compiler_callbacks_ = nullptr;
149 is_zygote_ = false;
150 interpreter_only_ = false;
151 is_explicit_gc_disabled_ = false;
152
153 long_pause_log_threshold_ = gc::Heap::kDefaultLongPauseLogThreshold;
154 long_gc_log_threshold_ = gc::Heap::kDefaultLongGCLogThreshold;
155 dump_gc_performance_on_shutdown_ = false;
156 ignore_max_footprint_ = false;
157
158 lock_profiling_threshold_ = 0;
159 hook_is_sensitive_thread_ = NULL;
160
161 hook_vfprintf_ = vfprintf;
162 hook_exit_ = exit;
163 hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort.
164
165// gLogVerbosity.class_linker = true; // TODO: don't check this in!
166// gLogVerbosity.compiler = true; // TODO: don't check this in!
167// gLogVerbosity.verifier = true; // TODO: don't check this in!
168// gLogVerbosity.heap = true; // TODO: don't check this in!
169// gLogVerbosity.gc = true; // TODO: don't check this in!
170// gLogVerbosity.jdwp = true; // TODO: don't check this in!
171// gLogVerbosity.jni = true; // TODO: don't check this in!
172// gLogVerbosity.monitor = true; // TODO: don't check this in!
173// gLogVerbosity.startup = true; // TODO: don't check this in!
174// gLogVerbosity.third_party_jni = true; // TODO: don't check this in!
175// gLogVerbosity.threads = true; // TODO: don't check this in!
176
177 method_trace_ = false;
178 method_trace_file_ = "/data/method-trace-file.bin";
179 method_trace_file_size_ = 10 * MB;
180
181 profile_ = false;
182 profile_period_s_ = 10; // Seconds.
183 profile_duration_s_ = 20; // Seconds.
184 profile_interval_us_ = 500; // Microseconds.
185 profile_backoff_coefficient_ = 2.0;
186 profile_clock_source_ = kDefaultProfilerClockSource;
187
188 for (size_t i = 0; i < options.size(); ++i) {
189 const std::string option(options[i].first);
190 if (true && options[0].first == "-Xzygote") {
191 LOG(INFO) << "option[" << i << "]=" << option;
192 }
193 if (StartsWith(option, "-help")) {
194 Usage(nullptr);
195 return false;
196 } else if (StartsWith(option, "-showversion")) {
197 UsageMessage(stdout, "ART version %s\n", Runtime::GetVersion());
198 Exit(0);
199 } else if (StartsWith(option, "-Xbootclasspath:")) {
200 boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data();
201 } else if (option == "-classpath" || option == "-cp") {
202 // TODO: support -Djava.class.path
203 i++;
204 if (i == options.size()) {
205 Usage("Missing required class path value for %s", option.c_str());
206 return false;
207 }
208 const StringPiece& value = options[i].first;
209 class_path_string_ = value.data();
210 } else if (option == "bootclasspath") {
211 boot_class_path_
212 = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second);
213 } else if (StartsWith(option, "-Ximage:")) {
214 if (!ParseStringAfterChar(option, ':', &image_)) {
215 return false;
216 }
217 } else if (StartsWith(option, "-Xcheck:jni")) {
218 check_jni_ = true;
219 } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) {
220 std::string tail(option.substr(option[1] == 'X' ? 10 : 15));
221 // TODO: move parsing logic out of Dbg
222 if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) {
223 if (tail != "help") {
224 UsageMessage(stderr, "Failed to parse JDWP option %s\n", tail.c_str());
225 }
226 Usage("Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
227 "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n\n");
228 return false;
229 }
230 } else if (StartsWith(option, "-Xms")) {
231 size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024);
232 if (size == 0) {
233 Usage("Failed to parse memory option %s", option.c_str());
234 return false;
235 }
236 heap_initial_size_ = size;
237 } else if (StartsWith(option, "-Xmx")) {
238 size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024);
239 if (size == 0) {
240 Usage("Failed to parse memory option %s", option.c_str());
241 return false;
242 }
243 heap_maximum_size_ = size;
244 } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) {
245 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024);
246 if (size == 0) {
247 Usage("Failed to parse memory option %s", option.c_str());
248 return false;
249 }
250 heap_growth_limit_ = size;
251 } else if (StartsWith(option, "-XX:HeapMinFree=")) {
252 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024);
253 if (size == 0) {
254 Usage("Failed to parse memory option %s", option.c_str());
255 return false;
256 }
257 heap_min_free_ = size;
258 } else if (StartsWith(option, "-XX:HeapMaxFree=")) {
259 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024);
260 if (size == 0) {
261 Usage("Failed to parse memory option %s", option.c_str());
262 return false;
263 }
264 heap_max_free_ = size;
265 } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) {
266 if (!ParseDouble(option, '=', 0.1, 0.9, &heap_target_utilization_)) {
267 return false;
268 }
269 } else if (StartsWith(option, "-XX:ParallelGCThreads=")) {
270 if (!ParseUnsignedInteger(option, '=', &parallel_gc_threads_)) {
271 return false;
272 }
273 } else if (StartsWith(option, "-XX:ConcGCThreads=")) {
274 if (!ParseUnsignedInteger(option, '=', &conc_gc_threads_)) {
275 return false;
276 }
277 } else if (StartsWith(option, "-Xss")) {
278 size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1);
279 if (size == 0) {
280 Usage("Failed to parse memory option %s", option.c_str());
281 return false;
282 }
283 stack_size_ = size;
284 } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) {
285 if (!ParseUnsignedInteger(option, '=', &max_spins_before_thin_lock_inflation_)) {
286 return false;
287 }
288 } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) {
289 size_t value;
290 if (!ParseUnsignedInteger(option, '=', &value)) {
291 return false;
292 }
293 long_pause_log_threshold_ = MsToNs(value);
294 } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) {
295 size_t value;
296 if (!ParseUnsignedInteger(option, '=', &value)) {
297 return false;
298 }
299 long_gc_log_threshold_ = MsToNs(value);
300 } else if (option == "-XX:DumpGCPerformanceOnShutdown") {
301 dump_gc_performance_on_shutdown_ = true;
302 } else if (option == "-XX:IgnoreMaxFootprint") {
303 ignore_max_footprint_ = true;
304 } else if (option == "-XX:LowMemoryMode") {
305 low_memory_mode_ = true;
306 } else if (option == "-XX:UseTLAB") {
307 use_tlab_ = true;
308 } else if (StartsWith(option, "-D")) {
309 properties_.push_back(option.substr(strlen("-D")));
310 } else if (StartsWith(option, "-Xjnitrace:")) {
311 jni_trace_ = option.substr(strlen("-Xjnitrace:"));
312 } else if (option == "compilercallbacks") {
313 compiler_callbacks_ =
314 reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second));
315 } else if (option == "-Xzygote") {
316 is_zygote_ = true;
317 } else if (option == "-Xint") {
318 interpreter_only_ = true;
319 } else if (StartsWith(option, "-Xgc:")) {
320 std::vector<std::string> gc_options;
321 Split(option.substr(strlen("-Xgc:")), ',', gc_options);
322 for (const std::string& gc_option : gc_options) {
323 gc::CollectorType collector_type = ParseCollectorType(gc_option);
324 if (collector_type != gc::kCollectorTypeNone) {
325 collector_type_ = collector_type;
326 } else if (gc_option == "preverify") {
327 verify_pre_gc_heap_ = true;
328 } else if (gc_option == "nopreverify") {
329 verify_pre_gc_heap_ = false;
330 } else if (gc_option == "postverify") {
331 verify_post_gc_heap_ = true;
332 } else if (gc_option == "nopostverify") {
333 verify_post_gc_heap_ = false;
334 } else if (gc_option == "preverify_rosalloc") {
335 verify_pre_gc_rosalloc_ = true;
336 } else if (gc_option == "nopreverify_rosalloc") {
337 verify_pre_gc_rosalloc_ = false;
338 } else if (gc_option == "postverify_rosalloc") {
339 verify_post_gc_rosalloc_ = true;
340 } else if (gc_option == "nopostverify_rosalloc") {
341 verify_post_gc_rosalloc_ = false;
342 } else if ((gc_option == "precise") ||
343 (gc_option == "noprecise") ||
344 (gc_option == "verifycardtable") ||
345 (gc_option == "noverifycardtable")) {
346 // Ignored for backwards compatibility.
347 } else {
348 Usage("Unknown -Xgc option %s", gc_option.c_str());
349 return false;
350 }
351 }
352 } else if (StartsWith(option, "-XX:BackgroundGC=")) {
353 std::string substring;
354 if (!ParseStringAfterChar(option, '=', &substring)) {
355 return false;
356 }
357 gc::CollectorType collector_type = ParseCollectorType(substring);
358 if (collector_type != gc::kCollectorTypeNone) {
359 background_collector_type_ = collector_type;
360 } else {
361 Usage("Unknown -XX:BackgroundGC option %s", substring.c_str());
362 return false;
363 }
364 } else if (option == "-XX:+DisableExplicitGC") {
365 is_explicit_gc_disabled_ = true;
366 } else if (StartsWith(option, "-verbose:")) {
367 std::vector<std::string> verbose_options;
368 Split(option.substr(strlen("-verbose:")), ',', verbose_options);
369 for (size_t i = 0; i < verbose_options.size(); ++i) {
370 if (verbose_options[i] == "class") {
371 gLogVerbosity.class_linker = true;
372 } else if (verbose_options[i] == "verifier") {
373 gLogVerbosity.verifier = true;
374 } else if (verbose_options[i] == "compiler") {
375 gLogVerbosity.compiler = true;
376 } else if (verbose_options[i] == "heap") {
377 gLogVerbosity.heap = true;
378 } else if (verbose_options[i] == "gc") {
379 gLogVerbosity.gc = true;
380 } else if (verbose_options[i] == "jdwp") {
381 gLogVerbosity.jdwp = true;
382 } else if (verbose_options[i] == "jni") {
383 gLogVerbosity.jni = true;
384 } else if (verbose_options[i] == "monitor") {
385 gLogVerbosity.monitor = true;
386 } else if (verbose_options[i] == "startup") {
387 gLogVerbosity.startup = true;
388 } else if (verbose_options[i] == "third-party-jni") {
389 gLogVerbosity.third_party_jni = true;
390 } else if (verbose_options[i] == "threads") {
391 gLogVerbosity.threads = true;
392 } else {
393 Usage("Unknown -verbose option %s", verbose_options[i].c_str());
394 return false;
395 }
396 }
397 } else if (StartsWith(option, "-Xlockprofthreshold:")) {
398 if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) {
399 return false;
400 }
401 } else if (StartsWith(option, "-Xstacktracefile:")) {
402 if (!ParseStringAfterChar(option, ':', &stack_trace_file_)) {
403 return false;
404 }
405 } else if (option == "sensitiveThread") {
406 const void* hook = options[i].second;
407 hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(hook));
408 } else if (option == "vfprintf") {
409 const void* hook = options[i].second;
410 if (hook == nullptr) {
411 Usage("vfprintf argument was NULL");
412 return false;
413 }
414 hook_vfprintf_ =
415 reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook));
416 } else if (option == "exit") {
417 const void* hook = options[i].second;
418 if (hook == nullptr) {
419 Usage("exit argument was NULL");
420 return false;
421 }
422 hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook));
423 } else if (option == "abort") {
424 const void* hook = options[i].second;
425 if (hook == nullptr) {
426 Usage("abort was NULL");
427 return false;
428 }
429 hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook));
430 } else if (option == "host-prefix") {
431 host_prefix_ = reinterpret_cast<const char*>(options[i].second);
432 } else if (option == "-Xmethod-trace") {
433 method_trace_ = true;
434 } else if (StartsWith(option, "-Xmethod-trace-file:")) {
435 method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:"));
436 } else if (StartsWith(option, "-Xmethod-trace-file-size:")) {
437 if (!ParseUnsignedInteger(option, ':', &method_trace_file_size_)) {
438 return false;
439 }
440 } else if (option == "-Xprofile:threadcpuclock") {
441 Trace::SetDefaultClockSource(kProfilerClockSourceThreadCpu);
442 } else if (option == "-Xprofile:wallclock") {
443 Trace::SetDefaultClockSource(kProfilerClockSourceWall);
444 } else if (option == "-Xprofile:dualclock") {
445 Trace::SetDefaultClockSource(kProfilerClockSourceDual);
446 } else if (StartsWith(option, "-Xprofile:")) {
447 if (!ParseStringAfterChar(option, ';', &profile_output_filename_)) {
448 return false;
449 }
450 profile_ = true;
451 } else if (StartsWith(option, "-Xprofile-period:")) {
452 if (!ParseUnsignedInteger(option, ':', &profile_period_s_)) {
453 return false;
454 }
455 } else if (StartsWith(option, "-Xprofile-duration:")) {
456 if (!ParseUnsignedInteger(option, ':', &profile_duration_s_)) {
457 return false;
458 }
459 } else if (StartsWith(option, "-Xprofile-interval:")) {
460 if (!ParseUnsignedInteger(option, ':', &profile_interval_us_)) {
461 return false;
462 }
463 } else if (StartsWith(option, "-Xprofile-backoff:")) {
464 if (!ParseDouble(option, ':', 1.0, 10.0, &profile_backoff_coefficient_)) {
465 return false;
466 }
467 } else if (option == "-Xcompiler-option") {
468 i++;
469 if (i == options.size()) {
470 Usage("Missing required compiler option for %s", option.c_str());
471 return false;
472 }
473 compiler_options_.push_back(options[i].first);
474 } else if (option == "-Ximage-compiler-option") {
475 i++;
476 if (i == options.size()) {
477 Usage("Missing required compiler option for %s", option.c_str());
478 return false;
479 }
480 image_compiler_options_.push_back(options[i].first);
481 } else if (StartsWith(option, "-ea:") ||
482 StartsWith(option, "-da:") ||
483 StartsWith(option, "-enableassertions:") ||
484 StartsWith(option, "-disableassertions:") ||
485 (option == "-esa") ||
486 (option == "-dsa") ||
487 (option == "-enablesystemassertions") ||
488 (option == "-disablesystemassertions") ||
489 StartsWith(option, "-Xverify:") ||
490 (option == "-Xrs") ||
491 StartsWith(option, "-Xint:") ||
492 StartsWith(option, "-Xdexopt:") ||
493 (option == "-Xnoquithandler") ||
494 StartsWith(option, "-Xjniopts:") ||
495 StartsWith(option, "-Xjnigreflimit:") ||
496 (option == "-Xgenregmap") ||
497 (option == "-Xnogenregmap") ||
498 StartsWith(option, "-Xverifyopt:") ||
499 (option == "-Xcheckdexsum") ||
500 (option == "-Xincludeselectedop") ||
501 StartsWith(option, "-Xjitop:") ||
502 (option == "-Xincludeselectedmethod") ||
503 StartsWith(option, "-Xjitthreshold:") ||
504 StartsWith(option, "-Xjitcodecachesize:") ||
505 (option == "-Xjitblocking") ||
506 StartsWith(option, "-Xjitmethod:") ||
507 StartsWith(option, "-Xjitclass:") ||
508 StartsWith(option, "-Xjitoffset:") ||
509 StartsWith(option, "-Xjitconfig:") ||
510 (option == "-Xjitcheckcg") ||
511 (option == "-Xjitverbose") ||
512 (option == "-Xjitprofile") ||
513 (option == "-Xjitdisableopt") ||
514 (option == "-Xjitsuspendpoll") ||
515 StartsWith(option, "-XX:mainThreadStackSize=")) {
516 // Ignored for backwards compatibility.
517 } else if (!ignore_unrecognized) {
518 Usage("Unrecognized option %s", option.c_str());
519 return false;
520 }
521 }
522
523 // If a reference to the dalvik core.jar snuck in, replace it with
524 // the art specific version. This can happen with on device
525 // boot.art/boot.oat generation by GenerateImage which relies on the
526 // value of BOOTCLASSPATH.
527 std::string core_jar("/core.jar");
528 size_t core_jar_pos = boot_class_path_string_.find(core_jar);
529 if (core_jar_pos != std::string::npos) {
530 boot_class_path_string_.replace(core_jar_pos, core_jar.size(), "/core-libart.jar");
531 }
532
533 if (compiler_callbacks_ == nullptr && image_.empty()) {
534 image_ += GetAndroidRoot();
535 image_ += "/framework/boot.art";
536 }
537 if (heap_growth_limit_ == 0) {
538 heap_growth_limit_ = heap_maximum_size_;
539 }
540 if (background_collector_type_ == gc::kCollectorTypeNone) {
541 background_collector_type_ = collector_type_;
542 }
543 return true;
544}
545
546void ParsedOptions::Exit(int status) {
547 hook_exit_(status);
548}
549
550void ParsedOptions::Abort() {
551 hook_abort_();
552}
553
554void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) {
555 hook_vfprintf_(stderr, fmt, ap);
556}
557
558void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) {
559 va_list ap;
560 va_start(ap, fmt);
561 UsageMessageV(stream, fmt, ap);
562 va_end(ap);
563}
564
565void ParsedOptions::Usage(const char* fmt, ...) {
566 bool error = (fmt != nullptr);
567 FILE* stream = error ? stderr : stdout;
568
569 if (fmt != nullptr) {
570 va_list ap;
571 va_start(ap, fmt);
572 UsageMessageV(stream, fmt, ap);
573 va_end(ap);
574 }
575
576 const char* program = "dalvikvm";
577 UsageMessage(stream, "%s: [options] class [argument ...]\n", program);
578 UsageMessage(stream, "\n");
579 UsageMessage(stream, "The following standard options are supported:\n");
580 UsageMessage(stream, " -classpath classpath (-cp classpath)\n");
581 UsageMessage(stream, " -Dproperty=value\n");
582 UsageMessage(stream, " -verbose:tag ('gc', 'jni', or 'class')\n");
583 UsageMessage(stream, " -showversion\n");
584 UsageMessage(stream, " -help\n");
585 UsageMessage(stream, " -agentlib:jdwp=options\n");
586 UsageMessage(stream, "\n");
587
588 UsageMessage(stream, "The following extended options are supported:\n");
589 UsageMessage(stream, " -Xrunjdwp:<options>\n");
590 UsageMessage(stream, " -Xbootclasspath:bootclasspath\n");
591 UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n");
592 UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n");
593 UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n");
594 UsageMessage(stream, " -XssN (stack size)\n");
595 UsageMessage(stream, " -Xint\n");
596 UsageMessage(stream, "\n");
597
598 UsageMessage(stream, "The following Dalvik options are supported:\n");
599 UsageMessage(stream, " -Xzygote\n");
600 UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n");
601 UsageMessage(stream, " -Xstacktracefile:<filename>\n");
602 UsageMessage(stream, " -Xgc:[no]preverify\n");
603 UsageMessage(stream, " -Xgc:[no]postverify\n");
604 UsageMessage(stream, " -XX:+DisableExplicitGC\n");
605 UsageMessage(stream, " -XX:HeapGrowthLimit=N\n");
606 UsageMessage(stream, " -XX:HeapMinFree=N\n");
607 UsageMessage(stream, " -XX:HeapMaxFree=N\n");
608 UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n");
609 UsageMessage(stream, " -XX:LowMemoryMode\n");
610 UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n");
611 UsageMessage(stream, "\n");
612
613 UsageMessage(stream, "The following unique to ART options are supported:\n");
614 UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n");
615 UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n");
616 UsageMessage(stream, " -Ximage:filename\n");
617 UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n");
618 UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n");
619 UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n");
620 UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n");
621 UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n");
622 UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n");
623 UsageMessage(stream, " -XX:IgnoreMaxFootprint\n");
624 UsageMessage(stream, " -XX:UseTLAB\n");
625 UsageMessage(stream, " -XX:BackgroundGC=none\n");
626 UsageMessage(stream, " -Xmethod-trace\n");
627 UsageMessage(stream, " -Xmethod-trace-file:filename");
628 UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n");
629 UsageMessage(stream, " -Xprofile=filename\n");
630 UsageMessage(stream, " -Xprofile-period:integervalue\n");
631 UsageMessage(stream, " -Xprofile-duration:integervalue\n");
632 UsageMessage(stream, " -Xprofile-interval:integervalue\n");
633 UsageMessage(stream, " -Xprofile-backoff:integervalue\n");
634 UsageMessage(stream, " -Xcompiler-option dex2oat-option\n");
635 UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n");
636 UsageMessage(stream, "\n");
637
638 UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n");
639 UsageMessage(stream, " -ea[:<package name>... |:<class name>]\n");
640 UsageMessage(stream, " -da[:<package name>... |:<class name>]\n");
641 UsageMessage(stream, " (-enableassertions, -disableassertions)\n");
642 UsageMessage(stream, " -esa\n");
643 UsageMessage(stream, " -dsa\n");
644 UsageMessage(stream, " (-enablesystemassertions, -disablesystemassertions)\n");
645 UsageMessage(stream, " -Xverify:{none,remote,all}\n");
646 UsageMessage(stream, " -Xrs\n");
647 UsageMessage(stream, " -Xint:portable, -Xint:fast, -Xint:jit\n");
648 UsageMessage(stream, " -Xdexopt:{none,verified,all,full}\n");
649 UsageMessage(stream, " -Xnoquithandler\n");
650 UsageMessage(stream, " -Xjniopts:{warnonly,forcecopy}\n");
651 UsageMessage(stream, " -Xjnigreflimit:integervalue\n");
652 UsageMessage(stream, " -Xgc:[no]precise\n");
653 UsageMessage(stream, " -Xgc:[no]verifycardtable\n");
654 UsageMessage(stream, " -X[no]genregmap\n");
655 UsageMessage(stream, " -Xverifyopt:[no]checkmon\n");
656 UsageMessage(stream, " -Xcheckdexsum\n");
657 UsageMessage(stream, " -Xincludeselectedop\n");
658 UsageMessage(stream, " -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*\n");
659 UsageMessage(stream, " -Xincludeselectedmethod\n");
660 UsageMessage(stream, " -Xjitthreshold:integervalue\n");
661 UsageMessage(stream, " -Xjitcodecachesize:decimalvalueofkbytes\n");
662 UsageMessage(stream, " -Xjitblocking\n");
663 UsageMessage(stream, " -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\\;replace)\n");
664 UsageMessage(stream, " -Xjitclass:classname[,classname]*\n");
665 UsageMessage(stream, " -Xjitoffset:offset[,offset]\n");
666 UsageMessage(stream, " -Xjitconfig:filename\n");
667 UsageMessage(stream, " -Xjitcheckcg\n");
668 UsageMessage(stream, " -Xjitverbose\n");
669 UsageMessage(stream, " -Xjitprofile\n");
670 UsageMessage(stream, " -Xjitdisableopt\n");
671 UsageMessage(stream, " -Xjitsuspendpoll\n");
672 UsageMessage(stream, " -XX:mainThreadStackSize=N\n");
673 UsageMessage(stream, "\n");
674
675 Exit((error) ? 1 : 0);
676}
677
678bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) {
679 std::string::size_type colon = s.find(c);
680 if (colon == std::string::npos) {
681 Usage("Missing char %c in option %s", c, s.c_str());
682 return false;
683 }
684 // Add one to remove the char we were trimming until.
685 *parsed_value = s.substr(colon + 1);
686 return true;
687}
688
689bool ParsedOptions::ParseInteger(const std::string& s, char after_char, int* parsed_value) {
690 std::string::size_type colon = s.find(after_char);
691 if (colon == std::string::npos) {
692 Usage("Missing char %c in option %s", after_char, s.c_str());
693 return false;
694 }
695 const char* begin = &s[colon + 1];
696 char* end;
697 size_t result = strtoul(begin, &end, 10);
698 if (begin == end || *end != '\0') {
699 Usage("Failed to parse integer from %s ", s.c_str());
700 return false;
701 }
702 *parsed_value = result;
703 return true;
704}
705
706bool ParsedOptions::ParseUnsignedInteger(const std::string& s, char after_char,
707 unsigned int* parsed_value) {
708 int i;
709 if (!ParseInteger(s, after_char, &i)) {
710 return false;
711 }
712 if (i < 0) {
713 Usage("Negative value %d passed for unsigned option %s", i, s.c_str());
714 return false;
715 }
716 *parsed_value = i;
717 return true;
718}
719
720bool ParsedOptions::ParseDouble(const std::string& option, char after_char,
721 double min, double max, double* parsed_value) {
722 std::string substring;
723 if (!ParseStringAfterChar(option, after_char, &substring)) {
724 return false;
725 }
726 std::istringstream iss(substring);
727 double value;
728 iss >> value;
729 // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range.
730 const bool sane_val = iss.eof() && (value >= min) && (value <= max);
731 if (!sane_val) {
732 Usage("Invalid double value %s for option %s", option.c_str());
733 return false;
734 }
735 *parsed_value = value;
736 return true;
737}
738
739} // namespace art