blob: 37e08a57ea16761b57974f1c4a30db1bc8e1f4ce [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
Andreas Gampe313f4032014-08-29 16:01:25 -070033ParsedOptions::ParsedOptions()
34 :
35 boot_class_path_(nullptr),
36 check_jni_(kIsDebugBuild), // -Xcheck:jni is off by default for regular
37 // builds but on by default in debug builds.
38 force_copy_(false),
39 compiler_callbacks_(nullptr),
40 is_zygote_(false),
41 must_relocate_(kDefaultMustRelocate),
42 dex2oat_enabled_(true),
43 image_dex2oat_enabled_(true),
44 interpreter_only_(kPoisonHeapReferences), // kPoisonHeapReferences currently works with
45 // the interpreter only.
46 // TODO: make it work with the compiler.
47 is_explicit_gc_disabled_(false),
48 use_tlab_(false),
49 verify_pre_gc_heap_(false),
50 verify_pre_sweeping_heap_(kIsDebugBuild), // Pre sweeping is the one that usually fails
51 // if the GC corrupted the heap.
52 verify_post_gc_heap_(false),
53 verify_pre_gc_rosalloc_(kIsDebugBuild),
54 verify_pre_sweeping_rosalloc_(false),
55 verify_post_gc_rosalloc_(false),
56 long_pause_log_threshold_(gc::Heap::kDefaultLongPauseLogThreshold),
57 long_gc_log_threshold_(gc::Heap::kDefaultLongGCLogThreshold),
58 dump_gc_performance_on_shutdown_(false),
59 ignore_max_footprint_(false),
60 heap_initial_size_(gc::Heap::kDefaultInitialSize),
61 heap_maximum_size_(gc::Heap::kDefaultMaximumSize),
62 heap_growth_limit_(0), // 0 means no growth limit.
63 heap_min_free_(gc::Heap::kDefaultMinFree),
64 heap_max_free_(gc::Heap::kDefaultMaxFree),
65 heap_non_moving_space_capacity_(gc::Heap::kDefaultNonMovingSpaceCapacity),
66 heap_target_utilization_(gc::Heap::kDefaultTargetUtilization),
67 foreground_heap_growth_multiplier_(gc::Heap::kDefaultHeapGrowthMultiplier),
68 parallel_gc_threads_(1),
Andreas Gampe2c2426c2014-08-29 18:15:04 -070069 conc_gc_threads_(0), // Only the main GC thread, no workers.
Andreas Gampe313f4032014-08-29 16:01:25 -070070 collector_type_( // The default GC type is set in makefiles.
71#if ART_DEFAULT_GC_TYPE_IS_CMS
72 gc::kCollectorTypeCMS),
73#elif ART_DEFAULT_GC_TYPE_IS_SS
74 gc::kCollectorTypeSS),
75#elif ART_DEFAULT_GC_TYPE_IS_GSS
76 gc::kCollectorTypeGSS),
77#else
78 gc::kCollectorTypeCMS),
79#error "ART default GC type must be set"
80#endif
81 background_collector_type_(gc::kCollectorTypeHomogeneousSpaceCompact),
82 // If background_collector_type_ is
83 // kCollectorTypeNone, it defaults to the
84 // collector_type_ after parsing options. If
85 // you set this to kCollectorTypeHSpaceCompact
86 // then we will do an hspace compaction when
87 // we transition to background instead of a
88 // normal collector transition.
89 stack_size_(0), // 0 means default.
90 max_spins_before_thin_lock_inflation_(Monitor::kDefaultMaxSpinsBeforeThinLockInflation),
91 low_memory_mode_(false),
92 lock_profiling_threshold_(0),
93 method_trace_(false),
94 method_trace_file_("/data/method-trace-file.bin"),
95 method_trace_file_size_(10 * MB),
96 hook_is_sensitive_thread_(nullptr),
97 hook_vfprintf_(vfprintf),
98 hook_exit_(exit),
99 hook_abort_(nullptr), // We don't call abort(3) by default; see
100 // Runtime::Abort.
101 profile_clock_source_(kDefaultTraceClockSource),
102 verify_(true),
103 image_isa_(kRuntimeISA),
104 use_homogeneous_space_compaction_for_oom_(false), // If we are using homogeneous space
105 // compaction then default background
106 // compaction to off since homogeneous
107 // space compactions when we transition
108 // to not jank perceptible.
109 min_interval_homogeneous_space_compaction_by_oom_(MsToNs(100 * 1000)) // 100s.
110 {}
111
Ian Rogerse63db272014-07-15 15:36:11 -0700112ParsedOptions* ParsedOptions::Create(const RuntimeOptions& options, bool ignore_unrecognized) {
Ian Rogers700a4022014-05-19 16:49:03 -0700113 std::unique_ptr<ParsedOptions> parsed(new ParsedOptions());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800114 if (parsed->Parse(options, ignore_unrecognized)) {
115 return parsed.release();
116 }
117 return nullptr;
118}
119
120// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
121// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
122// [gG] gigabytes.
123//
124// "s" should point just past the "-Xm?" part of the string.
125// "div" specifies a divisor, e.g. 1024 if the value must be a multiple
126// of 1024.
127//
128// The spec says the -Xmx and -Xms options must be multiples of 1024. It
129// doesn't say anything about -Xss.
130//
131// Returns 0 (a useless size) if "s" is malformed or specifies a low or
132// non-evenly-divisible value.
133//
134size_t ParseMemoryOption(const char* s, size_t div) {
135 // strtoul accepts a leading [+-], which we don't want,
136 // so make sure our string starts with a decimal digit.
137 if (isdigit(*s)) {
138 char* s2;
139 size_t val = strtoul(s, &s2, 10);
140 if (s2 != s) {
141 // s2 should be pointing just after the number.
142 // If this is the end of the string, the user
143 // has specified a number of bytes. Otherwise,
144 // there should be exactly one more character
145 // that specifies a multiplier.
146 if (*s2 != '\0') {
147 // The remainder of the string is either a single multiplier
148 // character, or nothing to indicate that the value is in
149 // bytes.
150 char c = *s2++;
151 if (*s2 == '\0') {
152 size_t mul;
153 if (c == '\0') {
154 mul = 1;
155 } else if (c == 'k' || c == 'K') {
156 mul = KB;
157 } else if (c == 'm' || c == 'M') {
158 mul = MB;
159 } else if (c == 'g' || c == 'G') {
160 mul = GB;
161 } else {
162 // Unknown multiplier character.
163 return 0;
164 }
165
166 if (val <= std::numeric_limits<size_t>::max() / mul) {
167 val *= mul;
168 } else {
169 // Clamp to a multiple of 1024.
170 val = std::numeric_limits<size_t>::max() & ~(1024-1);
171 }
172 } else {
173 // There's more than one character after the numeric part.
174 return 0;
175 }
176 }
177 // The man page says that a -Xm value must be a multiple of 1024.
178 if (val % div == 0) {
179 return val;
180 }
181 }
182 }
183 return 0;
184}
185
186static gc::CollectorType ParseCollectorType(const std::string& option) {
187 if (option == "MS" || option == "nonconcurrent") {
188 return gc::kCollectorTypeMS;
189 } else if (option == "CMS" || option == "concurrent") {
190 return gc::kCollectorTypeCMS;
191 } else if (option == "SS") {
192 return gc::kCollectorTypeSS;
193 } else if (option == "GSS") {
194 return gc::kCollectorTypeGSS;
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700195 } else if (option == "CC") {
196 return gc::kCollectorTypeCC;
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700197 } else if (option == "MC") {
198 return gc::kCollectorTypeMC;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800199 } else {
200 return gc::kCollectorTypeNone;
201 }
202}
203
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700204bool ParsedOptions::ParseXGcOption(const std::string& option) {
205 std::vector<std::string> gc_options;
206 Split(option.substr(strlen("-Xgc:")), ',', gc_options);
207 for (const std::string& gc_option : gc_options) {
208 gc::CollectorType collector_type = ParseCollectorType(gc_option);
209 if (collector_type != gc::kCollectorTypeNone) {
210 collector_type_ = collector_type;
211 } else if (gc_option == "preverify") {
212 verify_pre_gc_heap_ = true;
213 } else if (gc_option == "nopreverify") {
214 verify_pre_gc_heap_ = false;
215 } else if (gc_option == "presweepingverify") {
216 verify_pre_sweeping_heap_ = true;
217 } else if (gc_option == "nopresweepingverify") {
218 verify_pre_sweeping_heap_ = false;
219 } else if (gc_option == "postverify") {
220 verify_post_gc_heap_ = true;
221 } else if (gc_option == "nopostverify") {
222 verify_post_gc_heap_ = false;
223 } else if (gc_option == "preverify_rosalloc") {
224 verify_pre_gc_rosalloc_ = true;
225 } else if (gc_option == "nopreverify_rosalloc") {
226 verify_pre_gc_rosalloc_ = false;
227 } else if (gc_option == "presweepingverify_rosalloc") {
228 verify_pre_sweeping_rosalloc_ = true;
229 } else if (gc_option == "nopresweepingverify_rosalloc") {
230 verify_pre_sweeping_rosalloc_ = false;
231 } else if (gc_option == "postverify_rosalloc") {
232 verify_post_gc_rosalloc_ = true;
233 } else if (gc_option == "nopostverify_rosalloc") {
234 verify_post_gc_rosalloc_ = false;
235 } else if ((gc_option == "precise") ||
236 (gc_option == "noprecise") ||
237 (gc_option == "verifycardtable") ||
238 (gc_option == "noverifycardtable")) {
239 // Ignored for backwards compatibility.
240 } else {
241 Usage("Unknown -Xgc option %s\n", gc_option.c_str());
242 return false;
243 }
244 }
245 return true;
246}
247
Ian Rogerse63db272014-07-15 15:36:11 -0700248bool ParsedOptions::Parse(const RuntimeOptions& options, bool ignore_unrecognized) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800249 const char* boot_class_path_string = getenv("BOOTCLASSPATH");
250 if (boot_class_path_string != NULL) {
251 boot_class_path_string_ = boot_class_path_string;
252 }
253 const char* class_path_string = getenv("CLASSPATH");
254 if (class_path_string != NULL) {
255 class_path_string_ = class_path_string;
256 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800257
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800258 // Default to number of processors minus one since the main GC thread also does work.
259 parallel_gc_threads_ = sysconf(_SC_NPROCESSORS_CONF) - 1;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800260
261// gLogVerbosity.class_linker = true; // TODO: don't check this in!
262// gLogVerbosity.compiler = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800263// gLogVerbosity.gc = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700264// gLogVerbosity.heap = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800265// gLogVerbosity.jdwp = true; // TODO: don't check this in!
266// gLogVerbosity.jni = true; // TODO: don't check this in!
267// gLogVerbosity.monitor = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700268// gLogVerbosity.profiler = true; // TODO: don't check this in!
269// gLogVerbosity.signals = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800270// gLogVerbosity.startup = true; // TODO: don't check this in!
271// gLogVerbosity.third_party_jni = true; // TODO: don't check this in!
272// gLogVerbosity.threads = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700273// gLogVerbosity.verifier = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800274
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800275 for (size_t i = 0; i < options.size(); ++i) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800276 if (true && options[0].first == "-Xzygote") {
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800277 LOG(INFO) << "option[" << i << "]=" << options[i].first;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800278 }
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800279 }
280 for (size_t i = 0; i < options.size(); ++i) {
281 const std::string option(options[i].first);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800282 if (StartsWith(option, "-help")) {
283 Usage(nullptr);
284 return false;
285 } else if (StartsWith(option, "-showversion")) {
286 UsageMessage(stdout, "ART version %s\n", Runtime::GetVersion());
287 Exit(0);
288 } else if (StartsWith(option, "-Xbootclasspath:")) {
289 boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data();
Dave Allison69dfe512014-07-11 17:11:58 +0000290 LOG(INFO) << "setting boot class path to " << boot_class_path_string_;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800291 } else if (option == "-classpath" || option == "-cp") {
292 // TODO: support -Djava.class.path
293 i++;
294 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700295 Usage("Missing required class path value for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800296 return false;
297 }
298 const StringPiece& value = options[i].first;
299 class_path_string_ = value.data();
300 } else if (option == "bootclasspath") {
301 boot_class_path_
302 = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second);
303 } else if (StartsWith(option, "-Ximage:")) {
304 if (!ParseStringAfterChar(option, ':', &image_)) {
305 return false;
306 }
307 } else if (StartsWith(option, "-Xcheck:jni")) {
308 check_jni_ = true;
Ian Rogers68d8b422014-07-17 11:09:10 -0700309 } else if (StartsWith(option, "-Xjniopts:forcecopy")) {
310 force_copy_ = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800311 } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) {
312 std::string tail(option.substr(option[1] == 'X' ? 10 : 15));
313 // TODO: move parsing logic out of Dbg
314 if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) {
315 if (tail != "help") {
316 UsageMessage(stderr, "Failed to parse JDWP option %s\n", tail.c_str());
317 }
318 Usage("Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
319 "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n\n");
320 return false;
321 }
322 } else if (StartsWith(option, "-Xms")) {
323 size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024);
324 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700325 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800326 return false;
327 }
328 heap_initial_size_ = size;
329 } else if (StartsWith(option, "-Xmx")) {
330 size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024);
331 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700332 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800333 return false;
334 }
335 heap_maximum_size_ = size;
336 } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) {
337 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024);
338 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700339 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800340 return false;
341 }
342 heap_growth_limit_ = size;
343 } else if (StartsWith(option, "-XX:HeapMinFree=")) {
344 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024);
345 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700346 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800347 return false;
348 }
349 heap_min_free_ = size;
350 } else if (StartsWith(option, "-XX:HeapMaxFree=")) {
351 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024);
352 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700353 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800354 return false;
355 }
356 heap_max_free_ = size;
Mathieu Chartier6a7824d2014-08-22 14:53:04 -0700357 } else if (StartsWith(option, "-XX:NonMovingSpaceCapacity=")) {
358 size_t size = ParseMemoryOption(
359 option.substr(strlen("-XX:NonMovingSpaceCapacity=")).c_str(), 1024);
360 if (size == 0) {
361 Usage("Failed to parse memory option %s\n", option.c_str());
362 return false;
363 }
364 heap_non_moving_space_capacity_ = size;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800365 } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) {
366 if (!ParseDouble(option, '=', 0.1, 0.9, &heap_target_utilization_)) {
367 return false;
368 }
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700369 } else if (StartsWith(option, "-XX:ForegroundHeapGrowthMultiplier=")) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700370 if (!ParseDouble(option, '=', 0.1, 10.0, &foreground_heap_growth_multiplier_)) {
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700371 return false;
372 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800373 } else if (StartsWith(option, "-XX:ParallelGCThreads=")) {
374 if (!ParseUnsignedInteger(option, '=', &parallel_gc_threads_)) {
375 return false;
376 }
377 } else if (StartsWith(option, "-XX:ConcGCThreads=")) {
378 if (!ParseUnsignedInteger(option, '=', &conc_gc_threads_)) {
379 return false;
380 }
381 } else if (StartsWith(option, "-Xss")) {
382 size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1);
383 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700384 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800385 return false;
386 }
387 stack_size_ = size;
388 } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) {
389 if (!ParseUnsignedInteger(option, '=', &max_spins_before_thin_lock_inflation_)) {
390 return false;
391 }
392 } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) {
Andreas Gampe39d92182014-03-05 16:46:44 -0800393 unsigned int value;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800394 if (!ParseUnsignedInteger(option, '=', &value)) {
395 return false;
396 }
397 long_pause_log_threshold_ = MsToNs(value);
398 } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) {
Andreas Gampe39d92182014-03-05 16:46:44 -0800399 unsigned int value;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800400 if (!ParseUnsignedInteger(option, '=', &value)) {
401 return false;
402 }
403 long_gc_log_threshold_ = MsToNs(value);
404 } else if (option == "-XX:DumpGCPerformanceOnShutdown") {
405 dump_gc_performance_on_shutdown_ = true;
406 } else if (option == "-XX:IgnoreMaxFootprint") {
407 ignore_max_footprint_ = true;
408 } else if (option == "-XX:LowMemoryMode") {
409 low_memory_mode_ = true;
Alex Lighta59dd802014-07-02 16:28:08 -0700410 // TODO Might want to turn off must_relocate here.
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800411 } else if (option == "-XX:UseTLAB") {
412 use_tlab_ = true;
Zuo Wangf37a88b2014-07-10 04:26:41 -0700413 } else if (option == "-XX:EnableHSpaceCompactForOOM") {
414 use_homogeneous_space_compaction_for_oom_ = true;
415 } else if (option == "-XX:DisableHSpaceCompactForOOM") {
416 use_homogeneous_space_compaction_for_oom_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800417 } 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") {
Andreas Gampe20c89302014-08-19 17:28:06 -0700425 const char* isa_str = reinterpret_cast<const char*>(options[i].second);
426 image_isa_ = GetInstructionSetFromString(isa_str);
427 if (image_isa_ == kNone) {
428 Usage("%s is not a valid instruction set.", isa_str);
429 return false;
430 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800431 } else if (option == "-Xzygote") {
432 is_zygote_ = true;
Alex Lighta59dd802014-07-02 16:28:08 -0700433 } else if (StartsWith(option, "-Xpatchoat:")) {
434 if (!ParseStringAfterChar(option, ':', &patchoat_executable_)) {
435 return false;
436 }
437 } else if (option == "-Xrelocate") {
438 must_relocate_ = true;
439 } else if (option == "-Xnorelocate") {
440 must_relocate_ = false;
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100441 } else if (option == "-Xnodex2oat") {
442 dex2oat_enabled_ = false;
443 } else if (option == "-Xdex2oat") {
444 dex2oat_enabled_ = true;
Alex Light64ad14d2014-08-19 14:23:13 -0700445 } else if (option == "-Xnoimage-dex2oat") {
446 image_dex2oat_enabled_ = false;
447 } else if (option == "-Ximage-dex2oat") {
448 image_dex2oat_enabled_ = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800449 } else if (option == "-Xint") {
450 interpreter_only_ = true;
451 } else if (StartsWith(option, "-Xgc:")) {
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700452 if (!ParseXGcOption(option)) {
453 return false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800454 }
455 } else if (StartsWith(option, "-XX:BackgroundGC=")) {
456 std::string substring;
457 if (!ParseStringAfterChar(option, '=', &substring)) {
458 return false;
459 }
Zuo Wangf37a88b2014-07-10 04:26:41 -0700460 // Special handling for HSpaceCompact since this is only valid as a background GC type.
461 if (substring == "HSpaceCompact") {
462 background_collector_type_ = gc::kCollectorTypeHomogeneousSpaceCompact;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800463 } else {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700464 gc::CollectorType collector_type = ParseCollectorType(substring);
465 if (collector_type != gc::kCollectorTypeNone) {
466 background_collector_type_ = collector_type;
467 } else {
468 Usage("Unknown -XX:BackgroundGC option %s\n", substring.c_str());
469 return false;
470 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800471 }
472 } else if (option == "-XX:+DisableExplicitGC") {
473 is_explicit_gc_disabled_ = true;
474 } else if (StartsWith(option, "-verbose:")) {
475 std::vector<std::string> verbose_options;
476 Split(option.substr(strlen("-verbose:")), ',', verbose_options);
477 for (size_t i = 0; i < verbose_options.size(); ++i) {
478 if (verbose_options[i] == "class") {
479 gLogVerbosity.class_linker = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800480 } else if (verbose_options[i] == "compiler") {
481 gLogVerbosity.compiler = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800482 } else if (verbose_options[i] == "gc") {
483 gLogVerbosity.gc = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700484 } else if (verbose_options[i] == "heap") {
485 gLogVerbosity.heap = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800486 } else if (verbose_options[i] == "jdwp") {
487 gLogVerbosity.jdwp = true;
488 } else if (verbose_options[i] == "jni") {
489 gLogVerbosity.jni = true;
490 } else if (verbose_options[i] == "monitor") {
491 gLogVerbosity.monitor = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700492 } else if (verbose_options[i] == "profiler") {
493 gLogVerbosity.profiler = true;
494 } else if (verbose_options[i] == "signals") {
495 gLogVerbosity.signals = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800496 } else if (verbose_options[i] == "startup") {
497 gLogVerbosity.startup = true;
498 } else if (verbose_options[i] == "third-party-jni") {
499 gLogVerbosity.third_party_jni = true;
500 } else if (verbose_options[i] == "threads") {
501 gLogVerbosity.threads = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700502 } else if (verbose_options[i] == "verifier") {
503 gLogVerbosity.verifier = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800504 } else {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700505 Usage("Unknown -verbose option %s\n", verbose_options[i].c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800506 return false;
507 }
508 }
Mingyao Yang42d65c52014-04-18 16:49:39 -0700509 } else if (StartsWith(option, "-verbose-methods:")) {
510 gLogVerbosity.compiler = false;
511 Split(option.substr(strlen("-verbose-methods:")), ',', gVerboseMethods);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800512 } else if (StartsWith(option, "-Xlockprofthreshold:")) {
513 if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) {
514 return false;
515 }
516 } else if (StartsWith(option, "-Xstacktracefile:")) {
517 if (!ParseStringAfterChar(option, ':', &stack_trace_file_)) {
518 return false;
519 }
520 } else if (option == "sensitiveThread") {
521 const void* hook = options[i].second;
522 hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(hook));
523 } else if (option == "vfprintf") {
524 const void* hook = options[i].second;
525 if (hook == nullptr) {
526 Usage("vfprintf argument was NULL");
527 return false;
528 }
529 hook_vfprintf_ =
530 reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook));
531 } else if (option == "exit") {
532 const void* hook = options[i].second;
533 if (hook == nullptr) {
534 Usage("exit argument was NULL");
535 return false;
536 }
537 hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook));
538 } else if (option == "abort") {
539 const void* hook = options[i].second;
540 if (hook == nullptr) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700541 Usage("abort was NULL\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800542 return false;
543 }
544 hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook));
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800545 } else if (option == "-Xmethod-trace") {
546 method_trace_ = true;
547 } else if (StartsWith(option, "-Xmethod-trace-file:")) {
548 method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:"));
549 } else if (StartsWith(option, "-Xmethod-trace-file-size:")) {
550 if (!ParseUnsignedInteger(option, ':', &method_trace_file_size_)) {
551 return false;
552 }
553 } else if (option == "-Xprofile:threadcpuclock") {
Ian Rogerse63db272014-07-15 15:36:11 -0700554 Trace::SetDefaultClockSource(kTraceClockSourceThreadCpu);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800555 } else if (option == "-Xprofile:wallclock") {
Ian Rogerse63db272014-07-15 15:36:11 -0700556 Trace::SetDefaultClockSource(kTraceClockSourceWall);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800557 } else if (option == "-Xprofile:dualclock") {
Ian Rogerse63db272014-07-15 15:36:11 -0700558 Trace::SetDefaultClockSource(kTraceClockSourceDual);
Calin Juravlec1b643c2014-05-30 23:44:11 +0100559 } else if (option == "-Xenable-profiler") {
560 profiler_options_.enabled_ = true;
Wei Jin2221e3b2014-05-21 18:35:19 -0700561 } else if (StartsWith(option, "-Xprofile-filename:")) {
Ian Rogersf7fd3cb2014-05-19 22:57:34 -0700562 if (!ParseStringAfterChar(option, ':', &profile_output_filename_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800563 return false;
564 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800565 } else if (StartsWith(option, "-Xprofile-period:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100566 if (!ParseUnsignedInteger(option, ':', &profiler_options_.period_s_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800567 return false;
568 }
569 } else if (StartsWith(option, "-Xprofile-duration:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100570 if (!ParseUnsignedInteger(option, ':', &profiler_options_.duration_s_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800571 return false;
572 }
573 } else if (StartsWith(option, "-Xprofile-interval:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100574 if (!ParseUnsignedInteger(option, ':', &profiler_options_.interval_us_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800575 return false;
576 }
577 } else if (StartsWith(option, "-Xprofile-backoff:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100578 if (!ParseDouble(option, ':', 1.0, 10.0, &profiler_options_.backoff_coefficient_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800579 return false;
580 }
Calin Juravlec1b643c2014-05-30 23:44:11 +0100581 } else if (option == "-Xprofile-start-immediately") {
582 profiler_options_.start_immediately_ = true;
583 } else if (StartsWith(option, "-Xprofile-top-k-threshold:")) {
Calin Juravlec321c9b2014-06-11 19:04:35 +0100584 if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_threshold_)) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100585 return false;
586 }
587 } else if (StartsWith(option, "-Xprofile-top-k-change-threshold:")) {
Calin Juravlec321c9b2014-06-11 19:04:35 +0100588 if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_change_threshold_)) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100589 return false;
590 }
Wei Jina93b0bb2014-06-09 16:19:15 -0700591 } else if (option == "-Xprofile-type:method") {
592 profiler_options_.profile_type_ = kProfilerMethod;
Wei Jin445220d2014-06-20 15:56:53 -0700593 } else if (option == "-Xprofile-type:stack") {
594 profiler_options_.profile_type_ = kProfilerBoundedStack;
595 } else if (StartsWith(option, "-Xprofile-max-stack-depth:")) {
596 if (!ParseUnsignedInteger(option, ':', &profiler_options_.max_stack_depth_)) {
597 return false;
598 }
Tsu Chiang Chuang12e6d742014-05-22 10:22:25 -0700599 } else if (StartsWith(option, "-Xcompiler:")) {
600 if (!ParseStringAfterChar(option, ':', &compiler_executable_)) {
601 return false;
602 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800603 } else if (option == "-Xcompiler-option") {
604 i++;
605 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700606 Usage("Missing required compiler option for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800607 return false;
608 }
609 compiler_options_.push_back(options[i].first);
610 } else if (option == "-Ximage-compiler-option") {
611 i++;
612 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700613 Usage("Missing required compiler option for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800614 return false;
615 }
616 image_compiler_options_.push_back(options[i].first);
Jeff Hao4a200f52014-04-01 14:58:49 -0700617 } else if (StartsWith(option, "-Xverify:")) {
618 std::string verify_mode = option.substr(strlen("-Xverify:"));
619 if (verify_mode == "none") {
620 verify_ = false;
621 } else if (verify_mode == "remote" || verify_mode == "all") {
622 verify_ = true;
623 } else {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700624 Usage("Unknown -Xverify option %s\n", verify_mode.c_str());
Jeff Hao4a200f52014-04-01 14:58:49 -0700625 return false;
626 }
Andreas Gampec4a7acf2014-08-08 12:05:10 -0700627 } else if (StartsWith(option, "-XX:NativeBridge=")) {
Calin Juravlea68629e2014-08-22 12:53:59 +0100628 if (!ParseStringAfterChar(option, '=', &native_bridge_library_filename_)) {
Andreas Gampe855564b2014-07-25 02:32:19 -0700629 return false;
630 }
Yevgeny Roubana6119a22014-03-24 11:31:24 +0700631 } else if (StartsWith(option, "-ea") ||
632 StartsWith(option, "-da") ||
633 StartsWith(option, "-enableassertions") ||
634 StartsWith(option, "-disableassertions") ||
Dave Allisonb373e092014-02-20 16:06:36 -0800635 (option == "--runtime-arg") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800636 (option == "-esa") ||
637 (option == "-dsa") ||
638 (option == "-enablesystemassertions") ||
639 (option == "-disablesystemassertions") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800640 (option == "-Xrs") ||
641 StartsWith(option, "-Xint:") ||
642 StartsWith(option, "-Xdexopt:") ||
643 (option == "-Xnoquithandler") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800644 StartsWith(option, "-Xjnigreflimit:") ||
645 (option == "-Xgenregmap") ||
646 (option == "-Xnogenregmap") ||
647 StartsWith(option, "-Xverifyopt:") ||
648 (option == "-Xcheckdexsum") ||
649 (option == "-Xincludeselectedop") ||
650 StartsWith(option, "-Xjitop:") ||
651 (option == "-Xincludeselectedmethod") ||
652 StartsWith(option, "-Xjitthreshold:") ||
653 StartsWith(option, "-Xjitcodecachesize:") ||
654 (option == "-Xjitblocking") ||
655 StartsWith(option, "-Xjitmethod:") ||
656 StartsWith(option, "-Xjitclass:") ||
657 StartsWith(option, "-Xjitoffset:") ||
658 StartsWith(option, "-Xjitconfig:") ||
659 (option == "-Xjitcheckcg") ||
660 (option == "-Xjitverbose") ||
661 (option == "-Xjitprofile") ||
662 (option == "-Xjitdisableopt") ||
663 (option == "-Xjitsuspendpoll") ||
664 StartsWith(option, "-XX:mainThreadStackSize=")) {
665 // Ignored for backwards compatibility.
666 } else if (!ignore_unrecognized) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700667 Usage("Unrecognized option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800668 return false;
669 }
670 }
671
672 // If a reference to the dalvik core.jar snuck in, replace it with
673 // the art specific version. This can happen with on device
674 // boot.art/boot.oat generation by GenerateImage which relies on the
675 // value of BOOTCLASSPATH.
Kenny Rootd5185342014-05-13 14:47:05 -0700676#if defined(ART_TARGET)
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800677 std::string core_jar("/core.jar");
Kenny Rootd5185342014-05-13 14:47:05 -0700678 std::string core_libart_jar("/core-libart.jar");
679#else
680 // The host uses hostdex files.
681 std::string core_jar("/core-hostdex.jar");
682 std::string core_libart_jar("/core-libart-hostdex.jar");
683#endif
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800684 size_t core_jar_pos = boot_class_path_string_.find(core_jar);
685 if (core_jar_pos != std::string::npos) {
Kenny Rootd5185342014-05-13 14:47:05 -0700686 boot_class_path_string_.replace(core_jar_pos, core_jar.size(), core_libart_jar);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800687 }
688
689 if (compiler_callbacks_ == nullptr && image_.empty()) {
690 image_ += GetAndroidRoot();
Brian Carlstrom3ac05bb2014-05-13 19:31:38 -0700691 image_ += "/framework/boot.art";
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800692 }
693 if (heap_growth_limit_ == 0) {
694 heap_growth_limit_ = heap_maximum_size_;
695 }
696 if (background_collector_type_ == gc::kCollectorTypeNone) {
697 background_collector_type_ = collector_type_;
698 }
699 return true;
Narayan Kamath11d9f062014-04-23 20:24:57 +0100700} // NOLINT(readability/fn_size)
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800701
702void ParsedOptions::Exit(int status) {
703 hook_exit_(status);
704}
705
706void ParsedOptions::Abort() {
707 hook_abort_();
708}
709
710void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) {
711 hook_vfprintf_(stderr, fmt, ap);
712}
713
714void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) {
715 va_list ap;
716 va_start(ap, fmt);
717 UsageMessageV(stream, fmt, ap);
718 va_end(ap);
719}
720
721void ParsedOptions::Usage(const char* fmt, ...) {
722 bool error = (fmt != nullptr);
723 FILE* stream = error ? stderr : stdout;
724
725 if (fmt != nullptr) {
726 va_list ap;
727 va_start(ap, fmt);
728 UsageMessageV(stream, fmt, ap);
729 va_end(ap);
730 }
731
732 const char* program = "dalvikvm";
733 UsageMessage(stream, "%s: [options] class [argument ...]\n", program);
734 UsageMessage(stream, "\n");
735 UsageMessage(stream, "The following standard options are supported:\n");
736 UsageMessage(stream, " -classpath classpath (-cp classpath)\n");
737 UsageMessage(stream, " -Dproperty=value\n");
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100738 UsageMessage(stream, " -verbose:tag ('gc', 'jni', or 'class')\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800739 UsageMessage(stream, " -showversion\n");
740 UsageMessage(stream, " -help\n");
741 UsageMessage(stream, " -agentlib:jdwp=options\n");
742 UsageMessage(stream, "\n");
743
744 UsageMessage(stream, "The following extended options are supported:\n");
745 UsageMessage(stream, " -Xrunjdwp:<options>\n");
746 UsageMessage(stream, " -Xbootclasspath:bootclasspath\n");
747 UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n");
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100748 UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n");
749 UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n");
750 UsageMessage(stream, " -XssN (stack size)\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800751 UsageMessage(stream, " -Xint\n");
752 UsageMessage(stream, "\n");
753
754 UsageMessage(stream, "The following Dalvik options are supported:\n");
755 UsageMessage(stream, " -Xzygote\n");
756 UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n");
757 UsageMessage(stream, " -Xstacktracefile:<filename>\n");
758 UsageMessage(stream, " -Xgc:[no]preverify\n");
759 UsageMessage(stream, " -Xgc:[no]postverify\n");
760 UsageMessage(stream, " -XX:+DisableExplicitGC\n");
761 UsageMessage(stream, " -XX:HeapGrowthLimit=N\n");
762 UsageMessage(stream, " -XX:HeapMinFree=N\n");
763 UsageMessage(stream, " -XX:HeapMaxFree=N\n");
Mathieu Chartier6a7824d2014-08-22 14:53:04 -0700764 UsageMessage(stream, " -XX:NonMovingSpaceCapacity=N\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800765 UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n");
Mathieu Chartier455820e2014-04-18 12:02:39 -0700766 UsageMessage(stream, " -XX:ForegroundHeapGrowthMultiplier=doublevalue\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800767 UsageMessage(stream, " -XX:LowMemoryMode\n");
768 UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n");
769 UsageMessage(stream, "\n");
770
771 UsageMessage(stream, "The following unique to ART options are supported:\n");
772 UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n");
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700773 UsageMessage(stream, " -Xgc:[no]postsweepingverify_rosalloc\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800774 UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n");
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700775 UsageMessage(stream, " -Xgc:[no]presweepingverify\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800776 UsageMessage(stream, " -Ximage:filename\n");
777 UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n");
778 UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n");
779 UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n");
780 UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n");
781 UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n");
782 UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n");
783 UsageMessage(stream, " -XX:IgnoreMaxFootprint\n");
784 UsageMessage(stream, " -XX:UseTLAB\n");
785 UsageMessage(stream, " -XX:BackgroundGC=none\n");
786 UsageMessage(stream, " -Xmethod-trace\n");
787 UsageMessage(stream, " -Xmethod-trace-file:filename");
788 UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n");
Calin Juravlec1b643c2014-05-30 23:44:11 +0100789 UsageMessage(stream, " -Xenable-profiler\n");
Wei Jin2221e3b2014-05-21 18:35:19 -0700790 UsageMessage(stream, " -Xprofile-filename:filename\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800791 UsageMessage(stream, " -Xprofile-period:integervalue\n");
792 UsageMessage(stream, " -Xprofile-duration:integervalue\n");
793 UsageMessage(stream, " -Xprofile-interval:integervalue\n");
Calin Juravle54c73ca2014-05-22 12:13:54 +0100794 UsageMessage(stream, " -Xprofile-backoff:doublevalue\n");
Calin Juravlec1b643c2014-05-30 23:44:11 +0100795 UsageMessage(stream, " -Xprofile-start-immediately\n");
796 UsageMessage(stream, " -Xprofile-top-k-threshold:doublevalue\n");
797 UsageMessage(stream, " -Xprofile-top-k-change-threshold:doublevalue\n");
Wei Jin445220d2014-06-20 15:56:53 -0700798 UsageMessage(stream, " -Xprofile-type:{method,stack}\n");
799 UsageMessage(stream, " -Xprofile-max-stack-depth:integervalue\n");
Tsu Chiang Chuang12e6d742014-05-22 10:22:25 -0700800 UsageMessage(stream, " -Xcompiler:filename\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800801 UsageMessage(stream, " -Xcompiler-option dex2oat-option\n");
802 UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n");
Alex Lighta59dd802014-07-02 16:28:08 -0700803 UsageMessage(stream, " -Xpatchoat:filename\n");
804 UsageMessage(stream, " -X[no]relocate\n");
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100805 UsageMessage(stream, " -X[no]dex2oat (Whether to invoke dex2oat on the application)\n");
Alex Light64ad14d2014-08-19 14:23:13 -0700806 UsageMessage(stream, " -X[no]image-dex2oat (Whether to create and use a boot image)\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800807 UsageMessage(stream, "\n");
808
809 UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n");
810 UsageMessage(stream, " -ea[:<package name>... |:<class name>]\n");
811 UsageMessage(stream, " -da[:<package name>... |:<class name>]\n");
812 UsageMessage(stream, " (-enableassertions, -disableassertions)\n");
813 UsageMessage(stream, " -esa\n");
814 UsageMessage(stream, " -dsa\n");
815 UsageMessage(stream, " (-enablesystemassertions, -disablesystemassertions)\n");
816 UsageMessage(stream, " -Xverify:{none,remote,all}\n");
817 UsageMessage(stream, " -Xrs\n");
818 UsageMessage(stream, " -Xint:portable, -Xint:fast, -Xint:jit\n");
819 UsageMessage(stream, " -Xdexopt:{none,verified,all,full}\n");
820 UsageMessage(stream, " -Xnoquithandler\n");
821 UsageMessage(stream, " -Xjniopts:{warnonly,forcecopy}\n");
822 UsageMessage(stream, " -Xjnigreflimit:integervalue\n");
823 UsageMessage(stream, " -Xgc:[no]precise\n");
824 UsageMessage(stream, " -Xgc:[no]verifycardtable\n");
825 UsageMessage(stream, " -X[no]genregmap\n");
826 UsageMessage(stream, " -Xverifyopt:[no]checkmon\n");
827 UsageMessage(stream, " -Xcheckdexsum\n");
828 UsageMessage(stream, " -Xincludeselectedop\n");
829 UsageMessage(stream, " -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*\n");
830 UsageMessage(stream, " -Xincludeselectedmethod\n");
831 UsageMessage(stream, " -Xjitthreshold:integervalue\n");
832 UsageMessage(stream, " -Xjitcodecachesize:decimalvalueofkbytes\n");
833 UsageMessage(stream, " -Xjitblocking\n");
834 UsageMessage(stream, " -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\\;replace)\n");
835 UsageMessage(stream, " -Xjitclass:classname[,classname]*\n");
836 UsageMessage(stream, " -Xjitoffset:offset[,offset]\n");
837 UsageMessage(stream, " -Xjitconfig:filename\n");
838 UsageMessage(stream, " -Xjitcheckcg\n");
839 UsageMessage(stream, " -Xjitverbose\n");
840 UsageMessage(stream, " -Xjitprofile\n");
841 UsageMessage(stream, " -Xjitdisableopt\n");
842 UsageMessage(stream, " -Xjitsuspendpoll\n");
843 UsageMessage(stream, " -XX:mainThreadStackSize=N\n");
844 UsageMessage(stream, "\n");
845
846 Exit((error) ? 1 : 0);
847}
848
849bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) {
850 std::string::size_type colon = s.find(c);
851 if (colon == std::string::npos) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700852 Usage("Missing char %c in option %s\n", c, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800853 return false;
854 }
855 // Add one to remove the char we were trimming until.
856 *parsed_value = s.substr(colon + 1);
857 return true;
858}
859
860bool ParsedOptions::ParseInteger(const std::string& s, char after_char, int* parsed_value) {
861 std::string::size_type colon = s.find(after_char);
862 if (colon == std::string::npos) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700863 Usage("Missing char %c in option %s\n", after_char, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800864 return false;
865 }
866 const char* begin = &s[colon + 1];
867 char* end;
868 size_t result = strtoul(begin, &end, 10);
869 if (begin == end || *end != '\0') {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700870 Usage("Failed to parse integer from %s\n", s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800871 return false;
872 }
873 *parsed_value = result;
874 return true;
875}
876
877bool ParsedOptions::ParseUnsignedInteger(const std::string& s, char after_char,
878 unsigned int* parsed_value) {
879 int i;
880 if (!ParseInteger(s, after_char, &i)) {
881 return false;
882 }
883 if (i < 0) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700884 Usage("Negative value %d passed for unsigned option %s\n", i, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800885 return false;
886 }
887 *parsed_value = i;
888 return true;
889}
890
891bool ParsedOptions::ParseDouble(const std::string& option, char after_char,
892 double min, double max, double* parsed_value) {
893 std::string substring;
894 if (!ParseStringAfterChar(option, after_char, &substring)) {
895 return false;
896 }
Dave Allison999385c2014-05-20 15:16:02 -0700897 bool sane_val = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800898 double value;
Dave Allison999385c2014-05-20 15:16:02 -0700899 if (false) {
900 // TODO: this doesn't seem to work on the emulator. b/15114595
901 std::stringstream iss(substring);
902 iss >> value;
903 // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range.
904 sane_val = iss.eof() && (value >= min) && (value <= max);
905 } else {
906 char* end = nullptr;
907 value = strtod(substring.c_str(), &end);
908 sane_val = *end == '\0' && value >= min && value <= max;
909 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800910 if (!sane_val) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700911 Usage("Invalid double value %s for option %s\n", substring.c_str(), option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800912 return false;
913 }
914 *parsed_value = value;
915 return true;
916}
917
918} // namespace art