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 | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 27 | #include "runtime.h" |
| 28 | #include "trace.h" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 29 | #include "utils.h" |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 30 | |
| 31 | namespace art { |
| 32 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 33 | ParsedOptions* ParsedOptions::Create(const RuntimeOptions& options, bool ignore_unrecognized) { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 34 | std::unique_ptr<ParsedOptions> parsed(new ParsedOptions()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 35 | if (parsed->Parse(options, ignore_unrecognized)) { |
| 36 | return parsed.release(); |
| 37 | } |
| 38 | return nullptr; |
| 39 | } |
| 40 | |
| 41 | // Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify |
| 42 | // memory sizes. [kK] indicates kilobytes, [mM] megabytes, and |
| 43 | // [gG] gigabytes. |
| 44 | // |
| 45 | // "s" should point just past the "-Xm?" part of the string. |
| 46 | // "div" specifies a divisor, e.g. 1024 if the value must be a multiple |
| 47 | // of 1024. |
| 48 | // |
| 49 | // The spec says the -Xmx and -Xms options must be multiples of 1024. It |
| 50 | // doesn't say anything about -Xss. |
| 51 | // |
| 52 | // Returns 0 (a useless size) if "s" is malformed or specifies a low or |
| 53 | // non-evenly-divisible value. |
| 54 | // |
| 55 | size_t ParseMemoryOption(const char* s, size_t div) { |
| 56 | // strtoul accepts a leading [+-], which we don't want, |
| 57 | // so make sure our string starts with a decimal digit. |
| 58 | if (isdigit(*s)) { |
| 59 | char* s2; |
| 60 | size_t val = strtoul(s, &s2, 10); |
| 61 | if (s2 != s) { |
| 62 | // s2 should be pointing just after the number. |
| 63 | // If this is the end of the string, the user |
| 64 | // has specified a number of bytes. Otherwise, |
| 65 | // there should be exactly one more character |
| 66 | // that specifies a multiplier. |
| 67 | if (*s2 != '\0') { |
| 68 | // The remainder of the string is either a single multiplier |
| 69 | // character, or nothing to indicate that the value is in |
| 70 | // bytes. |
| 71 | char c = *s2++; |
| 72 | if (*s2 == '\0') { |
| 73 | size_t mul; |
| 74 | if (c == '\0') { |
| 75 | mul = 1; |
| 76 | } else if (c == 'k' || c == 'K') { |
| 77 | mul = KB; |
| 78 | } else if (c == 'm' || c == 'M') { |
| 79 | mul = MB; |
| 80 | } else if (c == 'g' || c == 'G') { |
| 81 | mul = GB; |
| 82 | } else { |
| 83 | // Unknown multiplier character. |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | if (val <= std::numeric_limits<size_t>::max() / mul) { |
| 88 | val *= mul; |
| 89 | } else { |
| 90 | // Clamp to a multiple of 1024. |
| 91 | val = std::numeric_limits<size_t>::max() & ~(1024-1); |
| 92 | } |
| 93 | } else { |
| 94 | // There's more than one character after the numeric part. |
| 95 | return 0; |
| 96 | } |
| 97 | } |
| 98 | // The man page says that a -Xm value must be a multiple of 1024. |
| 99 | if (val % div == 0) { |
| 100 | return val; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | static gc::CollectorType ParseCollectorType(const std::string& option) { |
| 108 | if (option == "MS" || option == "nonconcurrent") { |
| 109 | return gc::kCollectorTypeMS; |
| 110 | } else if (option == "CMS" || option == "concurrent") { |
| 111 | return gc::kCollectorTypeCMS; |
| 112 | } else if (option == "SS") { |
| 113 | return gc::kCollectorTypeSS; |
| 114 | } else if (option == "GSS") { |
| 115 | return gc::kCollectorTypeGSS; |
Hiroshi Yamauchi | d5307ec | 2014-03-27 21:07:51 -0700 | [diff] [blame] | 116 | } else if (option == "CC") { |
| 117 | return gc::kCollectorTypeCC; |
Mathieu Chartier | 52e4b43 | 2014-06-10 11:22:31 -0700 | [diff] [blame] | 118 | } else if (option == "MC") { |
| 119 | return gc::kCollectorTypeMC; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 120 | } else { |
| 121 | return gc::kCollectorTypeNone; |
| 122 | } |
| 123 | } |
| 124 | |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 125 | bool ParsedOptions::ParseXGcOption(const std::string& option) { |
| 126 | std::vector<std::string> gc_options; |
| 127 | Split(option.substr(strlen("-Xgc:")), ',', gc_options); |
| 128 | for (const std::string& gc_option : gc_options) { |
| 129 | gc::CollectorType collector_type = ParseCollectorType(gc_option); |
| 130 | if (collector_type != gc::kCollectorTypeNone) { |
| 131 | collector_type_ = collector_type; |
| 132 | } else if (gc_option == "preverify") { |
| 133 | verify_pre_gc_heap_ = true; |
| 134 | } else if (gc_option == "nopreverify") { |
| 135 | verify_pre_gc_heap_ = false; |
| 136 | } else if (gc_option == "presweepingverify") { |
| 137 | verify_pre_sweeping_heap_ = true; |
| 138 | } else if (gc_option == "nopresweepingverify") { |
| 139 | verify_pre_sweeping_heap_ = false; |
| 140 | } else if (gc_option == "postverify") { |
| 141 | verify_post_gc_heap_ = true; |
| 142 | } else if (gc_option == "nopostverify") { |
| 143 | verify_post_gc_heap_ = false; |
| 144 | } else if (gc_option == "preverify_rosalloc") { |
| 145 | verify_pre_gc_rosalloc_ = true; |
| 146 | } else if (gc_option == "nopreverify_rosalloc") { |
| 147 | verify_pre_gc_rosalloc_ = false; |
| 148 | } else if (gc_option == "presweepingverify_rosalloc") { |
| 149 | verify_pre_sweeping_rosalloc_ = true; |
| 150 | } else if (gc_option == "nopresweepingverify_rosalloc") { |
| 151 | verify_pre_sweeping_rosalloc_ = false; |
| 152 | } else if (gc_option == "postverify_rosalloc") { |
| 153 | verify_post_gc_rosalloc_ = true; |
| 154 | } else if (gc_option == "nopostverify_rosalloc") { |
| 155 | verify_post_gc_rosalloc_ = false; |
| 156 | } else if ((gc_option == "precise") || |
| 157 | (gc_option == "noprecise") || |
| 158 | (gc_option == "verifycardtable") || |
| 159 | (gc_option == "noverifycardtable")) { |
| 160 | // Ignored for backwards compatibility. |
| 161 | } else { |
| 162 | Usage("Unknown -Xgc option %s\n", gc_option.c_str()); |
| 163 | return false; |
| 164 | } |
| 165 | } |
| 166 | return true; |
| 167 | } |
| 168 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 169 | bool ParsedOptions::Parse(const RuntimeOptions& options, bool ignore_unrecognized) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 170 | const char* boot_class_path_string = getenv("BOOTCLASSPATH"); |
| 171 | if (boot_class_path_string != NULL) { |
| 172 | boot_class_path_string_ = boot_class_path_string; |
| 173 | } |
| 174 | const char* class_path_string = getenv("CLASSPATH"); |
| 175 | if (class_path_string != NULL) { |
| 176 | class_path_string_ = class_path_string; |
| 177 | } |
| 178 | // -Xcheck:jni is off by default for regular builds but on by default in debug builds. |
| 179 | check_jni_ = kIsDebugBuild; |
| 180 | |
| 181 | heap_initial_size_ = gc::Heap::kDefaultInitialSize; |
| 182 | heap_maximum_size_ = gc::Heap::kDefaultMaximumSize; |
| 183 | heap_min_free_ = gc::Heap::kDefaultMinFree; |
| 184 | heap_max_free_ = gc::Heap::kDefaultMaxFree; |
| 185 | heap_target_utilization_ = gc::Heap::kDefaultTargetUtilization; |
Mathieu Chartier | 2f8da3e | 2014-04-15 15:37:02 -0700 | [diff] [blame] | 186 | foreground_heap_growth_multiplier_ = gc::Heap::kDefaultHeapGrowthMultiplier; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 187 | heap_growth_limit_ = 0; // 0 means no growth limit . |
| 188 | // Default to number of processors minus one since the main GC thread also does work. |
| 189 | parallel_gc_threads_ = sysconf(_SC_NPROCESSORS_CONF) - 1; |
| 190 | // Only the main GC thread, no workers. |
| 191 | conc_gc_threads_ = 0; |
Hiroshi Yamauchi | 1dda060 | 2014-05-12 12:32:32 -0700 | [diff] [blame] | 192 | // The default GC type is set in makefiles. |
| 193 | #if ART_DEFAULT_GC_TYPE_IS_CMS |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 194 | collector_type_ = gc::kCollectorTypeCMS; |
Hiroshi Yamauchi | 1dda060 | 2014-05-12 12:32:32 -0700 | [diff] [blame] | 195 | #elif ART_DEFAULT_GC_TYPE_IS_SS |
| 196 | collector_type_ = gc::kCollectorTypeSS; |
| 197 | #elif ART_DEFAULT_GC_TYPE_IS_GSS |
| 198 | collector_type_ = gc::kCollectorTypeGSS; |
| 199 | #else |
| 200 | #error "ART default GC type must be set" |
| 201 | #endif |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 202 | // If we are using homogeneous space compaction then default background compaction to off since |
| 203 | // homogeneous space compactions when we transition to not jank perceptible. |
| 204 | use_homogeneous_space_compaction_for_oom_ = false; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 205 | // If background_collector_type_ is kCollectorTypeNone, it defaults to the collector_type_ after |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 206 | // parsing options. If you set this to kCollectorTypeHSpaceCompact then we will do an hspace |
| 207 | // compaction when we transition to background instead of a normal collector transition. |
Mathieu Chartier | a033f70 | 2014-06-17 12:01:06 -0700 | [diff] [blame] | 208 | background_collector_type_ = gc::kCollectorTypeSS; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 209 | stack_size_ = 0; // 0 means default. |
| 210 | max_spins_before_thin_lock_inflation_ = Monitor::kDefaultMaxSpinsBeforeThinLockInflation; |
| 211 | low_memory_mode_ = false; |
| 212 | use_tlab_ = false; |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 213 | min_interval_homogeneous_space_compaction_by_oom_ = MsToNs(100 * 1000); // 100s. |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 214 | verify_pre_gc_heap_ = false; |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 215 | // Pre sweeping is the one that usually fails if the GC corrupted the heap. |
| 216 | verify_pre_sweeping_heap_ = kIsDebugBuild; |
| 217 | verify_post_gc_heap_ = false; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 218 | verify_pre_gc_rosalloc_ = kIsDebugBuild; |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 219 | verify_pre_sweeping_rosalloc_ = false; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 220 | verify_post_gc_rosalloc_ = false; |
| 221 | |
| 222 | compiler_callbacks_ = nullptr; |
| 223 | is_zygote_ = false; |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 224 | must_relocate_ = kDefaultMustRelocate; |
Hiroshi Yamauchi | e63a745 | 2014-02-27 14:44:36 -0800 | [diff] [blame] | 225 | if (kPoisonHeapReferences) { |
| 226 | // kPoisonHeapReferences currently works only with the interpreter only. |
| 227 | // TODO: make it work with the compiler. |
| 228 | interpreter_only_ = true; |
| 229 | } else { |
| 230 | interpreter_only_ = false; |
| 231 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 232 | is_explicit_gc_disabled_ = false; |
| 233 | |
| 234 | long_pause_log_threshold_ = gc::Heap::kDefaultLongPauseLogThreshold; |
| 235 | long_gc_log_threshold_ = gc::Heap::kDefaultLongGCLogThreshold; |
| 236 | dump_gc_performance_on_shutdown_ = false; |
| 237 | ignore_max_footprint_ = false; |
| 238 | |
| 239 | lock_profiling_threshold_ = 0; |
| 240 | hook_is_sensitive_thread_ = NULL; |
| 241 | |
| 242 | hook_vfprintf_ = vfprintf; |
| 243 | hook_exit_ = exit; |
| 244 | hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort. |
| 245 | |
| 246 | // gLogVerbosity.class_linker = true; // TODO: don't check this in! |
| 247 | // gLogVerbosity.compiler = true; // TODO: don't check this in! |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 248 | // gLogVerbosity.gc = true; // TODO: don't check this in! |
Brian Carlstrom | 4d466a8 | 2014-05-08 19:05:29 -0700 | [diff] [blame] | 249 | // gLogVerbosity.heap = true; // TODO: don't check this in! |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 250 | // gLogVerbosity.jdwp = true; // TODO: don't check this in! |
| 251 | // gLogVerbosity.jni = true; // TODO: don't check this in! |
| 252 | // gLogVerbosity.monitor = true; // TODO: don't check this in! |
Brian Carlstrom | 4d466a8 | 2014-05-08 19:05:29 -0700 | [diff] [blame] | 253 | // gLogVerbosity.profiler = true; // TODO: don't check this in! |
| 254 | // gLogVerbosity.signals = true; // TODO: don't check this in! |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 255 | // gLogVerbosity.startup = true; // TODO: don't check this in! |
| 256 | // gLogVerbosity.third_party_jni = true; // TODO: don't check this in! |
| 257 | // gLogVerbosity.threads = true; // TODO: don't check this in! |
Brian Carlstrom | 4d466a8 | 2014-05-08 19:05:29 -0700 | [diff] [blame] | 258 | // gLogVerbosity.verifier = true; // TODO: don't check this in! |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 259 | |
| 260 | method_trace_ = false; |
| 261 | method_trace_file_ = "/data/method-trace-file.bin"; |
| 262 | method_trace_file_size_ = 10 * MB; |
| 263 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 264 | profile_clock_source_ = kDefaultTraceClockSource; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 265 | |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 266 | verify_ = true; |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 267 | image_isa_ = kRuntimeISA; |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 268 | |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 269 | for (size_t i = 0; i < options.size(); ++i) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 270 | if (true && options[0].first == "-Xzygote") { |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 271 | LOG(INFO) << "option[" << i << "]=" << options[i].first; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 272 | } |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 273 | } |
| 274 | for (size_t i = 0; i < options.size(); ++i) { |
| 275 | const std::string option(options[i].first); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 276 | if (StartsWith(option, "-help")) { |
| 277 | Usage(nullptr); |
| 278 | return false; |
| 279 | } else if (StartsWith(option, "-showversion")) { |
| 280 | UsageMessage(stdout, "ART version %s\n", Runtime::GetVersion()); |
| 281 | Exit(0); |
| 282 | } else if (StartsWith(option, "-Xbootclasspath:")) { |
| 283 | boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data(); |
Dave Allison | 69dfe51 | 2014-07-11 17:11:58 +0000 | [diff] [blame] | 284 | LOG(INFO) << "setting boot class path to " << boot_class_path_string_; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 285 | } else if (option == "-classpath" || option == "-cp") { |
| 286 | // TODO: support -Djava.class.path |
| 287 | i++; |
| 288 | if (i == options.size()) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 289 | Usage("Missing required class path value for %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 290 | return false; |
| 291 | } |
| 292 | const StringPiece& value = options[i].first; |
| 293 | class_path_string_ = value.data(); |
| 294 | } else if (option == "bootclasspath") { |
| 295 | boot_class_path_ |
| 296 | = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second); |
| 297 | } else if (StartsWith(option, "-Ximage:")) { |
| 298 | if (!ParseStringAfterChar(option, ':', &image_)) { |
| 299 | return false; |
| 300 | } |
| 301 | } else if (StartsWith(option, "-Xcheck:jni")) { |
| 302 | check_jni_ = true; |
| 303 | } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) { |
| 304 | std::string tail(option.substr(option[1] == 'X' ? 10 : 15)); |
| 305 | // TODO: move parsing logic out of Dbg |
| 306 | if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) { |
| 307 | if (tail != "help") { |
| 308 | UsageMessage(stderr, "Failed to parse JDWP option %s\n", tail.c_str()); |
| 309 | } |
| 310 | Usage("Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n" |
| 311 | "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n\n"); |
| 312 | return false; |
| 313 | } |
| 314 | } else if (StartsWith(option, "-Xms")) { |
| 315 | size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024); |
| 316 | if (size == 0) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 317 | Usage("Failed to parse memory option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 318 | return false; |
| 319 | } |
| 320 | heap_initial_size_ = size; |
| 321 | } else if (StartsWith(option, "-Xmx")) { |
| 322 | size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024); |
| 323 | if (size == 0) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 324 | Usage("Failed to parse memory option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 325 | return false; |
| 326 | } |
| 327 | heap_maximum_size_ = size; |
| 328 | } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) { |
| 329 | size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024); |
| 330 | if (size == 0) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 331 | Usage("Failed to parse memory option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 332 | return false; |
| 333 | } |
| 334 | heap_growth_limit_ = size; |
| 335 | } else if (StartsWith(option, "-XX:HeapMinFree=")) { |
| 336 | size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024); |
| 337 | if (size == 0) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 338 | Usage("Failed to parse memory option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 339 | return false; |
| 340 | } |
| 341 | heap_min_free_ = size; |
| 342 | } else if (StartsWith(option, "-XX:HeapMaxFree=")) { |
| 343 | size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024); |
| 344 | if (size == 0) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 345 | Usage("Failed to parse memory option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 346 | return false; |
| 347 | } |
| 348 | heap_max_free_ = size; |
| 349 | } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) { |
| 350 | if (!ParseDouble(option, '=', 0.1, 0.9, &heap_target_utilization_)) { |
| 351 | return false; |
| 352 | } |
Mathieu Chartier | 2f8da3e | 2014-04-15 15:37:02 -0700 | [diff] [blame] | 353 | } else if (StartsWith(option, "-XX:ForegroundHeapGrowthMultiplier=")) { |
Mathieu Chartier | 455820e | 2014-04-18 12:02:39 -0700 | [diff] [blame] | 354 | if (!ParseDouble(option, '=', 0.1, 10.0, &foreground_heap_growth_multiplier_)) { |
Mathieu Chartier | 2f8da3e | 2014-04-15 15:37:02 -0700 | [diff] [blame] | 355 | return false; |
| 356 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 357 | } else if (StartsWith(option, "-XX:ParallelGCThreads=")) { |
| 358 | if (!ParseUnsignedInteger(option, '=', ¶llel_gc_threads_)) { |
| 359 | return false; |
| 360 | } |
| 361 | } else if (StartsWith(option, "-XX:ConcGCThreads=")) { |
| 362 | if (!ParseUnsignedInteger(option, '=', &conc_gc_threads_)) { |
| 363 | return false; |
| 364 | } |
| 365 | } else if (StartsWith(option, "-Xss")) { |
| 366 | size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1); |
| 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 | stack_size_ = size; |
| 372 | } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) { |
| 373 | if (!ParseUnsignedInteger(option, '=', &max_spins_before_thin_lock_inflation_)) { |
| 374 | return false; |
| 375 | } |
| 376 | } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) { |
Andreas Gampe | 39d9218 | 2014-03-05 16:46:44 -0800 | [diff] [blame] | 377 | unsigned int value; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 378 | if (!ParseUnsignedInteger(option, '=', &value)) { |
| 379 | return false; |
| 380 | } |
| 381 | long_pause_log_threshold_ = MsToNs(value); |
| 382 | } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) { |
Andreas Gampe | 39d9218 | 2014-03-05 16:46:44 -0800 | [diff] [blame] | 383 | unsigned int value; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 384 | if (!ParseUnsignedInteger(option, '=', &value)) { |
| 385 | return false; |
| 386 | } |
| 387 | long_gc_log_threshold_ = MsToNs(value); |
| 388 | } else if (option == "-XX:DumpGCPerformanceOnShutdown") { |
| 389 | dump_gc_performance_on_shutdown_ = true; |
| 390 | } else if (option == "-XX:IgnoreMaxFootprint") { |
| 391 | ignore_max_footprint_ = true; |
| 392 | } else if (option == "-XX:LowMemoryMode") { |
| 393 | low_memory_mode_ = true; |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 394 | // TODO Might want to turn off must_relocate here. |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 395 | } else if (option == "-XX:UseTLAB") { |
| 396 | use_tlab_ = true; |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 397 | } else if (option == "-XX:EnableHSpaceCompactForOOM") { |
| 398 | use_homogeneous_space_compaction_for_oom_ = true; |
| 399 | } else if (option == "-XX:DisableHSpaceCompactForOOM") { |
| 400 | use_homogeneous_space_compaction_for_oom_ = false; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 401 | } else if (StartsWith(option, "-D")) { |
| 402 | properties_.push_back(option.substr(strlen("-D"))); |
| 403 | } else if (StartsWith(option, "-Xjnitrace:")) { |
| 404 | jni_trace_ = option.substr(strlen("-Xjnitrace:")); |
| 405 | } else if (option == "compilercallbacks") { |
| 406 | compiler_callbacks_ = |
| 407 | reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second)); |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 408 | } else if (option == "imageinstructionset") { |
| 409 | image_isa_ = GetInstructionSetFromString( |
| 410 | reinterpret_cast<const char*>(options[i].second)); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 411 | } else if (option == "-Xzygote") { |
| 412 | is_zygote_ = true; |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 413 | } else if (StartsWith(option, "-Xpatchoat:")) { |
| 414 | if (!ParseStringAfterChar(option, ':', &patchoat_executable_)) { |
| 415 | return false; |
| 416 | } |
| 417 | } else if (option == "-Xrelocate") { |
| 418 | must_relocate_ = true; |
| 419 | } else if (option == "-Xnorelocate") { |
| 420 | must_relocate_ = false; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 421 | } else if (option == "-Xint") { |
| 422 | interpreter_only_ = true; |
| 423 | } else if (StartsWith(option, "-Xgc:")) { |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 424 | if (!ParseXGcOption(option)) { |
| 425 | return false; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 426 | } |
| 427 | } else if (StartsWith(option, "-XX:BackgroundGC=")) { |
| 428 | std::string substring; |
| 429 | if (!ParseStringAfterChar(option, '=', &substring)) { |
| 430 | return false; |
| 431 | } |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 432 | // Special handling for HSpaceCompact since this is only valid as a background GC type. |
| 433 | if (substring == "HSpaceCompact") { |
| 434 | background_collector_type_ = gc::kCollectorTypeHomogeneousSpaceCompact; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 435 | } else { |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 436 | gc::CollectorType collector_type = ParseCollectorType(substring); |
| 437 | if (collector_type != gc::kCollectorTypeNone) { |
| 438 | background_collector_type_ = collector_type; |
| 439 | } else { |
| 440 | Usage("Unknown -XX:BackgroundGC option %s\n", substring.c_str()); |
| 441 | return false; |
| 442 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 443 | } |
| 444 | } else if (option == "-XX:+DisableExplicitGC") { |
| 445 | is_explicit_gc_disabled_ = true; |
| 446 | } else if (StartsWith(option, "-verbose:")) { |
| 447 | std::vector<std::string> verbose_options; |
| 448 | Split(option.substr(strlen("-verbose:")), ',', verbose_options); |
| 449 | for (size_t i = 0; i < verbose_options.size(); ++i) { |
| 450 | if (verbose_options[i] == "class") { |
| 451 | gLogVerbosity.class_linker = true; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 452 | } else if (verbose_options[i] == "compiler") { |
| 453 | gLogVerbosity.compiler = true; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 454 | } else if (verbose_options[i] == "gc") { |
| 455 | gLogVerbosity.gc = true; |
Brian Carlstrom | 4d466a8 | 2014-05-08 19:05:29 -0700 | [diff] [blame] | 456 | } else if (verbose_options[i] == "heap") { |
| 457 | gLogVerbosity.heap = true; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 458 | } else if (verbose_options[i] == "jdwp") { |
| 459 | gLogVerbosity.jdwp = true; |
| 460 | } else if (verbose_options[i] == "jni") { |
| 461 | gLogVerbosity.jni = true; |
| 462 | } else if (verbose_options[i] == "monitor") { |
| 463 | gLogVerbosity.monitor = true; |
Brian Carlstrom | 4d466a8 | 2014-05-08 19:05:29 -0700 | [diff] [blame] | 464 | } else if (verbose_options[i] == "profiler") { |
| 465 | gLogVerbosity.profiler = true; |
| 466 | } else if (verbose_options[i] == "signals") { |
| 467 | gLogVerbosity.signals = true; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 468 | } else if (verbose_options[i] == "startup") { |
| 469 | gLogVerbosity.startup = true; |
| 470 | } else if (verbose_options[i] == "third-party-jni") { |
| 471 | gLogVerbosity.third_party_jni = true; |
| 472 | } else if (verbose_options[i] == "threads") { |
| 473 | gLogVerbosity.threads = true; |
Brian Carlstrom | 4d466a8 | 2014-05-08 19:05:29 -0700 | [diff] [blame] | 474 | } else if (verbose_options[i] == "verifier") { |
| 475 | gLogVerbosity.verifier = true; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 476 | } else { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 477 | Usage("Unknown -verbose option %s\n", verbose_options[i].c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 478 | return false; |
| 479 | } |
| 480 | } |
Mingyao Yang | 42d65c5 | 2014-04-18 16:49:39 -0700 | [diff] [blame] | 481 | } else if (StartsWith(option, "-verbose-methods:")) { |
| 482 | gLogVerbosity.compiler = false; |
| 483 | Split(option.substr(strlen("-verbose-methods:")), ',', gVerboseMethods); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 484 | } else if (StartsWith(option, "-Xlockprofthreshold:")) { |
| 485 | if (!ParseUnsignedInteger(option, ':', &lock_profiling_threshold_)) { |
| 486 | return false; |
| 487 | } |
| 488 | } else if (StartsWith(option, "-Xstacktracefile:")) { |
| 489 | if (!ParseStringAfterChar(option, ':', &stack_trace_file_)) { |
| 490 | return false; |
| 491 | } |
| 492 | } else if (option == "sensitiveThread") { |
| 493 | const void* hook = options[i].second; |
| 494 | hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(hook)); |
| 495 | } else if (option == "vfprintf") { |
| 496 | const void* hook = options[i].second; |
| 497 | if (hook == nullptr) { |
| 498 | Usage("vfprintf argument was NULL"); |
| 499 | return false; |
| 500 | } |
| 501 | hook_vfprintf_ = |
| 502 | reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(hook)); |
| 503 | } else if (option == "exit") { |
| 504 | const void* hook = options[i].second; |
| 505 | if (hook == nullptr) { |
| 506 | Usage("exit argument was NULL"); |
| 507 | return false; |
| 508 | } |
| 509 | hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(hook)); |
| 510 | } else if (option == "abort") { |
| 511 | const void* hook = options[i].second; |
| 512 | if (hook == nullptr) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 513 | Usage("abort was NULL\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 514 | return false; |
| 515 | } |
| 516 | hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(hook)); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 517 | } else if (option == "-Xmethod-trace") { |
| 518 | method_trace_ = true; |
| 519 | } else if (StartsWith(option, "-Xmethod-trace-file:")) { |
| 520 | method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:")); |
| 521 | } else if (StartsWith(option, "-Xmethod-trace-file-size:")) { |
| 522 | if (!ParseUnsignedInteger(option, ':', &method_trace_file_size_)) { |
| 523 | return false; |
| 524 | } |
| 525 | } else if (option == "-Xprofile:threadcpuclock") { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 526 | Trace::SetDefaultClockSource(kTraceClockSourceThreadCpu); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 527 | } else if (option == "-Xprofile:wallclock") { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 528 | Trace::SetDefaultClockSource(kTraceClockSourceWall); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 529 | } else if (option == "-Xprofile:dualclock") { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 530 | Trace::SetDefaultClockSource(kTraceClockSourceDual); |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 531 | } else if (option == "-Xenable-profiler") { |
| 532 | profiler_options_.enabled_ = true; |
Wei Jin | 2221e3b | 2014-05-21 18:35:19 -0700 | [diff] [blame] | 533 | } else if (StartsWith(option, "-Xprofile-filename:")) { |
Ian Rogers | f7fd3cb | 2014-05-19 22:57:34 -0700 | [diff] [blame] | 534 | if (!ParseStringAfterChar(option, ':', &profile_output_filename_)) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 535 | return false; |
| 536 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 537 | } else if (StartsWith(option, "-Xprofile-period:")) { |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 538 | if (!ParseUnsignedInteger(option, ':', &profiler_options_.period_s_)) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 539 | return false; |
| 540 | } |
| 541 | } else if (StartsWith(option, "-Xprofile-duration:")) { |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 542 | if (!ParseUnsignedInteger(option, ':', &profiler_options_.duration_s_)) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 543 | return false; |
| 544 | } |
| 545 | } else if (StartsWith(option, "-Xprofile-interval:")) { |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 546 | if (!ParseUnsignedInteger(option, ':', &profiler_options_.interval_us_)) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 547 | return false; |
| 548 | } |
| 549 | } else if (StartsWith(option, "-Xprofile-backoff:")) { |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 550 | if (!ParseDouble(option, ':', 1.0, 10.0, &profiler_options_.backoff_coefficient_)) { |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 551 | return false; |
| 552 | } |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 553 | } else if (option == "-Xprofile-start-immediately") { |
| 554 | profiler_options_.start_immediately_ = true; |
| 555 | } else if (StartsWith(option, "-Xprofile-top-k-threshold:")) { |
Calin Juravle | c321c9b | 2014-06-11 19:04:35 +0100 | [diff] [blame] | 556 | if (!ParseDouble(option, ':', 0.0, 100.0, &profiler_options_.top_k_threshold_)) { |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 557 | return false; |
| 558 | } |
| 559 | } else if (StartsWith(option, "-Xprofile-top-k-change-threshold:")) { |
Calin Juravle | c321c9b | 2014-06-11 19:04:35 +0100 | [diff] [blame] | 560 | 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] | 561 | return false; |
| 562 | } |
Wei Jin | a93b0bb | 2014-06-09 16:19:15 -0700 | [diff] [blame] | 563 | } else if (option == "-Xprofile-type:method") { |
| 564 | profiler_options_.profile_type_ = kProfilerMethod; |
Wei Jin | 445220d | 2014-06-20 15:56:53 -0700 | [diff] [blame] | 565 | } else if (option == "-Xprofile-type:stack") { |
| 566 | profiler_options_.profile_type_ = kProfilerBoundedStack; |
| 567 | } else if (StartsWith(option, "-Xprofile-max-stack-depth:")) { |
| 568 | if (!ParseUnsignedInteger(option, ':', &profiler_options_.max_stack_depth_)) { |
| 569 | return false; |
| 570 | } |
Tsu Chiang Chuang | 12e6d74 | 2014-05-22 10:22:25 -0700 | [diff] [blame] | 571 | } else if (StartsWith(option, "-Xcompiler:")) { |
| 572 | if (!ParseStringAfterChar(option, ':', &compiler_executable_)) { |
| 573 | return false; |
| 574 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 575 | } else if (option == "-Xcompiler-option") { |
| 576 | i++; |
| 577 | if (i == options.size()) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 578 | Usage("Missing required compiler option for %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 579 | return false; |
| 580 | } |
| 581 | compiler_options_.push_back(options[i].first); |
| 582 | } else if (option == "-Ximage-compiler-option") { |
| 583 | i++; |
| 584 | if (i == options.size()) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 585 | Usage("Missing required compiler option for %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 586 | return false; |
| 587 | } |
| 588 | image_compiler_options_.push_back(options[i].first); |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 589 | } else if (StartsWith(option, "-Xverify:")) { |
| 590 | std::string verify_mode = option.substr(strlen("-Xverify:")); |
| 591 | if (verify_mode == "none") { |
| 592 | verify_ = false; |
| 593 | } else if (verify_mode == "remote" || verify_mode == "all") { |
| 594 | verify_ = true; |
| 595 | } else { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 596 | Usage("Unknown -Xverify option %s\n", verify_mode.c_str()); |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 597 | return false; |
| 598 | } |
Andreas Gampe | 855564b | 2014-07-25 02:32:19 -0700 | [diff] [blame^] | 599 | } else if (StartsWith(option, "-XX:NativeBridge=")) { |
| 600 | if (!ParseStringAfterChar(option, '=', &native_bridge_library_string_)) { |
| 601 | return false; |
| 602 | } |
Yevgeny Rouban | a6119a2 | 2014-03-24 11:31:24 +0700 | [diff] [blame] | 603 | } else if (StartsWith(option, "-ea") || |
| 604 | StartsWith(option, "-da") || |
| 605 | StartsWith(option, "-enableassertions") || |
| 606 | StartsWith(option, "-disableassertions") || |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 607 | (option == "--runtime-arg") || |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 608 | (option == "-esa") || |
| 609 | (option == "-dsa") || |
| 610 | (option == "-enablesystemassertions") || |
| 611 | (option == "-disablesystemassertions") || |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 612 | (option == "-Xrs") || |
| 613 | StartsWith(option, "-Xint:") || |
| 614 | StartsWith(option, "-Xdexopt:") || |
| 615 | (option == "-Xnoquithandler") || |
| 616 | StartsWith(option, "-Xjniopts:") || |
| 617 | StartsWith(option, "-Xjnigreflimit:") || |
| 618 | (option == "-Xgenregmap") || |
| 619 | (option == "-Xnogenregmap") || |
| 620 | StartsWith(option, "-Xverifyopt:") || |
| 621 | (option == "-Xcheckdexsum") || |
| 622 | (option == "-Xincludeselectedop") || |
| 623 | StartsWith(option, "-Xjitop:") || |
| 624 | (option == "-Xincludeselectedmethod") || |
| 625 | StartsWith(option, "-Xjitthreshold:") || |
| 626 | StartsWith(option, "-Xjitcodecachesize:") || |
| 627 | (option == "-Xjitblocking") || |
| 628 | StartsWith(option, "-Xjitmethod:") || |
| 629 | StartsWith(option, "-Xjitclass:") || |
| 630 | StartsWith(option, "-Xjitoffset:") || |
| 631 | StartsWith(option, "-Xjitconfig:") || |
| 632 | (option == "-Xjitcheckcg") || |
| 633 | (option == "-Xjitverbose") || |
| 634 | (option == "-Xjitprofile") || |
| 635 | (option == "-Xjitdisableopt") || |
| 636 | (option == "-Xjitsuspendpoll") || |
| 637 | StartsWith(option, "-XX:mainThreadStackSize=")) { |
| 638 | // Ignored for backwards compatibility. |
| 639 | } else if (!ignore_unrecognized) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 640 | Usage("Unrecognized option %s\n", option.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 641 | return false; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | // If a reference to the dalvik core.jar snuck in, replace it with |
| 646 | // the art specific version. This can happen with on device |
| 647 | // boot.art/boot.oat generation by GenerateImage which relies on the |
| 648 | // value of BOOTCLASSPATH. |
Kenny Root | d518534 | 2014-05-13 14:47:05 -0700 | [diff] [blame] | 649 | #if defined(ART_TARGET) |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 650 | std::string core_jar("/core.jar"); |
Kenny Root | d518534 | 2014-05-13 14:47:05 -0700 | [diff] [blame] | 651 | std::string core_libart_jar("/core-libart.jar"); |
| 652 | #else |
| 653 | // The host uses hostdex files. |
| 654 | std::string core_jar("/core-hostdex.jar"); |
| 655 | std::string core_libart_jar("/core-libart-hostdex.jar"); |
| 656 | #endif |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 657 | size_t core_jar_pos = boot_class_path_string_.find(core_jar); |
| 658 | if (core_jar_pos != std::string::npos) { |
Kenny Root | d518534 | 2014-05-13 14:47:05 -0700 | [diff] [blame] | 659 | 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] | 660 | } |
| 661 | |
| 662 | if (compiler_callbacks_ == nullptr && image_.empty()) { |
| 663 | image_ += GetAndroidRoot(); |
Brian Carlstrom | 3ac05bb | 2014-05-13 19:31:38 -0700 | [diff] [blame] | 664 | image_ += "/framework/boot.art"; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 665 | } |
| 666 | if (heap_growth_limit_ == 0) { |
| 667 | heap_growth_limit_ = heap_maximum_size_; |
| 668 | } |
| 669 | if (background_collector_type_ == gc::kCollectorTypeNone) { |
| 670 | background_collector_type_ = collector_type_; |
| 671 | } |
| 672 | return true; |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 673 | } // NOLINT(readability/fn_size) |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 674 | |
| 675 | void ParsedOptions::Exit(int status) { |
| 676 | hook_exit_(status); |
| 677 | } |
| 678 | |
| 679 | void ParsedOptions::Abort() { |
| 680 | hook_abort_(); |
| 681 | } |
| 682 | |
| 683 | void ParsedOptions::UsageMessageV(FILE* stream, const char* fmt, va_list ap) { |
| 684 | hook_vfprintf_(stderr, fmt, ap); |
| 685 | } |
| 686 | |
| 687 | void ParsedOptions::UsageMessage(FILE* stream, const char* fmt, ...) { |
| 688 | va_list ap; |
| 689 | va_start(ap, fmt); |
| 690 | UsageMessageV(stream, fmt, ap); |
| 691 | va_end(ap); |
| 692 | } |
| 693 | |
| 694 | void ParsedOptions::Usage(const char* fmt, ...) { |
| 695 | bool error = (fmt != nullptr); |
| 696 | FILE* stream = error ? stderr : stdout; |
| 697 | |
| 698 | if (fmt != nullptr) { |
| 699 | va_list ap; |
| 700 | va_start(ap, fmt); |
| 701 | UsageMessageV(stream, fmt, ap); |
| 702 | va_end(ap); |
| 703 | } |
| 704 | |
| 705 | const char* program = "dalvikvm"; |
| 706 | UsageMessage(stream, "%s: [options] class [argument ...]\n", program); |
| 707 | UsageMessage(stream, "\n"); |
| 708 | UsageMessage(stream, "The following standard options are supported:\n"); |
| 709 | UsageMessage(stream, " -classpath classpath (-cp classpath)\n"); |
| 710 | UsageMessage(stream, " -Dproperty=value\n"); |
| 711 | UsageMessage(stream, " -verbose:tag ('gc', 'jni', or 'class')\n"); |
| 712 | UsageMessage(stream, " -showversion\n"); |
| 713 | UsageMessage(stream, " -help\n"); |
| 714 | UsageMessage(stream, " -agentlib:jdwp=options\n"); |
| 715 | UsageMessage(stream, "\n"); |
| 716 | |
| 717 | UsageMessage(stream, "The following extended options are supported:\n"); |
| 718 | UsageMessage(stream, " -Xrunjdwp:<options>\n"); |
| 719 | UsageMessage(stream, " -Xbootclasspath:bootclasspath\n"); |
| 720 | UsageMessage(stream, " -Xcheck:tag (e.g. 'jni')\n"); |
| 721 | UsageMessage(stream, " -XmsN (min heap, must be multiple of 1K, >= 1MB)\n"); |
| 722 | UsageMessage(stream, " -XmxN (max heap, must be multiple of 1K, >= 2MB)\n"); |
| 723 | UsageMessage(stream, " -XssN (stack size)\n"); |
| 724 | UsageMessage(stream, " -Xint\n"); |
| 725 | UsageMessage(stream, "\n"); |
| 726 | |
| 727 | UsageMessage(stream, "The following Dalvik options are supported:\n"); |
| 728 | UsageMessage(stream, " -Xzygote\n"); |
| 729 | UsageMessage(stream, " -Xjnitrace:substring (eg NativeClass or nativeMethod)\n"); |
| 730 | UsageMessage(stream, " -Xstacktracefile:<filename>\n"); |
| 731 | UsageMessage(stream, " -Xgc:[no]preverify\n"); |
| 732 | UsageMessage(stream, " -Xgc:[no]postverify\n"); |
| 733 | UsageMessage(stream, " -XX:+DisableExplicitGC\n"); |
| 734 | UsageMessage(stream, " -XX:HeapGrowthLimit=N\n"); |
| 735 | UsageMessage(stream, " -XX:HeapMinFree=N\n"); |
| 736 | UsageMessage(stream, " -XX:HeapMaxFree=N\n"); |
| 737 | UsageMessage(stream, " -XX:HeapTargetUtilization=doublevalue\n"); |
Mathieu Chartier | 455820e | 2014-04-18 12:02:39 -0700 | [diff] [blame] | 738 | UsageMessage(stream, " -XX:ForegroundHeapGrowthMultiplier=doublevalue\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 739 | UsageMessage(stream, " -XX:LowMemoryMode\n"); |
| 740 | UsageMessage(stream, " -Xprofile:{threadcpuclock,wallclock,dualclock}\n"); |
| 741 | UsageMessage(stream, "\n"); |
| 742 | |
| 743 | UsageMessage(stream, "The following unique to ART options are supported:\n"); |
| 744 | UsageMessage(stream, " -Xgc:[no]preverify_rosalloc\n"); |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 745 | UsageMessage(stream, " -Xgc:[no]postsweepingverify_rosalloc\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 746 | UsageMessage(stream, " -Xgc:[no]postverify_rosalloc\n"); |
Mathieu Chartier | 6f365cc | 2014-04-23 12:42:27 -0700 | [diff] [blame] | 747 | UsageMessage(stream, " -Xgc:[no]presweepingverify\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 748 | UsageMessage(stream, " -Ximage:filename\n"); |
| 749 | UsageMessage(stream, " -XX:ParallelGCThreads=integervalue\n"); |
| 750 | UsageMessage(stream, " -XX:ConcGCThreads=integervalue\n"); |
| 751 | UsageMessage(stream, " -XX:MaxSpinsBeforeThinLockInflation=integervalue\n"); |
| 752 | UsageMessage(stream, " -XX:LongPauseLogThreshold=integervalue\n"); |
| 753 | UsageMessage(stream, " -XX:LongGCLogThreshold=integervalue\n"); |
| 754 | UsageMessage(stream, " -XX:DumpGCPerformanceOnShutdown\n"); |
| 755 | UsageMessage(stream, " -XX:IgnoreMaxFootprint\n"); |
| 756 | UsageMessage(stream, " -XX:UseTLAB\n"); |
| 757 | UsageMessage(stream, " -XX:BackgroundGC=none\n"); |
| 758 | UsageMessage(stream, " -Xmethod-trace\n"); |
| 759 | UsageMessage(stream, " -Xmethod-trace-file:filename"); |
| 760 | UsageMessage(stream, " -Xmethod-trace-file-size:integervalue\n"); |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 761 | UsageMessage(stream, " -Xenable-profiler\n"); |
Wei Jin | 2221e3b | 2014-05-21 18:35:19 -0700 | [diff] [blame] | 762 | UsageMessage(stream, " -Xprofile-filename:filename\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 763 | UsageMessage(stream, " -Xprofile-period:integervalue\n"); |
| 764 | UsageMessage(stream, " -Xprofile-duration:integervalue\n"); |
| 765 | UsageMessage(stream, " -Xprofile-interval:integervalue\n"); |
Calin Juravle | 54c73ca | 2014-05-22 12:13:54 +0100 | [diff] [blame] | 766 | UsageMessage(stream, " -Xprofile-backoff:doublevalue\n"); |
Calin Juravle | c1b643c | 2014-05-30 23:44:11 +0100 | [diff] [blame] | 767 | UsageMessage(stream, " -Xprofile-start-immediately\n"); |
| 768 | UsageMessage(stream, " -Xprofile-top-k-threshold:doublevalue\n"); |
| 769 | UsageMessage(stream, " -Xprofile-top-k-change-threshold:doublevalue\n"); |
Wei Jin | 445220d | 2014-06-20 15:56:53 -0700 | [diff] [blame] | 770 | UsageMessage(stream, " -Xprofile-type:{method,stack}\n"); |
| 771 | UsageMessage(stream, " -Xprofile-max-stack-depth:integervalue\n"); |
Tsu Chiang Chuang | 12e6d74 | 2014-05-22 10:22:25 -0700 | [diff] [blame] | 772 | UsageMessage(stream, " -Xcompiler:filename\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 773 | UsageMessage(stream, " -Xcompiler-option dex2oat-option\n"); |
| 774 | UsageMessage(stream, " -Ximage-compiler-option dex2oat-option\n"); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 775 | UsageMessage(stream, " -Xpatchoat:filename\n"); |
| 776 | UsageMessage(stream, " -X[no]relocate\n"); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 777 | UsageMessage(stream, "\n"); |
| 778 | |
| 779 | UsageMessage(stream, "The following previously supported Dalvik options are ignored:\n"); |
| 780 | UsageMessage(stream, " -ea[:<package name>... |:<class name>]\n"); |
| 781 | UsageMessage(stream, " -da[:<package name>... |:<class name>]\n"); |
| 782 | UsageMessage(stream, " (-enableassertions, -disableassertions)\n"); |
| 783 | UsageMessage(stream, " -esa\n"); |
| 784 | UsageMessage(stream, " -dsa\n"); |
| 785 | UsageMessage(stream, " (-enablesystemassertions, -disablesystemassertions)\n"); |
| 786 | UsageMessage(stream, " -Xverify:{none,remote,all}\n"); |
| 787 | UsageMessage(stream, " -Xrs\n"); |
| 788 | UsageMessage(stream, " -Xint:portable, -Xint:fast, -Xint:jit\n"); |
| 789 | UsageMessage(stream, " -Xdexopt:{none,verified,all,full}\n"); |
| 790 | UsageMessage(stream, " -Xnoquithandler\n"); |
| 791 | UsageMessage(stream, " -Xjniopts:{warnonly,forcecopy}\n"); |
| 792 | UsageMessage(stream, " -Xjnigreflimit:integervalue\n"); |
| 793 | UsageMessage(stream, " -Xgc:[no]precise\n"); |
| 794 | UsageMessage(stream, " -Xgc:[no]verifycardtable\n"); |
| 795 | UsageMessage(stream, " -X[no]genregmap\n"); |
| 796 | UsageMessage(stream, " -Xverifyopt:[no]checkmon\n"); |
| 797 | UsageMessage(stream, " -Xcheckdexsum\n"); |
| 798 | UsageMessage(stream, " -Xincludeselectedop\n"); |
| 799 | UsageMessage(stream, " -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*\n"); |
| 800 | UsageMessage(stream, " -Xincludeselectedmethod\n"); |
| 801 | UsageMessage(stream, " -Xjitthreshold:integervalue\n"); |
| 802 | UsageMessage(stream, " -Xjitcodecachesize:decimalvalueofkbytes\n"); |
| 803 | UsageMessage(stream, " -Xjitblocking\n"); |
| 804 | UsageMessage(stream, " -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\\;replace)\n"); |
| 805 | UsageMessage(stream, " -Xjitclass:classname[,classname]*\n"); |
| 806 | UsageMessage(stream, " -Xjitoffset:offset[,offset]\n"); |
| 807 | UsageMessage(stream, " -Xjitconfig:filename\n"); |
| 808 | UsageMessage(stream, " -Xjitcheckcg\n"); |
| 809 | UsageMessage(stream, " -Xjitverbose\n"); |
| 810 | UsageMessage(stream, " -Xjitprofile\n"); |
| 811 | UsageMessage(stream, " -Xjitdisableopt\n"); |
| 812 | UsageMessage(stream, " -Xjitsuspendpoll\n"); |
| 813 | UsageMessage(stream, " -XX:mainThreadStackSize=N\n"); |
| 814 | UsageMessage(stream, "\n"); |
| 815 | |
| 816 | Exit((error) ? 1 : 0); |
| 817 | } |
| 818 | |
| 819 | bool ParsedOptions::ParseStringAfterChar(const std::string& s, char c, std::string* parsed_value) { |
| 820 | std::string::size_type colon = s.find(c); |
| 821 | if (colon == std::string::npos) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 822 | Usage("Missing char %c in option %s\n", c, s.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 823 | return false; |
| 824 | } |
| 825 | // Add one to remove the char we were trimming until. |
| 826 | *parsed_value = s.substr(colon + 1); |
| 827 | return true; |
| 828 | } |
| 829 | |
| 830 | bool ParsedOptions::ParseInteger(const std::string& s, char after_char, int* parsed_value) { |
| 831 | std::string::size_type colon = s.find(after_char); |
| 832 | if (colon == std::string::npos) { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 833 | 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] | 834 | return false; |
| 835 | } |
| 836 | const char* begin = &s[colon + 1]; |
| 837 | char* end; |
| 838 | size_t result = strtoul(begin, &end, 10); |
| 839 | if (begin == end || *end != '\0') { |
Brian Carlstrom | 4ad33b3 | 2014-04-18 14:18:41 -0700 | [diff] [blame] | 840 | Usage("Failed to parse integer from %s\n", s.c_str()); |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 841 | return false; |
| 842 | } |
| 843 | *parsed_value = result; |
| 844 | return true; |
| 845 | } |
| 846 | |
| 847 | bool ParsedOptions::ParseUnsignedInteger(const std::string& s, char after_char, |
| 848 | unsigned int* parsed_value) { |
| 849 | int i; |
| 850 | if (!ParseInteger(s, after_char, &i)) { |
| 851 | return false; |
| 852 | } |
| 853 | if (i < 0) { |
Mathieu Chartier | 455820e | 2014-04-18 12:02:39 -0700 | [diff] [blame] | 854 | 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] | 855 | return false; |
| 856 | } |
| 857 | *parsed_value = i; |
| 858 | return true; |
| 859 | } |
| 860 | |
| 861 | bool ParsedOptions::ParseDouble(const std::string& option, char after_char, |
| 862 | double min, double max, double* parsed_value) { |
| 863 | std::string substring; |
| 864 | if (!ParseStringAfterChar(option, after_char, &substring)) { |
| 865 | return false; |
| 866 | } |
Dave Allison | 999385c | 2014-05-20 15:16:02 -0700 | [diff] [blame] | 867 | bool sane_val = true; |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 868 | double value; |
Dave Allison | 999385c | 2014-05-20 15:16:02 -0700 | [diff] [blame] | 869 | if (false) { |
| 870 | // TODO: this doesn't seem to work on the emulator. b/15114595 |
| 871 | std::stringstream iss(substring); |
| 872 | iss >> value; |
| 873 | // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range. |
| 874 | sane_val = iss.eof() && (value >= min) && (value <= max); |
| 875 | } else { |
| 876 | char* end = nullptr; |
| 877 | value = strtod(substring.c_str(), &end); |
| 878 | sane_val = *end == '\0' && value >= min && value <= max; |
| 879 | } |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 880 | if (!sane_val) { |
Mathieu Chartier | 455820e | 2014-04-18 12:02:39 -0700 | [diff] [blame] | 881 | 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] | 882 | return false; |
| 883 | } |
| 884 | *parsed_value = value; |
| 885 | return true; |
| 886 | } |
| 887 | |
| 888 | } // namespace art |