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, useConcurrentBarriers, true, Normal, nullptr) \
223 v(bool, useConcurrentGC, true, Normal, nullptr) \
224 v(bool, collectContinuously, false, Normal, nullptr) \
225 v(double, collectContinuouslyPeriodMS, 1, Normal, nullptr) \
226 v(bool, forceFencedBarrier, false, Normal, nullptr) \
227 v(bool, verboseVisitRace, false, Normal, nullptr) \
228 v(bool, optimizeParallelSlotVisitorsForStoppedMutator, false, Normal, nullptr) \
229 v(unsigned, largeHeapSize, 32 * 1024 * 1024, Normal, nullptr) \
230 v(unsigned, smallHeapSize, 1 * 1024 * 1024, Normal, nullptr) \
231 v(double, smallHeapRAMFraction, 0.25, Normal, nullptr) \
232 v(double, smallHeapGrowthFactor, 2, Normal, nullptr) \
233 v(double, mediumHeapRAMFraction, 0.5, Normal, nullptr) \
234 v(double, mediumHeapGrowthFactor, 1.5, Normal, nullptr) \
235 v(double, largeHeapGrowthFactor, 1.24, Normal, nullptr) \
236 v(double, miniVMHeapGrowthFactor, 1.27, Normal, nullptr) \
237 v(double, criticalGCMemoryThreshold, 0.80, Normal, "percent memory in use the GC considers critical. The collector is much more aggressive above this threshold") \
238 v(double, minimumMutatorUtilization, 0, Normal, nullptr) \
239 v(double, maximumMutatorUtilization, 0.7, Normal, nullptr) \
240 v(double, epsilonMutatorUtilization, 0.01, Normal, nullptr) \
241 v(double, concurrentGCMaxHeadroom, 1.5, Normal, nullptr) \
242 v(double, concurrentGCPeriodMS, 2, Normal, nullptr) \
243 v(bool, useStochasticMutatorScheduler, true, Normal, nullptr) \
244 v(double, minimumGCPauseMS, 0.3, Normal, nullptr) \
245 v(double, gcPauseScale, 0.3, Normal, nullptr) \
246 v(double, gcIncrementBytes, 10000, Normal, nullptr) \
247 v(double, gcIncrementMaxBytes, 100000, Normal, nullptr) \
248 v(double, gcIncrementScale, 0, Normal, nullptr) \
249 v(bool, scribbleFreeCells, false, Normal, nullptr) \
250 v(double, sizeClassProgression, 1.4, Normal, nullptr) \
251 v(unsigned, largeAllocationCutoff, 100000, Normal, nullptr) \
252 v(bool, dumpSizeClasses, false, Normal, nullptr) \
253 v(bool, useBumpAllocator, true, Normal, nullptr) \
254 v(bool, stealEmptyBlocksFromOtherAllocators, true, Normal, nullptr) \
255 v(bool, eagerlyUpdateTopCallFrame, false, Normal, nullptr) \
256 \
257 v(bool, useOSREntryToDFG, true, Normal, nullptr) \
258 v(bool, useOSREntryToFTL, true, Normal, nullptr) \
259 \
260 v(bool, useFTLJIT, true, Normal, "allows the FTL JIT to be used if true") \
261 v(bool, useFTLTBAA, true, Normal, nullptr) \
262 v(bool, validateFTLOSRExitLiveness, false, Normal, nullptr) \
263 v(unsigned, defaultB3OptLevel, 2, Normal, nullptr) \
264 v(bool, b3AlwaysFailsBeforeCompile, false, Normal, nullptr) \
265 v(bool, b3AlwaysFailsBeforeLink, false, Normal, nullptr) \
266 v(bool, ftlCrashes, false, Normal, nullptr) /* fool-proof way of checking that you ended up in the FTL. ;-) */\
267 v(bool, clobberAllRegsInFTLICSlowPath, !ASSERT_DISABLED, Normal, nullptr) \
268 v(bool, enableJITDebugAssertions, !ASSERT_DISABLED, Normal, nullptr) \
269 v(bool, useAccessInlining, true, Normal, nullptr) \
270 v(unsigned, maxAccessVariantListSize, 8, Normal, nullptr) \
271 v(bool, usePolyvariantDevirtualization, true, Normal, nullptr) \
272 v(bool, usePolymorphicAccessInlining, true, Normal, nullptr) \
273 v(unsigned, maxPolymorphicAccessInliningListSize, 8, Normal, nullptr) \
274 v(bool, usePolymorphicCallInlining, true, Normal, nullptr) \
275 v(bool, usePolymorphicCallInliningForNonStubStatus, false, Normal, nullptr) \
276 v(unsigned, maxPolymorphicCallVariantListSize, 15, Normal, nullptr) \
277 v(unsigned, maxPolymorphicCallVariantListSizeForTopTier, 5, Normal, nullptr) \
278 v(unsigned, maxPolymorphicCallVariantListSizeForWebAssemblyToJS, 5, Normal, nullptr) \
279 v(unsigned, maxPolymorphicCallVariantsForInlining, 5, Normal, nullptr) \
280 v(unsigned, frequentCallThreshold, 2, Normal, nullptr) \
281 v(double, minimumCallToKnownRate, 0.51, Normal, nullptr) \
282 v(bool, createPreHeaders, true, Normal, nullptr) \
283 v(bool, useMovHintRemoval, true, Normal, nullptr) \
284 v(bool, usePutStackSinking, true, Normal, nullptr) \
285 v(bool, useObjectAllocationSinking, true, Normal, nullptr) \
286 v(bool, useValueRepElimination, true, Normal, nullptr) \
287 v(bool, useArityFixupInlining, true, Normal, nullptr) \
288 v(bool, logExecutableAllocation, false, Normal, nullptr) \
289 \
290 v(bool, useConcurrentJIT, true, Normal, "allows the DFG / FTL compilation in threads other than the executing JS thread") \
291 v(unsigned, numberOfDFGCompilerThreads, computeNumberOfWorkerThreads(3, 2) - 1, Normal, nullptr) \
292 v(unsigned, numberOfFTLCompilerThreads, computeNumberOfWorkerThreads(MAXIMUM_NUMBER_OF_FTL_COMPILER_THREADS, 2) - 1, Normal, nullptr) \
293 v(int32, priorityDeltaOfDFGCompilerThreads, computePriorityDeltaOfWorkerThreads(-1, 0), Normal, nullptr) \
294 v(int32, priorityDeltaOfFTLCompilerThreads, computePriorityDeltaOfWorkerThreads(-2, 0), Normal, nullptr) \
295 v(int32, priorityDeltaOfWasmCompilerThreads, computePriorityDeltaOfWorkerThreads(-1, 0), Normal, nullptr) \
296 \
297 v(bool, useProfiler, false, Normal, nullptr) \
298 v(bool, disassembleBaselineForProfiler, true, Normal, nullptr) \
299 \
300 v(bool, useArchitectureSpecificOptimizations, true, Normal, nullptr) \
301 \
302 v(bool, breakOnThrow, false, Normal, nullptr) \
303 \
304 v(unsigned, maximumOptimizationCandidateInstructionCount, 100000, Normal, nullptr) \
305 \
306 v(unsigned, maximumFunctionForCallInlineCandidateInstructionCount, 120, Normal, nullptr) \
307 v(unsigned, maximumFunctionForClosureCallInlineCandidateInstructionCount, 100, Normal, nullptr) \
308 v(unsigned, maximumFunctionForConstructInlineCandidateInstructionCount, 100, Normal, nullptr) \
309 \
310 v(unsigned, maximumFTLCandidateInstructionCount, 20000, Normal, nullptr) \
311 \
312 /* Depth of inline stack, so 1 = no inlining, 2 = one level, etc. */ \
313 v(unsigned, maximumInliningDepth, 5, Normal, "maximum allowed inlining depth. Depth of 1 means no inlining") \
314 v(unsigned, maximumInliningRecursion, 2, Normal, nullptr) \
315 \
316 /* Maximum size of a caller for enabling inlining. This is purely to protect us */\
317 /* from super long compiles that take a lot of memory. */\
318 v(unsigned, maximumInliningCallerSize, 10000, Normal, nullptr) \
319 \
320 v(unsigned, maximumVarargsForInlining, 100, Normal, nullptr) \
321 \
322 v(bool, useMaximalFlushInsertionPhase, false, Normal, "Setting to true allows the DFG's MaximalFlushInsertionPhase to run.") \
323 \
324 v(unsigned, maximumBinaryStringSwitchCaseLength, 50, Normal, nullptr) \
325 v(unsigned, maximumBinaryStringSwitchTotalLength, 2000, Normal, nullptr) \
326 \
327 v(double, jitPolicyScale, 1.0, Normal, "scale JIT thresholds to this specified ratio between 0.0 (compile ASAP) and 1.0 (compile like normal).") \
328 v(bool, forceEagerCompilation, false, Normal, nullptr) \
329 v(int32, thresholdForJITAfterWarmUp, 500, Normal, nullptr) \
330 v(int32, thresholdForJITSoon, 100, Normal, nullptr) \
331 \
332 v(int32, thresholdForOptimizeAfterWarmUp, 1000, Normal, nullptr) \
333 v(int32, thresholdForOptimizeAfterLongWarmUp, 1000, Normal, nullptr) \
334 v(int32, thresholdForOptimizeSoon, 1000, Normal, nullptr) \
335 v(int32, executionCounterIncrementForLoop, 1, Normal, nullptr) \
336 v(int32, executionCounterIncrementForEntry, 15, Normal, nullptr) \
337 \
338 v(int32, thresholdForFTLOptimizeAfterWarmUp, 100000, Normal, nullptr) \
339 v(int32, thresholdForFTLOptimizeSoon, 1000, Normal, nullptr) \
340 v(int32, ftlTierUpCounterIncrementForLoop, 1, Normal, nullptr) \
341 v(int32, ftlTierUpCounterIncrementForReturn, 15, Normal, nullptr) \
342 v(unsigned, ftlOSREntryFailureCountForReoptimization, 15, Normal, nullptr) \
343 v(unsigned, ftlOSREntryRetryThreshold, 100, Normal, nullptr) \
344 \
345 v(int32, evalThresholdMultiplier, 10, Normal, nullptr) \
346 v(unsigned, maximumEvalCacheableSourceLength, 256, Normal, nullptr) \
347 \
348 v(bool, randomizeExecutionCountsBetweenCheckpoints, false, Normal, nullptr) \
349 v(int32, maximumExecutionCountsBetweenCheckpointsForBaseline, 1000, Normal, nullptr) \
350 v(int32, maximumExecutionCountsBetweenCheckpointsForUpperTiers, 50000, Normal, nullptr) \
351 \
352 v(unsigned, likelyToTakeSlowCaseMinimumCount, 20, Normal, nullptr) \
353 v(unsigned, couldTakeSlowCaseMinimumCount, 10, Normal, nullptr) \
354 \
355 v(unsigned, osrExitCountForReoptimization, 100, Normal, nullptr) \
356 v(unsigned, osrExitCountForReoptimizationFromLoop, 5, Normal, nullptr) \
357 \
358 v(unsigned, reoptimizationRetryCounterMax, 0, Normal, nullptr) \
359 \
360 v(unsigned, minimumOptimizationDelay, 1, Normal, nullptr) \
361 v(unsigned, maximumOptimizationDelay, 5, Normal, nullptr) \
362 v(double, desiredProfileLivenessRate, 0.75, Normal, nullptr) \
363 v(double, desiredProfileFullnessRate, 0.35, Normal, nullptr) \
364 \
365 v(double, doubleVoteRatioForDoubleFormat, 2, Normal, nullptr) \
366 v(double, structureCheckVoteRatioForHoisting, 1, Normal, nullptr) \
367 v(double, checkArrayVoteRatioForHoisting, 1, Normal, nullptr) \
368 \
369 v(unsigned, maximumDirectCallStackSize, 200, Normal, nullptr) \
370 \
371 v(unsigned, minimumNumberOfScansBetweenRebalance, 100, Normal, nullptr) \
372 v(unsigned, numberOfGCMarkers, computeNumberOfGCMarkers(8), Normal, nullptr) \
373 v(bool, useParallelMarkingConstraintSolver, true, Normal, nullptr) \
374 v(unsigned, opaqueRootMergeThreshold, 1000, Normal, nullptr) \
375 v(double, minHeapUtilization, 0.8, Normal, nullptr) \
376 v(double, minMarkedBlockUtilization, 0.9, Normal, nullptr) \
377 v(unsigned, slowPathAllocsBetweenGCs, 0, Normal, "force a GC on every Nth slow path alloc, where N is specified by this option") \
378 \
379 v(double, percentCPUPerMBForFullTimer, 0.0003125, Normal, nullptr) \
380 v(double, percentCPUPerMBForEdenTimer, 0.0025, Normal, nullptr) \
381 v(double, collectionTimerMaxPercentCPU, 0.05, Normal, nullptr) \
382 \
383 v(bool, forceWeakRandomSeed, false, Normal, nullptr) \
384 v(unsigned, forcedWeakRandomSeed, 0, Normal, nullptr) \
385 \
386 v(bool, useZombieMode, false, Normal, "debugging option to scribble over dead objects with 0xbadbeef0") \
387 v(bool, useImmortalObjects, false, Normal, "debugging option to keep all objects alive forever") \
388 v(bool, sweepSynchronously, false, Normal, "debugging option to sweep all dead objects synchronously at GC end before resuming mutator") \
389 v(unsigned, maxSingleAllocationSize, 0, Configurable, "debugging option to limit individual allocations to a max size (0 = limit not set, N = limit size in bytes)") \
390 \
391 v(gcLogLevel, logGC, GCLogging::None, Normal, "debugging option to log GC activity (0 = None, 1 = Basic, 2 = Verbose)") \
392 v(bool, useGC, true, Normal, nullptr) \
393 v(bool, gcAtEnd, false, Normal, "If true, the jsc CLI will do a GC before exiting") \
394 v(bool, forceGCSlowPaths, false, Normal, "If true, we will force all JIT fast allocations down their slow paths.") \
395 v(unsigned, gcMaxHeapSize, 0, Normal, nullptr) \
396 v(unsigned, forceRAMSize, 0, Normal, nullptr) \
397 v(bool, recordGCPauseTimes, false, Normal, nullptr) \
398 v(bool, dumpHeapStatisticsAtVMDestruction, false, Normal, nullptr) \
399 v(bool, forceCodeBlockToJettisonDueToOldAge, false, Normal, "If true, this means that anytime we can jettison a CodeBlock due to old age, we do.") \
400 v(bool, useEagerCodeBlockJettisonTiming, false, Normal, "If true, the time slices for jettisoning a CodeBlock due to old age are shrunk significantly.") \
401 \
402 v(bool, useTypeProfiler, false, Normal, nullptr) \
403 v(bool, useControlFlowProfiler, false, Normal, nullptr) \
404 \
405 v(bool, useSamplingProfiler, false, Normal, nullptr) \
406 v(unsigned, sampleInterval, 1000, Normal, "Time between stack traces in microseconds.") \
407 v(bool, collectSamplingProfilerDataForJSCShell, false, Normal, "This corresponds to the JSC shell's --sample option.") \
408 v(unsigned, samplingProfilerTopFunctionsCount, 12, Normal, "Number of top functions to report when using the command line interface.") \
409 v(unsigned, samplingProfilerTopBytecodesCount, 40, Normal, "Number of top bytecodes to report when using the command line interface.") \
410 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.") \
411 v(bool, sampleCCode, false, Normal, "Causes the sampling profiler to record profiling data for C frames.") \
412 \
413 v(bool, alwaysGeneratePCToCodeOriginMap, false, Normal, "This will make sure we always generate a PCToCodeOriginMap for JITed code.") \
414 \
415 v(bool, verifyHeap, false, Normal, nullptr) \
416 v(unsigned, numberOfGCCyclesToRecordForVerification, 3, Normal, nullptr) \
417 \
418 v(unsigned, exceptionStackTraceLimit, 100, Normal, "Stack trace limit for internal Exception object") \
419 v(unsigned, defaultErrorStackTraceLimit, 100, Normal, "The default value for Error.stackTraceLimit") \
420 v(bool, useExceptionFuzz, false, Normal, nullptr) \
421 v(unsigned, fireExceptionFuzzAt, 0, Normal, nullptr) \
422 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 */\
423 v(bool, dumpSimulatedThrows, false, Normal, "Dumps the call stack of the last simulated throw if exception scope verification fails") \
424 v(bool, validateExceptionChecks, false, Normal, "Verifies that needed exception checks are performed.") \
425 v(unsigned, unexpectedExceptionStackTraceLimit, 100, Normal, "Stack trace limit for debugging unexpected exceptions observed in the VM") \
426 \
427 v(bool, useExecutableAllocationFuzz, false, Normal, nullptr) \
428 v(unsigned, fireExecutableAllocationFuzzAt, 0, Normal, nullptr) \
429 v(unsigned, fireExecutableAllocationFuzzAtOrAfter, 0, Normal, nullptr) \
430 v(bool, verboseExecutableAllocationFuzz, false, Normal, nullptr) \
431 \
432 v(bool, useOSRExitFuzz, false, Normal, nullptr) \
433 v(unsigned, fireOSRExitFuzzAtStatic, 0, Normal, nullptr) \
434 v(unsigned, fireOSRExitFuzzAt, 0, Normal, nullptr) \
435 v(unsigned, fireOSRExitFuzzAtOrAfter, 0, Normal, nullptr) \
436 \
437 v(bool, useRandomizingFuzzerAgent, false, Normal, nullptr) \
438 v(unsigned, seedOfRandomizingFuzzerAgent, 1, Normal, nullptr) \
439 v(bool, dumpRandomizingFuzzerAgentPredictions, false, Normal, nullptr) \
440 v(bool, useDoublePredictionFuzzerAgent, false, Normal, nullptr) \
441 \
442 v(bool, logPhaseTimes, false, Normal, nullptr) \
443 v(double, rareBlockPenalty, 0.001, Normal, nullptr) \
444 v(bool, airLinearScanVerbose, false, Normal, nullptr) \
445 v(bool, airLinearScanSpillsEverything, false, Normal, nullptr) \
446 v(bool, airForceBriggsAllocator, false, Normal, nullptr) \
447 v(bool, airForceIRCAllocator, false, Normal, nullptr) \
448 v(bool, airRandomizeRegs, false, 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 /* FIXME: enable fast memories on iOS and pre-allocate them. https://bugs.webkit.org/show_bug.cgi?id=170774 */ \
496 v(bool, useWebAssemblyFastMemory, !isIOS(), Normal, "If true, we will try to use a 32-bit address space with a signal handler to bounds check wasm memory.") \
497 v(bool, logWebAssemblyMemory, false, Normal, nullptr) \
498 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") \
499 v(bool, crashIfWebAssemblyCantFastMemory, false, Normal, "If true, we will crash if we can't obtain fast memory for wasm.") \
500 v(unsigned, maxNumWebAssemblyFastMemories, 4, Normal, nullptr) \
501 v(bool, useFastTLSForWasmContext, true, Normal, "If true, we will store context in fast TLS. If false, we will pin it to a register.") \
502 v(bool, wasmBBQUsesAir, true, Normal, nullptr) \
503 v(bool, useWebAssemblyStreamingApi, enableWebAssemblyStreamingApi, Normal, "Allow to run WebAssembly's Streaming API") \
504 v(bool, useCallICsForWebAssemblyToJSCalls, true, Normal, "If true, we will use CallLinkInfo to inline cache Wasm to JS calls.") \
505 v(bool, useEagerWebAssemblyModuleHashing, false, Normal, "Unnamed WebAssembly modules are identified in backtraces through their hash, if available.") \
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
522
523enum OptionEquivalence {
524 SameOption,
525 InvertedOption,
526};
527
528#define JSC_ALIASED_OPTIONS(v) \
529 v(enableFunctionDotArguments, useFunctionDotArguments, SameOption) \
530 v(enableTailCalls, useTailCalls, SameOption) \
531 v(showDisassembly, dumpDisassembly, SameOption) \
532 v(showDFGDisassembly, dumpDFGDisassembly, SameOption) \
533 v(showFTLDisassembly, dumpFTLDisassembly, SameOption) \
534 v(showAllDFGNodes, dumpAllDFGNodes, SameOption) \
535 v(alwaysDoFullCollection, useGenerationalGC, InvertedOption) \
536 v(enableOSREntryToDFG, useOSREntryToDFG, SameOption) \
537 v(enableOSREntryToFTL, useOSREntryToFTL, SameOption) \
538 v(enableAccessInlining, useAccessInlining, SameOption) \
539 v(enablePolyvariantDevirtualization, usePolyvariantDevirtualization, SameOption) \
540 v(enablePolymorphicAccessInlining, usePolymorphicAccessInlining, SameOption) \
541 v(enablePolymorphicCallInlining, usePolymorphicCallInlining, SameOption) \
542 v(enableMovHintRemoval, useMovHintRemoval, SameOption) \
543 v(enableObjectAllocationSinking, useObjectAllocationSinking, SameOption) \
544 v(enableConcurrentJIT, useConcurrentJIT, SameOption) \
545 v(enableProfiler, useProfiler, SameOption) \
546 v(enableArchitectureSpecificOptimizations, useArchitectureSpecificOptimizations, SameOption) \
547 v(enablePolyvariantCallInlining, usePolyvariantCallInlining, SameOption) \
548 v(enablePolyvariantByIdInlining, usePolyvariantByIdInlining, SameOption) \
549 v(enableMaximalFlushInsertionPhase, useMaximalFlushInsertionPhase, SameOption) \
550 v(objectsAreImmortal, useImmortalObjects, SameOption) \
551 v(showObjectStatistics, dumpObjectStatistics, SameOption) \
552 v(disableGC, useGC, InvertedOption) \
553 v(enableTypeProfiler, useTypeProfiler, SameOption) \
554 v(enableControlFlowProfiler, useControlFlowProfiler, SameOption) \
555 v(enableExceptionFuzz, useExceptionFuzz, SameOption) \
556 v(enableExecutableAllocationFuzz, useExecutableAllocationFuzz, SameOption) \
557 v(enableOSRExitFuzz, useOSRExitFuzz, SameOption) \
558 v(enableDollarVM, useDollarVM, SameOption) \
559 v(enableWebAssembly, useWebAssembly, SameOption) \
560 v(verboseDFGByteCodeParsing, verboseDFGBytecodeParsing, SameOption) \
561
562
563class Options {
564public:
565 enum class DumpLevel {
566 None = 0,
567 Overridden,
568 All,
569 Verbose
570 };
571
572 enum class Availability {
573 Normal = 0,
574 Restricted,
575 Configurable
576 };
577
578 // This typedef is to allow us to eliminate the '_' in the field name in
579 // union inside Entry. This is needed to keep the style checker happy.
580 typedef int32_t int32;
581 typedef size_t size;
582
583 // Declare the option IDs:
584 enum ID {
585#define FOR_EACH_OPTION(type_, name_, defaultValue_, availability_, description_) \
586 name_##ID,
587 JSC_OPTIONS(FOR_EACH_OPTION)
588#undef FOR_EACH_OPTION
589 numberOfOptions
590 };
591
592 enum class Type {
593 boolType,
594 unsignedType,
595 doubleType,
596 int32Type,
597 sizeType,
598 optionRangeType,
599 optionStringType,
600 gcLogLevelType,
601 };
602
603 JS_EXPORT_PRIVATE static void initialize();
604
605 // Parses a string of options where each option is of the format "--<optionName>=<value>"
606 // and are separated by a space. The leading "--" is optional and will be ignored.
607 JS_EXPORT_PRIVATE static bool setOptions(const char* optionsList);
608
609 // Parses a single command line option in the format "<optionName>=<value>"
610 // (no spaces allowed) and set the specified option if appropriate.
611 JS_EXPORT_PRIVATE static bool setOption(const char* arg);
612
613 JS_EXPORT_PRIVATE static void dumpAllOptions(FILE*, DumpLevel, const char* title = nullptr);
614 JS_EXPORT_PRIVATE static void dumpAllOptionsInALine(StringBuilder&);
615
616 JS_EXPORT_PRIVATE static void ensureOptionsAreCoherent();
617
618 JS_EXPORT_PRIVATE static void enableRestrictedOptions(bool enableOrNot);
619
620 // Declare accessors for each option:
621#define FOR_EACH_OPTION(type_, name_, defaultValue_, availability_, description_) \
622 ALWAYS_INLINE static type_& name_() { return s_options[name_##ID].type_##Val; } \
623 ALWAYS_INLINE static type_& name_##Default() { return s_defaultOptions[name_##ID].type_##Val; }
624
625 JSC_OPTIONS(FOR_EACH_OPTION)
626#undef FOR_EACH_OPTION
627
628 static bool isAvailable(ID, Availability);
629
630private:
631 // For storing for an option value:
632 union Entry {
633 bool boolVal;
634 unsigned unsignedVal;
635 double doubleVal;
636 int32 int32Val;
637 size sizeVal;
638 OptionRange optionRangeVal;
639 const char* optionStringVal;
640 GCLogging::Level gcLogLevelVal;
641 };
642
643 // For storing constant meta data about each option:
644 struct EntryInfo {
645 const char* name;
646 const char* description;
647 Type type;
648 Availability availability;
649 };
650
651 Options();
652
653 enum DumpDefaultsOption {
654 DontDumpDefaults,
655 DumpDefaults
656 };
657 static void dumpOptionsIfNeeded();
658 static void dumpAllOptions(StringBuilder&, DumpLevel, const char* title,
659 const char* separator, const char* optionHeader, const char* optionFooter, DumpDefaultsOption);
660 static void dumpOption(StringBuilder&, DumpLevel, ID,
661 const char* optionHeader, const char* optionFooter, DumpDefaultsOption);
662
663 static bool setOptionWithoutAlias(const char* arg);
664 static bool setAliasedOption(const char* arg);
665 static bool overrideAliasedOptionWithHeuristic(const char* name);
666
667 // Declare the singleton instance of the options store:
668 JS_EXPORT_PRIVATE static Entry s_options[numberOfOptions];
669 static Entry s_defaultOptions[numberOfOptions];
670 static const EntryInfo s_optionsInfo[numberOfOptions];
671
672 friend class Option;
673};
674
675class Option {
676public:
677 Option(Options::ID id)
678 : m_id(id)
679 , m_entry(Options::s_options[m_id])
680 {
681 }
682
683 void dump(StringBuilder&) const;
684
685 bool operator==(const Option& other) const;
686 bool operator!=(const Option& other) const { return !(*this == other); }
687
688 Options::ID id() const { return m_id; }
689 const char* name() const;
690 const char* description() const;
691 Options::Type type() const;
692 Options::Availability availability() const;
693 bool isOverridden() const;
694 const Option defaultOption() const;
695
696 bool& boolVal();
697 unsigned& unsignedVal();
698 double& doubleVal();
699 int32_t& int32Val();
700 OptionRange optionRangeVal();
701 const char* optionStringVal();
702 GCLogging::Level& gcLogLevelVal();
703
704private:
705 // Only used for constructing default Options.
706 Option(Options::ID id, Options::Entry& entry)
707 : m_id(id)
708 , m_entry(entry)
709 {
710 }
711
712 Options::ID m_id;
713 Options::Entry& m_entry;
714};
715
716inline const char* Option::name() const
717{
718 return Options::s_optionsInfo[m_id].name;
719}
720
721inline const char* Option::description() const
722{
723 return Options::s_optionsInfo[m_id].description;
724}
725
726inline Options::Type Option::type() const
727{
728 return Options::s_optionsInfo[m_id].type;
729}
730
731inline Options::Availability Option::availability() const
732{
733 return Options::s_optionsInfo[m_id].availability;
734}
735
736inline bool Option::isOverridden() const
737{
738 return *this != defaultOption();
739}
740
741inline const Option Option::defaultOption() const
742{
743 return Option(m_id, Options::s_defaultOptions[m_id]);
744}
745
746inline bool& Option::boolVal()
747{
748 return m_entry.boolVal;
749}
750
751inline unsigned& Option::unsignedVal()
752{
753 return m_entry.unsignedVal;
754}
755
756inline double& Option::doubleVal()
757{
758 return m_entry.doubleVal;
759}
760
761inline int32_t& Option::int32Val()
762{
763 return m_entry.int32Val;
764}
765
766inline OptionRange Option::optionRangeVal()
767{
768 return m_entry.optionRangeVal;
769}
770
771inline const char* Option::optionStringVal()
772{
773 return m_entry.optionStringVal;
774}
775
776inline GCLogging::Level& Option::gcLogLevelVal()
777{
778 return m_entry.gcLogLevelVal;
779}
780
781} // namespace JSC
782