1/*
2 * Copyright (C) 2011-2019 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#pragma once
27
28#include "GCLogging.h"
29#include "JSExportMacros.h"
30#include <stdint.h>
31#include <stdio.h>
32#include <wtf/PrintStream.h>
33#include <wtf/StdLibExtras.h>
34
35namespace WTF {
36class StringBuilder;
37}
38using WTF::StringBuilder;
39
40namespace JSC {
41
42// How do JSC VM options work?
43// ===========================
44// The JSC_OPTIONS() macro below defines a list of all JSC options in use,
45// along with their types and default values. The options values are actually
46// realized as an array of Options::Entry elements.
47//
48// Options::initialize() will initialize the array of options values with
49// the defaults specified in JSC_OPTIONS() below. After that, the values can
50// be programmatically read and written to using an accessor method with the
51// same name as the option. For example, the option "useJIT" can be read and
52// set like so:
53//
54// bool jitIsOn = Options::useJIT(); // Get the option value.
55// Options::useJIT() = false; // Sets the option value.
56//
57// If you want to tweak any of these values programmatically for testing
58// purposes, you can do so in Options::initialize() after the default values
59// are set.
60//
61// Alternatively, you can override the default values by specifying
62// environment variables of the form: JSC_<name of JSC option>.
63//
64// Note: Options::initialize() tries to ensure some sanity on the option values
65// which are set by doing some range checks, and value corrections. These
66// checks are done after the option values are set. If you alter the option
67// values after the sanity checks (for your own testing), then you're liable to
68// ensure that the new values set are sane and reasonable for your own run.
69
70class OptionRange {
71private:
72 enum RangeState { Uninitialized, InitError, Normal, Inverted };
73public:
74 OptionRange& operator= (const int& rhs)
75 { // Only needed for initialization
76 if (!rhs) {
77 m_state = Uninitialized;
78 m_rangeString = 0;
79 m_lowLimit = 0;
80 m_highLimit = 0;
81 }
82 return *this;
83 }
84
85 bool init(const char*);
86 bool isInRange(unsigned);
87 const char* rangeString() const { return (m_state > InitError) ? m_rangeString : s_nullRangeStr; }
88
89 void dump(PrintStream& out) const;
90
91private:
92 static const char* const s_nullRangeStr;
93
94 RangeState m_state;
95 const char* m_rangeString;
96 unsigned m_lowLimit;
97 unsigned m_highLimit;
98};
99
100typedef OptionRange optionRange;
101typedef const char* optionString;
102
103#if PLATFORM(IOS_FAMILY)
104#define MAXIMUM_NUMBER_OF_FTL_COMPILER_THREADS 2
105#else
106#define MAXIMUM_NUMBER_OF_FTL_COMPILER_THREADS 8
107#endif
108
109#if ENABLE(EXPERIMENTAL_FEATURES)
110constexpr bool enableIntlNumberFormatToParts = true;
111#else
112constexpr bool enableIntlNumberFormatToParts = false;
113#endif
114
115#if ENABLE(EXPERIMENTAL_FEATURES)
116constexpr bool enableIntlPluralRules = true;
117#else
118constexpr bool enableIntlPluralRules = false;
119#endif
120
121#if ENABLE(WEBASSEMBLY_STREAMING_API)
122constexpr bool enableWebAssemblyStreamingApi = true;
123#else
124constexpr bool enableWebAssemblyStreamingApi = false;
125#endif
126
127#define JSC_OPTIONS(v) \
128 v(bool, validateOptions, false, Normal, "crashes if mis-typed JSC options were passed to the VM") \
129 v(unsigned, dumpOptions, 0, Normal, "dumps JSC options (0 = None, 1 = Overridden only, 2 = All, 3 = Verbose)") \
130 v(optionString, configFile, nullptr, Normal, "file to configure JSC options and logging location") \
131 \
132 v(bool, useLLInt, true, Normal, "allows the LLINT to be used if true") \
133 v(bool, useJIT, jitEnabledByDefault(), Normal, "allows the executable pages to be allocated for JIT and thunks if true") \
134 v(bool, useBaselineJIT, true, Normal, "allows the baseline JIT to be used if true") \
135 v(bool, useDFGJIT, true, Normal, "allows the DFG JIT to be used if true") \
136 v(bool, useRegExpJIT, jitEnabledByDefault(), Normal, "allows the RegExp JIT to be used if true") \
137 v(bool, useDOMJIT, is64Bit(), Normal, "allows the DOMJIT to be used if true") \
138 \
139 v(bool, reportMustSucceedExecutableAllocations, false, Normal, nullptr) \
140 \
141 v(unsigned, maxPerThreadStackUsage, 4 * MB, Normal, "Max allowed stack usage by the VM") \
142 v(unsigned, softReservedZoneSize, 128 * KB, Normal, "A buffer greater than reservedZoneSize that reserves space for stringifying exceptions.") \
143 v(unsigned, reservedZoneSize, 64 * KB, Normal, "The amount of stack space we guarantee to our clients (and to interal VM code that does not call out to clients).") \
144 \
145 v(bool, crashIfCantAllocateJITMemory, false, Normal, nullptr) \
146 v(unsigned, jitMemoryReservationSize, 0, Normal, "Set this number to change the executable allocation size in ExecutableAllocatorFixedVMPool. (In bytes.)") \
147 v(bool, useSeparatedWXHeap, false, Normal, nullptr) \
148 \
149 v(bool, forceCodeBlockLiveness, false, Normal, nullptr) \
150 v(bool, forceICFailure, false, Normal, nullptr) \
151 \
152 v(unsigned, repatchCountForCoolDown, 8, Normal, nullptr) \
153 v(unsigned, initialCoolDownCount, 20, Normal, nullptr) \
154 v(unsigned, repatchBufferingCountdown, 8, Normal, nullptr) \
155 \
156 v(bool, dumpGeneratedBytecodes, false, Normal, nullptr) \
157 v(bool, dumpBytecodeLivenessResults, false, Normal, nullptr) \
158 v(bool, validateBytecode, false, Normal, nullptr) \
159 v(bool, forceDebuggerBytecodeGeneration, false, Normal, nullptr) \
160 v(bool, dumpBytecodesBeforeGeneratorification, false, Normal, nullptr) \
161 \
162 v(bool, useFunctionDotArguments, true, Normal, nullptr) \
163 v(bool, useTailCalls, true, Normal, nullptr) \
164 v(bool, optimizeRecursiveTailCalls, true, Normal, nullptr) \
165 v(bool, alwaysUseShadowChicken, false, Normal, nullptr) \
166 v(unsigned, shadowChickenLogSize, 1000, Normal, nullptr) \
167 v(unsigned, shadowChickenMaxTailDeletedFramesSize, 128, Normal, nullptr) \
168 \
169 /* dumpDisassembly implies dumpDFGDisassembly. */ \
170 v(bool, dumpDisassembly, false, Normal, "dumps disassembly of all JIT compiled code upon compilation") \
171 v(bool, asyncDisassembly, false, Normal, nullptr) \
172 v(bool, dumpDFGDisassembly, false, Normal, "dumps disassembly of DFG function upon compilation") \
173 v(bool, dumpFTLDisassembly, false, Normal, "dumps disassembly of FTL function upon compilation") \
174 v(bool, dumpRegExpDisassembly, false, Normal, "dumps disassembly of RegExp upon compilation") \
175 v(bool, dumpAllDFGNodes, false, Normal, nullptr) \
176 v(bool, logJITCodeForPerf, false, Configurable, nullptr) \
177 v(optionRange, bytecodeRangeToJITCompile, 0, Normal, "bytecode size range to allow compilation on, e.g. 1:100") \
178 v(optionRange, bytecodeRangeToDFGCompile, 0, Normal, "bytecode size range to allow DFG compilation on, e.g. 1:100") \
179 v(optionRange, bytecodeRangeToFTLCompile, 0, Normal, "bytecode size range to allow FTL compilation on, e.g. 1:100") \
180 v(optionString, jitWhitelist, nullptr, Normal, "file with list of function signatures to allow compilation on") \
181 v(optionString, dfgWhitelist, nullptr, Normal, "file with list of function signatures to allow DFG compilation on") \
182 v(optionString, ftlWhitelist, nullptr, Normal, "file with list of function signatures to allow FTL compilation on") \
183 v(bool, dumpSourceAtDFGTime, false, Normal, "dumps source code of JS function being DFG compiled") \
184 v(bool, dumpBytecodeAtDFGTime, false, Normal, "dumps bytecode of JS function being DFG compiled") \
185 v(bool, dumpGraphAfterParsing, false, Normal, nullptr) \
186 v(bool, dumpGraphAtEachPhase, false, Normal, nullptr) \
187 v(bool, dumpDFGGraphAtEachPhase, false, Normal, "dumps the DFG graph at each phase of DFG compilation (note this excludes DFG graphs during FTL compilation)") \
188 v(bool, dumpDFGFTLGraphAtEachPhase, false, Normal, "dumps the DFG graph at each phase of DFG compilation when compiling FTL code") \
189 v(bool, dumpB3GraphAtEachPhase, false, Normal, "dumps the B3 graph at each phase of compilation") \
190 v(bool, dumpAirGraphAtEachPhase, false, Normal, "dumps the Air graph at each phase of compilation") \
191 v(bool, verboseDFGBytecodeParsing, false, Normal, nullptr) \
192 v(bool, safepointBeforeEachPhase, true, Normal, nullptr) \
193 v(bool, verboseCompilation, false, Normal, nullptr) \
194 v(bool, verboseFTLCompilation, false, Normal, nullptr) \
195 v(bool, logCompilationChanges, false, Normal, nullptr) \
196 v(bool, useProbeOSRExit, false, Normal, nullptr) \
197 v(bool, printEachOSRExit, false, Normal, nullptr) \
198 v(bool, validateGraph, false, Normal, nullptr) \
199 v(bool, validateGraphAtEachPhase, false, Normal, nullptr) \
200 v(bool, verboseValidationFailure, false, Normal, nullptr) \
201 v(bool, verboseOSR, false, Normal, nullptr) \
202 v(bool, verboseDFGOSRExit, false, Normal, nullptr) \
203 v(bool, verboseFTLOSRExit, false, Normal, nullptr) \
204 v(bool, verboseCallLink, false, Normal, nullptr) \
205 v(bool, verboseCompilationQueue, false, Normal, nullptr) \
206 v(bool, reportCompileTimes, false, Normal, "dumps JS function signature and the time it took to compile in all tiers") \
207 v(bool, reportBaselineCompileTimes, false, Normal, "dumps JS function signature and the time it took to BaselineJIT compile") \
208 v(bool, reportDFGCompileTimes, false, Normal, "dumps JS function signature and the time it took to DFG and FTL compile") \
209 v(bool, reportFTLCompileTimes, false, Normal, "dumps JS function signature and the time it took to FTL compile") \
210 v(bool, reportTotalCompileTimes, false, Normal, nullptr) \
211 v(bool, reportParseTimes, false, Normal, "dumps JS function signature and the time it took to parse") \
212 v(bool, reportBytecodeCompileTimes, false, Normal, "dumps JS function signature and the time it took to bytecode compile") \
213 v(bool, verboseExitProfile, false, Normal, nullptr) \
214 v(bool, verboseCFA, false, Normal, nullptr) \
215 v(bool, verboseDFGFailure, false, Normal, nullptr) \
216 v(bool, verboseFTLToJSThunk, false, Normal, nullptr) \
217 v(bool, verboseFTLFailure, false, Normal, nullptr) \
218 v(bool, alwaysComputeHash, false, Normal, nullptr) \
219 v(bool, testTheFTL, false, Normal, nullptr) \
220 v(bool, verboseSanitizeStack, false, Normal, nullptr) \
221 v(bool, useGenerationalGC, true, Normal, nullptr) \
222 v(bool, useConcurrentGC, true, Normal, nullptr) \
223 v(bool, collectContinuously, false, Normal, nullptr) \
224 v(double, collectContinuouslyPeriodMS, 1, Normal, nullptr) \
225 v(bool, forceFencedBarrier, false, Normal, nullptr) \
226 v(bool, verboseVisitRace, false, Normal, nullptr) \
227 v(bool, optimizeParallelSlotVisitorsForStoppedMutator, false, Normal, nullptr) \
228 v(unsigned, largeHeapSize, 32 * 1024 * 1024, Normal, nullptr) \
229 v(unsigned, smallHeapSize, 1 * 1024 * 1024, Normal, nullptr) \
230 v(double, smallHeapRAMFraction, 0.25, Normal, nullptr) \
231 v(double, smallHeapGrowthFactor, 2, Normal, nullptr) \
232 v(double, mediumHeapRAMFraction, 0.5, Normal, nullptr) \
233 v(double, mediumHeapGrowthFactor, 1.5, Normal, nullptr) \
234 v(double, largeHeapGrowthFactor, 1.24, Normal, nullptr) \
235 v(double, miniVMHeapGrowthFactor, 1.27, Normal, nullptr) \
236 v(double, criticalGCMemoryThreshold, 0.80, Normal, "percent memory in use the GC considers critical. The collector is much more aggressive above this threshold") \
237 v(double, minimumMutatorUtilization, 0, Normal, nullptr) \
238 v(double, maximumMutatorUtilization, 0.7, Normal, nullptr) \
239 v(double, epsilonMutatorUtilization, 0.01, Normal, nullptr) \
240 v(double, concurrentGCMaxHeadroom, 1.5, Normal, nullptr) \
241 v(double, concurrentGCPeriodMS, 2, Normal, nullptr) \
242 v(bool, useStochasticMutatorScheduler, true, Normal, nullptr) \
243 v(double, minimumGCPauseMS, 0.3, Normal, nullptr) \
244 v(double, gcPauseScale, 0.3, Normal, nullptr) \
245 v(double, gcIncrementBytes, 10000, Normal, nullptr) \
246 v(double, gcIncrementMaxBytes, 100000, Normal, nullptr) \
247 v(double, gcIncrementScale, 0, Normal, nullptr) \
248 v(bool, scribbleFreeCells, false, Normal, nullptr) \
249 v(double, sizeClassProgression, 1.4, Normal, nullptr) \
250 v(unsigned, largeAllocationCutoff, 100000, Normal, nullptr) \
251 v(bool, dumpSizeClasses, false, Normal, nullptr) \
252 v(bool, useBumpAllocator, true, Normal, nullptr) \
253 v(bool, stealEmptyBlocksFromOtherAllocators, true, Normal, nullptr) \
254 v(bool, eagerlyUpdateTopCallFrame, false, Normal, nullptr) \
255 \
256 v(bool, useOSREntryToDFG, true, Normal, nullptr) \
257 v(bool, useOSREntryToFTL, true, Normal, nullptr) \
258 \
259 v(bool, useFTLJIT, true, Normal, "allows the FTL JIT to be used if true") \
260 v(bool, useFTLTBAA, true, Normal, nullptr) \
261 v(bool, validateFTLOSRExitLiveness, false, Normal, nullptr) \
262 v(unsigned, defaultB3OptLevel, 2, Normal, nullptr) \
263 v(bool, b3AlwaysFailsBeforeCompile, false, Normal, nullptr) \
264 v(bool, b3AlwaysFailsBeforeLink, false, Normal, nullptr) \
265 v(bool, ftlCrashes, false, Normal, nullptr) /* fool-proof way of checking that you ended up in the FTL. ;-) */\
266 v(bool, clobberAllRegsInFTLICSlowPath, !ASSERT_DISABLED, Normal, nullptr) \
267 v(bool, enableJITDebugAssertions, !ASSERT_DISABLED, Normal, nullptr) \
268 v(bool, useAccessInlining, true, Normal, nullptr) \
269 v(unsigned, maxAccessVariantListSize, 8, Normal, nullptr) \
270 v(bool, usePolyvariantDevirtualization, true, Normal, nullptr) \
271 v(bool, usePolymorphicAccessInlining, true, Normal, nullptr) \
272 v(unsigned, maxPolymorphicAccessInliningListSize, 8, Normal, nullptr) \
273 v(bool, usePolymorphicCallInlining, true, Normal, nullptr) \
274 v(bool, usePolymorphicCallInliningForNonStubStatus, false, Normal, nullptr) \
275 v(unsigned, maxPolymorphicCallVariantListSize, 15, Normal, nullptr) \
276 v(unsigned, maxPolymorphicCallVariantListSizeForTopTier, 5, Normal, nullptr) \
277 v(unsigned, maxPolymorphicCallVariantListSizeForWebAssemblyToJS, 5, Normal, nullptr) \
278 v(unsigned, maxPolymorphicCallVariantsForInlining, 5, Normal, nullptr) \
279 v(unsigned, frequentCallThreshold, 2, Normal, nullptr) \
280 v(double, minimumCallToKnownRate, 0.51, Normal, nullptr) \
281 v(bool, createPreHeaders, true, Normal, nullptr) \
282 v(bool, useMovHintRemoval, true, Normal, nullptr) \
283 v(bool, usePutStackSinking, true, Normal, nullptr) \
284 v(bool, useObjectAllocationSinking, true, Normal, nullptr) \
285 v(bool, useValueRepElimination, true, Normal, nullptr) \
286 v(bool, useArityFixupInlining, true, Normal, nullptr) \
287 v(bool, logExecutableAllocation, false, Normal, nullptr) \
288 \
289 v(bool, useConcurrentJIT, true, Normal, "allows the DFG / FTL compilation in threads other than the executing JS thread") \
290 v(unsigned, numberOfDFGCompilerThreads, computeNumberOfWorkerThreads(3, 2) - 1, Normal, nullptr) \
291 v(unsigned, numberOfFTLCompilerThreads, computeNumberOfWorkerThreads(MAXIMUM_NUMBER_OF_FTL_COMPILER_THREADS, 2) - 1, Normal, nullptr) \
292 v(int32, priorityDeltaOfDFGCompilerThreads, computePriorityDeltaOfWorkerThreads(-1, 0), Normal, nullptr) \
293 v(int32, priorityDeltaOfFTLCompilerThreads, computePriorityDeltaOfWorkerThreads(-2, 0), Normal, nullptr) \
294 v(int32, priorityDeltaOfWasmCompilerThreads, computePriorityDeltaOfWorkerThreads(-1, 0), Normal, nullptr) \
295 \
296 v(bool, useProfiler, false, Normal, nullptr) \
297 v(bool, disassembleBaselineForProfiler, true, Normal, nullptr) \
298 \
299 v(bool, useArchitectureSpecificOptimizations, true, Normal, nullptr) \
300 \
301 v(bool, breakOnThrow, false, Normal, nullptr) \
302 \
303 v(unsigned, maximumOptimizationCandidateBytecodeCost, 100000, Normal, nullptr) \
304 \
305 v(unsigned, maximumFunctionForCallInlineCandidateBytecodeCost, 120, Normal, nullptr) \
306 v(unsigned, maximumFunctionForClosureCallInlineCandidateBytecodeCost, 100, Normal, nullptr) \
307 v(unsigned, maximumFunctionForConstructInlineCandidateBytecoodeCost, 100, Normal, nullptr) \
308 \
309 v(unsigned, maximumFTLCandidateBytecodeCost, 20000, Normal, nullptr) \
310 \
311 /* Depth of inline stack, so 1 = no inlining, 2 = one level, etc. */ \
312 v(unsigned, maximumInliningDepth, 5, Normal, "maximum allowed inlining depth. Depth of 1 means no inlining") \
313 v(unsigned, maximumInliningRecursion, 2, Normal, nullptr) \
314 \
315 /* Maximum size of a caller for enabling inlining. This is purely to protect us */\
316 /* from super long compiles that take a lot of memory. */\
317 v(unsigned, maximumInliningCallerBytecodeCost, 10000, Normal, nullptr) \
318 \
319 v(unsigned, maximumVarargsForInlining, 100, Normal, nullptr) \
320 \
321 v(bool, useMaximalFlushInsertionPhase, false, Normal, "Setting to true allows the DFG's MaximalFlushInsertionPhase to run.") \
322 \
323 v(unsigned, maximumBinaryStringSwitchCaseLength, 50, Normal, nullptr) \
324 v(unsigned, maximumBinaryStringSwitchTotalLength, 2000, Normal, nullptr) \
325 \
326 v(double, jitPolicyScale, 1.0, Normal, "scale JIT thresholds to this specified ratio between 0.0 (compile ASAP) and 1.0 (compile like normal).") \
327 v(bool, forceEagerCompilation, false, Normal, nullptr) \
328 v(int32, thresholdForJITAfterWarmUp, 500, Normal, nullptr) \
329 v(int32, thresholdForJITSoon, 100, Normal, nullptr) \
330 \
331 v(int32, thresholdForOptimizeAfterWarmUp, 1000, Normal, nullptr) \
332 v(int32, thresholdForOptimizeAfterLongWarmUp, 1000, Normal, nullptr) \
333 v(int32, thresholdForOptimizeSoon, 1000, Normal, nullptr) \
334 v(int32, executionCounterIncrementForLoop, 1, Normal, nullptr) \
335 v(int32, executionCounterIncrementForEntry, 15, Normal, nullptr) \
336 \
337 v(int32, thresholdForFTLOptimizeAfterWarmUp, 100000, Normal, nullptr) \
338 v(int32, thresholdForFTLOptimizeSoon, 1000, Normal, nullptr) \
339 v(int32, ftlTierUpCounterIncrementForLoop, 1, Normal, nullptr) \
340 v(int32, ftlTierUpCounterIncrementForReturn, 15, Normal, nullptr) \
341 v(unsigned, ftlOSREntryFailureCountForReoptimization, 15, Normal, nullptr) \
342 v(unsigned, ftlOSREntryRetryThreshold, 100, Normal, nullptr) \
343 \
344 v(int32, evalThresholdMultiplier, 10, Normal, nullptr) \
345 v(unsigned, maximumEvalCacheableSourceLength, 256, Normal, nullptr) \
346 \
347 v(bool, randomizeExecutionCountsBetweenCheckpoints, false, Normal, nullptr) \
348 v(int32, maximumExecutionCountsBetweenCheckpointsForBaseline, 1000, Normal, nullptr) \
349 v(int32, maximumExecutionCountsBetweenCheckpointsForUpperTiers, 50000, Normal, nullptr) \
350 \
351 v(unsigned, likelyToTakeSlowCaseMinimumCount, 20, Normal, nullptr) \
352 v(unsigned, couldTakeSlowCaseMinimumCount, 10, Normal, nullptr) \
353 \
354 v(unsigned, osrExitCountForReoptimization, 100, Normal, nullptr) \
355 v(unsigned, osrExitCountForReoptimizationFromLoop, 5, Normal, nullptr) \
356 \
357 v(unsigned, reoptimizationRetryCounterMax, 0, Normal, nullptr) \
358 \
359 v(unsigned, minimumOptimizationDelay, 1, Normal, nullptr) \
360 v(unsigned, maximumOptimizationDelay, 5, Normal, nullptr) \
361 v(double, desiredProfileLivenessRate, 0.75, Normal, nullptr) \
362 v(double, desiredProfileFullnessRate, 0.35, Normal, nullptr) \
363 \
364 v(double, doubleVoteRatioForDoubleFormat, 2, Normal, nullptr) \
365 v(double, structureCheckVoteRatioForHoisting, 1, Normal, nullptr) \
366 v(double, checkArrayVoteRatioForHoisting, 1, Normal, nullptr) \
367 \
368 v(unsigned, maximumDirectCallStackSize, 200, Normal, nullptr) \
369 \
370 v(unsigned, minimumNumberOfScansBetweenRebalance, 100, Normal, nullptr) \
371 v(unsigned, numberOfGCMarkers, computeNumberOfGCMarkers(8), Normal, nullptr) \
372 v(bool, useParallelMarkingConstraintSolver, true, Normal, nullptr) \
373 v(unsigned, opaqueRootMergeThreshold, 1000, Normal, nullptr) \
374 v(double, minHeapUtilization, 0.8, Normal, nullptr) \
375 v(double, minMarkedBlockUtilization, 0.9, Normal, nullptr) \
376 v(unsigned, slowPathAllocsBetweenGCs, 0, Normal, "force a GC on every Nth slow path alloc, where N is specified by this option") \
377 \
378 v(double, percentCPUPerMBForFullTimer, 0.0003125, Normal, nullptr) \
379 v(double, percentCPUPerMBForEdenTimer, 0.0025, Normal, nullptr) \
380 v(double, collectionTimerMaxPercentCPU, 0.05, Normal, nullptr) \
381 \
382 v(bool, forceWeakRandomSeed, false, Normal, nullptr) \
383 v(unsigned, forcedWeakRandomSeed, 0, Normal, nullptr) \
384 \
385 v(bool, useZombieMode, false, Normal, "debugging option to scribble over dead objects with 0xbadbeef0") \
386 v(bool, useImmortalObjects, false, Normal, "debugging option to keep all objects alive forever") \
387 v(bool, sweepSynchronously, false, Normal, "debugging option to sweep all dead objects synchronously at GC end before resuming mutator") \
388 v(unsigned, maxSingleAllocationSize, 0, Configurable, "debugging option to limit individual allocations to a max size (0 = limit not set, N = limit size in bytes)") \
389 \
390 v(gcLogLevel, logGC, GCLogging::None, Normal, "debugging option to log GC activity (0 = None, 1 = Basic, 2 = Verbose)") \
391 v(bool, useGC, true, Normal, nullptr) \
392 v(bool, gcAtEnd, false, Normal, "If true, the jsc CLI will do a GC before exiting") \
393 v(bool, forceGCSlowPaths, false, Normal, "If true, we will force all JIT fast allocations down their slow paths.") \
394 v(unsigned, gcMaxHeapSize, 0, Normal, nullptr) \
395 v(unsigned, forceRAMSize, 0, Normal, nullptr) \
396 v(bool, recordGCPauseTimes, false, Normal, nullptr) \
397 v(bool, dumpHeapStatisticsAtVMDestruction, false, Normal, nullptr) \
398 v(bool, forceCodeBlockToJettisonDueToOldAge, false, Normal, "If true, this means that anytime we can jettison a CodeBlock due to old age, we do.") \
399 v(bool, useEagerCodeBlockJettisonTiming, false, Normal, "If true, the time slices for jettisoning a CodeBlock due to old age are shrunk significantly.") \
400 \
401 v(bool, useTypeProfiler, false, Normal, nullptr) \
402 v(bool, useControlFlowProfiler, false, Normal, nullptr) \
403 \
404 v(bool, useSamplingProfiler, false, Normal, nullptr) \
405 v(unsigned, sampleInterval, 1000, Normal, "Time between stack traces in microseconds.") \
406 v(bool, collectSamplingProfilerDataForJSCShell, false, Normal, "This corresponds to the JSC shell's --sample option.") \
407 v(unsigned, samplingProfilerTopFunctionsCount, 12, Normal, "Number of top functions to report when using the command line interface.") \
408 v(unsigned, samplingProfilerTopBytecodesCount, 40, Normal, "Number of top bytecodes to report when using the command line interface.") \
409 v(optionString, samplingProfilerPath, nullptr, Normal, "The path to the directory to write sampiling profiler output to. This probably will not work with WK2 unless the path is in the whitelist.") \
410 v(bool, sampleCCode, false, Normal, "Causes the sampling profiler to record profiling data for C frames.") \
411 \
412 v(bool, alwaysGeneratePCToCodeOriginMap, false, Normal, "This will make sure we always generate a PCToCodeOriginMap for JITed code.") \
413 \
414 v(bool, verifyHeap, false, Normal, nullptr) \
415 v(unsigned, numberOfGCCyclesToRecordForVerification, 3, Normal, nullptr) \
416 \
417 v(unsigned, exceptionStackTraceLimit, 100, Normal, "Stack trace limit for internal Exception object") \
418 v(unsigned, defaultErrorStackTraceLimit, 100, Normal, "The default value for Error.stackTraceLimit") \
419 v(bool, useExceptionFuzz, false, Normal, nullptr) \
420 v(unsigned, fireExceptionFuzzAt, 0, Normal, nullptr) \
421 v(bool, validateDFGExceptionHandling, false, Normal, "Causes the DFG to emit code validating exception handling for each node that can exit") /* This is true by default on Debug builds */\
422 v(bool, dumpSimulatedThrows, false, Normal, "Dumps the call stack of the last simulated throw if exception scope verification fails") \
423 v(bool, validateExceptionChecks, false, Normal, "Verifies that needed exception checks are performed.") \
424 v(unsigned, unexpectedExceptionStackTraceLimit, 100, Normal, "Stack trace limit for debugging unexpected exceptions observed in the VM") \
425 \
426 v(bool, useExecutableAllocationFuzz, false, Normal, nullptr) \
427 v(unsigned, fireExecutableAllocationFuzzAt, 0, Normal, nullptr) \
428 v(unsigned, fireExecutableAllocationFuzzAtOrAfter, 0, Normal, nullptr) \
429 v(bool, verboseExecutableAllocationFuzz, false, Normal, nullptr) \
430 \
431 v(bool, useOSRExitFuzz, false, Normal, nullptr) \
432 v(unsigned, fireOSRExitFuzzAtStatic, 0, Normal, nullptr) \
433 v(unsigned, fireOSRExitFuzzAt, 0, Normal, nullptr) \
434 v(unsigned, fireOSRExitFuzzAtOrAfter, 0, Normal, nullptr) \
435 \
436 v(bool, useRandomizingFuzzerAgent, false, Normal, nullptr) \
437 v(unsigned, seedOfRandomizingFuzzerAgent, 1, Normal, nullptr) \
438 v(bool, dumpRandomizingFuzzerAgentPredictions, false, Normal, nullptr) \
439 v(bool, useDoublePredictionFuzzerAgent, false, Normal, nullptr) \
440 \
441 v(bool, logPhaseTimes, false, Normal, nullptr) \
442 v(double, rareBlockPenalty, 0.001, Normal, nullptr) \
443 v(bool, airLinearScanVerbose, false, Normal, nullptr) \
444 v(bool, airLinearScanSpillsEverything, false, Normal, nullptr) \
445 v(bool, airForceBriggsAllocator, false, Normal, nullptr) \
446 v(bool, airForceIRCAllocator, false, Normal, nullptr) \
447 v(bool, airRandomizeRegs, false, Normal, nullptr) \
448 v(unsigned, airRandomizeRegsSeed, 0, Normal, nullptr) \
449 v(bool, coalesceSpillSlots, true, Normal, nullptr) \
450 v(bool, logAirRegisterPressure, false, Normal, nullptr) \
451 v(bool, useB3TailDup, true, Normal, nullptr) \
452 v(unsigned, maxB3TailDupBlockSize, 3, Normal, nullptr) \
453 v(unsigned, maxB3TailDupBlockSuccessors, 3, Normal, nullptr) \
454 \
455 v(bool, useDollarVM, false, Restricted, "installs the $vm debugging tool in global objects") \
456 v(optionString, functionOverrides, nullptr, Restricted, "file with debugging overrides for function bodies") \
457 v(bool, useSigillCrashAnalyzer, false, Configurable, "logs data about SIGILL crashes") \
458 \
459 v(unsigned, watchdog, 0, Normal, "watchdog timeout (0 = Disabled, N = a timeout period of N milliseconds)") \
460 v(bool, usePollingTraps, false, Normal, "use polling (instead of signalling) VM traps") \
461 \
462 v(bool, useMachForExceptions, true, Normal, "Use mach exceptions rather than signals to handle faults and pass thread messages. (This does nothing on platforms without mach)") \
463 \
464 v(bool, useICStats, false, Normal, nullptr) \
465 \
466 v(unsigned, prototypeHitCountForLLIntCaching, 2, Normal, "Number of prototype property hits before caching a prototype in the LLInt. A count of 0 means never cache.") \
467 \
468 v(bool, dumpCompiledRegExpPatterns, false, Normal, nullptr) \
469 \
470 v(bool, dumpModuleRecord, false, Normal, nullptr) \
471 v(bool, dumpModuleLoadingState, false, Normal, nullptr) \
472 v(bool, exposeInternalModuleLoader, false, Normal, "expose the internal module loader object to the global space for debugging") \
473 \
474 v(bool, useSuperSampler, false, Normal, nullptr) \
475 \
476 v(bool, useSourceProviderCache, true, Normal, "If false, the parser will not use the source provider cache. It's good to verify everything works when this is false. Because the cache is so successful, it can mask bugs.") \
477 v(bool, useCodeCache, true, Normal, "If false, the unlinked byte code cache will not be used.") \
478 \
479 v(bool, useWebAssembly, true, Normal, "Expose the WebAssembly global object.") \
480 \
481 v(bool, enableSpectreMitigations, true, Restricted, "Enable Spectre mitigations.") \
482 v(bool, enableSpectreGadgets, false, Restricted, "enable gadgets to test Spectre mitigations.") \
483 v(bool, zeroStackFrame, false, Normal, "Zero stack frame on entry to a function.") \
484 \
485 v(bool, failToCompileWebAssemblyCode, false, Normal, "If true, no Wasm::Plan will sucessfully compile a function.") \
486 v(size, webAssemblyPartialCompileLimit, 5000, Normal, "Limit on the number of bytes a Wasm::Plan::compile should attempt before checking for other work.") \
487 v(unsigned, webAssemblyBBQOptimizationLevel, 0, Normal, "B3 Optimization level for BBQ Web Assembly module compilations.") \
488 v(unsigned, webAssemblyOMGOptimizationLevel, Options::defaultB3OptLevel(), Normal, "B3 Optimization level for OMG Web Assembly module compilations.") \
489 \
490 v(bool, useBBQTierUpChecks, true, Normal, "Enables tier up checks for our BBQ code.") \
491 v(unsigned, webAssemblyOMGTierUpCount, 5000, Normal, "The countdown before we tier up a function to OMG.") \
492 v(unsigned, webAssemblyLoopDecrement, 15, Normal, "The amount the tier up countdown is decremented on each loop backedge.") \
493 v(unsigned, webAssemblyFunctionEntryDecrement, 1, Normal, "The amount the tier up countdown is decremented on each function entry.") \
494 \
495 v(bool, useWebAssemblyFastMemory, true, Normal, "If true, we will try to use a 32-bit address space with a signal handler to bounds check wasm memory.") \
496 v(bool, logWebAssemblyMemory, false, Normal, nullptr) \
497 v(unsigned, webAssemblyFastMemoryRedzonePages, 128, Normal, "WebAssembly fast memories use 4GiB virtual allocations, plus a redzone (counted as multiple of 64KiB WebAssembly pages) at the end to catch reg+imm accesses which exceed 32-bit, anything beyond the redzone is explicitly bounds-checked") \
498 v(bool, crashIfWebAssemblyCantFastMemory, false, Normal, "If true, we will crash if we can't obtain fast memory for wasm.") \
499 v(unsigned, maxNumWebAssemblyFastMemories, 4, Normal, nullptr) \
500 v(bool, useFastTLSForWasmContext, true, Normal, "If true, we will store context in fast TLS. If false, we will pin it to a register.") \
501 v(bool, wasmBBQUsesAir, true, Normal, nullptr) \
502 v(bool, useWebAssemblyStreamingApi, enableWebAssemblyStreamingApi, Normal, "Allow to run WebAssembly's Streaming API") \
503 v(bool, useCallICsForWebAssemblyToJSCalls, true, Normal, "If true, we will use CallLinkInfo to inline cache Wasm to JS calls.") \
504 v(bool, useEagerWebAssemblyModuleHashing, false, Normal, "Unnamed WebAssembly modules are identified in backtraces through their hash, if available.") \
505 v(bool, useWebAssemblyReferences, true, Normal, "Allow types from the wasm references spec.") \
506 v(bool, useBigInt, false, Normal, "If true, we will enable BigInt support.") \
507 v(bool, useIntlNumberFormatToParts, enableIntlNumberFormatToParts, Normal, "If true, we will enable Intl.NumberFormat.prototype.formatToParts") \
508 v(bool, useIntlPluralRules, enableIntlPluralRules, Normal, "If true, we will enable Intl.PluralRules.") \
509 v(bool, useArrayAllocationProfiling, true, Normal, "If true, we will use our normal array allocation profiling. If false, the allocation profile will always claim to be undecided.") \
510 v(bool, forcePolyProto, false, Normal, "If true, create_this will always create an object with a poly proto structure.") \
511 v(bool, forceMiniVMMode, false, Normal, "If true, it will force mini VM mode on.") \
512 v(bool, useTracePoints, false, Normal, nullptr) \
513 v(bool, traceLLIntExecution, false, Configurable, nullptr) \
514 v(bool, traceLLIntSlowPath, false, Configurable, nullptr) \
515 v(bool, traceBaselineJITExecution, false, Normal, nullptr) \
516 v(unsigned, thresholdForGlobalLexicalBindingEpoch, UINT_MAX, Normal, "Threshold for global lexical binding epoch. If the epoch reaches to this value, CodeBlock metadata for scope operations will be revised globally. It needs to be greater than 1.") \
517 v(optionString, diskCachePath, nullptr, Restricted, nullptr) \
518 v(bool, forceDiskCache, false, Restricted, nullptr) \
519 v(bool, validateAbstractInterpreterState, false, Restricted, nullptr) \
520 v(double, validateAbstractInterpreterStateProbability, 0.5, Normal, nullptr) \
521 v(optionString, dumpJITMemoryPath, nullptr, Restricted, nullptr) \
522 v(double, dumpJITMemoryFlushInterval, 10, Restricted, "Maximum time in between flushes of the JIT memory dump in seconds.") \
523 v(bool, useUnlinkedCodeBlockJettisoning, false, Normal, "If true, UnlinkedCodeBlock can be jettisoned.") \
524
525
526enum OptionEquivalence {
527 SameOption,
528 InvertedOption,
529};
530
531#define JSC_ALIASED_OPTIONS(v) \
532 v(enableFunctionDotArguments, useFunctionDotArguments, SameOption) \
533 v(enableTailCalls, useTailCalls, SameOption) \
534 v(showDisassembly, dumpDisassembly, SameOption) \
535 v(showDFGDisassembly, dumpDFGDisassembly, SameOption) \
536 v(showFTLDisassembly, dumpFTLDisassembly, SameOption) \
537 v(showAllDFGNodes, dumpAllDFGNodes, SameOption) \
538 v(alwaysDoFullCollection, useGenerationalGC, InvertedOption) \
539 v(enableOSREntryToDFG, useOSREntryToDFG, SameOption) \
540 v(enableOSREntryToFTL, useOSREntryToFTL, SameOption) \
541 v(enableAccessInlining, useAccessInlining, SameOption) \
542 v(enablePolyvariantDevirtualization, usePolyvariantDevirtualization, SameOption) \
543 v(enablePolymorphicAccessInlining, usePolymorphicAccessInlining, SameOption) \
544 v(enablePolymorphicCallInlining, usePolymorphicCallInlining, SameOption) \
545 v(enableMovHintRemoval, useMovHintRemoval, SameOption) \
546 v(enableObjectAllocationSinking, useObjectAllocationSinking, SameOption) \
547 v(enableConcurrentJIT, useConcurrentJIT, SameOption) \
548 v(enableProfiler, useProfiler, SameOption) \
549 v(enableArchitectureSpecificOptimizations, useArchitectureSpecificOptimizations, SameOption) \
550 v(enablePolyvariantCallInlining, usePolyvariantCallInlining, SameOption) \
551 v(enablePolyvariantByIdInlining, usePolyvariantByIdInlining, SameOption) \
552 v(enableMaximalFlushInsertionPhase, useMaximalFlushInsertionPhase, SameOption) \
553 v(objectsAreImmortal, useImmortalObjects, SameOption) \
554 v(showObjectStatistics, dumpObjectStatistics, SameOption) \
555 v(disableGC, useGC, InvertedOption) \
556 v(enableTypeProfiler, useTypeProfiler, SameOption) \
557 v(enableControlFlowProfiler, useControlFlowProfiler, SameOption) \
558 v(enableExceptionFuzz, useExceptionFuzz, SameOption) \
559 v(enableExecutableAllocationFuzz, useExecutableAllocationFuzz, SameOption) \
560 v(enableOSRExitFuzz, useOSRExitFuzz, SameOption) \
561 v(enableDollarVM, useDollarVM, SameOption) \
562 v(enableWebAssembly, useWebAssembly, SameOption) \
563 v(verboseDFGByteCodeParsing, verboseDFGBytecodeParsing, SameOption) \
564 v(maximumOptimizationCandidateInstructionCount, maximumOptimizationCandidateBytecodeCost, SameOption) \
565 v(maximumFunctionForCallInlineCandidateInstructionCount, maximumFunctionForCallInlineCandidateBytecodeCost, SameOption) \
566 v(maximumFunctionForClosureCallInlineCandidateInstructionCount, maximumFunctionForClosureCallInlineCandidateBytecodeCost, SameOption) \
567 v(maximumFunctionForConstructInlineCandidateInstructionCount, maximumFunctionForConstructInlineCandidateBytecoodeCost, SameOption) \
568 v(maximumFTLCandidateInstructionCount, maximumFTLCandidateBytecodeCost, SameOption) \
569 v(maximumInliningCallerSize, maximumInliningCallerBytecodeCost, SameOption) \
570
571
572class Options {
573public:
574 enum class DumpLevel {
575 None = 0,
576 Overridden,
577 All,
578 Verbose
579 };
580
581 enum class Availability {
582 Normal = 0,
583 Restricted,
584 Configurable
585 };
586
587 // This typedef is to allow us to eliminate the '_' in the field name in
588 // union inside Entry. This is needed to keep the style checker happy.
589 typedef int32_t int32;
590 typedef size_t size;
591
592 // Declare the option IDs:
593 enum ID {
594#define FOR_EACH_OPTION(type_, name_, defaultValue_, availability_, description_) \
595 name_##ID,
596 JSC_OPTIONS(FOR_EACH_OPTION)
597#undef FOR_EACH_OPTION
598 numberOfOptions
599 };
600
601 enum class Type {
602 boolType,
603 unsignedType,
604 doubleType,
605 int32Type,
606 sizeType,
607 optionRangeType,
608 optionStringType,
609 gcLogLevelType,
610 };
611
612 JS_EXPORT_PRIVATE static void initialize();
613
614 // Parses a string of options where each option is of the format "--<optionName>=<value>"
615 // and are separated by a space. The leading "--" is optional and will be ignored.
616 JS_EXPORT_PRIVATE static bool setOptions(const char* optionsList);
617
618 // Parses a single command line option in the format "<optionName>=<value>"
619 // (no spaces allowed) and set the specified option if appropriate.
620 JS_EXPORT_PRIVATE static bool setOption(const char* arg);
621
622 JS_EXPORT_PRIVATE static void dumpAllOptions(FILE*, DumpLevel, const char* title = nullptr);
623 JS_EXPORT_PRIVATE static void dumpAllOptionsInALine(StringBuilder&);
624
625 JS_EXPORT_PRIVATE static void ensureOptionsAreCoherent();
626
627 JS_EXPORT_PRIVATE static void enableRestrictedOptions(bool enableOrNot);
628
629 // Declare accessors for each option:
630#define FOR_EACH_OPTION(type_, name_, defaultValue_, availability_, description_) \
631 ALWAYS_INLINE static type_& name_() { return s_options[name_##ID].type_##Val; } \
632 ALWAYS_INLINE static type_& name_##Default() { return s_defaultOptions[name_##ID].type_##Val; }
633
634 JSC_OPTIONS(FOR_EACH_OPTION)
635#undef FOR_EACH_OPTION
636
637 static bool isAvailable(ID, Availability);
638
639private:
640 // For storing for an option value:
641 union Entry {
642 bool boolVal;
643 unsigned unsignedVal;
644 double doubleVal;
645 int32 int32Val;
646 size sizeVal;
647 OptionRange optionRangeVal;
648 const char* optionStringVal;
649 GCLogging::Level gcLogLevelVal;
650 };
651
652 // For storing constant meta data about each option:
653 struct EntryInfo {
654 const char* name;
655 const char* description;
656 Type type;
657 Availability availability;
658 };
659
660 Options();
661
662 enum DumpDefaultsOption {
663 DontDumpDefaults,
664 DumpDefaults
665 };
666 static void dumpOptionsIfNeeded();
667 static void dumpAllOptions(StringBuilder&, DumpLevel, const char* title,
668 const char* separator, const char* optionHeader, const char* optionFooter, DumpDefaultsOption);
669 static void dumpOption(StringBuilder&, DumpLevel, ID,
670 const char* optionHeader, const char* optionFooter, DumpDefaultsOption);
671
672 static bool setOptionWithoutAlias(const char* arg);
673 static bool setAliasedOption(const char* arg);
674 static bool overrideAliasedOptionWithHeuristic(const char* name);
675
676 // Declare the singleton instance of the options store:
677 JS_EXPORT_PRIVATE static Entry s_options[numberOfOptions];
678 JS_EXPORT_PRIVATE static Entry s_defaultOptions[numberOfOptions];
679 static const EntryInfo s_optionsInfo[numberOfOptions];
680
681 friend class Option;
682};
683
684class Option {
685public:
686 Option(Options::ID id)
687 : m_id(id)
688 , m_entry(Options::s_options[m_id])
689 {
690 }
691
692 void dump(StringBuilder&) const;
693
694 bool operator==(const Option& other) const;
695 bool operator!=(const Option& other) const { return !(*this == other); }
696
697 Options::ID id() const { return m_id; }
698 const char* name() const;
699 const char* description() const;
700 Options::Type type() const;
701 Options::Availability availability() const;
702 bool isOverridden() const;
703 const Option defaultOption() const;
704
705 bool& boolVal();
706 unsigned& unsignedVal();
707 double& doubleVal();
708 int32_t& int32Val();
709 OptionRange optionRangeVal();
710 const char* optionStringVal();
711 GCLogging::Level& gcLogLevelVal();
712
713private:
714 // Only used for constructing default Options.
715 Option(Options::ID id, Options::Entry& entry)
716 : m_id(id)
717 , m_entry(entry)
718 {
719 }
720
721 Options::ID m_id;
722 Options::Entry& m_entry;
723};
724
725inline const char* Option::name() const
726{
727 return Options::s_optionsInfo[m_id].name;
728}
729
730inline const char* Option::description() const
731{
732 return Options::s_optionsInfo[m_id].description;
733}
734
735inline Options::Type Option::type() const
736{
737 return Options::s_optionsInfo[m_id].type;
738}
739
740inline Options::Availability Option::availability() const
741{
742 return Options::s_optionsInfo[m_id].availability;
743}
744
745inline bool Option::isOverridden() const
746{
747 return *this != defaultOption();
748}
749
750inline const Option Option::defaultOption() const
751{
752 return Option(m_id, Options::s_defaultOptions[m_id]);
753}
754
755inline bool& Option::boolVal()
756{
757 return m_entry.boolVal;
758}
759
760inline unsigned& Option::unsignedVal()
761{
762 return m_entry.unsignedVal;
763}
764
765inline double& Option::doubleVal()
766{
767 return m_entry.doubleVal;
768}
769
770inline int32_t& Option::int32Val()
771{
772 return m_entry.int32Val;
773}
774
775inline OptionRange Option::optionRangeVal()
776{
777 return m_entry.optionRangeVal;
778}
779
780inline const char* Option::optionStringVal()
781{
782 return m_entry.optionStringVal;
783}
784
785inline GCLogging::Level& Option::gcLogLevelVal()
786{
787 return m_entry.gcLogLevelVal;
788}
789
790} // namespace JSC
791