]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/Options.cpp
2 * Copyright (C) 2011, 2012 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"
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
);
80 void overrideOptionWithHeuristic(T
& variable
, const char* name
)
83 const char* stringValue
= getenv(name
);
87 if (parse(stringValue
, variable
))
90 fprintf(stderr
, "WARNING: failed to parse %s=%s\n", name
, stringValue
);
94 static unsigned computeNumberOfGCMarkers(int maxNumberOfGCMarkers
)
98 #if ENABLE(PARALLEL_GC)
99 cpusToUse
= std::min(WTF::numberOfProcessorCores(), maxNumberOfGCMarkers
);
101 // Be paranoid, it is the OS we're dealing with, after all.
102 ASSERT(cpusToUse
>= 1);
106 UNUSED_PARAM(maxNumberOfGCMarkers
);
112 bool OptionRange::init(const char* rangeString
)
114 // rangeString should be in the form of [!]<low>[:<high>]
115 // where low and high are unsigned
119 if (m_state
> Uninitialized
)
127 m_rangeString
= rangeString
;
129 if (*rangeString
== '!') {
134 int scanResult
= sscanf(rangeString
, " %u:%u", &m_lowLimit
, &m_highLimit
);
136 if (!scanResult
|| scanResult
== EOF
) {
142 m_highLimit
= m_lowLimit
;
144 if (m_lowLimit
> m_highLimit
) {
149 m_state
= invert
? Inverted
: Normal
;
154 bool OptionRange::isInRange(unsigned count
)
156 if (m_state
< Normal
)
159 if ((m_lowLimit
<= count
) && (count
<= m_highLimit
))
160 return m_state
== Normal
? true : false;
162 return m_state
== Normal
? false : true;
165 Options::Entry
Options::s_options
[Options::numberOfOptions
];
167 // Realize the names for each of the options:
168 const Options::EntryInfo
Options::s_optionsInfo
[Options::numberOfOptions
] = {
169 #define FOR_EACH_OPTION(type_, name_, defaultValue_) \
170 { #name_, Options::type_##Type },
171 JSC_OPTIONS(FOR_EACH_OPTION
)
172 #undef FOR_EACH_OPTION
175 void Options::initialize()
177 // Initialize each of the options with their default values:
178 #define FOR_EACH_OPTION(type_, name_, defaultValue_) \
179 name_() = defaultValue_;
180 JSC_OPTIONS(FOR_EACH_OPTION
)
181 #undef FOR_EACH_OPTION
183 #if USE(CF) || OS(UNIX)
184 objectsAreImmortal() = !!getenv("JSImmortalZombieEnabled");
185 useZombieMode() = !!getenv("JSImmortalZombieEnabled") || !!getenv("JSZombieEnabled");
187 gcMaxHeapSize() = getenv("GCMaxHeapSize") ? HeapStatistics::parseMemoryAmount(getenv("GCMaxHeapSize")) : 0;
188 recordGCPauseTimes() = !!getenv("JSRecordGCPauseTimes");
189 logHeapStatisticsAtExit() = gcMaxHeapSize() || recordGCPauseTimes();
192 // Allow environment vars to override options if applicable.
193 // The evn var should be the name of the option prefixed with
195 #define FOR_EACH_OPTION(type_, name_, defaultValue_) \
196 overrideOptionWithHeuristic(name_(), "JSC_" #name_);
197 JSC_OPTIONS(FOR_EACH_OPTION
)
198 #undef FOR_EACH_OPTION
201 ; // Deconfuse editors that do auto indentation
208 #if !ENABLE(YARR_JIT)
209 useRegExpJIT() = false;
212 // Do range checks where needed and make corrections to the options:
213 ASSERT(thresholdForOptimizeAfterLongWarmUp() >= thresholdForOptimizeAfterWarmUp());
214 ASSERT(thresholdForOptimizeAfterWarmUp() >= thresholdForOptimizeSoon());
215 ASSERT(thresholdForOptimizeAfterWarmUp() >= 0);
217 // Compute the maximum value of the reoptimization retry counter. This is simply
218 // the largest value at which we don't overflow the execute counter, when using it
219 // to left-shift the execution counter by this amount. Currently the value ends
220 // up being 18, so this loop is not so terrible; it probably takes up ~100 cycles
221 // total on a 32-bit processor.
222 reoptimizationRetryCounterMax() = 0;
223 while ((static_cast<int64_t>(thresholdForOptimizeAfterLongWarmUp()) << (reoptimizationRetryCounterMax() + 1)) <= static_cast<int64_t>(std::numeric_limits
<int32
>::max()))
224 reoptimizationRetryCounterMax()++;
226 ASSERT((static_cast<int64_t>(thresholdForOptimizeAfterLongWarmUp()) << reoptimizationRetryCounterMax()) > 0);
227 ASSERT((static_cast<int64_t>(thresholdForOptimizeAfterLongWarmUp()) << reoptimizationRetryCounterMax()) <= static_cast<int64_t>(std::numeric_limits
<int32
>::max()));
230 // Parses a single command line option in the format "<optionName>=<value>"
231 // (no spaces allowed) and set the specified option if appropriate.
232 bool Options::setOption(const char* arg
)
234 // arg should look like this:
235 // <jscOptionName>=<appropriate value>
236 const char* equalStr
= strchr(arg
, '=');
240 const char* valueStr
= equalStr
+ 1;
242 // For each option, check if the specify arg is a match. If so, set the arg
243 // if the value makes sense. Otherwise, move on to checking the next option.
244 #define FOR_EACH_OPTION(type_, name_, defaultValue_) \
245 if (!strncmp(arg, #name_, equalStr - arg)) { \
248 bool success = parse(valueStr, value); \
256 JSC_OPTIONS(FOR_EACH_OPTION
)
257 #undef FOR_EACH_OPTION
259 return false; // No option matched.
262 void Options::dumpAllOptions(FILE* stream
)
264 fprintf(stream
, "JSC runtime options:\n");
265 for (int id
= 0; id
< numberOfOptions
; id
++)
266 dumpOption(static_cast<OptionID
>(id
), stream
, " ", "\n");
269 void Options::dumpOption(OptionID id
, FILE* stream
, const char* header
, const char* footer
)
271 if (id
>= numberOfOptions
)
272 return; // Illegal option.
274 fprintf(stream
, "%s%s: ", header
, s_optionsInfo
[id
].name
);
275 switch (s_optionsInfo
[id
].type
) {
277 fprintf(stream
, "%s", s_options
[id
].u
.boolVal
?"true":"false");
280 fprintf(stream
, "%u", s_options
[id
].u
.unsignedVal
);
283 fprintf(stream
, "%lf", s_options
[id
].u
.doubleVal
);
286 fprintf(stream
, "%d", s_options
[id
].u
.int32Val
);
288 case optionRangeType
:
289 fprintf(stream
, "%s", s_options
[id
].u
.optionRangeVal
.rangeString());
292 fprintf(stream
, "%s", footer
);