forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathJSObject.cpp
More file actions
7602 lines (6881 loc) · 385 KB
/
Copy pathJSObject.cpp
File metadata and controls
7602 lines (6881 loc) · 385 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) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2003-2024 Apple Inc. All rights reserved.
* Copyright (C) 2007 Eric Seidel (eric@webkit.org)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "config.h"
#include "JSObject.h"
#include "AllocationFailureMode.h"
#include "ArrayProfile.h"
#include "CustomGetterSetter.h"
#include "Exception.h"
#include "GCDeferralContextInlines.h"
#include "GetterSetter.h"
#include "HeapAnalyzer.h"
#include "IndexingHeaderInlines.h"
#include "JSCInlines.h"
#include "IndexingTypeInlines.h"
#include "JSCellButterfly.h"
#include "JSCustomGetterFunction.h"
#include "JSCustomSetterFunction.h"
#include "JSFunction.h"
#include "Lookup.h"
#include "PropertyDescriptor.h"
#include "PropertyNameArray.h"
#include "ProxyObject.h"
#include "ResourceExhaustion.h"
#include "TopExceptionScope.h"
#include "TypeError.h"
#include "VMInlines.h"
#include "VMTrapsInlines.h"
#include <wtf/Assertions.h>
#include <wtf/text/MakeString.h>
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
namespace JSC {
// We keep track of the size of the last array after it was grown. We use this
// as a simple heuristic for as the value to grow the next array from size 0.
// This value is capped by the constant FIRST_VECTOR_GROW defined in
// ArrayConventions.h.
// UNGIL (AB-10 closure follow-on): GIL-off, N mutators grow ArrayStorage
// vectors concurrently (e.g. post-haveABadTime slow puts), racing this
// purely-advisory sizing hint. Relaxed atomic per the TSAN triage convention
// for advisory heuristics (TSAN-TRIAGE.md families 12-14/19): a stale value
// only perturbs the growth heuristic, never correctness.
static std::atomic<unsigned> lastArraySize { 0 };
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSObject);
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSObjectWithButterfly);
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSFinalObject);
const ASCIILiteral NonExtensibleObjectPropertyDefineError { "Attempting to define property on object that is not extensible."_s };
const ASCIILiteral ReadonlyPropertyWriteError { "Attempted to assign to readonly property."_s };
const ASCIILiteral ReadonlyPropertyChangeError { "Attempting to change value of a readonly property."_s };
const ASCIILiteral UnableToDeletePropertyError { "Unable to delete property."_s };
const ASCIILiteral UnconfigurablePropertyChangeAccessMechanismError { "Attempting to change access mechanism for an unconfigurable property."_s };
const ASCIILiteral UnconfigurablePropertyChangeConfigurabilityError { "Attempting to change configurable attribute of unconfigurable property."_s };
const ASCIILiteral UnconfigurablePropertyChangeEnumerabilityError { "Attempting to change enumerable attribute of unconfigurable property."_s };
const ASCIILiteral UnconfigurablePropertyChangeWritabilityError { "Attempting to change writable attribute of unconfigurable property."_s };
const ASCIILiteral PrototypeValueCanOnlyBeAnObjectOrNullTypeError { "Prototype value can only be an object or null"_s };
const ClassInfo JSObject::s_info = { "Object"_s, nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(JSObject) };
const ClassInfo JSObjectWithButterfly::s_info = { "Object"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSObjectWithButterfly) };
const ClassInfo JSFinalObject::s_info = { "Object"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFinalObject) };
template<typename Visitor>
ALWAYS_INLINE void JSObjectWithButterfly::markAuxiliaryAndVisitOutOfLineProperties(Visitor& visitor, Butterfly* butterfly, Structure* structure, PropertyOffset maxOffset)
{
// We call this when we found everything without races.
ASSERT(structure);
if (!butterfly)
return;
if (isCopyOnWrite(structure->indexingMode())) {
visitor.append(std::bit_cast<WriteBarrier<JSCell>>(JSCellButterfly::fromButterfly(butterfly)));
return;
}
bool hasIndexingHeader = structure->hasIndexingHeader(this);
size_t preCapacity;
if (hasIndexingHeader)
preCapacity = butterfly->indexingHeader()->preCapacity(structure);
else
preCapacity = 0;
HeapCell* base = std::bit_cast<HeapCell*>(
butterfly->base(preCapacity, Structure::outOfLineCapacity(maxOffset)));
ASSERT(Heap::heap(base) == visitor.heap());
visitor.markAuxiliary(base);
unsigned outOfLineSize = Structure::outOfLineSize(maxOffset);
visitor.appendValuesHidden(butterfly->propertyStorage() - outOfLineSize, outOfLineSize);
}
template<typename Visitor>
ALWAYS_INLINE Structure* JSObjectWithButterfly::visitButterfly(Visitor& visitor)
{
static const char* const raceReason = "JSObjectWithButterfly::visitButterfly";
Structure* result = visitButterflyImpl(visitor);
if (!result)
visitor.didRace(this, raceReason);
return result;
}
template<typename Visitor>
ALWAYS_INLINE Structure* JSObjectWithButterfly::visitButterflyImpl(Visitor& visitor)
{
Butterfly* butterfly;
Structure* structure;
PropertyOffset maxOffset;
#if USE(JSVALUE64)
// Latched option (I22): load once per visit instead of three cross-DSO
// global loads per visited object per mark pass.
const bool jsThreads = Options::useJSThreads();
#endif
auto visitElements = [&] (IndexingType indexingMode) {
switch (indexingMode) {
// We don't need to visit the elements for CopyOnWrite butterflies since they we marked the JSCellButterfly acting as our butterfly.
case ALL_WRITABLE_CONTIGUOUS_INDEXING_TYPES: {
unsigned visitBound = butterfly->publicLength();
#if USE(JSVALUE64)
// SPEC-objectmodel review round 3 (I21/I25 - GC bound vs lock-free
// truncation): on a SHARED-WRITTEN flat word (SW=1), a §3 dense
// store may legally land in [newLength, vectorLength) while a
// truncating plain setPublicLength (pop/setLength/shrink) is
// mid-flight; bounding the value visit by publicLength would then
// leave that store's cell unmarked FOREVER (the store's barrier
// re-greys the object, but the revisit would use the same
// too-small bound) - a sweep of a reachable value, resurfacing as
// a dangling read once a later grow re-exposes the slot. Visit the
// full storage bound instead: flag-on, every published flat
// butterfly is hole-initialized through vectorLength (creation
// hole-fills, T1/T2/conversion copies clear their slack, and
// ObjectInitializationScope windows are thread-private and can
// never be SW=1), so the extra slots hold holes or stale-but-valid
// JSValues. SW monotonicity makes a re-loaded word's bit safe to
// key on (over-visiting is conservative).
if (jsThreads && butterflySharedWrite(taggedButterflyWord())) [[unlikely]]
visitBound = butterfly->vectorLength();
#endif
visitor.appendValuesHidden(butterfly->contiguous().data(), visitBound);
break;
}
case ALL_ARRAY_STORAGE_INDEXING_TYPES:
visitor.appendValuesHidden(butterfly->arrayStorage()->m_vector, butterfly->arrayStorage()->vectorLength());
if (butterfly->arrayStorage()->m_sparseMap)
visitor.append(butterfly->arrayStorage()->m_sparseMap);
break;
default:
break;
}
};
if (visitor.mutatorIsStopped()) {
#if USE(JSVALUE64)
// SPEC-objectmodel Task 2 audit: mask the §2 tag off the butterfly word.
// Segmented words take the §4.5 visit (Task 6b). With the mutator
// stopped nothing can race: the structureID is settled (transitions
// are poll-free between nuke and restore, O2), so the visit must
// succeed - a nullptr here would be a logic error, not a race.
if (jsThreads) [[unlikely]] {
uint64_t word = taggedButterflyWord();
if (isSegmentedButterfly(word)) [[unlikely]] {
// Review round 2: pass the settled {id, structure, maxOffset,
// indexingMode} snapshot (the visit no longer self-loads it;
// see the concurrent call site below). Settled because the
// mutator is stopped and transitions are poll-free between
// nuke and restore (O2).
StructureID settledID = structureID();
RELEASE_ASSERT(!settledID.isNuked());
Structure* settledStructure = settledID.decode();
Structure* result = visitSegmentedButterfly(visitor, this, butterflySpine(word), settledID, settledStructure, settledStructure->maxOffset(), settledStructure->indexingMode());
RELEASE_ASSERT(result);
return result;
}
butterfly = untaggedButterfly(word);
} else
#endif
butterfly = this->butterfly();
structure = this->structure();
maxOffset = structure->maxOffset();
markAuxiliaryAndVisitOutOfLineProperties(visitor, butterfly, structure, maxOffset);
visitElements(structure->indexingMode());
return structure;
}
// We want to ensure that we only scan the butterfly if we have an exactly matched structure and an
// exactly matched size. The mutator is required to perform the following shenanigans when
// reallocating the butterfly with a concurrent collector, with all fencing necessary to ensure
// that this executes as if under sequential consistency:
//
// object->structure = nuke(object->structure)
// object->butterfly = newButterfly
// structure->m_offset = newMaxOffset
// object->structure = newStructure
//
// It's OK to skip this when reallocating the butterfly in a way that does not affect the m_offset.
// We have other protocols in place for that.
//
// Note that the m_offset can change without the structure changing, but in that case the mutator
// will still store null to the structure.
//
// The collector will ensure that it always sees a matched butterfly/structure by reading the
// structure before and after reading the butterfly. For simplicity, let's first consider the case
// where the only way to change the outOfLineCapacity is to change the structure. This works
// because the mutator performs the following steps sequentially:
//
// NukeStructure ChangeButterfly PutNewStructure
//
// Meanwhile the collector performs the following steps sequentially:
//
// ReadStructureEarly ReadButterfly ReadStructureLate
//
// The collector is allowed to do any of these three things:
//
// BEFORE: Scan the object with the structure and butterfly *before* the mutator's transition.
// AFTER: Scan the object with the structure and butterfly *after* the mutator's transition.
// IGNORE: Ignore the butterfly and call didRace to schedule us to be revisted again in the future.
//
// In other words, the collector will never see any torn structure/butterfly mix. It will
// always see the structure/butterfly before the transition or after but not in between.
//
// We can prove that this is correct by exhaustively considering all interleavings:
//
// NukeStructure ChangeButterfly PutNewStructure ReadStructureEarly ReadButterfly ReadStructureLate: AFTER, trivially.
// NukeStructure ChangeButterfly ReadStructureEarly PutNewStructure ReadButterfly ReadStructureLate: IGNORE, because nuked structure read early
// NukeStructure ChangeButterfly ReadStructureEarly ReadButterfly PutNewStructure ReadStructureLate: IGNORE, because nuked structure read early
// NukeStructure ChangeButterfly ReadStructureEarly ReadButterfly ReadStructureLate PutNewStructure: IGNORE, because nuked structure read early
// NukeStructure ReadStructureEarly ChangeButterfly PutNewStructure ReadButterfly ReadStructureLate: IGNORE, because nuked structure read early
// NukeStructure ReadStructureEarly ChangeButterfly ReadButterfly PutNewStructure ReadStructureLate: IGNORE, because nuked structure read early
// NukeStructure ReadStructureEarly ChangeButterfly ReadButterfly ReadStructureLate PutNewStructure: IGNORE, because nuked structure read early
// NukeStructure ReadStructureEarly ReadButterfly ChangeButterfly PutNewStructure ReadStructureLate: IGNORE, because nuked structure read early
// NukeStructure ReadStructureEarly ReadButterfly ChangeButterfly ReadStructureLate PutNewStructure: IGNORE, because nuked structure read early
// NukeStructure ReadStructureEarly ReadButterfly ReadStructureLate ChangeButterfly PutNewStructure: IGNORE, because nuked structure read early
// ReadStructureEarly NukeStructure ChangeButterfly PutNewStructure ReadButterfly ReadStructureLate: IGNORE, because early and late structures don't match
// ReadStructureEarly NukeStructure ChangeButterfly ReadButterfly PutNewStructure ReadStructureLate: IGNORE, because early and late structures don't match
// ReadStructureEarly NukeStructure ChangeButterfly ReadButterfly ReadStructureLate PutNewStructure: IGNORE, because nuked structure read late
// ReadStructureEarly NukeStructure ReadButterfly ChangeButterfly PutNewStructure ReadStructureLate: IGNORE, because early and late structures don't match
// ReadStructureEarly NukeStructure ReadButterfly ChangeButterfly ReadStructureLate PutNewStructure: IGNORE, because nuked structure read late
// ReadStructureEarly NukeStructure ReadButterfly ReadStructureLate ChangeButterfly PutNewStructure: IGNORE, because nuked structure read late
// ReadStructureEarly ReadButterfly NukeStructure ChangeButterfly PutNewStructure ReadStructureLate: IGNORE, because early and late structures don't match
// ReadStructureEarly ReadButterfly NukeStructure ChangeButterfly ReadStructureLate PutNewStructure: IGNORE, because nuked structure read late
// ReadStructureEarly ReadButterfly NukeStructure ReadStructureLate ChangeButterfly PutNewStructure: IGNORE, because nuked structure read late
// ReadStructureEarly ReadButterfly ReadStructureLate NukeStructure ChangeButterfly PutNewStructure: BEFORE, trivially.
//
// But we additionally have to worry about the size changing. We make this work by requiring that
// the collector reads the size early and late as well. Lets consider the interleaving of the
// mutator changing the size without changing the structure:
//
// NukeStructure ChangeButterfly ChangeMaxOffset RestoreStructure
//
// Meanwhile the collector does:
//
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate
//
// The collector can detect races by not only comparing the early structure to the late structure
// (which will be the same before and after the algorithm runs) but also by comparing the early and
// late maxOffsets. Note: the IGNORE proofs do not cite all of the reasons why the collector will
// ignore the case, since we only need to identify one to say that we're in the ignore case.
//
// NukeStructure ChangeButterfly ChangeMaxOffset RestoreStructure ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate: AFTER, trivially
// NukeStructure ChangeButterfly ChangeMaxOffset ReadStructureEarly RestoreStructure ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ChangeMaxOffset ReadStructureEarly ReadMaxOffsetEarly RestoreStructure ReadButterfly ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ChangeMaxOffset ReadStructureEarly ReadMaxOffsetEarly ReadButterfly RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ChangeMaxOffset ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ChangeMaxOffset ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ChangeMaxOffset RestoreStructure ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ChangeMaxOffset ReadMaxOffsetEarly RestoreStructure ReadButterfly ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ChangeMaxOffset ReadMaxOffsetEarly ReadButterfly RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ChangeMaxOffset ReadMaxOffsetEarly ReadButterfly ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ChangeMaxOffset ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ReadMaxOffsetEarly ChangeMaxOffset RestoreStructure ReadButterfly ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ReadMaxOffsetEarly ChangeMaxOffset ReadButterfly RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ReadMaxOffsetEarly ChangeMaxOffset ReadButterfly ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ReadMaxOffsetEarly ChangeMaxOffset ReadButterfly ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ChangeMaxOffset RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ChangeMaxOffset ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ChangeMaxOffset ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ChangeButterfly ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ChangeMaxOffset RestoreStructure ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ChangeMaxOffset ReadMaxOffsetEarly RestoreStructure ReadButterfly ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ChangeMaxOffset ReadMaxOffsetEarly ReadButterfly RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ChangeMaxOffset ReadMaxOffsetEarly ReadButterfly ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ChangeMaxOffset ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ReadMaxOffsetEarly ChangeMaxOffset RestoreStructure ReadButterfly ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ReadMaxOffsetEarly ChangeMaxOffset ReadButterfly RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ReadMaxOffsetEarly ChangeMaxOffset ReadButterfly ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ReadMaxOffsetEarly ChangeMaxOffset ReadButterfly ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ReadMaxOffsetEarly ReadButterfly ChangeMaxOffset RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ReadMaxOffsetEarly ReadButterfly ChangeMaxOffset ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ReadMaxOffsetEarly ReadButterfly ChangeMaxOffset ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ChangeButterfly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ChangeButterfly ChangeMaxOffset RestoreStructure ReadButterfly ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ChangeButterfly ChangeMaxOffset ReadButterfly RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ChangeButterfly ChangeMaxOffset ReadButterfly ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ChangeButterfly ChangeMaxOffset ReadButterfly ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ChangeButterfly ReadButterfly ChangeMaxOffset RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ChangeButterfly ReadButterfly ChangeMaxOffset ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ChangeButterfly ReadButterfly ChangeMaxOffset ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ChangeButterfly ReadButterfly ReadStructureLate ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ChangeButterfly ReadButterfly ReadStructureLate ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ChangeButterfly ReadButterfly ReadStructureLate ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ChangeButterfly ChangeMaxOffset RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ChangeButterfly ChangeMaxOffset ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ChangeButterfly ChangeMaxOffset ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ChangeButterfly ReadStructureLate ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ChangeButterfly ReadStructureLate ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ChangeButterfly ReadStructureLate ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ChangeButterfly ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ChangeButterfly ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ChangeButterfly ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure early
// NukeStructure ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate ChangeButterfly ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure early
// ReadStructureEarly NukeStructure ChangeButterfly ChangeMaxOffset RestoreStructure ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate: AFTER, the ReadStructureEarly sees the same structure as after and everything else runs after.
// ReadStructureEarly NukeStructure ChangeButterfly ChangeMaxOffset ReadMaxOffsetEarly RestoreStructure ReadButterfly ReadStructureLate ReadMaxOffsetLate: AFTER, as above and the ReadMaxOffsetEarly sees the maxOffset after.
// ReadStructureEarly NukeStructure ChangeButterfly ChangeMaxOffset ReadMaxOffsetEarly ReadButterfly RestoreStructure ReadStructureLate ReadMaxOffsetLate: AFTER, as above and the ReadButterfly sees the right butterfly after.
// ReadStructureEarly NukeStructure ChangeButterfly ChangeMaxOffset ReadMaxOffsetEarly ReadButterfly ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure late
// ReadStructureEarly NukeStructure ChangeButterfly ChangeMaxOffset ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly NukeStructure ChangeButterfly ReadMaxOffsetEarly ChangeMaxOffset RestoreStructure ReadButterfly ReadStructureLate ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ChangeButterfly ReadMaxOffsetEarly ChangeMaxOffset ReadButterfly RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ChangeButterfly ReadMaxOffsetEarly ChangeMaxOffset ReadButterfly ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ChangeButterfly ReadMaxOffsetEarly ChangeMaxOffset ReadButterfly ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ChangeButterfly ReadMaxOffsetEarly ReadButterfly ChangeMaxOffset RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ChangeButterfly ReadMaxOffsetEarly ReadButterfly ChangeMaxOffset ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ChangeButterfly ReadMaxOffsetEarly ReadButterfly ChangeMaxOffset ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ChangeButterfly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ChangeButterfly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ChangeButterfly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ChangeButterfly ChangeMaxOffset RestoreStructure ReadButterfly ReadStructureLate ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ChangeButterfly ChangeMaxOffset ReadButterfly RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ChangeButterfly ChangeMaxOffset ReadButterfly ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ChangeButterfly ChangeMaxOffset ReadButterfly ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ChangeButterfly ReadButterfly ChangeMaxOffset RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ChangeButterfly ReadButterfly ChangeMaxOffset ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ChangeButterfly ReadButterfly ChangeMaxOffset ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ChangeButterfly ReadButterfly ReadStructureLate ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ChangeButterfly ReadButterfly ReadStructureLate ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ChangeButterfly ReadButterfly ReadStructureLate ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ReadButterfly ChangeButterfly ChangeMaxOffset RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ReadButterfly ChangeButterfly ChangeMaxOffset ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ReadButterfly ChangeButterfly ChangeMaxOffset ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ReadButterfly ChangeButterfly ReadStructureLate ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ReadButterfly ChangeButterfly ReadStructureLate ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ReadButterfly ChangeButterfly ReadStructureLate ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ReadButterfly ReadStructureLate ChangeButterfly ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ReadButterfly ReadStructureLate ChangeButterfly ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ReadButterfly ReadStructureLate ChangeButterfly ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly NukeStructure ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate ChangeButterfly ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ChangeButterfly ChangeMaxOffset RestoreStructure ReadButterfly ReadStructureLate ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ChangeButterfly ChangeMaxOffset ReadButterfly RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ChangeButterfly ChangeMaxOffset ReadButterfly ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ChangeButterfly ChangeMaxOffset ReadButterfly ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ChangeButterfly ReadButterfly ChangeMaxOffset RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ChangeButterfly ReadButterfly ChangeMaxOffset ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ChangeButterfly ReadButterfly ChangeMaxOffset ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ChangeButterfly ReadButterfly ReadStructureLate ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ChangeButterfly ReadButterfly ReadStructureLate ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ChangeButterfly ReadButterfly ReadStructureLate ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ReadButterfly ChangeButterfly ChangeMaxOffset RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ReadButterfly ChangeButterfly ChangeMaxOffset ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ReadButterfly ChangeButterfly ChangeMaxOffset ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ReadButterfly ChangeButterfly ReadStructureLate ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ReadButterfly ChangeButterfly ReadStructureLate ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ReadButterfly ChangeButterfly ReadStructureLate ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ReadButterfly ReadStructureLate ChangeButterfly ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ReadButterfly ReadStructureLate ChangeButterfly ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ReadButterfly ReadStructureLate ChangeButterfly ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly NukeStructure ReadButterfly ReadStructureLate ReadMaxOffsetLate ChangeButterfly ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly NukeStructure ChangeButterfly ChangeMaxOffset RestoreStructure ReadStructureLate ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly NukeStructure ChangeButterfly ChangeMaxOffset ReadStructureLate RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly NukeStructure ChangeButterfly ChangeMaxOffset ReadStructureLate ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly NukeStructure ChangeButterfly ReadStructureLate ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly NukeStructure ChangeButterfly ReadStructureLate ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly NukeStructure ChangeButterfly ReadStructureLate ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly NukeStructure ReadStructureLate ChangeButterfly ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly NukeStructure ReadStructureLate ChangeButterfly ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly NukeStructure ReadStructureLate ChangeButterfly ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly NukeStructure ReadStructureLate ReadMaxOffsetLate ChangeButterfly ChangeMaxOffset RestoreStructure: IGNORE, read nuked structure late
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate NukeStructure ChangeButterfly ChangeMaxOffset RestoreStructure ReadMaxOffsetLate: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate NukeStructure ChangeButterfly ChangeMaxOffset ReadMaxOffsetLate RestoreStructure: IGNORE, read different offsets
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate NukeStructure ChangeButterfly ReadMaxOffsetLate ChangeMaxOffset RestoreStructure: BEFORE, reads the offset before, everything else happens before
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate NukeStructure ReadMaxOffsetLate ChangeButterfly ChangeMaxOffset RestoreStructure: BEFORE, reads the offset before, everything else happens before
// ReadStructureEarly ReadMaxOffsetEarly ReadButterfly ReadStructureLate ReadMaxOffsetLate NukeStructure ChangeButterfly ChangeMaxOffset RestoreStructure: BEFORE, trivially
//
// Whew.
//
// What the collector is doing is just the "double collect" snapshot from "The Unbounded Single-
// Writer Algorithm" from Yehuda Afek et al's "Atomic Snapshots of Shared Memory" in JACM 1993,
// also available here:
//
// http://people.csail.mit.edu/shanir/publications/AADGMS.pdf
//
// Unlike Afek et al's algorithm, ours does not require extra hacks to force wait-freedom (see
// "Observation 2" in the paper). This simplifies the whole algorithm. Instead we are happy with
// obstruction-freedom, and like any good obstruction-free algorithm, we ensure progress using
// scheduling. We also only collect the butterfly once instead of twice; this optimization seems
// to hold up in my proofs above and I'm not sure it's part of Afek et al's algos.
//
// For more background on this kind of madness, I like this paper; it's where I learned about
// both the snapshot algorithm and obstruction-freedom:
//
// Lunchangco, Moir, Shavit. "Nonblocking k-compare-single-swap." SPAA '03
// https://pdfs.semanticscholar.org/343f/7182cde7669ca2a7de3dc01127927f384ef7.pdf
StructureID structureID = this->structureID();
if (structureID.isNuked())
return nullptr;
structure = structureID.decode();
maxOffset = structure->maxOffset();
IndexingType indexingMode;
Dependency indexingModeDependency = structure->fencedIndexingMode(indexingMode);
Locker<JSCellLock> locker(NoLockingNecessary);
switch (indexingMode) {
case ALL_ARRAY_STORAGE_INDEXING_TYPES:
// We need to hold this lock to protect against changes to the innards of the butterfly
// that can happen when the butterfly is used for array storage.
// We do not need to hold this lock for contiguous butterflies. We do not reuse the existing
// butterfly with contiguous shape for new array storage butterfly. When converting the butterfly
// with contiguous shape to array storage, we always allocate a new one. Holding this lock for contiguous
// butterflies is unnecessary since contiguous shaped butterfly never becomes broken state.
locker = Locker { cellLock() };
break;
default:
break;
}
Dependency butterflyDependency = indexingModeDependency.consume(this)->fencedButterfly(butterfly);
if (!butterfly)
return structure;
if (butterflyDependency.consume(this)->structureID() != structureID)
return nullptr;
if (butterflyDependency.consume(structure)->maxOffset() != maxOffset)
return nullptr;
#if USE(JSVALUE64)
// SPEC-objectmodel Task 2 audit: fencedButterfly loaded the TAGGED word
// (§2); mask before dereferencing. The dependency chain is preserved: the
// masked pointer is computed from the loaded value (M1). Segmented words ->
// the §4.5 visit (Task 6b; review round 2): §4.5 step 2's
// Dependency-ordered tagged-word load is the fencedButterfly above. The
// visit RECEIVES our bracketed {early structureID, structure, maxOffset,
// indexingMode} snapshot - the spine load above is dependency-ordered
// after the early structureID load and the late re-checks above already
// passed, so the pair is the same ReadStructureEarly/ReadButterfly/
// ReadStructureLate bracket the flat path uses. The visit must NOT load
// its own fresh structureID: a fresh load could pair a newer structure
// (e.g. a §4.7 in-place relabel, which stops mutators but not concurrent
// markers) with this older spine and value-visit raw double lanes as
// JSValues. nullptr => didRace, surfaced exactly like the flat path.
if (jsThreads) [[unlikely]] {
uint64_t word = std::bit_cast<uint64_t>(butterfly);
if (isSegmentedButterfly(word)) [[unlikely]]
return visitSegmentedButterfly(visitor, this, butterflySpine(word), structureID, structure, maxOffset, indexingMode); // §4.5; nullptr => didRace.
butterfly = untaggedButterfly(word);
}
#endif
markAuxiliaryAndVisitOutOfLineProperties(visitor, butterfly, structure, maxOffset);
ASSERT(indexingMode == structure->indexingMode());
visitElements(indexingMode);
return structure;
}
size_t JSObject::estimatedSize(JSCell* cell, VM& vm)
{
JSObject* thisObject = uncheckedDowncast<JSObject>(cell);
size_t butterflyOutOfLineSize = thisObject->butterfly() ? thisObject->structure()->outOfLineSize() : 0;
return Base::estimatedSize(cell, vm) + butterflyOutOfLineSize;
}
#if USE(JSVALUE64)
// ===== SPEC-objectmodel Task 2: flag-on regime-dispatching slow paths =====
//
// These implement the §Q dispatch for locationForOffset and the quickly-family.
// They are reached only when Options::useJSThreads() is on (I22) and are the
// E5 rule in action: interpreter/runtime slow paths never rely on elision and
// always dispatch on the loaded tagged word. The full §2-dispatch *Concurrent
// accessors of §9.5 (get/putDirectConcurrent, get/putIndexConcurrent — which
// additionally provide M5 tryDecode nuke tolerance and drive the §4.3/N2
// transition protocols) land with Task 6.
const WriteBarrierBase<Unknown>* JSObject::locationForOutOfLineOffsetConcurrent(PropertyOffset offset) const
{
ASSERT(Options::useJSThreads());
ASSERT(isOutOfLineOffset(offset));
// M7(d): the caller's structureID load (the offset's provenance) must be
// ordered before the tagged-word load, else arm64 load-load reordering can
// pair a new structure's offset with a stale, smaller butterfly/spine
// (I24). A loadLoadFence is the only conforming option when the structure
// load lives in caller code (§Q). x86-64: compiler-only barrier.
WTF::loadLoadFence();
uint64_t word = taggedButterflyWord();
while (true) {
if (isSegmentedButterfly(word)) [[unlikely]] {
ButterflySpine* spine = butterflySpine(word);
// I33 out-of-line clause: bound by 4 * spine->outOfLineFragmentCount.
// Out-of-range = the loaded spine is stale (superseded by a grown
// one) => acquire-re-load the tagged word and re-dispatch.
if (const WriteBarrierBase<Unknown>* slot = segmentedOutOfLineSlotIfWithinBounds(spine, offset))
return slot;
WTF::loadLoadFence();
word = taggedButterflyWord();
continue;
}
// Flat (any TID, any SW): mask and index exactly as today. Soundness of
// pairing the caller's structure with this possibly newer flat
// butterfly: every offset-map-changing transition publishes the
// butterfly atomically WITH the structure (locked DCAS, §4.2-5/§4.3-5)
// or BEFORE it (E4 nuke order; M5), and live storage never shrinks
// (deletes quarantine slots, I18/I30) — so a butterfly loaded after the
// structureID always satisfies that structure's storage requirements
// (history §15.4).
return &untaggedButterfly(word)->propertyStorage()[offsetInOutOfLineStorage(offset)];
}
}
// TSAN wave 4 (triage §3.10 / §8.10 jsvalue-slots residual): typed-array arm
// of the concurrent quickly accessors. JSArrayBufferView::m_length and the
// element words are intentionally-racy data words under shared-heap threading
// (SPEC-objectmodel ground truth; SAB-granularity tolerance): a foreign
// thread's trySetIndexQuicklyConcurrent element store (or a racing detach
// zeroing m_length) pairs with this thread's plain loads inside
// canGetIndexQuicklyForTypedArray / getIndexQuicklyForTypedArray, which is
// UB. Route the length read and the element load/store through relaxed
// WTF::Atomic word accesses — the updateEncodedJSValueConcurrent analog for
// non-JSValue words. These helpers are reachable only from the *Concurrent
// accessors (which assert Options::useJSThreads()), so flag-off behavior and
// codegen are untouched. Resizable/growable/auto-length views
// (!canUseRawFieldsDirectly) conservatively report "not quickly": their
// bounds derive from multi-word ArrayBuffer state that cannot be snapshotted
// with a single relaxed load; callers fall to their generic paths.
static ALWAYS_INLINE size_t typedArrayLengthRawConcurrent(const JSArrayBufferView* view)
{
// Annex-N6: length is the SECOND word of the {vector, length} snapshot pair
// and is loaded with acquire so a release-published larger length (arm 4
// grow) pairs. On x86-64 this is still a plain MOV; flag-off never reaches
// here (callers assert Options::useJSThreads()).
return std::bit_cast<const WTF::Atomic<size_t>*>(std::bit_cast<const uint8_t*>(view) + JSArrayBufferView::offsetOfLength())->load(std::memory_order_acquire);
}
// Sized integer alias so the element access compiles to a single relaxed
// atomic word op for every adaptor type (including double and Float16,
// where Atomic<Type> itself would be exotic).
template<typename Type>
using TypedArrayElementRawWord = std::conditional_t<sizeof(Type) == 1, uint8_t,
std::conditional_t<sizeof(Type) == 2, uint16_t,
std::conditional_t<sizeof(Type) == 4, uint32_t, uint64_t>>>;
// CVE-AUDIT A1 (MC-GROW S4/S8) / annex-N6 single-snapshot read protocol for
// the concurrent TA fast paths. JSArrayBufferView::detachFromArrayBuffer()
// (JSArrayBufferView.cpp:263-270) publishes m_length=0 then m_vector=nullptr
// under cellLock; the previous shape here bounds-checked against a freshly
// loaded length THEN re-loaded typedVector(), so a racing detach interleaved
// {old length, null vector} -> SEGV at *(null + i) (ASAN evidence:
// JSTests/threads/cve/mc-grow-buffer-storm.CRASH-{19,37,s4-nullvec}.log,
// repro mc-grow-s4-detach-nullvec-repro.js). Annex-N6 PRINCIPLE: a racing
// reader must NEVER pair a passing length with an unmapped-or-short base.
// Reader discipline: load the vector word FIRST (single relaxed caged-word
// load via vectorCagedConcurrently()); bail to the slow path on null; THEN
// load length (acquire) and bounds-check; dereference the SNAPSHOTTED vector
// only — never a re-load. Any non-null vector word ever observed names backing
// storage that stays mapped through the next heap §10 stop (annex-N6 arm-1/2/3
// quarantine), so {old vector, old length} is stale-but-safe and {*, 0}
// bounds-fails. Reachable only via the *Concurrent accessors (assert
// Options::useJSThreads()): flag-off codegen untouched.
template<typename Adaptor>
static ALWAYS_INLINE const typename Adaptor::Type* snapshotTypedVectorAndBoundsCheckConcurrent(const JSGenericTypedArrayView<Adaptor>* view, unsigned i)
{
if (!view->canUseRawFieldsDirectly()) [[unlikely]]
return nullptr;
const typename Adaptor::Type* vector = view->typedVector(); // relaxed atomic m_vector load
if (!vector) [[unlikely]]
return nullptr; // annex-N6 null-vector bail: detached/torn pair
if (i >= typedArrayLengthRawConcurrent(view))
return nullptr;
return vector;
}
template<typename Adaptor>
static ALWAYS_INLINE bool canGetIndexQuicklyForTypedArrayViewConcurrent(const JSGenericTypedArrayView<Adaptor>* view, unsigned i)
{
if (!Adaptor::canConvertToJSQuickly)
return false;
return !!snapshotTypedVectorAndBoundsCheckConcurrent(view, i);
}
template<typename Adaptor>
static ALWAYS_INLINE JSValue tryGetIndexQuicklyForTypedArrayViewConcurrent(const JSGenericTypedArrayView<Adaptor>* view, unsigned i)
{
using Type = typename Adaptor::Type;
using RawWord = TypedArrayElementRawWord<Type>;
static_assert(sizeof(RawWord) == sizeof(Type));
if (!Adaptor::canConvertToJSQuickly)
return JSValue();
const Type* vector = snapshotTypedVectorAndBoundsCheckConcurrent(view, i);
if (!vector)
return JSValue();
RawWord raw = std::bit_cast<const WTF::Atomic<RawWord>*>(vector + i)->loadRelaxed();
return Adaptor::toJSValue(nullptr, std::bit_cast<Type>(raw));
}
template<typename Adaptor>
static ALWAYS_INLINE bool trySetIndexQuicklyForTypedArrayViewConcurrent(JSGenericTypedArrayView<Adaptor>* view, unsigned i, JSValue value)
{
using Type = typename Adaptor::Type;
using RawWord = TypedArrayElementRawWord<Type>;
static_assert(sizeof(RawWord) == sizeof(Type));
if (!value.isNumber())
return false;
// canSetIndexQuickly == canGetIndexQuickly + isNumber for the quickly family.
if (!Adaptor::canConvertToJSQuickly)
return false;
const Type* vector = snapshotTypedVectorAndBoundsCheckConcurrent(view, i);
if (!vector)
return false;
// toNativeFromValue on a number is pure (no JS, no allocation).
Type native = toNativeFromValue<Adaptor>(value);
std::bit_cast<WTF::Atomic<RawWord>*>(const_cast<Type*>(vector) + i)->storeRelaxed(std::bit_cast<RawWord>(native));
return true;
}
static ALWAYS_INLINE bool canGetIndexQuicklyForTypedArrayConcurrent(const JSObject* object, unsigned i)
{
switch (object->type()) {
#define CASE_TYPED_ARRAY_TYPE(name) \
case name ## ArrayType: \
return canGetIndexQuicklyForTypedArrayViewConcurrent(uncheckedDowncast<JS ## name ## Array>(object), i);
FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(CASE_TYPED_ARRAY_TYPE)
#undef CASE_TYPED_ARRAY_TYPE
default:
return false;
}
}
static ALWAYS_INLINE JSValue tryGetIndexQuicklyForTypedArrayConcurrent(const JSObject* object, unsigned i, ArrayProfile* arrayProfile)
{
#if USE(LARGE_TYPED_ARRAYS)
if (i > ArrayProfile::s_smallTypedArrayMaxLength && arrayProfile)
arrayProfile->setMayBeLargeTypedArray();
#else
UNUSED_PARAM(arrayProfile);
#endif
switch (object->type()) {
#define CASE_TYPED_ARRAY_TYPE(name) \
case name ## ArrayType: \
return tryGetIndexQuicklyForTypedArrayViewConcurrent(uncheckedDowncast<JS ## name ## Array>(object), i);
FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(CASE_TYPED_ARRAY_TYPE)
#undef CASE_TYPED_ARRAY_TYPE
default:
return JSValue();
}
}
static ALWAYS_INLINE bool trySetIndexQuicklyForTypedArrayConcurrent(JSObject* object, unsigned i, JSValue value, ArrayProfile* arrayProfile)
{
bool result;
switch (object->type()) {
#define CASE_TYPED_ARRAY_TYPE(name) \
case name ## ArrayType: \
result = trySetIndexQuicklyForTypedArrayViewConcurrent(uncheckedDowncast<JS ## name ## Array>(object), i, value); \
break;
FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(CASE_TYPED_ARRAY_TYPE)
#undef CASE_TYPED_ARRAY_TYPE
default:
return false;
}
if (!result)
return false;
#if USE(LARGE_TYPED_ARRAYS)
if (i > ArrayProfile::s_smallTypedArrayMaxLength && arrayProfile)
arrayProfile->setMayBeLargeTypedArray();
#else
UNUSED_PARAM(arrayProfile);
#endif
return true;
}
bool JSObject::canGetIndexQuicklyConcurrent(unsigned i) const
{
ASSERT(Options::useJSThreads());
// E5 "None first" (review round 4): the word is loaded BEFORE the indexing
// byte in program order, and the N3 first indexed-storage install is
// lock-free (no stop) - so a stale word==0 can pair with a FRESH indexed
// type here. Every flat dense branch below must therefore null-check the
// payload of the SAME loaded word and report "not quickly" (callers take
// their generic path, which re-dispatches on fresh state). Dereferencing
// untaggedButterfly(0) would read around address 0 - a crash from a race.
uint64_t word = taggedButterflyWord();
switch (indexingType()) {
case ALL_BLANK_INDEXING_TYPES:
return canGetIndexQuicklyForTypedArrayConcurrent(this, i); // §3.10: relaxed m_length read
case ALL_UNDECIDED_INDEXING_TYPES:
return false;
case ALL_INT32_INDEXING_TYPES:
case ALL_CONTIGUOUS_INDEXING_TYPES: {
if (isSegmentedButterfly(word)) [[unlikely]] {
const WriteBarrierBase<Unknown>* slot = segmentedIndexedSlotIfReadable(butterflySpine(word), i); // C4
return slot && !!slot->get();
}
const Butterfly* butterfly = untaggedButterfly(word);
if (!butterfly) [[unlikely]]
return false; // E5 None-first: racing N3 first install (round 4).
return i < butterfly->vectorLength() && butterfly->contiguous().at(this, i);
}
case ALL_DOUBLE_INDEXING_TYPES: {
if (isSegmentedButterfly(word)) [[unlikely]] {
// §4.7: Double fragments hold RAW doubles (shape-keyed interpretation;
// aligned 8B slots are tear-free at SAB granularity; holes = PNaN).
const WriteBarrierBase<Unknown>* slot = segmentedIndexedSlotIfReadable(butterflySpine(word), i); // C4
if (!slot)
return false;
double value = *std::bit_cast<const double*>(slot);
return value == value;
}
const Butterfly* butterfly = untaggedButterfly(word);
if (!butterfly) [[unlikely]]
return false; // E5 None-first (round 4).
if (i >= butterfly->vectorLength())
return false;
double value = butterfly->contiguousDouble().at(this, i);
return value == value;
}
case ALL_ARRAY_STORAGE_INDEXING_TYPES:
// §Q/I31: flag-on, AS-shape quickly probes answer false so callers fall
// to their generic paths (E5 dispatch = §4.6 cell-locked access).
return false;
default:
RELEASE_ASSERT_NOT_REACHED();
return false;
}
}
JSValue JSObject::getIndexQuicklyConcurrent(unsigned i) const
{
ASSERT(Options::useJSThreads());
uint64_t word = taggedButterflyWord();
switch (indexingType()) {
case ALL_INT32_INDEXING_TYPES:
case ALL_CONTIGUOUS_INDEXING_TYPES: {
JSValue value;
if (isSegmentedButterfly(word)) [[unlikely]] {
const WriteBarrierBase<Unknown>* slot = segmentedIndexedSlotIfReadable(butterflySpine(word), i); // C4
value = slot ? slot->get() : JSValue();
} else {
const Butterfly* butterfly = untaggedButterfly(word);
// E5 None-first + C4-style bound on the SAME loaded word (round 4):
// a stale word (racing N3 install / older flat snapshot than the
// caller's bound check) reads as a hole, never a wild deref.
if (!butterfly || i >= butterfly->vectorLength()) [[unlikely]]
return jsUndefined();
value = butterfly->contiguous().at(this, i).get();
}
// Race tolerance (I21/SAB semantics): a hole surfacing under a racing
// shrink/delete reads as undefined rather than an empty JSValue.
if (!value) [[unlikely]]
return jsUndefined();
if (hasInt32(indexingType()))
return jsNumber(value.asInt32());
return value;
}
case ALL_DOUBLE_INDEXING_TYPES: {
double value;
if (isSegmentedButterfly(word)) [[unlikely]] {
const WriteBarrierBase<Unknown>* slot = segmentedIndexedSlotIfReadable(butterflySpine(word), i); // C4
if (!slot) [[unlikely]]
return jsUndefined();
value = *std::bit_cast<const double*>(slot); // §4.7 raw double
} else {
const Butterfly* butterfly = untaggedButterfly(word);
if (!butterfly || i >= butterfly->vectorLength()) [[unlikely]] // E5 None-first + snapshot bound (round 4)
return jsUndefined();
value = butterfly->contiguousDouble().at(this, i);
}
if (value != value) [[unlikely]]
return jsUndefined(); // hole (PNaN) surfaced under a race
return JSValue(JSValue::EncodeAsDouble, value);
}
case ALL_ARRAY_STORAGE_INDEXING_TYPES: {
// I31: flag-on, EVERY runtime AS access is cell-locked (AS never
// segments). Re-load the word under the lock: AS-COPY (§4.6) may have
// republished a fresh AS butterfly.
Locker locker { cellLock() };
const Butterfly* butterfly = untaggedButterfly(taggedButterflyWord());
const ArrayStorage* storage = butterfly->arrayStorage();
if (i >= storage->vectorLength()) [[unlikely]]
return jsUndefined();
JSValue value = storage->m_vector[i].get();
return value ? value : jsUndefined();
}
case ALL_BLANK_INDEXING_TYPES: {
// §3.10: relaxed length + element reads. A racing detach/length change
// between the caller's canGetIndexQuicklyConcurrent and this read
// surfaces as undefined — same race tolerance as the dense arms above —
// instead of tripping getIndexQuicklyForTypedArray's RELEASE_ASSERT.
JSValue result = tryGetIndexQuicklyForTypedArrayConcurrent(this, i, nullptr);
return result ? result : jsUndefined();
}
default:
RELEASE_ASSERT_NOT_REACHED();
return JSValue();
}
}
JSValue JSObject::tryGetIndexQuicklyConcurrent(unsigned i, ArrayProfile* arrayProfile) const
{
ASSERT(Options::useJSThreads());
uint64_t word = taggedButterflyWord();
switch (indexingType()) {
case ALL_BLANK_INDEXING_TYPES:
// §3.10: relaxed length + element reads (single length snapshot — no
// can/get TOCTOU against a racing detach).
if (JSValue result = tryGetIndexQuicklyForTypedArrayConcurrent(this, i, arrayProfile))
return result;
break;
case ALL_UNDECIDED_INDEXING_TYPES:
break;
case ALL_INT32_INDEXING_TYPES:
case ALL_CONTIGUOUS_INDEXING_TYPES: {
if (isSegmentedButterfly(word)) [[unlikely]] {
const WriteBarrierBase<Unknown>* slot = segmentedIndexedSlotIfReadable(butterflySpine(word), i); // C4
if (!slot)
break;
JSValue result = slot->get();
ASSERT(!hasInt32(indexingType()) || result.isInt32() || !result);
return result; // empty => caller's generic path
}
const Butterfly* butterfly = untaggedButterfly(word);
if (!butterfly) [[unlikely]]
break; // E5 None-first: racing N3 first install (round 4) => generic path.
// Bound by vectorLength too (round 4): on a flat word that a racing
// §4.2 conversion + T2 grow superseded, the aliased publicLength slot
// can race past THIS snapshot's storage.
if (i < butterfly->publicLength() && i < butterfly->vectorLength()) {
JSValue result = butterfly->contiguous().at(this, i).get();
ASSERT(!hasInt32(indexingType()) || result.isInt32() || !result);
return result;
}
break;
}
case ALL_DOUBLE_INDEXING_TYPES: {
double result;
if (isSegmentedButterfly(word)) [[unlikely]] {
const WriteBarrierBase<Unknown>* slot = segmentedIndexedSlotIfReadable(butterflySpine(word), i); // C4
if (!slot)
break;
result = WTF::atomicLoad(std::bit_cast<double*>(const_cast<WriteBarrierBase<Unknown>*>(slot)), std::memory_order_relaxed); // §4.7 raw double; relaxed atomic (intentionally racy JS value word)
} else {
const Butterfly* butterfly = untaggedButterfly(word);
if (!butterfly) [[unlikely]]
break; // E5 None-first (round 4).
if (i >= butterfly->publicLength() || i >= butterfly->vectorLength()) // round 4: snapshot bound (aliased publicLength can race past it)
break;
result = WTF::atomicLoad(const_cast<double*>(&butterfly->contiguousDouble().at(this, i).m_data), std::memory_order_relaxed); // relaxed atomic (intentionally racy JS value word)
}
if (result != result)
break;
return JSValue(JSValue::EncodeAsDouble, result);
}
case ALL_ARRAY_STORAGE_INDEXING_TYPES:
// §Q/I31: not-quickly; callers fall to the generic (§4.6 locked) path.
break;
default:
RELEASE_ASSERT_NOT_REACHED();
break;
}
return JSValue();
}
// Review round 2: dense-store publicLength update for FLAT words. On a SHARED
// word (SW=1) the legacy read-then-plain-store can regress publicLength under
// racing growers - T1 stores a[8]/len=9, T0 (stale len read) stores a[5]/len=6
// - hiding T1's element behind the min(publicLength, vectorLength) read bound
// (I21 "no lost properties"; i03-t5-racing-growers part (a)). Shared words
// therefore CAS-max; owner-exclusive (t, 0) words keep today's plain store
// (only the owner can be in a dense grow while SW=0: a foreign grower flips SW
// first, §3 F1). Segmented words use ButterflySpine::bumpPublicLengthToAtLeast
// at their own sites.
// AB17f (I21 publication ordering): the CAS-max bump is now a RELEASE, so the
// element store above each call is published no later than the length; the
// reader-side acquire gap (ARM64) is the KNOWN RESIDUAL recorded at
// Butterfly::bumpPublicLengthToAtLeast. The owner-exclusive (SW=0) plain
// setPublicLength arm is inside the same residual: foreign READERS of an SW=0
// word get SAB-granularity staleness at worst (spurious hole => generic path).
static ALWAYS_INLINE void updatePublicLengthAfterDenseStoreConcurrent(uint64_t word, Butterfly* butterfly, unsigned i)
{
if (i < butterfly->publicLength()) [[likely]]
return;
if (butterflySharedWrite(word))
butterfly->bumpPublicLengthToAtLeast(i + 1);
else
butterfly->setPublicLength(i + 1);
}
bool JSObject::trySetIndexQuicklyConcurrent(VM& vm, unsigned i, JSValue v, ArrayProfile* arrayProfile)
{
ASSERT(Options::useJSThreads());
// §4.8/I35 (cve fix): classify the MODE before loading the WORD, with a
// load-load fence between them. The §4.8 materializer publishes
// {writable header, fresh word} as one seq_cst DCAS (PA flavor: the word
// CAS precedes the new header bytes), so a WRITABLE mode observed here
// guarantees the fenced word load below is NOT the superseded CoW word.
// The old order (word first, indexingMode() read at the switch) let a
// racing materialization pair the STALE CoW word with the fresh writable
// mode: the dense branches then stored straight into the shared
// JSImmutableButterfly payload (sibling-visible mutation; I35/I21,
// mc-lock-cow-materialize-race pass-1 oracle).
IndexingType mode = indexingMode();
if (isCopyOnWrite(mode)) [[unlikely]]
return false; // §4.8 materialization belongs to the caller's generic path (putByIndex / convertFromCopyOnWrite).
WTF::loadLoadFence();
uint64_t word = taggedButterflyWord();
// §3 F1 (review round 1; Task 7's ensureSharedWriteBit is landed): a
// foreign write to an SW=0 FLAT word must fire writeThreadLocal and flip
// SW BEFORE any plain store lands - otherwise the owner's T1 copying
// resize still sees (t,0), its CAS succeeds against a payload that
// received our store mid-copy, and the store is silently dropped (I21);
// it would also break I12 (writeThreadLocal valid <=> no foreign write
// ever), unsounding the watchpoint-elision argument. Scope: exactly the
// flat dense-write branches below (Int32/Double/Contiguous, incl. their
// publicLength bumps). CoW is excluded (WRITABLE modes never match CoW;
// the default leg returns false to the caller's §4.8 path); AS and
// Undecided return false below; typed-array (BLANK) stores do not touch
// the butterfly. Segmented and SW=1 words need no flip (I3/I4).
if ((word & butterflyPointerMask) && !isSegmentedButterfly(word)
&& !butterflySharedWrite(word) && butterflyWriterIsForeign(word) // incl. §9.6 forceButterflySWBit
&& (hasInt32(mode) || hasDouble(mode) || hasContiguous(mode))) [[unlikely]] {
ensureSharedWriteBit(vm, static_cast<JSObjectWithButterfly*>(this));
mode = indexingMode(); // A racing STW relabel may advance the shape while we are parked in the stop; CoW cannot reappear (monotone exit, §4.8).
WTF::loadLoadFence(); // Same mode-before-word ordering as above.
word = taggedButterflyWord(); // Re-dispatch on the fresh tag (SW=1 flat or segmented now).
}
switch (mode) {
case ALL_BLANK_INDEXING_TYPES:
return trySetIndexQuicklyForTypedArrayConcurrent(this, i, v, arrayProfile); // §3.10: relaxed length read + element store
case ALL_UNDECIDED_INDEXING_TYPES:
return false;
case ALL_WRITABLE_INT32_INDEXING_TYPES: {
if (isSegmentedButterfly(word)) [[unlikely]] {
if (!v.isInt32())
return false; // shape transition => generic path (§4.3/§4.7, Tasks 6-8)
WriteBarrierBase<Unknown>* slot = segmentedIndexedSlotIfWithinVectorLength(butterflySpine(word), i);
if (!slot)
return false;
slot->set(vm, this, v); // §4.5: fragment-slot stores use WriteBarrierBase::set on the owner
// Review round 2: segmented words are shared by definition, so the
// length bump must be a CAS-max - a plain read-then-store loses
// racing growers' elements (I21; i03-t5 part (a)).
butterflySpine(word)->bumpPublicLengthToAtLeast(i + 1);
return true;
}
Butterfly* butterfly = untaggedButterfly(word);
if (!butterfly) [[unlikely]]
return false; // E5 None-first: racing N3 first install (round 4) => generic path.
if (i >= butterfly->vectorLength())
return false;
if (!v.isInt32()) {
convertInt32ToDoubleOrContiguousWhilePerformingSetIndex(vm, i, v);
return true;
}
butterfly->contiguous().at(this, i).setWithoutWriteBarrier(v);
updatePublicLengthAfterDenseStoreConcurrent(word, butterfly, i);
vm.writeBarrier(this, v);
return true;
}
case ALL_WRITABLE_CONTIGUOUS_INDEXING_TYPES: {
if (isSegmentedButterfly(word)) [[unlikely]] {