FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
WebKit/Source/JavaScriptCore/heap/Heap.cpp at main · WebKit/WebKit · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
WebKit
/
WebKit
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10.1k
Code
Pull requests
2.6k
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
WebKit
/
Source
/
JavaScriptCore
/
heap
/
Heap.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
3687 lines (3107 loc) · 132 KB
Breadcrumbs
WebKit
/
Source
/
JavaScriptCore
/
heap
/
Heap.cpp
Copy path
File metadata and controls
3687 lines (3107 loc) · 132 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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) 2003-2026 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 Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#
include
"
config.h
"
#
include
"
Heap.h
"
#
include
"
JSCJSValueInlines.h
"
#
include
"
BaselineJITCode.h
"
#
include
"
BuiltinExecutables.h
"
#
include
"
CodeBlock.h
"
#
include
"
CodeBlockSetInlines.h
"
#
include
"
CollectingScope.h
"
#
include
"
ConservativeRoots.h
"
#
include
"
EdenGCActivityCallback.h
"
#
include
"
EvalExecutable.h
"
#
include
"
Exception.h
"
#
include
"
FastMallocAlignedMemoryAllocator.h
"
#
include
"
FullGCActivityCallback.h
"
#
include
"
FunctionExecutableInlines.h
"
#
include
"
GCActivityCallback.h
"
#
include
"
GCIncomingRefCountedInlines.h
"
#
include
"
GCIncomingRefCountedSetInlines.h
"
#
include
"
GCSegmentedArrayInlines.h
"
#
include
"
GCTypeMap.h
"
#
include
"
GigacageAlignedMemoryAllocator.h
"
#
include
"
HasOwnPropertyCache.h
"
#
include
"
HeapHelperPool.h
"
#
include
"
HeapIterationScope.h
"
#
include
"
HeapProfiler.h
"
#
include
"
HeapSnapshot.h
"
#
include
"
HeapSubspaceTypes.h
"
#
include
"
HeapVerifier.h
"
#
include
"
IncrementalSweeper.h
"
#
include
"
Interpreter.h
"
#
include
"
IsoCellSetInlines.h
"
#
include
"
IsoInlinedHeapCellTypeInlines.h
"
#
include
"
JITStubRoutineSet.h
"
#
include
"
JITWorklistInlines.h
"
#
include
"
JSFinalizationRegistry.h
"
#
include
"
JSFunctionWithFields.h
"
#
include
"
JSIterator.h
"
#
include
"
JSMicrotaskDispatcher.h
"
#
include
"
JSModuleLoader.h
"
#
include
"
JSPromiseCombinatorsContext.h
"
#
include
"
JSPromiseCombinatorsGlobalContext.h
"
#
include
"
JSPromiseReaction.h
"
#
include
"
JSRawJSONObject.h
"
#
include
"
JSRemoteFunction.h
"
#
include
"
JSSentinel.h
"
#
include
"
JSVirtualMachineInternal.h
"
#
include
"
JSWeakMap.h
"
#
include
"
JSWeakObjectRef.h
"
#
include
"
JSWeakSet.h
"
#
include
"
MachineStackMarker.h
"
#
include
"
MarkStackMergingConstraint.h
"
#
include
"
MarkedSpaceInlines.h
"
#
include
"
MarkingConstraintSet.h
"
#
include
"
MegamorphicCache.h
"
#
include
"
ModuleLoadingContext.h
"
#
include
"
ModuleProgramExecutable.h
"
#
include
"
ModuleRegistryEntry.h
"
#
include
"
NumberObject.h
"
#
include
"
PinballCompletion.h
"
#
include
"
PreventCollectionScope.h
"
#
include
"
ProgramExecutable.h
"
#
include
"
ProxyObject.h
"
#
include
"
SamplingProfiler.h
"
#
include
"
ShadowChicken.h
"
#
include
"
SpaceTimeMutatorScheduler.h
"
#
include
"
StochasticSpaceTimeMutatorScheduler.h
"
#
include
"
StopIfNecessaryTimer.h
"
#
include
"
StringSplitCache.h
"
#
include
"
StructureAlignedMemoryAllocator.h
"
#
include
"
SubspaceInlines.h
"
#
include
"
SuperSampler.h
"
#
include
"
SweepingScope.h
"
#
include
"
SymbolTableInlines.h
"
#
include
"
SynchronousStopTheWorldMutatorScheduler.h
"
#
include
"
TypeProfiler.h
"
#
include
"
TypeProfilerLog.h
"
#
include
"
UnlinkedEvalCodeBlock.h
"
#
include
"
VM.h
"
#
include
"
VerifierSlotVisitorInlines.h
"
#
include
"
WasmCallee.h
"
#
include
"
WeakMapImplInlines.h
"
#
include
"
WeakSetInlines.h
"
#
include
<
algorithm
>
#
include
<
wtf/AvailableMemory.h
>
#
include
<
wtf/CryptographicallyRandomNumber.h
>
#
include
<
wtf/ListDump.h
>
#
include
<
wtf/MemoryFootprint.h
>
#
include
<
wtf/RAMSize.h
>
#
include
<
wtf/Scope.h
>
#
include
<
wtf/SetForScope.h
>
#
include
<
wtf/SimpleStats.h
>
#
include
<
wtf/SystemTracing.h
>
#
include
<
wtf/TZoneMallocInlines.h
>
#
include
<
wtf/Threading.h
>
#
if
USE(FOUNDATION)
#
include
<
wtf/spi/cocoa/objcSPI.h
>
#
endif
#
ifdef
JSC_GLIB_API_ENABLED
#
include
"
JSCGLibWrapperObject.h
"
#
endif
namespace
JSC
{
namespace
HeapInternal
{
static
constexpr
bool
verbose =
false
;
static
constexpr
bool
verboseStop =
false
;
}
namespace
{
static
double
maxPauseMS
(
double
thisPauseMS)
{
static
double
maxPauseMS;
maxPauseMS =
std::max
(thisPauseMS, maxPauseMS);
return
maxPauseMS;
}
static
GrowthMode
NODELETE
growthMode
(
size_t
ramSize)
{
//
An Aggressive heap uses more memory to go faster.
//
We do this for machines with enough RAM.
size_t
aggressiveHeapThresholdInBytes =
static_cast
<
size_t
>(
Options::aggressiveHeapThresholdInMB
()) *
MB
;
if
(ramSize >= aggressiveHeapThresholdInBytes)
return
GrowthMode::Aggressive;
return
GrowthMode::Default;
}
static
size_t
minHeapSize
(HeapType heapType,
size_t
ramSize)
{
switch
(heapType) {
case
HeapType::Large:
return
static_cast
<
size_t
>(
std::min
(
static_cast
<
double
>(
Options::largeHeapSize
()),
ramSize *
Options::smallHeapRAMFraction
()));
case
HeapType::Medium:
return
Options::mediumHeapSize
();
case
HeapType::Small:
return
Options::smallHeapSize
();
default
:
RELEASE_ASSERT_NOT_REACHED
();
break
;
}
}
static
size_t
NODELETE
maxEdenSizeForRateLimiting
(GrowthMode growthMode,
size_t
minBytesPerCycle)
{
//
Only do rate limiting for Aggressive heaps.
if
(growthMode == GrowthMode::Aggressive)
return
Options::maxEdenSizeForRateLimitingMultiplier
() * minBytesPerCycle;
return
0.0
;
}
static
size_t
proportionalHeapSize
(
size_t
heapSize, GrowthMode growthMode,
size_t
ramSize)
{
if
(
VM::isInMiniMode
())
return
Options::miniVMHeapGrowthFactor
() * heapSize;
bool
useNewHeapGrowthFactor = growthMode == GrowthMode::Aggressive;
//
Use new heuristic function for Aggressive heaps (machines >= 16GB RAM).
//
https://www.mathway.com/en/Algebra?asciimath=2%20*%20e%5E(-1%20*%20x)%20%2B%201%20%3Dy
//
Disable it for Darwin Intel machine.
#
if
OS(DARWIN) && CPU(X86_64)
useNewHeapGrowthFactor =
false
;
#
endif
if
(useNewHeapGrowthFactor) {
double
x =
static_cast
<
double
>(
std::min
(heapSize, ramSize)) / ramSize;
double
ratio =
Options::heapGrowthMaxIncrease
() *
std::exp
(-(
Options::heapGrowthSteepnessFactor
() * x)) +
1
;
return
ratio * heapSize;
}
#
if
USE(MEMORY_FOOTPRINT_API)
size_t
memoryFootprint =
WTF::memoryFootprint
();
if
(memoryFootprint < ramSize *
Options::smallHeapRAMFraction
())
return
Options::smallHeapGrowthFactor
() * heapSize;
if
(memoryFootprint < ramSize *
Options::mediumHeapRAMFraction
())
return
Options::mediumHeapGrowthFactor
() * heapSize;
#
else
if
(heapSize < ramSize *
Options::smallHeapRAMFraction
())
return
Options::smallHeapGrowthFactor
() * heapSize;
if
(heapSize < ramSize *
Options::mediumHeapRAMFraction
())
return
Options::mediumHeapGrowthFactor
() * heapSize;
#
endif
return
Options::largeHeapGrowthFactor
() * heapSize;
}
static
void
recordType
(TypeCountSet& set, JSCell* cell)
{
auto
typeName =
"
[unknown]
"
_s;
const
ClassInfo* info = cell->
classInfo
();
if
(info && info->
className
)
typeName = info->
className
;
set.
add
(typeName);
}
constexpr
bool
NODELETE
measurePhaseTiming
()
{
return
false
;
}
UncheckedKeyHashMap<
const
char
*, GCTypeMap<SimpleStats>>&
timingStats
()
{
static
UncheckedKeyHashMap<
const
char
*, GCTypeMap<SimpleStats>>* result;
static
std::once_flag once;
std::call_once
(
once,
[] {
result =
new
UncheckedKeyHashMap<
const
char
*, GCTypeMap<SimpleStats>>();
});
return
*result;
}
SimpleStats&
timingStats
(
const
char
* name, CollectionScope scope)
{
return
timingStats
().
add
(name, GCTypeMap<SimpleStats>()).
iterator
->
value
[scope];
}
class
TimingScope
{
public:
TimingScope
(std::optional<CollectionScope> scope, ASCIILiteral name)
: m_scope(scope)
, m_name(name)
{
if
(
measurePhaseTiming
())
m_before =
MonotonicTime::now
();
}
TimingScope
(
JSC
::Heap& heap, ASCIILiteral name)
: TimingScope(heap.collectionScope(), name)
{
}
void
NODELETE
setScope
(std::optional<CollectionScope> scope)
{
m_scope = scope;
}
void
NODELETE
setScope
(
JSC
::Heap& heap)
{
setScope
(heap.
collectionScope
());
}
~TimingScope
()
{
if
(
measurePhaseTiming
()) {
MonotonicTime after =
MonotonicTime::now
();
Seconds timing = after - m_before;
SimpleStats& stats =
timingStats
(m_name, *m_scope);
stats.
add
(timing.
milliseconds
());
dataLog
(
"
[GC:
"
, *m_scope,
"
]
"
, m_name,
"
took:
"
, timing.
milliseconds
(),
"
ms (average
"
, stats.
mean
(),
"
ms).
\n
"
);
}
}
private:
std::optional<CollectionScope> m_scope;
MonotonicTime m_before;
ASCIILiteral m_name;
};
}
//
anonymous namespace
class
Heap
::HeapThread
final
: public AutomaticThread {
WTF_MAKE_TZONE_ALLOCATED_INLINE
(HeapThread);
WTF_OVERRIDE_DELETE_FOR_CHECKED_PTR
(HeapThread);
public:
HeapThread
(
const
AbstractLocker& locker,
JSC
::Heap& heap)
: AutomaticThread(locker, heap.m_threadLock, heap.m_threadCondition.copyRef())
, m_heap(heap)
{
}
ASCIILiteral
name
()
const
final
{
return
"
JSC Heap Collector Thread
"
_s;
}
private:
PollResult
poll
(
const
AbstractLocker& locker)
final
{
if
(m_heap.
m_threadShouldStop
) {
m_heap.
notifyThreadStopping
(locker);
return
PollResult::Stop;
}
if
(m_heap.
shouldCollectInCollectorThread
(locker)) {
m_heap.
m_collectorThreadIsRunning
=
true
;
return
PollResult::Work;
}
m_heap.
m_collectorThreadIsRunning
=
false
;
return
PollResult::Wait;
}
WorkResult
work
()
final
{
m_heap.
collectInCollectorThread
();
return
WorkResult::Continue;
}
void
threadDidStart
()
final
{
Thread::registerGCThread
(GCThreadType::Main);
}
void
threadIsStopping
(
const
AbstractLocker&)
final
{
m_heap.
m_collectorThreadIsRunning
=
false
;
}
JSC
::Heap& m_heap;
};
#
define
INIT_SERVER_ISO_SUBSPACE
(
name, heapCellType, type
) \
, name
ISO_SUBSPACE_INIT
(*
this
, heapCellType, type)
#
define
INIT_SERVER_STRUCTURE_ISO_SUBSPACE
(
name, heapCellType, type
) \
, name(#name, *
this
, heapCellType,
WTF
::roundUpToMultipleOf<type::atomSize>(
sizeof
(type)), type::numberOfLowerTierPreciseCells, makeUnique<StructureAlignedMemoryAllocator>())
Heap::Heap
(
VM
& vm, HeapType heapType)
: m_heapType(heapType)
, m_ramSize(Options::forceRAMSize() ? Options::forceRAMSize() : ramSize())
, m_growthMode(growthMode(m_ramSize))
, m_minBytesPerCycle(minHeapSize(m_heapType, m_ramSize))
, m_maxEdenSizeForRateLimiting(maxEdenSizeForRateLimiting(m_growthMode, m_minBytesPerCycle))
, m_maxEdenSize(m_minBytesPerCycle)
, m_maxHeapSize(m_minBytesPerCycle)
, m_objectSpace(
this
)
, m_machineThreads(makeUnique<MachineThreads>())
, m_collectorSlotVisitor(makeUnique<SlotVisitor>(*
this
,
"
C
"
_s))
, m_mutatorSlotVisitor(makeUnique<SlotVisitor>(*
this
,
"
M
"
_s))
, m_mutatorMarkStack(makeUnique<MarkStackArray>())
, m_raceMarkStack(makeUnique<MarkStackArray>())
, m_constraintSet(makeUnique<MarkingConstraintSet>(*
this
))
, m_strongSet(vm)
, m_codeBlocks(makeUnique<CodeBlockSet>())
, m_jitStubRoutines(makeUnique<JITStubRoutineSet>())
//
We seed with 10ms so that GCActivityCallback::didAllocate doesn't continuously
//
schedule the timer if we've never done a collection.
, m_fullActivityCallback(FullGCActivityCallback::tryCreate(*
this
))
, m_edenActivityCallback(EdenGCActivityCallback::tryCreate(*
this
))
, m_sweeper(adoptRef(*
new
IncrementalSweeper(
this
)))
, m_stopIfNecessaryTimer(adoptRef(*
new
StopIfNecessaryTimer(vm)))
, m_sharedCollectorMarkStack(makeUnique<MarkStackArray>())
, m_sharedMutatorMarkStack(makeUnique<MarkStackArray>())
, m_helperClient(&
heapHelperPool
())
, m_threadLock(Box<Lock>::create())
, m_threadCondition(AutomaticThreadCondition::create())
//
HeapCellTypes
, auxiliaryHeapCellType(CellAttributes(DoesNotNeedDestruction, HeapCell::Auxiliary))
, immutableButterflyHeapCellType(CellAttributes(DoesNotNeedDestruction, HeapCell::JSCellWithIndexingHeader))
, cellHeapCellType(CellAttributes(DoesNotNeedDestruction, HeapCell::JSCell))
, destructibleCellHeapCellType(CellAttributes(NeedsDestruction, HeapCell::JSCell))
, apiGlobalObjectHeapCellType(IsoHeapCellType::Args<JSAPIGlobalObject>())
, callbackConstructorHeapCellType(IsoHeapCellType::Args<JSCallbackConstructor>())
, callbackGlobalObjectHeapCellType(IsoHeapCellType::Args<JSCallbackObject<JSGlobalObject>>())
, callbackObjectHeapCellType(IsoHeapCellType::Args<JSCallbackObject<JSNonFinalObject>>())
, customGetterFunctionHeapCellType(IsoHeapCellType::Args<JSCustomGetterFunction>())
, customSetterFunctionHeapCellType(IsoHeapCellType::Args<JSCustomSetterFunction>())
, dateInstanceHeapCellType(IsoHeapCellType::Args<DateInstance>())
, errorInstanceHeapCellType(IsoHeapCellType::Args<ErrorInstance>())
, finalizationRegistryCellType(IsoHeapCellType::Args<JSFinalizationRegistry>())
, globalLexicalEnvironmentHeapCellType(IsoHeapCellType::Args<JSGlobalLexicalEnvironment>())
, globalObjectHeapCellType(IsoHeapCellType::Args<JSGlobalObject>())
, injectedScriptHostSpaceHeapCellType(IsoHeapCellType::Args<Inspector::JSInjectedScriptHost>())
, javaScriptCallFrameHeapCellType(IsoHeapCellType::Args<Inspector::JSJavaScriptCallFrame>())
, jsModuleRecordHeapCellType(IsoHeapCellType::Args<JSModuleRecord>())
, syntheticModuleRecordHeapCellType(IsoHeapCellType::Args<SyntheticModuleRecord>())
, moduleNamespaceObjectHeapCellType(IsoHeapCellType::Args<JSModuleNamespaceObject>())
, nativeStdFunctionHeapCellType(IsoHeapCellType::Args<JSNativeStdFunction>())
, weakMapHeapCellType(IsoHeapCellType::Args<JSWeakMap>())
, weakSetHeapCellType(IsoHeapCellType::Args<JSWeakSet>())
#
if
JSC_OBJC_API_ENABLED
, apiWrapperObjectHeapCellType(IsoHeapCellType::Args<JSCallbackObject<JSAPIWrapperObject>>())
, objCCallbackFunctionHeapCellType(IsoHeapCellType::Args<ObjCCallbackFunction>())
#
endif
#
ifdef
JSC_GLIB_API_ENABLED
, apiWrapperObjectHeapCellType(IsoHeapCellType::Args<JSCallbackObject<JSAPIWrapperObject>>())
, callbackAPIWrapperGlobalObjectHeapCellType(IsoHeapCellType::Args<JSCallbackObject<JSAPIWrapperGlobalObject>>())
, jscCallbackFunctionHeapCellType(IsoHeapCellType::Args<JSCCallbackFunction>())
#
endif
, intlCollatorHeapCellType(IsoHeapCellType::Args<IntlCollator>())
, intlDateTimeFormatHeapCellType(IsoHeapCellType::Args<IntlDateTimeFormat>())
, intlDisplayNamesHeapCellType(IsoHeapCellType::Args<IntlDisplayNames>())
, intlDurationFormatHeapCellType(IsoHeapCellType::Args<IntlDurationFormat>())
, intlListFormatHeapCellType(IsoHeapCellType::Args<IntlListFormat>())
, intlLocaleHeapCellType(IsoHeapCellType::Args<IntlLocale>())
, intlNumberFormatHeapCellType(IsoHeapCellType::Args<IntlNumberFormat>())
, intlPluralRulesHeapCellType(IsoHeapCellType::Args<IntlPluralRules>())
, intlRelativeTimeFormatHeapCellType(IsoHeapCellType::Args<IntlRelativeTimeFormat>())
, intlSegmentIteratorHeapCellType(IsoHeapCellType::Args<IntlSegmentIterator>())
, intlSegmenterHeapCellType(IsoHeapCellType::Args<IntlSegmenter>())
, intlSegmentsHeapCellType(IsoHeapCellType::Args<IntlSegments>())
#
if
ENABLE(WEBASSEMBLY)
, webAssemblyExceptionHeapCellType(IsoHeapCellType::Args<JSWebAssemblyException>())
, webAssemblyFunctionHeapCellType(IsoHeapCellType::Args<WebAssemblyFunction>())
, webAssemblyGlobalHeapCellType(IsoHeapCellType::Args<JSWebAssemblyGlobal>())
, webAssemblyInstanceHeapCellType(IsoHeapCellType::Args<JSWebAssemblyInstance>())
, webAssemblyMemoryHeapCellType(IsoHeapCellType::Args<JSWebAssemblyMemory>())
, webAssemblyModuleHeapCellType(IsoHeapCellType::Args<JSWebAssemblyModule>())
, webAssemblyModuleRecordHeapCellType(IsoHeapCellType::Args<WebAssemblyModuleRecord>())
, webAssemblyTableHeapCellType(IsoHeapCellType::Args<JSWebAssemblyTable>())
, webAssemblyTagHeapCellType(IsoHeapCellType::Args<JSWebAssemblyTag>())
#
endif
//
AlignedMemoryAllocators
, fastMallocAllocator(makeUnique<FastMallocAlignedMemoryAllocator>())
, primitiveGigacageAllocator(makeUnique<GigacageAlignedMemoryAllocator>(Gigacage::Primitive))
//
Subspaces
, primitiveGigacageAuxiliarySpace(
"
Primitive Gigacage Auxiliary
"
_s, *
this
, auxiliaryHeapCellType, primitiveGigacageAllocator.get())
//
Hash:0x3e7cd762
, auxiliarySpace(
"
Auxiliary
"
_s, *
this
, auxiliaryHeapCellType, fastMallocAllocator.get())
//
Hash:0x96255ba1
, immutableButterflyAuxiliarySpace(
"
ImmutableButterfly JSCellWithIndexingHeader
"
_s, *
this
, immutableButterflyHeapCellType, fastMallocAllocator.get())
//
Hash:0xaadcb3c1
, cellSpace(
"
JSCell
"
_s, *
this
, cellHeapCellType, fastMallocAllocator.get())
//
Hash:0xadfb5a79
, destructibleObjectSpace(
"
JSDestructibleObject
"
_s, *
this
, destructibleObjectHeapCellType, fastMallocAllocator.get())
//
Hash:0x4f5ed7a9
FOR_EACH_JSC_COMMON_ISO_SUBSPACE
(
INIT_SERVER_ISO_SUBSPACE
)
FOR_EACH_JSC_STRUCTURE_ISO_SUBSPACE(
INIT_SERVER_STRUCTURE_ISO_SUBSPACE
)
, codeBlockSpaceAndSet ISO_SUBSPACE_INIT(*
this
, destructibleCellHeapCellType, CodeBlock)
//
Hash:0x2b743c6a
, functionExecutableSpaceAndSet ISO_SUBSPACE_INIT(*
this
, destructibleCellHeapCellType, FunctionExecutable)
//
Hash:0xbcb36268
, programExecutableSpaceAndSet ISO_SUBSPACE_INIT(*
this
, destructibleCellHeapCellType, ProgramExecutable)
//
Hash:0x4c9208f7
, unlinkedFunctionExecutableSpaceAndSet ISO_SUBSPACE_INIT(*
this
, destructibleCellHeapCellType, UnlinkedFunctionExecutable)
//
Hash:0x3ba0f4e1
{
if
(
Options::forceFencedBarrier
()) {
m_mutatorShouldBeFenced =
true
;
m_barrierThreshold = tautologicalThreshold;
}
m_worldState.
store
(
0
);
for
(
unsigned
i =
0
, numberOfParallelThreads =
heapHelperPool
().
numberOfThreads
(); i < numberOfParallelThreads; ++i) {
std::unique_ptr<SlotVisitor> visitor = makeUnique<SlotVisitor>(*
this
,
toCString
(
"
P
"
, i +
1
));
if
(
Options::optimizeParallelSlotVisitorsForStoppedMutator
())
visitor->
optimizeForStoppedMutator
();
m_availableParallelSlotVisitors.
append
(visitor.
get
());
m_parallelSlotVisitors.
append
(
WTF::move
(visitor));
}
if
(
Options::useConcurrentGC
()) {
if
(
Options::useStochasticMutatorScheduler
())
m_scheduler = makeUnique<StochasticSpaceTimeMutatorScheduler>(*
this
);
else
m_scheduler = makeUnique<SpaceTimeMutatorScheduler>(*
this
);
}
else
{
//
We simulate turning off concurrent GC by making the scheduler say that the world
//
should always be stopped when the collector is running.
m_scheduler = makeUnique<SynchronousStopTheWorldMutatorScheduler>();
}
if
(
Options::verifyHeap
())
m_verifier = makeUnique<HeapVerifier>(
this
,
Options::numberOfGCCyclesToRecordForVerification
());
m_collectorSlotVisitor->
optimizeForStoppedMutator
();
//
When memory is critical, allow allocating 25% of the amount above the critical threshold before collecting.
size_t
memoryAboveCriticalThreshold =
static_cast
<
size_t
>(
static_cast
<
double
>(m_ramSize) * (
1.0
-
Options::criticalGCMemoryThreshold
()));
m_maxEdenSizeWhenCritical = memoryAboveCriticalThreshold /
4
;
Locker locker { *m_threadLock };
lazyInitialize
(m_thread,
adoptRef
(*
new
HeapThread
(locker, *
this
)));
}
#
undef
INIT_SERVER_ISO_SUBSPACE
#
undef
INIT_SERVER_STRUCTURE_ISO_SUBSPACE
Heap::~Heap
()
{
//
Scribble m_worldState to make it clear that the heap has already been destroyed if we crash in checkConn
m_worldState.
store
(
0xbadbeeffu
);
forEachSlotVisitor
(
[&] (SlotVisitor& visitor) {
visitor.
clearMarkStacks
();
});
m_mutatorMarkStack->
clear
();
m_raceMarkStack->
clear
();
for
(WeakBlock* block : m_logicallyEmptyWeakBlocks)
WeakBlock::destroy
(*
this
, block);
}
bool
Heap::isPagedOut
()
{
return
m_objectSpace.
isPagedOut
();
}
void
Heap::dumpHeapStatisticsAtVMDestruction
()
{
unsigned
counter =
0
;
HeapIterationScope
iterationScope
(*
this
);
m_objectSpace.
forEachBlock
([&] (MarkedBlock::Handle* block) {
unsigned
live =
0
;
block->
forEachLiveCell
([&] (
size_t
, HeapCell*, HeapCell::Kind) {
live++;
return
IterationStatus::Continue;
});
dataLogLn
(
"
[
"
, counter++,
"
]
"
, block->
cellSize
(),
"
,
"
, live,
"
/
"
, block->
cellsPerBlock
(),
"
"
,
static_cast
<
double
>(live) / block->
cellsPerBlock
() *
100
,
"
%
"
, block->
attributes
(),
"
"
, block->
subspace
()->
name
());
block->
forEachLiveCell
([&] (
size_t
, HeapCell* heapCell, HeapCell::Kind kind) {
if
(kind == HeapCell::Kind::JSCell) {
auto
* cell =
static_cast
<JSCell*>(heapCell);
if
(cell->
isObject
())
dataLogLn
(
"
"
,
JSValue
((JSObject*)cell));
else
dataLogLn
(
"
"
, *cell);
}
return
IterationStatus::Continue;
});
});
}
//
The VM is being destroyed and the collector will never run again.
//
Run all pending finalizers now because we won't get another chance.
void
Heap::lastChanceToFinalize
()
{
MonotonicTime before;
if
(
Options::logGC
())
[[unlikely]]
{
before =
MonotonicTime::now
();
dataLog
(
"
[GC<
"
,
RawPointer
(
this
),
"
>: shutdown
"
);
}
m_isShuttingDown =
true
;
RELEASE_ASSERT
(!
vm
().
entryScope
);
RELEASE_ASSERT
(m_mutatorState == MutatorState::Running);
if
(m_collectContinuouslyThread) {
{
Locker locker { m_collectContinuouslyLock };
m_shouldStopCollectingContinuously =
true
;
m_collectContinuouslyCondition.
notifyOne
();
}
m_collectContinuouslyThread->
waitForCompletion
();
}
dataLogIf
(
Options::logGC
(),
"
1
"
);
//
Prevent new collections from being started. This is probably not even necessary, since we're not
//
going to call into anything that starts collections. Still, this makes the algorithm more
//
obviously sound.
m_isSafeToCollect =
false
;
dataLogIf
(
Options::logGC
(),
"
2
"
);
bool
isCollecting;
{
Locker locker { *m_threadLock };
RELEASE_ASSERT
(m_lastServedTicket <= m_lastGrantedTicket);
isCollecting = m_lastServedTicket < m_lastGrantedTicket;
}
if
(isCollecting) {
dataLogIf
(
Options::logGC
(),
"
...]
\n
"
);
//
Wait for the current collection to finish.
waitForCollector
(
[&] (
const
AbstractLocker&) ->
bool
{
RELEASE_ASSERT
(m_lastServedTicket <= m_lastGrantedTicket);
return
m_lastServedTicket == m_lastGrantedTicket;
});
dataLogIf
(
Options::logGC
(),
"
[GC<
"
,
RawPointer
(
this
),
"
>: shutdown
"
);
}
dataLogIf
(
Options::logGC
(),
"
3
"
);
RELEASE_ASSERT
(m_requests.
isEmpty
());
RELEASE_ASSERT
(m_lastServedTicket == m_lastGrantedTicket);
//
Carefully bring the thread down.
bool
stopped =
false
;
{
Locker locker { *m_threadLock };
stopped = m_thread->
tryStop
(locker);
m_threadShouldStop =
true
;
if
(!stopped)
m_threadCondition->
notifyOne
(locker);
}
dataLogIf
(
Options::logGC
(),
"
4
"
);
if
(!stopped)
m_thread->
join
();
dataLogIf
(
Options::logGC
(),
"
5
"
);
if
(
Options::dumpHeapStatisticsAtVMDestruction
())
[[unlikely]]
dumpHeapStatisticsAtVMDestruction
();
m_arrayBuffers.
lastChanceToFinalize
();
m_objectSpace.
lastChanceToFinalize
();
releaseDelayedReleasedObjects
();
#
if
ENABLE(WEBASSEMBLY)
Wasm::TypeInformation::cleanupIfRequested
();
#
endif
sweepAllLogicallyEmptyWeakBlocks
();
m_objectSpace.
freeMemory
();
dataLogIf
(
Options::logGC
(), (
MonotonicTime::now
() - before).
milliseconds
(),
"
ms]
\n
"
);
}
void
Heap::releaseDelayedReleasedObjects
()
{
#
if
USE(FOUNDATION) || defined(JSC_GLIB_API_ENABLED)
//
We need to guard against the case that releasing an object can create more objects due to the
//
release calling into JS. When those JS call(s) exit and all locks are being dropped we end up
//
back here and could try to recursively release objects. We guard that with a recursive entry
//
count. Only the initial call will release objects, recursive calls simple return and let the
//
the initial call to the function take care of any objects created during release time.
//
This also means that we need to loop until there are no objects in m_delayedReleaseObjects
//
and use a temp Vector for the actual releasing.
if
(!m_delayedReleaseRecursionCount++) {
while
(!m_delayedReleaseObjects.
isEmpty
()) {
ASSERT
(
vm
().
currentThreadIsHoldingAPILock
());
auto
objectsToRelease =
WTF::move
(m_delayedReleaseObjects);
{
//
We need to drop locks before calling out to arbitrary code.
JSLock::DropAllLocks
dropAllLocks
(
vm
());
#
if
USE(FOUNDATION)
void
* context =
objc_autoreleasePoolPush
();
#
endif
objectsToRelease.
clear
();
#
if
USE(FOUNDATION)
objc_autoreleasePoolPop
(context);
#
endif
}
}
}
m_delayedReleaseRecursionCount--;
#
endif
}
void
Heap::reportExtraMemoryAllocatedPossiblyFromAlreadyMarkedCell
(
const
JSCell* cell,
size_t
size)
{
ASSERT
(cell);
//
Increasing extraMemory of already marked objects will not be visible as a retained memory.
//
We need to report this additionally to tell GC that we get additional extra memory now,
//
and GC needs to consider scheduling GC based on this increase.
if
(
mutatorShouldBeFenced
())
[[unlikely]]
{
//
In this case, the barrierThreshold is the tautological threshold, so cell could still be
//
not black. But we can't know for sure until we fire off a fence.
WTF::storeLoadFence
();
if
(cell->
cellState
() != CellState::PossiblyBlack)
return
;
WTF::loadLoadFence
();
if
(!
isMarked
(cell)) {
//
During a full collection a store into an unmarked object that had surivived past
//
collections will manifest as a store to an unmarked PossiblyBlack object. If the
//
object gets marked at some time after this then it will go down the normal marking
//
path. So, we don't have to remember this object. We could return here. But we go
//
further and attempt to re-white the object.
ASSERT
(m_collectionScope && m_collectionScope.
value
() == CollectionScope::Full);
return
;
}
}
else
ASSERT
(
isMarked
(cell));
//
It could be that the object was *just* marked. This means that the collector may set the
//
state to DefinitelyGrey and then to PossiblyOldOrBlack at any time. It's OK for us to
//
race with the collector here. If we win then this is accurate because the object _will_
//
get scanned again. If we lose then someone else will barrier the object again. That would
//
be unfortunate but not the end of the world.
reportExtraMemoryVisited
(size);
}
void
Heap::reportExtraMemoryAllocatedSlowCase
(GCDeferralContext* deferralContext,
const
JSCell* cell,
size_t
size)
{
didAllocate
(size);
if
(cell) {
if
(
isWithinThreshold
(cell->
cellState
(),
barrierThreshold
()))
[[unlikely]]
reportExtraMemoryAllocatedPossiblyFromAlreadyMarkedCell
(cell, size);
}
collectIfNecessaryOrDefer
(deferralContext);
}
void
Heap::deprecatedReportExtraMemorySlowCase
(
size_t
size)
{
//
FIXME: Change this to use SaturatingArithmetic when available.
//
https://bugs.webkit.org/show_bug.cgi?id=170411
CheckedSize checkedNewSize = m_deprecatedExtraMemorySize;
checkedNewSize += size;
size_t
newSize = std::numeric_limits<
size_t
>::
max
();
if
(!checkedNewSize.
hasOverflowed
())
[[likely]]
newSize = checkedNewSize.
value
();
m_deprecatedExtraMemorySize = newSize;
reportExtraMemoryAllocatedSlowCase
(
nullptr
,
nullptr
, size);
}
bool
Heap::overCriticalMemoryThreshold
(MemoryThresholdCallType memoryThresholdCallType)
{
#
if
USE(MEMORY_FOOTPRINT_API)
if
(memoryThresholdCallType == MemoryThresholdCallType::Direct || ++m_percentAvailableMemoryCachedCallCount >=
100
) {
m_overCriticalMemoryThreshold =
WTF::percentAvailableMemoryInUse
() >
Options::criticalGCMemoryThreshold
();
m_percentAvailableMemoryCachedCallCount =
0
;
}
return
m_overCriticalMemoryThreshold;
#
else
UNUSED_PARAM
(memoryThresholdCallType);
return
false
;
#
endif
}
void
Heap::reportAbandonedObjectGraph
()
{
//
Our clients don't know exactly how much memory they
//
are abandoning so we just guess for them.
size_t
abandonedBytes =
static_cast
<
size_t
>(
0.1
*
capacity
());
m_bytesAbandonedSinceLastFullCollect += abandonedBytes;
//
We want to accelerate the next collection. Because memory has just
//
been abandoned, the next collection has the potential to
//
be more profitable. Since allocation is the trigger for collection,
//
we hasten the next collection by pretending that we've allocated more memory.
if
(m_fullActivityCallback) {
m_fullActivityCallback->
didAllocate
(*
this
,
m_sizeAfterLastCollect - m_sizeAfterLastFullCollect +
totalBytesAllocatedThisCycle
() + m_bytesAbandonedSinceLastFullCollect);
}
}
void
Heap::protect
(JSValue k)
{
ASSERT
(k);
ASSERT
(
vm
().
currentThreadIsHoldingAPILock
());
if
(!k.
isCell
())
return
;
m_protectedValues.
add
(k.
asCell
());
}
bool
Heap::unprotect
(JSValue k)
{
ASSERT
(k);
ASSERT
(
vm
().
currentThreadIsHoldingAPILock
());
if
(!k.
isCell
())
return
false
;
return
m_protectedValues.
remove
(k.
asCell
());
}
void
Heap::addReference
(JSCell* cell, ArrayBuffer* buffer)
{
if
(m_arrayBuffers.
addReference
(cell, buffer)) {
collectIfNecessaryOrDefer
();
didAllocate
(buffer->
gcSizeEstimateInBytes
());
}
}
template
<
typename
CellType,
typename
CellSet>
void
Heap::reconcileWeakReferencesInMarkedCells
(CellSet& cellSet, CollectionScope collectionScope)
{
cellSet.
forEachMarkedCell
(
[&] (HeapCell* cell, HeapCell::Kind) {
static_cast
<CellType*>(cell)->
reconcileWeakReferencesAtGCEnd
(
vm
(), collectionScope);
});
}
//
Weak reference reconciliation: settle every untraced pointer against the liveness that
//
marking just established. Must run after marking, because isMarked() only means "dead"
//
once the closure is complete, and before sweeping, because a dying referent may still
//
need to be identified or read.
void
Heap::reconcileWeakReferencesAtGCEnd
()
{
CollectionScope collectionScope =
this
->
collectionScope
().
value_or
(CollectionScope::Full);
{
//
Executables go before CodeBlock, since CodeBlock::reconcileWeakReferencesAtGCEnd looks at the owner executable's installed CodeBlock.
//
FunctionExecutable requires all live instances to be processed, so iterate the whole space rather than a tracking set.
reconcileWeakReferencesInMarkedCells<FunctionExecutable>(functionExecutableSpaceAndSet.
space
, collectionScope);
reconcileWeakReferencesInMarkedCells<ProgramExecutable>(programExecutableSpaceAndSet.
weakReconciliationSet
, collectionScope);
if
(m_evalExecutableSpace)
reconcileWeakReferencesInMarkedCells<EvalExecutable>(m_evalExecutableSpace->
weakReconciliationSet
, collectionScope);
if
(m_moduleProgramExecutableSpace)
reconcileWeakReferencesInMarkedCells<ModuleProgramExecutable>(m_moduleProgramExecutableSpace->
weakReconciliationSet
, collectionScope);
}
reconcileWeakReferencesInMarkedCells<SymbolTable>(symbolTableSpace, collectionScope);
forEachCodeBlockSpace
(
[&] (
auto
& space) {
this
->
reconcileWeakReferencesInMarkedCells
<CodeBlock>(space.
set
, collectionScope);
});
if
(collectionScope == CollectionScope::Full) {
reconcileWeakReferencesInMarkedCells<Structure>(structureSpace, collectionScope);
reconcileWeakReferencesInMarkedCells<BrandedStructure>(brandedStructureSpace, collectionScope);
#
if
ENABLE(WEBASSEMBLY)
reconcileWeakReferencesInMarkedCells<WebAssemblyGCStructure>(webAssemblyGCStructureSpace, collectionScope);
#
endif
}
reconcileWeakReferencesInMarkedCells<StructureRareData>(structureRareDataSpace, collectionScope);
reconcileWeakReferencesInMarkedCells<UnlinkedFunctionExecutable>(unlinkedFunctionExecutableSpaceAndSet.
set
, collectionScope);
if
(m_weakSetSpace)
reconcileWeakReferencesInMarkedCells<JSWeakSet>(*m_weakSetSpace, collectionScope);
if
(m_weakMapSpace)
reconcileWeakReferencesInMarkedCells<JSWeakMap>(*m_weakMapSpace, collectionScope);
if
(m_weakObjectRefSpace)
reconcileWeakReferencesInMarkedCells<JSWeakObjectRef>(*m_weakObjectRefSpace, collectionScope);
if
(m_errorInstanceSpace)
reconcileWeakReferencesInMarkedCells<ErrorInstance>(*m_errorInstanceSpace, collectionScope);
//
FinalizationRegistries currently rely on serial finalization because they can post tasks to the deferredWorkTimer, which normally expects tasks to only be posted by the API lock holder.
if
(m_finalizationRegistrySpace)
reconcileWeakReferencesInMarkedCells<JSFinalizationRegistry>(*m_finalizationRegistrySpace, collectionScope);
#
if
ENABLE(WEBASSEMBLY)
if
(m_webAssemblyInstanceSpace)
reconcileWeakReferencesInMarkedCells<JSWebAssemblyInstance>(*m_webAssemblyInstanceSpace, collectionScope);
#
endif
vm
().
reconcileWeakReferencesAtGCEnd
();
}
void
Heap::willStartIterating
()
{
m_objectSpace.
willStartIterating
();
}
void
Heap::didFinishIterating
()
{
m_objectSpace.
didFinishIterating
();
}
void
Heap::completeAllJITPlans
()
{
if
(!
Options::useJIT
())
return
;
#
if
ENABLE(JIT)
JITWorklist::ensureGlobalWorklist
().
completeAllPlansForVM
(
vm
());
#
endif
//
ENABLE(JIT)
}
template
<
typename
Visitor>
void
Heap::iterateExecutingAndCompilingCodeBlocks
(Visitor& visitor,
NOESCAPE
const
Function<
void
(CodeBlock*)>& func)
{
m_codeBlocks->
iterateCurrentlyExecuting
(func);
#
if
ENABLE(JIT)
if
(
Options::useJIT
())
JITWorklist::ensureGlobalWorklist
().
iterateCodeBlocksForGC
(visitor,
vm
(), func);
#
else
UNUSED_PARAM
(visitor);
#
endif
//
ENABLE(JIT)
}
template
<
typename
Func,
typename
Visitor>
void
Heap::iterateExecutingAndCompilingCodeBlocksWithoutHoldingLocks
(Visitor& visitor,
const
Func& func)
{
Vector<CodeBlock*,
256
> codeBlocks;
iterateExecutingAndCompilingCodeBlocks
(visitor,
[&] (CodeBlock* codeBlock) {
codeBlocks.
append
(codeBlock);
});
for
(CodeBlock* codeBlock : codeBlocks)
func
(codeBlock);
}
void
Heap::assertMarkStacksEmpty
()
{
bool
ok =
true
;
if
(!m_sharedCollectorMarkStack->
isEmpty
()) {
dataLog
(
"
FATAL: Shared collector mark stack not empty! It has
"
, m_sharedCollectorMarkStack->
size
(),
"
elements.
\n
"
);
ok =
false
;
}
if
(!m_sharedMutatorMarkStack->
isEmpty
()) {
dataLog
(
"
FATAL: Shared mutator mark stack not empty! It has
"
, m_sharedMutatorMarkStack->
size
(),
"
elements.
\n
"
);
ok =
false
;
}
forEachSlotVisitor
(
[&] (SlotVisitor& visitor) {
if
(visitor.
isEmpty
())
return
;
dataLog
(
"
FATAL: Visitor
"
,
RawPointer
(&visitor),
"
is not empty!
\n
"
);
ok =
false
;
});
RELEASE_ASSERT
(ok);
}
void
Heap::gatherStackRoots
(ConservativeRoots& roots)
{
m_machineThreads->
gatherConservativeRoots
(roots, *m_jitStubRoutines, *m_codeBlocks, m_currentThreadState, m_currentThread);
#
if
ENABLE(C_LOOP)
vm
().
cloopStack
().
gatherConservativeRoots
(roots, *m_jitStubRoutines, *m_codeBlocks);
#
endif
}
void
Heap::gatherVMRoots
(ConservativeRoots& roots)
{
VM
& vm =
this
->
vm
();
#
if
ENABLE(DFG_JIT)
if
(
Options::useJIT
()) {
vm.
gatherScratchBufferRoots
(roots);
vm.
scanSideState
(roots);
}
#
endif
#
if
!ENABLE(DFG_JIT)
UNUSED_PARAM
(roots);
UNUSED_VARIABLE
(vm);
#
endif
}
void
Heap::beginMarking
()
{
TimingScope
timingScope
(*
this
,
"
Heap::beginMarking
"
_s);
m_jitStubRoutines->
clearMarks
();
m_objectSpace.
beginMarking
();
vm
().
beginMarking
();
setMutatorShouldBeFenced
(
true
);
}
void
Heap::removeDeadCompilerWorklistEntries
()
{
if
(!
Options::useJIT
())
return
;
#
if
ENABLE(JIT)
JITWorklist::ensureGlobalWorklist
().
removeDeadPlans
(
vm
());
#
endif
//
ENABLE(JIT)
}
struct
GatherExtraHeapData
: MarkedBlock::CountFunctor {
GatherExtraHeapData
(HeapAnalyzer& analyzer)
: m_analyzer(analyzer)
{
}
IterationStatus
operator
()(HeapCell* heapCell, HeapCell::Kind kind)
const
{
if
(
isJSCellKind
(kind)) {
JSCell* cell =
static_cast
<JSCell*>(heapCell);
cell->
methodTable
()->
analyzeHeap
(cell, m_analyzer);
}
return
IterationStatus::Continue;
}
HeapAnalyzer& m_analyzer;
};
void
Heap::gatherExtraHeapData
(HeapProfiler& heapProfiler)
{
if
(
auto
* analyzer = heapProfiler.
activeHeapAnalyzer
()) {
HeapIterationScope
heapIterationScope
(*
this
);
GatherExtraHeapData
functor
(*analyzer);
m_objectSpace.
forEachLiveCell
(heapIterationScope, functor);
}
}
struct
RemoveDeadHeapSnapshotNodes
: MarkedBlock::CountFunctor {
RemoveDeadHeapSnapshotNodes
(HeapSnapshot& snapshot)
: m_snapshot(snapshot)
{
}
IterationStatus
operator
()(HeapCell* cell, HeapCell::Kind kind)
const
{
if
(
isJSCellKind
(kind))
m_snapshot.
sweepCell
(
static_cast
<JSCell*>(cell));
return
IterationStatus::Continue;
}
HeapSnapshot& m_snapshot;
};
void
Heap::removeDeadHeapSnapshotNodes
(HeapProfiler& heapProfiler)
{
if
(HeapSnapshot* snapshot = heapProfiler.
mostRecentSnapshot
()) {
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL