Skip to content

Commit 4f97164

Browse files
committed
[JSC] Remove friend declarations Heap and Collector no longer need
https://bugs.webkit.org/show_bug.cgi?id=328127 rdar://190469351 Reviewed by Vassili Bykov. Many of Heap's friends reach nothing private, or reach one member that a public accessor can provide. Unneeded friendships hide which parts of Heap other classes actually use, so remove them. Collector drops CollectorThread, a nested class that already has access. Heap drops 14 friends. These reach nothing private: JIT, DFG::SpeculativeJIT, CodeBlock, GCLogging, HeapUtil, JITStubRoutine, LLIntOffsetsExtractor, BlockDirectory, MarkedBlock, IncrementalSweeper, and GCThread, which no longer exists. These now use public accessors: - HeapVerifier uses objectSpace() and verifier(). - GCAwareJITStubRoutine registers itself through the new addGCAwareJITStubRoutine(). It replaces jitStubRoutines(), which nothing called and which exposed the whole set. - ConservativeRoots reports the strings it finds on a stack through the new noteStringFoundOnStack(), instead of reaching into how Heap keeps swapped-out string buffers alive. The set is renamed m_stringsFoundOnStack, since it holds every such string, not only those a GCOwnedDataScope reads. Where the collection epilogue uses it, a comment now says why dropping those buffers is safe: the set conservatively covers GCOwnedDataScopes, and the collection parked compiler threads at a safepoint. No behavior change. * Source/JavaScriptCore/heap/Collector.h: * Source/JavaScriptCore/heap/ConservativeRoots.cpp: (JSC::ConservativeRoots::genericAddPointer): * Source/JavaScriptCore/heap/Heap.cpp: (JSC::Heap::addGCAwareJITStubRoutine): (JSC::Heap::runCollectionEpilogue): * Source/JavaScriptCore/heap/Heap.h: (JSC::Heap::jitStubRoutines): Deleted. (JSC::Heap::noteStringFoundOnStack): * Source/JavaScriptCore/jit/GCAwareJITStubRoutine.cpp: (JSC::GCAwareJITStubRoutine::makeGCAware): * Source/JavaScriptCore/tools/HeapVerifier.cpp: (JSC::HeapVerifier::gatherLiveCells): (JSC::HeapVerifier::checkIfRecorded): Canonical link: https://commits.webkit.org/324279@main
1 parent a5ab322 commit 4f97164

6 files changed

Lines changed: 19 additions & 25 deletions

File tree

‎Source/JavaScriptCore/heap/Collector.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ class Collector {
121121

122122
private:
123123
class CollectorThread;
124-
friend class CollectorThread;
125124
friend class Heap;
126125
friend class MarkStackMergingConstraint;
127126
friend class SlotVisitor;

‎Source/JavaScriptCore/heap/ConservativeRoots.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ inline void ConservativeRoots::genericAddPointer(char* pointer, HeapVersion mark
167167
// Since we're looking for strings we only need to check if we know we're not looking at an allocation with an IndexingHeader.
168168
// FIXME: If we wanted to make this more performant we could have a JSString HeapCell::Kind or embed the JSType in the MarkedBlock::Handle.
169169
if (auto* string = dynamicDowncast<const JSString>(std::bit_cast<const JSCell*>(pointer)))
170-
m_heap.m_discoveredAccessedStringsFromGCOwnedDataScope.add(string);
170+
m_heap.noteStringFoundOnStack(string);
171171
return true;
172172
}
173173
return false;

‎Source/JavaScriptCore/heap/Heap.cpp‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,11 @@ bool Heap::unprotect(JSValue k)
650650
return m_protectedValues.remove(k.asCell());
651651
}
652652

653+
void Heap::addGCAwareJITStubRoutine(GCAwareJITStubRoutine* routine)
654+
{
655+
m_jitStubRoutines->add(routine);
656+
}
657+
653658
void Heap::addReference(JSCell* cell, ArrayBuffer* buffer)
654659
{
655660
ASSERT(cell->heap() == this);
@@ -1717,10 +1722,12 @@ void Heap::runCollectionEpilogue()
17171722
cache->clear();
17181723
vm().jsonCache().clearJSStrings();
17191724

1725+
// Drop the old buffers of strings no stack refers to. No GCOwnedDataScope can be reading them, and a
1726+
// compiler thread that read one has since stopped at a safepoint, so it no longer holds it.
17201727
m_possiblyAccessedStringsFromConcurrentThreadsOrGCOwnedDataScope.removeAllMatching([&](const auto& iter) {
1721-
return !m_discoveredAccessedStringsFromGCOwnedDataScope.contains(iter.first);
1728+
return !m_stringsFoundOnStack.contains(iter.first);
17221729
});
1723-
m_discoveredAccessedStringsFromGCOwnedDataScope.clear();
1730+
m_stringsFoundOnStack.clear();
17241731

17251732
immutableButterflyToStringCache.clear();
17261733

‎Source/JavaScriptCore/heap/Heap.h‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ class HeapUtil;
324324
class Heap {
325325
WTF_MAKE_NONCOPYABLE(Heap);
326326
public:
327-
friend class JIT;
328-
friend class DFG::SpeculativeJIT;
329327
static JSC::Heap* heap(const JSValue); // 0 for immediate values
330328
static JSC::Heap* heap(const HeapCell*);
331329

@@ -499,7 +497,9 @@ class Heap {
499497

500498
JS_EXPORT_PRIVATE void didAllocate(size_t);
501499

502-
const JITStubRoutineSet& jitStubRoutines() { return *m_jitStubRoutines; }
500+
void addGCAwareJITStubRoutine(GCAwareJITStubRoutine*);
501+
502+
void noteStringFoundOnStack(const JSString* string) { m_stringsFoundOnStack.add(string); }
503503

504504
void addReference(JSCell*, ArrayBuffer*);
505505

@@ -634,27 +634,15 @@ class Heap {
634634

635635
private:
636636
friend class AllocatingScope;
637-
friend class CodeBlock;
638637
friend class CollectingScope;
639638
friend class Collector;
640-
friend class ConservativeRoots;
641639
friend class DeferGC;
642640
friend class DeferGCForAWhile;
643-
friend class GCAwareJITStubRoutine;
644-
friend class GCLogging;
645-
friend class GCThread;
646-
friend class HeapUtil;
647-
friend class HeapVerifier;
648-
friend class JITStubRoutine;
649-
friend class LLIntOffsetsExtractor;
650641
friend class MarkStackMergingConstraint;
651642
friend class MarkedSpace;
652-
friend class BlockDirectory;
653-
friend class MarkedBlock;
654643
friend class RunningScope;
655644
friend class SlotVisitor;
656645
friend class SweepingScope;
657-
friend class IncrementalSweeper;
658646
friend class VM;
659647
friend class WeakBlock;
660648
friend class WeakSet;
@@ -896,7 +884,7 @@ class Heap {
896884
// Since this list is walked once to deref all the strings
897885
// We don't need fast access.
898886
SegmentedVector<std::pair<const JSString*, String>, 256, 10, SegmentedVectorGrowthPolicy::Doubling> m_possiblyAccessedStringsFromConcurrentThreadsOrGCOwnedDataScope;
899-
UncheckedKeyHashSet<const JSString*> m_discoveredAccessedStringsFromGCOwnedDataScope;
887+
UncheckedKeyHashSet<const JSString*> m_stringsFoundOnStack;
900888

901889
RefPtr<GCActivityCallback> m_fullActivityCallback;
902890
RefPtr<GCActivityCallback> m_edenActivityCallback;

‎Source/JavaScriptCore/jit/GCAwareJITStubRoutine.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ GCAwareJITStubRoutine::GCAwareJITStubRoutine(Type type, const MacroAssemblerCode
4949

5050
void GCAwareJITStubRoutine::makeGCAware(VM& vm)
5151
{
52-
vm.heap.m_jitStubRoutines->add(this);
52+
vm.heap.addGCAwareJITStubRoutine(this);
5353
m_isGCAware = true;
5454
}
5555

‎Source/JavaScriptCore/tools/HeapVerifier.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void HeapVerifier::gatherLiveCells(HeapVerifier::Phase phase)
9292
CellList& list = *cellListForGathering(phase);
9393

9494
list.reset();
95-
heap->m_objectSpace.forEachLiveCell([&list] (HeapCell* cell, HeapCell::Kind kind) {
95+
heap->objectSpace().forEachLiveCell([&list](HeapCell* cell, HeapCell::Kind kind) {
9696
list.add({ cell, kind, CellProfile::Live });
9797
return IterationStatus::Continue;
9898
});
@@ -446,10 +446,10 @@ void HeapVerifier::checkIfRecorded(uintptr_t candidateCell)
446446
if (!vm.isInService())
447447
return IterationStatus::Continue;
448448

449-
if (!vm.heap.m_verifier)
449+
auto* verifier = vm.heap.verifier();
450+
if (!verifier)
450451
return IterationStatus::Continue;
451-
452-
auto* verifier = vm.heap.m_verifier.get();
452+
453453
dataLog("Search for cell ", RawPointer(candidateHeapCell), " in VM ", RawPointer(&vm), ":\n");
454454
verifier->checkIfRecorded(candidateHeapCell);
455455
return IterationStatus::Continue;

0 commit comments

Comments
 (0)