forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathOptions.cpp
More file actions
1804 lines (1541 loc) · 66.9 KB
/
Copy pathOptions.cpp
File metadata and controls
1804 lines (1541 loc) · 66.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2011-2025 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "Options.h"
#include "ConcurrentButterflyOperations.h"
#include "CPU.h"
#include "JITOperationValidation.h"
#include "LLIntCommon.h"
#include "MacroAssembler.h"
#include "MinimumReservedZoneSize.h"
#include <algorithm>
#include <limits>
#include <mutex>
#include <stdlib.h>
#include <string.h>
#include <wtf/ASCIICType.h>
#include <wtf/BitSet.h>
#include <wtf/Compiler.h>
#include <wtf/DataLog.h>
#include <wtf/FastMalloc.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/NumberOfCores.h>
#include <wtf/StdLibExtras.h>
#include <wtf/TranslatedProcess.h>
#include <wtf/text/MakeString.h>
#include <wtf/text/StringBuilder.h>
#include <wtf/threads/Signals.h>
#if PLATFORM(COCOA)
#include <wtf/darwin/OSLogPrintStream.h>
#endif
#if PLATFORM(COCOA)
#include <crt_externs.h>
#endif
#if ENABLE(JIT_CAGE)
#include <machine/cpu_capabilities.h>
#include <wtf/cocoa/Entitlements.h>
#endif
#if OS(LINUX)
#include <unistd.h>
extern "C" char **environ;
#endif
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
namespace JSC {
bool useOSLogOptionHasChanged = false;
Options::SandboxPolicy Options::machExceptionHandlerSandboxPolicy = Options::SandboxPolicy::Unknown;
namespace OptionsHelper {
// The purpose of Metadata is to hold transient info needed during initialization of
// Options. It will be released in Options::finalize(), and will not be kept during
// VM run time. For now, the only field it contains is a copy of Options defaults
// which are only used to provide more info for Options dumps.
struct Metadata {
// This struct does not need to be TZONE_ALLOCATED because it is only used for transient memory
// during Options initialization, and will not be re-allocated thereafter. See comment above.
WTF_DEPRECATED_MAKE_FAST_ALLOCATED(Metadata);
public:
OptionsStorage defaults;
};
static LazyNeverDestroyed<std::unique_ptr<Metadata>> g_metadata;
static LazyNeverDestroyed<WTF::BitSet<NumberOfOptions>> g_optionWasOverridden;
struct ConstMetaData {
ASCIILiteral name;
ASCIILiteral description;
Options::Type type;
Options::Availability availability;
uint16_t offsetOfOption;
};
// Realize the names for each of the options:
static const ConstMetaData g_constMetaData[NumberOfOptions] = {
#define FILL_OPTION_INFO(type_, name_, defaultValue_, availability_, description_) \
{ #name_ ## _s, description_, Options::Type::type_, Options::Availability::availability_, offsetof(OptionsStorage, name_) },
FOR_EACH_JSC_OPTION(FILL_OPTION_INFO)
#undef FILL_OPTION_INFO
};
class Option {
public:
void dump(StringBuilder&) const;
bool operator==(const Option&) const;
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
ASCIILiteral NODELETE name() const { return g_constMetaData[m_id].name; }
ASCIILiteral NODELETE description() const { return g_constMetaData[m_id].description; }
Options::Type NODELETE type() const { return g_constMetaData[m_id].type; }
Options::Availability NODELETE availability() const { return g_constMetaData[m_id].availability; }
WTF_ALLOW_UNSAFE_BUFFER_USAGE_END
Option(Options::ID id, void* addressOfValue)
: m_id(id)
{
initValue(addressOfValue);
}
void initValue(void* addressOfValue);
Options::ID m_id;
union {
bool m_bool;
unsigned m_unsigned;
double m_double;
int32_t m_int32;
size_t m_size;
OptionRange m_optionRange;
const char* m_optionString;
GCLogging::Level m_gcLogLevel;
OSLogType m_osLogType;
};
};
static void initialize()
{
g_optionWasOverridden.construct();
// Make a transient copy of the default option values into g_metadata before they get
// modified. The defaults are only needed to provide more info when dumping options.
// g_metadata will be released in Options::finalize() (see releaseMetadata()).
g_metadata.construct();
auto metadata = makeUnique<Metadata>();
memcpy(&metadata->defaults, &g_jscConfig.options, sizeof(OptionsStorage));
g_metadata.get() = WTF::move(metadata);
}
static void releaseMetadata()
{
g_metadata.get() = nullptr;
}
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
static const Option defaultFor(Options::ID id)
{
auto offset = g_constMetaData[id].offsetOfOption;
void* addressOfDefault = reinterpret_cast<uint8_t*>(&g_metadata.get()->defaults) + offset;
return Option(id, addressOfDefault);
}
inline static void* NODELETE addressOfOption(Options::ID id)
{
auto offset = g_constMetaData[id].offsetOfOption;
return reinterpret_cast<uint8_t*>(&g_jscConfig.options) + offset;
}
WTF_ALLOW_UNSAFE_BUFFER_USAGE_END
static const Option optionFor(Options::ID id)
{
return Option(id, addressOfOption(id));
}
inline static bool NODELETE hasMetadata()
{
return !!g_metadata.get();
}
inline static bool NODELETE wasOverridden(Options::ID id)
{
ASSERT(id < NumberOfOptions);
return g_optionWasOverridden->get(id);
}
inline static void NODELETE setWasOverridden(Options::ID id)
{
ASSERT(id < NumberOfOptions);
g_optionWasOverridden->set(id);
}
} // namespace OptionsHelper
template<typename T>
std::optional<T> parse(const char* string);
template<>
std::optional<OptionsStorage::Bool> parse(const char* string)
{
auto span = unsafeSpan(string);
if (equalLettersIgnoringASCIICase(span, "true"_s) || equalLettersIgnoringASCIICase(span, "yes"_s) || !strcmp(string, "1"))
return true;
if (equalLettersIgnoringASCIICase(span, "false"_s) || equalLettersIgnoringASCIICase(span, "no"_s) || !strcmp(string, "0"))
return false;
return std::nullopt;
}
template<>
std::optional<OptionsStorage::Int32> parse(const char* string)
{
int32_t value;
if (sscanf(string, "%d", &value) == 1)
return value;
return std::nullopt;
}
template<>
std::optional<OptionsStorage::Unsigned> parse(const char* string)
{
unsigned value;
if (sscanf(string, "%u", &value) == 1)
return value;
return std::nullopt;
}
#if CPU(ADDRESS64) || OS(DARWIN) || OS(HAIKU)
template<>
std::optional<OptionsStorage::Size> parse(const char* string)
{
size_t value;
if (sscanf(string, "%zu", &value) == 1)
return value;
return std::nullopt;
}
#endif // CPU(ADDRESS64) || OS(DARWIN) || OS(HAIKU)
template<>
std::optional<OptionsStorage::Double> parse(const char* string)
{
double value;
if (sscanf(string, "%lf", &value) == 1)
return value;
return std::nullopt;
}
template<>
std::optional<OptionsStorage::OptionRange> parse(const char* string)
{
OptionRange range;
if (range.init(string))
return range;
return std::nullopt;
}
template<>
std::optional<OptionsStorage::OptionString> parse(const char* string)
{
const char* value = nullptr;
if (!strlen(string))
return value;
// FIXME <https://webkit.org/b/169057>: This could leak if this option is set more than once.
// Given that Options are typically used for testing, this isn't considered to be a problem.
value = WTF::fastStrDup(string);
return value;
}
template<>
std::optional<OptionsStorage::GCLogLevel> parse(const char* string)
{
auto span = unsafeSpan(string);
if (equalLettersIgnoringASCIICase(span, "none"_s) || equalLettersIgnoringASCIICase(span, "no"_s) || equalLettersIgnoringASCIICase(span, "false"_s) || !strcmp(string, "0"))
return GCLogging::None;
if (equalLettersIgnoringASCIICase(span, "basic"_s) || equalLettersIgnoringASCIICase(span, "yes"_s) || equalLettersIgnoringASCIICase(span, "true"_s) || !strcmp(string, "1"))
return GCLogging::Basic;
if (equalLettersIgnoringASCIICase(span, "verbose"_s) || !strcmp(string, "2"))
return GCLogging::Verbose;
return std::nullopt;
}
template<>
std::optional<OptionsStorage::OSLogType> parse(const char* string)
{
std::optional<OptionsStorage::OSLogType> result;
auto span = unsafeSpan(string);
if (equalLettersIgnoringASCIICase(span, "none"_s) || equalLettersIgnoringASCIICase(span, "false"_s) || !strcmp(string, "0"))
result = OSLogType::None;
else if (equalLettersIgnoringASCIICase(span, "true"_s) || !strcmp(string, "1"))
result = OSLogType::Error;
else if (equalLettersIgnoringASCIICase(span, "default"_s))
result = OSLogType::Default;
else if (equalLettersIgnoringASCIICase(span, "info"_s))
result = OSLogType::Info;
else if (equalLettersIgnoringASCIICase(span, "debug"_s))
result = OSLogType::Debug;
else if (equalLettersIgnoringASCIICase(span, "error"_s))
result = OSLogType::Error;
else if (equalLettersIgnoringASCIICase(span, "fault"_s))
result = OSLogType::Fault;
if (result && result.value() != Options::useOSLog())
useOSLogOptionHasChanged = true;
return result;
}
#if PLATFORM(COCOA)
static os_log_type_t NODELETE asDarwinOSLogType(OSLogType type)
{
switch (type) {
case OSLogType::None:
RELEASE_ASSERT_NOT_REACHED();
case OSLogType::Default:
return OS_LOG_TYPE_DEFAULT;
case OSLogType::Info:
return OS_LOG_TYPE_INFO;
case OSLogType::Debug:
return OS_LOG_TYPE_DEBUG;
case OSLogType::Error:
return OS_LOG_TYPE_ERROR;
case OSLogType::Fault:
return OS_LOG_TYPE_FAULT;
}
RELEASE_ASSERT_NOT_REACHED();
return OS_LOG_TYPE_DEFAULT;
}
static void initializeDatafileToUseOSLog()
{
static bool alreadyInitialized = false;
RELEASE_ASSERT(!alreadyInitialized);
WTF::setDataFile(OSLogPrintStream::open("com.apple.JavaScriptCore", "DataLog", asDarwinOSLogType(Options::useOSLog())));
alreadyInitialized = true;
// Make sure no one jumped here for nefarious reasons...
RELEASE_ASSERT(Options::useOSLog() != OSLogType::None);
}
#endif // OS(DARWIN)
static ASCIILiteral asString(OSLogType type)
{
switch (type) {
case OSLogType::None:
return "none"_s;
case OSLogType::Default:
return "default"_s;
case OSLogType::Info:
return "info"_s;
case OSLogType::Debug:
return "debug"_s;
case OSLogType::Error:
return "error"_s;
case OSLogType::Fault:
return "fault"_s;
}
RELEASE_ASSERT_NOT_REACHED();
return nullptr;
}
bool Options::isAvailable(Options::ID id, Options::Availability availability)
{
if (availability == Availability::Restricted)
return g_jscConfig.restrictedOptionsEnabled;
ASSERT(availability == Availability::Configurable);
UNUSED_PARAM(id);
#if !defined(NDEBUG)
if (id == maxSingleAllocationSizeID)
return true;
#endif
if (id == traceLLIntExecutionID)
return !!LLINT_TRACING;
if (id == traceLLIntSlowPathID)
return !!LLINT_TRACING;
if (id == validateVMEntryCalleeSavesID)
return !!ASSERT_ENABLED;
return false;
}
#if !PLATFORM(COCOA)
template<typename T>
bool overrideOptionWithHeuristic(T& variable, Options::ID id, const char* name, Options::Availability availability)
{
bool available = (availability == Options::Availability::Normal)
|| Options::isAvailable(id, availability);
const char* stringValue = getenv(name);
if (!stringValue)
return false;
if (available) {
std::optional<T> value = parse<T>(stringValue);
if (value) {
variable = value.value();
return true;
}
}
fprintf(stderr, "WARNING: failed to parse %s=%s\n", name, stringValue);
return false;
}
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
bool Options::overrideAliasedOptionWithHeuristic(const char* name)
{
const char* stringValue = getenv(name);
if (!stringValue)
return false;
auto aliasedOption = makeString(unsafeSpan(&name[4]), '=', unsafeSpan(stringValue));
if (Options::setOption(aliasedOption.utf8().data()))
return true;
fprintf(stderr, "WARNING: failed to parse %s=%s\n", name, stringValue);
return false;
}
WTF_ALLOW_UNSAFE_BUFFER_USAGE_END
#endif // !PLATFORM(COCOA)
unsigned Options::computeNumberOfWorkerThreads(int maxNumberOfWorkerThreads, int minimum)
{
int cpusToUse = std::min(kernTCSMAwareNumberOfProcessorCores(), maxNumberOfWorkerThreads);
// Be paranoid, it is the OS we're dealing with, after all.
ASSERT(cpusToUse >= 1);
return std::max(cpusToUse, minimum);
}
int32_t Options::computePriorityDeltaOfWorkerThreads(int32_t twoCorePriorityDelta, int32_t multiCorePriorityDelta)
{
if (kernTCSMAwareNumberOfProcessorCores() <= 2)
return twoCorePriorityDelta;
return multiCorePriorityDelta;
}
unsigned Options::computeNumberOfGCMarkers(unsigned maxNumberOfGCMarkers)
{
return computeNumberOfWorkerThreads(maxNumberOfGCMarkers);
}
bool Options::defaultTCSMValue()
{
return true;
}
const char* const OptionRange::s_nullRangeStr = "<null>";
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
bool OptionRange::init(const char* rangeString)
{
// rangeString should be in the form of [!]<low>[:<high>]
// where low and high are unsigned
bool invert = false;
if (!rangeString) {
m_state = InitError;
return false;
}
if (!strcmp(rangeString, s_nullRangeStr)) {
m_state = Uninitialized;
return true;
}
const char* p = rangeString;
if (*p == '!') {
invert = true;
p++;
}
int scanResult = sscanf(p, " %u:%u", &m_lowLimit, &m_highLimit);
if (!scanResult || scanResult == EOF) {
m_state = InitError;
return false;
}
if (scanResult == 1)
m_highLimit = m_lowLimit;
if (m_lowLimit > m_highLimit) {
m_state = InitError;
return false;
}
// FIXME <https://webkit.org/b/169057>: This could leak if this particular option is set more than once.
// Given that these options are used for testing, this isn't considered to be problem.
m_rangeString = WTF::fastStrDup(rangeString);
m_state = invert ? Inverted : Normal;
return true;
}
WTF_ALLOW_UNSAFE_BUFFER_USAGE_END
bool OptionRange::isInRange(unsigned count) const
{
if (m_state < Normal)
return true;
if ((m_lowLimit <= count) && (count <= m_highLimit))
return m_state == Normal;
return m_state != Normal;
}
void OptionRange::dump(PrintStream& out) const
{
out.print(m_rangeString);
}
static void scaleJITPolicy()
{
auto& scaleFactor = Options::jitPolicyScale();
if (scaleFactor > 1.0)
scaleFactor = 1.0;
else if (scaleFactor < 0.0)
scaleFactor = 0.0;
auto scaleOption = [&] (int32_t& optionValue, int32_t minValue) {
optionValue *= scaleFactor;
optionValue = std::max(optionValue, minValue);
};
scaleOption(Options::thresholdForJITAfterWarmUp(), 0);
scaleOption(Options::thresholdForJITSoon(), 0);
scaleOption(Options::thresholdForOptimizeAfterWarmUp(), 1);
scaleOption(Options::thresholdForOptimizeAfterLongWarmUp(), 1);
scaleOption(Options::thresholdForOptimizeSoon(), 1);
scaleOption(Options::thresholdForFTLOptimizeSoon(), 2);
scaleOption(Options::thresholdForFTLOptimizeAfterWarmUp(), 2);
scaleOption(Options::thresholdForBBQOptimizeAfterWarmUp(), 0);
scaleOption(Options::thresholdForBBQOptimizeSoon(), 0);
scaleOption(Options::thresholdForOMGOptimizeAfterWarmUp(), 1);
scaleOption(Options::thresholdForOMGOptimizeSoon(), 1);
}
#if OS(DARWIN)
static void disableAllSignalHandlerBasedOptions();
#endif
static void overrideDefaults()
{
#if OS(DARWIN)
if (Options::machExceptionHandlerSandboxPolicy == Options::SandboxPolicy::Block)
disableAllSignalHandlerBasedOptions();
#endif
#if !PLATFORM(IOS_FAMILY)
if (WTF::numberOfProcessorCores() < 4)
#endif
{
Options::maximumMutatorUtilization() = 0.6;
Options::concurrentGCMaxHeadroom() = 1.4;
Options::minimumGCPauseMS() = 1;
Options::useStochasticMutatorScheduler() = false;
if (WTF::numberOfProcessorCores() <= 1)
Options::gcIncrementScale() = 1;
else
Options::gcIncrementScale() = 0;
}
#if OS(DARWIN) && CPU(ARM64)
Options::numberOfGCMarkers() = std::min<unsigned>(4, kernTCSMAwareNumberOfProcessorCores());
Options::minNumberOfWorklistThreads() = 1;
Options::maxNumberOfWorklistThreads() = std::min<unsigned>(4, kernTCSMAwareNumberOfProcessorCores());
Options::numberOfBaselineCompilerThreads() = std::min<unsigned>(4, kernTCSMAwareNumberOfProcessorCores());
Options::numberOfDFGCompilerThreads() = std::min<unsigned>(4, kernTCSMAwareNumberOfProcessorCores());
Options::numberOfFTLCompilerThreads() = std::min<unsigned>(4, kernTCSMAwareNumberOfProcessorCores());
Options::worklistLoadFactor() = 20;
Options::worklistBaselineLoadWeight() = 2;
Options::worklistDFGLoadWeight() = 5;
// Set the FTL load weight equal to the load-factor so that a new thread is started for each FTL plan
Options::worklistFTLLoadWeight() = 20;
#endif
#if OS(LINUX) && CPU(ARM)
Options::maximumFunctionForCallInlineCandidateBytecodeCostForDFG() = 77;
Options::maximumOptimizationCandidateBytecodeCost() = 42403;
Options::maximumFunctionForClosureCallInlineCandidateBytecodeCostForDFG() = 68;
Options::maximumInliningCallerBytecodeCost() = 9912;
Options::maximumInliningDepth() = 8;
Options::maximumInliningRecursion() = 3;
#endif
#if USE(MEMORY_FOOTPRINT_API)
// On iOS and conditionally Linux, we control heap growth using process memory footprint. Therefore these values can be agressive.
Options::smallHeapRAMFraction() = 0.8;
Options::mediumHeapRAMFraction() = 0.9;
#endif
#if !ENABLE(SIGNAL_BASED_VM_TRAPS)
Options::usePollingTraps() = true;
#endif
#if !ENABLE(WEBASSEMBLY)
Options::useWasmFastMemory() = false;
Options::useWasmFaultSignalHandler() = false;
#endif
#if !HAVE(MACH_EXCEPTIONS)
Options::useMachForExceptions() = false;
#endif
#if ASAN_ENABLED
// This is a heuristic because ASAN builds are memory hogs in terms of stack frame usage.
// So, we need a much larger ReservedZoneSize to allow stack overflow handlers to execute.
Options::reservedZoneSize() = 3 * Options::reservedZoneSize();
#endif
#if PLATFORM(IOS_FAMILY)
// This is used to mitigate performance regression rdar://150522186.
if (Options::usePartialLoopUnrolling())
Options::maxPartialLoopUnrollingBodyNodeSize() = 50;
#endif
}
bool Options::setAllJITCodeValidations(const char* valueStr)
{
auto value = parse<OptionsStorage::Bool>(valueStr);
if (!value)
return false;
setAllJITCodeValidations(value.value());
return true;
}
void Options::setAllJITCodeValidations(bool value)
{
Options::validateDFGClobberize() = value;
Options::validateDFGExceptionHandling() = value;
Options::validateDFGMayExit() = value;
Options::validateDoesGC() = value;
Options::useJITAsserts() = value;
}
static inline void NODELETE disableAllWasmJITOptions()
{
#if ENABLE(WEBASSEMBLY)
// This really only makes sense if could use wasm, otherwise we should not override this.
Options::useLLInt() = true;
#endif
Options::useBBQJIT() = false;
Options::useOMGJIT() = false;
Options::useWasmSIMD() = Options::useWasmSIMD() && Options::useWasmIPIntSIMD();
Options::dumpWasmDisassembly() = false;
Options::dumpBBQDisassembly() = false;
Options::dumpOMGDisassembly() = false;
}
static inline void NODELETE disableAllWasmOptions()
{
disableAllWasmJITOptions();
Options::useWasm() = false;
Options::useWasmIPInt() = false;
Options::useWasmIPIntSIMD() = false;
Options::failToCompileWasmCode() = true;
Options::useWasmFastMemory() = false;
Options::useWasmFaultSignalHandler() = false;
Options::numberOfWasmCompilerThreads() = 0;
Options::useWasmSIMD() = false;
Options::useWasmRelaxedSIMD() = false;
Options::useWasmTailCalls() = false;
}
static inline void NODELETE disableAllJITOptions()
{
#if ENABLE(WEBASSEMBLY)
// This really only makes sense if could use wasm, otherwise we should not override this.
Options::useLLInt() = true;
#endif
Options::useJIT() = false;
disableAllWasmJITOptions();
Options::useBaselineJIT() = false;
Options::useLOLJIT() = false;
Options::useDFGJIT() = false;
Options::useFTLJIT() = false;
Options::useDOMJIT() = false;
Options::useRegExpJIT() = false;
Options::useJITCage() = false;
Options::useConcurrentJIT() = false;
Options::usePollingTraps() = true;
Options::dumpDisassembly() = false;
Options::dumpBaselineDisassembly() = false;
Options::dumpDFGDisassembly() = false;
Options::dumpFTLDisassembly() = false;
Options::dumpRegExpDisassembly() = false;
Options::needDisassemblySupport() = false;
}
#if OS(DARWIN)
static void NODELETE disableAllSignalHandlerBasedOptions()
{
Options::usePollingTraps() = true;
Options::useSharedArrayBuffer() = false;
Options::useWasmFastMemory() = false;
Options::useWasmFaultSignalHandler() = false;
}
#endif
void Options::executeDumpOptions()
{
if (!Options::dumpOptions()) [[likely]]
return;
DumpLevel level = static_cast<DumpLevel>(Options::dumpOptions());
if (level > DumpLevel::Verbose)
level = DumpLevel::Verbose;
ASCIILiteral title;
switch (level) {
case DumpLevel::None:
break;
case DumpLevel::Overridden:
title = "Modified JSC options:"_s;
break;
case DumpLevel::All:
title = "All JSC options:"_s;
break;
case DumpLevel::Verbose:
title = "All JSC options with descriptions:"_s;
break;
}
StringBuilder builder;
dumpAllOptions(builder, level, title, nullptr, " "_s, "\n"_s, DumpDefaults);
dataLog(builder.toString());
}
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
void Options::notifyOptionsChanged()
{
AllowUnfinalizedAccessScope scope;
// SPEC-vmstate §3 R2 (M_opts2): useJSThreads=1 MUST imply all three
// vmstate flags. (The prep-stub `useThreads` alias was removed by
// INTEGRATE-api 9.2-1, so its normalization line is dropped per
// INTEGRATE-vmstate cross-WS item 14.)
if (Options::useJSThreads()) {
Options::useSharedAtomStringTable() = true;
Options::useVMLite() = true;
Options::useStructureAllocationLock() = true;
}
// UNGIL §0 U0 (config gate; landed at U-T14 with the default flip):
// GIL-off ("useJSThreads && !useThreadGIL") additionally requires the
// full trio {useVMLite, useSharedAtomStringTable, useSharedGCHeap}. A
// GIL-off shape without the trio is REFUSED at option validation by
// forcing useThreadGIL=1 (ANNEX U0C: gilOffProcess is OPTION-derived
// from this conjunction at Config finalization). This normalization is
// what keeps VM::isGILOffProcess() (VM.cpp) and every landed
// `useJSThreads() && !useThreadGIL()` derivation (ArrayBuffer.cpp,
// VMInspector.cpp, SamplingProfiler.h, Watchdog.h, JSLock.cpp)
// mutually equivalent. The M_opts2 normalization above already forces
// useVMLite/useSharedAtomStringTable under useJSThreads, so in practice
// this gates on the shared GC server. Flag-off (useJSThreads=0) is
// byte-identical: the condition is unreachable. The U19 GIL-on oracle
// (useJSThreads=1, useThreadGIL=1) is unaffected: an explicit
// useThreadGIL=1 never enters this branch.
if (Options::useJSThreads() && !Options::useThreadGIL()
&& !(Options::useVMLite() && Options::useSharedAtomStringTable() && Options::useSharedGCHeap()))
Options::useThreadGIL() = true;
// UNGIL activation-checklist refusal (review finding against the U-T14
// close ruling): the trio opt-in alone is NOT a sufficient gate for
// GIL-off, because useJSThreads=1 auto-forces useVMLite and
// useSharedAtomStringTable above — so `--useJSThreads=1
// --useSharedGCHeap=1` (two flags) would construct a live gilOff process
// while blocker-grade activation items remain open with NO in-code
// fail-stop on every path (AB-1 LLInt Group-3 split-brain is silently
// UNSOUND; VM::updateStackLimits still clobbers the single VM-level soft
// stack limit under N-parallel entry — VMTraps.h checklist item (3); the
// per-lite trap words still alias the VM word — VMLite.cpp §A.2.1). Per
// the house rule (fail-stop/refusal over silent corruption), the U0
// validation REFUSES the gilOff shape outright unless the explicit
// development escape hatch useThreadGILOffUnsafe is ALSO set. This keeps
// every "enable the trio" experiment on the GIL'd oracle (the J.1
// ordering) until the AB list (INTEGRATE-ungil.md AB-1..AB-15) is
// discharged, at which point this clause is deleted and the trio opt-in
// again derives gilOff directly.
if (Options::useJSThreads() && !Options::useThreadGIL() && !Options::useThreadGILOffUnsafe()) {
dataLogLn("JSC: refusing GIL-off configuration (UNGIL activation checklist incomplete); forcing useThreadGIL=1. Set useThreadGILOffUnsafe=1 to override for development.");
Options::useThreadGIL() = true;
}
// UNGIL §A.2.2 (AB-17 follow-up): the LOL tier has not been audited for
// the §A.1.3 COMPILED-FOR-VM rule (per-lite Group-3 state, butterfly TID
// tags, etc. beyond the now-rerouted prologue soft-stack-limit check in
// LOLJIT.cpp). Per the house rule (fail-stop/refusal over silent
// corruption), force it off under the GIL-off shape rather than let an
// unaudited tier compile spawned-thread code. Flag-off and GIL-on are
// unaffected; delete this once LOL passes the §A.1.3 audit.
if (Options::useJSThreads() && !Options::useThreadGIL() && Options::useLOLJIT()) {
dataLogLn("JSC: disabling useLOLJIT under GIL-off (LOL tier not yet audited for UNGIL §A.1.3 COMPILED-FOR-VM; see AB-17).");
Options::useLOLJIT() = false;
}
// UNGIL §A.1.3 (AB-17 round-5 amendment): the wasm tiers have not been
// audited for COMPILED-FOR-VM either — the wasm<->JS glue still emits
// raw VM-block exception-word checks (VM::exceptionOffset() loads in
// WasmToJS.cpp, JSToWasm.cpp, WebAssemblyBuiltinTrampoline.cpp) that are
// inert spare storage GIL-off, so a throwing callee of a CARRIER-executed
// wasm<->JS call would be silently missed (the AB-15 SD7 refusal in
// VMEntryScope.cpp only covers SPAWNED threads calling carrier-created
// exports). Per the house rule (fail-stop/refusal over silent
// corruption), force wasm off under the GIL-off shape — LOLJIT precedent
// above. Flag-off and GIL-on are unaffected; delete this once the wasm
// glue is rerouted through the mode-keyed exception-slot pattern
// (AssemblyHelpers::loadException / materializeGILOffExceptionSlot) and
// passes the §A.1.3 audit.
if (Options::useJSThreads() && !Options::useThreadGIL() && Options::useWasm()) {
dataLogLn("JSC: disabling useWasm under GIL-off (wasm glue still reads the raw VM-block exception word; not yet audited for UNGIL §A.1.3 COMPILED-FOR-VM; see AB-17 status block in VMEntryScope.cpp).");
Options::useWasm() = false;
}
#if !(CPU(X86_64) || CPU(ARM64)) || ENABLE(C_LOOP)
// UNGIL §A.1.3 / AB-1 (A6-amend review finding, 2026-06-11): the GIL-off
// Group-3 mode split is implemented only for the 64-bit JIT
// configurations. The C++ writers store encodedHostCallReturnValue
// through group3Primitives() (per-lite copy when a gilOff same-VM lite is
// current), and the matching mode-split READ sites exist only in
// LowLevelInterpreter64.asm (llint_get_host_call_return_value AB-1
// split) and LLIntThunks.cpp getHostCallReturnValueThunk's
// #if CPU(X86_64) || CPU(ARM64) arm. LowLevelInterpreter32_64.asm
// (and the CLoop build of it) still reads the raw VM-block words
// unconditionally, so a spawned thread's host call on such a
// configuration would consume a stale/garbage return value SILENTLY —
// writer hits the lite copy, reader the VM block. Per the house rule
// (fail-stop/refusal over silent corruption), REFUSE the GIL-off shape
// outright on these configurations instead of relying on the charter
// convention that GIL-off targets 64-bit JIT builds. Flag-off and
// GIL-on are unaffected (condition requires useThreadGIL=0); 64-bit
// JIT builds compile this block away entirely (byte-identical codegen).
// Delete the relevant arm once the 32_64/CLoop read sites get the same
// mode split.
if (Options::useJSThreads() && !Options::useThreadGIL()) {
dataLogLn("JSC: refusing GIL-off configuration on a non-64-bit-JIT/CLoop build (LowLevelInterpreter32_64 reads the raw VM-block encodedHostCallReturnValue words; the UNGIL AB-1 Group-3 mode split is 64-bit-only); forcing useThreadGIL=1.");
Options::useThreadGIL() = true;
}
#endif
// ANNEX U0C write-once latch backstop (U-T14 amend, reviewer round 2):
// gilOffProcess is OPTION-derived and IMMUTABLE for the process. The
// real latch — the JSCConfig gilOffProcess byte — is U-T3's open
// obligation 9b (INTEGRATE-ungil.md; see AB-1). Until it lands, this
// shadow latch closes the divergence window between
// construction-latched consumers (VM::m_gilOff, Watchdog::m_gilOff)
// and the live-read short forms (ArrayBuffer.cpp gilOffThreadsProcess,
// VMInspector.cpp isGILOffProcessForInspection, SamplingProfiler.h,
// JSLock.cpp, VM::isGILOffProcess): Options::setOptions /
// setOption(verify=true) re-run this function and could otherwise flip
// the derivation mid-process (including this very U0 normalization
// forcing useThreadGIL 0 -> 1), silently splitting the lock-arm /
// detach-table selection across consumers. Options::finalize() runs at
// the tail of JSC::initialize() (InitializeThreading.cpp), strictly
// before any VM can be constructed, so refusing post-finalization
// CHANGES of the derivation is exactly "latched at Config
// finalization" minus the JSCConfig storage. Pre-finalization calls
// (Options::initialize, the jsc-shell CommandLine::parseArguments
// setOption loop, embedder setOptions before JSC::initialize) re-latch
// freely. Flag-off and U19 GIL-on: the derivation is constant (false),
// so the assert is unreachable; codegen shape unaffected (host C++
// only). When the JSCConfig byte lands (U-T3), it subsumes this latch
// and the statics below should be replaced by it, keeping the
// RELEASE_ASSERT.
{
bool gilOffProcessDerivation = Options::useJSThreads() && !Options::useThreadGIL()
&& Options::useVMLite() && Options::useSharedAtomStringTable() && Options::useSharedGCHeap();
static bool s_gilOffProcessLatch = false;
static bool s_gilOffProcessLatchIsSet = false;
if (!g_jscConfig.options.isFinalized || !s_gilOffProcessLatchIsSet) {
s_gilOffProcessLatch = gilOffProcessDerivation;
s_gilOffProcessLatchIsSet = true;
} else
RELEASE_ASSERT(gilOffProcessDerivation == s_gilOffProcessLatch);
}
// SCALEBENCH §27.S2 (campaign-4 task C1-congc-no-default): deliberately
// NOT forcing useConcurrentSharedGCMarking=1 under the GIL-off shape.
// The campaign-3 ceiling hypothesis ("STW collection wall fraction") was
// MEASURED and REFUTED by gcwall instrumentation (METHOD B, 3-run W=16):
// STW-GC open-to-resume is 807 ms / 14847 ms = 5.4% of wall with congc
// OFF, and 765 ms / 15119 ms = 5.1% with congc ON — i.e. congc=1 saves
// ~42 ms of stop time but adds ~30 extra Reentry-rendezvous windows
// (57 -> 87-88) and REGRESSES bench wall +1.8% (+270 ms). congcab A/B
// independently: W=8 median +0.2%, W=16 +1.2%, cpu_util 718 -> 701 (did
// not rise), 0/16 checksum divergence. So defaulting C1 on here would
// cost wall, not save it; even a perfect congc caps the gain at 5.4%,
// far short of the 12600 ms Java-parity target. The actual W=16 ceiling
// is ~52% thread-0 serial inter-phase work + the parallel-phase 5.6x
// CPU-waste tax (SCALEBENCH §27.S1/S2). The congc-specific follow-up the
// profile names — eliminate the ~30 extra Reentry rendezvous windows C1
// introduces — is recorded in §27.S2 as DEFERRED. Leave the
// OptionsList.h default at false; revisit only with a fresh gcwall A/B
// showing >=10% STW wall fraction.
// SPEC-congc §13.2 stage-flag validation (CG-2; INTEGRATE-congc.md
// manifest row 1): the §7 prefix rule — a stage flag requires every
// earlier stage's flag — and all four stages require useSharedGCHeap.
// Enforced by forcing the dependent flag OFF (house style: refuse the
// unsupported shape rather than silently run it). Evaluated C1-first so
// a violation cascades: clearing an earlier stage clears every later
// one. Flags-off (all default false): every condition is false —
// byte-identical behavior. NOTE: the flags are development-only until
// CG-3..CG-6 land the C1-C4 behavior behind them (the windowed arms CG-1
// staged activate via Heap::sharedGCWindowedStagesEnabled(), but the
// stage semantics — kill-switch retires, marker scheduling, collector
// thread, sweeping, assist — are not in-tree yet).
if (Options::useConcurrentSharedGCMarking() && !Options::useSharedGCHeap()) {
dataLogLn("JSC: disabling useConcurrentSharedGCMarking (SPEC-congc §13.2: requires useSharedGCHeap).");
Options::useConcurrentSharedGCMarking() = false;
}
if (Options::useSharedGCCollectorThread() && !Options::useConcurrentSharedGCMarking()) {
dataLogLn("JSC: disabling useSharedGCCollectorThread (SPEC-congc §13.2 prefix rule: requires useConcurrentSharedGCMarking).");
Options::useSharedGCCollectorThread() = false;
}
if (Options::useSharedGCIncrementalSweep() && !Options::useSharedGCCollectorThread()) {
dataLogLn("JSC: disabling useSharedGCIncrementalSweep (SPEC-congc §13.2 prefix rule: requires useSharedGCCollectorThread).");
Options::useSharedGCIncrementalSweep() = false;
}
if (Options::useSharedGCMutatorAssist() && !Options::useSharedGCIncrementalSweep()) {
dataLogLn("JSC: disabling useSharedGCMutatorAssist (SPEC-congc §13.2 prefix rule: requires useSharedGCIncrementalSweep).");
Options::useSharedGCMutatorAssist() = false;
}
unsigned thresholdForGlobalLexicalBindingEpoch = Options::thresholdForGlobalLexicalBindingEpoch();
if (thresholdForGlobalLexicalBindingEpoch == 0 || thresholdForGlobalLexicalBindingEpoch == 1)
Options::thresholdForGlobalLexicalBindingEpoch() = UINT_MAX;
#if !ENABLE(OFFLINE_ASM_ALT_ENTRY)
if (Options::useGdbJITInfo())
dataLogLn("useGdbJITInfo should be used with OFFLINE_ASM_ALT_ENTRY");
#endif
#if !ENABLE(JIT)
Options::useJIT() = false;
#endif
#if !ENABLE(CONCURRENT_JS)
Options::useConcurrentJIT() = false;
#endif
#if !ENABLE(YARR_JIT)
Options::useRegExpJIT() = false;
#endif
#if !ENABLE(DFG_JIT)
Options::useDFGJIT() = false;
Options::useFTLJIT() = false;
#endif
#if !ENABLE(FTL_JIT)
Options::useFTLJIT() = false;
#endif
#if CPU(RISCV64)
// On RISCV64, JIT levels are enabled at build-time to simplify building JSC, avoiding
// otherwise rare combinations of build-time configuration. FTL on RISCV64 is disabled
// at runtime for now, until it gets int a proper working state.
// https://webkit.org/b/239707
Options::useFTLJIT() = false;
#endif
#if !CPU(X86_64) && !CPU(ARM64)
Options::useConcurrentGC() = false;
Options::forceUnlinkedDFG() = false;
Options::useWasmSIMD() = false;
Options::useWasmIPInt() = false;
#if !CPU(ARM_THUMB2)
Options::useBBQJIT() = false;
#endif
#endif