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" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 18 | |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 19 | #ifdef HAVE_ANDROID_OS |
| 20 | #include "cutils/properties.h" |
| 21 | #endif |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 22 | |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 23 | #include "base/stringpiece.h" |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 24 | #include "debugger.h" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 25 | #include "gc/heap.h" |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 26 | #include "monitor.h" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 27 | #include "utils.h" |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 28 | |
| 29 | namespace art { |
| 30 | |
| 31 | ParsedOptions* ParsedOptions::Create(const Runtime::Options& options, bool ignore_unrecognized) { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 32 | std::unique_ptr<ParsedOptions> parsed(new ParsedOptions()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 33 | 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 | // |
| 53 | size_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 | |
| 105 | static 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 Yamauchi | d5307ec | 2014-03-27 21:07:51 -0700 | [diff] [blame] | 114 | } else if (option == "CC") { |
| 115 | return gc::kCollectorTypeCC; |
Mathieu Chartier | 52e4b43 | 2014-06-10 11:22:31 -0700 | [diff] [blame] | 116 | } else if (option == "MC") { |
| 117 | return gc::kCollectorTypeMC; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 118 | } else { |
| 119 | return gc::kCollectorTypeNone; |
| 120 | } |
| 121 | } |
| 122 | |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 123 | bool 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 Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 167 | bool 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 Chartier | 2f8da3e | 2014-04-15 15:37:02 -0700 | [diff] [blame] | 184 | foreground_heap_growth_multiplier_ = gc::Heap::kDefaultHeapGrowthMultiplier; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 185 | 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 Yamauchi | 1dda060 | 2014-05-12 12:32:32 -0700 | [diff] [blame] | 190 | // The default GC type is set in makefiles. |
| 191 | #if ART_DEFAULT_GC_TYPE_IS_CMS |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 192 | collector_type_ = gc::kCollectorTypeCMS; |
Hiroshi Yamauchi | 1dda060 | 2014-05-12 12:32:32 -0700 | [diff] [blame] | 193 | #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 |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 200 | // If background_collector_type_ is kCollectorTypeNone, it defaults to the collector_type_ after |
| 201 | // parsing options. |
Mathieu Chartier | a033f70 | 2014-06-17 12:01:06 -0700 | [diff] [blame] | 202 | background_collector_type_ = gc::kCollectorTypeSS; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 203 | stack_size_ = 0; // 0 means default. |
| 204 | max_spins_before_thin_lock_inflation_ = Monitor::kDefaultMaxSpinsBeforeThinLockInflation; |
| 205 | low_memory_mode_ = false; |
| 206 | use_tlab_ = false; |
| 207 | verify_pre_gc_heap_ = false; |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 208 | // Pre sweeping is the one that usually fails if the GC corrupted the heap. |
| 209 | verify_pre_sweeping_heap_ = kIsDebugBuild; |
| 210 | verify_post_gc_heap_ = false; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 211 | verify_pre_gc_rosalloc_ = kIsDebugBuild; |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 212 | verify_pre_sweeping_rosalloc_ = false; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 213 | verify_post_gc_rosalloc_ = false; |
| 214 | |
| 215 | compiler_callbacks_ = nullptr; |
| 216 | is_zygote_ = false; |
Hiroshi Yamauchi | e63a745 | 2014-02-27 14:44:36 -0800 | [diff] [blame] | 217 | if (kPoisonHeapReferences) { |
| 218 | // kPoisonHeapReferences currently works only with the interpreter only. |
| 219 | // TODO: make it work with the compiler. |
| 220 | interpreter_only_ = true; |
| 221 | } else { |
| 222 | interpreter_only_ = false; |
| 223 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 224 | is_explicit_gc_disabled_ = false; |
| 225 | |
| 226 | long_pause_log_threshold_ = gc::Heap::kDefaultLongPauseLogThreshold; |
| 227 | long_gc_log_threshold_ = gc::Heap::kDefaultLongGCLogThreshold; |
| 228 | dump_gc_performance_on_shutdown_ = false; |
| 229 | ignore_max_footprint_ = false; |
| 230 | |
| 231 | lock_profiling_threshold_ = 0; |
| 232 | hook_is_sensitive_thread_ = NULL; |
| 233 | |
| 234 | hook_vfprintf_ = vfprintf; |
| 235 | hook_exit_ = exit; |
| 236 | hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort. |
| 237 | |
| 238 | // gLogVerbosity.class_linker = true; // TODO: don't check this in! |
| 239 | // gLogVerbosity.compiler = true; // TODO: don't check this in! |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 240 | // gLogVerbosity.gc = true; // TODO: don't check this in! |
Brian Carlstrom | 4d466a8 | 2014-05-08 19:05:29 -0700 | [diff] [blame] | 241 | // gLogVerbosity.heap = true; // TODO: don't check this in! |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 242 | // gLogVerbosity.jdwp = true; // TODO: don't check this in! |
| 243 | // gLogVerbosity.jni = true; // TODO: don't check this in! |
| 244 | // gLogVerbosity.monitor = true; // TODO: don't check this in! |
Brian Carlstrom | 4d466a8 | 2014-05-08 19:05:29 -0700 | [diff] [blame] | 245 | // gLogVerbosity.profiler = true; // TODO: don't check this in! |
| 246 | // gLogVerbosity.signals = true; // TODO: don't check this in! |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 247 | // gLogVerbosity.startup = true; // TODO: don't check this in! |
| 248 | // gLogVerbosity.third_party_jni = true; // TODO: don't check this in! |
| 249 | // gLogVerbosity.threads = true; // TODO: don't check this in! |
Brian Carlstrom | 4d466a8 | 2014-05-08 19:05:29 -0700 | [diff] [blame] | 250 | // gLogVerbosity.verifier = true; // TODO: don't check this in! |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 251 | |
| 252 | method_trace_ = false; |
| 253 | method_trace_file_ = "/data/method-trace-file.bin"; |
| 254 | method_trace_file_size_ = 10 * MB; |
| 255 | |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 256 | profile_clock_source_ = kDefaultProfilerClockSource; |
| 257 | |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 258 | verify_ = true; |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 259 | image_isa_ = kRuntimeISA; |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 260 | |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 261 | // Default to explicit checks. Switch off with -implicit-checks:. |
| 262 | // or setprop dalvik.vm.implicit_checks check1,check2,... |
| 263 | #ifdef HAVE_ANDROID_OS |
| 264 | { |
| 265 | char buf[PROP_VALUE_MAX]; |
Dave Allison | c0cf944 | 2014-05-30 11:25:06 -0700 | [diff] [blame] | 266 | property_get("dalvik.vm.implicit_checks", buf, "null,stack"); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 267 | std::string checks(buf); |
| 268 | std::vector<std::string> checkvec; |
| 269 | Split(checks, ',', checkvec); |
Dave Allison | dd2e825 | 2014-03-20 14:45:17 -0700 | [diff] [blame] | 270 | explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck | |
| 271 | kExplicitStackOverflowCheck; |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 272 | for (auto& str : checkvec) { |
| 273 | std::string val = Trim(str); |
| 274 | if (val == "none") { |
| 275 | explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck | |
Dave Allison | dd2e825 | 2014-03-20 14:45:17 -0700 | [diff] [blame] | 276 | kExplicitStackOverflowCheck; |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 277 | } else if (val == "null") { |
| 278 | explicit_checks_ &= ~kExplicitNullCheck; |
| 279 | } else if (val == "suspend") { |
| 280 | explicit_checks_ &= ~kExplicitSuspendCheck; |
| 281 | } else if (val == "stack") { |
| 282 | explicit_checks_ &= ~kExplicitStackOverflowCheck; |
| 283 | } else if (val == "all") { |
| 284 | explicit_checks_ = 0; |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | #else |
| 289 | explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck | |
| 290 | kExplicitStackOverflowCheck; |
| 291 | #endif |
| 292 | |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 293 | for (size_t i = 0; i < options.size(); ++i) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 294 | if (true && options[0].first == "-Xzygote") { |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 295 | LOG(INFO) << "option[" << i << "]=" << options[i].first; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 296 | } |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 297 | } |
| 298 | for (size_t i = 0; i < options.size(); ++i) { |
| 299 | const std::string option(options[i].first); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 300 | if (StartsWith(option, "-help")) { |
| 301 | Usage(nullptr); |
| 302 | return false; |
| 303 | } else if (StartsWith(option, "-showversion")) { |
| 304 | UsageMessage(stdout, "ART version %s\n", Runtime::GetVersion()); |
| 305 | Exit(0); |
| 306 | } else if (StartsWith(option, "-Xbootclasspath:")) { |
| 307 | boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data(); |
| 308 | } else if (option == "-classpath" || option == "-cp") { |
| 309 | // TODO: support -Djava.class.path |
| 310 | i++; |
| 311 | if (i == options.size()) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 312 | Usage("Missing required class path value for %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 313 | return false; |
| 314 | } |
| 315 | const StringPiece& value = options[i].first; |
| 316 | class_path_string_ = value.data(); |
| 317 | } else if (option == "bootclasspath") { |
| 318 | boot_class_path_ |
| 319 | = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second); |
| 320 | } else if (StartsWith(option, "-Ximage:")) { |
| 321 | if (!ParseStringAfterChar(option, ':', &image_)) { |
| 322 | return false; |
| 323 | } |
| 324 | } else if (StartsWith(option, "-Xcheck:jni")) { |
| 325 | check_jni_ = true; |
| 326 | } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) { |
| 327 | std::string tail(option.substr(option[1] == 'X' ? 10 : 15)); |
| 328 | // TODO: move parsing logic out of Dbg |
| 329 | if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) { |
| 330 | if (tail != "help") { |
| 331 | UsageMessage(stderr, "Failed to parse JDWP option %s\n", tail.c_str()); |
| 332 | } |
| 333 | Usage("Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n" |
| 334 | "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n\n"); |
| 335 | return false; |
| 336 | } |
| 337 | } else if (StartsWith(option, "-Xms")) { |
| 338 | size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024); |
| 339 | if (size == 0) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 340 | Usage("Failed to parse memory option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 341 | return false; |
| 342 | } |
| 343 | heap_initial_size_ = size; |
| 344 | } else if (StartsWith(option, "-Xmx")) { |
| 345 | size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024); |
| 346 | if (size == 0) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 347 | Usage("Failed to parse memory option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 348 | return false; |
| 349 | } |
| 350 | heap_maximum_size_ = size; |
| 351 | } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) { |
| 352 | size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024); |
| 353 | if (size == 0) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 354 | Usage("Failed to parse memory option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 355 | return false; |
| 356 | } |
| 357 | heap_growth_limit_ = size; |
| 358 | } else if (StartsWith(option, "-XX:HeapMinFree=")) { |
| 359 | size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024); |
| 360 | if (size == 0) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 361 | Usage("Failed to parse memory option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 362 | return false; |
| 363 | } |
| 364 | heap_min_free_ = size; |
| 365 | } else if (StartsWith(option, "-XX:HeapMaxFree=")) { |
| 366 | size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024); |
| 367 | if (size == 0) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 368 | Usage("Failed to parse memory option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 369 | return false; |
| 370 | } |
| 371 | heap_max_free_ = size; |
| 372 | } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) { |
| 373 | if (!ParseDouble(option, '=', 0.1, 0.9, &heap_target_utilization_)) { |
| 374 | return false; |
| 375 | } |
Mathieu Chartier | 2f8da3e | 2014-04-15 15:37:02 -0700 | [diff] [blame] | 376 | } else if (StartsWith(option, "-XX:ForegroundHeapGrowthMultiplier=")) { |
Mathieu Chartier | 455820e | 2014-04-18 12:02:39 -0700 | [diff] [blame] | 377 | if (!ParseDouble(option, '=', 0.1, 10.0, &foreground_heap_growth_multiplier_)) { |
Mathieu Chartier | 2f8da3e | 2014-04-15 15:37:02 -0700 | [diff] [blame] | 378 | return false; |
| 379 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 380 | } else if (StartsWith(option, "-XX:ParallelGCThreads=")) { |
| 381 | if (!ParseUnsignedInteger(option, '=', ¶llel_gc_threads_)) { |
| 382 | return false; |
| 383 | } |
| 384 | } else if (StartsWith(option, "-XX:ConcGCThreads=")) { |
| 385 | if (!ParseUnsignedInteger(option, '=', &conc_gc_threads_)) { |
| 386 | return false; |
| 387 | } |
| 388 | } else if (StartsWith(option, "-Xss")) { |
| 389 | size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1); |
| 390 | if (size == 0) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 391 | Usage("Failed to parse memory option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 392 | return false; |
| 393 | } |
| 394 | stack_size_ = size; |
| 395 | } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) { |
| 396 | if (!ParseUnsignedInteger(option, '=', &max_spins_before_thin_lock_inflation_)) { |
| 397 | return false; |
| 398 | } |
| 399 | } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) { |
Andreas Gampe | 39d9218 | 2014-03-05 16:46:44 -0800 | [diff] [blame] | 400 | unsigned int value; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 401 | if (!ParseUnsignedInteger(option, '=', &value)) { |
| 402 | return false; |
| 403 | } |
| 404 | long_pause_log_threshold_ = MsToNs(value); |
| 405 | } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) { |
Andreas Gampe | 39d9218 | 2014-03-05 16:46:44 -0800 | [diff] [blame] | 406 | unsigned int value; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 407 | if (!ParseUnsignedInteger(option, '=', &value)) { |
| 408 | return false; |
| 409 | } |
| 410 | long_gc_log_threshold_ = MsToNs(value); |
| 411 | } else if (option == "-XX:DumpGCPerformanceOnShutdown") { |
| 412 | dump_gc_performance_on_shutdown_ = true; |
| 413 | } else if (option == "-XX:IgnoreMaxFootprint") { |
| 414 | ignore_max_footprint_ = true; |
| 415 | } else if (option == "-XX:LowMemoryMode") { |
| 416 | low_memory_mode_ = true; |
| 417 | } else if (option == "-XX:UseTLAB") { |
| 418 | use_tlab_ = true; |
| 419 | } 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 Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 426 | } else if (option == "imageinstructionset") { |
| 427 | image_isa_ = GetInstructionSetFromString( |
| 428 | reinterpret_cast<const char*>(options[i].second)); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 429 | } else if (option == "-Xzygote") { |
| 430 | is_zygote_ = true; |
| 431 | } else if (option == "-Xint") { |
| 432 | interpreter_only_ = true; |
| 433 | } else if (StartsWith(option, "-Xgc:")) { |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 434 | if (!ParseXGcOption(option)) { |
| 435 | return false; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 436 | } |
| 437 | } else if (StartsWith(option, "-XX:BackgroundGC=")) { |
| 438 | std::string substring; |
| 439 | if (!ParseStringAfterChar(option, '=', &substring)) { |
| 440 | return false; |
| 441 | } |
| 442 | gc::CollectorType collector_type = ParseCollectorType(substring); |
| 443 | if (collector_type != gc::kCollectorTypeNone) { |
| 444 | background_collector_type_ = collector_type; |
| 445 | } else { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 446 | Usage("Unknown -XX:BackgroundGC option %s\n", substring.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 447 | return false; |
| 448 | } |
| 449 | } else if (option == "-XX:+DisableExplicitGC") { |
| 450 | is_explicit_gc_disabled_ = true; |
| 451 | } else if (StartsWith(option, "-verbose:")) { |
| 452 | std::vector<std::string> verbose_options; |
| 453 | Split(option.substr(strlen("-verbose:")), ',', verbose_options); |
| 454 | for (size_t i = 0; i < verbose_options.size(); ++i) { |
| 455 | if (verbose_options[i] == "class") { |
| 456 | gLogVerbosity.class_linker = true; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 457 | } else if (verbose_options[i] == "compiler") { |
| 458 | gLogVerbosity.compiler = true; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 459 | } else if (verbose_options[i] == "gc") { |
| 460 | gLogVerbosity.gc = true; |
Brian Carlstrom | 4d466a8 | 2014-05-08 19:05:29 -0700 | [diff] [blame] | 461 | } else if (verbose_options[i] == "heap") { |
| 462 | gLogVerbosity.heap = true; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 463 | } else if (verbose_options[i] == "jdwp") { |
| 464 | gLogVerbosity.jdwp = true; |
| 465 | } else if (verbose_options[i] == "jni") { |
| 466 | gLogVerbosity.jni = true; |
| 467 | } else if (verbose_options[i] == "monitor") { |
| 468 | gLogVerbosity.monitor = true; |
Brian Carlstrom | 4d466a8 | 2014-05-08 19:05:29 -0700 | [diff] [blame] | 469 | } else if (verbose_options[i] == "profiler") { |
| 470 | gLogVerbosity.profiler = true; |
| 471 | } else if (verbose_options[i] == "signals") { |
| 472 | gLogVerbosity.signals = true; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 473 | } else if (verbose_options[i] == "startup") { |
| 474 | gLogVerbosity.startup = true; |
| 475 | } else if (verbose_options[i] == "third-party-jni") { |
| 476 | gLogVerbosity.third_party_jni = true; |
| 477 | } else if (verbose_options[i] == "threads") { |
| 478 | gLogVerbosity.threads = true; |
Brian Carlstrom | 4d466a8 | 2014-05-08 19:05:29 -0700 | [diff] [blame] | 479 | } else if (verbose_options[i] == "verifier") { |
| 480 | gLogVerbosity.verifier = true; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 481 | } else { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 482 | Usage("Unknown -verbose option %s\n", verbose_options[i].c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 483 | return false; |
| 484 | } |
| 485 | } |
Mingyao Yang | 42d65c5 | 2014-04-18 16:49:39 -0700 | [diff] [blame] | 486 | } else if (StartsWith(option, "-verbose-methods:")) { |
| 487 | gLogVerbosity.compiler = false; |
| 488 | Split(option.substr(strlen("-verbose-methods:")), ',', gVerboseMethods); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 489 | } else if (StartsWith(option, "-Xlockprofthreshold:")) { |
| 490 | if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) { |
| 491 | return false; |
| 492 | } |
| 493 | } else if (StartsWith(option, "-Xstacktracefile:")) { |
| 494 | if (!ParseStringAfterChar(option, ':', &stack_trace_file_)) { |
| 495 | return false; |
| 496 | } |
| 497 | } else if (option == "sensitiveThread") { |
| 498 | const void* hook = options[i].second; |
| 499 | hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(hook)); |
| 500 | } else if (option == "vfprintf") { |
| 501 | const void* hook = options[i].second; |
| 502 | if (hook == nullptr) { |
| 503 | Usage("vfprintf argument was NULL"); |
| 504 | return false; |
| 505 | } |
| 506 | hook_vfprintf_ = |
| 507 | reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook)); |
| 508 | } else if (option == "exit") { |
| 509 | const void* hook = options[i].second; |
| 510 | if (hook == nullptr) { |
| 511 | Usage("exit argument was NULL"); |
| 512 | return false; |
| 513 | } |
| 514 | hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook)); |
| 515 | } else if (option == "abort") { |
| 516 | const void* hook = options[i].second; |
| 517 | if (hook == nullptr) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 518 | Usage("abort was NULL\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 519 | return false; |
| 520 | } |
| 521 | hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook)); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 522 | } else if (option == "-Xmethod-trace") { |
| 523 | method_trace_ = true; |
| 524 | } else if (StartsWith(option, "-Xmethod-trace-file:")) { |
| 525 | method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:")); |
| 526 | } else if (StartsWith(option, "-Xmethod-trace-file-size:")) { |
| 527 | if (!ParseUnsignedInteger(option, ':', &method_trace_file_size_)) { |
| 528 | return false; |
| 529 | } |
| 530 | } else if (option == "-Xprofile:threadcpuclock") { |
| 531 | Trace::SetDefaultClockSource(kProfilerClockSourceThreadCpu); |
| 532 | } else if (option == "-Xprofile:wallclock") { |
| 533 | Trace::SetDefaultClockSource(kProfilerClockSourceWall); |
| 534 | } else if (option == "-Xprofile:dualclock") { |
| 535 | Trace::SetDefaultClockSource(kProfilerClockSourceDual); |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 536 | } else if (option == "-Xenable-profiler") { |
| 537 | profiler_options_.enabled_ = true; |
Wei Jin | 2221e3b | 2014-05-21 18:35:19 -0700 | [diff] [blame] | 538 | } else if (StartsWith(option, "-Xprofile-filename:")) { |
Ian Rogers | f7fd3cb | 2014-05-19 22:57:34 -0700 | [diff] [blame] | 539 | if (!ParseStringAfterChar(option, ':', &profile_output_filename_)) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 540 | return false; |
| 541 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 542 | } else if (StartsWith(option, "-Xprofile-period:")) { |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 543 | if (!ParseUnsignedInteger(option, ':', &profiler_options_.period_s_)) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 544 | return false; |
| 545 | } |
| 546 | } else if (StartsWith(option, "-Xprofile-duration:")) { |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 547 | if (!ParseUnsignedInteger(option, ':', &profiler_options_.duration_s_)) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 548 | return false; |
| 549 | } |
| 550 | } else if (StartsWith(option, "-Xprofile-interval:")) { |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 551 | if (!ParseUnsignedInteger(option, ':', &profiler_options_.interval_us_)) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 552 | return false; |
| 553 | } |
| 554 | } else if (StartsWith(option, "-Xprofile-backoff:")) { |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 555 | if (!ParseDouble(option, ':', 1.0, 10.0, &profiler_options_.backoff_coefficient_)) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 556 | return false; |
| 557 | } |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 558 | } else if (option == "-Xprofile-start-immediately") { |
| 559 | profiler_options_.start_immediately_ = true; |
| 560 | } else if (StartsWith(option, "-Xprofile-top-k-threshold:")) { |
Calin Juravle | c321c9b | 2014-06-11 19:04:35 +0100 | [diff] [blame] | 561 | if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_threshold_)) { |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 562 | return false; |
| 563 | } |
| 564 | } else if (StartsWith(option, "-Xprofile-top-k-change-threshold:")) { |
Calin Juravle | c321c9b | 2014-06-11 19:04:35 +0100 | [diff] [blame] | 565 | if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_change_threshold_)) { |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 566 | return false; |
| 567 | } |
Wei Jin | a93b0bb | 2014-06-09 16:19:15 -0700 | [diff] [blame] | 568 | } else if (option == "-Xprofile-type:method") { |
| 569 | profiler_options_.profile_type_ = kProfilerMethod; |
Wei Jin | 445220d | 2014-06-20 15:56:53 -0700 | [diff] [blame] | 570 | } else if (option == "-Xprofile-type:stack") { |
| 571 | profiler_options_.profile_type_ = kProfilerBoundedStack; |
| 572 | } else if (StartsWith(option, "-Xprofile-max-stack-depth:")) { |
| 573 | if (!ParseUnsignedInteger(option, ':', &profiler_options_.max_stack_depth_)) { |
| 574 | return false; |
| 575 | } |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 576 | } else if (StartsWith(option, "-implicit-checks:")) { |
| 577 | std::string checks; |
| 578 | if (!ParseStringAfterChar(option, ':', &checks)) { |
| 579 | return false; |
| 580 | } |
| 581 | std::vector<std::string> checkvec; |
| 582 | Split(checks, ',', checkvec); |
| 583 | for (auto& str : checkvec) { |
| 584 | std::string val = Trim(str); |
| 585 | if (val == "none") { |
| 586 | explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck | |
| 587 | kExplicitStackOverflowCheck; |
| 588 | } else if (val == "null") { |
| 589 | explicit_checks_ &= ~kExplicitNullCheck; |
| 590 | } else if (val == "suspend") { |
| 591 | explicit_checks_ &= ~kExplicitSuspendCheck; |
| 592 | } else if (val == "stack") { |
| 593 | explicit_checks_ &= ~kExplicitStackOverflowCheck; |
| 594 | } else if (val == "all") { |
| 595 | explicit_checks_ = 0; |
| 596 | } else { |
| 597 | return false; |
| 598 | } |
| 599 | } |
| 600 | } else if (StartsWith(option, "-explicit-checks:")) { |
| 601 | std::string checks; |
| 602 | if (!ParseStringAfterChar(option, ':', &checks)) { |
| 603 | return false; |
| 604 | } |
| 605 | std::vector<std::string> checkvec; |
| 606 | Split(checks, ',', checkvec); |
| 607 | for (auto& str : checkvec) { |
| 608 | std::string val = Trim(str); |
| 609 | if (val == "none") { |
| 610 | explicit_checks_ = 0; |
| 611 | } else if (val == "null") { |
| 612 | explicit_checks_ |= kExplicitNullCheck; |
| 613 | } else if (val == "suspend") { |
| 614 | explicit_checks_ |= kExplicitSuspendCheck; |
| 615 | } else if (val == "stack") { |
| 616 | explicit_checks_ |= kExplicitStackOverflowCheck; |
| 617 | } else if (val == "all") { |
| 618 | explicit_checks_ = kExplicitNullCheck | kExplicitSuspendCheck | |
| 619 | kExplicitStackOverflowCheck; |
| 620 | } else { |
| 621 | return false; |
| 622 | } |
| 623 | } |
Tsu Chiang Chuang | 12e6d74 | 2014-05-22 10:22:25 -0700 | [diff] [blame] | 624 | } else if (StartsWith(option, "-Xcompiler:")) { |
| 625 | if (!ParseStringAfterChar(option, ':', &compiler_executable_)) { |
| 626 | return false; |
| 627 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 628 | } else if (option == "-Xcompiler-option") { |
| 629 | i++; |
| 630 | if (i == options.size()) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 631 | Usage("Missing required compiler option for %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 632 | return false; |
| 633 | } |
| 634 | compiler_options_.push_back(options[i].first); |
| 635 | } else if (option == "-Ximage-compiler-option") { |
| 636 | i++; |
| 637 | if (i == options.size()) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 638 | Usage("Missing required compiler option for %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 639 | return false; |
| 640 | } |
| 641 | image_compiler_options_.push_back(options[i].first); |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 642 | } else if (StartsWith(option, "-Xverify:")) { |
| 643 | std::string verify_mode = option.substr(strlen("-Xverify:")); |
| 644 | if (verify_mode == "none") { |
| 645 | verify_ = false; |
| 646 | } else if (verify_mode == "remote" || verify_mode == "all") { |
| 647 | verify_ = true; |
| 648 | } else { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 649 | Usage("Unknown -Xverify option %s\n", verify_mode.c_str()); |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 650 | return false; |
| 651 | } |
Yevgeny Rouban | a6119a2 | 2014-03-24 11:31:24 +0700 | [diff] [blame] | 652 | } else if (StartsWith(option, "-ea") || |
| 653 | StartsWith(option, "-da") || |
| 654 | StartsWith(option, "-enableassertions") || |
| 655 | StartsWith(option, "-disableassertions") || |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 656 | (option == "--runtime-arg") || |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 657 | (option == "-esa") || |
| 658 | (option == "-dsa") || |
| 659 | (option == "-enablesystemassertions") || |
| 660 | (option == "-disablesystemassertions") || |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 661 | (option == "-Xrs") || |
| 662 | StartsWith(option, "-Xint:") || |
| 663 | StartsWith(option, "-Xdexopt:") || |
| 664 | (option == "-Xnoquithandler") || |
| 665 | StartsWith(option, "-Xjniopts:") || |
| 666 | StartsWith(option, "-Xjnigreflimit:") || |
| 667 | (option == "-Xgenregmap") || |
| 668 | (option == "-Xnogenregmap") || |
| 669 | StartsWith(option, "-Xverifyopt:") || |
| 670 | (option == "-Xcheckdexsum") || |
| 671 | (option == "-Xincludeselectedop") || |
| 672 | StartsWith(option, "-Xjitop:") || |
| 673 | (option == "-Xincludeselectedmethod") || |
| 674 | StartsWith(option, "-Xjitthreshold:") || |
| 675 | StartsWith(option, "-Xjitcodecachesize:") || |
| 676 | (option == "-Xjitblocking") || |
| 677 | StartsWith(option, "-Xjitmethod:") || |
| 678 | StartsWith(option, "-Xjitclass:") || |
| 679 | StartsWith(option, "-Xjitoffset:") || |
| 680 | StartsWith(option, "-Xjitconfig:") || |
| 681 | (option == "-Xjitcheckcg") || |
| 682 | (option == "-Xjitverbose") || |
| 683 | (option == "-Xjitprofile") || |
| 684 | (option == "-Xjitdisableopt") || |
| 685 | (option == "-Xjitsuspendpoll") || |
| 686 | StartsWith(option, "-XX:mainThreadStackSize=")) { |
| 687 | // Ignored for backwards compatibility. |
| 688 | } else if (!ignore_unrecognized) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 689 | Usage("Unrecognized option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 690 | return false; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | // If a reference to the dalvik core.jar snuck in, replace it with |
| 695 | // the art specific version. This can happen with on device |
| 696 | // boot.art/boot.oat generation by GenerateImage which relies on the |
| 697 | // value of BOOTCLASSPATH. |
Kenny Root | d518534 | 2014-05-13 14:47:05 -0700 | [diff] [blame] | 698 | #if defined(ART_TARGET) |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 699 | std::string core_jar("/core.jar"); |
Kenny Root | d518534 | 2014-05-13 14:47:05 -0700 | [diff] [blame] | 700 | std::string core_libart_jar("/core-libart.jar"); |
| 701 | #else |
| 702 | // The host uses hostdex files. |
| 703 | std::string core_jar("/core-hostdex.jar"); |
| 704 | std::string core_libart_jar("/core-libart-hostdex.jar"); |
| 705 | #endif |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 706 | size_t core_jar_pos = boot_class_path_string_.find(core_jar); |
| 707 | if (core_jar_pos != std::string::npos) { |
Kenny Root | d518534 | 2014-05-13 14:47:05 -0700 | [diff] [blame] | 708 | boot_class_path_string_.replace(core_jar_pos, core_jar.size(), core_libart_jar); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | if (compiler_callbacks_ == nullptr && image_.empty()) { |
| 712 | image_ += GetAndroidRoot(); |
Brian Carlstrom | 3ac05bb | 2014-05-13 19:31:38 -0700 | [diff] [blame] | 713 | image_ += "/framework/boot.art"; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 714 | } |
| 715 | if (heap_growth_limit_ == 0) { |
| 716 | heap_growth_limit_ = heap_maximum_size_; |
| 717 | } |
| 718 | if (background_collector_type_ == gc::kCollectorTypeNone) { |
| 719 | background_collector_type_ = collector_type_; |
| 720 | } |
| 721 | return true; |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 722 | } // NOLINT(readability/fn_size) |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 723 | |
| 724 | void ParsedOptions::Exit(int status) { |
| 725 | hook_exit_(status); |
| 726 | } |
| 727 | |
| 728 | void ParsedOptions::Abort() { |
| 729 | hook_abort_(); |
| 730 | } |
| 731 | |
| 732 | void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) { |
| 733 | hook_vfprintf_(stderr, fmt, ap); |
| 734 | } |
| 735 | |
| 736 | void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) { |
| 737 | va_list ap; |
| 738 | va_start(ap, fmt); |
| 739 | UsageMessageV(stream, fmt, ap); |
| 740 | va_end(ap); |
| 741 | } |
| 742 | |
| 743 | void ParsedOptions::Usage(const char* fmt, ...) { |
| 744 | bool error = (fmt != nullptr); |
| 745 | FILE* stream = error ? stderr : stdout; |
| 746 | |
| 747 | if (fmt != nullptr) { |
| 748 | va_list ap; |
| 749 | va_start(ap, fmt); |
| 750 | UsageMessageV(stream, fmt, ap); |
| 751 | va_end(ap); |
| 752 | } |
| 753 | |
| 754 | const char* program = "dalvikvm"; |
| 755 | UsageMessage(stream, "%s: [options] class [argument ...]\n", program); |
| 756 | UsageMessage(stream, "\n"); |
| 757 | UsageMessage(stream, "The following standard options are supported:\n"); |
| 758 | UsageMessage(stream, " -classpath classpath (-cp classpath)\n"); |
| 759 | UsageMessage(stream, " -Dproperty=value\n"); |
| 760 | UsageMessage(stream, " -verbose:tag ('gc', 'jni', or 'class')\n"); |
| 761 | UsageMessage(stream, " -showversion\n"); |
| 762 | UsageMessage(stream, " -help\n"); |
| 763 | UsageMessage(stream, " -agentlib:jdwp=options\n"); |
| 764 | UsageMessage(stream, "\n"); |
| 765 | |
| 766 | UsageMessage(stream, "The following extended options are supported:\n"); |
| 767 | UsageMessage(stream, " -Xrunjdwp:<options>\n"); |
| 768 | UsageMessage(stream, " -Xbootclasspath:bootclasspath\n"); |
| 769 | UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n"); |
| 770 | UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n"); |
| 771 | UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n"); |
| 772 | UsageMessage(stream, " -XssN (stack size)\n"); |
| 773 | UsageMessage(stream, " -Xint\n"); |
| 774 | UsageMessage(stream, "\n"); |
| 775 | |
| 776 | UsageMessage(stream, "The following Dalvik options are supported:\n"); |
| 777 | UsageMessage(stream, " -Xzygote\n"); |
| 778 | UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n"); |
| 779 | UsageMessage(stream, " -Xstacktracefile:<filename>\n"); |
| 780 | UsageMessage(stream, " -Xgc:[no]preverify\n"); |
| 781 | UsageMessage(stream, " -Xgc:[no]postverify\n"); |
| 782 | UsageMessage(stream, " -XX:+DisableExplicitGC\n"); |
| 783 | UsageMessage(stream, " -XX:HeapGrowthLimit=N\n"); |
| 784 | UsageMessage(stream, " -XX:HeapMinFree=N\n"); |
| 785 | UsageMessage(stream, " -XX:HeapMaxFree=N\n"); |
| 786 | UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n"); |
Mathieu Chartier | 455820e | 2014-04-18 12:02:39 -0700 | [diff] [blame] | 787 | UsageMessage(stream, " -XX:ForegroundHeapGrowthMultiplier=doublevalue\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 788 | UsageMessage(stream, " -XX:LowMemoryMode\n"); |
| 789 | UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n"); |
| 790 | UsageMessage(stream, "\n"); |
| 791 | |
| 792 | UsageMessage(stream, "The following unique to ART options are supported:\n"); |
| 793 | UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n"); |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 794 | UsageMessage(stream, " -Xgc:[no]postsweepingverify_rosalloc\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 795 | UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n"); |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 796 | UsageMessage(stream, " -Xgc:[no]presweepingverify\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 797 | UsageMessage(stream, " -Ximage:filename\n"); |
| 798 | UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n"); |
| 799 | UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n"); |
| 800 | UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n"); |
| 801 | UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n"); |
| 802 | UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n"); |
| 803 | UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n"); |
| 804 | UsageMessage(stream, " -XX:IgnoreMaxFootprint\n"); |
| 805 | UsageMessage(stream, " -XX:UseTLAB\n"); |
| 806 | UsageMessage(stream, " -XX:BackgroundGC=none\n"); |
| 807 | UsageMessage(stream, " -Xmethod-trace\n"); |
| 808 | UsageMessage(stream, " -Xmethod-trace-file:filename"); |
| 809 | UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n"); |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 810 | UsageMessage(stream, " -Xenable-profiler\n"); |
Wei Jin | 2221e3b | 2014-05-21 18:35:19 -0700 | [diff] [blame] | 811 | UsageMessage(stream, " -Xprofile-filename:filename\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 812 | UsageMessage(stream, " -Xprofile-period:integervalue\n"); |
| 813 | UsageMessage(stream, " -Xprofile-duration:integervalue\n"); |
| 814 | UsageMessage(stream, " -Xprofile-interval:integervalue\n"); |
Calin Juravle | 54c73ca | 2014-05-22 12:13:54 +0100 | [diff] [blame] | 815 | UsageMessage(stream, " -Xprofile-backoff:doublevalue\n"); |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 816 | UsageMessage(stream, " -Xprofile-start-immediately\n"); |
| 817 | UsageMessage(stream, " -Xprofile-top-k-threshold:doublevalue\n"); |
| 818 | UsageMessage(stream, " -Xprofile-top-k-change-threshold:doublevalue\n"); |
Wei Jin | 445220d | 2014-06-20 15:56:53 -0700 | [diff] [blame] | 819 | UsageMessage(stream, " -Xprofile-type:{method,stack}\n"); |
| 820 | UsageMessage(stream, " -Xprofile-max-stack-depth:integervalue\n"); |
Tsu Chiang Chuang | 12e6d74 | 2014-05-22 10:22:25 -0700 | [diff] [blame] | 821 | UsageMessage(stream, " -Xcompiler:filename\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 822 | UsageMessage(stream, " -Xcompiler-option dex2oat-option\n"); |
| 823 | UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n"); |
| 824 | UsageMessage(stream, "\n"); |
| 825 | |
| 826 | UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n"); |
| 827 | UsageMessage(stream, " -ea[:<package name>... |:<class name>]\n"); |
| 828 | UsageMessage(stream, " -da[:<package name>... |:<class name>]\n"); |
| 829 | UsageMessage(stream, " (-enableassertions, -disableassertions)\n"); |
| 830 | UsageMessage(stream, " -esa\n"); |
| 831 | UsageMessage(stream, " -dsa\n"); |
| 832 | UsageMessage(stream, " (-enablesystemassertions, -disablesystemassertions)\n"); |
| 833 | UsageMessage(stream, " -Xverify:{none,remote,all}\n"); |
| 834 | UsageMessage(stream, " -Xrs\n"); |
| 835 | UsageMessage(stream, " -Xint:portable, -Xint:fast, -Xint:jit\n"); |
| 836 | UsageMessage(stream, " -Xdexopt:{none,verified,all,full}\n"); |
| 837 | UsageMessage(stream, " -Xnoquithandler\n"); |
| 838 | UsageMessage(stream, " -Xjniopts:{warnonly,forcecopy}\n"); |
| 839 | UsageMessage(stream, " -Xjnigreflimit:integervalue\n"); |
| 840 | UsageMessage(stream, " -Xgc:[no]precise\n"); |
| 841 | UsageMessage(stream, " -Xgc:[no]verifycardtable\n"); |
| 842 | UsageMessage(stream, " -X[no]genregmap\n"); |
| 843 | UsageMessage(stream, " -Xverifyopt:[no]checkmon\n"); |
| 844 | UsageMessage(stream, " -Xcheckdexsum\n"); |
| 845 | UsageMessage(stream, " -Xincludeselectedop\n"); |
| 846 | UsageMessage(stream, " -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*\n"); |
| 847 | UsageMessage(stream, " -Xincludeselectedmethod\n"); |
| 848 | UsageMessage(stream, " -Xjitthreshold:integervalue\n"); |
| 849 | UsageMessage(stream, " -Xjitcodecachesize:decimalvalueofkbytes\n"); |
| 850 | UsageMessage(stream, " -Xjitblocking\n"); |
| 851 | UsageMessage(stream, " -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\\;replace)\n"); |
| 852 | UsageMessage(stream, " -Xjitclass:classname[,classname]*\n"); |
| 853 | UsageMessage(stream, " -Xjitoffset:offset[,offset]\n"); |
| 854 | UsageMessage(stream, " -Xjitconfig:filename\n"); |
| 855 | UsageMessage(stream, " -Xjitcheckcg\n"); |
| 856 | UsageMessage(stream, " -Xjitverbose\n"); |
| 857 | UsageMessage(stream, " -Xjitprofile\n"); |
| 858 | UsageMessage(stream, " -Xjitdisableopt\n"); |
| 859 | UsageMessage(stream, " -Xjitsuspendpoll\n"); |
| 860 | UsageMessage(stream, " -XX:mainThreadStackSize=N\n"); |
| 861 | UsageMessage(stream, "\n"); |
| 862 | |
| 863 | Exit((error) ? 1 : 0); |
| 864 | } |
| 865 | |
| 866 | bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) { |
| 867 | std::string::size_type colon = s.find(c); |
| 868 | if (colon == std::string::npos) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 869 | Usage("Missing char %c in option %s\n", c, s.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 870 | return false; |
| 871 | } |
| 872 | // Add one to remove the char we were trimming until. |
| 873 | *parsed_value = s.substr(colon + 1); |
| 874 | return true; |
| 875 | } |
| 876 | |
| 877 | bool ParsedOptions::ParseInteger(const std::string& s, char after_char, int* parsed_value) { |
| 878 | std::string::size_type colon = s.find(after_char); |
| 879 | if (colon == std::string::npos) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 880 | Usage("Missing char %c in option %s\n", after_char, s.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 881 | return false; |
| 882 | } |
| 883 | const char* begin = &s[colon + 1]; |
| 884 | char* end; |
| 885 | size_t result = strtoul(begin, &end, 10); |
| 886 | if (begin == end || *end != '\0') { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 887 | Usage("Failed to parse integer from %s\n", s.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 888 | return false; |
| 889 | } |
| 890 | *parsed_value = result; |
| 891 | return true; |
| 892 | } |
| 893 | |
| 894 | bool ParsedOptions::ParseUnsignedInteger(const std::string& s, char after_char, |
| 895 | unsigned int* parsed_value) { |
| 896 | int i; |
| 897 | if (!ParseInteger(s, after_char, &i)) { |
| 898 | return false; |
| 899 | } |
| 900 | if (i < 0) { |
Mathieu Chartier | 455820e | 2014-04-18 12:02:39 -0700 | [diff] [blame] | 901 | Usage("Negative value %d passed for unsigned option %s\n", i, s.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 902 | return false; |
| 903 | } |
| 904 | *parsed_value = i; |
| 905 | return true; |
| 906 | } |
| 907 | |
| 908 | bool ParsedOptions::ParseDouble(const std::string& option, char after_char, |
| 909 | double min, double max, double* parsed_value) { |
| 910 | std::string substring; |
| 911 | if (!ParseStringAfterChar(option, after_char, &substring)) { |
| 912 | return false; |
| 913 | } |
Dave Allison | 999385c | 2014-05-20 15:16:02 -0700 | [diff] [blame] | 914 | bool sane_val = true; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 915 | double value; |
Dave Allison | 999385c | 2014-05-20 15:16:02 -0700 | [diff] [blame] | 916 | if (false) { |
| 917 | // TODO: this doesn't seem to work on the emulator. b/15114595 |
| 918 | std::stringstream iss(substring); |
| 919 | iss >> value; |
| 920 | // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range. |
| 921 | sane_val = iss.eof() && (value >= min) && (value <= max); |
| 922 | } else { |
| 923 | char* end = nullptr; |
| 924 | value = strtod(substring.c_str(), &end); |
| 925 | sane_val = *end == '\0' && value >= min && value <= max; |
| 926 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 927 | if (!sane_val) { |
Mathieu Chartier | 455820e | 2014-04-18 12:02:39 -0700 | [diff] [blame] | 928 | Usage("Invalid double value %s for option %s\n", substring.c_str(), option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 929 | return false; |
| 930 | } |
| 931 | *parsed_value = value; |
| 932 | return true; |
| 933 | } |
| 934 | |
| 935 | } // namespace art |