blob: a016cc50ac552ff6cdfa6282fcf8fc6d600d7ce3 [file] [log] [blame]
Brian Carlstrom491ca9e2014-03-02 18:24:38 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "parsed_options.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070018
Dave Allisonb373e092014-02-20 16:06:36 -080019#ifdef HAVE_ANDROID_OS
20#include "cutils/properties.h"
21#endif
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080022
Ian Rogers576ca0c2014-06-06 15:58:22 -070023#include "base/stringpiece.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080024#include "debugger.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070025#include "gc/heap.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080026#include "monitor.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070027#include "utils.h"
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080028
29namespace art {
30
31ParsedOptions* ParsedOptions::Create(const Runtime::Options& options, bool ignore_unrecognized) {
Ian Rogers700a4022014-05-19 16:49:03 -070032 std::unique_ptr<ParsedOptions> parsed(new ParsedOptions());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080033 if (parsed->Parse(options, ignore_unrecognized)) {
34 return parsed.release();
35 }
36 return nullptr;
37}
38
39// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
40// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
41// [gG] gigabytes.
42//
43// "s" should point just past the "-Xm?" part of the string.
44// "div" specifies a divisor, e.g. 1024 if the value must be a multiple
45// of 1024.
46//
47// The spec says the -Xmx and -Xms options must be multiples of 1024. It
48// doesn't say anything about -Xss.
49//
50// Returns 0 (a useless size) if "s" is malformed or specifies a low or
51// non-evenly-divisible value.
52//
53size_t ParseMemoryOption(const char* s, size_t div) {
54 // strtoul accepts a leading [+-], which we don't want,
55 // so make sure our string starts with a decimal digit.
56 if (isdigit(*s)) {
57 char* s2;
58 size_t val = strtoul(s, &s2, 10);
59 if (s2 != s) {
60 // s2 should be pointing just after the number.
61 // If this is the end of the string, the user
62 // has specified a number of bytes. Otherwise,
63 // there should be exactly one more character
64 // that specifies a multiplier.
65 if (*s2 != '\0') {
66 // The remainder of the string is either a single multiplier
67 // character, or nothing to indicate that the value is in
68 // bytes.
69 char c = *s2++;
70 if (*s2 == '\0') {
71 size_t mul;
72 if (c == '\0') {
73 mul = 1;
74 } else if (c == 'k' || c == 'K') {
75 mul = KB;
76 } else if (c == 'm' || c == 'M') {
77 mul = MB;
78 } else if (c == 'g' || c == 'G') {
79 mul = GB;
80 } else {
81 // Unknown multiplier character.
82 return 0;
83 }
84
85 if (val <= std::numeric_limits<size_t>::max() / mul) {
86 val *= mul;
87 } else {
88 // Clamp to a multiple of 1024.
89 val = std::numeric_limits<size_t>::max() & ~(1024-1);
90 }
91 } else {
92 // There's more than one character after the numeric part.
93 return 0;
94 }
95 }
96 // The man page says that a -Xm value must be a multiple of 1024.
97 if (val % div == 0) {
98 return val;
99 }
100 }
101 }
102 return 0;
103}
104
105static gc::CollectorType ParseCollectorType(const std::string& option) {
106 if (option == "MS" || option == "nonconcurrent") {
107 return gc::kCollectorTypeMS;
108 } else if (option == "CMS" || option == "concurrent") {
109 return gc::kCollectorTypeCMS;
110 } else if (option == "SS") {
111 return gc::kCollectorTypeSS;
112 } else if (option == "GSS") {
113 return gc::kCollectorTypeGSS;
Hiroshi Yamauchid5307ec2014-03-27 21:07:51 -0700114 } else if (option == "CC") {
115 return gc::kCollectorTypeCC;
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700116 } else if (option == "MC") {
117 return gc::kCollectorTypeMC;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800118 } else {
119 return gc::kCollectorTypeNone;
120 }
121}
122
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700123bool ParsedOptions::ParseXGcOption(const std::string& option) {
124 std::vector<std::string> gc_options;
125 Split(option.substr(strlen("-Xgc:")), ',', gc_options);
126 for (const std::string& gc_option : gc_options) {
127 gc::CollectorType collector_type = ParseCollectorType(gc_option);
128 if (collector_type != gc::kCollectorTypeNone) {
129 collector_type_ = collector_type;
130 } else if (gc_option == "preverify") {
131 verify_pre_gc_heap_ = true;
132 } else if (gc_option == "nopreverify") {
133 verify_pre_gc_heap_ = false;
134 } else if (gc_option == "presweepingverify") {
135 verify_pre_sweeping_heap_ = true;
136 } else if (gc_option == "nopresweepingverify") {
137 verify_pre_sweeping_heap_ = false;
138 } else if (gc_option == "postverify") {
139 verify_post_gc_heap_ = true;
140 } else if (gc_option == "nopostverify") {
141 verify_post_gc_heap_ = false;
142 } else if (gc_option == "preverify_rosalloc") {
143 verify_pre_gc_rosalloc_ = true;
144 } else if (gc_option == "nopreverify_rosalloc") {
145 verify_pre_gc_rosalloc_ = false;
146 } else if (gc_option == "presweepingverify_rosalloc") {
147 verify_pre_sweeping_rosalloc_ = true;
148 } else if (gc_option == "nopresweepingverify_rosalloc") {
149 verify_pre_sweeping_rosalloc_ = false;
150 } else if (gc_option == "postverify_rosalloc") {
151 verify_post_gc_rosalloc_ = true;
152 } else if (gc_option == "nopostverify_rosalloc") {
153 verify_post_gc_rosalloc_ = false;
154 } else if ((gc_option == "precise") ||
155 (gc_option == "noprecise") ||
156 (gc_option == "verifycardtable") ||
157 (gc_option == "noverifycardtable")) {
158 // Ignored for backwards compatibility.
159 } else {
160 Usage("Unknown -Xgc option %s\n", gc_option.c_str());
161 return false;
162 }
163 }
164 return true;
165}
166
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800167bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecognized) {
168 const char* boot_class_path_string = getenv("BOOTCLASSPATH");
169 if (boot_class_path_string != NULL) {
170 boot_class_path_string_ = boot_class_path_string;
171 }
172 const char* class_path_string = getenv("CLASSPATH");
173 if (class_path_string != NULL) {
174 class_path_string_ = class_path_string;
175 }
176 // -Xcheck:jni is off by default for regular builds but on by default in debug builds.
177 check_jni_ = kIsDebugBuild;
178
179 heap_initial_size_ = gc::Heap::kDefaultInitialSize;
180 heap_maximum_size_ = gc::Heap::kDefaultMaximumSize;
181 heap_min_free_ = gc::Heap::kDefaultMinFree;
182 heap_max_free_ = gc::Heap::kDefaultMaxFree;
183 heap_target_utilization_ = gc::Heap::kDefaultTargetUtilization;
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700184 foreground_heap_growth_multiplier_ = gc::Heap::kDefaultHeapGrowthMultiplier;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800185 heap_growth_limit_ = 0; // 0 means no growth limit .
186 // Default to number of processors minus one since the main GC thread also does work.
187 parallel_gc_threads_ = sysconf(_SC_NPROCESSORS_CONF) - 1;
188 // Only the main GC thread, no workers.
189 conc_gc_threads_ = 0;
Hiroshi Yamauchi1dda0602014-05-12 12:32:32 -0700190 // The default GC type is set in makefiles.
191#if ART_DEFAULT_GC_TYPE_IS_CMS
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800192 collector_type_ = gc::kCollectorTypeCMS;
Hiroshi Yamauchi1dda0602014-05-12 12:32:32 -0700193#elif ART_DEFAULT_GC_TYPE_IS_SS
194 collector_type_ = gc::kCollectorTypeSS;
195#elif ART_DEFAULT_GC_TYPE_IS_GSS
196 collector_type_ = gc::kCollectorTypeGSS;
197#else
198#error "ART default GC type must be set"
199#endif
Zuo Wangf37a88b2014-07-10 04:26:41 -0700200 // If we are using homogeneous space compaction then default background compaction to off since
201 // homogeneous space compactions when we transition to not jank perceptible.
202 use_homogeneous_space_compaction_for_oom_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800203 // If background_collector_type_ is kCollectorTypeNone, it defaults to the collector_type_ after
Zuo Wangf37a88b2014-07-10 04:26:41 -0700204 // parsing options. If you set this to kCollectorTypeHSpaceCompact then we will do an hspace
205 // compaction when we transition to background instead of a normal collector transition.
Mathieu Chartiera033f702014-06-17 12:01:06 -0700206 background_collector_type_ = gc::kCollectorTypeSS;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800207 stack_size_ = 0; // 0 means default.
208 max_spins_before_thin_lock_inflation_ = Monitor::kDefaultMaxSpinsBeforeThinLockInflation;
209 low_memory_mode_ = false;
210 use_tlab_ = false;
Zuo Wangf37a88b2014-07-10 04:26:41 -0700211 min_interval_homogeneous_space_compaction_by_oom_ = MsToNs(100 * 1000); // 100s.
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800212 verify_pre_gc_heap_ = false;
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700213 // Pre sweeping is the one that usually fails if the GC corrupted the heap.
214 verify_pre_sweeping_heap_ = kIsDebugBuild;
215 verify_post_gc_heap_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800216 verify_pre_gc_rosalloc_ = kIsDebugBuild;
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700217 verify_pre_sweeping_rosalloc_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800218 verify_post_gc_rosalloc_ = false;
219
220 compiler_callbacks_ = nullptr;
221 is_zygote_ = false;
Hiroshi Yamauchie63a7452014-02-27 14:44:36 -0800222 if (kPoisonHeapReferences) {
223 // kPoisonHeapReferences currently works only with the interpreter only.
224 // TODO: make it work with the compiler.
225 interpreter_only_ = true;
226 } else {
227 interpreter_only_ = false;
228 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800229 is_explicit_gc_disabled_ = false;
230
231 long_pause_log_threshold_ = gc::Heap::kDefaultLongPauseLogThreshold;
232 long_gc_log_threshold_ = gc::Heap::kDefaultLongGCLogThreshold;
233 dump_gc_performance_on_shutdown_ = false;
234 ignore_max_footprint_ = false;
235
236 lock_profiling_threshold_ = 0;
237 hook_is_sensitive_thread_ = NULL;
238
239 hook_vfprintf_ = vfprintf;
240 hook_exit_ = exit;
241 hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort.
242
243// gLogVerbosity.class_linker = true; // TODO: don't check this in!
244// gLogVerbosity.compiler = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800245// gLogVerbosity.gc = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700246// gLogVerbosity.heap = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800247// gLogVerbosity.jdwp = true; // TODO: don't check this in!
248// gLogVerbosity.jni = true; // TODO: don't check this in!
249// gLogVerbosity.monitor = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700250// gLogVerbosity.profiler = true; // TODO: don't check this in!
251// gLogVerbosity.signals = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800252// gLogVerbosity.startup = true; // TODO: don't check this in!
253// gLogVerbosity.third_party_jni = true; // TODO: don't check this in!
254// gLogVerbosity.threads = true; // TODO: don't check this in!
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700255// gLogVerbosity.verifier = true; // TODO: don't check this in!
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800256
257 method_trace_ = false;
258 method_trace_file_ = "/data/method-trace-file.bin";
259 method_trace_file_size_ = 10 * MB;
260
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800261 profile_clock_source_ = kDefaultProfilerClockSource;
262
Jeff Hao4a200f52014-04-01 14:58:49 -0700263 verify_ = true;
Narayan Kamath11d9f062014-04-23 20:24:57 +0100264 image_isa_ = kRuntimeISA;
Jeff Hao4a200f52014-04-01 14:58:49 -0700265
Nicolas Geoffray0025a862014-07-11 08:26:40 +0000266 // Default to explicit checks. Switch off with -implicit-checks:.
267 // or setprop dalvik.vm.implicit_checks check1,check2,...
268#ifdef HAVE_ANDROID_OS
269 {
270 char buf[PROP_VALUE_MAX];
271 property_get("dalvik.vm.implicit_checks", buf, "null,stack");
272 std::string checks(buf);
273 std::vector<std::string> checkvec;
274 Split(checks, ',', checkvec);
275 explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck |
276 kExplicitStackOverflowCheck;
277 for (auto& str : checkvec) {
278 std::string val = Trim(str);
279 if (val == "none") {
280 explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck |
281 kExplicitStackOverflowCheck;
282 } else if (val == "null") {
283 explicit_checks_ &= ~kExplicitNullCheck;
284 } else if (val == "suspend") {
285 explicit_checks_ &= ~kExplicitSuspendCheck;
286 } else if (val == "stack") {
287 explicit_checks_ &= ~kExplicitStackOverflowCheck;
288 } else if (val == "all") {
289 explicit_checks_ = 0;
290 }
291 }
292 }
293#else
294 explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck |
295 kExplicitStackOverflowCheck;
296#endif
297
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800298 for (size_t i = 0; i < options.size(); ++i) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800299 if (true && options[0].first == "-Xzygote") {
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800300 LOG(INFO) << "option[" << i << "]=" << options[i].first;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800301 }
Brian Carlstrom2ec65202014-03-03 15:16:37 -0800302 }
303 for (size_t i = 0; i < options.size(); ++i) {
304 const std::string option(options[i].first);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800305 if (StartsWith(option, "-help")) {
306 Usage(nullptr);
307 return false;
308 } else if (StartsWith(option, "-showversion")) {
309 UsageMessage(stdout, "ART version %s\n", Runtime::GetVersion());
310 Exit(0);
311 } else if (StartsWith(option, "-Xbootclasspath:")) {
312 boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data();
313 } else if (option == "-classpath" || option == "-cp") {
314 // TODO: support -Djava.class.path
315 i++;
316 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700317 Usage("Missing required class path value for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800318 return false;
319 }
320 const StringPiece& value = options[i].first;
321 class_path_string_ = value.data();
322 } else if (option == "bootclasspath") {
323 boot_class_path_
324 = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second);
325 } else if (StartsWith(option, "-Ximage:")) {
326 if (!ParseStringAfterChar(option, ':', &image_)) {
327 return false;
328 }
329 } else if (StartsWith(option, "-Xcheck:jni")) {
330 check_jni_ = true;
331 } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) {
332 std::string tail(option.substr(option[1] == 'X' ? 10 : 15));
333 // TODO: move parsing logic out of Dbg
334 if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) {
335 if (tail != "help") {
336 UsageMessage(stderr, "Failed to parse JDWP option %s\n", tail.c_str());
337 }
338 Usage("Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
339 "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n\n");
340 return false;
341 }
342 } else if (StartsWith(option, "-Xms")) {
343 size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024);
344 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700345 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800346 return false;
347 }
348 heap_initial_size_ = size;
349 } else if (StartsWith(option, "-Xmx")) {
350 size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024);
351 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700352 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800353 return false;
354 }
355 heap_maximum_size_ = size;
356 } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) {
357 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024);
358 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700359 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800360 return false;
361 }
362 heap_growth_limit_ = size;
363 } else if (StartsWith(option, "-XX:HeapMinFree=")) {
364 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024);
365 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700366 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800367 return false;
368 }
369 heap_min_free_ = size;
370 } else if (StartsWith(option, "-XX:HeapMaxFree=")) {
371 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024);
372 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700373 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800374 return false;
375 }
376 heap_max_free_ = size;
377 } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) {
378 if (!ParseDouble(option, '=', 0.1, 0.9, &heap_target_utilization_)) {
379 return false;
380 }
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700381 } else if (StartsWith(option, "-XX:ForegroundHeapGrowthMultiplier=")) {
Mathieu Chartier455820e2014-04-18 12:02:39 -0700382 if (!ParseDouble(option, '=', 0.1, 10.0, &foreground_heap_growth_multiplier_)) {
Mathieu Chartier2f8da3e2014-04-15 15:37:02 -0700383 return false;
384 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800385 } else if (StartsWith(option, "-XX:ParallelGCThreads=")) {
386 if (!ParseUnsignedInteger(option, '=', &parallel_gc_threads_)) {
387 return false;
388 }
389 } else if (StartsWith(option, "-XX:ConcGCThreads=")) {
390 if (!ParseUnsignedInteger(option, '=', &conc_gc_threads_)) {
391 return false;
392 }
393 } else if (StartsWith(option, "-Xss")) {
394 size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1);
395 if (size == 0) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700396 Usage("Failed to parse memory option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800397 return false;
398 }
399 stack_size_ = size;
400 } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) {
401 if (!ParseUnsignedInteger(option, '=', &max_spins_before_thin_lock_inflation_)) {
402 return false;
403 }
404 } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) {
Andreas Gampe39d92182014-03-05 16:46:44 -0800405 unsigned int value;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800406 if (!ParseUnsignedInteger(option, '=', &value)) {
407 return false;
408 }
409 long_pause_log_threshold_ = MsToNs(value);
410 } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) {
Andreas Gampe39d92182014-03-05 16:46:44 -0800411 unsigned int value;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800412 if (!ParseUnsignedInteger(option, '=', &value)) {
413 return false;
414 }
415 long_gc_log_threshold_ = MsToNs(value);
416 } else if (option == "-XX:DumpGCPerformanceOnShutdown") {
417 dump_gc_performance_on_shutdown_ = true;
418 } else if (option == "-XX:IgnoreMaxFootprint") {
419 ignore_max_footprint_ = true;
420 } else if (option == "-XX:LowMemoryMode") {
421 low_memory_mode_ = true;
422 } else if (option == "-XX:UseTLAB") {
423 use_tlab_ = true;
Zuo Wangf37a88b2014-07-10 04:26:41 -0700424 } else if (option == "-XX:EnableHSpaceCompactForOOM") {
425 use_homogeneous_space_compaction_for_oom_ = true;
426 } else if (option == "-XX:DisableHSpaceCompactForOOM") {
427 use_homogeneous_space_compaction_for_oom_ = false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800428 } else if (StartsWith(option, "-D")) {
429 properties_.push_back(option.substr(strlen("-D")));
430 } else if (StartsWith(option, "-Xjnitrace:")) {
431 jni_trace_ = option.substr(strlen("-Xjnitrace:"));
432 } else if (option == "compilercallbacks") {
433 compiler_callbacks_ =
434 reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second));
Narayan Kamath11d9f062014-04-23 20:24:57 +0100435 } else if (option == "imageinstructionset") {
436 image_isa_ = GetInstructionSetFromString(
437 reinterpret_cast<const char*>(options[i].second));
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800438 } else if (option == "-Xzygote") {
439 is_zygote_ = true;
440 } else if (option == "-Xint") {
441 interpreter_only_ = true;
442 } else if (StartsWith(option, "-Xgc:")) {
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700443 if (!ParseXGcOption(option)) {
444 return false;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800445 }
446 } else if (StartsWith(option, "-XX:BackgroundGC=")) {
447 std::string substring;
448 if (!ParseStringAfterChar(option, '=', &substring)) {
449 return false;
450 }
Zuo Wangf37a88b2014-07-10 04:26:41 -0700451 // Special handling for HSpaceCompact since this is only valid as a background GC type.
452 if (substring == "HSpaceCompact") {
453 background_collector_type_ = gc::kCollectorTypeHomogeneousSpaceCompact;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800454 } else {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700455 gc::CollectorType collector_type = ParseCollectorType(substring);
456 if (collector_type != gc::kCollectorTypeNone) {
457 background_collector_type_ = collector_type;
458 } else {
459 Usage("Unknown -XX:BackgroundGC option %s\n", substring.c_str());
460 return false;
461 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800462 }
463 } else if (option == "-XX:+DisableExplicitGC") {
464 is_explicit_gc_disabled_ = true;
465 } else if (StartsWith(option, "-verbose:")) {
466 std::vector<std::string> verbose_options;
467 Split(option.substr(strlen("-verbose:")), ',', verbose_options);
468 for (size_t i = 0; i < verbose_options.size(); ++i) {
469 if (verbose_options[i] == "class") {
470 gLogVerbosity.class_linker = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800471 } else if (verbose_options[i] == "compiler") {
472 gLogVerbosity.compiler = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800473 } else if (verbose_options[i] == "gc") {
474 gLogVerbosity.gc = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700475 } else if (verbose_options[i] == "heap") {
476 gLogVerbosity.heap = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800477 } else if (verbose_options[i] == "jdwp") {
478 gLogVerbosity.jdwp = true;
479 } else if (verbose_options[i] == "jni") {
480 gLogVerbosity.jni = true;
481 } else if (verbose_options[i] == "monitor") {
482 gLogVerbosity.monitor = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700483 } else if (verbose_options[i] == "profiler") {
484 gLogVerbosity.profiler = true;
485 } else if (verbose_options[i] == "signals") {
486 gLogVerbosity.signals = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800487 } else if (verbose_options[i] == "startup") {
488 gLogVerbosity.startup = true;
489 } else if (verbose_options[i] == "third-party-jni") {
490 gLogVerbosity.third_party_jni = true;
491 } else if (verbose_options[i] == "threads") {
492 gLogVerbosity.threads = true;
Brian Carlstrom4d466a82014-05-08 19:05:29 -0700493 } else if (verbose_options[i] == "verifier") {
494 gLogVerbosity.verifier = true;
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800495 } else {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700496 Usage("Unknown -verbose option %s\n", verbose_options[i].c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800497 return false;
498 }
499 }
Mingyao Yang42d65c52014-04-18 16:49:39 -0700500 } else if (StartsWith(option, "-verbose-methods:")) {
501 gLogVerbosity.compiler = false;
502 Split(option.substr(strlen("-verbose-methods:")), ',', gVerboseMethods);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800503 } else if (StartsWith(option, "-Xlockprofthreshold:")) {
504 if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) {
505 return false;
506 }
507 } else if (StartsWith(option, "-Xstacktracefile:")) {
508 if (!ParseStringAfterChar(option, ':', &stack_trace_file_)) {
509 return false;
510 }
511 } else if (option == "sensitiveThread") {
512 const void* hook = options[i].second;
513 hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(hook));
514 } else if (option == "vfprintf") {
515 const void* hook = options[i].second;
516 if (hook == nullptr) {
517 Usage("vfprintf argument was NULL");
518 return false;
519 }
520 hook_vfprintf_ =
521 reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook));
522 } else if (option == "exit") {
523 const void* hook = options[i].second;
524 if (hook == nullptr) {
525 Usage("exit argument was NULL");
526 return false;
527 }
528 hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook));
529 } else if (option == "abort") {
530 const void* hook = options[i].second;
531 if (hook == nullptr) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700532 Usage("abort was NULL\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800533 return false;
534 }
535 hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook));
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800536 } else if (option == "-Xmethod-trace") {
537 method_trace_ = true;
538 } else if (StartsWith(option, "-Xmethod-trace-file:")) {
539 method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:"));
540 } else if (StartsWith(option, "-Xmethod-trace-file-size:")) {
541 if (!ParseUnsignedInteger(option, ':', &method_trace_file_size_)) {
542 return false;
543 }
544 } else if (option == "-Xprofile:threadcpuclock") {
545 Trace::SetDefaultClockSource(kProfilerClockSourceThreadCpu);
546 } else if (option == "-Xprofile:wallclock") {
547 Trace::SetDefaultClockSource(kProfilerClockSourceWall);
548 } else if (option == "-Xprofile:dualclock") {
549 Trace::SetDefaultClockSource(kProfilerClockSourceDual);
Calin Juravlec1b643c2014-05-30 23:44:11 +0100550 } else if (option == "-Xenable-profiler") {
551 profiler_options_.enabled_ = true;
Wei Jin2221e3b2014-05-21 18:35:19 -0700552 } else if (StartsWith(option, "-Xprofile-filename:")) {
Ian Rogersf7fd3cb2014-05-19 22:57:34 -0700553 if (!ParseStringAfterChar(option, ':', &profile_output_filename_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800554 return false;
555 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800556 } else if (StartsWith(option, "-Xprofile-period:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100557 if (!ParseUnsignedInteger(option, ':', &profiler_options_.period_s_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800558 return false;
559 }
560 } else if (StartsWith(option, "-Xprofile-duration:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100561 if (!ParseUnsignedInteger(option, ':', &profiler_options_.duration_s_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800562 return false;
563 }
564 } else if (StartsWith(option, "-Xprofile-interval:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100565 if (!ParseUnsignedInteger(option, ':', &profiler_options_.interval_us_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800566 return false;
567 }
568 } else if (StartsWith(option, "-Xprofile-backoff:")) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100569 if (!ParseDouble(option, ':', 1.0, 10.0, &profiler_options_.backoff_coefficient_)) {
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800570 return false;
571 }
Calin Juravlec1b643c2014-05-30 23:44:11 +0100572 } else if (option == "-Xprofile-start-immediately") {
573 profiler_options_.start_immediately_ = true;
574 } else if (StartsWith(option, "-Xprofile-top-k-threshold:")) {
Calin Juravlec321c9b2014-06-11 19:04:35 +0100575 if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_threshold_)) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100576 return false;
577 }
578 } else if (StartsWith(option, "-Xprofile-top-k-change-threshold:")) {
Calin Juravlec321c9b2014-06-11 19:04:35 +0100579 if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_change_threshold_)) {
Calin Juravlec1b643c2014-05-30 23:44:11 +0100580 return false;
581 }
Wei Jina93b0bb2014-06-09 16:19:15 -0700582 } else if (option == "-Xprofile-type:method") {
583 profiler_options_.profile_type_ = kProfilerMethod;
Wei Jin445220d2014-06-20 15:56:53 -0700584 } else if (option == "-Xprofile-type:stack") {
585 profiler_options_.profile_type_ = kProfilerBoundedStack;
586 } else if (StartsWith(option, "-Xprofile-max-stack-depth:")) {
587 if (!ParseUnsignedInteger(option, ':', &profiler_options_.max_stack_depth_)) {
588 return false;
589 }
Nicolas Geoffray0025a862014-07-11 08:26:40 +0000590 } else if (StartsWith(option, "-implicit-checks:")) {
591 std::string checks;
592 if (!ParseStringAfterChar(option, ':', &checks)) {
593 return false;
594 }
595 std::vector<std::string> checkvec;
596 Split(checks, ',', checkvec);
597 for (auto& str : checkvec) {
598 std::string val = Trim(str);
599 if (val == "none") {
600 explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck |
601 kExplicitStackOverflowCheck;
602 } else if (val == "null") {
603 explicit_checks_ &= ~kExplicitNullCheck;
604 } else if (val == "suspend") {
605 explicit_checks_ &= ~kExplicitSuspendCheck;
606 } else if (val == "stack") {
607 explicit_checks_ &= ~kExplicitStackOverflowCheck;
608 } else if (val == "all") {
609 explicit_checks_ = 0;
610 } else {
611 return false;
612 }
613 }
614 } else if (StartsWith(option, "-explicit-checks:")) {
615 std::string checks;
616 if (!ParseStringAfterChar(option, ':', &checks)) {
617 return false;
618 }
619 std::vector<std::string> checkvec;
620 Split(checks, ',', checkvec);
621 for (auto& str : checkvec) {
622 std::string val = Trim(str);
623 if (val == "none") {
624 explicit_checks_ = 0;
625 } else if (val == "null") {
626 explicit_checks_ |= kExplicitNullCheck;
627 } else if (val == "suspend") {
628 explicit_checks_ |= kExplicitSuspendCheck;
629 } else if (val == "stack") {
630 explicit_checks_ |= kExplicitStackOverflowCheck;
631 } else if (val == "all") {
632 explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck |
633 kExplicitStackOverflowCheck;
634 } else {
635 return false;
636 }
637 }
Tsu Chiang Chuang12e6d742014-05-22 10:22:25 -0700638 } else if (StartsWith(option, "-Xcompiler:")) {
639 if (!ParseStringAfterChar(option, ':', &compiler_executable_)) {
640 return false;
641 }
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800642 } else if (option == "-Xcompiler-option") {
643 i++;
644 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700645 Usage("Missing required compiler option for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800646 return false;
647 }
648 compiler_options_.push_back(options[i].first);
649 } else if (option == "-Ximage-compiler-option") {
650 i++;
651 if (i == options.size()) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700652 Usage("Missing required compiler option for %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800653 return false;
654 }
655 image_compiler_options_.push_back(options[i].first);
Jeff Hao4a200f52014-04-01 14:58:49 -0700656 } else if (StartsWith(option, "-Xverify:")) {
657 std::string verify_mode = option.substr(strlen("-Xverify:"));
658 if (verify_mode == "none") {
659 verify_ = false;
660 } else if (verify_mode == "remote" || verify_mode == "all") {
661 verify_ = true;
662 } else {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700663 Usage("Unknown -Xverify option %s\n", verify_mode.c_str());
Jeff Hao4a200f52014-04-01 14:58:49 -0700664 return false;
665 }
Yevgeny Roubana6119a22014-03-24 11:31:24 +0700666 } else if (StartsWith(option, "-ea") ||
667 StartsWith(option, "-da") ||
668 StartsWith(option, "-enableassertions") ||
669 StartsWith(option, "-disableassertions") ||
Dave Allisonb373e092014-02-20 16:06:36 -0800670 (option == "--runtime-arg") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800671 (option == "-esa") ||
672 (option == "-dsa") ||
673 (option == "-enablesystemassertions") ||
674 (option == "-disablesystemassertions") ||
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800675 (option == "-Xrs") ||
676 StartsWith(option, "-Xint:") ||
677 StartsWith(option, "-Xdexopt:") ||
678 (option == "-Xnoquithandler") ||
679 StartsWith(option, "-Xjniopts:") ||
680 StartsWith(option, "-Xjnigreflimit:") ||
681 (option == "-Xgenregmap") ||
682 (option == "-Xnogenregmap") ||
683 StartsWith(option, "-Xverifyopt:") ||
684 (option == "-Xcheckdexsum") ||
685 (option == "-Xincludeselectedop") ||
686 StartsWith(option, "-Xjitop:") ||
687 (option == "-Xincludeselectedmethod") ||
688 StartsWith(option, "-Xjitthreshold:") ||
689 StartsWith(option, "-Xjitcodecachesize:") ||
690 (option == "-Xjitblocking") ||
691 StartsWith(option, "-Xjitmethod:") ||
692 StartsWith(option, "-Xjitclass:") ||
693 StartsWith(option, "-Xjitoffset:") ||
694 StartsWith(option, "-Xjitconfig:") ||
695 (option == "-Xjitcheckcg") ||
696 (option == "-Xjitverbose") ||
697 (option == "-Xjitprofile") ||
698 (option == "-Xjitdisableopt") ||
699 (option == "-Xjitsuspendpoll") ||
700 StartsWith(option, "-XX:mainThreadStackSize=")) {
701 // Ignored for backwards compatibility.
702 } else if (!ignore_unrecognized) {
Brian Carlstrom4ad33b32014-04-18 14:18:41 -0700703 Usage("Unrecognized option %s\n", option.c_str());
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800704 return false;
705 }
706 }
707
708 // If a reference to the dalvik core.jar snuck in, replace it with
709 // the art specific version. This can happen with on device
710 // boot.art/boot.oat generation by GenerateImage which relies on the
711 // value of BOOTCLASSPATH.
Kenny Rootd5185342014-05-13 14:47:05 -0700712#if defined(ART_TARGET)
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800713 std::string core_jar("/core.jar");
Kenny Rootd5185342014-05-13 14:47:05 -0700714 std::string core_libart_jar("/core-libart.jar");
715#else
716 // The host uses hostdex files.
717 std::string core_jar("/core-hostdex.jar");
718 std::string core_libart_jar("/core-libart-hostdex.jar");
719#endif
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800720 size_t core_jar_pos = boot_class_path_string_.find(core_jar);
721 if (core_jar_pos != std::string::npos) {
Kenny Rootd5185342014-05-13 14:47:05 -0700722 boot_class_path_string_.replace(core_jar_pos, core_jar.size(), core_libart_jar);
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800723 }
724
725 if (compiler_callbacks_ == nullptr && image_.empty()) {
726 image_ += GetAndroidRoot();
Brian Carlstrom3ac05bb2014-05-13 19:31:38 -0700727 image_ += "/framework/boot.art";
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800728 }
729 if (heap_growth_limit_ == 0) {
730 heap_growth_limit_ = heap_maximum_size_;
731 }
732 if (background_collector_type_ == gc::kCollectorTypeNone) {
733 background_collector_type_ = collector_type_;
734 }
735 return true;
Narayan Kamath11d9f062014-04-23 20:24:57 +0100736} // NOLINT(readability/fn_size)
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800737
738void ParsedOptions::Exit(int status) {
739 hook_exit_(status);
740}
741
742void ParsedOptions::Abort() {
743 hook_abort_();
744}
745
746void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) {
747 hook_vfprintf_(stderr, fmt, ap);
748}
749
750void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) {
751 va_list ap;
752 va_start(ap, fmt);
753 UsageMessageV(stream, fmt, ap);
754 va_end(ap);
755}
756
757void ParsedOptions::Usage(const char* fmt, ...) {
758 bool error = (fmt != nullptr);
759 FILE* stream = error ? stderr : stdout;
760
761 if (fmt != nullptr) {
762 va_list ap;
763 va_start(ap, fmt);
764 UsageMessageV(stream, fmt, ap);
765 va_end(ap);
766 }
767
768 const char* program = "dalvikvm";
769 UsageMessage(stream, "%s: [options] class [argument ...]\n", program);
770 UsageMessage(stream, "\n");
771 UsageMessage(stream, "The following standard options are supported:\n");
772 UsageMessage(stream, " -classpath classpath (-cp classpath)\n");
773 UsageMessage(stream, " -Dproperty=value\n");
774 UsageMessage(stream, " -verbose:tag ('gc', 'jni', or 'class')\n");
775 UsageMessage(stream, " -showversion\n");
776 UsageMessage(stream, " -help\n");
777 UsageMessage(stream, " -agentlib:jdwp=options\n");
778 UsageMessage(stream, "\n");
779
780 UsageMessage(stream, "The following extended options are supported:\n");
781 UsageMessage(stream, " -Xrunjdwp:<options>\n");
782 UsageMessage(stream, " -Xbootclasspath:bootclasspath\n");
783 UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n");
784 UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n");
785 UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n");
786 UsageMessage(stream, " -XssN (stack size)\n");
787 UsageMessage(stream, " -Xint\n");
788 UsageMessage(stream, "\n");
789
790 UsageMessage(stream, "The following Dalvik options are supported:\n");
791 UsageMessage(stream, " -Xzygote\n");
792 UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n");
793 UsageMessage(stream, " -Xstacktracefile:<filename>\n");
794 UsageMessage(stream, " -Xgc:[no]preverify\n");
795 UsageMessage(stream, " -Xgc:[no]postverify\n");
796 UsageMessage(stream, " -XX:+DisableExplicitGC\n");
797 UsageMessage(stream, " -XX:HeapGrowthLimit=N\n");
798 UsageMessage(stream, " -XX:HeapMinFree=N\n");
799 UsageMessage(stream, " -XX:HeapMaxFree=N\n");
800 UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n");
Mathieu Chartier455820e2014-04-18 12:02:39 -0700801 UsageMessage(stream, " -XX:ForegroundHeapGrowthMultiplier=doublevalue\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800802 UsageMessage(stream, " -XX:LowMemoryMode\n");
803 UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n");
804 UsageMessage(stream, "\n");
805
806 UsageMessage(stream, "The following unique to ART options are supported:\n");
807 UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n");
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700808 UsageMessage(stream, " -Xgc:[no]postsweepingverify_rosalloc\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800809 UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n");
Mathieu Chartier6f365cc2014-04-23 12:42:27 -0700810 UsageMessage(stream, " -Xgc:[no]presweepingverify\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800811 UsageMessage(stream, " -Ximage:filename\n");
812 UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n");
813 UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n");
814 UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n");
815 UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n");
816 UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n");
817 UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n");
818 UsageMessage(stream, " -XX:IgnoreMaxFootprint\n");
819 UsageMessage(stream, " -XX:UseTLAB\n");
820 UsageMessage(stream, " -XX:BackgroundGC=none\n");
821 UsageMessage(stream, " -Xmethod-trace\n");
822 UsageMessage(stream, " -Xmethod-trace-file:filename");
823 UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n");
Calin Juravlec1b643c2014-05-30 23:44:11 +0100824 UsageMessage(stream, " -Xenable-profiler\n");
Wei Jin2221e3b2014-05-21 18:35:19 -0700825 UsageMessage(stream, " -Xprofile-filename:filename\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800826 UsageMessage(stream, " -Xprofile-period:integervalue\n");
827 UsageMessage(stream, " -Xprofile-duration:integervalue\n");
828 UsageMessage(stream, " -Xprofile-interval:integervalue\n");
Calin Juravle54c73ca2014-05-22 12:13:54 +0100829 UsageMessage(stream, " -Xprofile-backoff:doublevalue\n");
Calin Juravlec1b643c2014-05-30 23:44:11 +0100830 UsageMessage(stream, " -Xprofile-start-immediately\n");
831 UsageMessage(stream, " -Xprofile-top-k-threshold:doublevalue\n");
832 UsageMessage(stream, " -Xprofile-top-k-change-threshold:doublevalue\n");
Wei Jin445220d2014-06-20 15:56:53 -0700833 UsageMessage(stream, " -Xprofile-type:{method,stack}\n");
834 UsageMessage(stream, " -Xprofile-max-stack-depth:integervalue\n");
Tsu Chiang Chuang12e6d742014-05-22 10:22:25 -0700835 UsageMessage(stream, " -Xcompiler:filename\n");
Brian Carlstrom491ca9e2014-03-02 18:24:38 -0800836 UsageMessage(stream, " -Xcompiler-option dex2oat-option\n");
837 UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n");
838 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;
Dave Allison999385c2014-05-20 15:16:02 -0700930 if (false) {
931 // 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