blob: 7ac5bceda26743e894fb953e7a479aae2b460764 [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 Rogerse63db272014-07-15 15:36:11 -070027#include "runtime.h"
28#include "trace.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070029#include "utils.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080030
31namespace art {
32
Ian Rogerse63db272014-07-15 15:36:11 -070033ParsedOptions* ParsedOptions::Create(const RuntimeOptions& options, bool ignore_unrecognized) {
Ian Rogers700a4022014-05-19 16:49:03 -070034 std::unique_ptr<ParsedOptions> parsed(new ParsedOptions());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080035 if (parsed->Parse(options, ignore_unrecognized)) {
36 return parsed.release();
37 }
38 return nullptr;
39}
40
41// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
42// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
43// [gG] gigabytes.
44//
45// "s" should point just past the "-Xm?" part of the string.
46// "div" specifies a divisor, e.g. 1024 if the value must be a multiple
47// of 1024.
48//
49// The spec says the -Xmx and -Xms options must be multiples of 1024. It
50// doesn't say anything about -Xss.
51//
52// Returns 0 (a useless size) if "s" is malformed or specifies a low or
53// non-evenly-divisible value.
54//
55size_t ParseMemoryOption(const char* s, size_t div) {
56 // strtoul accepts a leading [+-], which we don't want,
57 // so make sure our string starts with a decimal digit.
58 if (isdigit(*s)) {
59 char* s2;
60 size_t val = strtoul(s, &s2, 10);
61 if (s2 != s) {
62 // s2 should be pointing just after the number.
63 // If this is the end of the string, the user
64 // has specified a number of bytes. Otherwise,
65 // there should be exactly one more character
66 // that specifies a multiplier.
67 if (*s2 != '\0') {
68 // The remainder of the string is either a single multiplier
69 // character, or nothing to indicate that the value is in
70 // bytes.
71 char c = *s2++;
72 if (*s2 == '\0') {
73 size_t mul;
74 if (c == '\0') {
75 mul = 1;
76 } else if (c == 'k' || c == 'K') {
77 mul = KB;
78 } else if (c == 'm' || c == 'M') {
79 mul = MB;
80 } else if (c == 'g' || c == 'G') {
81 mul = GB;
82 } else {
83 // Unknown multiplier character.
84 return 0;
85 }
86
87 if (val <= std::numeric_limits<size_t>::max() / mul) {
88 val *= mul;
89 } else {
90 // Clamp to a multiple of 1024.
91 val = std::numeric_limits<size_t>::max() & ~(1024-1);
92 }
93 } else {
94 // There's more than one character after the numeric part.
95 return 0;
96 }
97 }
98 // The man page says that a -Xm value must be a multiple of 1024.
99 if (val % div == 0) {
100 return val;
101 }
102 }
103 }
104 return 0;
105}
106
107static gc::CollectorType ParseCollectorType(const std::string& option) {
108 if (option == "MS" || option == "nonconcurrent") {
109 return gc::kCollectorTypeMS;
110 } else if (option == "CMS" || option == "concurrent") {
111 return gc::kCollectorTypeCMS;
112 } else if (option == "SS") {
113 return gc::kCollectorTypeSS;
114 } else if (option == "GSS") {
115 return gc::kCollectorTypeGSS;
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700116 } else if (option == "CC") {
117 return gc::kCollectorTypeCC;
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700118 } else if (option == "MC") {
119 return gc::kCollectorTypeMC;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800120 } else {
121 return gc::kCollectorTypeNone;
122 }
123}
124
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700125bool ParsedOptions::ParseXGcOption(const std::string& option) {
126 std::vector<std::string> gc_options;
127 Split(option.substr(strlen("-Xgc:")), ',', gc_options);
128 for (const std::string& gc_option : gc_options) {
129 gc::CollectorType collector_type = ParseCollectorType(gc_option);
130 if (collector_type != gc::kCollectorTypeNone) {
131 collector_type_ = collector_type;
132 } else if (gc_option == "preverify") {
133 verify_pre_gc_heap_ = true;
134 } else if (gc_option == "nopreverify") {
135 verify_pre_gc_heap_ = false;
136 } else if (gc_option == "presweepingverify") {
137 verify_pre_sweeping_heap_ = true;
138 } else if (gc_option == "nopresweepingverify") {
139 verify_pre_sweeping_heap_ = false;
140 } else if (gc_option == "postverify") {
141 verify_post_gc_heap_ = true;
142 } else if (gc_option == "nopostverify") {
143 verify_post_gc_heap_ = false;
144 } else if (gc_option == "preverify_rosalloc") {
145 verify_pre_gc_rosalloc_ = true;
146 } else if (gc_option == "nopreverify_rosalloc") {
147 verify_pre_gc_rosalloc_ = false;
148 } else if (gc_option == "presweepingverify_rosalloc") {
149 verify_pre_sweeping_rosalloc_ = true;
150 } else if (gc_option == "nopresweepingverify_rosalloc") {
151 verify_pre_sweeping_rosalloc_ = false;
152 } else if (gc_option == "postverify_rosalloc") {
153 verify_post_gc_rosalloc_ = true;
154 } else if (gc_option == "nopostverify_rosalloc") {
155 verify_post_gc_rosalloc_ = false;
156 } else if ((gc_option == "precise") ||
157 (gc_option == "noprecise") ||
158 (gc_option == "verifycardtable") ||
159 (gc_option == "noverifycardtable")) {
160 // Ignored for backwards compatibility.
161 } else {
162 Usage("Unknown -Xgc option %s\n", gc_option.c_str());
163 return false;
164 }
165 }
166 return true;
167}
168
Ian Rogerse63db272014-07-15 15:36:11 -0700169bool ParsedOptions::Parse(const RuntimeOptions& options, bool ignore_unrecognized) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800170 const char* boot_class_path_string = getenv("BOOTCLASSPATH");
171 if (boot_class_path_string != NULL) {
172 boot_class_path_string_ = boot_class_path_string;
173 }
174 const char* class_path_string = getenv("CLASSPATH");
175 if (class_path_string != NULL) {
176 class_path_string_ = class_path_string;
177 }
178 // -Xcheck:jni is off by default for regular builds but on by default in debug builds.
179 check_jni_ = kIsDebugBuild;
Ian Rogers68d8b422014-07-17 11:09:10 -0700180 force_copy_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800181
182 heap_initial_size_ = gc::Heap::kDefaultInitialSize;
183 heap_maximum_size_ = gc::Heap::kDefaultMaximumSize;
184 heap_min_free_ = gc::Heap::kDefaultMinFree;
185 heap_max_free_ = gc::Heap::kDefaultMaxFree;
Mathieu Chartier6a7824d2014-08-22 14:53:04 -0700186 heap_non_moving_space_capacity_ = gc::Heap::kDefaultNonMovingSpaceCapacity;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800187 heap_target_utilization_ = gc::Heap::kDefaultTargetUtilization;
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700188 foreground_heap_growth_multiplier_ = gc::Heap::kDefaultHeapGrowthMultiplier;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800189 heap_growth_limit_ = 0; // 0 means no growth limit .
190 // Default to number of processors minus one since the main GC thread also does work.
191 parallel_gc_threads_ = sysconf(_SC_NPROCESSORS_CONF) - 1;
192 // Only the main GC thread, no workers.
193 conc_gc_threads_ = 0;
Hiroshi Yamauchi1dda0602014-05-12 12:32:32 -0700194 // The default GC type is set in makefiles.
195#if ART_DEFAULT_GC_TYPE_IS_CMS
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800196 collector_type_ = gc::kCollectorTypeCMS;
Hiroshi Yamauchi1dda0602014-05-12 12:32:32 -0700197#elif ART_DEFAULT_GC_TYPE_IS_SS
198 collector_type_ = gc::kCollectorTypeSS;
199#elif ART_DEFAULT_GC_TYPE_IS_GSS
200 collector_type_ = gc::kCollectorTypeGSS;
201#else
202#error "ART default GC type must be set"
203#endif
Zuo Wangf37a88b2014-07-10 04:26:41 -0700204 // If we are using homogeneous space compaction then default background compaction to off since
205 // homogeneous space compactions when we transition to not jank perceptible.
206 use_homogeneous_space_compaction_for_oom_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800207 // If background_collector_type_ is kCollectorTypeNone, it defaults to the collector_type_ after
Zuo Wangf37a88b2014-07-10 04:26:41 -0700208 // parsing options. If you set this to kCollectorTypeHSpaceCompact then we will do an hspace
209 // compaction when we transition to background instead of a normal collector transition.
Mathieu Chartier22e4bb02014-08-13 18:07:31 -0700210 background_collector_type_ = gc::kCollectorTypeHomogeneousSpaceCompact;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800211 stack_size_ = 0; // 0 means default.
212 max_spins_before_thin_lock_inflation_ = Monitor::kDefaultMaxSpinsBeforeThinLockInflation;
213 low_memory_mode_ = false;
214 use_tlab_ = false;
Zuo Wangf37a88b2014-07-10 04:26:41 -0700215 min_interval_homogeneous_space_compaction_by_oom_ = MsToNs(100 * 1000); // 100s.
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800216 verify_pre_gc_heap_ = false;
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700217 // Pre sweeping is the one that usually fails if the GC corrupted the heap.
218 verify_pre_sweeping_heap_ = kIsDebugBuild;
219 verify_post_gc_heap_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800220 verify_pre_gc_rosalloc_ = kIsDebugBuild;
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700221 verify_pre_sweeping_rosalloc_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800222 verify_post_gc_rosalloc_ = false;
223
224 compiler_callbacks_ = nullptr;
225 is_zygote_ = false;
Alex Lighta59dd802014-07-02 16:28:08 -0700226 must_relocate_ = kDefaultMustRelocate;
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100227 dex2oat_enabled_ = true;
Alex Light64ad14d2014-08-19 14:23:13 -0700228 image_dex2oat_enabled_ = true;
Hiroshi Yamauchie63a7452014-02-27 14:44:36 -0800229 if (kPoisonHeapReferences) {
230 // kPoisonHeapReferences currently works only with the interpreter only.
231 // TODO: make it work with the compiler.
232 interpreter_only_ = true;
233 } else {
234 interpreter_only_ = false;
235 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800236 is_explicit_gc_disabled_ = false;
237
238 long_pause_log_threshold_ = gc::Heap::kDefaultLongPauseLogThreshold;
239 long_gc_log_threshold_ = gc::Heap::kDefaultLongGCLogThreshold;
240 dump_gc_performance_on_shutdown_ = false;
241 ignore_max_footprint_ = false;
242
243 lock_profiling_threshold_ = 0;
244 hook_is_sensitive_thread_ = NULL;
245
246 hook_vfprintf_ = vfprintf;
247 hook_exit_ = exit;
248 hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort.
249
250// gLogVerbosity.class_linker = true; // TODO: don't check this in!
251// gLogVerbosity.compiler = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800252// gLogVerbosity.gc = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700253// gLogVerbosity.heap = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800254// gLogVerbosity.jdwp = true; // TODO: don't check this in!
255// gLogVerbosity.jni = true; // TODO: don't check this in!
256// gLogVerbosity.monitor = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700257// gLogVerbosity.profiler = true; // TODO: don't check this in!
258// gLogVerbosity.signals = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800259// gLogVerbosity.startup = true; // TODO: don't check this in!
260// gLogVerbosity.third_party_jni = true; // TODO: don't check this in!
261// gLogVerbosity.threads = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700262// gLogVerbosity.verifier = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800263
264 method_trace_ = false;
265 method_trace_file_ = "/data/method-trace-file.bin";
266 method_trace_file_size_ = 10 * MB;
267
Ian Rogerse63db272014-07-15 15:36:11 -0700268 profile_clock_source_ = kDefaultTraceClockSource;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800269
Jeff Hao4a200f52014-04-01 14:58:49 -0700270 verify_ = true;
Narayan Kamath11d9f062014-04-23 20:24:57 +0100271 image_isa_ = kRuntimeISA;
Jeff Hao4a200f52014-04-01 14:58:49 -0700272
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800273 for (size_t i = 0; i < options.size(); ++i) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800274 if (true && options[0].first == "-Xzygote") {
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800275 LOG(INFO) << "option[" << i << "]=" << options[i].first;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800276 }
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800277 }
278 for (size_t i = 0; i < options.size(); ++i) {
279 const std::string option(options[i].first);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800280 if (StartsWith(option, "-help")) {
281 Usage(nullptr);
282 return false;
283 } else if (StartsWith(option, "-showversion")) {
284 UsageMessage(stdout, "ART version %s\n", Runtime::GetVersion());
285 Exit(0);
286 } else if (StartsWith(option, "-Xbootclasspath:")) {
287 boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data();
Dave Allison69dfe512014-07-11 17:11:58 +0000288 LOG(INFO) << "setting boot class path to " << boot_class_path_string_;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800289 } else if (option == "-classpath" || option == "-cp") {
290 // TODO: support -Djava.class.path
291 i++;
292 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700293 Usage("Missing required class path value for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800294 return false;
295 }
296 const StringPiece& value = options[i].first;
297 class_path_string_ = value.data();
298 } else if (option == "bootclasspath") {
299 boot_class_path_
300 = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second);
301 } else if (StartsWith(option, "-Ximage:")) {
302 if (!ParseStringAfterChar(option, ':', &image_)) {
303 return false;
304 }
305 } else if (StartsWith(option, "-Xcheck:jni")) {
306 check_jni_ = true;
Ian Rogers68d8b422014-07-17 11:09:10 -0700307 } else if (StartsWith(option, "-Xjniopts:forcecopy")) {
308 force_copy_ = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800309 } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) {
310 std::string tail(option.substr(option[1] == 'X' ? 10 : 15));
311 // TODO: move parsing logic out of Dbg
312 if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) {
313 if (tail != "help") {
314 UsageMessage(stderr, "Failed to parse JDWP option %s\n", tail.c_str());
315 }
316 Usage("Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
317 "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n\n");
318 return false;
319 }
320 } else if (StartsWith(option, "-Xms")) {
321 size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024);
322 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700323 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800324 return false;
325 }
326 heap_initial_size_ = size;
327 } else if (StartsWith(option, "-Xmx")) {
328 size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024);
329 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700330 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800331 return false;
332 }
333 heap_maximum_size_ = size;
334 } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) {
335 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024);
336 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700337 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800338 return false;
339 }
340 heap_growth_limit_ = size;
341 } else if (StartsWith(option, "-XX:HeapMinFree=")) {
342 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024);
343 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700344 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800345 return false;
346 }
347 heap_min_free_ = size;
348 } else if (StartsWith(option, "-XX:HeapMaxFree=")) {
349 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024);
350 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700351 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800352 return false;
353 }
354 heap_max_free_ = size;
Mathieu Chartier6a7824d2014-08-22 14:53:04 -0700355 } else if (StartsWith(option, "-XX:NonMovingSpaceCapacity=")) {
356 size_t size = ParseMemoryOption(
357 option.substr(strlen("-XX:NonMovingSpaceCapacity=")).c_str(), 1024);
358 if (size == 0) {
359 Usage("Failed to parse memory option %s\n", option.c_str());
360 return false;
361 }
362 heap_non_moving_space_capacity_ = size;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800363 } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) {
364 if (!ParseDouble(option, '=', 0.1, 0.9, &heap_target_utilization_)) {
365 return false;
366 }
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700367 } else if (StartsWith(option, "-XX:ForegroundHeapGrowthMultiplier=")) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700368 if (!ParseDouble(option, '=', 0.1, 10.0, &foreground_heap_growth_multiplier_)) {
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700369 return false;
370 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800371 } else if (StartsWith(option, "-XX:ParallelGCThreads=")) {
372 if (!ParseUnsignedInteger(option, '=', &parallel_gc_threads_)) {
373 return false;
374 }
375 } else if (StartsWith(option, "-XX:ConcGCThreads=")) {
376 if (!ParseUnsignedInteger(option, '=', &conc_gc_threads_)) {
377 return false;
378 }
379 } else if (StartsWith(option, "-Xss")) {
380 size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1);
381 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700382 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800383 return false;
384 }
385 stack_size_ = size;
386 } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) {
387 if (!ParseUnsignedInteger(option, '=', &max_spins_before_thin_lock_inflation_)) {
388 return false;
389 }
390 } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) {
Andreas Gampe39d92182014-03-05 16:46:44 -0800391 unsigned int value;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800392 if (!ParseUnsignedInteger(option, '=', &value)) {
393 return false;
394 }
395 long_pause_log_threshold_ = MsToNs(value);
396 } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) {
Andreas Gampe39d92182014-03-05 16:46:44 -0800397 unsigned int value;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800398 if (!ParseUnsignedInteger(option, '=', &value)) {
399 return false;
400 }
401 long_gc_log_threshold_ = MsToNs(value);
402 } else if (option == "-XX:DumpGCPerformanceOnShutdown") {
403 dump_gc_performance_on_shutdown_ = true;
404 } else if (option == "-XX:IgnoreMaxFootprint") {
405 ignore_max_footprint_ = true;
406 } else if (option == "-XX:LowMemoryMode") {
407 low_memory_mode_ = true;
Alex Lighta59dd802014-07-02 16:28:08 -0700408 // TODO Might want to turn off must_relocate here.
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800409 } else if (option == "-XX:UseTLAB") {
410 use_tlab_ = true;
Zuo Wangf37a88b2014-07-10 04:26:41 -0700411 } else if (option == "-XX:EnableHSpaceCompactForOOM") {
412 use_homogeneous_space_compaction_for_oom_ = true;
413 } else if (option == "-XX:DisableHSpaceCompactForOOM") {
414 use_homogeneous_space_compaction_for_oom_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800415 } else if (StartsWith(option, "-D")) {
416 properties_.push_back(option.substr(strlen("-D")));
417 } else if (StartsWith(option, "-Xjnitrace:")) {
418 jni_trace_ = option.substr(strlen("-Xjnitrace:"));
419 } else if (option == "compilercallbacks") {
420 compiler_callbacks_ =
421 reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second));
Narayan Kamath11d9f062014-04-23 20:24:57 +0100422 } else if (option == "imageinstructionset") {
Andreas Gampe20c89302014-08-19 17:28:06 -0700423 const char* isa_str = reinterpret_cast<const char*>(options[i].second);
424 image_isa_ = GetInstructionSetFromString(isa_str);
425 if (image_isa_ == kNone) {
426 Usage("%s is not a valid instruction set.", isa_str);
427 return false;
428 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800429 } else if (option == "-Xzygote") {
430 is_zygote_ = true;
Alex Lighta59dd802014-07-02 16:28:08 -0700431 } else if (StartsWith(option, "-Xpatchoat:")) {
432 if (!ParseStringAfterChar(option, ':', &patchoat_executable_)) {
433 return false;
434 }
435 } else if (option == "-Xrelocate") {
436 must_relocate_ = true;
437 } else if (option == "-Xnorelocate") {
438 must_relocate_ = false;
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100439 } else if (option == "-Xnodex2oat") {
440 dex2oat_enabled_ = false;
441 } else if (option == "-Xdex2oat") {
442 dex2oat_enabled_ = true;
Alex Light64ad14d2014-08-19 14:23:13 -0700443 } else if (option == "-Xnoimage-dex2oat") {
444 image_dex2oat_enabled_ = false;
445 } else if (option == "-Ximage-dex2oat") {
446 image_dex2oat_enabled_ = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800447 } else if (option == "-Xint") {
448 interpreter_only_ = true;
449 } else if (StartsWith(option, "-Xgc:")) {
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700450 if (!ParseXGcOption(option)) {
451 return false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800452 }
453 } else if (StartsWith(option, "-XX:BackgroundGC=")) {
454 std::string substring;
455 if (!ParseStringAfterChar(option, '=', &substring)) {
456 return false;
457 }
Zuo Wangf37a88b2014-07-10 04:26:41 -0700458 // Special handling for HSpaceCompact since this is only valid as a background GC type.
459 if (substring == "HSpaceCompact") {
460 background_collector_type_ = gc::kCollectorTypeHomogeneousSpaceCompact;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800461 } else {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700462 gc::CollectorType collector_type = ParseCollectorType(substring);
463 if (collector_type != gc::kCollectorTypeNone) {
464 background_collector_type_ = collector_type;
465 } else {
466 Usage("Unknown -XX:BackgroundGC option %s\n", substring.c_str());
467 return false;
468 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800469 }
470 } else if (option == "-XX:+DisableExplicitGC") {
471 is_explicit_gc_disabled_ = true;
472 } else if (StartsWith(option, "-verbose:")) {
473 std::vector<std::string> verbose_options;
474 Split(option.substr(strlen("-verbose:")), ',', verbose_options);
475 for (size_t i = 0; i < verbose_options.size(); ++i) {
476 if (verbose_options[i] == "class") {
477 gLogVerbosity.class_linker = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800478 } else if (verbose_options[i] == "compiler") {
479 gLogVerbosity.compiler = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800480 } else if (verbose_options[i] == "gc") {
481 gLogVerbosity.gc = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700482 } else if (verbose_options[i] == "heap") {
483 gLogVerbosity.heap = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800484 } else if (verbose_options[i] == "jdwp") {
485 gLogVerbosity.jdwp = true;
486 } else if (verbose_options[i] == "jni") {
487 gLogVerbosity.jni = true;
488 } else if (verbose_options[i] == "monitor") {
489 gLogVerbosity.monitor = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700490 } else if (verbose_options[i] == "profiler") {
491 gLogVerbosity.profiler = true;
492 } else if (verbose_options[i] == "signals") {
493 gLogVerbosity.signals = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800494 } else if (verbose_options[i] == "startup") {
495 gLogVerbosity.startup = true;
496 } else if (verbose_options[i] == "third-party-jni") {
497 gLogVerbosity.third_party_jni = true;
498 } else if (verbose_options[i] == "threads") {
499 gLogVerbosity.threads = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700500 } else if (verbose_options[i] == "verifier") {
501 gLogVerbosity.verifier = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800502 } else {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700503 Usage("Unknown -verbose option %s\n", verbose_options[i].c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800504 return false;
505 }
506 }
Mingyao Yang42d65c52014-04-18 16:49:39 -0700507 } else if (StartsWith(option, "-verbose-methods:")) {
508 gLogVerbosity.compiler = false;
509 Split(option.substr(strlen("-verbose-methods:")), ',', gVerboseMethods);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800510 } else if (StartsWith(option, "-Xlockprofthreshold:")) {
511 if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) {
512 return false;
513 }
514 } else if (StartsWith(option, "-Xstacktracefile:")) {
515 if (!ParseStringAfterChar(option, ':', &stack_trace_file_)) {
516 return false;
517 }
518 } else if (option == "sensitiveThread") {
519 const void* hook = options[i].second;
520 hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(hook));
521 } else if (option == "vfprintf") {
522 const void* hook = options[i].second;
523 if (hook == nullptr) {
524 Usage("vfprintf argument was NULL");
525 return false;
526 }
527 hook_vfprintf_ =
528 reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook));
529 } else if (option == "exit") {
530 const void* hook = options[i].second;
531 if (hook == nullptr) {
532 Usage("exit argument was NULL");
533 return false;
534 }
535 hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook));
536 } else if (option == "abort") {
537 const void* hook = options[i].second;
538 if (hook == nullptr) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700539 Usage("abort was NULL\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800540 return false;
541 }
542 hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook));
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800543 } else if (option == "-Xmethod-trace") {
544 method_trace_ = true;
545 } else if (StartsWith(option, "-Xmethod-trace-file:")) {
546 method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:"));
547 } else if (StartsWith(option, "-Xmethod-trace-file-size:")) {
548 if (!ParseUnsignedInteger(option, ':', &method_trace_file_size_)) {
549 return false;
550 }
551 } else if (option == "-Xprofile:threadcpuclock") {
Ian Rogerse63db272014-07-15 15:36:11 -0700552 Trace::SetDefaultClockSource(kTraceClockSourceThreadCpu);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800553 } else if (option == "-Xprofile:wallclock") {
Ian Rogerse63db272014-07-15 15:36:11 -0700554 Trace::SetDefaultClockSource(kTraceClockSourceWall);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800555 } else if (option == "-Xprofile:dualclock") {
Ian Rogerse63db272014-07-15 15:36:11 -0700556 Trace::SetDefaultClockSource(kTraceClockSourceDual);
Calin Juravlec1b643c2014-05-30 23:44:11 +0100557 } else if (option == "-Xenable-profiler") {
558 profiler_options_.enabled_ = true;
Wei Jin2221e3b2014-05-21 18:35:19 -0700559 } else if (StartsWith(option, "-Xprofile-filename:")) {
Ian Rogersf7fd3cb2014-05-19 22:57:34 -0700560 if (!ParseStringAfterChar(option, ':', &profile_output_filename_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800561 return false;
562 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800563 } else if (StartsWith(option, "-Xprofile-period:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100564 if (!ParseUnsignedInteger(option, ':', &profiler_options_.period_s_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800565 return false;
566 }
567 } else if (StartsWith(option, "-Xprofile-duration:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100568 if (!ParseUnsignedInteger(option, ':', &profiler_options_.duration_s_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800569 return false;
570 }
571 } else if (StartsWith(option, "-Xprofile-interval:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100572 if (!ParseUnsignedInteger(option, ':', &profiler_options_.interval_us_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800573 return false;
574 }
575 } else if (StartsWith(option, "-Xprofile-backoff:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100576 if (!ParseDouble(option, ':', 1.0, 10.0, &profiler_options_.backoff_coefficient_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800577 return false;
578 }
Calin Juravlec1b643c2014-05-30 23:44:11 +0100579 } else if (option == "-Xprofile-start-immediately") {
580 profiler_options_.start_immediately_ = true;
581 } else if (StartsWith(option, "-Xprofile-top-k-threshold:")) {
Calin Juravlec321c9b2014-06-11 19:04:35 +0100582 if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_threshold_)) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100583 return false;
584 }
585 } else if (StartsWith(option, "-Xprofile-top-k-change-threshold:")) {
Calin Juravlec321c9b2014-06-11 19:04:35 +0100586 if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_change_threshold_)) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100587 return false;
588 }
Wei Jina93b0bb2014-06-09 16:19:15 -0700589 } else if (option == "-Xprofile-type:method") {
590 profiler_options_.profile_type_ = kProfilerMethod;
Wei Jin445220d2014-06-20 15:56:53 -0700591 } else if (option == "-Xprofile-type:stack") {
592 profiler_options_.profile_type_ = kProfilerBoundedStack;
593 } else if (StartsWith(option, "-Xprofile-max-stack-depth:")) {
594 if (!ParseUnsignedInteger(option, ':', &profiler_options_.max_stack_depth_)) {
595 return false;
596 }
Tsu Chiang Chuang12e6d742014-05-22 10:22:25 -0700597 } else if (StartsWith(option, "-Xcompiler:")) {
598 if (!ParseStringAfterChar(option, ':', &compiler_executable_)) {
599 return false;
600 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800601 } else if (option == "-Xcompiler-option") {
602 i++;
603 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700604 Usage("Missing required compiler option for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800605 return false;
606 }
607 compiler_options_.push_back(options[i].first);
608 } else if (option == "-Ximage-compiler-option") {
609 i++;
610 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700611 Usage("Missing required compiler option for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800612 return false;
613 }
614 image_compiler_options_.push_back(options[i].first);
Jeff Hao4a200f52014-04-01 14:58:49 -0700615 } else if (StartsWith(option, "-Xverify:")) {
616 std::string verify_mode = option.substr(strlen("-Xverify:"));
617 if (verify_mode == "none") {
618 verify_ = false;
619 } else if (verify_mode == "remote" || verify_mode == "all") {
620 verify_ = true;
621 } else {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700622 Usage("Unknown -Xverify option %s\n", verify_mode.c_str());
Jeff Hao4a200f52014-04-01 14:58:49 -0700623 return false;
624 }
Andreas Gampec4a7acf2014-08-08 12:05:10 -0700625 } else if (StartsWith(option, "-XX:NativeBridge=")) {
Calin Juravlea68629e2014-08-22 12:53:59 +0100626 if (!ParseStringAfterChar(option, '=', &native_bridge_library_filename_)) {
Andreas Gampe855564b2014-07-25 02:32:19 -0700627 return false;
628 }
Yevgeny Roubana6119a22014-03-24 11:31:24 +0700629 } else if (StartsWith(option, "-ea") ||
630 StartsWith(option, "-da") ||
631 StartsWith(option, "-enableassertions") ||
632 StartsWith(option, "-disableassertions") ||
Dave Allisonb373e092014-02-20 16:06:36 -0800633 (option == "--runtime-arg") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800634 (option == "-esa") ||
635 (option == "-dsa") ||
636 (option == "-enablesystemassertions") ||
637 (option == "-disablesystemassertions") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800638 (option == "-Xrs") ||
639 StartsWith(option, "-Xint:") ||
640 StartsWith(option, "-Xdexopt:") ||
641 (option == "-Xnoquithandler") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800642 StartsWith(option, "-Xjnigreflimit:") ||
643 (option == "-Xgenregmap") ||
644 (option == "-Xnogenregmap") ||
645 StartsWith(option, "-Xverifyopt:") ||
646 (option == "-Xcheckdexsum") ||
647 (option == "-Xincludeselectedop") ||
648 StartsWith(option, "-Xjitop:") ||
649 (option == "-Xincludeselectedmethod") ||
650 StartsWith(option, "-Xjitthreshold:") ||
651 StartsWith(option, "-Xjitcodecachesize:") ||
652 (option == "-Xjitblocking") ||
653 StartsWith(option, "-Xjitmethod:") ||
654 StartsWith(option, "-Xjitclass:") ||
655 StartsWith(option, "-Xjitoffset:") ||
656 StartsWith(option, "-Xjitconfig:") ||
657 (option == "-Xjitcheckcg") ||
658 (option == "-Xjitverbose") ||
659 (option == "-Xjitprofile") ||
660 (option == "-Xjitdisableopt") ||
661 (option == "-Xjitsuspendpoll") ||
662 StartsWith(option, "-XX:mainThreadStackSize=")) {
663 // Ignored for backwards compatibility.
664 } else if (!ignore_unrecognized) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700665 Usage("Unrecognized option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800666 return false;
667 }
668 }
669
670 // If a reference to the dalvik core.jar snuck in, replace it with
671 // the art specific version. This can happen with on device
672 // boot.art/boot.oat generation by GenerateImage which relies on the
673 // value of BOOTCLASSPATH.
Kenny Rootd5185342014-05-13 14:47:05 -0700674#if defined(ART_TARGET)
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800675 std::string core_jar("/core.jar");
Kenny Rootd5185342014-05-13 14:47:05 -0700676 std::string core_libart_jar("/core-libart.jar");
677#else
678 // The host uses hostdex files.
679 std::string core_jar("/core-hostdex.jar");
680 std::string core_libart_jar("/core-libart-hostdex.jar");
681#endif
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800682 size_t core_jar_pos = boot_class_path_string_.find(core_jar);
683 if (core_jar_pos != std::string::npos) {
Kenny Rootd5185342014-05-13 14:47:05 -0700684 boot_class_path_string_.replace(core_jar_pos, core_jar.size(), core_libart_jar);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800685 }
686
687 if (compiler_callbacks_ == nullptr && image_.empty()) {
688 image_ += GetAndroidRoot();
Brian Carlstrom3ac05bb2014-05-13 19:31:38 -0700689 image_ += "/framework/boot.art";
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800690 }
691 if (heap_growth_limit_ == 0) {
692 heap_growth_limit_ = heap_maximum_size_;
693 }
694 if (background_collector_type_ == gc::kCollectorTypeNone) {
695 background_collector_type_ = collector_type_;
696 }
697 return true;
Narayan Kamath11d9f062014-04-23 20:24:57 +0100698} // NOLINT(readability/fn_size)
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800699
700void ParsedOptions::Exit(int status) {
701 hook_exit_(status);
702}
703
704void ParsedOptions::Abort() {
705 hook_abort_();
706}
707
708void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) {
709 hook_vfprintf_(stderr, fmt, ap);
710}
711
712void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) {
713 va_list ap;
714 va_start(ap, fmt);
715 UsageMessageV(stream, fmt, ap);
716 va_end(ap);
717}
718
719void ParsedOptions::Usage(const char* fmt, ...) {
720 bool error = (fmt != nullptr);
721 FILE* stream = error ? stderr : stdout;
722
723 if (fmt != nullptr) {
724 va_list ap;
725 va_start(ap, fmt);
726 UsageMessageV(stream, fmt, ap);
727 va_end(ap);
728 }
729
730 const char* program = "dalvikvm";
731 UsageMessage(stream, "%s: [options] class [argument ...]\n", program);
732 UsageMessage(stream, "\n");
733 UsageMessage(stream, "The following standard options are supported:\n");
734 UsageMessage(stream, " -classpath classpath (-cp classpath)\n");
735 UsageMessage(stream, " -Dproperty=value\n");
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100736 UsageMessage(stream, " -verbose:tag ('gc', 'jni', or 'class')\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800737 UsageMessage(stream, " -showversion\n");
738 UsageMessage(stream, " -help\n");
739 UsageMessage(stream, " -agentlib:jdwp=options\n");
740 UsageMessage(stream, "\n");
741
742 UsageMessage(stream, "The following extended options are supported:\n");
743 UsageMessage(stream, " -Xrunjdwp:<options>\n");
744 UsageMessage(stream, " -Xbootclasspath:bootclasspath\n");
745 UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n");
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100746 UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n");
747 UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n");
748 UsageMessage(stream, " -XssN (stack size)\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800749 UsageMessage(stream, " -Xint\n");
750 UsageMessage(stream, "\n");
751
752 UsageMessage(stream, "The following Dalvik options are supported:\n");
753 UsageMessage(stream, " -Xzygote\n");
754 UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n");
755 UsageMessage(stream, " -Xstacktracefile:<filename>\n");
756 UsageMessage(stream, " -Xgc:[no]preverify\n");
757 UsageMessage(stream, " -Xgc:[no]postverify\n");
758 UsageMessage(stream, " -XX:+DisableExplicitGC\n");
759 UsageMessage(stream, " -XX:HeapGrowthLimit=N\n");
760 UsageMessage(stream, " -XX:HeapMinFree=N\n");
761 UsageMessage(stream, " -XX:HeapMaxFree=N\n");
Mathieu Chartier6a7824d2014-08-22 14:53:04 -0700762 UsageMessage(stream, " -XX:NonMovingSpaceCapacity=N\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800763 UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n");
Mathieu Chartier455820e2014-04-18 12:02:39 -0700764 UsageMessage(stream, " -XX:ForegroundHeapGrowthMultiplier=doublevalue\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800765 UsageMessage(stream, " -XX:LowMemoryMode\n");
766 UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n");
767 UsageMessage(stream, "\n");
768
769 UsageMessage(stream, "The following unique to ART options are supported:\n");
770 UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n");
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700771 UsageMessage(stream, " -Xgc:[no]postsweepingverify_rosalloc\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800772 UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n");
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700773 UsageMessage(stream, " -Xgc:[no]presweepingverify\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800774 UsageMessage(stream, " -Ximage:filename\n");
775 UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n");
776 UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n");
777 UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n");
778 UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n");
779 UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n");
780 UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n");
781 UsageMessage(stream, " -XX:IgnoreMaxFootprint\n");
782 UsageMessage(stream, " -XX:UseTLAB\n");
783 UsageMessage(stream, " -XX:BackgroundGC=none\n");
784 UsageMessage(stream, " -Xmethod-trace\n");
785 UsageMessage(stream, " -Xmethod-trace-file:filename");
786 UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n");
Calin Juravlec1b643c2014-05-30 23:44:11 +0100787 UsageMessage(stream, " -Xenable-profiler\n");
Wei Jin2221e3b2014-05-21 18:35:19 -0700788 UsageMessage(stream, " -Xprofile-filename:filename\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800789 UsageMessage(stream, " -Xprofile-period:integervalue\n");
790 UsageMessage(stream, " -Xprofile-duration:integervalue\n");
791 UsageMessage(stream, " -Xprofile-interval:integervalue\n");
Calin Juravle54c73ca2014-05-22 12:13:54 +0100792 UsageMessage(stream, " -Xprofile-backoff:doublevalue\n");
Calin Juravlec1b643c2014-05-30 23:44:11 +0100793 UsageMessage(stream, " -Xprofile-start-immediately\n");
794 UsageMessage(stream, " -Xprofile-top-k-threshold:doublevalue\n");
795 UsageMessage(stream, " -Xprofile-top-k-change-threshold:doublevalue\n");
Wei Jin445220d2014-06-20 15:56:53 -0700796 UsageMessage(stream, " -Xprofile-type:{method,stack}\n");
797 UsageMessage(stream, " -Xprofile-max-stack-depth:integervalue\n");
Tsu Chiang Chuang12e6d742014-05-22 10:22:25 -0700798 UsageMessage(stream, " -Xcompiler:filename\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800799 UsageMessage(stream, " -Xcompiler-option dex2oat-option\n");
800 UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n");
Alex Lighta59dd802014-07-02 16:28:08 -0700801 UsageMessage(stream, " -Xpatchoat:filename\n");
802 UsageMessage(stream, " -X[no]relocate\n");
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100803 UsageMessage(stream, " -X[no]dex2oat (Whether to invoke dex2oat on the application)\n");
Alex Light64ad14d2014-08-19 14:23:13 -0700804 UsageMessage(stream, " -X[no]image-dex2oat (Whether to create and use a boot image)\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800805 UsageMessage(stream, "\n");
806
807 UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n");
808 UsageMessage(stream, " -ea[:<package name>... |:<class name>]\n");
809 UsageMessage(stream, " -da[:<package name>... |:<class name>]\n");
810 UsageMessage(stream, " (-enableassertions, -disableassertions)\n");
811 UsageMessage(stream, " -esa\n");
812 UsageMessage(stream, " -dsa\n");
813 UsageMessage(stream, " (-enablesystemassertions, -disablesystemassertions)\n");
814 UsageMessage(stream, " -Xverify:{none,remote,all}\n");
815 UsageMessage(stream, " -Xrs\n");
816 UsageMessage(stream, " -Xint:portable, -Xint:fast, -Xint:jit\n");
817 UsageMessage(stream, " -Xdexopt:{none,verified,all,full}\n");
818 UsageMessage(stream, " -Xnoquithandler\n");
819 UsageMessage(stream, " -Xjniopts:{warnonly,forcecopy}\n");
820 UsageMessage(stream, " -Xjnigreflimit:integervalue\n");
821 UsageMessage(stream, " -Xgc:[no]precise\n");
822 UsageMessage(stream, " -Xgc:[no]verifycardtable\n");
823 UsageMessage(stream, " -X[no]genregmap\n");
824 UsageMessage(stream, " -Xverifyopt:[no]checkmon\n");
825 UsageMessage(stream, " -Xcheckdexsum\n");
826 UsageMessage(stream, " -Xincludeselectedop\n");
827 UsageMessage(stream, " -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*\n");
828 UsageMessage(stream, " -Xincludeselectedmethod\n");
829 UsageMessage(stream, " -Xjitthreshold:integervalue\n");
830 UsageMessage(stream, " -Xjitcodecachesize:decimalvalueofkbytes\n");
831 UsageMessage(stream, " -Xjitblocking\n");
832 UsageMessage(stream, " -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\\;replace)\n");
833 UsageMessage(stream, " -Xjitclass:classname[,classname]*\n");
834 UsageMessage(stream, " -Xjitoffset:offset[,offset]\n");
835 UsageMessage(stream, " -Xjitconfig:filename\n");
836 UsageMessage(stream, " -Xjitcheckcg\n");
837 UsageMessage(stream, " -Xjitverbose\n");
838 UsageMessage(stream, " -Xjitprofile\n");
839 UsageMessage(stream, " -Xjitdisableopt\n");
840 UsageMessage(stream, " -Xjitsuspendpoll\n");
841 UsageMessage(stream, " -XX:mainThreadStackSize=N\n");
842 UsageMessage(stream, "\n");
843
844 Exit((error) ? 1 : 0);
845}
846
847bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) {
848 std::string::size_type colon = s.find(c);
849 if (colon == std::string::npos) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700850 Usage("Missing char %c in option %s\n", c, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800851 return false;
852 }
853 // Add one to remove the char we were trimming until.
854 *parsed_value = s.substr(colon + 1);
855 return true;
856}
857
858bool ParsedOptions::ParseInteger(const std::string& s, char after_char, int* parsed_value) {
859 std::string::size_type colon = s.find(after_char);
860 if (colon == std::string::npos) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700861 Usage("Missing char %c in option %s\n", after_char, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800862 return false;
863 }
864 const char* begin = &s[colon + 1];
865 char* end;
866 size_t result = strtoul(begin, &end, 10);
867 if (begin == end || *end != '\0') {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700868 Usage("Failed to parse integer from %s\n", s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800869 return false;
870 }
871 *parsed_value = result;
872 return true;
873}
874
875bool ParsedOptions::ParseUnsignedInteger(const std::string& s, char after_char,
876 unsigned int* parsed_value) {
877 int i;
878 if (!ParseInteger(s, after_char, &i)) {
879 return false;
880 }
881 if (i < 0) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700882 Usage("Negative value %d passed for unsigned option %s\n", i, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800883 return false;
884 }
885 *parsed_value = i;
886 return true;
887}
888
889bool ParsedOptions::ParseDouble(const std::string& option, char after_char,
890 double min, double max, double* parsed_value) {
891 std::string substring;
892 if (!ParseStringAfterChar(option, after_char, &substring)) {
893 return false;
894 }
Dave Allison999385c2014-05-20 15:16:02 -0700895 bool sane_val = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800896 double value;
Dave Allison999385c2014-05-20 15:16:02 -0700897 if (false) {
898 // TODO: this doesn't seem to work on the emulator. b/15114595
899 std::stringstream iss(substring);
900 iss >> value;
901 // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range.
902 sane_val = iss.eof() && (value >= min) && (value <= max);
903 } else {
904 char* end = nullptr;
905 value = strtod(substring.c_str(), &end);
906 sane_val = *end == '\0' && value >= min && value <= max;
907 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800908 if (!sane_val) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700909 Usage("Invalid double value %s for option %s\n", substring.c_str(), option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800910 return false;
911 }
912 *parsed_value = value;
913 return true;
914}
915
916} // namespace art