1/*
2 * Copyright (C) 2011-2016 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef Options_h
27#define Options_h
28
29#include "GCLogging.h"
30#include "JSExportMacros.h"
31#include <stdint.h>
32#include <stdio.h>
33#include <wtf/PrintStream.h>
34#include <wtf/StdLibExtras.h>
35
36namespace WTF {
37class StringBuilder;
38}
39using WTF::StringBuilder;
40
41namespace JSC {
42
43// How do JSC VM options work?
44// ===========================
45// The JSC_OPTIONS() macro below defines a list of all JSC options in use,
46// along with their types and default values. The options values are actually
47// realized as an array of Options::Entry elements.
48//
49// Options::initialize() will initialize the array of options values with
50// the defaults specified in JSC_OPTIONS() below. After that, the values can
51// be programmatically read and written to using an accessor method with the
52// same name as the option. For example, the option "useJIT" can be read and
53// set like so:
54//
55// bool jitIsOn = Options::useJIT(); // Get the option value.
56// Options::useJIT() = false; // Sets the option value.
57//
58// If you want to tweak any of these values programmatically for testing
59// purposes, you can do so in Options::initialize() after the default values
60// are set.
61//
62// Alternatively, you can override the default values by specifying
63// environment variables of the form: JSC_<name of JSC option>.
64//
65// Note: Options::initialize() tries to ensure some sanity on the option values
66// which are set by doing some range checks, and value corrections. These
67// checks are done after the option values are set. If you alter the option
68// values after the sanity checks (for your own testing), then you're liable to
69// ensure that the new values set are sane and reasonable for your own run.
70
71class OptionRange {
72private:
73 enum RangeState { Uninitialized, InitError, Normal, Inverted };
74public:
75 OptionRange& operator= (const int& rhs)
76 { // Only needed for initialization
77 if (!rhs) {
78 m_state = Uninitialized;
79 m_rangeString = 0;
80 m_lowLimit = 0;
81 m_highLimit = 0;
82 }
83 return *this;
84 }
85
86 bool init(const char*);
87 bool isInRange(unsigned);
88 const char* rangeString() const { return (m_state > InitError) ? m_rangeString : s_nullRangeStr; }
89
90 void dump(PrintStream& out) const;
91
92private:
93 static const char* const s_nullRangeStr;
94
95 RangeState m_state;
96 const char* m_rangeString;
97 unsigned m_lowLimit;
98 unsigned m_highLimit;
99};
100
101typedef OptionRange optionRange;
102typedef const char* optionString;
103
104#define JSC_OPTIONS(v) \
105 v(bool, validateOptions, false, "crashes if mis-typed JSC options were passed to the VM") \
106 v(unsigned, dumpOptions, 0, "dumps JSC options (0 = None, 1 = Overridden only, 2 = All, 3 = Verbose)") \
107 \
108 v(bool, useLLInt, true, "allows the LLINT to be used if true") \
109 v(bool, useJIT, true, "allows the baseline JIT to be used if true") \
110 v(bool, useDFGJIT, true, "allows the DFG JIT to be used if true") \
111 v(bool, useRegExpJIT, true, "allows the RegExp JIT to be used if true") \
112 \
113 v(bool, reportMustSucceedExecutableAllocations, false, nullptr) \
114 \
115 v(unsigned, maxPerThreadStackUsage, 4 * MB, nullptr) \
116 v(unsigned, reservedZoneSize, 128 * KB, nullptr) \
117 v(unsigned, errorModeReservedZoneSize, 64 * KB, nullptr) \
118 \
119 v(bool, crashIfCantAllocateJITMemory, false, nullptr) \
120 v(unsigned, jitMemoryReservationSize, 0, "Set this number to change the executable allocation size in ExecutableAllocatorFixedVMPool. (In bytes.)") \
121 \
122 v(bool, forceCodeBlockLiveness, false, nullptr) \
123 v(bool, forceICFailure, false, nullptr) \
124 \
125 v(unsigned, repatchCountForCoolDown, 10, nullptr) \
126 v(unsigned, initialCoolDownCount, 20, nullptr) \
127 \
128 v(bool, dumpGeneratedBytecodes, false, nullptr) \
129 v(bool, dumpBytecodeLivenessResults, false, nullptr) \
130 v(bool, validateBytecode, false, nullptr) \
131 v(bool, forceDebuggerBytecodeGeneration, false, nullptr) \
132 v(bool, forceProfilerBytecodeGeneration, false, nullptr) \
133 \
134 v(bool, useFunctionDotArguments, true, nullptr) \
135 v(bool, useTailCalls, true, nullptr) \
136 \
137 /* dumpDisassembly implies dumpDFGDisassembly. */ \
138 v(bool, dumpDisassembly, false, "dumps disassembly of all JIT compiled code upon compilation") \
139 v(bool, asyncDisassembly, false, nullptr) \
140 v(bool, dumpDFGDisassembly, false, "dumps disassembly of DFG function upon compilation") \
141 v(bool, dumpFTLDisassembly, false, "dumps disassembly of FTL function upon compilation") \
142 v(bool, dumpAllDFGNodes, false, nullptr) \
143 v(optionRange, bytecodeRangeToDFGCompile, 0, "bytecode size range to allow DFG compilation on, e.g. 1:100") \
144 v(optionRange, bytecodeRangeToFTLCompile, 0, "bytecode size range to allow FTL compilation on, e.g. 1:100") \
145 v(optionString, dfgWhitelist, nullptr, "file with list of function signatures to allow DFG compilation on") \
146 v(bool, dumpSourceAtDFGTime, false, "dumps source code of JS function being DFG compiled") \
147 v(bool, dumpBytecodeAtDFGTime, false, "dumps bytecode of JS function being DFG compiled") \
148 v(bool, dumpGraphAfterParsing, false, nullptr) \
149 v(bool, dumpGraphAtEachPhase, false, nullptr) \
150 v(bool, dumpDFGGraphAtEachPhase, false, "dumps the DFG graph at each phase DFG of complitaion (note this excludes DFG graphs during FTL compilation)") \
151 v(bool, dumpDFGFTLGraphAtEachPhase, false, "dumps the DFG graph at each phase DFG of complitaion when compiling FTL code") \
152 v(bool, dumpB3GraphAtEachPhase, false, "dumps the B3 graph at each phase of compilation") \
153 v(bool, dumpAirGraphAtEachPhase, false, "dumps the Air graph at each phase of compilation") \
154 v(bool, verboseDFGByteCodeParsing, false, nullptr) \
155 v(bool, verboseCompilation, false, nullptr) \
156 v(bool, verboseFTLCompilation, false, nullptr) \
157 v(bool, logCompilationChanges, false, nullptr) \
158 v(bool, printEachOSRExit, false, nullptr) \
159 v(bool, validateGraph, false, nullptr) \
160 v(bool, validateGraphAtEachPhase, false, nullptr) \
161 v(bool, verboseValidationFailure, false, nullptr) \
162 v(bool, verboseOSR, false, nullptr) \
163 v(bool, verboseFTLOSRExit, false, nullptr) \
164 v(bool, verboseCallLink, false, nullptr) \
165 v(bool, verboseCompilationQueue, false, nullptr) \
166 v(bool, reportCompileTimes, false, "dumps JS function signature and the time it took to compile") \
167 v(bool, reportFTLCompileTimes, false, "dumps JS function signature and the time it took to FTL compile") \
168 v(bool, reportTotalCompileTimes, false, nullptr) \
169 v(bool, verboseCFA, false, nullptr) \
170 v(bool, verboseFTLToJSThunk, false, nullptr) \
171 v(bool, verboseFTLFailure, false, nullptr) \
172 v(bool, alwaysComputeHash, false, nullptr) \
173 v(bool, testTheFTL, false, nullptr) \
174 v(bool, verboseSanitizeStack, false, nullptr) \
175 v(bool, useGenerationalGC, true, nullptr) \
176 v(bool, eagerlyUpdateTopCallFrame, false, nullptr) \
177 \
178 v(bool, useOSREntryToDFG, true, nullptr) \
179 v(bool, useOSREntryToFTL, true, nullptr) \
180 \
181 v(bool, useFTLJIT, true, "allows the FTL JIT to be used if true") \
182 v(bool, useFTLTBAA, true, nullptr) \
183 v(bool, validateFTLOSRExitLiveness, false, nullptr) \
184 v(bool, b3AlwaysFailsBeforeCompile, false, nullptr) \
185 v(bool, b3AlwaysFailsBeforeLink, false, nullptr) \
186 v(bool, ftlCrashes, false, nullptr) /* fool-proof way of checking that you ended up in the FTL. ;-) */\
187 v(bool, clobberAllRegsInFTLICSlowPath, !ASSERT_DISABLED, nullptr) \
188 v(bool, useAccessInlining, true, nullptr) \
189 v(unsigned, maxAccessVariantListSize, 8, nullptr) \
190 v(bool, usePolyvariantDevirtualization, true, nullptr) \
191 v(bool, usePolymorphicAccessInlining, true, nullptr) \
192 v(bool, usePolymorphicCallInlining, true, nullptr) \
193 v(unsigned, maxPolymorphicCallVariantListSize, 15, nullptr) \
194 v(unsigned, maxPolymorphicCallVariantListSizeForTopTier, 5, nullptr) \
195 v(unsigned, maxPolymorphicCallVariantsForInlining, 5, nullptr) \
196 v(unsigned, frequentCallThreshold, 2, nullptr) \
197 v(double, minimumCallToKnownRate, 0.51, nullptr) \
198 v(bool, createPreHeaders, true, nullptr) \
199 v(bool, useMovHintRemoval, true, nullptr) \
200 v(bool, usePutStackSinking, true, nullptr) \
201 v(bool, useObjectAllocationSinking, true, nullptr) \
202 v(bool, useCopyBarrierOptimization, true, nullptr) \
203 \
204 v(bool, useConcurrentJIT, true, "allows the DFG / FTL compilation in threads other than the executing JS thread") \
205 v(unsigned, numberOfDFGCompilerThreads, computeNumberOfWorkerThreads(2, 2) - 1, nullptr) \
206 v(unsigned, numberOfFTLCompilerThreads, computeNumberOfWorkerThreads(8, 2) - 1, nullptr) \
207 v(int32, priorityDeltaOfDFGCompilerThreads, computePriorityDeltaOfWorkerThreads(-1, 0), nullptr) \
208 v(int32, priorityDeltaOfFTLCompilerThreads, computePriorityDeltaOfWorkerThreads(-2, 0), nullptr) \
209 \
210 v(bool, useProfiler, false, nullptr) \
211 \
212 v(bool, useArchitectureSpecificOptimizations, true, nullptr) \
213 \
214 v(bool, breakOnThrow, false, nullptr) \
215 \
216 v(unsigned, maximumOptimizationCandidateInstructionCount, 100000, nullptr) \
217 \
218 v(unsigned, maximumFunctionForCallInlineCandidateInstructionCount, 180, nullptr) \
219 v(unsigned, maximumFunctionForClosureCallInlineCandidateInstructionCount, 100, nullptr) \
220 v(unsigned, maximumFunctionForConstructInlineCandidateInstructionCount, 100, nullptr) \
221 \
222 v(unsigned, maximumFTLCandidateInstructionCount, 20000, nullptr) \
223 \
224 /* Depth of inline stack, so 1 = no inlining, 2 = one level, etc. */ \
225 v(unsigned, maximumInliningDepth, 5, "maximum allowed inlining depth. Depth of 1 means no inlining") \
226 v(unsigned, maximumInliningRecursion, 2, nullptr) \
227 \
228 /* Maximum size of a caller for enabling inlining. This is purely to protect us */\
229 /* from super long compiles that take a lot of memory. */\
230 v(unsigned, maximumInliningCallerSize, 10000, nullptr) \
231 \
232 v(unsigned, maximumVarargsForInlining, 100, nullptr) \
233 \
234 v(bool, usePolyvariantCallInlining, true, nullptr) \
235 v(bool, usePolyvariantByIdInlining, true, nullptr) \
236 \
237 v(bool, useMaximalFlushInsertionPhase, false, "Setting to true allows the DFG's MaximalFlushInsertionPhase to run.") \
238 \
239 v(unsigned, maximumBinaryStringSwitchCaseLength, 50, nullptr) \
240 v(unsigned, maximumBinaryStringSwitchTotalLength, 2000, nullptr) \
241 \
242 v(double, jitPolicyScale, 1.0, "scale JIT thresholds to this specified ratio between 0.0 (compile ASAP) and 1.0 (compile like normal).") \
243 v(bool, forceEagerCompilation, false, nullptr) \
244 v(int32, thresholdForJITAfterWarmUp, 500, nullptr) \
245 v(int32, thresholdForJITSoon, 100, nullptr) \
246 \
247 v(int32, thresholdForOptimizeAfterWarmUp, 1000, nullptr) \
248 v(int32, thresholdForOptimizeAfterLongWarmUp, 1000, nullptr) \
249 v(int32, thresholdForOptimizeSoon, 1000, nullptr) \
250 v(int32, executionCounterIncrementForLoop, 1, nullptr) \
251 v(int32, executionCounterIncrementForEntry, 15, nullptr) \
252 \
253 v(int32, thresholdForFTLOptimizeAfterWarmUp, 100000, nullptr) \
254 v(int32, thresholdForFTLOptimizeSoon, 1000, nullptr) \
255 v(int32, ftlTierUpCounterIncrementForLoop, 1, nullptr) \
256 v(int32, ftlTierUpCounterIncrementForReturn, 15, nullptr) \
257 v(unsigned, ftlOSREntryFailureCountForReoptimization, 15, nullptr) \
258 v(unsigned, ftlOSREntryRetryThreshold, 100, nullptr) \
259 \
260 v(int32, evalThresholdMultiplier, 10, nullptr) \
261 v(unsigned, maximumEvalCacheableSourceLength, 256, nullptr) \
262 \
263 v(bool, randomizeExecutionCountsBetweenCheckpoints, false, nullptr) \
264 v(int32, maximumExecutionCountsBetweenCheckpointsForBaseline, 1000, nullptr) \
265 v(int32, maximumExecutionCountsBetweenCheckpointsForUpperTiers, 50000, nullptr) \
266 \
267 v(unsigned, likelyToTakeSlowCaseMinimumCount, 20, nullptr) \
268 v(unsigned, couldTakeSlowCaseMinimumCount, 10, nullptr) \
269 \
270 v(unsigned, osrExitCountForReoptimization, 100, nullptr) \
271 v(unsigned, osrExitCountForReoptimizationFromLoop, 5, nullptr) \
272 \
273 v(unsigned, reoptimizationRetryCounterMax, 0, nullptr) \
274 \
275 v(bool, assertICSizing, false, "crash if estimated IC sizes are inadequate") \
276 v(bool, dumpFailedICSizing, false, "dumps a log entry if estimated IC sizes are inadequate") \
277 \
278 v(unsigned, minimumOptimizationDelay, 1, nullptr) \
279 v(unsigned, maximumOptimizationDelay, 5, nullptr) \
280 v(double, desiredProfileLivenessRate, 0.75, nullptr) \
281 v(double, desiredProfileFullnessRate, 0.35, nullptr) \
282 \
283 v(double, doubleVoteRatioForDoubleFormat, 2, nullptr) \
284 v(double, structureCheckVoteRatioForHoisting, 1, nullptr) \
285 v(double, checkArrayVoteRatioForHoisting, 1, nullptr) \
286 \
287 v(unsigned, minimumNumberOfScansBetweenRebalance, 100, nullptr) \
288 v(unsigned, numberOfGCMarkers, computeNumberOfGCMarkers(7), nullptr) \
289 v(unsigned, opaqueRootMergeThreshold, 1000, nullptr) \
290 v(double, minHeapUtilization, 0.8, nullptr) \
291 v(double, minCopiedBlockUtilization, 0.9, nullptr) \
292 v(double, minMarkedBlockUtilization, 0.9, nullptr) \
293 v(unsigned, slowPathAllocsBetweenGCs, 0, "force a GC on every Nth slow path alloc, where N is specified by this option") \
294 \
295 v(double, percentCPUPerMBForFullTimer, 0.0003125, nullptr) \
296 v(double, percentCPUPerMBForEdenTimer, 0.0025, nullptr) \
297 v(double, collectionTimerMaxPercentCPU, 0.05, nullptr) \
298 \
299 v(bool, forceWeakRandomSeed, false, nullptr) \
300 v(unsigned, forcedWeakRandomSeed, 0, nullptr) \
301 \
302 v(bool, useZombieMode, false, "debugging option to scribble over dead objects with 0xdeadbeef") \
303 v(bool, useImmortalObjects, false, "debugging option to keep all objects alive forever") \
304 v(bool, dumpObjectStatistics, false, nullptr) \
305 \
306 v(gcLogLevel, logGC, GCLogging::None, "debugging option to log GC activity (0 = None, 1 = Basic, 2 = Verbose)") \
307 v(bool, useGC, true, nullptr) \
308 v(bool, gcAtEnd, false, "If true, the jsc CLI will do a GC before exiting") \
309 v(bool, forceGCSlowPaths, false, "If true, we will force all JIT fast allocations down their slow paths.")\
310 v(unsigned, gcMaxHeapSize, 0, nullptr) \
311 v(unsigned, forceRAMSize, 0, nullptr) \
312 v(bool, recordGCPauseTimes, false, nullptr) \
313 v(bool, logHeapStatisticsAtExit, false, nullptr) \
314 v(bool, useTypeProfiler, false, nullptr) \
315 v(bool, useControlFlowProfiler, false, nullptr) \
316 v(bool, useSamplingProfiler, false, nullptr) \
317 v(bool, alwaysGeneratePCToCodeOriginMap, false, "This will make sure we always generate a PCToCodeOriginMap for JITed code.") \
318 \
319 v(bool, verifyHeap, false, nullptr) \
320 v(unsigned, numberOfGCCyclesToRecordForVerification, 3, nullptr) \
321 \
322 v(bool, useExceptionFuzz, false, nullptr) \
323 v(unsigned, fireExceptionFuzzAt, 0, nullptr) \
324 v(bool, validateDFGExceptionHandling, false, "Causes the DFG to emit code validating exception handling for each node that can exit") /* This is true by default on Debug builds */\
325 \
326 v(bool, useExecutableAllocationFuzz, false, nullptr) \
327 v(unsigned, fireExecutableAllocationFuzzAt, 0, nullptr) \
328 v(unsigned, fireExecutableAllocationFuzzAtOrAfter, 0, nullptr) \
329 v(bool, verboseExecutableAllocationFuzz, false, nullptr) \
330 \
331 v(bool, useOSRExitFuzz, false, nullptr) \
332 v(unsigned, fireOSRExitFuzzAtStatic, 0, nullptr) \
333 v(unsigned, fireOSRExitFuzzAt, 0, nullptr) \
334 v(unsigned, fireOSRExitFuzzAtOrAfter, 0, nullptr) \
335 \
336 v(bool, logB3PhaseTimes, false, nullptr) \
337 v(double, rareBlockPenalty, 0.001, nullptr) \
338 v(bool, airSpillsEverything, false, nullptr) \
339 v(bool, logAirRegisterPressure, false, nullptr) \
340 v(unsigned, maxB3TailDupBlockSize, 3, nullptr) \
341 v(unsigned, maxB3TailDupBlockSuccessors, 3, nullptr) \
342 \
343 v(bool, useDollarVM, false, "installs the $vm debugging tool in global objects") \
344 v(optionString, functionOverrides, nullptr, "file with debugging overrides for function bodies") \
345 \
346 v(unsigned, watchdog, 0, "watchdog timeout (0 = Disabled, N = a timeout period of N milliseconds)") \
347 \
348 v(bool, dumpModuleRecord, false, nullptr) \
349 v(bool, dumpModuleLoadingState, false, nullptr) \
350 v(bool, exposeInternalModuleLoader, false, "expose the internal module loader object to the global space for debugging") \
351
352enum OptionEquivalence {
353 SameOption,
354 InvertedOption,
355};
356
357#define JSC_ALIASED_OPTIONS(v) \
358 v(enableFunctionDotArguments, useFunctionDotArguments, SameOption) \
359 v(enableTailCalls, useTailCalls, SameOption) \
360 v(showDisassembly, dumpDisassembly, SameOption) \
361 v(showDFGDisassembly, dumpDFGDisassembly, SameOption) \
362 v(showFTLDisassembly, dumpFTLDisassembly, SameOption) \
363 v(showAllDFGNodes, dumpAllDFGNodes, SameOption) \
364 v(alwaysDoFullCollection, useGenerationalGC, InvertedOption) \
365 v(enableOSREntryToDFG, useOSREntryToDFG, SameOption) \
366 v(enableOSREntryToFTL, useOSREntryToFTL, SameOption) \
367 v(enableAccessInlining, useAccessInlining, SameOption) \
368 v(enablePolyvariantDevirtualization, usePolyvariantDevirtualization, SameOption) \
369 v(enablePolymorphicAccessInlining, usePolymorphicAccessInlining, SameOption) \
370 v(enablePolymorphicCallInlining, usePolymorphicCallInlining, SameOption) \
371 v(enableMovHintRemoval, useMovHintRemoval, SameOption) \
372 v(enableObjectAllocationSinking, useObjectAllocationSinking, SameOption) \
373 v(enableCopyBarrierOptimization, useCopyBarrierOptimization, SameOption) \
374 v(enableConcurrentJIT, useConcurrentJIT, SameOption) \
375 v(enableProfiler, useProfiler, SameOption) \
376 v(enableArchitectureSpecificOptimizations, useArchitectureSpecificOptimizations, SameOption) \
377 v(enablePolyvariantCallInlining, usePolyvariantCallInlining, SameOption) \
378 v(enablePolyvariantByIdInlining, usePolyvariantByIdInlining, SameOption) \
379 v(enableMaximalFlushInsertionPhase, useMaximalFlushInsertionPhase, SameOption) \
380 v(objectsAreImmortal, useImmortalObjects, SameOption) \
381 v(showObjectStatistics, dumpObjectStatistics, SameOption) \
382 v(disableGC, useGC, InvertedOption) \
383 v(enableTypeProfiler, useTypeProfiler, SameOption) \
384 v(enableControlFlowProfiler, useControlFlowProfiler, SameOption) \
385 v(enableExceptionFuzz, useExceptionFuzz, SameOption) \
386 v(enableExecutableAllocationFuzz, useExecutableAllocationFuzz, SameOption) \
387 v(enableOSRExitFuzz, useOSRExitFuzz, SameOption) \
388 v(enableDollarVM, useDollarVM, SameOption) \
389
390class Options {
391public:
392 enum class DumpLevel {
393 None = 0,
394 Overridden,
395 All,
396 Verbose
397 };
398
399 // This typedef is to allow us to eliminate the '_' in the field name in
400 // union inside Entry. This is needed to keep the style checker happy.
401 typedef int32_t int32;
402
403 // Declare the option IDs:
404 enum OptionID {
405#define FOR_EACH_OPTION(type_, name_, defaultValue_, description_) \
406 name_##ID,
407 JSC_OPTIONS(FOR_EACH_OPTION)
408#undef FOR_EACH_OPTION
409 numberOfOptions
410 };
411
412 enum class Type {
413 boolType,
414 unsignedType,
415 doubleType,
416 int32Type,
417 optionRangeType,
418 optionStringType,
419 gcLogLevelType,
420 };
421
422 JS_EXPORT_PRIVATE static void initialize();
423
424 // Parses a string of options where each option is of the format "--<optionName>=<value>"
425 // and are separated by a space. The leading "--" is optional and will be ignored.
426 JS_EXPORT_PRIVATE static bool setOptions(const char* optionsList);
427
428 // Parses a single command line option in the format "<optionName>=<value>"
429 // (no spaces allowed) and set the specified option if appropriate.
430 JS_EXPORT_PRIVATE static bool setOption(const char* arg);
431
432 JS_EXPORT_PRIVATE static void dumpAllOptions(FILE*, DumpLevel, const char* title = nullptr);
433 JS_EXPORT_PRIVATE static void dumpAllOptionsInALine(StringBuilder&);
434
435 JS_EXPORT_PRIVATE static void ensureOptionsAreCoherent();
436
437 // Declare accessors for each option:
438#define FOR_EACH_OPTION(type_, name_, defaultValue_, description_) \
439 ALWAYS_INLINE static type_& name_() { return s_options[name_##ID].type_##Val; } \
440 ALWAYS_INLINE static type_& name_##Default() { return s_defaultOptions[name_##ID].type_##Val; }
441
442 JSC_OPTIONS(FOR_EACH_OPTION)
443#undef FOR_EACH_OPTION
444
445private:
446 // For storing for an option value:
447 union Entry {
448 bool boolVal;
449 unsigned unsignedVal;
450 double doubleVal;
451 int32 int32Val;
452 OptionRange optionRangeVal;
453 const char* optionStringVal;
454 GCLogging::Level gcLogLevelVal;
455 };
456
457 // For storing constant meta data about each option:
458 struct EntryInfo {
459 const char* name;
460 const char* description;
461 Type type;
462 };
463
464 Options();
465
466 enum DumpDefaultsOption {
467 DontDumpDefaults,
468 DumpDefaults
469 };
470 static void dumpOptionsIfNeeded();
471 static void dumpAllOptions(StringBuilder&, DumpLevel, const char* title,
472 const char* separator, const char* optionHeader, const char* optionFooter, DumpDefaultsOption);
473 static void dumpOption(StringBuilder&, DumpLevel, OptionID,
474 const char* optionHeader, const char* optionFooter, DumpDefaultsOption);
475
476 static bool setOptionWithoutAlias(const char* arg);
477 static bool setAliasedOption(const char* arg);
478 static bool overrideAliasedOptionWithHeuristic(const char* name);
479
480 // Declare the singleton instance of the options store:
481 JS_EXPORTDATA static Entry s_options[numberOfOptions];
482 static Entry s_defaultOptions[numberOfOptions];
483 static const EntryInfo s_optionsInfo[numberOfOptions];
484
485 friend class Option;
486};
487
488class Option {
489public:
490 Option(Options::OptionID id)
491 : m_id(id)
492 , m_entry(Options::s_options[m_id])
493 {
494 }
495
496 void dump(StringBuilder&) const;
497
498 bool operator==(const Option& other) const;
499 bool operator!=(const Option& other) const { return !(*this == other); }
500
501 const char* name() const;
502 const char* description() const;
503 Options::Type type() const;
504 bool isOverridden() const;
505 const Option defaultOption() const;
506
507 bool& boolVal();
508 unsigned& unsignedVal();
509 double& doubleVal();
510 int32_t& int32Val();
511 OptionRange optionRangeVal();
512 const char* optionStringVal();
513 GCLogging::Level& gcLogLevelVal();
514
515private:
516 // Only used for constructing default Options.
517 Option(Options::OptionID id, Options::Entry& entry)
518 : m_id(id)
519 , m_entry(entry)
520 {
521 }
522
523 Options::OptionID m_id;
524 Options::Entry& m_entry;
525};
526
527inline const char* Option::name() const
528{
529 return Options::s_optionsInfo[m_id].name;
530}
531
532inline const char* Option::description() const
533{
534 return Options::s_optionsInfo[m_id].description;
535}
536
537inline Options::Type Option::type() const
538{
539 return Options::s_optionsInfo[m_id].type;
540}
541
542inline bool Option::isOverridden() const
543{
544 return *this != defaultOption();
545}
546
547inline const Option Option::defaultOption() const
548{
549 return Option(m_id, Options::s_defaultOptions[m_id]);
550}
551
552inline bool& Option::boolVal()
553{
554 return m_entry.boolVal;
555}
556
557inline unsigned& Option::unsignedVal()
558{
559 return m_entry.unsignedVal;
560}
561
562inline double& Option::doubleVal()
563{
564 return m_entry.doubleVal;
565}
566
567inline int32_t& Option::int32Val()
568{
569 return m_entry.int32Val;
570}
571
572inline OptionRange Option::optionRangeVal()
573{
574 return m_entry.optionRangeVal;
575}
576
577inline const char* Option::optionStringVal()
578{
579 return m_entry.optionStringVal;
580}
581
582inline GCLogging::Level& Option::gcLogLevelVal()
583{
584 return m_entry.gcLogLevelVal;
585}
586
587} // namespace JSC
588
589#endif // Options_h
590