blob: 37db4624be7b062d09347f2098ffebe0b3cebfc0 [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;
Hiroshi Yamauchie63a7452014-02-27 14:44:36 -0800150 if (kPoisonHeapReferences) {
151 // kPoisonHeapReferences currently works only with the interpreter only.
152 // TODO: make it work with the compiler.
153 interpreter_only_ = true;
154 } else {
155 interpreter_only_ = false;
156 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800157 is_explicit_gc_disabled_ = false;
158
159 long_pause_log_threshold_ = gc::Heap::kDefaultLongPauseLogThreshold;
160 long_gc_log_threshold_ = gc::Heap::kDefaultLongGCLogThreshold;
161 dump_gc_performance_on_shutdown_ = false;
162 ignore_max_footprint_ = false;
163
164 lock_profiling_threshold_ = 0;
165 hook_is_sensitive_thread_ = NULL;
166
167 hook_vfprintf_ = vfprintf;
168 hook_exit_ = exit;
169 hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort.
170
171// gLogVerbosity.class_linker = true; // TODO: don't check this in!
172// gLogVerbosity.compiler = true; // TODO: don't check this in!
173// gLogVerbosity.verifier = true; // TODO: don't check this in!
174// gLogVerbosity.heap = true; // TODO: don't check this in!
175// gLogVerbosity.gc = true; // TODO: don't check this in!
176// gLogVerbosity.jdwp = true; // TODO: don't check this in!
177// gLogVerbosity.jni = true; // TODO: don't check this in!
178// gLogVerbosity.monitor = true; // TODO: don't check this in!
179// gLogVerbosity.startup = true; // TODO: don't check this in!
180// gLogVerbosity.third_party_jni = true; // TODO: don't check this in!
181// gLogVerbosity.threads = true; // TODO: don't check this in!
182
183 method_trace_ = false;
184 method_trace_file_ = "/data/method-trace-file.bin";
185 method_trace_file_size_ = 10 * MB;
186
187 profile_ = false;
188 profile_period_s_ = 10; // Seconds.
189 profile_duration_s_ = 20; // Seconds.
190 profile_interval_us_ = 500; // Microseconds.
191 profile_backoff_coefficient_ = 2.0;
192 profile_clock_source_ = kDefaultProfilerClockSource;
193
194 for (size_t i = 0; i < options.size(); ++i) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800195 if (true && options[0].first == "-Xzygote") {
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800196 LOG(INFO) << "option[" << i << "]=" << options[i].first;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800197 }
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800198 }
199 for (size_t i = 0; i < options.size(); ++i) {
200 const std::string option(options[i].first);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800201 if (StartsWith(option, "-help")) {
202 Usage(nullptr);
203 return false;
204 } else if (StartsWith(option, "-showversion")) {
205 UsageMessage(stdout, "ART version %s\n", Runtime::GetVersion());
206 Exit(0);
207 } else if (StartsWith(option, "-Xbootclasspath:")) {
208 boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data();
209 } else if (option == "-classpath" || option == "-cp") {
210 // TODO: support -Djava.class.path
211 i++;
212 if (i == options.size()) {
213 Usage("Missing required class path value for %s", option.c_str());
214 return false;
215 }
216 const StringPiece& value = options[i].first;
217 class_path_string_ = value.data();
218 } else if (option == "bootclasspath") {
219 boot_class_path_
220 = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second);
221 } else if (StartsWith(option, "-Ximage:")) {
222 if (!ParseStringAfterChar(option, ':', &image_)) {
223 return false;
224 }
225 } else if (StartsWith(option, "-Xcheck:jni")) {
226 check_jni_ = true;
227 } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) {
228 std::string tail(option.substr(option[1] == 'X' ? 10 : 15));
229 // TODO: move parsing logic out of Dbg
230 if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) {
231 if (tail != "help") {
232 UsageMessage(stderr, "Failed to parse JDWP option %s\n", tail.c_str());
233 }
234 Usage("Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
235 "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n\n");
236 return false;
237 }
238 } else if (StartsWith(option, "-Xms")) {
239 size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024);
240 if (size == 0) {
241 Usage("Failed to parse memory option %s", option.c_str());
242 return false;
243 }
244 heap_initial_size_ = size;
245 } else if (StartsWith(option, "-Xmx")) {
246 size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024);
247 if (size == 0) {
248 Usage("Failed to parse memory option %s", option.c_str());
249 return false;
250 }
251 heap_maximum_size_ = size;
252 } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) {
253 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024);
254 if (size == 0) {
255 Usage("Failed to parse memory option %s", option.c_str());
256 return false;
257 }
258 heap_growth_limit_ = size;
259 } else if (StartsWith(option, "-XX:HeapMinFree=")) {
260 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024);
261 if (size == 0) {
262 Usage("Failed to parse memory option %s", option.c_str());
263 return false;
264 }
265 heap_min_free_ = size;
266 } else if (StartsWith(option, "-XX:HeapMaxFree=")) {
267 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024);
268 if (size == 0) {
269 Usage("Failed to parse memory option %s", option.c_str());
270 return false;
271 }
272 heap_max_free_ = size;
273 } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) {
274 if (!ParseDouble(option, '=', 0.1, 0.9, &heap_target_utilization_)) {
275 return false;
276 }
277 } else if (StartsWith(option, "-XX:ParallelGCThreads=")) {
278 if (!ParseUnsignedInteger(option, '=', &parallel_gc_threads_)) {
279 return false;
280 }
281 } else if (StartsWith(option, "-XX:ConcGCThreads=")) {
282 if (!ParseUnsignedInteger(option, '=', &conc_gc_threads_)) {
283 return false;
284 }
285 } else if (StartsWith(option, "-Xss")) {
286 size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1);
287 if (size == 0) {
288 Usage("Failed to parse memory option %s", option.c_str());
289 return false;
290 }
291 stack_size_ = size;
292 } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) {
293 if (!ParseUnsignedInteger(option, '=', &max_spins_before_thin_lock_inflation_)) {
294 return false;
295 }
296 } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) {
Andreas Gampe39d92182014-03-05 16:46:44 -0800297 unsigned int value;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800298 if (!ParseUnsignedInteger(option, '=', &value)) {
299 return false;
300 }
301 long_pause_log_threshold_ = MsToNs(value);
302 } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) {
Andreas Gampe39d92182014-03-05 16:46:44 -0800303 unsigned int value;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800304 if (!ParseUnsignedInteger(option, '=', &value)) {
305 return false;
306 }
307 long_gc_log_threshold_ = MsToNs(value);
308 } else if (option == "-XX:DumpGCPerformanceOnShutdown") {
309 dump_gc_performance_on_shutdown_ = true;
310 } else if (option == "-XX:IgnoreMaxFootprint") {
311 ignore_max_footprint_ = true;
312 } else if (option == "-XX:LowMemoryMode") {
313 low_memory_mode_ = true;
314 } else if (option == "-XX:UseTLAB") {
315 use_tlab_ = true;
316 } else if (StartsWith(option, "-D")) {
317 properties_.push_back(option.substr(strlen("-D")));
318 } else if (StartsWith(option, "-Xjnitrace:")) {
319 jni_trace_ = option.substr(strlen("-Xjnitrace:"));
320 } else if (option == "compilercallbacks") {
321 compiler_callbacks_ =
322 reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second));
323 } else if (option == "-Xzygote") {
324 is_zygote_ = true;
325 } else if (option == "-Xint") {
326 interpreter_only_ = true;
327 } else if (StartsWith(option, "-Xgc:")) {
328 std::vector<std::string> gc_options;
329 Split(option.substr(strlen("-Xgc:")), ',', gc_options);
330 for (const std::string& gc_option : gc_options) {
331 gc::CollectorType collector_type = ParseCollectorType(gc_option);
332 if (collector_type != gc::kCollectorTypeNone) {
333 collector_type_ = collector_type;
334 } else if (gc_option == "preverify") {
335 verify_pre_gc_heap_ = true;
336 } else if (gc_option == "nopreverify") {
337 verify_pre_gc_heap_ = false;
338 } else if (gc_option == "postverify") {
339 verify_post_gc_heap_ = true;
340 } else if (gc_option == "nopostverify") {
341 verify_post_gc_heap_ = false;
342 } else if (gc_option == "preverify_rosalloc") {
343 verify_pre_gc_rosalloc_ = true;
344 } else if (gc_option == "nopreverify_rosalloc") {
345 verify_pre_gc_rosalloc_ = false;
346 } else if (gc_option == "postverify_rosalloc") {
347 verify_post_gc_rosalloc_ = true;
348 } else if (gc_option == "nopostverify_rosalloc") {
349 verify_post_gc_rosalloc_ = false;
350 } else if ((gc_option == "precise") ||
351 (gc_option == "noprecise") ||
352 (gc_option == "verifycardtable") ||
353 (gc_option == "noverifycardtable")) {
354 // Ignored for backwards compatibility.
355 } else {
356 Usage("Unknown -Xgc option %s", gc_option.c_str());
357 return false;
358 }
359 }
360 } else if (StartsWith(option, "-XX:BackgroundGC=")) {
361 std::string substring;
362 if (!ParseStringAfterChar(option, '=', &substring)) {
363 return false;
364 }
365 gc::CollectorType collector_type = ParseCollectorType(substring);
366 if (collector_type != gc::kCollectorTypeNone) {
367 background_collector_type_ = collector_type;
368 } else {
369 Usage("Unknown -XX:BackgroundGC option %s", substring.c_str());
370 return false;
371 }
372 } else if (option == "-XX:+DisableExplicitGC") {
373 is_explicit_gc_disabled_ = true;
374 } else if (StartsWith(option, "-verbose:")) {
375 std::vector<std::string> verbose_options;
376 Split(option.substr(strlen("-verbose:")), ',', verbose_options);
377 for (size_t i = 0; i < verbose_options.size(); ++i) {
378 if (verbose_options[i] == "class") {
379 gLogVerbosity.class_linker = true;
380 } else if (verbose_options[i] == "verifier") {
381 gLogVerbosity.verifier = true;
382 } else if (verbose_options[i] == "compiler") {
383 gLogVerbosity.compiler = true;
384 } else if (verbose_options[i] == "heap") {
385 gLogVerbosity.heap = true;
386 } else if (verbose_options[i] == "gc") {
387 gLogVerbosity.gc = true;
388 } else if (verbose_options[i] == "jdwp") {
389 gLogVerbosity.jdwp = true;
390 } else if (verbose_options[i] == "jni") {
391 gLogVerbosity.jni = true;
392 } else if (verbose_options[i] == "monitor") {
393 gLogVerbosity.monitor = true;
394 } else if (verbose_options[i] == "startup") {
395 gLogVerbosity.startup = true;
396 } else if (verbose_options[i] == "third-party-jni") {
397 gLogVerbosity.third_party_jni = true;
398 } else if (verbose_options[i] == "threads") {
399 gLogVerbosity.threads = true;
400 } else {
401 Usage("Unknown -verbose option %s", verbose_options[i].c_str());
402 return false;
403 }
404 }
405 } else if (StartsWith(option, "-Xlockprofthreshold:")) {
406 if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) {
407 return false;
408 }
409 } else if (StartsWith(option, "-Xstacktracefile:")) {
410 if (!ParseStringAfterChar(option, ':', &stack_trace_file_)) {
411 return false;
412 }
413 } else if (option == "sensitiveThread") {
414 const void* hook = options[i].second;
415 hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(hook));
416 } else if (option == "vfprintf") {
417 const void* hook = options[i].second;
418 if (hook == nullptr) {
419 Usage("vfprintf argument was NULL");
420 return false;
421 }
422 hook_vfprintf_ =
423 reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook));
424 } else if (option == "exit") {
425 const void* hook = options[i].second;
426 if (hook == nullptr) {
427 Usage("exit argument was NULL");
428 return false;
429 }
430 hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook));
431 } else if (option == "abort") {
432 const void* hook = options[i].second;
433 if (hook == nullptr) {
434 Usage("abort was NULL");
435 return false;
436 }
437 hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook));
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800438 } else if (option == "-Xmethod-trace") {
439 method_trace_ = true;
440 } else if (StartsWith(option, "-Xmethod-trace-file:")) {
441 method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:"));
442 } else if (StartsWith(option, "-Xmethod-trace-file-size:")) {
443 if (!ParseUnsignedInteger(option, ':', &method_trace_file_size_)) {
444 return false;
445 }
446 } else if (option == "-Xprofile:threadcpuclock") {
447 Trace::SetDefaultClockSource(kProfilerClockSourceThreadCpu);
448 } else if (option == "-Xprofile:wallclock") {
449 Trace::SetDefaultClockSource(kProfilerClockSourceWall);
450 } else if (option == "-Xprofile:dualclock") {
451 Trace::SetDefaultClockSource(kProfilerClockSourceDual);
452 } else if (StartsWith(option, "-Xprofile:")) {
453 if (!ParseStringAfterChar(option, ';', &profile_output_filename_)) {
454 return false;
455 }
456 profile_ = true;
457 } else if (StartsWith(option, "-Xprofile-period:")) {
458 if (!ParseUnsignedInteger(option, ':', &profile_period_s_)) {
459 return false;
460 }
461 } else if (StartsWith(option, "-Xprofile-duration:")) {
462 if (!ParseUnsignedInteger(option, ':', &profile_duration_s_)) {
463 return false;
464 }
465 } else if (StartsWith(option, "-Xprofile-interval:")) {
466 if (!ParseUnsignedInteger(option, ':', &profile_interval_us_)) {
467 return false;
468 }
469 } else if (StartsWith(option, "-Xprofile-backoff:")) {
470 if (!ParseDouble(option, ':', 1.0, 10.0, &profile_backoff_coefficient_)) {
471 return false;
472 }
473 } else if (option == "-Xcompiler-option") {
474 i++;
475 if (i == options.size()) {
476 Usage("Missing required compiler option for %s", option.c_str());
477 return false;
478 }
479 compiler_options_.push_back(options[i].first);
480 } else if (option == "-Ximage-compiler-option") {
481 i++;
482 if (i == options.size()) {
483 Usage("Missing required compiler option for %s", option.c_str());
484 return false;
485 }
486 image_compiler_options_.push_back(options[i].first);
487 } else if (StartsWith(option, "-ea:") ||
488 StartsWith(option, "-da:") ||
489 StartsWith(option, "-enableassertions:") ||
490 StartsWith(option, "-disableassertions:") ||
491 (option == "-esa") ||
492 (option == "-dsa") ||
493 (option == "-enablesystemassertions") ||
494 (option == "-disablesystemassertions") ||
495 StartsWith(option, "-Xverify:") ||
496 (option == "-Xrs") ||
497 StartsWith(option, "-Xint:") ||
498 StartsWith(option, "-Xdexopt:") ||
499 (option == "-Xnoquithandler") ||
500 StartsWith(option, "-Xjniopts:") ||
501 StartsWith(option, "-Xjnigreflimit:") ||
502 (option == "-Xgenregmap") ||
503 (option == "-Xnogenregmap") ||
504 StartsWith(option, "-Xverifyopt:") ||
505 (option == "-Xcheckdexsum") ||
506 (option == "-Xincludeselectedop") ||
507 StartsWith(option, "-Xjitop:") ||
508 (option == "-Xincludeselectedmethod") ||
509 StartsWith(option, "-Xjitthreshold:") ||
510 StartsWith(option, "-Xjitcodecachesize:") ||
511 (option == "-Xjitblocking") ||
512 StartsWith(option, "-Xjitmethod:") ||
513 StartsWith(option, "-Xjitclass:") ||
514 StartsWith(option, "-Xjitoffset:") ||
515 StartsWith(option, "-Xjitconfig:") ||
516 (option == "-Xjitcheckcg") ||
517 (option == "-Xjitverbose") ||
518 (option == "-Xjitprofile") ||
519 (option == "-Xjitdisableopt") ||
520 (option == "-Xjitsuspendpoll") ||
521 StartsWith(option, "-XX:mainThreadStackSize=")) {
522 // Ignored for backwards compatibility.
523 } else if (!ignore_unrecognized) {
524 Usage("Unrecognized option %s", option.c_str());
525 return false;
526 }
527 }
528
529 // If a reference to the dalvik core.jar snuck in, replace it with
530 // the art specific version. This can happen with on device
531 // boot.art/boot.oat generation by GenerateImage which relies on the
532 // value of BOOTCLASSPATH.
533 std::string core_jar("/core.jar");
534 size_t core_jar_pos = boot_class_path_string_.find(core_jar);
535 if (core_jar_pos != std::string::npos) {
536 boot_class_path_string_.replace(core_jar_pos, core_jar.size(), "/core-libart.jar");
537 }
538
539 if (compiler_callbacks_ == nullptr && image_.empty()) {
540 image_ += GetAndroidRoot();
541 image_ += "/framework/boot.art";
542 }
543 if (heap_growth_limit_ == 0) {
544 heap_growth_limit_ = heap_maximum_size_;
545 }
546 if (background_collector_type_ == gc::kCollectorTypeNone) {
547 background_collector_type_ = collector_type_;
548 }
549 return true;
550}
551
552void ParsedOptions::Exit(int status) {
553 hook_exit_(status);
554}
555
556void ParsedOptions::Abort() {
557 hook_abort_();
558}
559
560void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) {
561 hook_vfprintf_(stderr, fmt, ap);
562}
563
564void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) {
565 va_list ap;
566 va_start(ap, fmt);
567 UsageMessageV(stream, fmt, ap);
568 va_end(ap);
569}
570
571void ParsedOptions::Usage(const char* fmt, ...) {
572 bool error = (fmt != nullptr);
573 FILE* stream = error ? stderr : stdout;
574
575 if (fmt != nullptr) {
576 va_list ap;
577 va_start(ap, fmt);
578 UsageMessageV(stream, fmt, ap);
579 va_end(ap);
580 }
581
582 const char* program = "dalvikvm";
583 UsageMessage(stream, "%s: [options] class [argument ...]\n", program);
584 UsageMessage(stream, "\n");
585 UsageMessage(stream, "The following standard options are supported:\n");
586 UsageMessage(stream, " -classpath classpath (-cp classpath)\n");
587 UsageMessage(stream, " -Dproperty=value\n");
588 UsageMessage(stream, " -verbose:tag ('gc', 'jni', or 'class')\n");
589 UsageMessage(stream, " -showversion\n");
590 UsageMessage(stream, " -help\n");
591 UsageMessage(stream, " -agentlib:jdwp=options\n");
592 UsageMessage(stream, "\n");
593
594 UsageMessage(stream, "The following extended options are supported:\n");
595 UsageMessage(stream, " -Xrunjdwp:<options>\n");
596 UsageMessage(stream, " -Xbootclasspath:bootclasspath\n");
597 UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n");
598 UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n");
599 UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n");
600 UsageMessage(stream, " -XssN (stack size)\n");
601 UsageMessage(stream, " -Xint\n");
602 UsageMessage(stream, "\n");
603
604 UsageMessage(stream, "The following Dalvik options are supported:\n");
605 UsageMessage(stream, " -Xzygote\n");
606 UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n");
607 UsageMessage(stream, " -Xstacktracefile:<filename>\n");
608 UsageMessage(stream, " -Xgc:[no]preverify\n");
609 UsageMessage(stream, " -Xgc:[no]postverify\n");
610 UsageMessage(stream, " -XX:+DisableExplicitGC\n");
611 UsageMessage(stream, " -XX:HeapGrowthLimit=N\n");
612 UsageMessage(stream, " -XX:HeapMinFree=N\n");
613 UsageMessage(stream, " -XX:HeapMaxFree=N\n");
614 UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n");
615 UsageMessage(stream, " -XX:LowMemoryMode\n");
616 UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n");
617 UsageMessage(stream, "\n");
618
619 UsageMessage(stream, "The following unique to ART options are supported:\n");
620 UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n");
621 UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n");
622 UsageMessage(stream, " -Ximage:filename\n");
623 UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n");
624 UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n");
625 UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n");
626 UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n");
627 UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n");
628 UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n");
629 UsageMessage(stream, " -XX:IgnoreMaxFootprint\n");
630 UsageMessage(stream, " -XX:UseTLAB\n");
631 UsageMessage(stream, " -XX:BackgroundGC=none\n");
632 UsageMessage(stream, " -Xmethod-trace\n");
633 UsageMessage(stream, " -Xmethod-trace-file:filename");
634 UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n");
635 UsageMessage(stream, " -Xprofile=filename\n");
636 UsageMessage(stream, " -Xprofile-period:integervalue\n");
637 UsageMessage(stream, " -Xprofile-duration:integervalue\n");
638 UsageMessage(stream, " -Xprofile-interval:integervalue\n");
639 UsageMessage(stream, " -Xprofile-backoff:integervalue\n");
640 UsageMessage(stream, " -Xcompiler-option dex2oat-option\n");
641 UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n");
642 UsageMessage(stream, "\n");
643
644 UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n");
645 UsageMessage(stream, " -ea[:<package name>... |:<class name>]\n");
646 UsageMessage(stream, " -da[:<package name>... |:<class name>]\n");
647 UsageMessage(stream, " (-enableassertions, -disableassertions)\n");
648 UsageMessage(stream, " -esa\n");
649 UsageMessage(stream, " -dsa\n");
650 UsageMessage(stream, " (-enablesystemassertions, -disablesystemassertions)\n");
651 UsageMessage(stream, " -Xverify:{none,remote,all}\n");
652 UsageMessage(stream, " -Xrs\n");
653 UsageMessage(stream, " -Xint:portable, -Xint:fast, -Xint:jit\n");
654 UsageMessage(stream, " -Xdexopt:{none,verified,all,full}\n");
655 UsageMessage(stream, " -Xnoquithandler\n");
656 UsageMessage(stream, " -Xjniopts:{warnonly,forcecopy}\n");
657 UsageMessage(stream, " -Xjnigreflimit:integervalue\n");
658 UsageMessage(stream, " -Xgc:[no]precise\n");
659 UsageMessage(stream, " -Xgc:[no]verifycardtable\n");
660 UsageMessage(stream, " -X[no]genregmap\n");
661 UsageMessage(stream, " -Xverifyopt:[no]checkmon\n");
662 UsageMessage(stream, " -Xcheckdexsum\n");
663 UsageMessage(stream, " -Xincludeselectedop\n");
664 UsageMessage(stream, " -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*\n");
665 UsageMessage(stream, " -Xincludeselectedmethod\n");
666 UsageMessage(stream, " -Xjitthreshold:integervalue\n");
667 UsageMessage(stream, " -Xjitcodecachesize:decimalvalueofkbytes\n");
668 UsageMessage(stream, " -Xjitblocking\n");
669 UsageMessage(stream, " -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\\;replace)\n");
670 UsageMessage(stream, " -Xjitclass:classname[,classname]*\n");
671 UsageMessage(stream, " -Xjitoffset:offset[,offset]\n");
672 UsageMessage(stream, " -Xjitconfig:filename\n");
673 UsageMessage(stream, " -Xjitcheckcg\n");
674 UsageMessage(stream, " -Xjitverbose\n");
675 UsageMessage(stream, " -Xjitprofile\n");
676 UsageMessage(stream, " -Xjitdisableopt\n");
677 UsageMessage(stream, " -Xjitsuspendpoll\n");
678 UsageMessage(stream, " -XX:mainThreadStackSize=N\n");
679 UsageMessage(stream, "\n");
680
681 Exit((error) ? 1 : 0);
682}
683
684bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) {
685 std::string::size_type colon = s.find(c);
686 if (colon == std::string::npos) {
687 Usage("Missing char %c in option %s", c, s.c_str());
688 return false;
689 }
690 // Add one to remove the char we were trimming until.
691 *parsed_value = s.substr(colon + 1);
692 return true;
693}
694
695bool ParsedOptions::ParseInteger(const std::string& s, char after_char, int* parsed_value) {
696 std::string::size_type colon = s.find(after_char);
697 if (colon == std::string::npos) {
698 Usage("Missing char %c in option %s", after_char, s.c_str());
699 return false;
700 }
701 const char* begin = &s[colon + 1];
702 char* end;
703 size_t result = strtoul(begin, &end, 10);
704 if (begin == end || *end != '\0') {
705 Usage("Failed to parse integer from %s ", s.c_str());
706 return false;
707 }
708 *parsed_value = result;
709 return true;
710}
711
712bool ParsedOptions::ParseUnsignedInteger(const std::string& s, char after_char,
713 unsigned int* parsed_value) {
714 int i;
715 if (!ParseInteger(s, after_char, &i)) {
716 return false;
717 }
718 if (i < 0) {
719 Usage("Negative value %d passed for unsigned option %s", i, s.c_str());
720 return false;
721 }
722 *parsed_value = i;
723 return true;
724}
725
726bool ParsedOptions::ParseDouble(const std::string& option, char after_char,
727 double min, double max, double* parsed_value) {
728 std::string substring;
729 if (!ParseStringAfterChar(option, after_char, &substring)) {
730 return false;
731 }
732 std::istringstream iss(substring);
733 double value;
734 iss >> value;
735 // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range.
736 const bool sane_val = iss.eof() && (value >= min) && (value <= max);
737 if (!sane_val) {
738 Usage("Invalid double value %s for option %s", option.c_str());
739 return false;
740 }
741 *parsed_value = value;
742 return true;
743}
744
745} // namespace art