blob: ef20d1ce2256e12982c79125dc51e7255e7a3dda [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
Dave Allisonb373e092014-02-20 16:06:36 -080019#ifdef HAVE_ANDROID_OS
20#include "cutils/properties.h"
21#endif
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080022
Ian Rogers576ca0c2014-06-06 15:58:22 -070023#include "base/stringpiece.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080024#include "debugger.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070025#include "gc/heap.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080026#include "monitor.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070027#include "utils.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080028
29namespace art {
30
31ParsedOptions* ParsedOptions::Create(const Runtime::Options& options, bool ignore_unrecognized) {
Ian Rogers700a4022014-05-19 16:49:03 -070032 std::unique_ptr<ParsedOptions> parsed(new ParsedOptions());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080033 if (parsed->Parse(options, ignore_unrecognized)) {
34 return parsed.release();
35 }
36 return nullptr;
37}
38
39// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
40// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
41// [gG] gigabytes.
42//
43// "s" should point just past the "-Xm?" part of the string.
44// "div" specifies a divisor, e.g. 1024 if the value must be a multiple
45// of 1024.
46//
47// The spec says the -Xmx and -Xms options must be multiples of 1024. It
48// doesn't say anything about -Xss.
49//
50// Returns 0 (a useless size) if "s" is malformed or specifies a low or
51// non-evenly-divisible value.
52//
53size_t ParseMemoryOption(const char* s, size_t div) {
54 // strtoul accepts a leading [+-], which we don't want,
55 // so make sure our string starts with a decimal digit.
56 if (isdigit(*s)) {
57 char* s2;
58 size_t val = strtoul(s, &s2, 10);
59 if (s2 != s) {
60 // s2 should be pointing just after the number.
61 // If this is the end of the string, the user
62 // has specified a number of bytes. Otherwise,
63 // there should be exactly one more character
64 // that specifies a multiplier.
65 if (*s2 != '\0') {
66 // The remainder of the string is either a single multiplier
67 // character, or nothing to indicate that the value is in
68 // bytes.
69 char c = *s2++;
70 if (*s2 == '\0') {
71 size_t mul;
72 if (c == '\0') {
73 mul = 1;
74 } else if (c == 'k' || c == 'K') {
75 mul = KB;
76 } else if (c == 'm' || c == 'M') {
77 mul = MB;
78 } else if (c == 'g' || c == 'G') {
79 mul = GB;
80 } else {
81 // Unknown multiplier character.
82 return 0;
83 }
84
85 if (val <= std::numeric_limits<size_t>::max() / mul) {
86 val *= mul;
87 } else {
88 // Clamp to a multiple of 1024.
89 val = std::numeric_limits<size_t>::max() & ~(1024-1);
90 }
91 } else {
92 // There's more than one character after the numeric part.
93 return 0;
94 }
95 }
96 // The man page says that a -Xm value must be a multiple of 1024.
97 if (val % div == 0) {
98 return val;
99 }
100 }
101 }
102 return 0;
103}
104
105static gc::CollectorType ParseCollectorType(const std::string& option) {
106 if (option == "MS" || option == "nonconcurrent") {
107 return gc::kCollectorTypeMS;
108 } else if (option == "CMS" || option == "concurrent") {
109 return gc::kCollectorTypeCMS;
110 } else if (option == "SS") {
111 return gc::kCollectorTypeSS;
112 } else if (option == "GSS") {
113 return gc::kCollectorTypeGSS;
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700114 } else if (option == "CC") {
115 return gc::kCollectorTypeCC;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800116 } else {
117 return gc::kCollectorTypeNone;
118 }
119}
120
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700121bool ParsedOptions::ParseXGcOption(const std::string& option) {
122 std::vector<std::string> gc_options;
123 Split(option.substr(strlen("-Xgc:")), ',', gc_options);
124 for (const std::string& gc_option : gc_options) {
125 gc::CollectorType collector_type = ParseCollectorType(gc_option);
126 if (collector_type != gc::kCollectorTypeNone) {
127 collector_type_ = collector_type;
128 } else if (gc_option == "preverify") {
129 verify_pre_gc_heap_ = true;
130 } else if (gc_option == "nopreverify") {
131 verify_pre_gc_heap_ = false;
132 } else if (gc_option == "presweepingverify") {
133 verify_pre_sweeping_heap_ = true;
134 } else if (gc_option == "nopresweepingverify") {
135 verify_pre_sweeping_heap_ = false;
136 } else if (gc_option == "postverify") {
137 verify_post_gc_heap_ = true;
138 } else if (gc_option == "nopostverify") {
139 verify_post_gc_heap_ = false;
140 } else if (gc_option == "preverify_rosalloc") {
141 verify_pre_gc_rosalloc_ = true;
142 } else if (gc_option == "nopreverify_rosalloc") {
143 verify_pre_gc_rosalloc_ = false;
144 } else if (gc_option == "presweepingverify_rosalloc") {
145 verify_pre_sweeping_rosalloc_ = true;
146 } else if (gc_option == "nopresweepingverify_rosalloc") {
147 verify_pre_sweeping_rosalloc_ = false;
148 } else if (gc_option == "postverify_rosalloc") {
149 verify_post_gc_rosalloc_ = true;
150 } else if (gc_option == "nopostverify_rosalloc") {
151 verify_post_gc_rosalloc_ = false;
152 } else if ((gc_option == "precise") ||
153 (gc_option == "noprecise") ||
154 (gc_option == "verifycardtable") ||
155 (gc_option == "noverifycardtable")) {
156 // Ignored for backwards compatibility.
157 } else {
158 Usage("Unknown -Xgc option %s\n", gc_option.c_str());
159 return false;
160 }
161 }
162 return true;
163}
164
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800165bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecognized) {
166 const char* boot_class_path_string = getenv("BOOTCLASSPATH");
167 if (boot_class_path_string != NULL) {
168 boot_class_path_string_ = boot_class_path_string;
169 }
170 const char* class_path_string = getenv("CLASSPATH");
171 if (class_path_string != NULL) {
172 class_path_string_ = class_path_string;
173 }
174 // -Xcheck:jni is off by default for regular builds but on by default in debug builds.
175 check_jni_ = kIsDebugBuild;
176
177 heap_initial_size_ = gc::Heap::kDefaultInitialSize;
178 heap_maximum_size_ = gc::Heap::kDefaultMaximumSize;
179 heap_min_free_ = gc::Heap::kDefaultMinFree;
180 heap_max_free_ = gc::Heap::kDefaultMaxFree;
181 heap_target_utilization_ = gc::Heap::kDefaultTargetUtilization;
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700182 foreground_heap_growth_multiplier_ = gc::Heap::kDefaultHeapGrowthMultiplier;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800183 heap_growth_limit_ = 0; // 0 means no growth limit .
184 // Default to number of processors minus one since the main GC thread also does work.
185 parallel_gc_threads_ = sysconf(_SC_NPROCESSORS_CONF) - 1;
186 // Only the main GC thread, no workers.
187 conc_gc_threads_ = 0;
Hiroshi Yamauchi1dda0602014-05-12 12:32:32 -0700188 // The default GC type is set in makefiles.
189#if ART_DEFAULT_GC_TYPE_IS_CMS
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800190 collector_type_ = gc::kCollectorTypeCMS;
Hiroshi Yamauchi1dda0602014-05-12 12:32:32 -0700191#elif ART_DEFAULT_GC_TYPE_IS_SS
192 collector_type_ = gc::kCollectorTypeSS;
193#elif ART_DEFAULT_GC_TYPE_IS_GSS
194 collector_type_ = gc::kCollectorTypeGSS;
195#else
196#error "ART default GC type must be set"
197#endif
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800198 // If background_collector_type_ is kCollectorTypeNone, it defaults to the collector_type_ after
199 // parsing options.
Mathieu Chartiera033f702014-06-17 12:01:06 -0700200 background_collector_type_ = gc::kCollectorTypeSS;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800201 stack_size_ = 0; // 0 means default.
202 max_spins_before_thin_lock_inflation_ = Monitor::kDefaultMaxSpinsBeforeThinLockInflation;
203 low_memory_mode_ = false;
204 use_tlab_ = false;
205 verify_pre_gc_heap_ = false;
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700206 // Pre sweeping is the one that usually fails if the GC corrupted the heap.
207 verify_pre_sweeping_heap_ = kIsDebugBuild;
208 verify_post_gc_heap_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800209 verify_pre_gc_rosalloc_ = kIsDebugBuild;
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700210 verify_pre_sweeping_rosalloc_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800211 verify_post_gc_rosalloc_ = false;
212
213 compiler_callbacks_ = nullptr;
214 is_zygote_ = false;
Hiroshi Yamauchie63a7452014-02-27 14:44:36 -0800215 if (kPoisonHeapReferences) {
216 // kPoisonHeapReferences currently works only with the interpreter only.
217 // TODO: make it work with the compiler.
218 interpreter_only_ = true;
219 } else {
220 interpreter_only_ = false;
221 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800222 is_explicit_gc_disabled_ = false;
223
224 long_pause_log_threshold_ = gc::Heap::kDefaultLongPauseLogThreshold;
225 long_gc_log_threshold_ = gc::Heap::kDefaultLongGCLogThreshold;
226 dump_gc_performance_on_shutdown_ = false;
227 ignore_max_footprint_ = false;
228
229 lock_profiling_threshold_ = 0;
230 hook_is_sensitive_thread_ = NULL;
231
232 hook_vfprintf_ = vfprintf;
233 hook_exit_ = exit;
234 hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort.
235
236// gLogVerbosity.class_linker = true; // TODO: don't check this in!
237// gLogVerbosity.compiler = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800238// gLogVerbosity.gc = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700239// gLogVerbosity.heap = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800240// gLogVerbosity.jdwp = true; // TODO: don't check this in!
241// gLogVerbosity.jni = true; // TODO: don't check this in!
242// gLogVerbosity.monitor = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700243// gLogVerbosity.profiler = true; // TODO: don't check this in!
244// gLogVerbosity.signals = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800245// gLogVerbosity.startup = true; // TODO: don't check this in!
246// gLogVerbosity.third_party_jni = true; // TODO: don't check this in!
247// gLogVerbosity.threads = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700248// gLogVerbosity.verifier = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800249
250 method_trace_ = false;
251 method_trace_file_ = "/data/method-trace-file.bin";
252 method_trace_file_size_ = 10 * MB;
253
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800254 profile_clock_source_ = kDefaultProfilerClockSource;
255
Jeff Hao4a200f52014-04-01 14:58:49 -0700256 verify_ = true;
Narayan Kamath11d9f062014-04-23 20:24:57 +0100257 image_isa_ = kRuntimeISA;
Jeff Hao4a200f52014-04-01 14:58:49 -0700258
Dave Allisonb373e092014-02-20 16:06:36 -0800259 // Default to explicit checks. Switch off with -implicit-checks:.
260 // or setprop dalvik.vm.implicit_checks check1,check2,...
261#ifdef HAVE_ANDROID_OS
262 {
263 char buf[PROP_VALUE_MAX];
Dave Allisonc0cf9442014-05-30 11:25:06 -0700264 property_get("dalvik.vm.implicit_checks", buf, "null,stack");
Dave Allisonb373e092014-02-20 16:06:36 -0800265 std::string checks(buf);
266 std::vector<std::string> checkvec;
267 Split(checks, ',', checkvec);
Dave Allisondd2e8252014-03-20 14:45:17 -0700268 explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck |
269 kExplicitStackOverflowCheck;
Dave Allisonb373e092014-02-20 16:06:36 -0800270 for (auto& str : checkvec) {
271 std::string val = Trim(str);
272 if (val == "none") {
273 explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck |
Dave Allisondd2e8252014-03-20 14:45:17 -0700274 kExplicitStackOverflowCheck;
Dave Allisonb373e092014-02-20 16:06:36 -0800275 } else if (val == "null") {
276 explicit_checks_ &= ~kExplicitNullCheck;
277 } else if (val == "suspend") {
278 explicit_checks_ &= ~kExplicitSuspendCheck;
279 } else if (val == "stack") {
280 explicit_checks_ &= ~kExplicitStackOverflowCheck;
281 } else if (val == "all") {
282 explicit_checks_ = 0;
283 }
284 }
285 }
286#else
287 explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck |
288 kExplicitStackOverflowCheck;
289#endif
290
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800291 for (size_t i = 0; i < options.size(); ++i) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800292 if (true && options[0].first == "-Xzygote") {
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800293 LOG(INFO) << "option[" << i << "]=" << options[i].first;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800294 }
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800295 }
296 for (size_t i = 0; i < options.size(); ++i) {
297 const std::string option(options[i].first);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800298 if (StartsWith(option, "-help")) {
299 Usage(nullptr);
300 return false;
301 } else if (StartsWith(option, "-showversion")) {
302 UsageMessage(stdout, "ART version %s\n", Runtime::GetVersion());
303 Exit(0);
304 } else if (StartsWith(option, "-Xbootclasspath:")) {
305 boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data();
306 } else if (option == "-classpath" || option == "-cp") {
307 // TODO: support -Djava.class.path
308 i++;
309 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700310 Usage("Missing required class path value for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800311 return false;
312 }
313 const StringPiece& value = options[i].first;
314 class_path_string_ = value.data();
315 } else if (option == "bootclasspath") {
316 boot_class_path_
317 = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second);
318 } else if (StartsWith(option, "-Ximage:")) {
319 if (!ParseStringAfterChar(option, ':', &image_)) {
320 return false;
321 }
322 } else if (StartsWith(option, "-Xcheck:jni")) {
323 check_jni_ = true;
324 } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) {
325 std::string tail(option.substr(option[1] == 'X' ? 10 : 15));
326 // TODO: move parsing logic out of Dbg
327 if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) {
328 if (tail != "help") {
329 UsageMessage(stderr, "Failed to parse JDWP option %s\n", tail.c_str());
330 }
331 Usage("Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
332 "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n\n");
333 return false;
334 }
335 } else if (StartsWith(option, "-Xms")) {
336 size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024);
337 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700338 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800339 return false;
340 }
341 heap_initial_size_ = size;
342 } else if (StartsWith(option, "-Xmx")) {
343 size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024);
344 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700345 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800346 return false;
347 }
348 heap_maximum_size_ = size;
349 } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) {
350 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024);
351 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700352 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800353 return false;
354 }
355 heap_growth_limit_ = size;
356 } else if (StartsWith(option, "-XX:HeapMinFree=")) {
357 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024);
358 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700359 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800360 return false;
361 }
362 heap_min_free_ = size;
363 } else if (StartsWith(option, "-XX:HeapMaxFree=")) {
364 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024);
365 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700366 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800367 return false;
368 }
369 heap_max_free_ = size;
370 } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) {
371 if (!ParseDouble(option, '=', 0.1, 0.9, &heap_target_utilization_)) {
372 return false;
373 }
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700374 } else if (StartsWith(option, "-XX:ForegroundHeapGrowthMultiplier=")) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700375 if (!ParseDouble(option, '=', 0.1, 10.0, &foreground_heap_growth_multiplier_)) {
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700376 return false;
377 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800378 } else if (StartsWith(option, "-XX:ParallelGCThreads=")) {
379 if (!ParseUnsignedInteger(option, '=', &parallel_gc_threads_)) {
380 return false;
381 }
382 } else if (StartsWith(option, "-XX:ConcGCThreads=")) {
383 if (!ParseUnsignedInteger(option, '=', &conc_gc_threads_)) {
384 return false;
385 }
386 } else if (StartsWith(option, "-Xss")) {
387 size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1);
388 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700389 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800390 return false;
391 }
392 stack_size_ = size;
393 } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) {
394 if (!ParseUnsignedInteger(option, '=', &max_spins_before_thin_lock_inflation_)) {
395 return false;
396 }
397 } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) {
Andreas Gampe39d92182014-03-05 16:46:44 -0800398 unsigned int value;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800399 if (!ParseUnsignedInteger(option, '=', &value)) {
400 return false;
401 }
402 long_pause_log_threshold_ = MsToNs(value);
403 } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) {
Andreas Gampe39d92182014-03-05 16:46:44 -0800404 unsigned int value;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800405 if (!ParseUnsignedInteger(option, '=', &value)) {
406 return false;
407 }
408 long_gc_log_threshold_ = MsToNs(value);
409 } else if (option == "-XX:DumpGCPerformanceOnShutdown") {
410 dump_gc_performance_on_shutdown_ = true;
411 } else if (option == "-XX:IgnoreMaxFootprint") {
412 ignore_max_footprint_ = true;
413 } else if (option == "-XX:LowMemoryMode") {
414 low_memory_mode_ = true;
415 } else if (option == "-XX:UseTLAB") {
416 use_tlab_ = true;
417 } else if (StartsWith(option, "-D")) {
418 properties_.push_back(option.substr(strlen("-D")));
419 } else if (StartsWith(option, "-Xjnitrace:")) {
420 jni_trace_ = option.substr(strlen("-Xjnitrace:"));
421 } else if (option == "compilercallbacks") {
422 compiler_callbacks_ =
423 reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second));
Narayan Kamath11d9f062014-04-23 20:24:57 +0100424 } else if (option == "imageinstructionset") {
425 image_isa_ = GetInstructionSetFromString(
426 reinterpret_cast<const char*>(options[i].second));
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800427 } else if (option == "-Xzygote") {
428 is_zygote_ = true;
429 } else if (option == "-Xint") {
430 interpreter_only_ = true;
431 } else if (StartsWith(option, "-Xgc:")) {
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700432 if (!ParseXGcOption(option)) {
433 return false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800434 }
435 } else if (StartsWith(option, "-XX:BackgroundGC=")) {
436 std::string substring;
437 if (!ParseStringAfterChar(option, '=', &substring)) {
438 return false;
439 }
440 gc::CollectorType collector_type = ParseCollectorType(substring);
441 if (collector_type != gc::kCollectorTypeNone) {
442 background_collector_type_ = collector_type;
443 } else {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700444 Usage("Unknown -XX:BackgroundGC option %s\n", substring.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800445 return false;
446 }
447 } else if (option == "-XX:+DisableExplicitGC") {
448 is_explicit_gc_disabled_ = true;
449 } else if (StartsWith(option, "-verbose:")) {
450 std::vector<std::string> verbose_options;
451 Split(option.substr(strlen("-verbose:")), ',', verbose_options);
452 for (size_t i = 0; i < verbose_options.size(); ++i) {
453 if (verbose_options[i] == "class") {
454 gLogVerbosity.class_linker = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800455 } else if (verbose_options[i] == "compiler") {
456 gLogVerbosity.compiler = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800457 } else if (verbose_options[i] == "gc") {
458 gLogVerbosity.gc = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700459 } else if (verbose_options[i] == "heap") {
460 gLogVerbosity.heap = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800461 } else if (verbose_options[i] == "jdwp") {
462 gLogVerbosity.jdwp = true;
463 } else if (verbose_options[i] == "jni") {
464 gLogVerbosity.jni = true;
465 } else if (verbose_options[i] == "monitor") {
466 gLogVerbosity.monitor = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700467 } else if (verbose_options[i] == "profiler") {
468 gLogVerbosity.profiler = true;
469 } else if (verbose_options[i] == "signals") {
470 gLogVerbosity.signals = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800471 } else if (verbose_options[i] == "startup") {
472 gLogVerbosity.startup = true;
473 } else if (verbose_options[i] == "third-party-jni") {
474 gLogVerbosity.third_party_jni = true;
475 } else if (verbose_options[i] == "threads") {
476 gLogVerbosity.threads = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700477 } else if (verbose_options[i] == "verifier") {
478 gLogVerbosity.verifier = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800479 } else {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700480 Usage("Unknown -verbose option %s\n", verbose_options[i].c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800481 return false;
482 }
483 }
Mingyao Yang42d65c52014-04-18 16:49:39 -0700484 } else if (StartsWith(option, "-verbose-methods:")) {
485 gLogVerbosity.compiler = false;
486 Split(option.substr(strlen("-verbose-methods:")), ',', gVerboseMethods);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800487 } else if (StartsWith(option, "-Xlockprofthreshold:")) {
488 if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) {
489 return false;
490 }
491 } else if (StartsWith(option, "-Xstacktracefile:")) {
492 if (!ParseStringAfterChar(option, ':', &stack_trace_file_)) {
493 return false;
494 }
495 } else if (option == "sensitiveThread") {
496 const void* hook = options[i].second;
497 hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(hook));
498 } else if (option == "vfprintf") {
499 const void* hook = options[i].second;
500 if (hook == nullptr) {
501 Usage("vfprintf argument was NULL");
502 return false;
503 }
504 hook_vfprintf_ =
505 reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook));
506 } else if (option == "exit") {
507 const void* hook = options[i].second;
508 if (hook == nullptr) {
509 Usage("exit argument was NULL");
510 return false;
511 }
512 hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook));
513 } else if (option == "abort") {
514 const void* hook = options[i].second;
515 if (hook == nullptr) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700516 Usage("abort was NULL\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800517 return false;
518 }
519 hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook));
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800520 } else if (option == "-Xmethod-trace") {
521 method_trace_ = true;
522 } else if (StartsWith(option, "-Xmethod-trace-file:")) {
523 method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:"));
524 } else if (StartsWith(option, "-Xmethod-trace-file-size:")) {
525 if (!ParseUnsignedInteger(option, ':', &method_trace_file_size_)) {
526 return false;
527 }
528 } else if (option == "-Xprofile:threadcpuclock") {
529 Trace::SetDefaultClockSource(kProfilerClockSourceThreadCpu);
530 } else if (option == "-Xprofile:wallclock") {
531 Trace::SetDefaultClockSource(kProfilerClockSourceWall);
532 } else if (option == "-Xprofile:dualclock") {
533 Trace::SetDefaultClockSource(kProfilerClockSourceDual);
Calin Juravlec1b643c2014-05-30 23:44:11 +0100534 } else if (option == "-Xenable-profiler") {
535 profiler_options_.enabled_ = true;
Wei Jin2221e3b2014-05-21 18:35:19 -0700536 } else if (StartsWith(option, "-Xprofile-filename:")) {
Ian Rogersf7fd3cb2014-05-19 22:57:34 -0700537 if (!ParseStringAfterChar(option, ':', &profile_output_filename_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800538 return false;
539 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800540 } else if (StartsWith(option, "-Xprofile-period:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100541 if (!ParseUnsignedInteger(option, ':', &profiler_options_.period_s_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800542 return false;
543 }
544 } else if (StartsWith(option, "-Xprofile-duration:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100545 if (!ParseUnsignedInteger(option, ':', &profiler_options_.duration_s_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800546 return false;
547 }
548 } else if (StartsWith(option, "-Xprofile-interval:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100549 if (!ParseUnsignedInteger(option, ':', &profiler_options_.interval_us_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800550 return false;
551 }
552 } else if (StartsWith(option, "-Xprofile-backoff:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100553 if (!ParseDouble(option, ':', 1.0, 10.0, &profiler_options_.backoff_coefficient_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800554 return false;
555 }
Calin Juravlec1b643c2014-05-30 23:44:11 +0100556 } else if (option == "-Xprofile-start-immediately") {
557 profiler_options_.start_immediately_ = true;
558 } else if (StartsWith(option, "-Xprofile-top-k-threshold:")) {
Calin Juravlec321c9b2014-06-11 19:04:35 +0100559 if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_threshold_)) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100560 return false;
561 }
562 } else if (StartsWith(option, "-Xprofile-top-k-change-threshold:")) {
Calin Juravlec321c9b2014-06-11 19:04:35 +0100563 if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_change_threshold_)) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100564 return false;
565 }
Wei Jina93b0bb2014-06-09 16:19:15 -0700566 } else if (option == "-Xprofile-type:method") {
567 profiler_options_.profile_type_ = kProfilerMethod;
568 } else if (option == "-Xprofile-type:dexpc") {
569 profiler_options_.profile_type_ = kProfilerMethodAndDexPC;
Dave Allisonb373e092014-02-20 16:06:36 -0800570 } else if (StartsWith(option, "-implicit-checks:")) {
571 std::string checks;
572 if (!ParseStringAfterChar(option, ':', &checks)) {
573 return false;
574 }
575 std::vector<std::string> checkvec;
576 Split(checks, ',', checkvec);
577 for (auto& str : checkvec) {
578 std::string val = Trim(str);
579 if (val == "none") {
580 explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck |
581 kExplicitStackOverflowCheck;
582 } else if (val == "null") {
583 explicit_checks_ &= ~kExplicitNullCheck;
584 } else if (val == "suspend") {
585 explicit_checks_ &= ~kExplicitSuspendCheck;
586 } else if (val == "stack") {
587 explicit_checks_ &= ~kExplicitStackOverflowCheck;
588 } else if (val == "all") {
589 explicit_checks_ = 0;
590 } else {
591 return false;
592 }
593 }
594 } else if (StartsWith(option, "-explicit-checks:")) {
595 std::string checks;
596 if (!ParseStringAfterChar(option, ':', &checks)) {
597 return false;
598 }
599 std::vector<std::string> checkvec;
600 Split(checks, ',', checkvec);
601 for (auto& str : checkvec) {
602 std::string val = Trim(str);
603 if (val == "none") {
604 explicit_checks_ = 0;
605 } else if (val == "null") {
606 explicit_checks_ |= kExplicitNullCheck;
607 } else if (val == "suspend") {
608 explicit_checks_ |= kExplicitSuspendCheck;
609 } else if (val == "stack") {
610 explicit_checks_ |= kExplicitStackOverflowCheck;
611 } else if (val == "all") {
612 explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck |
613 kExplicitStackOverflowCheck;
614 } else {
615 return false;
616 }
617 }
Tsu Chiang Chuang12e6d742014-05-22 10:22:25 -0700618 } else if (StartsWith(option, "-Xcompiler:")) {
619 if (!ParseStringAfterChar(option, ':', &compiler_executable_)) {
620 return false;
621 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800622 } else if (option == "-Xcompiler-option") {
623 i++;
624 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700625 Usage("Missing required compiler option for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800626 return false;
627 }
628 compiler_options_.push_back(options[i].first);
629 } else if (option == "-Ximage-compiler-option") {
630 i++;
631 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700632 Usage("Missing required compiler option for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800633 return false;
634 }
635 image_compiler_options_.push_back(options[i].first);
Jeff Hao4a200f52014-04-01 14:58:49 -0700636 } else if (StartsWith(option, "-Xverify:")) {
637 std::string verify_mode = option.substr(strlen("-Xverify:"));
638 if (verify_mode == "none") {
639 verify_ = false;
640 } else if (verify_mode == "remote" || verify_mode == "all") {
641 verify_ = true;
642 } else {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700643 Usage("Unknown -Xverify option %s\n", verify_mode.c_str());
Jeff Hao4a200f52014-04-01 14:58:49 -0700644 return false;
645 }
Yevgeny Roubana6119a22014-03-24 11:31:24 +0700646 } else if (StartsWith(option, "-ea") ||
647 StartsWith(option, "-da") ||
648 StartsWith(option, "-enableassertions") ||
649 StartsWith(option, "-disableassertions") ||
Dave Allisonb373e092014-02-20 16:06:36 -0800650 (option == "--runtime-arg") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800651 (option == "-esa") ||
652 (option == "-dsa") ||
653 (option == "-enablesystemassertions") ||
654 (option == "-disablesystemassertions") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800655 (option == "-Xrs") ||
656 StartsWith(option, "-Xint:") ||
657 StartsWith(option, "-Xdexopt:") ||
658 (option == "-Xnoquithandler") ||
659 StartsWith(option, "-Xjniopts:") ||
660 StartsWith(option, "-Xjnigreflimit:") ||
661 (option == "-Xgenregmap") ||
662 (option == "-Xnogenregmap") ||
663 StartsWith(option, "-Xverifyopt:") ||
664 (option == "-Xcheckdexsum") ||
665 (option == "-Xincludeselectedop") ||
666 StartsWith(option, "-Xjitop:") ||
667 (option == "-Xincludeselectedmethod") ||
668 StartsWith(option, "-Xjitthreshold:") ||
669 StartsWith(option, "-Xjitcodecachesize:") ||
670 (option == "-Xjitblocking") ||
671 StartsWith(option, "-Xjitmethod:") ||
672 StartsWith(option, "-Xjitclass:") ||
673 StartsWith(option, "-Xjitoffset:") ||
674 StartsWith(option, "-Xjitconfig:") ||
675 (option == "-Xjitcheckcg") ||
676 (option == "-Xjitverbose") ||
677 (option == "-Xjitprofile") ||
678 (option == "-Xjitdisableopt") ||
679 (option == "-Xjitsuspendpoll") ||
680 StartsWith(option, "-XX:mainThreadStackSize=")) {
681 // Ignored for backwards compatibility.
682 } else if (!ignore_unrecognized) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700683 Usage("Unrecognized option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800684 return false;
685 }
686 }
687
688 // If a reference to the dalvik core.jar snuck in, replace it with
689 // the art specific version. This can happen with on device
690 // boot.art/boot.oat generation by GenerateImage which relies on the
691 // value of BOOTCLASSPATH.
Kenny Rootd5185342014-05-13 14:47:05 -0700692#if defined(ART_TARGET)
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800693 std::string core_jar("/core.jar");
Kenny Rootd5185342014-05-13 14:47:05 -0700694 std::string core_libart_jar("/core-libart.jar");
695#else
696 // The host uses hostdex files.
697 std::string core_jar("/core-hostdex.jar");
698 std::string core_libart_jar("/core-libart-hostdex.jar");
699#endif
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800700 size_t core_jar_pos = boot_class_path_string_.find(core_jar);
701 if (core_jar_pos != std::string::npos) {
Kenny Rootd5185342014-05-13 14:47:05 -0700702 boot_class_path_string_.replace(core_jar_pos, core_jar.size(), core_libart_jar);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800703 }
704
705 if (compiler_callbacks_ == nullptr && image_.empty()) {
706 image_ += GetAndroidRoot();
Brian Carlstrom3ac05bb2014-05-13 19:31:38 -0700707 image_ += "/framework/boot.art";
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800708 }
709 if (heap_growth_limit_ == 0) {
710 heap_growth_limit_ = heap_maximum_size_;
711 }
712 if (background_collector_type_ == gc::kCollectorTypeNone) {
713 background_collector_type_ = collector_type_;
714 }
715 return true;
Narayan Kamath11d9f062014-04-23 20:24:57 +0100716} // NOLINT(readability/fn_size)
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800717
718void ParsedOptions::Exit(int status) {
719 hook_exit_(status);
720}
721
722void ParsedOptions::Abort() {
723 hook_abort_();
724}
725
726void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) {
727 hook_vfprintf_(stderr, fmt, ap);
728}
729
730void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) {
731 va_list ap;
732 va_start(ap, fmt);
733 UsageMessageV(stream, fmt, ap);
734 va_end(ap);
735}
736
737void ParsedOptions::Usage(const char* fmt, ...) {
738 bool error = (fmt != nullptr);
739 FILE* stream = error ? stderr : stdout;
740
741 if (fmt != nullptr) {
742 va_list ap;
743 va_start(ap, fmt);
744 UsageMessageV(stream, fmt, ap);
745 va_end(ap);
746 }
747
748 const char* program = "dalvikvm";
749 UsageMessage(stream, "%s: [options] class [argument ...]\n", program);
750 UsageMessage(stream, "\n");
751 UsageMessage(stream, "The following standard options are supported:\n");
752 UsageMessage(stream, " -classpath classpath (-cp classpath)\n");
753 UsageMessage(stream, " -Dproperty=value\n");
754 UsageMessage(stream, " -verbose:tag ('gc', 'jni', or 'class')\n");
755 UsageMessage(stream, " -showversion\n");
756 UsageMessage(stream, " -help\n");
757 UsageMessage(stream, " -agentlib:jdwp=options\n");
758 UsageMessage(stream, "\n");
759
760 UsageMessage(stream, "The following extended options are supported:\n");
761 UsageMessage(stream, " -Xrunjdwp:<options>\n");
762 UsageMessage(stream, " -Xbootclasspath:bootclasspath\n");
763 UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n");
764 UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n");
765 UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n");
766 UsageMessage(stream, " -XssN (stack size)\n");
767 UsageMessage(stream, " -Xint\n");
768 UsageMessage(stream, "\n");
769
770 UsageMessage(stream, "The following Dalvik options are supported:\n");
771 UsageMessage(stream, " -Xzygote\n");
772 UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n");
773 UsageMessage(stream, " -Xstacktracefile:<filename>\n");
774 UsageMessage(stream, " -Xgc:[no]preverify\n");
775 UsageMessage(stream, " -Xgc:[no]postverify\n");
776 UsageMessage(stream, " -XX:+DisableExplicitGC\n");
777 UsageMessage(stream, " -XX:HeapGrowthLimit=N\n");
778 UsageMessage(stream, " -XX:HeapMinFree=N\n");
779 UsageMessage(stream, " -XX:HeapMaxFree=N\n");
780 UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n");
Mathieu Chartier455820e2014-04-18 12:02:39 -0700781 UsageMessage(stream, " -XX:ForegroundHeapGrowthMultiplier=doublevalue\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800782 UsageMessage(stream, " -XX:LowMemoryMode\n");
783 UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n");
784 UsageMessage(stream, "\n");
785
786 UsageMessage(stream, "The following unique to ART options are supported:\n");
787 UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n");
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700788 UsageMessage(stream, " -Xgc:[no]postsweepingverify_rosalloc\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800789 UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n");
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700790 UsageMessage(stream, " -Xgc:[no]presweepingverify\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800791 UsageMessage(stream, " -Ximage:filename\n");
792 UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n");
793 UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n");
794 UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n");
795 UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n");
796 UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n");
797 UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n");
798 UsageMessage(stream, " -XX:IgnoreMaxFootprint\n");
799 UsageMessage(stream, " -XX:UseTLAB\n");
800 UsageMessage(stream, " -XX:BackgroundGC=none\n");
801 UsageMessage(stream, " -Xmethod-trace\n");
802 UsageMessage(stream, " -Xmethod-trace-file:filename");
803 UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n");
Calin Juravlec1b643c2014-05-30 23:44:11 +0100804 UsageMessage(stream, " -Xenable-profiler\n");
Wei Jin2221e3b2014-05-21 18:35:19 -0700805 UsageMessage(stream, " -Xprofile-filename:filename\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800806 UsageMessage(stream, " -Xprofile-period:integervalue\n");
807 UsageMessage(stream, " -Xprofile-duration:integervalue\n");
808 UsageMessage(stream, " -Xprofile-interval:integervalue\n");
Calin Juravle54c73ca2014-05-22 12:13:54 +0100809 UsageMessage(stream, " -Xprofile-backoff:doublevalue\n");
Calin Juravlec1b643c2014-05-30 23:44:11 +0100810 UsageMessage(stream, " -Xprofile-start-immediately\n");
811 UsageMessage(stream, " -Xprofile-top-k-threshold:doublevalue\n");
812 UsageMessage(stream, " -Xprofile-top-k-change-threshold:doublevalue\n");
Wei Jina93b0bb2014-06-09 16:19:15 -0700813 UsageMessage(stream, " -Xprofile-type:{method,dexpc}\n");
Tsu Chiang Chuang12e6d742014-05-22 10:22:25 -0700814 UsageMessage(stream, " -Xcompiler:filename\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800815 UsageMessage(stream, " -Xcompiler-option dex2oat-option\n");
816 UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n");
817 UsageMessage(stream, "\n");
818
819 UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n");
820 UsageMessage(stream, " -ea[:<package name>... |:<class name>]\n");
821 UsageMessage(stream, " -da[:<package name>... |:<class name>]\n");
822 UsageMessage(stream, " (-enableassertions, -disableassertions)\n");
823 UsageMessage(stream, " -esa\n");
824 UsageMessage(stream, " -dsa\n");
825 UsageMessage(stream, " (-enablesystemassertions, -disablesystemassertions)\n");
826 UsageMessage(stream, " -Xverify:{none,remote,all}\n");
827 UsageMessage(stream, " -Xrs\n");
828 UsageMessage(stream, " -Xint:portable, -Xint:fast, -Xint:jit\n");
829 UsageMessage(stream, " -Xdexopt:{none,verified,all,full}\n");
830 UsageMessage(stream, " -Xnoquithandler\n");
831 UsageMessage(stream, " -Xjniopts:{warnonly,forcecopy}\n");
832 UsageMessage(stream, " -Xjnigreflimit:integervalue\n");
833 UsageMessage(stream, " -Xgc:[no]precise\n");
834 UsageMessage(stream, " -Xgc:[no]verifycardtable\n");
835 UsageMessage(stream, " -X[no]genregmap\n");
836 UsageMessage(stream, " -Xverifyopt:[no]checkmon\n");
837 UsageMessage(stream, " -Xcheckdexsum\n");
838 UsageMessage(stream, " -Xincludeselectedop\n");
839 UsageMessage(stream, " -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*\n");
840 UsageMessage(stream, " -Xincludeselectedmethod\n");
841 UsageMessage(stream, " -Xjitthreshold:integervalue\n");
842 UsageMessage(stream, " -Xjitcodecachesize:decimalvalueofkbytes\n");
843 UsageMessage(stream, " -Xjitblocking\n");
844 UsageMessage(stream, " -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\\;replace)\n");
845 UsageMessage(stream, " -Xjitclass:classname[,classname]*\n");
846 UsageMessage(stream, " -Xjitoffset:offset[,offset]\n");
847 UsageMessage(stream, " -Xjitconfig:filename\n");
848 UsageMessage(stream, " -Xjitcheckcg\n");
849 UsageMessage(stream, " -Xjitverbose\n");
850 UsageMessage(stream, " -Xjitprofile\n");
851 UsageMessage(stream, " -Xjitdisableopt\n");
852 UsageMessage(stream, " -Xjitsuspendpoll\n");
853 UsageMessage(stream, " -XX:mainThreadStackSize=N\n");
854 UsageMessage(stream, "\n");
855
856 Exit((error) ? 1 : 0);
857}
858
859bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) {
860 std::string::size_type colon = s.find(c);
861 if (colon == std::string::npos) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700862 Usage("Missing char %c in option %s\n", c, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800863 return false;
864 }
865 // Add one to remove the char we were trimming until.
866 *parsed_value = s.substr(colon + 1);
867 return true;
868}
869
870bool ParsedOptions::ParseInteger(const std::string& s, char after_char, int* parsed_value) {
871 std::string::size_type colon = s.find(after_char);
872 if (colon == std::string::npos) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700873 Usage("Missing char %c in option %s\n", after_char, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800874 return false;
875 }
876 const char* begin = &s[colon + 1];
877 char* end;
878 size_t result = strtoul(begin, &end, 10);
879 if (begin == end || *end != '\0') {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700880 Usage("Failed to parse integer from %s\n", s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800881 return false;
882 }
883 *parsed_value = result;
884 return true;
885}
886
887bool ParsedOptions::ParseUnsignedInteger(const std::string& s, char after_char,
888 unsigned int* parsed_value) {
889 int i;
890 if (!ParseInteger(s, after_char, &i)) {
891 return false;
892 }
893 if (i < 0) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700894 Usage("Negative value %d passed for unsigned option %s\n", i, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800895 return false;
896 }
897 *parsed_value = i;
898 return true;
899}
900
901bool ParsedOptions::ParseDouble(const std::string& option, char after_char,
902 double min, double max, double* parsed_value) {
903 std::string substring;
904 if (!ParseStringAfterChar(option, after_char, &substring)) {
905 return false;
906 }
Dave Allison999385c2014-05-20 15:16:02 -0700907 bool sane_val = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800908 double value;
Dave Allison999385c2014-05-20 15:16:02 -0700909 if (false) {
910 // TODO: this doesn't seem to work on the emulator. b/15114595
911 std::stringstream iss(substring);
912 iss >> value;
913 // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range.
914 sane_val = iss.eof() && (value >= min) && (value <= max);
915 } else {
916 char* end = nullptr;
917 value = strtod(substring.c_str(), &end);
918 sane_val = *end == '\0' && value >= min && value <= max;
919 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800920 if (!sane_val) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700921 Usage("Invalid double value %s for option %s\n", substring.c_str(), option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800922 return false;
923 }
924 *parsed_value = value;
925 return true;
926}
927
928} // namespace art