blob: 6b4f764d6e648f5d694ce6c916e623354f96d443 [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),
Mathieu Chartier2dbe6272014-09-16 10:43:23 -070066 large_object_space_type_(gc::Heap::kDefaultLargeObjectSpaceType),
67 large_object_threshold_(gc::Heap::kDefaultLargeObjectThreshold),
Andreas Gampe313f4032014-08-29 16:01:25 -070068 heap_target_utilization_(gc::Heap::kDefaultTargetUtilization),
69 foreground_heap_growth_multiplier_(gc::Heap::kDefaultHeapGrowthMultiplier),
70 parallel_gc_threads_(1),
Andreas Gampe2c2426c2014-08-29 18:15:04 -070071 conc_gc_threads_(0), // Only the main GC thread, no workers.
Andreas Gampe313f4032014-08-29 16:01:25 -070072 collector_type_( // The default GC type is set in makefiles.
73#if ART_DEFAULT_GC_TYPE_IS_CMS
74 gc::kCollectorTypeCMS),
75#elif ART_DEFAULT_GC_TYPE_IS_SS
76 gc::kCollectorTypeSS),
77#elif ART_DEFAULT_GC_TYPE_IS_GSS
78 gc::kCollectorTypeGSS),
79#else
80 gc::kCollectorTypeCMS),
81#error "ART default GC type must be set"
82#endif
83 background_collector_type_(gc::kCollectorTypeHomogeneousSpaceCompact),
84 // If background_collector_type_ is
85 // kCollectorTypeNone, it defaults to the
86 // collector_type_ after parsing options. If
87 // you set this to kCollectorTypeHSpaceCompact
88 // then we will do an hspace compaction when
89 // we transition to background instead of a
90 // normal collector transition.
91 stack_size_(0), // 0 means default.
92 max_spins_before_thin_lock_inflation_(Monitor::kDefaultMaxSpinsBeforeThinLockInflation),
93 low_memory_mode_(false),
94 lock_profiling_threshold_(0),
95 method_trace_(false),
96 method_trace_file_("/data/method-trace-file.bin"),
97 method_trace_file_size_(10 * MB),
98 hook_is_sensitive_thread_(nullptr),
99 hook_vfprintf_(vfprintf),
100 hook_exit_(exit),
101 hook_abort_(nullptr), // We don't call abort(3) by default; see
102 // Runtime::Abort.
103 profile_clock_source_(kDefaultTraceClockSource),
104 verify_(true),
105 image_isa_(kRuntimeISA),
106 use_homogeneous_space_compaction_for_oom_(false), // If we are using homogeneous space
107 // compaction then default background
108 // compaction to off since homogeneous
109 // space compactions when we transition
110 // to not jank perceptible.
111 min_interval_homogeneous_space_compaction_by_oom_(MsToNs(100 * 1000)) // 100s.
112 {}
113
Ian Rogerse63db272014-07-15 15:36:11 -0700114ParsedOptions* ParsedOptions::Create(const RuntimeOptions& options, bool ignore_unrecognized) {
Ian Rogers700a4022014-05-19 16:49:03 -0700115 std::unique_ptr<ParsedOptions> parsed(new ParsedOptions());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800116 if (parsed->Parse(options, ignore_unrecognized)) {
117 return parsed.release();
118 }
119 return nullptr;
120}
121
122// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
123// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
124// [gG] gigabytes.
125//
126// "s" should point just past the "-Xm?" part of the string.
127// "div" specifies a divisor, e.g. 1024 if the value must be a multiple
128// of 1024.
129//
130// The spec says the -Xmx and -Xms options must be multiples of 1024. It
131// doesn't say anything about -Xss.
132//
133// Returns 0 (a useless size) if "s" is malformed or specifies a low or
134// non-evenly-divisible value.
135//
136size_t ParseMemoryOption(const char* s, size_t div) {
137 // strtoul accepts a leading [+-], which we don't want,
138 // so make sure our string starts with a decimal digit.
139 if (isdigit(*s)) {
140 char* s2;
141 size_t val = strtoul(s, &s2, 10);
142 if (s2 != s) {
143 // s2 should be pointing just after the number.
144 // If this is the end of the string, the user
145 // has specified a number of bytes. Otherwise,
146 // there should be exactly one more character
147 // that specifies a multiplier.
148 if (*s2 != '\0') {
149 // The remainder of the string is either a single multiplier
150 // character, or nothing to indicate that the value is in
151 // bytes.
152 char c = *s2++;
153 if (*s2 == '\0') {
154 size_t mul;
155 if (c == '\0') {
156 mul = 1;
157 } else if (c == 'k' || c == 'K') {
158 mul = KB;
159 } else if (c == 'm' || c == 'M') {
160 mul = MB;
161 } else if (c == 'g' || c == 'G') {
162 mul = GB;
163 } else {
164 // Unknown multiplier character.
165 return 0;
166 }
167
168 if (val <= std::numeric_limits<size_t>::max() / mul) {
169 val *= mul;
170 } else {
171 // Clamp to a multiple of 1024.
172 val = std::numeric_limits<size_t>::max() & ~(1024-1);
173 }
174 } else {
175 // There's more than one character after the numeric part.
176 return 0;
177 }
178 }
179 // The man page says that a -Xm value must be a multiple of 1024.
180 if (val % div == 0) {
181 return val;
182 }
183 }
184 }
185 return 0;
186}
187
188static gc::CollectorType ParseCollectorType(const std::string& option) {
189 if (option == "MS" || option == "nonconcurrent") {
190 return gc::kCollectorTypeMS;
191 } else if (option == "CMS" || option == "concurrent") {
192 return gc::kCollectorTypeCMS;
193 } else if (option == "SS") {
194 return gc::kCollectorTypeSS;
195 } else if (option == "GSS") {
196 return gc::kCollectorTypeGSS;
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700197 } else if (option == "CC") {
198 return gc::kCollectorTypeCC;
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700199 } else if (option == "MC") {
200 return gc::kCollectorTypeMC;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800201 } else {
202 return gc::kCollectorTypeNone;
203 }
204}
205
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700206bool ParsedOptions::ParseXGcOption(const std::string& option) {
207 std::vector<std::string> gc_options;
208 Split(option.substr(strlen("-Xgc:")), ',', gc_options);
209 for (const std::string& gc_option : gc_options) {
210 gc::CollectorType collector_type = ParseCollectorType(gc_option);
211 if (collector_type != gc::kCollectorTypeNone) {
212 collector_type_ = collector_type;
213 } else if (gc_option == "preverify") {
214 verify_pre_gc_heap_ = true;
215 } else if (gc_option == "nopreverify") {
216 verify_pre_gc_heap_ = false;
217 } else if (gc_option == "presweepingverify") {
218 verify_pre_sweeping_heap_ = true;
219 } else if (gc_option == "nopresweepingverify") {
220 verify_pre_sweeping_heap_ = false;
221 } else if (gc_option == "postverify") {
222 verify_post_gc_heap_ = true;
223 } else if (gc_option == "nopostverify") {
224 verify_post_gc_heap_ = false;
225 } else if (gc_option == "preverify_rosalloc") {
226 verify_pre_gc_rosalloc_ = true;
227 } else if (gc_option == "nopreverify_rosalloc") {
228 verify_pre_gc_rosalloc_ = false;
229 } else if (gc_option == "presweepingverify_rosalloc") {
230 verify_pre_sweeping_rosalloc_ = true;
231 } else if (gc_option == "nopresweepingverify_rosalloc") {
232 verify_pre_sweeping_rosalloc_ = false;
233 } else if (gc_option == "postverify_rosalloc") {
234 verify_post_gc_rosalloc_ = true;
235 } else if (gc_option == "nopostverify_rosalloc") {
236 verify_post_gc_rosalloc_ = false;
237 } else if ((gc_option == "precise") ||
238 (gc_option == "noprecise") ||
239 (gc_option == "verifycardtable") ||
240 (gc_option == "noverifycardtable")) {
241 // Ignored for backwards compatibility.
242 } else {
243 Usage("Unknown -Xgc option %s\n", gc_option.c_str());
244 return false;
245 }
246 }
247 return true;
248}
249
Ian Rogerse63db272014-07-15 15:36:11 -0700250bool ParsedOptions::Parse(const RuntimeOptions& options, bool ignore_unrecognized) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800251 const char* boot_class_path_string = getenv("BOOTCLASSPATH");
252 if (boot_class_path_string != NULL) {
253 boot_class_path_string_ = boot_class_path_string;
254 }
255 const char* class_path_string = getenv("CLASSPATH");
256 if (class_path_string != NULL) {
257 class_path_string_ = class_path_string;
258 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800259
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800260 // Default to number of processors minus one since the main GC thread also does work.
261 parallel_gc_threads_ = sysconf(_SC_NPROCESSORS_CONF) - 1;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800262
263// gLogVerbosity.class_linker = true; // TODO: don't check this in!
264// gLogVerbosity.compiler = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800265// gLogVerbosity.gc = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700266// gLogVerbosity.heap = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800267// gLogVerbosity.jdwp = true; // TODO: don't check this in!
268// gLogVerbosity.jni = true; // TODO: don't check this in!
269// gLogVerbosity.monitor = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700270// gLogVerbosity.profiler = true; // TODO: don't check this in!
271// gLogVerbosity.signals = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800272// gLogVerbosity.startup = true; // TODO: don't check this in!
273// gLogVerbosity.third_party_jni = true; // TODO: don't check this in!
274// gLogVerbosity.threads = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700275// gLogVerbosity.verifier = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800276
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800277 for (size_t i = 0; i < options.size(); ++i) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800278 if (true && options[0].first == "-Xzygote") {
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800279 LOG(INFO) << "option[" << i << "]=" << options[i].first;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800280 }
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800281 }
282 for (size_t i = 0; i < options.size(); ++i) {
283 const std::string option(options[i].first);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800284 if (StartsWith(option, "-help")) {
285 Usage(nullptr);
286 return false;
287 } else if (StartsWith(option, "-showversion")) {
288 UsageMessage(stdout, "ART version %s\n", Runtime::GetVersion());
289 Exit(0);
290 } else if (StartsWith(option, "-Xbootclasspath:")) {
291 boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data();
Dave Allison69dfe512014-07-11 17:11:58 +0000292 LOG(INFO) << "setting boot class path to " << boot_class_path_string_;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800293 } else if (option == "-classpath" || option == "-cp") {
294 // TODO: support -Djava.class.path
295 i++;
296 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700297 Usage("Missing required class path value for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800298 return false;
299 }
300 const StringPiece& value = options[i].first;
301 class_path_string_ = value.data();
302 } else if (option == "bootclasspath") {
303 boot_class_path_
304 = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second);
305 } else if (StartsWith(option, "-Ximage:")) {
306 if (!ParseStringAfterChar(option, ':', &image_)) {
307 return false;
308 }
309 } else if (StartsWith(option, "-Xcheck:jni")) {
310 check_jni_ = true;
Ian Rogers68d8b422014-07-17 11:09:10 -0700311 } else if (StartsWith(option, "-Xjniopts:forcecopy")) {
312 force_copy_ = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800313 } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) {
314 std::string tail(option.substr(option[1] == 'X' ? 10 : 15));
315 // TODO: move parsing logic out of Dbg
316 if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) {
317 if (tail != "help") {
318 UsageMessage(stderr, "Failed to parse JDWP option %s\n", tail.c_str());
319 }
320 Usage("Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
321 "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n\n");
322 return false;
323 }
324 } else if (StartsWith(option, "-Xms")) {
325 size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024);
326 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700327 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800328 return false;
329 }
330 heap_initial_size_ = size;
331 } else if (StartsWith(option, "-Xmx")) {
332 size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024);
333 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700334 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800335 return false;
336 }
337 heap_maximum_size_ = size;
338 } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) {
339 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024);
340 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700341 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800342 return false;
343 }
344 heap_growth_limit_ = size;
345 } else if (StartsWith(option, "-XX:HeapMinFree=")) {
346 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024);
347 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700348 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800349 return false;
350 }
351 heap_min_free_ = size;
352 } else if (StartsWith(option, "-XX:HeapMaxFree=")) {
353 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024);
354 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700355 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800356 return false;
357 }
358 heap_max_free_ = size;
Mathieu Chartier6a7824d2014-08-22 14:53:04 -0700359 } else if (StartsWith(option, "-XX:NonMovingSpaceCapacity=")) {
360 size_t size = ParseMemoryOption(
361 option.substr(strlen("-XX:NonMovingSpaceCapacity=")).c_str(), 1024);
362 if (size == 0) {
363 Usage("Failed to parse memory option %s\n", option.c_str());
364 return false;
365 }
366 heap_non_moving_space_capacity_ = size;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800367 } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) {
368 if (!ParseDouble(option, '=', 0.1, 0.9, &heap_target_utilization_)) {
369 return false;
370 }
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700371 } else if (StartsWith(option, "-XX:ForegroundHeapGrowthMultiplier=")) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700372 if (!ParseDouble(option, '=', 0.1, 10.0, &foreground_heap_growth_multiplier_)) {
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700373 return false;
374 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800375 } else if (StartsWith(option, "-XX:ParallelGCThreads=")) {
376 if (!ParseUnsignedInteger(option, '=', &parallel_gc_threads_)) {
377 return false;
378 }
379 } else if (StartsWith(option, "-XX:ConcGCThreads=")) {
380 if (!ParseUnsignedInteger(option, '=', &conc_gc_threads_)) {
381 return false;
382 }
383 } else if (StartsWith(option, "-Xss")) {
384 size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1);
385 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700386 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800387 return false;
388 }
389 stack_size_ = size;
390 } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) {
391 if (!ParseUnsignedInteger(option, '=', &max_spins_before_thin_lock_inflation_)) {
392 return false;
393 }
394 } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) {
Andreas Gampe39d92182014-03-05 16:46:44 -0800395 unsigned int value;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800396 if (!ParseUnsignedInteger(option, '=', &value)) {
397 return false;
398 }
399 long_pause_log_threshold_ = MsToNs(value);
400 } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) {
Andreas Gampe39d92182014-03-05 16:46:44 -0800401 unsigned int value;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800402 if (!ParseUnsignedInteger(option, '=', &value)) {
403 return false;
404 }
405 long_gc_log_threshold_ = MsToNs(value);
406 } else if (option == "-XX:DumpGCPerformanceOnShutdown") {
407 dump_gc_performance_on_shutdown_ = true;
408 } else if (option == "-XX:IgnoreMaxFootprint") {
409 ignore_max_footprint_ = true;
410 } else if (option == "-XX:LowMemoryMode") {
411 low_memory_mode_ = true;
Alex Lighta59dd802014-07-02 16:28:08 -0700412 // TODO Might want to turn off must_relocate here.
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800413 } else if (option == "-XX:UseTLAB") {
414 use_tlab_ = true;
Zuo Wangf37a88b2014-07-10 04:26:41 -0700415 } else if (option == "-XX:EnableHSpaceCompactForOOM") {
416 use_homogeneous_space_compaction_for_oom_ = true;
417 } else if (option == "-XX:DisableHSpaceCompactForOOM") {
418 use_homogeneous_space_compaction_for_oom_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800419 } else if (StartsWith(option, "-D")) {
420 properties_.push_back(option.substr(strlen("-D")));
421 } else if (StartsWith(option, "-Xjnitrace:")) {
422 jni_trace_ = option.substr(strlen("-Xjnitrace:"));
423 } else if (option == "compilercallbacks") {
424 compiler_callbacks_ =
425 reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second));
Narayan Kamath11d9f062014-04-23 20:24:57 +0100426 } else if (option == "imageinstructionset") {
Andreas Gampe20c89302014-08-19 17:28:06 -0700427 const char* isa_str = reinterpret_cast<const char*>(options[i].second);
428 image_isa_ = GetInstructionSetFromString(isa_str);
429 if (image_isa_ == kNone) {
430 Usage("%s is not a valid instruction set.", isa_str);
431 return false;
432 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800433 } else if (option == "-Xzygote") {
434 is_zygote_ = true;
Alex Lighta59dd802014-07-02 16:28:08 -0700435 } else if (StartsWith(option, "-Xpatchoat:")) {
436 if (!ParseStringAfterChar(option, ':', &patchoat_executable_)) {
437 return false;
438 }
439 } else if (option == "-Xrelocate") {
440 must_relocate_ = true;
441 } else if (option == "-Xnorelocate") {
442 must_relocate_ = false;
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100443 } else if (option == "-Xnodex2oat") {
444 dex2oat_enabled_ = false;
445 } else if (option == "-Xdex2oat") {
446 dex2oat_enabled_ = true;
Alex Light64ad14d2014-08-19 14:23:13 -0700447 } else if (option == "-Xnoimage-dex2oat") {
448 image_dex2oat_enabled_ = false;
449 } else if (option == "-Ximage-dex2oat") {
450 image_dex2oat_enabled_ = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800451 } else if (option == "-Xint") {
452 interpreter_only_ = true;
453 } else if (StartsWith(option, "-Xgc:")) {
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700454 if (!ParseXGcOption(option)) {
455 return false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800456 }
Mathieu Chartier2dbe6272014-09-16 10:43:23 -0700457 } else if (StartsWith(option, "-XX:LargeObjectSpace=")) {
458 std::string substring;
459 if (!ParseStringAfterChar(option, '=', &substring)) {
460 return false;
461 }
462 if (substring == "disabled") {
463 large_object_space_type_ = gc::space::kLargeObjectSpaceTypeDisabled;
464 } else if (substring == "freelist") {
465 large_object_space_type_ = gc::space::kLargeObjectSpaceTypeFreeList;
466 } else if (substring == "map") {
467 large_object_space_type_ = gc::space::kLargeObjectSpaceTypeMap;
468 } else {
469 Usage("Unknown -XX:LargeObjectSpace= option %s\n", substring.c_str());
470 return false;
471 }
472 } else if (StartsWith(option, "-XX:LargeObjectThreshold=")) {
473 std::string substring;
474 if (!ParseStringAfterChar(option, '=', &substring)) {
475 return false;
476 }
477 size_t size = ParseMemoryOption(substring.c_str(), 1);
478 if (size == 0) {
479 Usage("Failed to parse memory option %s\n", option.c_str());
480 return false;
481 }
482 large_object_threshold_ = size;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800483 } else if (StartsWith(option, "-XX:BackgroundGC=")) {
484 std::string substring;
485 if (!ParseStringAfterChar(option, '=', &substring)) {
486 return false;
487 }
Zuo Wangf37a88b2014-07-10 04:26:41 -0700488 // Special handling for HSpaceCompact since this is only valid as a background GC type.
489 if (substring == "HSpaceCompact") {
490 background_collector_type_ = gc::kCollectorTypeHomogeneousSpaceCompact;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800491 } else {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700492 gc::CollectorType collector_type = ParseCollectorType(substring);
493 if (collector_type != gc::kCollectorTypeNone) {
494 background_collector_type_ = collector_type;
495 } else {
496 Usage("Unknown -XX:BackgroundGC option %s\n", substring.c_str());
497 return false;
498 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800499 }
500 } else if (option == "-XX:+DisableExplicitGC") {
501 is_explicit_gc_disabled_ = true;
502 } else if (StartsWith(option, "-verbose:")) {
503 std::vector<std::string> verbose_options;
504 Split(option.substr(strlen("-verbose:")), ',', verbose_options);
505 for (size_t i = 0; i < verbose_options.size(); ++i) {
506 if (verbose_options[i] == "class") {
507 gLogVerbosity.class_linker = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800508 } else if (verbose_options[i] == "compiler") {
509 gLogVerbosity.compiler = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800510 } else if (verbose_options[i] == "gc") {
511 gLogVerbosity.gc = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700512 } else if (verbose_options[i] == "heap") {
513 gLogVerbosity.heap = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800514 } else if (verbose_options[i] == "jdwp") {
515 gLogVerbosity.jdwp = true;
516 } else if (verbose_options[i] == "jni") {
517 gLogVerbosity.jni = true;
518 } else if (verbose_options[i] == "monitor") {
519 gLogVerbosity.monitor = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700520 } else if (verbose_options[i] == "profiler") {
521 gLogVerbosity.profiler = true;
522 } else if (verbose_options[i] == "signals") {
523 gLogVerbosity.signals = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800524 } else if (verbose_options[i] == "startup") {
525 gLogVerbosity.startup = true;
526 } else if (verbose_options[i] == "third-party-jni") {
527 gLogVerbosity.third_party_jni = true;
528 } else if (verbose_options[i] == "threads") {
529 gLogVerbosity.threads = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700530 } else if (verbose_options[i] == "verifier") {
531 gLogVerbosity.verifier = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800532 } else {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700533 Usage("Unknown -verbose option %s\n", verbose_options[i].c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800534 return false;
535 }
536 }
Mingyao Yang42d65c52014-04-18 16:49:39 -0700537 } else if (StartsWith(option, "-verbose-methods:")) {
538 gLogVerbosity.compiler = false;
539 Split(option.substr(strlen("-verbose-methods:")), ',', gVerboseMethods);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800540 } else if (StartsWith(option, "-Xlockprofthreshold:")) {
541 if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) {
542 return false;
543 }
544 } else if (StartsWith(option, "-Xstacktracefile:")) {
545 if (!ParseStringAfterChar(option, ':', &stack_trace_file_)) {
546 return false;
547 }
548 } else if (option == "sensitiveThread") {
549 const void* hook = options[i].second;
550 hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(hook));
551 } else if (option == "vfprintf") {
552 const void* hook = options[i].second;
553 if (hook == nullptr) {
554 Usage("vfprintf argument was NULL");
555 return false;
556 }
557 hook_vfprintf_ =
558 reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook));
559 } else if (option == "exit") {
560 const void* hook = options[i].second;
561 if (hook == nullptr) {
562 Usage("exit argument was NULL");
563 return false;
564 }
565 hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook));
566 } else if (option == "abort") {
567 const void* hook = options[i].second;
568 if (hook == nullptr) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700569 Usage("abort was NULL\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800570 return false;
571 }
572 hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook));
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800573 } else if (option == "-Xmethod-trace") {
574 method_trace_ = true;
575 } else if (StartsWith(option, "-Xmethod-trace-file:")) {
576 method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:"));
577 } else if (StartsWith(option, "-Xmethod-trace-file-size:")) {
578 if (!ParseUnsignedInteger(option, ':', &method_trace_file_size_)) {
579 return false;
580 }
581 } else if (option == "-Xprofile:threadcpuclock") {
Ian Rogerse63db272014-07-15 15:36:11 -0700582 Trace::SetDefaultClockSource(kTraceClockSourceThreadCpu);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800583 } else if (option == "-Xprofile:wallclock") {
Ian Rogerse63db272014-07-15 15:36:11 -0700584 Trace::SetDefaultClockSource(kTraceClockSourceWall);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800585 } else if (option == "-Xprofile:dualclock") {
Ian Rogerse63db272014-07-15 15:36:11 -0700586 Trace::SetDefaultClockSource(kTraceClockSourceDual);
Calin Juravlec1b643c2014-05-30 23:44:11 +0100587 } else if (option == "-Xenable-profiler") {
588 profiler_options_.enabled_ = true;
Wei Jin2221e3b2014-05-21 18:35:19 -0700589 } else if (StartsWith(option, "-Xprofile-filename:")) {
Ian Rogersf7fd3cb2014-05-19 22:57:34 -0700590 if (!ParseStringAfterChar(option, ':', &profile_output_filename_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800591 return false;
592 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800593 } else if (StartsWith(option, "-Xprofile-period:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100594 if (!ParseUnsignedInteger(option, ':', &profiler_options_.period_s_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800595 return false;
596 }
597 } else if (StartsWith(option, "-Xprofile-duration:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100598 if (!ParseUnsignedInteger(option, ':', &profiler_options_.duration_s_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800599 return false;
600 }
601 } else if (StartsWith(option, "-Xprofile-interval:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100602 if (!ParseUnsignedInteger(option, ':', &profiler_options_.interval_us_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800603 return false;
604 }
605 } else if (StartsWith(option, "-Xprofile-backoff:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100606 if (!ParseDouble(option, ':', 1.0, 10.0, &profiler_options_.backoff_coefficient_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800607 return false;
608 }
Calin Juravlec1b643c2014-05-30 23:44:11 +0100609 } else if (option == "-Xprofile-start-immediately") {
610 profiler_options_.start_immediately_ = true;
611 } else if (StartsWith(option, "-Xprofile-top-k-threshold:")) {
Calin Juravlec321c9b2014-06-11 19:04:35 +0100612 if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_threshold_)) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100613 return false;
614 }
615 } else if (StartsWith(option, "-Xprofile-top-k-change-threshold:")) {
Calin Juravlec321c9b2014-06-11 19:04:35 +0100616 if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_change_threshold_)) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100617 return false;
618 }
Wei Jina93b0bb2014-06-09 16:19:15 -0700619 } else if (option == "-Xprofile-type:method") {
620 profiler_options_.profile_type_ = kProfilerMethod;
Wei Jin445220d2014-06-20 15:56:53 -0700621 } else if (option == "-Xprofile-type:stack") {
622 profiler_options_.profile_type_ = kProfilerBoundedStack;
623 } else if (StartsWith(option, "-Xprofile-max-stack-depth:")) {
624 if (!ParseUnsignedInteger(option, ':', &profiler_options_.max_stack_depth_)) {
625 return false;
626 }
Tsu Chiang Chuang12e6d742014-05-22 10:22:25 -0700627 } else if (StartsWith(option, "-Xcompiler:")) {
628 if (!ParseStringAfterChar(option, ':', &compiler_executable_)) {
629 return false;
630 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800631 } else if (option == "-Xcompiler-option") {
632 i++;
633 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700634 Usage("Missing required compiler option for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800635 return false;
636 }
637 compiler_options_.push_back(options[i].first);
638 } else if (option == "-Ximage-compiler-option") {
639 i++;
640 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700641 Usage("Missing required compiler option for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800642 return false;
643 }
644 image_compiler_options_.push_back(options[i].first);
Jeff Hao4a200f52014-04-01 14:58:49 -0700645 } else if (StartsWith(option, "-Xverify:")) {
646 std::string verify_mode = option.substr(strlen("-Xverify:"));
647 if (verify_mode == "none") {
648 verify_ = false;
649 } else if (verify_mode == "remote" || verify_mode == "all") {
650 verify_ = true;
651 } else {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700652 Usage("Unknown -Xverify option %s\n", verify_mode.c_str());
Jeff Hao4a200f52014-04-01 14:58:49 -0700653 return false;
654 }
Andreas Gampec4a7acf2014-08-08 12:05:10 -0700655 } else if (StartsWith(option, "-XX:NativeBridge=")) {
Calin Juravlea68629e2014-08-22 12:53:59 +0100656 if (!ParseStringAfterChar(option, '=', &native_bridge_library_filename_)) {
Andreas Gampe855564b2014-07-25 02:32:19 -0700657 return false;
658 }
Yevgeny Roubana6119a22014-03-24 11:31:24 +0700659 } else if (StartsWith(option, "-ea") ||
660 StartsWith(option, "-da") ||
661 StartsWith(option, "-enableassertions") ||
662 StartsWith(option, "-disableassertions") ||
Dave Allisonb373e092014-02-20 16:06:36 -0800663 (option == "--runtime-arg") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800664 (option == "-esa") ||
665 (option == "-dsa") ||
666 (option == "-enablesystemassertions") ||
667 (option == "-disablesystemassertions") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800668 (option == "-Xrs") ||
669 StartsWith(option, "-Xint:") ||
670 StartsWith(option, "-Xdexopt:") ||
671 (option == "-Xnoquithandler") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800672 StartsWith(option, "-Xjnigreflimit:") ||
673 (option == "-Xgenregmap") ||
674 (option == "-Xnogenregmap") ||
675 StartsWith(option, "-Xverifyopt:") ||
676 (option == "-Xcheckdexsum") ||
677 (option == "-Xincludeselectedop") ||
678 StartsWith(option, "-Xjitop:") ||
679 (option == "-Xincludeselectedmethod") ||
680 StartsWith(option, "-Xjitthreshold:") ||
681 StartsWith(option, "-Xjitcodecachesize:") ||
682 (option == "-Xjitblocking") ||
683 StartsWith(option, "-Xjitmethod:") ||
684 StartsWith(option, "-Xjitclass:") ||
685 StartsWith(option, "-Xjitoffset:") ||
686 StartsWith(option, "-Xjitconfig:") ||
687 (option == "-Xjitcheckcg") ||
688 (option == "-Xjitverbose") ||
689 (option == "-Xjitprofile") ||
690 (option == "-Xjitdisableopt") ||
691 (option == "-Xjitsuspendpoll") ||
692 StartsWith(option, "-XX:mainThreadStackSize=")) {
693 // Ignored for backwards compatibility.
694 } else if (!ignore_unrecognized) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700695 Usage("Unrecognized option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800696 return false;
697 }
698 }
699
700 // If a reference to the dalvik core.jar snuck in, replace it with
701 // the art specific version. This can happen with on device
702 // boot.art/boot.oat generation by GenerateImage which relies on the
703 // value of BOOTCLASSPATH.
Kenny Rootd5185342014-05-13 14:47:05 -0700704#if defined(ART_TARGET)
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800705 std::string core_jar("/core.jar");
Kenny Rootd5185342014-05-13 14:47:05 -0700706 std::string core_libart_jar("/core-libart.jar");
707#else
708 // The host uses hostdex files.
709 std::string core_jar("/core-hostdex.jar");
710 std::string core_libart_jar("/core-libart-hostdex.jar");
711#endif
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800712 size_t core_jar_pos = boot_class_path_string_.find(core_jar);
713 if (core_jar_pos != std::string::npos) {
Kenny Rootd5185342014-05-13 14:47:05 -0700714 boot_class_path_string_.replace(core_jar_pos, core_jar.size(), core_libart_jar);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800715 }
716
717 if (compiler_callbacks_ == nullptr && image_.empty()) {
718 image_ += GetAndroidRoot();
Brian Carlstrom3ac05bb2014-05-13 19:31:38 -0700719 image_ += "/framework/boot.art";
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800720 }
721 if (heap_growth_limit_ == 0) {
722 heap_growth_limit_ = heap_maximum_size_;
723 }
724 if (background_collector_type_ == gc::kCollectorTypeNone) {
725 background_collector_type_ = collector_type_;
726 }
727 return true;
Narayan Kamath11d9f062014-04-23 20:24:57 +0100728} // NOLINT(readability/fn_size)
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800729
730void ParsedOptions::Exit(int status) {
731 hook_exit_(status);
732}
733
734void ParsedOptions::Abort() {
735 hook_abort_();
736}
737
738void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) {
739 hook_vfprintf_(stderr, fmt, ap);
740}
741
742void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) {
743 va_list ap;
744 va_start(ap, fmt);
745 UsageMessageV(stream, fmt, ap);
746 va_end(ap);
747}
748
749void ParsedOptions::Usage(const char* fmt, ...) {
750 bool error = (fmt != nullptr);
751 FILE* stream = error ? stderr : stdout;
752
753 if (fmt != nullptr) {
754 va_list ap;
755 va_start(ap, fmt);
756 UsageMessageV(stream, fmt, ap);
757 va_end(ap);
758 }
759
760 const char* program = "dalvikvm";
761 UsageMessage(stream, "%s: [options] class [argument ...]\n", program);
762 UsageMessage(stream, "\n");
763 UsageMessage(stream, "The following standard options are supported:\n");
764 UsageMessage(stream, " -classpath classpath (-cp classpath)\n");
765 UsageMessage(stream, " -Dproperty=value\n");
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100766 UsageMessage(stream, " -verbose:tag ('gc', 'jni', or 'class')\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800767 UsageMessage(stream, " -showversion\n");
768 UsageMessage(stream, " -help\n");
769 UsageMessage(stream, " -agentlib:jdwp=options\n");
770 UsageMessage(stream, "\n");
771
772 UsageMessage(stream, "The following extended options are supported:\n");
773 UsageMessage(stream, " -Xrunjdwp:<options>\n");
774 UsageMessage(stream, " -Xbootclasspath:bootclasspath\n");
775 UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n");
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100776 UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n");
777 UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n");
778 UsageMessage(stream, " -XssN (stack size)\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800779 UsageMessage(stream, " -Xint\n");
780 UsageMessage(stream, "\n");
781
782 UsageMessage(stream, "The following Dalvik options are supported:\n");
783 UsageMessage(stream, " -Xzygote\n");
784 UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n");
785 UsageMessage(stream, " -Xstacktracefile:<filename>\n");
786 UsageMessage(stream, " -Xgc:[no]preverify\n");
787 UsageMessage(stream, " -Xgc:[no]postverify\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800788 UsageMessage(stream, " -XX:HeapGrowthLimit=N\n");
789 UsageMessage(stream, " -XX:HeapMinFree=N\n");
790 UsageMessage(stream, " -XX:HeapMaxFree=N\n");
Mathieu Chartier6a7824d2014-08-22 14:53:04 -0700791 UsageMessage(stream, " -XX:NonMovingSpaceCapacity=N\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800792 UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n");
Mathieu Chartier455820e2014-04-18 12:02:39 -0700793 UsageMessage(stream, " -XX:ForegroundHeapGrowthMultiplier=doublevalue\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800794 UsageMessage(stream, " -XX:LowMemoryMode\n");
795 UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n");
796 UsageMessage(stream, "\n");
797
798 UsageMessage(stream, "The following unique to ART options are supported:\n");
799 UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n");
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700800 UsageMessage(stream, " -Xgc:[no]postsweepingverify_rosalloc\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800801 UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n");
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700802 UsageMessage(stream, " -Xgc:[no]presweepingverify\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800803 UsageMessage(stream, " -Ximage:filename\n");
Mathieu Chartier2dbe6272014-09-16 10:43:23 -0700804 UsageMessage(stream, " -XX:+DisableExplicitGC\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800805 UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n");
806 UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n");
807 UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n");
808 UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n");
809 UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n");
810 UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n");
811 UsageMessage(stream, " -XX:IgnoreMaxFootprint\n");
812 UsageMessage(stream, " -XX:UseTLAB\n");
813 UsageMessage(stream, " -XX:BackgroundGC=none\n");
Mathieu Chartier2dbe6272014-09-16 10:43:23 -0700814 UsageMessage(stream, " -XX:LargeObjectSpace={disabled,map,freelist}\n");
815 UsageMessage(stream, " -XX:LargeObjectThreshold=N\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800816 UsageMessage(stream, " -Xmethod-trace\n");
817 UsageMessage(stream, " -Xmethod-trace-file:filename");
818 UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n");
Calin Juravlec1b643c2014-05-30 23:44:11 +0100819 UsageMessage(stream, " -Xenable-profiler\n");
Wei Jin2221e3b2014-05-21 18:35:19 -0700820 UsageMessage(stream, " -Xprofile-filename:filename\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800821 UsageMessage(stream, " -Xprofile-period:integervalue\n");
822 UsageMessage(stream, " -Xprofile-duration:integervalue\n");
823 UsageMessage(stream, " -Xprofile-interval:integervalue\n");
Calin Juravle54c73ca2014-05-22 12:13:54 +0100824 UsageMessage(stream, " -Xprofile-backoff:doublevalue\n");
Calin Juravlec1b643c2014-05-30 23:44:11 +0100825 UsageMessage(stream, " -Xprofile-start-immediately\n");
826 UsageMessage(stream, " -Xprofile-top-k-threshold:doublevalue\n");
827 UsageMessage(stream, " -Xprofile-top-k-change-threshold:doublevalue\n");
Wei Jin445220d2014-06-20 15:56:53 -0700828 UsageMessage(stream, " -Xprofile-type:{method,stack}\n");
829 UsageMessage(stream, " -Xprofile-max-stack-depth:integervalue\n");
Tsu Chiang Chuang12e6d742014-05-22 10:22:25 -0700830 UsageMessage(stream, " -Xcompiler:filename\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800831 UsageMessage(stream, " -Xcompiler-option dex2oat-option\n");
832 UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n");
Alex Lighta59dd802014-07-02 16:28:08 -0700833 UsageMessage(stream, " -Xpatchoat:filename\n");
834 UsageMessage(stream, " -X[no]relocate\n");
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100835 UsageMessage(stream, " -X[no]dex2oat (Whether to invoke dex2oat on the application)\n");
Alex Light64ad14d2014-08-19 14:23:13 -0700836 UsageMessage(stream, " -X[no]image-dex2oat (Whether to create and use a boot image)\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800837 UsageMessage(stream, "\n");
838
839 UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n");
840 UsageMessage(stream, " -ea[:<package name>... |:<class name>]\n");
841 UsageMessage(stream, " -da[:<package name>... |:<class name>]\n");
842 UsageMessage(stream, " (-enableassertions, -disableassertions)\n");
843 UsageMessage(stream, " -esa\n");
844 UsageMessage(stream, " -dsa\n");
845 UsageMessage(stream, " (-enablesystemassertions, -disablesystemassertions)\n");
846 UsageMessage(stream, " -Xverify:{none,remote,all}\n");
847 UsageMessage(stream, " -Xrs\n");
848 UsageMessage(stream, " -Xint:portable, -Xint:fast, -Xint:jit\n");
849 UsageMessage(stream, " -Xdexopt:{none,verified,all,full}\n");
850 UsageMessage(stream, " -Xnoquithandler\n");
851 UsageMessage(stream, " -Xjniopts:{warnonly,forcecopy}\n");
852 UsageMessage(stream, " -Xjnigreflimit:integervalue\n");
853 UsageMessage(stream, " -Xgc:[no]precise\n");
854 UsageMessage(stream, " -Xgc:[no]verifycardtable\n");
855 UsageMessage(stream, " -X[no]genregmap\n");
856 UsageMessage(stream, " -Xverifyopt:[no]checkmon\n");
857 UsageMessage(stream, " -Xcheckdexsum\n");
858 UsageMessage(stream, " -Xincludeselectedop\n");
859 UsageMessage(stream, " -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*\n");
860 UsageMessage(stream, " -Xincludeselectedmethod\n");
861 UsageMessage(stream, " -Xjitthreshold:integervalue\n");
862 UsageMessage(stream, " -Xjitcodecachesize:decimalvalueofkbytes\n");
863 UsageMessage(stream, " -Xjitblocking\n");
864 UsageMessage(stream, " -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\\;replace)\n");
865 UsageMessage(stream, " -Xjitclass:classname[,classname]*\n");
866 UsageMessage(stream, " -Xjitoffset:offset[,offset]\n");
867 UsageMessage(stream, " -Xjitconfig:filename\n");
868 UsageMessage(stream, " -Xjitcheckcg\n");
869 UsageMessage(stream, " -Xjitverbose\n");
870 UsageMessage(stream, " -Xjitprofile\n");
871 UsageMessage(stream, " -Xjitdisableopt\n");
872 UsageMessage(stream, " -Xjitsuspendpoll\n");
873 UsageMessage(stream, " -XX:mainThreadStackSize=N\n");
874 UsageMessage(stream, "\n");
875
876 Exit((error) ? 1 : 0);
877}
878
879bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) {
880 std::string::size_type colon = s.find(c);
881 if (colon == std::string::npos) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700882 Usage("Missing char %c in option %s\n", c, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800883 return false;
884 }
885 // Add one to remove the char we were trimming until.
886 *parsed_value = s.substr(colon + 1);
887 return true;
888}
889
890bool ParsedOptions::ParseInteger(const std::string& s, char after_char, int* parsed_value) {
891 std::string::size_type colon = s.find(after_char);
892 if (colon == std::string::npos) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700893 Usage("Missing char %c in option %s\n", after_char, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800894 return false;
895 }
896 const char* begin = &s[colon + 1];
897 char* end;
898 size_t result = strtoul(begin, &end, 10);
899 if (begin == end || *end != '\0') {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700900 Usage("Failed to parse integer from %s\n", s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800901 return false;
902 }
903 *parsed_value = result;
904 return true;
905}
906
907bool ParsedOptions::ParseUnsignedInteger(const std::string& s, char after_char,
908 unsigned int* parsed_value) {
909 int i;
910 if (!ParseInteger(s, after_char, &i)) {
911 return false;
912 }
913 if (i < 0) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700914 Usage("Negative value %d passed for unsigned option %s\n", i, s.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800915 return false;
916 }
917 *parsed_value = i;
918 return true;
919}
920
921bool ParsedOptions::ParseDouble(const std::string& option, char after_char,
922 double min, double max, double* parsed_value) {
923 std::string substring;
924 if (!ParseStringAfterChar(option, after_char, &substring)) {
925 return false;
926 }
Dave Allison999385c2014-05-20 15:16:02 -0700927 bool sane_val = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800928 double value;
Dave Allison999385c2014-05-20 15:16:02 -0700929 if (false) {
930 // TODO: this doesn't seem to work on the emulator. b/15114595
931 std::stringstream iss(substring);
932 iss >> value;
933 // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range.
934 sane_val = iss.eof() && (value >= min) && (value <= max);
935 } else {
936 char* end = nullptr;
937 value = strtod(substring.c_str(), &end);
938 sane_val = *end == '\0' && value >= min && value <= max;
939 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800940 if (!sane_val) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700941 Usage("Invalid double value %s for option %s\n", substring.c_str(), option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800942 return false;
943 }
944 *parsed_value = value;
945 return true;
946}
947
948} // namespace art