]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/Options.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / Options.h
1 /*
2 * Copyright (C) 2011-2015 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
36 namespace JSC {
37
38 // How do JSC VM options work?
39 // ===========================
40 // The JSC_OPTIONS() macro below defines a list of all JSC options in use,
41 // along with their types and default values. The options values are actually
42 // realized as an array of Options::Entry elements.
43 //
44 // Options::initialize() will initialize the array of options values with
45 // the defaults specified in JSC_OPTIONS() below. After that, the values can
46 // be programmatically read and written to using an accessor method with the
47 // same name as the option. For example, the option "useJIT" can be read and
48 // set like so:
49 //
50 // bool jitIsOn = Options::useJIT(); // Get the option value.
51 // Options::useJIT() = false; // Sets the option value.
52 //
53 // If you want to tweak any of these values programmatically for testing
54 // purposes, you can do so in Options::initialize() after the default values
55 // are set.
56 //
57 // Alternatively, you can override the default values by specifying
58 // environment variables of the form: JSC_<name of JSC option>.
59 //
60 // Note: Options::initialize() tries to ensure some sanity on the option values
61 // which are set by doing some range checks, and value corrections. These
62 // checks are done after the option values are set. If you alter the option
63 // values after the sanity checks (for your own testing), then you're liable to
64 // ensure that the new values set are sane and reasonable for your own run.
65
66 class OptionRange {
67 private:
68 enum RangeState { Uninitialized, InitError, Normal, Inverted };
69 public:
70 OptionRange& operator= (const int& rhs)
71 { // Only needed for initialization
72 if (!rhs) {
73 m_state = Uninitialized;
74 m_rangeString = 0;
75 m_lowLimit = 0;
76 m_highLimit = 0;
77 }
78 return *this;
79 }
80
81 bool init(const char*);
82 bool isInRange(unsigned);
83 const char* rangeString() const { return (m_state > InitError) ? m_rangeString : "<null>"; }
84
85 void dump(PrintStream& out) const;
86
87 private:
88 RangeState m_state;
89 const char* m_rangeString;
90 unsigned m_lowLimit;
91 unsigned m_highLimit;
92 };
93
94 typedef OptionRange optionRange;
95 typedef const char* optionString;
96
97 #define JSC_OPTIONS(v) \
98 v(unsigned, showOptions, 0, "shows JSC options (0 = None, 1 = Overridden only, 2 = All, 3 = Verbose)") \
99 \
100 v(bool, useLLInt, true, "allows the LLINT to be used if true") \
101 v(bool, useJIT, true, "allows the baseline JIT to be used if true") \
102 v(bool, useDFGJIT, true, "allows the DFG JIT to be used if true") \
103 v(bool, useRegExpJIT, true, "allows the RegExp JIT to be used if true") \
104 \
105 v(bool, reportMustSucceedExecutableAllocations, false, nullptr) \
106 \
107 v(unsigned, maxPerThreadStackUsage, 4 * MB, nullptr) \
108 v(unsigned, reservedZoneSize, 128 * KB, nullptr) \
109 v(unsigned, errorModeReservedZoneSize, 64 * KB, nullptr) \
110 \
111 v(bool, crashIfCantAllocateJITMemory, false, nullptr) \
112 v(unsigned, jitMemoryReservationSize, 0, nullptr) \
113 \
114 v(bool, forceDFGCodeBlockLiveness, false, nullptr) \
115 v(bool, forceICFailure, false, nullptr) \
116 \
117 v(bool, dumpGeneratedBytecodes, false, nullptr) \
118 v(bool, dumpBytecodeLivenessResults, false, nullptr) \
119 v(bool, validateBytecode, false, nullptr) \
120 v(bool, forceDebuggerBytecodeGeneration, false, nullptr) \
121 v(bool, forceProfilerBytecodeGeneration, false, nullptr) \
122 \
123 v(bool, enableFunctionDotArguments, true, nullptr) \
124 \
125 /* showDisassembly implies showDFGDisassembly. */ \
126 v(bool, showDisassembly, false, "dumps disassembly of all JIT compiled code upon compilation") \
127 v(bool, asyncDisassembly, false, nullptr) \
128 v(bool, showDFGDisassembly, false, "dumps disassembly of DFG function upon compilation") \
129 v(bool, showFTLDisassembly, false, "dumps disassembly of FTL function upon compilation") \
130 v(bool, showAllDFGNodes, false, nullptr) \
131 v(optionRange, bytecodeRangeToDFGCompile, 0, "bytecode size range to allow DFG compilation on, e.g. 1:100") \
132 v(optionString, dfgWhitelist, nullptr, "file with list of function signatures to allow DFG compilation on") \
133 v(bool, dumpSourceAtDFGTime, false, "dumps source code of JS function being DFG compiled") \
134 v(bool, dumpBytecodeAtDFGTime, false, "dumps bytecode of JS function being DFG compiled") \
135 v(bool, dumpGraphAfterParsing, false, nullptr) \
136 v(bool, dumpGraphAtEachPhase, false, nullptr) \
137 v(bool, verboseDFGByteCodeParsing, false, nullptr) \
138 v(bool, verboseCompilation, false, nullptr) \
139 v(bool, verboseFTLCompilation, false, nullptr) \
140 v(bool, logCompilationChanges, false, nullptr) \
141 v(bool, printEachOSRExit, false, nullptr) \
142 v(bool, validateGraph, false, nullptr) \
143 v(bool, validateGraphAtEachPhase, false, nullptr) \
144 v(bool, verboseValidationFailure, false, nullptr) \
145 v(bool, verboseOSR, false, nullptr) \
146 v(bool, verboseFTLOSRExit, false, nullptr) \
147 v(bool, verboseCallLink, false, nullptr) \
148 v(bool, verboseCompilationQueue, false, nullptr) \
149 v(bool, reportCompileTimes, false, "dumps JS function signature and the time it took to compile") \
150 v(bool, reportFTLCompileTimes, false, "dumps JS function signature and the time it took to FTL compile") \
151 v(bool, verboseCFA, false, nullptr) \
152 v(bool, verboseFTLToJSThunk, false, nullptr) \
153 v(bool, verboseFTLFailure, false, nullptr) \
154 v(bool, alwaysComputeHash, false, nullptr) \
155 v(bool, testTheFTL, false, nullptr) \
156 v(bool, verboseSanitizeStack, false, nullptr) \
157 v(bool, alwaysDoFullCollection, false, nullptr) \
158 v(bool, eagerlyUpdateTopCallFrame, false, nullptr) \
159 \
160 v(bool, enableOSREntryToDFG, true, nullptr) \
161 v(bool, enableOSREntryToFTL, true, nullptr) \
162 \
163 v(bool, useFTLJIT, true, "allows the FTL JIT to be used if true") \
164 v(bool, useFTLTBAA, true, nullptr) \
165 v(bool, enableLLVMFastISel, false, nullptr) \
166 v(bool, useLLVMSmallCodeModel, false, nullptr) \
167 v(bool, dumpLLVMIR, false, nullptr) \
168 v(bool, validateFTLOSRExitLiveness, false, nullptr) \
169 v(bool, llvmAlwaysFailsBeforeCompile, false, nullptr) \
170 v(bool, llvmAlwaysFailsBeforeLink, false, nullptr) \
171 v(bool, llvmSimpleOpt, true, nullptr) \
172 v(unsigned, llvmBackendOptimizationLevel, 2, nullptr) \
173 v(unsigned, llvmOptimizationLevel, 2, nullptr) \
174 v(unsigned, llvmSizeLevel, 0, nullptr) \
175 v(unsigned, llvmMaxStackSize, 128 * KB, nullptr) \
176 v(bool, llvmDisallowAVX, true, nullptr) \
177 v(bool, ftlCrashes, false, nullptr) /* fool-proof way of checking that you ended up in the FTL. ;-) */\
178 v(bool, ftlCrashesIfCantInitializeLLVM, false, nullptr) \
179 v(bool, clobberAllRegsInFTLICSlowPath, !ASSERT_DISABLED, nullptr) \
180 v(bool, assumeAllRegsInFTLICAreLive, false, nullptr) \
181 v(bool, enableAccessInlining, true, nullptr) \
182 v(bool, enablePolyvariantDevirtualization, true, nullptr) \
183 v(bool, enablePolymorphicAccessInlining, true, nullptr) \
184 v(bool, enablePolymorphicCallInlining, true, nullptr) \
185 v(unsigned, maxPolymorphicCallVariantListSize, 15, nullptr) \
186 v(unsigned, maxPolymorphicCallVariantListSizeForTopTier, 5, nullptr) \
187 v(unsigned, maxPolymorphicCallVariantsForInlining, 5, nullptr) \
188 v(unsigned, frequentCallThreshold, 2, nullptr) \
189 v(double, minimumCallToKnownRate, 0.51, nullptr) \
190 v(bool, optimizeNativeCalls, false, nullptr) \
191 v(bool, enableMovHintRemoval, true, nullptr) \
192 v(bool, enableObjectAllocationSinking, true, nullptr) \
193 \
194 v(bool, enableConcurrentJIT, true, "allows the DFG / FTL compilation in threads other than the executing JS thread") \
195 v(unsigned, numberOfDFGCompilerThreads, computeNumberOfWorkerThreads(2, 2) - 1, nullptr) \
196 v(unsigned, numberOfFTLCompilerThreads, computeNumberOfWorkerThreads(8, 2) - 1, nullptr) \
197 v(int32, priorityDeltaOfDFGCompilerThreads, computePriorityDeltaOfWorkerThreads(-1, 0), nullptr) \
198 v(int32, priorityDeltaOfFTLCompilerThreads, computePriorityDeltaOfWorkerThreads(-2, 0), nullptr) \
199 \
200 v(bool, enableProfiler, false, nullptr) \
201 \
202 v(bool, forceUDis86Disassembler, false, nullptr) \
203 v(bool, forceLLVMDisassembler, false, nullptr) \
204 \
205 v(bool, enableArchitectureSpecificOptimizations, true, nullptr) \
206 \
207 v(bool, breakOnThrow, false, nullptr) \
208 \
209 v(unsigned, maximumOptimizationCandidateInstructionCount, 100000, nullptr) \
210 \
211 v(unsigned, maximumFunctionForCallInlineCandidateInstructionCount, 180, nullptr) \
212 v(unsigned, maximumFunctionForClosureCallInlineCandidateInstructionCount, 100, nullptr) \
213 v(unsigned, maximumFunctionForConstructInlineCandidateInstructionCount, 100, nullptr) \
214 \
215 v(unsigned, maximumFTLCandidateInstructionCount, 20000, nullptr) \
216 \
217 /* Depth of inline stack, so 1 = no inlining, 2 = one level, etc. */ \
218 v(unsigned, maximumInliningDepth, 5, "maximum allowed inlining depth. Depth of 1 means no inlining") \
219 v(unsigned, maximumInliningRecursion, 2, nullptr) \
220 \
221 v(unsigned, maximumLLVMInstructionCountForNativeInlining, 80, nullptr) \
222 \
223 /* Maximum size of a caller for enabling inlining. This is purely to protect us */\
224 /* from super long compiles that take a lot of memory. */\
225 v(unsigned, maximumInliningCallerSize, 10000, nullptr) \
226 \
227 v(unsigned, maximumVarargsForInlining, 100, nullptr) \
228 \
229 v(bool, enablePolyvariantCallInlining, true, nullptr) \
230 v(bool, enablePolyvariantByIdInlining, true, nullptr) \
231 \
232 v(unsigned, maximumBinaryStringSwitchCaseLength, 50, nullptr) \
233 v(unsigned, maximumBinaryStringSwitchTotalLength, 2000, nullptr) \
234 \
235 v(double, jitPolicyScale, 1.0, "scale JIT thresholds to this specified ratio between 0.0 (compile ASAP) and 1.0 (compile like normal).") \
236 v(bool, forceEagerCompilation, false, nullptr) \
237 v(int32, thresholdForJITAfterWarmUp, 500, nullptr) \
238 v(int32, thresholdForJITSoon, 100, nullptr) \
239 \
240 v(int32, thresholdForOptimizeAfterWarmUp, 1000, nullptr) \
241 v(int32, thresholdForOptimizeAfterLongWarmUp, 1000, nullptr) \
242 v(int32, thresholdForOptimizeSoon, 1000, nullptr) \
243 v(int32, executionCounterIncrementForLoop, 1, nullptr) \
244 v(int32, executionCounterIncrementForEntry, 15, nullptr) \
245 \
246 v(int32, thresholdForFTLOptimizeAfterWarmUp, 100000, nullptr) \
247 v(int32, thresholdForFTLOptimizeSoon, 1000, nullptr) \
248 v(int32, ftlTierUpCounterIncrementForLoop, 1, nullptr) \
249 v(int32, ftlTierUpCounterIncrementForReturn, 15, nullptr) \
250 v(unsigned, ftlOSREntryFailureCountForReoptimization, 15, nullptr) \
251 v(unsigned, ftlOSREntryRetryThreshold, 100, nullptr) \
252 \
253 v(int32, evalThresholdMultiplier, 10, nullptr) \
254 v(unsigned, maximumEvalCacheableSourceLength, 256, nullptr) \
255 \
256 v(bool, randomizeExecutionCountsBetweenCheckpoints, false, nullptr) \
257 v(int32, maximumExecutionCountsBetweenCheckpointsForBaseline, 1000, nullptr) \
258 v(int32, maximumExecutionCountsBetweenCheckpointsForUpperTiers, 50000, nullptr) \
259 \
260 v(unsigned, likelyToTakeSlowCaseMinimumCount, 20, nullptr) \
261 v(unsigned, couldTakeSlowCaseMinimumCount, 10, nullptr) \
262 \
263 v(unsigned, osrExitCountForReoptimization, 100, nullptr) \
264 v(unsigned, osrExitCountForReoptimizationFromLoop, 5, nullptr) \
265 \
266 v(unsigned, reoptimizationRetryCounterMax, 0, nullptr) \
267 \
268 v(unsigned, minimumOptimizationDelay, 1, nullptr) \
269 v(unsigned, maximumOptimizationDelay, 5, nullptr) \
270 v(double, desiredProfileLivenessRate, 0.75, nullptr) \
271 v(double, desiredProfileFullnessRate, 0.35, nullptr) \
272 \
273 v(double, doubleVoteRatioForDoubleFormat, 2, nullptr) \
274 v(double, structureCheckVoteRatioForHoisting, 1, nullptr) \
275 v(double, checkArrayVoteRatioForHoisting, 1, nullptr) \
276 \
277 v(unsigned, minimumNumberOfScansBetweenRebalance, 100, nullptr) \
278 v(unsigned, numberOfGCMarkers, computeNumberOfGCMarkers(7), nullptr) \
279 v(unsigned, opaqueRootMergeThreshold, 1000, nullptr) \
280 v(double, minHeapUtilization, 0.8, nullptr) \
281 v(double, minCopiedBlockUtilization, 0.9, nullptr) \
282 v(double, minMarkedBlockUtilization, 0.9, nullptr) \
283 v(unsigned, slowPathAllocsBetweenGCs, 0, "force a GC on every Nth slow path alloc, where N is specified by this option") \
284 \
285 v(double, percentCPUPerMBForFullTimer, 0.0003125, nullptr) \
286 v(double, percentCPUPerMBForEdenTimer, 0.0025, nullptr) \
287 v(double, collectionTimerMaxPercentCPU, 0.05, nullptr) \
288 \
289 v(bool, forceWeakRandomSeed, false, nullptr) \
290 v(unsigned, forcedWeakRandomSeed, 0, nullptr) \
291 \
292 v(bool, useZombieMode, false, "debugging option to scribble over dead objects with 0xdeadbeef") \
293 v(bool, objectsAreImmortal, false, "debugging option to keep all objects alive forever") \
294 v(bool, showObjectStatistics, false, nullptr) \
295 \
296 v(gcLogLevel, logGC, GCLogging::None, "debugging option to log GC activity (0 = None, 1 = Basic, 2 = Verbose)") \
297 v(bool, disableGC, false, nullptr) \
298 v(unsigned, gcMaxHeapSize, 0, nullptr) \
299 v(unsigned, forceRAMSize, 0, nullptr) \
300 v(bool, recordGCPauseTimes, false, nullptr) \
301 v(bool, logHeapStatisticsAtExit, false, nullptr) \
302 v(bool, enableTypeProfiler, false, nullptr) \
303 v(bool, enableControlFlowProfiler, false, nullptr) \
304 \
305 v(bool, verifyHeap, false, nullptr) \
306 v(unsigned, numberOfGCCyclesToRecordForVerification, 3, nullptr) \
307 \
308 v(bool, enableExceptionFuzz, false, nullptr) \
309 v(unsigned, fireExceptionFuzzAt, 0, nullptr) \
310 \
311 v(bool, enableExecutableAllocationFuzz, false, nullptr) \
312 v(unsigned, fireExecutableAllocationFuzzAt, 0, nullptr) \
313 v(unsigned, fireExecutableAllocationFuzzAtOrAfter, 0, nullptr) \
314 v(bool, verboseExecutableAllocationFuzz, false, nullptr) \
315 \
316 v(bool, enableOSRExitFuzz, false, nullptr) \
317 v(unsigned, fireOSRExitFuzzAtStatic, 0, nullptr) \
318 v(unsigned, fireOSRExitFuzzAt, 0, nullptr) \
319 v(unsigned, fireOSRExitFuzzAtOrAfter, 0, nullptr) \
320 \
321 v(bool, enableDollarVM, false, "installs the $vm debugging tool in global objects") \
322 v(optionString, functionOverrides, nullptr, "file with debugging overrides for function bodies") \
323
324 class Options {
325 public:
326 enum class DumpLevel {
327 None = 0,
328 Overridden,
329 All,
330 Verbose
331 };
332
333 // This typedef is to allow us to eliminate the '_' in the field name in
334 // union inside Entry. This is needed to keep the style checker happy.
335 typedef int32_t int32;
336
337 // Declare the option IDs:
338 enum OptionID {
339 #define FOR_EACH_OPTION(type_, name_, defaultValue_, description_) \
340 name_##ID,
341 JSC_OPTIONS(FOR_EACH_OPTION)
342 #undef FOR_EACH_OPTION
343 numberOfOptions
344 };
345
346 enum class Type {
347 boolType,
348 unsignedType,
349 doubleType,
350 int32Type,
351 optionRangeType,
352 optionStringType,
353 gcLogLevelType,
354 };
355
356 JS_EXPORT_PRIVATE static void initialize();
357
358 // Parses a single command line option in the format "<optionName>=<value>"
359 // (no spaces allowed) and set the specified option if appropriate.
360 JS_EXPORT_PRIVATE static bool setOption(const char* arg);
361 JS_EXPORT_PRIVATE static void dumpAllOptions(DumpLevel, const char* title = nullptr, FILE* stream = stdout);
362 static void dumpOption(DumpLevel, OptionID, FILE* stream = stdout, const char* header = "", const char* footer = "");
363 JS_EXPORT_PRIVATE static void ensureOptionsAreCoherent();
364
365 // Declare accessors for each option:
366 #define FOR_EACH_OPTION(type_, name_, defaultValue_, description_) \
367 ALWAYS_INLINE static type_& name_() { return s_options[name_##ID].type_##Val; } \
368 ALWAYS_INLINE static type_& name_##Default() { return s_defaultOptions[name_##ID].type_##Val; }
369
370 JSC_OPTIONS(FOR_EACH_OPTION)
371 #undef FOR_EACH_OPTION
372
373 private:
374 // For storing for an option value:
375 union Entry {
376 bool boolVal;
377 unsigned unsignedVal;
378 double doubleVal;
379 int32 int32Val;
380 OptionRange optionRangeVal;
381 const char* optionStringVal;
382 GCLogging::Level gcLogLevelVal;
383 };
384
385 // For storing constant meta data about each option:
386 struct EntryInfo {
387 const char* name;
388 const char* description;
389 Type type;
390 };
391
392 Options();
393
394 // Declare the singleton instance of the options store:
395 JS_EXPORTDATA static Entry s_options[numberOfOptions];
396 static Entry s_defaultOptions[numberOfOptions];
397 static const EntryInfo s_optionsInfo[numberOfOptions];
398
399 friend class Option;
400 };
401
402 class Option {
403 public:
404 Option(Options::OptionID id)
405 : m_id(id)
406 , m_entry(Options::s_options[m_id])
407 {
408 }
409
410 void dump(FILE*) const;
411 bool operator==(const Option& other) const;
412 bool operator!=(const Option& other) const { return !(*this == other); }
413
414 const char* name() const;
415 const char* description() const;
416 Options::Type type() const;
417 bool isOverridden() const;
418 const Option defaultOption() const;
419
420 bool& boolVal();
421 unsigned& unsignedVal();
422 double& doubleVal();
423 int32_t& int32Val();
424 OptionRange optionRangeVal();
425 const char* optionStringVal();
426 GCLogging::Level& gcLogLevelVal();
427
428 private:
429 // Only used for constructing default Options.
430 Option(Options::OptionID id, Options::Entry& entry)
431 : m_id(id)
432 , m_entry(entry)
433 {
434 }
435
436 Options::OptionID m_id;
437 Options::Entry& m_entry;
438 };
439
440 inline const char* Option::name() const
441 {
442 return Options::s_optionsInfo[m_id].name;
443 }
444
445 inline const char* Option::description() const
446 {
447 return Options::s_optionsInfo[m_id].description;
448 }
449
450 inline Options::Type Option::type() const
451 {
452 return Options::s_optionsInfo[m_id].type;
453 }
454
455 inline bool Option::isOverridden() const
456 {
457 return *this != defaultOption();
458 }
459
460 inline const Option Option::defaultOption() const
461 {
462 return Option(m_id, Options::s_defaultOptions[m_id]);
463 }
464
465 inline bool& Option::boolVal()
466 {
467 return m_entry.boolVal;
468 }
469
470 inline unsigned& Option::unsignedVal()
471 {
472 return m_entry.unsignedVal;
473 }
474
475 inline double& Option::doubleVal()
476 {
477 return m_entry.doubleVal;
478 }
479
480 inline int32_t& Option::int32Val()
481 {
482 return m_entry.int32Val;
483 }
484
485 inline OptionRange Option::optionRangeVal()
486 {
487 return m_entry.optionRangeVal;
488 }
489
490 inline const char* Option::optionStringVal()
491 {
492 return m_entry.optionStringVal;
493 }
494
495 inline GCLogging::Level& Option::gcLogLevelVal()
496 {
497 return m_entry.gcLogLevelVal;
498 }
499
500 } // namespace JSC
501
502 #endif // Options_h