blob: 3e6c86b7c9ec39ca1d2389fe5fabd3b38a00148e [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
Ian Rogersc7dd2952014-10-21 23:31:19 -070019#include <sstream>
20
Dave Allisonb373e092014-02-20 16:06:36 -080021#ifdef HAVE_ANDROID_OS
22#include "cutils/properties.h"
23#endif
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080024
Ian Rogers576ca0c2014-06-06 15:58:22 -070025#include "base/stringpiece.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080026#include "debugger.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070027#include "gc/heap.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080028#include "monitor.h"
Ian Rogerse63db272014-07-15 15:36:11 -070029#include "runtime.h"
30#include "trace.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070031#include "utils.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080032
33namespace art {
34
Andreas Gampe313f4032014-08-29 16:01:25 -070035ParsedOptions::ParsedOptions()
36 :
37 boot_class_path_(nullptr),
38 check_jni_(kIsDebugBuild), // -Xcheck:jni is off by default for regular
39 // builds but on by default in debug builds.
40 force_copy_(false),
41 compiler_callbacks_(nullptr),
42 is_zygote_(false),
43 must_relocate_(kDefaultMustRelocate),
44 dex2oat_enabled_(true),
45 image_dex2oat_enabled_(true),
46 interpreter_only_(kPoisonHeapReferences), // kPoisonHeapReferences currently works with
47 // the interpreter only.
48 // TODO: make it work with the compiler.
49 is_explicit_gc_disabled_(false),
50 use_tlab_(false),
51 verify_pre_gc_heap_(false),
52 verify_pre_sweeping_heap_(kIsDebugBuild), // Pre sweeping is the one that usually fails
53 // if the GC corrupted the heap.
54 verify_post_gc_heap_(false),
55 verify_pre_gc_rosalloc_(kIsDebugBuild),
56 verify_pre_sweeping_rosalloc_(false),
57 verify_post_gc_rosalloc_(false),
58 long_pause_log_threshold_(gc::Heap::kDefaultLongPauseLogThreshold),
59 long_gc_log_threshold_(gc::Heap::kDefaultLongGCLogThreshold),
60 dump_gc_performance_on_shutdown_(false),
61 ignore_max_footprint_(false),
62 heap_initial_size_(gc::Heap::kDefaultInitialSize),
63 heap_maximum_size_(gc::Heap::kDefaultMaximumSize),
64 heap_growth_limit_(0), // 0 means no growth limit.
65 heap_min_free_(gc::Heap::kDefaultMinFree),
66 heap_max_free_(gc::Heap::kDefaultMaxFree),
67 heap_non_moving_space_capacity_(gc::Heap::kDefaultNonMovingSpaceCapacity),
Mathieu Chartier2dbe6272014-09-16 10:43:23 -070068 large_object_space_type_(gc::Heap::kDefaultLargeObjectSpaceType),
69 large_object_threshold_(gc::Heap::kDefaultLargeObjectThreshold),
Andreas Gampe313f4032014-08-29 16:01:25 -070070 heap_target_utilization_(gc::Heap::kDefaultTargetUtilization),
71 foreground_heap_growth_multiplier_(gc::Heap::kDefaultHeapGrowthMultiplier),
72 parallel_gc_threads_(1),
Andreas Gampe2c2426c2014-08-29 18:15:04 -070073 conc_gc_threads_(0), // Only the main GC thread, no workers.
Andreas Gampe313f4032014-08-29 16:01:25 -070074 collector_type_( // The default GC type is set in makefiles.
75#if ART_DEFAULT_GC_TYPE_IS_CMS
76 gc::kCollectorTypeCMS),
77#elif ART_DEFAULT_GC_TYPE_IS_SS
78 gc::kCollectorTypeSS),
79#elif ART_DEFAULT_GC_TYPE_IS_GSS
80 gc::kCollectorTypeGSS),
81#else
82 gc::kCollectorTypeCMS),
83#error "ART default GC type must be set"
84#endif
Mathieu Chartier6b2352b2014-08-20 14:13:18 -070085 background_collector_type_(gc::kCollectorTypeNone),
Andreas Gampe313f4032014-08-29 16:01:25 -070086 // If background_collector_type_ is
87 // kCollectorTypeNone, it defaults to the
88 // collector_type_ after parsing options. If
89 // you set this to kCollectorTypeHSpaceCompact
90 // then we will do an hspace compaction when
91 // we transition to background instead of a
92 // normal collector transition.
93 stack_size_(0), // 0 means default.
94 max_spins_before_thin_lock_inflation_(Monitor::kDefaultMaxSpinsBeforeThinLockInflation),
95 low_memory_mode_(false),
96 lock_profiling_threshold_(0),
97 method_trace_(false),
98 method_trace_file_("/data/method-trace-file.bin"),
99 method_trace_file_size_(10 * MB),
100 hook_is_sensitive_thread_(nullptr),
101 hook_vfprintf_(vfprintf),
102 hook_exit_(exit),
103 hook_abort_(nullptr), // We don't call abort(3) by default; see
104 // Runtime::Abort.
105 profile_clock_source_(kDefaultTraceClockSource),
106 verify_(true),
107 image_isa_(kRuntimeISA),
Hiroshi Yamauchi20ed5af2014-11-17 18:05:44 -0800108 use_homogeneous_space_compaction_for_oom_(true), // Enable hspace compaction on OOM by default.
Andreas Gampe313f4032014-08-29 16:01:25 -0700109 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;
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700206 Split(option.substr(strlen("-Xgc:")), ',', &gc_options);
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700207 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 }
Mathieu Chartier2dbe6272014-09-16 10:43:23 -0700455 } else if (StartsWith(option, "-XX:LargeObjectSpace=")) {
456 std::string substring;
457 if (!ParseStringAfterChar(option, '=', &substring)) {
458 return false;
459 }
460 if (substring == "disabled") {
461 large_object_space_type_ = gc::space::kLargeObjectSpaceTypeDisabled;
462 } else if (substring == "freelist") {
463 large_object_space_type_ = gc::space::kLargeObjectSpaceTypeFreeList;
464 } else if (substring == "map") {
465 large_object_space_type_ = gc::space::kLargeObjectSpaceTypeMap;
466 } else {
467 Usage("Unknown -XX:LargeObjectSpace= option %s\n", substring.c_str());
468 return false;
469 }
470 } else if (StartsWith(option, "-XX:LargeObjectThreshold=")) {
471 std::string substring;
472 if (!ParseStringAfterChar(option, '=', &substring)) {
473 return false;
474 }
475 size_t size = ParseMemoryOption(substring.c_str(), 1);
476 if (size == 0) {
477 Usage("Failed to parse memory option %s\n", option.c_str());
478 return false;
479 }
480 large_object_threshold_ = size;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800481 } else if (StartsWith(option, "-XX:BackgroundGC=")) {
482 std::string substring;
483 if (!ParseStringAfterChar(option, '=', &substring)) {
484 return false;
485 }
Zuo Wangf37a88b2014-07-10 04:26:41 -0700486 // Special handling for HSpaceCompact since this is only valid as a background GC type.
487 if (substring == "HSpaceCompact") {
488 background_collector_type_ = gc::kCollectorTypeHomogeneousSpaceCompact;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800489 } else {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700490 gc::CollectorType collector_type = ParseCollectorType(substring);
491 if (collector_type != gc::kCollectorTypeNone) {
492 background_collector_type_ = collector_type;
493 } else {
494 Usage("Unknown -XX:BackgroundGC option %s\n", substring.c_str());
495 return false;
496 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800497 }
498 } else if (option == "-XX:+DisableExplicitGC") {
499 is_explicit_gc_disabled_ = true;
500 } else if (StartsWith(option, "-verbose:")) {
501 std::vector<std::string> verbose_options;
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700502 Split(option.substr(strlen("-verbose:")), ',', &verbose_options);
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800503 for (size_t j = 0; j < verbose_options.size(); ++j) {
504 if (verbose_options[j] == "class") {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800505 gLogVerbosity.class_linker = true;
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800506 } else if (verbose_options[j] == "compiler") {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800507 gLogVerbosity.compiler = true;
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800508 } else if (verbose_options[j] == "gc") {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800509 gLogVerbosity.gc = true;
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800510 } else if (verbose_options[j] == "heap") {
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700511 gLogVerbosity.heap = true;
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800512 } else if (verbose_options[j] == "jdwp") {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800513 gLogVerbosity.jdwp = true;
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800514 } else if (verbose_options[j] == "jni") {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800515 gLogVerbosity.jni = true;
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800516 } else if (verbose_options[j] == "monitor") {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800517 gLogVerbosity.monitor = true;
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800518 } else if (verbose_options[j] == "profiler") {
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700519 gLogVerbosity.profiler = true;
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800520 } else if (verbose_options[j] == "signals") {
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700521 gLogVerbosity.signals = true;
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800522 } else if (verbose_options[j] == "startup") {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800523 gLogVerbosity.startup = true;
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800524 } else if (verbose_options[j] == "third-party-jni") {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800525 gLogVerbosity.third_party_jni = true;
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800526 } else if (verbose_options[j] == "threads") {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800527 gLogVerbosity.threads = true;
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800528 } else if (verbose_options[j] == "verifier") {
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700529 gLogVerbosity.verifier = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800530 } else {
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800531 Usage("Unknown -verbose option %s\n", verbose_options[j].c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800532 return false;
533 }
534 }
535 } else if (StartsWith(option, "-Xlockprofthreshold:")) {
536 if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) {
537 return false;
538 }
539 } else if (StartsWith(option, "-Xstacktracefile:")) {
540 if (!ParseStringAfterChar(option, ':', &stack_trace_file_)) {
541 return false;
542 }
543 } else if (option == "sensitiveThread") {
544 const void* hook = options[i].second;
545 hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(hook));
546 } else if (option == "vfprintf") {
547 const void* hook = options[i].second;
548 if (hook == nullptr) {
549 Usage("vfprintf argument was NULL");
550 return false;
551 }
552 hook_vfprintf_ =
553 reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook));
554 } else if (option == "exit") {
555 const void* hook = options[i].second;
556 if (hook == nullptr) {
557 Usage("exit argument was NULL");
558 return false;
559 }
560 hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook));
561 } else if (option == "abort") {
562 const void* hook = options[i].second;
563 if (hook == nullptr) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700564 Usage("abort was NULL\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800565 return false;
566 }
567 hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook));
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800568 } else if (option == "-Xmethod-trace") {
569 method_trace_ = true;
570 } else if (StartsWith(option, "-Xmethod-trace-file:")) {
571 method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:"));
572 } else if (StartsWith(option, "-Xmethod-trace-file-size:")) {
573 if (!ParseUnsignedInteger(option, ':', &method_trace_file_size_)) {
574 return false;
575 }
576 } else if (option == "-Xprofile:threadcpuclock") {
Ian Rogerse63db272014-07-15 15:36:11 -0700577 Trace::SetDefaultClockSource(kTraceClockSourceThreadCpu);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800578 } else if (option == "-Xprofile:wallclock") {
Ian Rogerse63db272014-07-15 15:36:11 -0700579 Trace::SetDefaultClockSource(kTraceClockSourceWall);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800580 } else if (option == "-Xprofile:dualclock") {
Ian Rogerse63db272014-07-15 15:36:11 -0700581 Trace::SetDefaultClockSource(kTraceClockSourceDual);
Calin Juravlec1b643c2014-05-30 23:44:11 +0100582 } else if (option == "-Xenable-profiler") {
583 profiler_options_.enabled_ = true;
Wei Jin2221e3b2014-05-21 18:35:19 -0700584 } else if (StartsWith(option, "-Xprofile-filename:")) {
Ian Rogersf7fd3cb2014-05-19 22:57:34 -0700585 if (!ParseStringAfterChar(option, ':', &profile_output_filename_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800586 return false;
587 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800588 } else if (StartsWith(option, "-Xprofile-period:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100589 if (!ParseUnsignedInteger(option, ':', &profiler_options_.period_s_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800590 return false;
591 }
592 } else if (StartsWith(option, "-Xprofile-duration:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100593 if (!ParseUnsignedInteger(option, ':', &profiler_options_.duration_s_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800594 return false;
595 }
596 } else if (StartsWith(option, "-Xprofile-interval:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100597 if (!ParseUnsignedInteger(option, ':', &profiler_options_.interval_us_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800598 return false;
599 }
600 } else if (StartsWith(option, "-Xprofile-backoff:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100601 if (!ParseDouble(option, ':', 1.0, 10.0, &profiler_options_.backoff_coefficient_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800602 return false;
603 }
Calin Juravlec1b643c2014-05-30 23:44:11 +0100604 } else if (option == "-Xprofile-start-immediately") {
605 profiler_options_.start_immediately_ = true;
606 } else if (StartsWith(option, "-Xprofile-top-k-threshold:")) {
Calin Juravlec321c9b2014-06-11 19:04:35 +0100607 if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_threshold_)) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100608 return false;
609 }
610 } else if (StartsWith(option, "-Xprofile-top-k-change-threshold:")) {
Calin Juravlec321c9b2014-06-11 19:04:35 +0100611 if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_change_threshold_)) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100612 return false;
613 }
Wei Jina93b0bb2014-06-09 16:19:15 -0700614 } else if (option == "-Xprofile-type:method") {
615 profiler_options_.profile_type_ = kProfilerMethod;
Wei Jin445220d2014-06-20 15:56:53 -0700616 } else if (option == "-Xprofile-type:stack") {
617 profiler_options_.profile_type_ = kProfilerBoundedStack;
618 } else if (StartsWith(option, "-Xprofile-max-stack-depth:")) {
619 if (!ParseUnsignedInteger(option, ':', &profiler_options_.max_stack_depth_)) {
620 return false;
621 }
Tsu Chiang Chuang12e6d742014-05-22 10:22:25 -0700622 } else if (StartsWith(option, "-Xcompiler:")) {
623 if (!ParseStringAfterChar(option, ':', &compiler_executable_)) {
624 return false;
625 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800626 } else if (option == "-Xcompiler-option") {
627 i++;
628 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700629 Usage("Missing required compiler option for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800630 return false;
631 }
632 compiler_options_.push_back(options[i].first);
633 } else if (option == "-Ximage-compiler-option") {
634 i++;
635 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700636 Usage("Missing required compiler option for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800637 return false;
638 }
639 image_compiler_options_.push_back(options[i].first);
Jeff Hao4a200f52014-04-01 14:58:49 -0700640 } else if (StartsWith(option, "-Xverify:")) {
641 std::string verify_mode = option.substr(strlen("-Xverify:"));
642 if (verify_mode == "none") {
643 verify_ = false;
644 } else if (verify_mode == "remote" || verify_mode == "all") {
645 verify_ = true;
646 } else {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700647 Usage("Unknown -Xverify option %s\n", verify_mode.c_str());
Jeff Hao4a200f52014-04-01 14:58:49 -0700648 return false;
649 }
Andreas Gampec4a7acf2014-08-08 12:05:10 -0700650 } else if (StartsWith(option, "-XX:NativeBridge=")) {
Calin Juravlea68629e2014-08-22 12:53:59 +0100651 if (!ParseStringAfterChar(option, '=', &native_bridge_library_filename_)) {
Andreas Gampe855564b2014-07-25 02:32:19 -0700652 return false;
653 }
Yevgeny Roubana6119a22014-03-24 11:31:24 +0700654 } else if (StartsWith(option, "-ea") ||
655 StartsWith(option, "-da") ||
656 StartsWith(option, "-enableassertions") ||
657 StartsWith(option, "-disableassertions") ||
Dave Allisonb373e092014-02-20 16:06:36 -0800658 (option == "--runtime-arg") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800659 (option == "-esa") ||
660 (option == "-dsa") ||
661 (option == "-enablesystemassertions") ||
662 (option == "-disablesystemassertions") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800663 (option == "-Xrs") ||
664 StartsWith(option, "-Xint:") ||
665 StartsWith(option, "-Xdexopt:") ||
666 (option == "-Xnoquithandler") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800667 StartsWith(option, "-Xjnigreflimit:") ||
668 (option == "-Xgenregmap") ||
669 (option == "-Xnogenregmap") ||
670 StartsWith(option, "-Xverifyopt:") ||
671 (option == "-Xcheckdexsum") ||
672 (option == "-Xincludeselectedop") ||
673 StartsWith(option, "-Xjitop:") ||
674 (option == "-Xincludeselectedmethod") ||
675 StartsWith(option, "-Xjitthreshold:") ||
676 StartsWith(option, "-Xjitcodecachesize:") ||
677 (option == "-Xjitblocking") ||
678 StartsWith(option, "-Xjitmethod:") ||
679 StartsWith(option, "-Xjitclass:") ||
680 StartsWith(option, "-Xjitoffset:") ||
681 StartsWith(option, "-Xjitconfig:") ||
682 (option == "-Xjitcheckcg") ||
683 (option == "-Xjitverbose") ||
684 (option == "-Xjitprofile") ||
685 (option == "-Xjitdisableopt") ||
686 (option == "-Xjitsuspendpoll") ||
687 StartsWith(option, "-XX:mainThreadStackSize=")) {
688 // Ignored for backwards compatibility.
689 } else if (!ignore_unrecognized) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700690 Usage("Unrecognized option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800691 return false;
692 }
693 }
Mathieu Chartier6b2352b2014-08-20 14:13:18 -0700694 // If not set, background collector type defaults to homogeneous compaction
695 // if not low memory mode, semispace otherwise.
696 if (background_collector_type_ == gc::kCollectorTypeNone) {
697 background_collector_type_ = low_memory_mode_ ?
698 gc::kCollectorTypeSS : gc::kCollectorTypeHomogeneousSpaceCompact;
699 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800700
701 // If a reference to the dalvik core.jar snuck in, replace it with
702 // the art specific version. This can happen with on device
703 // boot.art/boot.oat generation by GenerateImage which relies on the
704 // value of BOOTCLASSPATH.
Kenny Rootd5185342014-05-13 14:47:05 -0700705#if defined(ART_TARGET)
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800706 std::string core_jar("/core.jar");
Kenny Rootd5185342014-05-13 14:47:05 -0700707 std::string core_libart_jar("/core-libart.jar");
708#else
709 // The host uses hostdex files.
710 std::string core_jar("/core-hostdex.jar");
711 std::string core_libart_jar("/core-libart-hostdex.jar");
712#endif
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800713 size_t core_jar_pos = boot_class_path_string_.find(core_jar);
714 if (core_jar_pos != std::string::npos) {
Kenny Rootd5185342014-05-13 14:47:05 -0700715 boot_class_path_string_.replace(core_jar_pos, core_jar.size(), core_libart_jar);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800716 }
717
718 if (compiler_callbacks_ == nullptr && image_.empty()) {
719 image_ += GetAndroidRoot();
Brian Carlstrom3ac05bb2014-05-13 19:31:38 -0700720 image_ += "/framework/boot.art";
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800721 }
722 if (heap_growth_limit_ == 0) {
723 heap_growth_limit_ = heap_maximum_size_;
724 }
725 if (background_collector_type_ == gc::kCollectorTypeNone) {
726 background_collector_type_ = collector_type_;
727 }
728 return true;
Narayan Kamath11d9f062014-04-23 20:24:57 +0100729} // NOLINT(readability/fn_size)
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800730
731void ParsedOptions::Exit(int status) {
732 hook_exit_(status);
733}
734
735void ParsedOptions::Abort() {
736 hook_abort_();
737}
738
739void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700740 hook_vfprintf_(stream, fmt, ap);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800741}
742
743void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) {
744 va_list ap;
745 va_start(ap, fmt);
746 UsageMessageV(stream, fmt, ap);
747 va_end(ap);
748}
749
750void ParsedOptions::Usage(const char* fmt, ...) {
751 bool error = (fmt != nullptr);
752 FILE* stream = error ? stderr : stdout;
753
754 if (fmt != nullptr) {
755 va_list ap;
756 va_start(ap, fmt);
757 UsageMessageV(stream, fmt, ap);
758 va_end(ap);
759 }
760
761 const char* program = "dalvikvm";
762 UsageMessage(stream, "%s: [options] class [argument ...]\n", program);
763 UsageMessage(stream, "\n");
764 UsageMessage(stream, "The following standard options are supported:\n");
765 UsageMessage(stream, " -classpath classpath (-cp classpath)\n");
766 UsageMessage(stream, " -Dproperty=value\n");
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100767 UsageMessage(stream, " -verbose:tag ('gc', 'jni', or 'class')\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800768 UsageMessage(stream, " -showversion\n");
769 UsageMessage(stream, " -help\n");
770 UsageMessage(stream, " -agentlib:jdwp=options\n");
771 UsageMessage(stream, "\n");
772
773 UsageMessage(stream, "The following extended options are supported:\n");
774 UsageMessage(stream, " -Xrunjdwp:<options>\n");
775 UsageMessage(stream, " -Xbootclasspath:bootclasspath\n");
776 UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n");
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100777 UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n");
778 UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n");
779 UsageMessage(stream, " -XssN (stack size)\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800780 UsageMessage(stream, " -Xint\n");
781 UsageMessage(stream, "\n");
782
783 UsageMessage(stream, "The following Dalvik options are supported:\n");
784 UsageMessage(stream, " -Xzygote\n");
785 UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n");
786 UsageMessage(stream, " -Xstacktracefile:<filename>\n");
787 UsageMessage(stream, " -Xgc:[no]preverify\n");
788 UsageMessage(stream, " -Xgc:[no]postverify\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800789 UsageMessage(stream, " -XX:HeapGrowthLimit=N\n");
790 UsageMessage(stream, " -XX:HeapMinFree=N\n");
791 UsageMessage(stream, " -XX:HeapMaxFree=N\n");
Mathieu Chartier6a7824d2014-08-22 14:53:04 -0700792 UsageMessage(stream, " -XX:NonMovingSpaceCapacity=N\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800793 UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n");
Mathieu Chartier455820e2014-04-18 12:02:39 -0700794 UsageMessage(stream, " -XX:ForegroundHeapGrowthMultiplier=doublevalue\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800795 UsageMessage(stream, " -XX:LowMemoryMode\n");
796 UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n");
797 UsageMessage(stream, "\n");
798
799 UsageMessage(stream, "The following unique to ART options are supported:\n");
800 UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n");
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700801 UsageMessage(stream, " -Xgc:[no]postsweepingverify_rosalloc\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800802 UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n");
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700803 UsageMessage(stream, " -Xgc:[no]presweepingverify\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800804 UsageMessage(stream, " -Ximage:filename\n");
Mathieu Chartier2dbe6272014-09-16 10:43:23 -0700805 UsageMessage(stream, " -XX:+DisableExplicitGC\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800806 UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n");
807 UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n");
808 UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n");
809 UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n");
810 UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n");
811 UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n");
812 UsageMessage(stream, " -XX:IgnoreMaxFootprint\n");
813 UsageMessage(stream, " -XX:UseTLAB\n");
814 UsageMessage(stream, " -XX:BackgroundGC=none\n");
Mathieu Chartier2dbe6272014-09-16 10:43:23 -0700815 UsageMessage(stream, " -XX:LargeObjectSpace={disabled,map,freelist}\n");
816 UsageMessage(stream, " -XX:LargeObjectThreshold=N\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800817 UsageMessage(stream, " -Xmethod-trace\n");
818 UsageMessage(stream, " -Xmethod-trace-file:filename");
819 UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n");
Calin Juravlec1b643c2014-05-30 23:44:11 +0100820 UsageMessage(stream, " -Xenable-profiler\n");
Wei Jin2221e3b2014-05-21 18:35:19 -0700821 UsageMessage(stream, " -Xprofile-filename:filename\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800822 UsageMessage(stream, " -Xprofile-period:integervalue\n");
823 UsageMessage(stream, " -Xprofile-duration:integervalue\n");
824 UsageMessage(stream, " -Xprofile-interval:integervalue\n");
Calin Juravle54c73ca2014-05-22 12:13:54 +0100825 UsageMessage(stream, " -Xprofile-backoff:doublevalue\n");
Calin Juravlec1b643c2014-05-30 23:44:11 +0100826 UsageMessage(stream, " -Xprofile-start-immediately\n");
827 UsageMessage(stream, " -Xprofile-top-k-threshold:doublevalue\n");
828 UsageMessage(stream, " -Xprofile-top-k-change-threshold:doublevalue\n");
Wei Jin445220d2014-06-20 15:56:53 -0700829 UsageMessage(stream, " -Xprofile-type:{method,stack}\n");
830 UsageMessage(stream, " -Xprofile-max-stack-depth:integervalue\n");
Tsu Chiang Chuang12e6d742014-05-22 10:22:25 -0700831 UsageMessage(stream, " -Xcompiler:filename\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800832 UsageMessage(stream, " -Xcompiler-option dex2oat-option\n");
833 UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n");
Alex Lighta59dd802014-07-02 16:28:08 -0700834 UsageMessage(stream, " -Xpatchoat:filename\n");
835 UsageMessage(stream, " -X[no]relocate\n");
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100836 UsageMessage(stream, " -X[no]dex2oat (Whether to invoke dex2oat on the application)\n");
Alex Light64ad14d2014-08-19 14:23:13 -0700837 UsageMessage(stream, " -X[no]image-dex2oat (Whether to create and use a boot image)\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800838 UsageMessage(stream, "\n");
839
840 UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n");
841 UsageMessage(stream, " -ea[:<package name>... |:<class name>]\n");
842 UsageMessage(stream, " -da[:<package name>... |:<class name>]\n");
843 UsageMessage(stream, " (-enableassertions, -disableassertions)\n");
844 UsageMessage(stream, " -esa\n");
845 UsageMessage(stream, " -dsa\n");
846 UsageMessage(stream, " (-enablesystemassertions, -disablesystemassertions)\n");
847 UsageMessage(stream, " -Xverify:{none,remote,all}\n");
848 UsageMessage(stream, " -Xrs\n");
849 UsageMessage(stream, " -Xint:portable, -Xint:fast, -Xint:jit\n");
850 UsageMessage(stream, " -Xdexopt:{none,verified,all,full}\n");
851 UsageMessage(stream, " -Xnoquithandler\n");
852 UsageMessage(stream, " -Xjniopts:{warnonly,forcecopy}\n");
853 UsageMessage(stream, " -Xjnigreflimit:integervalue\n");
854 UsageMessage(stream, " -Xgc:[no]precise\n");
855 UsageMessage(stream, " -Xgc:[no]verifycardtable\n");
856 UsageMessage(stream, " -X[no]genregmap\n");
857 UsageMessage(stream, " -Xverifyopt:[no]checkmon\n");
858 UsageMessage(stream, " -Xcheckdexsum\n");
859 UsageMessage(stream, " -Xincludeselectedop\n");
860 UsageMessage(stream, " -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*\n");
861 UsageMessage(stream, " -Xincludeselectedmethod\n");
862 UsageMessage(stream, " -Xjitthreshold:integervalue\n");
863 UsageMessage(stream, " -Xjitcodecachesize:decimalvalueofkbytes\n");
864 UsageMessage(stream, " -Xjitblocking\n");
865 UsageMessage(stream, " -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\\;replace)\n");
866 UsageMessage(stream, " -Xjitclass:classname[,classname]*\n");
867 UsageMessage(stream, " -Xjitoffset:offset[,offset]\n");
868 UsageMessage(stream, " -Xjitconfig:filename\n");
869 UsageMessage(stream, " -Xjitcheckcg\n");
870 UsageMessage(stream, " -Xjitverbose\n");
871 UsageMessage(stream, " -Xjitprofile\n");
872 UsageMessage(stream, " -Xjitdisableopt\n");
873 UsageMessage(stream, " -Xjitsuspendpoll\n");
874 UsageMessage(stream, " -XX:mainThreadStackSize=N\n");
875 UsageMessage(stream, "\n");
876
877 Exit((error) ? 1 : 0);
878}
879
880bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) {
881 std::string::size_type colon = s.find(c);
882 if (colon == std::string::npos) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700883 Usage("Missing char %c in option %s\n", c, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800884 return false;
885 }
886 // Add one to remove the char we were trimming until.
887 *parsed_value = s.substr(colon + 1);
888 return true;
889}
890
891bool ParsedOptions::ParseInteger(const std::string& s, char after_char, int* parsed_value) {
892 std::string::size_type colon = s.find(after_char);
893 if (colon == std::string::npos) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700894 Usage("Missing char %c in option %s\n", after_char, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800895 return false;
896 }
897 const char* begin = &s[colon + 1];
898 char* end;
899 size_t result = strtoul(begin, &end, 10);
900 if (begin == end || *end != '\0') {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700901 Usage("Failed to parse integer from %s\n", s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800902 return false;
903 }
904 *parsed_value = result;
905 return true;
906}
907
908bool ParsedOptions::ParseUnsignedInteger(const std::string& s, char after_char,
909 unsigned int* parsed_value) {
910 int i;
911 if (!ParseInteger(s, after_char, &i)) {
912 return false;
913 }
914 if (i < 0) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700915 Usage("Negative value %d passed for unsigned option %s\n", i, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800916 return false;
917 }
918 *parsed_value = i;
919 return true;
920}
921
922bool ParsedOptions::ParseDouble(const std::string& option, char after_char,
923 double min, double max, double* parsed_value) {
924 std::string substring;
925 if (!ParseStringAfterChar(option, after_char, &substring)) {
926 return false;
927 }
Dave Allison999385c2014-05-20 15:16:02 -0700928 bool sane_val = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800929 double value;
Ian Rogers07140832014-09-30 15:43:59 -0700930 if ((false)) {
Dave Allison999385c2014-05-20 15:16:02 -0700931 // TODO: this doesn't seem to work on the emulator. b/15114595
932 std::stringstream iss(substring);
933 iss >> value;
934 // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range.
935 sane_val = iss.eof() && (value >= min) && (value <= max);
936 } else {
937 char* end = nullptr;
938 value = strtod(substring.c_str(), &end);
939 sane_val = *end == '\0' && value >= min && value <= max;
940 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800941 if (!sane_val) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700942 Usage("Invalid double value %s for option %s\n", substring.c_str(), option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800943 return false;
944 }
945 *parsed_value = value;
946 return true;
947}
948
949} // namespace art