]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/Options.cpp
f0ddf98e745e606b15db48f47f03678c96534522
2 * Copyright (C) 2011, 2012, 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #include "HeapStatistics.h"
34 #include <wtf/DataLog.h>
35 #include <wtf/NumberOfCores.h>
36 #include <wtf/PageBlock.h>
37 #include <wtf/StdLibExtras.h>
38 #include <wtf/StringExtras.h>
40 #if OS(DARWIN) && ENABLE(PARALLEL_GC)
41 #include <sys/sysctl.h>
46 static bool parse(const char* string
, bool& value
)
48 if (!strcasecmp(string
, "true") || !strcasecmp(string
, "yes") || !strcmp(string
, "1")) {
52 if (!strcasecmp(string
, "false") || !strcasecmp(string
, "no") || !strcmp(string
, "0")) {
59 static bool parse(const char* string
, int32_t& value
)
61 return sscanf(string
, "%d", &value
) == 1;
64 static bool parse(const char* string
, unsigned& value
)
66 return sscanf(string
, "%u", &value
) == 1;
69 static bool parse(const char* string
, double& value
)
71 return sscanf(string
, "%lf", &value
) == 1;
74 static bool parse(const char* string
, OptionRange
& value
)
76 return value
.init(string
);
79 static bool parse(const char* string
, const char*& value
)
85 static bool parse(const char* string
, GCLogging::Level
& value
)
87 if (!strcasecmp(string
, "none") || !strcasecmp(string
, "no") || !strcasecmp(string
, "false") || !strcmp(string
, "0")) {
88 value
= GCLogging::None
;
92 if (!strcasecmp(string
, "basic") || !strcasecmp(string
, "yes") || !strcasecmp(string
, "true") || !strcmp(string
, "1")) {
93 value
= GCLogging::Basic
;
97 if (!strcasecmp(string
, "verbose") || !strcmp(string
, "2")) {
98 value
= GCLogging::Verbose
;
106 bool overrideOptionWithHeuristic(T
& variable
, const char* name
)
109 const char* stringValue
= getenv(name
);
113 if (parse(stringValue
, variable
))
116 fprintf(stderr
, "WARNING: failed to parse %s=%s\n", name
, stringValue
);
121 static unsigned computeNumberOfWorkerThreads(int maxNumberOfWorkerThreads
, int minimum
= 1)
123 int cpusToUse
= std::min(WTF::numberOfProcessorCores(), maxNumberOfWorkerThreads
);
125 // Be paranoid, it is the OS we're dealing with, after all.
126 ASSERT(cpusToUse
>= 1);
127 return std::max(cpusToUse
, minimum
);
130 static int32_t computePriorityDeltaOfWorkerThreads(int32_t twoCorePriorityDelta
, int32_t multiCorePriorityDelta
)
132 if (WTF::numberOfProcessorCores() <= 2)
133 return twoCorePriorityDelta
;
135 return multiCorePriorityDelta
;
138 static unsigned computeNumberOfGCMarkers(unsigned maxNumberOfGCMarkers
)
140 #if ENABLE(PARALLEL_GC)
141 return computeNumberOfWorkerThreads(maxNumberOfGCMarkers
);
143 UNUSED_PARAM(maxNumberOfGCMarkers
);
148 bool OptionRange::init(const char* rangeString
)
150 // rangeString should be in the form of [!]<low>[:<high>]
151 // where low and high are unsigned
155 if (m_state
> Uninitialized
)
163 m_rangeString
= rangeString
;
165 if (*rangeString
== '!') {
170 int scanResult
= sscanf(rangeString
, " %u:%u", &m_lowLimit
, &m_highLimit
);
172 if (!scanResult
|| scanResult
== EOF
) {
178 m_highLimit
= m_lowLimit
;
180 if (m_lowLimit
> m_highLimit
) {
185 m_state
= invert
? Inverted
: Normal
;
190 bool OptionRange::isInRange(unsigned count
)
192 if (m_state
< Normal
)
195 if ((m_lowLimit
<= count
) && (count
<= m_highLimit
))
196 return m_state
== Normal
? true : false;
198 return m_state
== Normal
? false : true;
201 Options::Entry
Options::s_options
[Options::numberOfOptions
];
203 // Realize the names for each of the options:
204 const Options::EntryInfo
Options::s_optionsInfo
[Options::numberOfOptions
] = {
205 #define FOR_EACH_OPTION(type_, name_, defaultValue_) \
206 { #name_, Options::type_##Type },
207 JSC_OPTIONS(FOR_EACH_OPTION
)
208 #undef FOR_EACH_OPTION
211 static void recomputeDependentOptions()
214 Options::useLLInt() = true;
215 Options::useJIT() = false;
216 Options::useDFGJIT() = false;
217 Options::useFTLJIT() = false;
219 #if !ENABLE(YARR_JIT)
220 Options::useRegExpJIT() = false;
222 #if !ENABLE(CONCURRENT_JIT)
223 Options::enableConcurrentJIT() = false;
226 Options::useDFGJIT() = false;
227 Options::useFTLJIT() = false;
230 Options::useFTLJIT() = false;
233 if (Options::showDisassembly()
234 || Options::showDFGDisassembly()
235 || Options::showFTLDisassembly()
236 || Options::dumpBytecodeAtDFGTime()
237 || Options::dumpGraphAtEachPhase()
238 || Options::verboseCompilation()
239 || Options::verboseFTLCompilation()
240 || Options::logCompilationChanges()
241 || Options::validateGraph()
242 || Options::validateGraphAtEachPhase()
243 || Options::verboseOSR()
244 || Options::verboseCompilationQueue()
245 || Options::reportCompileTimes()
246 || Options::reportFTLCompileTimes()
247 || Options::verboseCFA()
248 || Options::verboseFTLFailure())
249 Options::alwaysComputeHash() = true;
251 // Compute the maximum value of the reoptimization retry counter. This is simply
252 // the largest value at which we don't overflow the execute counter, when using it
253 // to left-shift the execution counter by this amount. Currently the value ends
254 // up being 18, so this loop is not so terrible; it probably takes up ~100 cycles
255 // total on a 32-bit processor.
256 Options::reoptimizationRetryCounterMax() = 0;
257 while ((static_cast<int64_t>(Options::thresholdForOptimizeAfterLongWarmUp()) << (Options::reoptimizationRetryCounterMax() + 1)) <= static_cast<int64_t>(std::numeric_limits
<int32_t>::max()))
258 Options::reoptimizationRetryCounterMax()++;
260 ASSERT((static_cast<int64_t>(Options::thresholdForOptimizeAfterLongWarmUp()) << Options::reoptimizationRetryCounterMax()) > 0);
261 ASSERT((static_cast<int64_t>(Options::thresholdForOptimizeAfterLongWarmUp()) << Options::reoptimizationRetryCounterMax()) <= static_cast<int64_t>(std::numeric_limits
<int32_t>::max()));
264 void Options::initialize()
266 // Initialize each of the options with their default values:
267 #define FOR_EACH_OPTION(type_, name_, defaultValue_) \
268 name_() = defaultValue_;
269 JSC_OPTIONS(FOR_EACH_OPTION
)
270 #undef FOR_EACH_OPTION
272 // Allow environment vars to override options if applicable.
273 // The evn var should be the name of the option prefixed with
275 #define FOR_EACH_OPTION(type_, name_, defaultValue_) \
276 if (overrideOptionWithHeuristic(name_(), "JSC_" #name_)) \
277 s_options[OPT_##name_].didOverride = true;
278 JSC_OPTIONS(FOR_EACH_OPTION
)
279 #undef FOR_EACH_OPTION
282 ; // Deconfuse editors that do auto indentation
285 recomputeDependentOptions();
287 // Do range checks where needed and make corrections to the options:
288 ASSERT(Options::thresholdForOptimizeAfterLongWarmUp() >= Options::thresholdForOptimizeAfterWarmUp());
289 ASSERT(Options::thresholdForOptimizeAfterWarmUp() >= Options::thresholdForOptimizeSoon());
290 ASSERT(Options::thresholdForOptimizeAfterWarmUp() >= 0);
293 // Parses a single command line option in the format "<optionName>=<value>"
294 // (no spaces allowed) and set the specified option if appropriate.
295 bool Options::setOption(const char* arg
)
297 // arg should look like this:
298 // <jscOptionName>=<appropriate value>
299 const char* equalStr
= strchr(arg
, '=');
303 const char* valueStr
= equalStr
+ 1;
305 // For each option, check if the specify arg is a match. If so, set the arg
306 // if the value makes sense. Otherwise, move on to checking the next option.
307 #define FOR_EACH_OPTION(type_, name_, defaultValue_) \
308 if (!strncmp(arg, #name_, equalStr - arg)) { \
310 value = (defaultValue_); \
311 bool success = parse(valueStr, value); \
314 s_options[OPT_##name_].didOverride = true; \
315 recomputeDependentOptions(); \
321 JSC_OPTIONS(FOR_EACH_OPTION
)
322 #undef FOR_EACH_OPTION
324 return false; // No option matched.
327 void Options::dumpAllOptions(FILE* stream
)
329 fprintf(stream
, "JSC runtime options:\n");
330 for (int id
= 0; id
< numberOfOptions
; id
++)
331 dumpOption(static_cast<OptionID
>(id
), stream
, " ", "\n");
334 void Options::dumpOption(OptionID id
, FILE* stream
, const char* header
, const char* footer
)
336 if (id
>= numberOfOptions
)
337 return; // Illegal option.
339 fprintf(stream
, "%s%s: ", header
, s_optionsInfo
[id
].name
);
340 switch (s_optionsInfo
[id
].type
) {
342 fprintf(stream
, "%s", s_options
[id
].u
.boolVal
?"true":"false");
345 fprintf(stream
, "%u", s_options
[id
].u
.unsignedVal
);
348 fprintf(stream
, "%lf", s_options
[id
].u
.doubleVal
);
351 fprintf(stream
, "%d", s_options
[id
].u
.int32Val
);
353 case optionRangeType
:
354 fprintf(stream
, "%s", s_options
[id
].u
.optionRangeVal
.rangeString());
356 case optionStringType
: {
357 const char* option
= s_options
[id
].u
.optionStringVal
;
360 fprintf(stream
, "%s", option
);
363 case gcLogLevelType
: {
364 fprintf(stream
, "%s", GCLogging::levelAsString(s_options
[id
].u
.gcLogLevelVal
));
368 fprintf(stream
, "%s", footer
);