Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 1 | /* |
| 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" |
| 18 | |
| 19 | #include "debugger.h" |
| 20 | #include "monitor.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | ParsedOptions* ParsedOptions::Create(const Runtime::Options& options, bool ignore_unrecognized) { |
| 25 | UniquePtr<ParsedOptions> parsed(new ParsedOptions()); |
| 26 | if (parsed->Parse(options, ignore_unrecognized)) { |
| 27 | return parsed.release(); |
| 28 | } |
| 29 | return nullptr; |
| 30 | } |
| 31 | |
| 32 | // Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify |
| 33 | // memory sizes. [kK] indicates kilobytes, [mM] megabytes, and |
| 34 | // [gG] gigabytes. |
| 35 | // |
| 36 | // "s" should point just past the "-Xm?" part of the string. |
| 37 | // "div" specifies a divisor, e.g. 1024 if the value must be a multiple |
| 38 | // of 1024. |
| 39 | // |
| 40 | // The spec says the -Xmx and -Xms options must be multiples of 1024. It |
| 41 | // doesn't say anything about -Xss. |
| 42 | // |
| 43 | // Returns 0 (a useless size) if "s" is malformed or specifies a low or |
| 44 | // non-evenly-divisible value. |
| 45 | // |
| 46 | size_t ParseMemoryOption(const char* s, size_t div) { |
| 47 | // strtoul accepts a leading [+-], which we don't want, |
| 48 | // so make sure our string starts with a decimal digit. |
| 49 | if (isdigit(*s)) { |
| 50 | char* s2; |
| 51 | size_t val = strtoul(s, &s2, 10); |
| 52 | if (s2 != s) { |
| 53 | // s2 should be pointing just after the number. |
| 54 | // If this is the end of the string, the user |
| 55 | // has specified a number of bytes. Otherwise, |
| 56 | // there should be exactly one more character |
| 57 | // that specifies a multiplier. |
| 58 | if (*s2 != '\0') { |
| 59 | // The remainder of the string is either a single multiplier |
| 60 | // character, or nothing to indicate that the value is in |
| 61 | // bytes. |
| 62 | char c = *s2++; |
| 63 | if (*s2 == '\0') { |
| 64 | size_t mul; |
| 65 | if (c == '\0') { |
| 66 | mul = 1; |
| 67 | } else if (c == 'k' || c == 'K') { |
| 68 | mul = KB; |
| 69 | } else if (c == 'm' || c == 'M') { |
| 70 | mul = MB; |
| 71 | } else if (c == 'g' || c == 'G') { |
| 72 | mul = GB; |
| 73 | } else { |
| 74 | // Unknown multiplier character. |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | if (val <= std::numeric_limits<size_t>::max() / mul) { |
| 79 | val *= mul; |
| 80 | } else { |
| 81 | // Clamp to a multiple of 1024. |
| 82 | val = std::numeric_limits<size_t>::max() & ~(1024-1); |
| 83 | } |
| 84 | } else { |
| 85 | // There's more than one character after the numeric part. |
| 86 | return 0; |
| 87 | } |
| 88 | } |
| 89 | // The man page says that a -Xm value must be a multiple of 1024. |
| 90 | if (val % div == 0) { |
| 91 | return val; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static gc::CollectorType ParseCollectorType(const std::string& option) { |
| 99 | if (option == "MS" || option == "nonconcurrent") { |
| 100 | return gc::kCollectorTypeMS; |
| 101 | } else if (option == "CMS" || option == "concurrent") { |
| 102 | return gc::kCollectorTypeCMS; |
| 103 | } else if (option == "SS") { |
| 104 | return gc::kCollectorTypeSS; |
| 105 | } else if (option == "GSS") { |
| 106 | return gc::kCollectorTypeGSS; |
| 107 | } else { |
| 108 | return gc::kCollectorTypeNone; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | bool ParsedOptions::Parse(const Runtime::Options& options, bool ignore_unrecognized) { |
| 113 | const char* boot_class_path_string = getenv("BOOTCLASSPATH"); |
| 114 | if (boot_class_path_string != NULL) { |
| 115 | boot_class_path_string_ = boot_class_path_string; |
| 116 | } |
| 117 | const char* class_path_string = getenv("CLASSPATH"); |
| 118 | if (class_path_string != NULL) { |
| 119 | class_path_string_ = class_path_string; |
| 120 | } |
| 121 | // -Xcheck:jni is off by default for regular builds but on by default in debug builds. |
| 122 | check_jni_ = kIsDebugBuild; |
| 123 | |
| 124 | heap_initial_size_ = gc::Heap::kDefaultInitialSize; |
| 125 | heap_maximum_size_ = gc::Heap::kDefaultMaximumSize; |
| 126 | heap_min_free_ = gc::Heap::kDefaultMinFree; |
| 127 | heap_max_free_ = gc::Heap::kDefaultMaxFree; |
| 128 | heap_target_utilization_ = gc::Heap::kDefaultTargetUtilization; |
| 129 | heap_growth_limit_ = 0; // 0 means no growth limit . |
| 130 | // Default to number of processors minus one since the main GC thread also does work. |
| 131 | parallel_gc_threads_ = sysconf(_SC_NPROCESSORS_CONF) - 1; |
| 132 | // Only the main GC thread, no workers. |
| 133 | conc_gc_threads_ = 0; |
| 134 | // Default is CMS which is Sticky + Partial + Full CMS GC. |
| 135 | collector_type_ = gc::kCollectorTypeCMS; |
| 136 | // If background_collector_type_ is kCollectorTypeNone, it defaults to the collector_type_ after |
| 137 | // parsing options. |
| 138 | background_collector_type_ = gc::kCollectorTypeNone; |
| 139 | stack_size_ = 0; // 0 means default. |
| 140 | max_spins_before_thin_lock_inflation_ = Monitor::kDefaultMaxSpinsBeforeThinLockInflation; |
| 141 | low_memory_mode_ = false; |
| 142 | use_tlab_ = false; |
| 143 | verify_pre_gc_heap_ = false; |
| 144 | verify_post_gc_heap_ = kIsDebugBuild; |
| 145 | verify_pre_gc_rosalloc_ = kIsDebugBuild; |
| 146 | verify_post_gc_rosalloc_ = false; |
| 147 | |
| 148 | compiler_callbacks_ = nullptr; |
| 149 | is_zygote_ = false; |
| 150 | interpreter_only_ = false; |
| 151 | is_explicit_gc_disabled_ = false; |
| 152 | |
| 153 | long_pause_log_threshold_ = gc::Heap::kDefaultLongPauseLogThreshold; |
| 154 | long_gc_log_threshold_ = gc::Heap::kDefaultLongGCLogThreshold; |
| 155 | dump_gc_performance_on_shutdown_ = false; |
| 156 | ignore_max_footprint_ = false; |
| 157 | |
| 158 | lock_profiling_threshold_ = 0; |
| 159 | hook_is_sensitive_thread_ = NULL; |
| 160 | |
| 161 | hook_vfprintf_ = vfprintf; |
| 162 | hook_exit_ = exit; |
| 163 | hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort. |
| 164 | |
| 165 | // gLogVerbosity.class_linker = true; // TODO: don't check this in! |
| 166 | // gLogVerbosity.compiler = true; // TODO: don't check this in! |
| 167 | // gLogVerbosity.verifier = true; // TODO: don't check this in! |
| 168 | // gLogVerbosity.heap = true; // TODO: don't check this in! |
| 169 | // gLogVerbosity.gc = true; // TODO: don't check this in! |
| 170 | // gLogVerbosity.jdwp = true; // TODO: don't check this in! |
| 171 | // gLogVerbosity.jni = true; // TODO: don't check this in! |
| 172 | // gLogVerbosity.monitor = true; // TODO: don't check this in! |
| 173 | // gLogVerbosity.startup = true; // TODO: don't check this in! |
| 174 | // gLogVerbosity.third_party_jni = true; // TODO: don't check this in! |
| 175 | // gLogVerbosity.threads = true; // TODO: don't check this in! |
| 176 | |
| 177 | method_trace_ = false; |
| 178 | method_trace_file_ = "/data/method-trace-file.bin"; |
| 179 | method_trace_file_size_ = 10 * MB; |
| 180 | |
| 181 | profile_ = false; |
| 182 | profile_period_s_ = 10; // Seconds. |
| 183 | profile_duration_s_ = 20; // Seconds. |
| 184 | profile_interval_us_ = 500; // Microseconds. |
| 185 | profile_backoff_coefficient_ = 2.0; |
| 186 | profile_clock_source_ = kDefaultProfilerClockSource; |
| 187 | |
| 188 | for (size_t i = 0; i < options.size(); ++i) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 189 | if (true && options[0].first == "-Xzygote") { |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 190 | LOG(INFO) << "option[" << i << "]=" << options[i].first; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 191 | } |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 192 | } |
| 193 | for (size_t i = 0; i < options.size(); ++i) { |
| 194 | const std::string option(options[i].first); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 195 | if (StartsWith(option, "-help")) { |
| 196 | Usage(nullptr); |
| 197 | return false; |
| 198 | } else if (StartsWith(option, "-showversion")) { |
| 199 | UsageMessage(stdout, "ART version %s\n", Runtime::GetVersion()); |
| 200 | Exit(0); |
| 201 | } else if (StartsWith(option, "-Xbootclasspath:")) { |
| 202 | boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data(); |
| 203 | } else if (option == "-classpath" || option == "-cp") { |
| 204 | // TODO: support -Djava.class.path |
| 205 | i++; |
| 206 | if (i == options.size()) { |
| 207 | Usage("Missing required class path value for %s", option.c_str()); |
| 208 | return false; |
| 209 | } |
| 210 | const StringPiece& value = options[i].first; |
| 211 | class_path_string_ = value.data(); |
| 212 | } else if (option == "bootclasspath") { |
| 213 | boot_class_path_ |
| 214 | = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second); |
| 215 | } else if (StartsWith(option, "-Ximage:")) { |
| 216 | if (!ParseStringAfterChar(option, ':', &image_)) { |
| 217 | return false; |
| 218 | } |
| 219 | } else if (StartsWith(option, "-Xcheck:jni")) { |
| 220 | check_jni_ = true; |
| 221 | } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) { |
| 222 | std::string tail(option.substr(option[1] == 'X' ? 10 : 15)); |
| 223 | // TODO: move parsing logic out of Dbg |
| 224 | if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) { |
| 225 | if (tail != "help") { |
| 226 | UsageMessage(stderr, "Failed to parse JDWP option %s\n", tail.c_str()); |
| 227 | } |
| 228 | Usage("Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n" |
| 229 | "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n\n"); |
| 230 | return false; |
| 231 | } |
| 232 | } else if (StartsWith(option, "-Xms")) { |
| 233 | size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024); |
| 234 | if (size == 0) { |
| 235 | Usage("Failed to parse memory option %s", option.c_str()); |
| 236 | return false; |
| 237 | } |
| 238 | heap_initial_size_ = size; |
| 239 | } else if (StartsWith(option, "-Xmx")) { |
| 240 | size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024); |
| 241 | if (size == 0) { |
| 242 | Usage("Failed to parse memory option %s", option.c_str()); |
| 243 | return false; |
| 244 | } |
| 245 | heap_maximum_size_ = size; |
| 246 | } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) { |
| 247 | size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024); |
| 248 | if (size == 0) { |
| 249 | Usage("Failed to parse memory option %s", option.c_str()); |
| 250 | return false; |
| 251 | } |
| 252 | heap_growth_limit_ = size; |
| 253 | } else if (StartsWith(option, "-XX:HeapMinFree=")) { |
| 254 | size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024); |
| 255 | if (size == 0) { |
| 256 | Usage("Failed to parse memory option %s", option.c_str()); |
| 257 | return false; |
| 258 | } |
| 259 | heap_min_free_ = size; |
| 260 | } else if (StartsWith(option, "-XX:HeapMaxFree=")) { |
| 261 | size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024); |
| 262 | if (size == 0) { |
| 263 | Usage("Failed to parse memory option %s", option.c_str()); |
| 264 | return false; |
| 265 | } |
| 266 | heap_max_free_ = size; |
| 267 | } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) { |
| 268 | if (!ParseDouble(option, '=', 0.1, 0.9, &heap_target_utilization_)) { |
| 269 | return false; |
| 270 | } |
| 271 | } else if (StartsWith(option, "-XX:ParallelGCThreads=")) { |
| 272 | if (!ParseUnsignedInteger(option, '=', ¶llel_gc_threads_)) { |
| 273 | return false; |
| 274 | } |
| 275 | } else if (StartsWith(option, "-XX:ConcGCThreads=")) { |
| 276 | if (!ParseUnsignedInteger(option, '=', &conc_gc_threads_)) { |
| 277 | return false; |
| 278 | } |
| 279 | } else if (StartsWith(option, "-Xss")) { |
| 280 | size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1); |
| 281 | if (size == 0) { |
| 282 | Usage("Failed to parse memory option %s", option.c_str()); |
| 283 | return false; |
| 284 | } |
| 285 | stack_size_ = size; |
| 286 | } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) { |
| 287 | if (!ParseUnsignedInteger(option, '=', &max_spins_before_thin_lock_inflation_)) { |
| 288 | return false; |
| 289 | } |
| 290 | } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) { |
Andreas Gampe | 39d9218 | 2014-03-05 16:46:44 -0800 | [diff] [blame^] | 291 | unsigned int value; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 292 | if (!ParseUnsignedInteger(option, '=', &value)) { |
| 293 | return false; |
| 294 | } |
| 295 | long_pause_log_threshold_ = MsToNs(value); |
| 296 | } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) { |
Andreas Gampe | 39d9218 | 2014-03-05 16:46:44 -0800 | [diff] [blame^] | 297 | unsigned int value; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 298 | if (!ParseUnsignedInteger(option, '=', &value)) { |
| 299 | return false; |
| 300 | } |
| 301 | long_gc_log_threshold_ = MsToNs(value); |
| 302 | } else if (option == "-XX:DumpGCPerformanceOnShutdown") { |
| 303 | dump_gc_performance_on_shutdown_ = true; |
| 304 | } else if (option == "-XX:IgnoreMaxFootprint") { |
| 305 | ignore_max_footprint_ = true; |
| 306 | } else if (option == "-XX:LowMemoryMode") { |
| 307 | low_memory_mode_ = true; |
| 308 | } else if (option == "-XX:UseTLAB") { |
| 309 | use_tlab_ = true; |
| 310 | } else if (StartsWith(option, "-D")) { |
| 311 | properties_.push_back(option.substr(strlen("-D"))); |
| 312 | } else if (StartsWith(option, "-Xjnitrace:")) { |
| 313 | jni_trace_ = option.substr(strlen("-Xjnitrace:")); |
| 314 | } else if (option == "compilercallbacks") { |
| 315 | compiler_callbacks_ = |
| 316 | reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second)); |
| 317 | } else if (option == "-Xzygote") { |
| 318 | is_zygote_ = true; |
| 319 | } else if (option == "-Xint") { |
| 320 | interpreter_only_ = true; |
| 321 | } else if (StartsWith(option, "-Xgc:")) { |
| 322 | std::vector<std::string> gc_options; |
| 323 | Split(option.substr(strlen("-Xgc:")), ',', gc_options); |
| 324 | for (const std::string& gc_option : gc_options) { |
| 325 | gc::CollectorType collector_type = ParseCollectorType(gc_option); |
| 326 | if (collector_type != gc::kCollectorTypeNone) { |
| 327 | collector_type_ = collector_type; |
| 328 | } else if (gc_option == "preverify") { |
| 329 | verify_pre_gc_heap_ = true; |
| 330 | } else if (gc_option == "nopreverify") { |
| 331 | verify_pre_gc_heap_ = false; |
| 332 | } else if (gc_option == "postverify") { |
| 333 | verify_post_gc_heap_ = true; |
| 334 | } else if (gc_option == "nopostverify") { |
| 335 | verify_post_gc_heap_ = false; |
| 336 | } else if (gc_option == "preverify_rosalloc") { |
| 337 | verify_pre_gc_rosalloc_ = true; |
| 338 | } else if (gc_option == "nopreverify_rosalloc") { |
| 339 | verify_pre_gc_rosalloc_ = false; |
| 340 | } else if (gc_option == "postverify_rosalloc") { |
| 341 | verify_post_gc_rosalloc_ = true; |
| 342 | } else if (gc_option == "nopostverify_rosalloc") { |
| 343 | verify_post_gc_rosalloc_ = false; |
| 344 | } else if ((gc_option == "precise") || |
| 345 | (gc_option == "noprecise") || |
| 346 | (gc_option == "verifycardtable") || |
| 347 | (gc_option == "noverifycardtable")) { |
| 348 | // Ignored for backwards compatibility. |
| 349 | } else { |
| 350 | Usage("Unknown -Xgc option %s", gc_option.c_str()); |
| 351 | return false; |
| 352 | } |
| 353 | } |
| 354 | } else if (StartsWith(option, "-XX:BackgroundGC=")) { |
| 355 | std::string substring; |
| 356 | if (!ParseStringAfterChar(option, '=', &substring)) { |
| 357 | return false; |
| 358 | } |
| 359 | gc::CollectorType collector_type = ParseCollectorType(substring); |
| 360 | if (collector_type != gc::kCollectorTypeNone) { |
| 361 | background_collector_type_ = collector_type; |
| 362 | } else { |
| 363 | Usage("Unknown -XX:BackgroundGC option %s", substring.c_str()); |
| 364 | return false; |
| 365 | } |
| 366 | } else if (option == "-XX:+DisableExplicitGC") { |
| 367 | is_explicit_gc_disabled_ = true; |
| 368 | } else if (StartsWith(option, "-verbose:")) { |
| 369 | std::vector<std::string> verbose_options; |
| 370 | Split(option.substr(strlen("-verbose:")), ',', verbose_options); |
| 371 | for (size_t i = 0; i < verbose_options.size(); ++i) { |
| 372 | if (verbose_options[i] == "class") { |
| 373 | gLogVerbosity.class_linker = true; |
| 374 | } else if (verbose_options[i] == "verifier") { |
| 375 | gLogVerbosity.verifier = true; |
| 376 | } else if (verbose_options[i] == "compiler") { |
| 377 | gLogVerbosity.compiler = true; |
| 378 | } else if (verbose_options[i] == "heap") { |
| 379 | gLogVerbosity.heap = true; |
| 380 | } else if (verbose_options[i] == "gc") { |
| 381 | gLogVerbosity.gc = true; |
| 382 | } else if (verbose_options[i] == "jdwp") { |
| 383 | gLogVerbosity.jdwp = true; |
| 384 | } else if (verbose_options[i] == "jni") { |
| 385 | gLogVerbosity.jni = true; |
| 386 | } else if (verbose_options[i] == "monitor") { |
| 387 | gLogVerbosity.monitor = true; |
| 388 | } else if (verbose_options[i] == "startup") { |
| 389 | gLogVerbosity.startup = true; |
| 390 | } else if (verbose_options[i] == "third-party-jni") { |
| 391 | gLogVerbosity.third_party_jni = true; |
| 392 | } else if (verbose_options[i] == "threads") { |
| 393 | gLogVerbosity.threads = true; |
| 394 | } else { |
| 395 | Usage("Unknown -verbose option %s", verbose_options[i].c_str()); |
| 396 | return false; |
| 397 | } |
| 398 | } |
| 399 | } else if (StartsWith(option, "-Xlockprofthreshold:")) { |
| 400 | if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) { |
| 401 | return false; |
| 402 | } |
| 403 | } else if (StartsWith(option, "-Xstacktracefile:")) { |
| 404 | if (!ParseStringAfterChar(option, ':', &stack_trace_file_)) { |
| 405 | return false; |
| 406 | } |
| 407 | } else if (option == "sensitiveThread") { |
| 408 | const void* hook = options[i].second; |
| 409 | hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(hook)); |
| 410 | } else if (option == "vfprintf") { |
| 411 | const void* hook = options[i].second; |
| 412 | if (hook == nullptr) { |
| 413 | Usage("vfprintf argument was NULL"); |
| 414 | return false; |
| 415 | } |
| 416 | hook_vfprintf_ = |
| 417 | reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook)); |
| 418 | } else if (option == "exit") { |
| 419 | const void* hook = options[i].second; |
| 420 | if (hook == nullptr) { |
| 421 | Usage("exit argument was NULL"); |
| 422 | return false; |
| 423 | } |
| 424 | hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook)); |
| 425 | } else if (option == "abort") { |
| 426 | const void* hook = options[i].second; |
| 427 | if (hook == nullptr) { |
| 428 | Usage("abort was NULL"); |
| 429 | return false; |
| 430 | } |
| 431 | hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook)); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 432 | } else if (option == "-Xmethod-trace") { |
| 433 | method_trace_ = true; |
| 434 | } else if (StartsWith(option, "-Xmethod-trace-file:")) { |
| 435 | method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:")); |
| 436 | } else if (StartsWith(option, "-Xmethod-trace-file-size:")) { |
| 437 | if (!ParseUnsignedInteger(option, ':', &method_trace_file_size_)) { |
| 438 | return false; |
| 439 | } |
| 440 | } else if (option == "-Xprofile:threadcpuclock") { |
| 441 | Trace::SetDefaultClockSource(kProfilerClockSourceThreadCpu); |
| 442 | } else if (option == "-Xprofile:wallclock") { |
| 443 | Trace::SetDefaultClockSource(kProfilerClockSourceWall); |
| 444 | } else if (option == "-Xprofile:dualclock") { |
| 445 | Trace::SetDefaultClockSource(kProfilerClockSourceDual); |
| 446 | } else if (StartsWith(option, "-Xprofile:")) { |
| 447 | if (!ParseStringAfterChar(option, ';', &profile_output_filename_)) { |
| 448 | return false; |
| 449 | } |
| 450 | profile_ = true; |
| 451 | } else if (StartsWith(option, "-Xprofile-period:")) { |
| 452 | if (!ParseUnsignedInteger(option, ':', &profile_period_s_)) { |
| 453 | return false; |
| 454 | } |
| 455 | } else if (StartsWith(option, "-Xprofile-duration:")) { |
| 456 | if (!ParseUnsignedInteger(option, ':', &profile_duration_s_)) { |
| 457 | return false; |
| 458 | } |
| 459 | } else if (StartsWith(option, "-Xprofile-interval:")) { |
| 460 | if (!ParseUnsignedInteger(option, ':', &profile_interval_us_)) { |
| 461 | return false; |
| 462 | } |
| 463 | } else if (StartsWith(option, "-Xprofile-backoff:")) { |
| 464 | if (!ParseDouble(option, ':', 1.0, 10.0, &profile_backoff_coefficient_)) { |
| 465 | return false; |
| 466 | } |
| 467 | } else if (option == "-Xcompiler-option") { |
| 468 | i++; |
| 469 | if (i == options.size()) { |
| 470 | Usage("Missing required compiler option for %s", option.c_str()); |
| 471 | return false; |
| 472 | } |
| 473 | compiler_options_.push_back(options[i].first); |
| 474 | } else if (option == "-Ximage-compiler-option") { |
| 475 | i++; |
| 476 | if (i == options.size()) { |
| 477 | Usage("Missing required compiler option for %s", option.c_str()); |
| 478 | return false; |
| 479 | } |
| 480 | image_compiler_options_.push_back(options[i].first); |
| 481 | } else if (StartsWith(option, "-ea:") || |
| 482 | StartsWith(option, "-da:") || |
| 483 | StartsWith(option, "-enableassertions:") || |
| 484 | StartsWith(option, "-disableassertions:") || |
| 485 | (option == "-esa") || |
| 486 | (option == "-dsa") || |
| 487 | (option == "-enablesystemassertions") || |
| 488 | (option == "-disablesystemassertions") || |
| 489 | StartsWith(option, "-Xverify:") || |
| 490 | (option == "-Xrs") || |
| 491 | StartsWith(option, "-Xint:") || |
| 492 | StartsWith(option, "-Xdexopt:") || |
| 493 | (option == "-Xnoquithandler") || |
| 494 | StartsWith(option, "-Xjniopts:") || |
| 495 | StartsWith(option, "-Xjnigreflimit:") || |
| 496 | (option == "-Xgenregmap") || |
| 497 | (option == "-Xnogenregmap") || |
| 498 | StartsWith(option, "-Xverifyopt:") || |
| 499 | (option == "-Xcheckdexsum") || |
| 500 | (option == "-Xincludeselectedop") || |
| 501 | StartsWith(option, "-Xjitop:") || |
| 502 | (option == "-Xincludeselectedmethod") || |
| 503 | StartsWith(option, "-Xjitthreshold:") || |
| 504 | StartsWith(option, "-Xjitcodecachesize:") || |
| 505 | (option == "-Xjitblocking") || |
| 506 | StartsWith(option, "-Xjitmethod:") || |
| 507 | StartsWith(option, "-Xjitclass:") || |
| 508 | StartsWith(option, "-Xjitoffset:") || |
| 509 | StartsWith(option, "-Xjitconfig:") || |
| 510 | (option == "-Xjitcheckcg") || |
| 511 | (option == "-Xjitverbose") || |
| 512 | (option == "-Xjitprofile") || |
| 513 | (option == "-Xjitdisableopt") || |
| 514 | (option == "-Xjitsuspendpoll") || |
| 515 | StartsWith(option, "-XX:mainThreadStackSize=")) { |
| 516 | // Ignored for backwards compatibility. |
| 517 | } else if (!ignore_unrecognized) { |
| 518 | Usage("Unrecognized option %s", option.c_str()); |
| 519 | return false; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | // If a reference to the dalvik core.jar snuck in, replace it with |
| 524 | // the art specific version. This can happen with on device |
| 525 | // boot.art/boot.oat generation by GenerateImage which relies on the |
| 526 | // value of BOOTCLASSPATH. |
| 527 | std::string core_jar("/core.jar"); |
| 528 | size_t core_jar_pos = boot_class_path_string_.find(core_jar); |
| 529 | if (core_jar_pos != std::string::npos) { |
| 530 | boot_class_path_string_.replace(core_jar_pos, core_jar.size(), "/core-libart.jar"); |
| 531 | } |
| 532 | |
| 533 | if (compiler_callbacks_ == nullptr && image_.empty()) { |
| 534 | image_ += GetAndroidRoot(); |
| 535 | image_ += "/framework/boot.art"; |
| 536 | } |
| 537 | if (heap_growth_limit_ == 0) { |
| 538 | heap_growth_limit_ = heap_maximum_size_; |
| 539 | } |
| 540 | if (background_collector_type_ == gc::kCollectorTypeNone) { |
| 541 | background_collector_type_ = collector_type_; |
| 542 | } |
| 543 | return true; |
| 544 | } |
| 545 | |
| 546 | void ParsedOptions::Exit(int status) { |
| 547 | hook_exit_(status); |
| 548 | } |
| 549 | |
| 550 | void ParsedOptions::Abort() { |
| 551 | hook_abort_(); |
| 552 | } |
| 553 | |
| 554 | void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) { |
| 555 | hook_vfprintf_(stderr, fmt, ap); |
| 556 | } |
| 557 | |
| 558 | void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) { |
| 559 | va_list ap; |
| 560 | va_start(ap, fmt); |
| 561 | UsageMessageV(stream, fmt, ap); |
| 562 | va_end(ap); |
| 563 | } |
| 564 | |
| 565 | void ParsedOptions::Usage(const char* fmt, ...) { |
| 566 | bool error = (fmt != nullptr); |
| 567 | FILE* stream = error ? stderr : stdout; |
| 568 | |
| 569 | if (fmt != nullptr) { |
| 570 | va_list ap; |
| 571 | va_start(ap, fmt); |
| 572 | UsageMessageV(stream, fmt, ap); |
| 573 | va_end(ap); |
| 574 | } |
| 575 | |
| 576 | const char* program = "dalvikvm"; |
| 577 | UsageMessage(stream, "%s: [options] class [argument ...]\n", program); |
| 578 | UsageMessage(stream, "\n"); |
| 579 | UsageMessage(stream, "The following standard options are supported:\n"); |
| 580 | UsageMessage(stream, " -classpath classpath (-cp classpath)\n"); |
| 581 | UsageMessage(stream, " -Dproperty=value\n"); |
| 582 | UsageMessage(stream, " -verbose:tag ('gc', 'jni', or 'class')\n"); |
| 583 | UsageMessage(stream, " -showversion\n"); |
| 584 | UsageMessage(stream, " -help\n"); |
| 585 | UsageMessage(stream, " -agentlib:jdwp=options\n"); |
| 586 | UsageMessage(stream, "\n"); |
| 587 | |
| 588 | UsageMessage(stream, "The following extended options are supported:\n"); |
| 589 | UsageMessage(stream, " -Xrunjdwp:<options>\n"); |
| 590 | UsageMessage(stream, " -Xbootclasspath:bootclasspath\n"); |
| 591 | UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n"); |
| 592 | UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n"); |
| 593 | UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n"); |
| 594 | UsageMessage(stream, " -XssN (stack size)\n"); |
| 595 | UsageMessage(stream, " -Xint\n"); |
| 596 | UsageMessage(stream, "\n"); |
| 597 | |
| 598 | UsageMessage(stream, "The following Dalvik options are supported:\n"); |
| 599 | UsageMessage(stream, " -Xzygote\n"); |
| 600 | UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n"); |
| 601 | UsageMessage(stream, " -Xstacktracefile:<filename>\n"); |
| 602 | UsageMessage(stream, " -Xgc:[no]preverify\n"); |
| 603 | UsageMessage(stream, " -Xgc:[no]postverify\n"); |
| 604 | UsageMessage(stream, " -XX:+DisableExplicitGC\n"); |
| 605 | UsageMessage(stream, " -XX:HeapGrowthLimit=N\n"); |
| 606 | UsageMessage(stream, " -XX:HeapMinFree=N\n"); |
| 607 | UsageMessage(stream, " -XX:HeapMaxFree=N\n"); |
| 608 | UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n"); |
| 609 | UsageMessage(stream, " -XX:LowMemoryMode\n"); |
| 610 | UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n"); |
| 611 | UsageMessage(stream, "\n"); |
| 612 | |
| 613 | UsageMessage(stream, "The following unique to ART options are supported:\n"); |
| 614 | UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n"); |
| 615 | UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n"); |
| 616 | UsageMessage(stream, " -Ximage:filename\n"); |
| 617 | UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n"); |
| 618 | UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n"); |
| 619 | UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n"); |
| 620 | UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n"); |
| 621 | UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n"); |
| 622 | UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n"); |
| 623 | UsageMessage(stream, " -XX:IgnoreMaxFootprint\n"); |
| 624 | UsageMessage(stream, " -XX:UseTLAB\n"); |
| 625 | UsageMessage(stream, " -XX:BackgroundGC=none\n"); |
| 626 | UsageMessage(stream, " -Xmethod-trace\n"); |
| 627 | UsageMessage(stream, " -Xmethod-trace-file:filename"); |
| 628 | UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n"); |
| 629 | UsageMessage(stream, " -Xprofile=filename\n"); |
| 630 | UsageMessage(stream, " -Xprofile-period:integervalue\n"); |
| 631 | UsageMessage(stream, " -Xprofile-duration:integervalue\n"); |
| 632 | UsageMessage(stream, " -Xprofile-interval:integervalue\n"); |
| 633 | UsageMessage(stream, " -Xprofile-backoff:integervalue\n"); |
| 634 | UsageMessage(stream, " -Xcompiler-option dex2oat-option\n"); |
| 635 | UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n"); |
| 636 | UsageMessage(stream, "\n"); |
| 637 | |
| 638 | UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n"); |
| 639 | UsageMessage(stream, " -ea[:<package name>... |:<class name>]\n"); |
| 640 | UsageMessage(stream, " -da[:<package name>... |:<class name>]\n"); |
| 641 | UsageMessage(stream, " (-enableassertions, -disableassertions)\n"); |
| 642 | UsageMessage(stream, " -esa\n"); |
| 643 | UsageMessage(stream, " -dsa\n"); |
| 644 | UsageMessage(stream, " (-enablesystemassertions, -disablesystemassertions)\n"); |
| 645 | UsageMessage(stream, " -Xverify:{none,remote,all}\n"); |
| 646 | UsageMessage(stream, " -Xrs\n"); |
| 647 | UsageMessage(stream, " -Xint:portable, -Xint:fast, -Xint:jit\n"); |
| 648 | UsageMessage(stream, " -Xdexopt:{none,verified,all,full}\n"); |
| 649 | UsageMessage(stream, " -Xnoquithandler\n"); |
| 650 | UsageMessage(stream, " -Xjniopts:{warnonly,forcecopy}\n"); |
| 651 | UsageMessage(stream, " -Xjnigreflimit:integervalue\n"); |
| 652 | UsageMessage(stream, " -Xgc:[no]precise\n"); |
| 653 | UsageMessage(stream, " -Xgc:[no]verifycardtable\n"); |
| 654 | UsageMessage(stream, " -X[no]genregmap\n"); |
| 655 | UsageMessage(stream, " -Xverifyopt:[no]checkmon\n"); |
| 656 | UsageMessage(stream, " -Xcheckdexsum\n"); |
| 657 | UsageMessage(stream, " -Xincludeselectedop\n"); |
| 658 | UsageMessage(stream, " -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*\n"); |
| 659 | UsageMessage(stream, " -Xincludeselectedmethod\n"); |
| 660 | UsageMessage(stream, " -Xjitthreshold:integervalue\n"); |
| 661 | UsageMessage(stream, " -Xjitcodecachesize:decimalvalueofkbytes\n"); |
| 662 | UsageMessage(stream, " -Xjitblocking\n"); |
| 663 | UsageMessage(stream, " -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\\;replace)\n"); |
| 664 | UsageMessage(stream, " -Xjitclass:classname[,classname]*\n"); |
| 665 | UsageMessage(stream, " -Xjitoffset:offset[,offset]\n"); |
| 666 | UsageMessage(stream, " -Xjitconfig:filename\n"); |
| 667 | UsageMessage(stream, " -Xjitcheckcg\n"); |
| 668 | UsageMessage(stream, " -Xjitverbose\n"); |
| 669 | UsageMessage(stream, " -Xjitprofile\n"); |
| 670 | UsageMessage(stream, " -Xjitdisableopt\n"); |
| 671 | UsageMessage(stream, " -Xjitsuspendpoll\n"); |
| 672 | UsageMessage(stream, " -XX:mainThreadStackSize=N\n"); |
| 673 | UsageMessage(stream, "\n"); |
| 674 | |
| 675 | Exit((error) ? 1 : 0); |
| 676 | } |
| 677 | |
| 678 | bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) { |
| 679 | std::string::size_type colon = s.find(c); |
| 680 | if (colon == std::string::npos) { |
| 681 | Usage("Missing char %c in option %s", c, s.c_str()); |
| 682 | return false; |
| 683 | } |
| 684 | // Add one to remove the char we were trimming until. |
| 685 | *parsed_value = s.substr(colon + 1); |
| 686 | return true; |
| 687 | } |
| 688 | |
| 689 | bool ParsedOptions::ParseInteger(const std::string& s, char after_char, int* parsed_value) { |
| 690 | std::string::size_type colon = s.find(after_char); |
| 691 | if (colon == std::string::npos) { |
| 692 | Usage("Missing char %c in option %s", after_char, s.c_str()); |
| 693 | return false; |
| 694 | } |
| 695 | const char* begin = &s[colon + 1]; |
| 696 | char* end; |
| 697 | size_t result = strtoul(begin, &end, 10); |
| 698 | if (begin == end || *end != '\0') { |
| 699 | Usage("Failed to parse integer from %s ", s.c_str()); |
| 700 | return false; |
| 701 | } |
| 702 | *parsed_value = result; |
| 703 | return true; |
| 704 | } |
| 705 | |
| 706 | bool ParsedOptions::ParseUnsignedInteger(const std::string& s, char after_char, |
| 707 | unsigned int* parsed_value) { |
| 708 | int i; |
| 709 | if (!ParseInteger(s, after_char, &i)) { |
| 710 | return false; |
| 711 | } |
| 712 | if (i < 0) { |
| 713 | Usage("Negative value %d passed for unsigned option %s", i, s.c_str()); |
| 714 | return false; |
| 715 | } |
| 716 | *parsed_value = i; |
| 717 | return true; |
| 718 | } |
| 719 | |
| 720 | bool ParsedOptions::ParseDouble(const std::string& option, char after_char, |
| 721 | double min, double max, double* parsed_value) { |
| 722 | std::string substring; |
| 723 | if (!ParseStringAfterChar(option, after_char, &substring)) { |
| 724 | return false; |
| 725 | } |
| 726 | std::istringstream iss(substring); |
| 727 | double value; |
| 728 | iss >> value; |
| 729 | // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range. |
| 730 | const bool sane_val = iss.eof() && (value >= min) && (value <= max); |
| 731 | if (!sane_val) { |
| 732 | Usage("Invalid double value %s for option %s", option.c_str()); |
| 733 | return false; |
| 734 | } |
| 735 | *parsed_value = value; |
| 736 | return true; |
| 737 | } |
| 738 | |
| 739 | } // namespace art |