Options.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright (C) 2011, 2012 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. #ifndef Options_h
  26. #define Options_h
  27. #include "JSExportMacros.h"
  28. #include <stdint.h>
  29. #include <stdio.h>
  30. namespace JSC {
  31. // How do JSC VM options work?
  32. // ===========================
  33. // The JSC_OPTIONS() macro below defines a list of all JSC options in use,
  34. // along with their types and default values. The options values are actually
  35. // realized as an array of Options::Entry elements.
  36. //
  37. // Options::initialize() will initialize the array of options values with
  38. // the defaults specified in JSC_OPTIONS() below. After that, the values can
  39. // be programmatically read and written to using an accessor method with the
  40. // same name as the option. For example, the option "useJIT" can be read and
  41. // set like so:
  42. //
  43. // bool jitIsOn = Options::useJIT(); // Get the option value.
  44. // Options::useJIT() = false; // Sets the option value.
  45. //
  46. // If you want to tweak any of these values programmatically for testing
  47. // purposes, you can do so in Options::initialize() after the default values
  48. // are set.
  49. //
  50. // Alternatively, you can override the default values by specifying
  51. // environment variables of the form: JSC_<name of JSC option>.
  52. //
  53. // Note: Options::initialize() tries to ensure some sanity on the option values
  54. // which are set by doing some range checks, and value corrections. These
  55. // checks are done after the option values are set. If you alter the option
  56. // values after the sanity checks (for your own testing), then you're liable to
  57. // ensure that the new values set are sane and reasonable for your own run.
  58. class OptionRange {
  59. private:
  60. enum RangeState { Uninitialized, InitError, Normal, Inverted };
  61. public:
  62. OptionRange& operator= (const int& rhs)
  63. { // Only needed for initialization
  64. if (!rhs) {
  65. m_state = Uninitialized;
  66. m_rangeString = 0;
  67. m_lowLimit = 0;
  68. m_highLimit = 0;
  69. }
  70. return *this;
  71. }
  72. bool init(const char*);
  73. bool isInRange(unsigned);
  74. const char* rangeString() { return (m_state > InitError) ? m_rangeString : "<null>"; }
  75. private:
  76. RangeState m_state;
  77. const char* m_rangeString;
  78. unsigned m_lowLimit;
  79. unsigned m_highLimit;
  80. };
  81. typedef OptionRange optionRange;
  82. #define JSC_OPTIONS(v) \
  83. v(bool, useJIT, true) \
  84. v(bool, useDFGJIT, true) \
  85. v(bool, useRegExpJIT, true) \
  86. \
  87. v(bool, forceDFGCodeBlockLiveness, false) \
  88. \
  89. v(bool, dumpGeneratedBytecodes, false) \
  90. \
  91. /* showDisassembly implies showDFGDisassembly. */ \
  92. v(bool, showDisassembly, false) \
  93. v(bool, showDFGDisassembly, false) \
  94. v(bool, showAllDFGNodes, false) \
  95. v(optionRange, bytecodeRangeToDFGCompile, 0) \
  96. v(bool, dumpBytecodeAtDFGTime, false) \
  97. v(bool, dumpGraphAtEachPhase, false) \
  98. v(bool, verboseCompilation, false) \
  99. v(bool, logCompilationChanges, false) \
  100. v(bool, printEachOSRExit, false) \
  101. v(bool, validateGraph, false) \
  102. v(bool, validateGraphAtEachPhase, false) \
  103. \
  104. v(bool, enableProfiler, false) \
  105. \
  106. v(unsigned, maximumOptimizationCandidateInstructionCount, 10000) \
  107. \
  108. v(unsigned, maximumFunctionForCallInlineCandidateInstructionCount, 180) \
  109. v(unsigned, maximumFunctionForClosureCallInlineCandidateInstructionCount, 100) \
  110. v(unsigned, maximumFunctionForConstructInlineCandidateInstructionCount, 100) \
  111. \
  112. /* Depth of inline stack, so 1 = no inlining, 2 = one level, etc. */ \
  113. v(unsigned, maximumInliningDepth, 5) \
  114. \
  115. v(int32, thresholdForJITAfterWarmUp, 100) \
  116. v(int32, thresholdForJITSoon, 100) \
  117. \
  118. v(int32, thresholdForOptimizeAfterWarmUp, 1000) \
  119. v(int32, thresholdForOptimizeAfterLongWarmUp, 1000) \
  120. v(int32, thresholdForOptimizeSoon, 1000) \
  121. \
  122. v(int32, executionCounterIncrementForLoop, 1) \
  123. v(int32, executionCounterIncrementForReturn, 15) \
  124. \
  125. v(int32, evalThresholdMultiplier, 10) \
  126. \
  127. v(bool, randomizeExecutionCountsBetweenCheckpoints, false) \
  128. v(int32, maximumExecutionCountsBetweenCheckpoints, 1000) \
  129. \
  130. v(unsigned, likelyToTakeSlowCaseMinimumCount, 100) \
  131. v(unsigned, couldTakeSlowCaseMinimumCount, 10) \
  132. \
  133. v(unsigned, osrExitCountForReoptimization, 100) \
  134. v(unsigned, osrExitCountForReoptimizationFromLoop, 5) \
  135. \
  136. v(unsigned, reoptimizationRetryCounterMax, 0) \
  137. v(unsigned, reoptimizationRetryCounterStep, 1) \
  138. \
  139. v(unsigned, minimumOptimizationDelay, 1) \
  140. v(unsigned, maximumOptimizationDelay, 5) \
  141. v(double, desiredProfileLivenessRate, 0.75) \
  142. v(double, desiredProfileFullnessRate, 0.35) \
  143. \
  144. v(double, doubleVoteRatioForDoubleFormat, 2) \
  145. v(double, structureCheckVoteRatioForHoisting, 1) \
  146. \
  147. v(unsigned, minimumNumberOfScansBetweenRebalance, 100) \
  148. v(unsigned, numberOfGCMarkers, computeNumberOfGCMarkers(7)) \
  149. v(unsigned, opaqueRootMergeThreshold, 1000) \
  150. v(double, minHeapUtilization, 0.8) \
  151. v(double, minCopiedBlockUtilization, 0.9) \
  152. \
  153. v(bool, forceWeakRandomSeed, false) \
  154. v(unsigned, forcedWeakRandomSeed, 0) \
  155. \
  156. v(bool, useZombieMode, false) \
  157. v(bool, objectsAreImmortal, false) \
  158. v(bool, showObjectStatistics, false) \
  159. \
  160. v(unsigned, gcMaxHeapSize, 0) \
  161. v(bool, recordGCPauseTimes, false) \
  162. v(bool, logHeapStatisticsAtExit, false)
  163. class Options {
  164. public:
  165. // This typedef is to allow us to eliminate the '_' in the field name in
  166. // union inside Entry. This is needed to keep the style checker happy.
  167. typedef int32_t int32;
  168. // Declare the option IDs:
  169. enum OptionID {
  170. #define FOR_EACH_OPTION(type_, name_, defaultValue_) \
  171. OPT_##name_,
  172. JSC_OPTIONS(FOR_EACH_OPTION)
  173. #undef FOR_EACH_OPTION
  174. numberOfOptions
  175. };
  176. static void initialize();
  177. // Parses a single command line option in the format "<optionName>=<value>"
  178. // (no spaces allowed) and set the specified option if appropriate.
  179. JS_EXPORT_PRIVATE static bool setOption(const char* arg);
  180. JS_EXPORT_PRIVATE static void dumpAllOptions(FILE* stream = stdout);
  181. static void dumpOption(OptionID id, FILE* stream = stdout, const char* header = "", const char* footer = "");
  182. // Declare accessors for each option:
  183. #define FOR_EACH_OPTION(type_, name_, defaultValue_) \
  184. ALWAYS_INLINE static type_& name_() { return s_options[OPT_##name_].u.type_##Val; }
  185. JSC_OPTIONS(FOR_EACH_OPTION)
  186. #undef FOR_EACH_OPTION
  187. private:
  188. enum EntryType {
  189. boolType,
  190. unsignedType,
  191. doubleType,
  192. int32Type,
  193. optionRangeType,
  194. };
  195. // For storing for an option value:
  196. struct Entry {
  197. union {
  198. bool boolVal;
  199. unsigned unsignedVal;
  200. double doubleVal;
  201. int32 int32Val;
  202. OptionRange optionRangeVal;
  203. } u;
  204. };
  205. // For storing constant meta data about each option:
  206. struct EntryInfo {
  207. const char* name;
  208. EntryType type;
  209. };
  210. Options();
  211. // Declare the options:
  212. #define FOR_EACH_OPTION(type_, name_, defaultValue_) \
  213. type_ m_##name_;
  214. JSC_OPTIONS(FOR_EACH_OPTION)
  215. #undef FOR_EACH_OPTION
  216. // Declare the singleton instance of the options store:
  217. JS_EXPORTDATA static Entry s_options[numberOfOptions];
  218. static const EntryInfo s_optionsInfo[numberOfOptions];
  219. };
  220. } // namespace JSC
  221. #endif // Options_h