fourthTier: Landing the initial FTL logic in a single commit to avoid spurious
[WebKit-https.git] / Source / JavaScriptCore / runtime / Options.h
index 2f80bf6..1e28a9a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #ifndef Options_h
 #define Options_h
 
+#include "JSExportMacros.h"
 #include <stdint.h>
+#include <stdio.h>
 
-namespace JSC { namespace Options {
+namespace JSC {
 
-// maximumInliningDepth is the maximum depth of inline stack, so 1 = no
-// inlining, 2 = one level, etc
+// How do JSC VM options work?
+// ===========================
+// The JSC_OPTIONS() macro below defines a list of all JSC options in use,
+// along with their types and default values. The options values are actually
+// realized as an array of Options::Entry elements.
+//
+//     Options::initialize() will initialize the array of options values with
+// the defaults specified in JSC_OPTIONS() below. After that, the values can
+// be programmatically read and written to using an accessor method with the
+// same name as the option. For example, the option "useJIT" can be read and
+// set like so:
+//
+//     bool jitIsOn = Options::useJIT();  // Get the option value.
+//     Options::useJIT() = false;         // Sets the option value.
+//
+//     If you want to tweak any of these values programmatically for testing
+// purposes, you can do so in Options::initialize() after the default values
+// are set.
+//
+//     Alternatively, you can override the default values by specifying
+// environment variables of the form: JSC_<name of JSC option>.
+//
+// Note: Options::initialize() tries to ensure some sanity on the option values
+// which are set by doing some range checks, and value corrections. These
+// checks are done after the option values are set. If you alter the option
+// values after the sanity checks (for your own testing), then you're liable to
+// ensure that the new values set are sane and reasonable for your own run.
 
-// couldTakeSlowCaseThreshold shouldn't be zero because some ops will spuriously
-// take slow case, for example for linking or caching.
+class OptionRange {
+private:
+    enum RangeState { Uninitialized, InitError, Normal, Inverted };
+public:
+    OptionRange& operator= (const int& rhs)
+    { // Only needed for initialization
+        if (!rhs) {
+            m_state = Uninitialized;
+            m_rangeString = 0;
+            m_lowLimit = 0;
+            m_highLimit = 0;
+        }
+        return *this;
+    }
 
-#define FOR_EACH_HEURISTIC(m) \
-    m(unsigned, maximumOptimizationCandidateInstructionCount, 1000) \
+    bool init(const char*);
+    bool isInRange(unsigned);
+    const char* rangeString() { return (m_state > InitError) ? m_rangeString : "<null>"; }
+
+private:
+    RangeState m_state;
+    const char* m_rangeString;
+    unsigned m_lowLimit;
+    unsigned m_highLimit;
+};
+
+typedef OptionRange optionRange;
+
+#define JSC_OPTIONS(v) \
+    v(bool, useJIT,    true) \
+    v(bool, useDFGJIT, true) \
+    v(bool, useRegExpJIT, true) \
+    \
+    v(bool, forceDFGCodeBlockLiveness, false) \
+    \
+    v(bool, dumpGeneratedBytecodes, false) \
+    \
+    /* showDisassembly implies showDFGDisassembly. */ \
+    v(bool, showDisassembly, false) \
+    v(bool, showDFGDisassembly, false) \
+    v(bool, showAllDFGNodes, false) \
+    v(optionRange, bytecodeRangeToDFGCompile, 0) \
+    v(bool, dumpBytecodeAtDFGTime, false) \
+    v(bool, dumpGraphAtEachPhase, false) \
+    v(bool, verboseCompilation, false) \
+    v(bool, logCompilationChanges, false) \
+    v(bool, printEachOSRExit, false) \
+    v(bool, validateGraph, false) \
+    v(bool, validateGraphAtEachPhase, false) \
+    \
+    v(bool, useExperimentalFTL, false) \
+    v(bool, useFTLTBAA, true) \
+    v(bool, enableLLVMLICM, true) \
+    v(unsigned, llvmOptimizationLevel, 2) \
+    \
+    v(bool, enableProfiler, false) \
+    \
+    v(unsigned, maximumOptimizationCandidateInstructionCount, 10000) \
+    \
+    v(unsigned, maximumFunctionForCallInlineCandidateInstructionCount, 180) \
+    v(unsigned, maximumFunctionForClosureCallInlineCandidateInstructionCount, 100) \
+    v(unsigned, maximumFunctionForConstructInlineCandidateInstructionCount, 100) \
+    \
+    /* Depth of inline stack, so 1 = no inlining, 2 = one level, etc. */ \
+    v(unsigned, maximumInliningDepth, 5) \
+    \
+    v(int32, thresholdForJITAfterWarmUp, 100) \
+    v(int32, thresholdForJITSoon, 100) \
     \
-    m(unsigned, maximumFunctionForCallInlineCandidateInstructionCount, 150) \
-    m(unsigned, maximumFunctionForConstructInlineCandidateInstructionCount, 80) \
+    v(int32, thresholdForOptimizeAfterWarmUp, 1000) \
+    v(int32, thresholdForOptimizeAfterLongWarmUp, 1000) \
+    v(int32, thresholdForOptimizeSoon, 1000) \
     \
-    m(unsigned, maximumInliningDepth, 5)                              \
+    v(int32, executionCounterIncrementForLoop, 1) \
+    v(int32, executionCounterIncrementForReturn, 15) \
     \
-    m(int32_t, executionCounterValueForOptimizeAfterWarmUp,      -1000) \
-    m(int32_t, executionCounterValueForOptimizeAfterLongWarmUp,  -5000) \
-    m(int32_t, executionCounterValueForDontOptimizeAnytimeSoon,  std::numeric_limits<int32_t>::min()) \
-    m(int32_t, executionCounterValueForOptimizeSoon,             -1000) \
-    m(int32_t, executionCounterValueForOptimizeNextInvocation,   0) \
+    v(int32, evalThresholdMultiplier, 10) \
     \
-    m(int32_t, executionCounterIncrementForLoop,       1) \
-    m(int32_t, executionCounterIncrementForReturn,     15) \
+    v(bool, randomizeExecutionCountsBetweenCheckpoints, false) \
+    v(int32, maximumExecutionCountsBetweenCheckpoints, 1000) \
     \
-    m(unsigned, desiredSpeculativeSuccessFailRatio,    6) \
+    v(unsigned, likelyToTakeSlowCaseMinimumCount, 100) \
+    v(unsigned, couldTakeSlowCaseMinimumCount, 10) \
     \
-    m(double,   likelyToTakeSlowCaseThreshold,         0.15) \
-    m(double,   couldTakeSlowCaseThreshold,            0.05) \
-    m(unsigned, likelyToTakeSlowCaseMinimumCount,      100) \
-    m(unsigned, couldTakeSlowCaseMinimumCount,         10) \
+    v(unsigned, osrExitCountForReoptimization, 100) \
+    v(unsigned, osrExitCountForReoptimizationFromLoop, 5) \
     \
-    m(double,   osrExitProminenceForFrequentExitSite,  0.3) \
+    v(unsigned, reoptimizationRetryCounterMax, 0)  \
+    v(unsigned, reoptimizationRetryCounterStep, 1) \
     \
-    m(unsigned, largeFailCountThresholdBase,           20) \
-    m(unsigned, largeFailCountThresholdBaseForLoop,    1) \
+    v(unsigned, minimumOptimizationDelay, 1) \
+    v(unsigned, maximumOptimizationDelay, 5) \
+    v(double, desiredProfileLivenessRate, 0.75) \
+    v(double, desiredProfileFullnessRate, 0.35) \
     \
-    m(unsigned, reoptimizationRetryCounterMax,         0) \
-    m(unsigned, reoptimizationRetryCounterStep,        1) \
+    v(double, doubleVoteRatioForDoubleFormat, 2) \
+    v(double, structureCheckVoteRatioForHoisting, 1) \
     \
-    m(unsigned, minimumOptimizationDelay,              1) \
-    m(unsigned, maximumOptimizationDelay,              5) \
-    m(double, desiredProfileLivenessRate,              0.75) \
-    m(double, desiredProfileFullnessRate,              0.35) \
+    v(unsigned, minimumNumberOfScansBetweenRebalance, 100) \
+    v(unsigned, numberOfGCMarkers, computeNumberOfGCMarkers(7)) \
+    v(unsigned, opaqueRootMergeThreshold, 1000) \
+    v(double, minHeapUtilization, 0.8) \
+    v(double, minCopiedBlockUtilization, 0.9) \
     \
-    m(double,   doubleVoteRatioForDoubleFormat,        2) \
+    v(bool, forceWeakRandomSeed, false) \
+    v(unsigned, forcedWeakRandomSeed, 0) \
     \
-    m(unsigned, minimumNumberOfScansBetweenRebalance,  10000) \
-    m(unsigned, gcMarkStackSegmentSize,                0) \
-    m(unsigned, minimumNumberOfCellsToKeep,            10) \
-    m(unsigned, maximumNumberOfSharedSegments,         3) \
-    m(unsigned, sharedStackWakeupThreshold,            1) \
-    m(unsigned, numberOfGCMarkers,                     0) \
-    m(unsigned, opaqueRootMergeThreshold,              1000)
+    v(bool, useZombieMode, false) \
+    v(bool, objectsAreImmortal, false) \
+    v(bool, showObjectStatistics, false) \
+    \
+    v(unsigned, gcMaxHeapSize, 0) \
+    v(bool, recordGCPauseTimes, false) \
+    v(bool, logHeapStatisticsAtExit, false) 
 
-#define FOR_EACH_OPTION(m) \
-    FOR_EACH_HEURISTIC(m)
+class Options {
+public:
+    // This typedef is to allow us to eliminate the '_' in the field name in
+    // union inside Entry. This is needed to keep the style checker happy.
+    typedef int32_t int32;
 
-#define DECLARE(type, cname, default_val) extern type cname;
-FOR_EACH_OPTION(DECLARE)
-#undef DECLARE
+    // Declare the option IDs:
+    enum OptionID {
+#define FOR_EACH_OPTION(type_, name_, defaultValue_) \
+        OPT_##name_,
+        JSC_OPTIONS(FOR_EACH_OPTION)
+#undef FOR_EACH_OPTION
+        numberOfOptions
+    };
 
-void initializeOptions();
 
-} } // namespace JSC::Options
+    static void initialize();
 
-#endif // Options_h
+    // Parses a single command line option in the format "<optionName>=<value>"
+    // (no spaces allowed) and set the specified option if appropriate.
+    JS_EXPORT_PRIVATE static bool setOption(const char* arg);
+    JS_EXPORT_PRIVATE static void dumpAllOptions(FILE* stream = stdout);
+    static void dumpOption(OptionID id, FILE* stream = stdout, const char* header = "", const char* footer = "");
+
+    // Declare accessors for each option:
+#define FOR_EACH_OPTION(type_, name_, defaultValue_) \
+    ALWAYS_INLINE static type_& name_() { return s_options[OPT_##name_].u.type_##Val; }
+
+    JSC_OPTIONS(FOR_EACH_OPTION)
+#undef FOR_EACH_OPTION
+
+private:
+    enum EntryType {
+        boolType,
+        unsignedType,
+        doubleType,
+        int32Type,
+        optionRangeType,
+    };
+
+    // For storing for an option value:
+    struct Entry {
+        union {
+            bool boolVal;
+            unsigned unsignedVal;
+            double doubleVal;
+            int32 int32Val;
+            OptionRange optionRangeVal;
+        } u;
+    };
 
+    // For storing constant meta data about each option:
+    struct EntryInfo {
+        const char* name;
+        EntryType type;
+    };
+
+    Options();
+
+    // Declare the options:
+#define FOR_EACH_OPTION(type_, name_, defaultValue_) \
+    type_ m_##name_;
+    JSC_OPTIONS(FOR_EACH_OPTION)
+#undef FOR_EACH_OPTION
+
+    // Declare the singleton instance of the options store:
+    JS_EXPORTDATA static Entry s_options[numberOfOptions];
+    static const EntryInfo s_optionsInfo[numberOfOptions];
+};
+
+} // namespace JSC
+
+#endif // Options_h