Skip to content

Commit 27959d8

Browse files
committed
Introduce compile-time checking and alternate allocation for compact pointer types
https://bugs.webkit.org/show_bug.cgi?id=266080 rdar://119382681 Reviewed by Mark Lam. Adds compile-time checking to WTF compact and packed pointer types requiring the pointed-to types to be explicitly marked as compatible with compact pointers. Also adds new equivalents to the existing WTF::fastMalloc and WTF::isoMalloc allocation functions for compactible types, giving us an API point to play with how types used in compact pointers are allocated. * Source/JavaScriptCore/bytecode/CallLinkInfoBase.h: * Source/JavaScriptCore/bytecode/CodeBlock.h: * Source/JavaScriptCore/bytecode/InlineCallFrame.h: * Source/JavaScriptCore/bytecode/InlineCallFrameSet.h: * Source/JavaScriptCore/bytecode/StructureStubClearingWatchpoint.h: * Source/JavaScriptCore/bytecode/Watchpoint.h: * Source/JavaScriptCore/dfg/DFGJITCode.h: * Source/JavaScriptCore/heap/FastMallocAlignedMemoryAllocator.cpp: * Source/JavaScriptCore/heap/IsoAlignedMemoryAllocator.cpp: * Source/JavaScriptCore/jit/BaselineJITCode.h: * Source/JavaScriptCore/jit/ExecutableMemoryHandle.h: * Source/JavaScriptCore/jit/JITCode.h: * Source/JavaScriptCore/jit/PolymorphicCallStubRoutine.h: * Source/JavaScriptCore/runtime/ClassInfo.h: * Source/JavaScriptCore/runtime/JSArray.h: * Source/JavaScriptCore/wasm/WasmTypeDefinition.h: * Source/WTF/wtf/Bag.h: * Source/WTF/wtf/CompactPointerTuple.h: * Source/WTF/wtf/CompactPtr.h: * Source/WTF/wtf/DebugHeap.h: * Source/WTF/wtf/FastMalloc.cpp: * Source/WTF/wtf/FastMalloc.h: * Source/WTF/wtf/IsoMalloc.h: * Source/WTF/wtf/IsoMallocInlines.h: * Source/WTF/wtf/SentinelLinkedList.h: * Source/WTF/wtf/WeakPtr.h: * Source/WTF/wtf/text/StringImpl.h: * Source/WTF/wtf/text/WTFString.h: * Source/WebCore/dom/Node.h: * Source/WebCore/dom/NodeRareData.h: * Source/WebCore/rendering/RenderObject.cpp: * Source/WebCore/rendering/RenderObject.h: * Source/bmalloc/bmalloc/AllocationCounts.h: * Source/bmalloc/bmalloc/IsoHeap.cpp: * Source/bmalloc/bmalloc/IsoHeap.h: * Source/bmalloc/bmalloc/IsoHeapImpl.h: * Source/bmalloc/bmalloc/IsoHeapInlines.h: * Source/bmalloc/bmalloc/Packed.h: * Tools/TestWebKitAPI/Tests/WTF/AlignedRefLogger.h: * Tools/TestWebKitAPI/Tests/WTF/CompactRefPtr.cpp: * Tools/TestWebKitAPI/Tests/WTF/CompactUniquePtrTuple.cpp: * Tools/TestWebKitAPI/Tests/WTF/RefLogger.h: Canonical link: https://commits.webkit.org/271796@main
1 parent e171a19 commit 27959d8

52 files changed

Lines changed: 693 additions & 145 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Source/JavaScriptCore/bytecode/CallLinkInfoBase.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace JSC {
3131

3232
class VM;
3333

34-
class CallLinkInfoBase : public PackedRawSentinelNode<CallLinkInfoBase> {
34+
class CallLinkInfoBase : public BasicRawSentinelNode<CallLinkInfoBase> {
3535
public:
3636
enum class CallSiteType : uint8_t {
3737
CallLinkInfo,

‎Source/JavaScriptCore/bytecode/CodeBlock.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ class CodeBlock : public JSCell {
952952
VM* const m_vm;
953953

954954
const void* const m_instructionsRawPointer { nullptr };
955-
SentinelLinkedList<CallLinkInfoBase, PackedRawSentinelNode<CallLinkInfoBase>> m_incomingCalls;
955+
SentinelLinkedList<CallLinkInfoBase, BasicRawSentinelNode<CallLinkInfoBase>> m_incomingCalls;
956956
uint16_t m_optimizationDelayCounter { 0 };
957957
uint16_t m_reoptimizationRetryCounter { 0 };
958958
StructureWatchpointMap m_llintGetByIdWatchpointMap;

‎Source/JavaScriptCore/bytecode/InlineCallFrame.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ struct InlineCallFrame;
4040
class CallFrame;
4141
class JSFunction;
4242

43+
DECLARE_COMPACT_ALLOCATOR_WITH_HEAP_IDENTIFIER(InlineCallFrame);
44+
4345
struct InlineCallFrame {
46+
WTF_MAKE_STRUCT_FAST_COMPACT_ALLOCATED_WITH_HEAP_IDENTIFIER(InlineCallFrame);
47+
4448
enum Kind {
4549
Call,
4650
Construct,

‎Source/JavaScriptCore/bytecode/InlineCallFrameSet.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ class InlineCallFrameSet : public RefCounted<InlineCallFrameSet> {
4141

4242
InlineCallFrame* add();
4343

44-
typedef Bag<InlineCallFrame>::iterator iterator;
44+
using FrameBag = Bag<InlineCallFrame, RawPtrTraits<InlineCallFrame>, InlineCallFrameMalloc>;
45+
typedef FrameBag::iterator iterator;
4546
iterator begin() { return m_frames.begin(); }
4647
iterator end() { return m_frames.end(); }
4748

4849
private:
49-
Bag<InlineCallFrame> m_frames;
50+
FrameBag m_frames;
5051
};
5152

5253
} // namespace JSC

‎Source/JavaScriptCore/bytecode/StructureStubClearingWatchpoint.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class StructureTransitionStructureStubClearingWatchpoint final : public Watchpoi
5454
void fireInternal(VM&, const FireDetail&);
5555

5656
private:
57-
PackedPtr<WatchpointsOnStructureStubInfo> m_holder;
57+
WatchpointsOnStructureStubInfo* m_holder;
5858
ObjectPropertyCondition m_key;
5959
};
6060

@@ -75,7 +75,7 @@ class AdaptiveValueStructureStubClearingWatchpoint final : public AdaptiveInferr
7575

7676

7777
private:
78-
PackedPtr<WatchpointsOnStructureStubInfo> m_holder;
78+
WatchpointsOnStructureStubInfo* m_holder;
7979
};
8080

8181
class WatchpointsOnStructureStubInfo final {

‎Source/JavaScriptCore/bytecode/Watchpoint.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class WatchpointSet;
111111

112112
DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(Watchpoint);
113113

114-
class Watchpoint : public PackedRawSentinelNode<Watchpoint> {
114+
class Watchpoint : public BasicRawSentinelNode<Watchpoint> {
115115
WTF_MAKE_NONCOPYABLE(Watchpoint);
116116
WTF_MAKE_NONMOVABLE(Watchpoint);
117117
WTF_MAKE_STRUCT_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(Watchpoint);
@@ -274,7 +274,7 @@ class WatchpointSet : public ThreadSafeRefCounted<WatchpointSet> {
274274
int8_t m_state;
275275
int8_t m_setIsNotEmpty;
276276

277-
SentinelLinkedList<Watchpoint, PackedRawSentinelNode<Watchpoint>> m_set;
277+
SentinelLinkedList<Watchpoint, BasicRawSentinelNode<Watchpoint>> m_set;
278278
};
279279

280280
// InlineWatchpointSet is a low-overhead, non-copyable watchpoint set in which

‎Source/JavaScriptCore/dfg/DFGJITCode.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class LinkerIR {
9494
public:
9595
using Constant = unsigned;
9696

97-
enum class Type : uint16_t {
97+
enum class Type : uint8_t {
9898
Invalid,
9999
CallLinkInfo,
100100
CellPointer,
@@ -115,12 +115,12 @@ class LinkerIR {
115115
ObjectPrototypeChainIsSaneWatchpointSet,
116116
};
117117

118-
using Value = CompactPointerTuple<void*, Type>;
118+
using Value = JITConstant<Type>;
119119

120120
struct ValueHash {
121121
static unsigned hash(const Value& p)
122122
{
123-
return computeHash(p.type(), p.pointer());
123+
return p.hash();
124124
}
125125

126126
static bool equal(const Value& a, const Value& b)

‎Source/JavaScriptCore/heap/FastMallocAlignedMemoryAllocator.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void* FastMallocAlignedMemoryAllocator::tryAllocateAlignedMemory(size_t alignmen
4646
#if ENABLE(MALLOC_HEAP_BREAKDOWN)
4747
return m_heap.memalign(alignment, size, true);
4848
#else
49-
return tryFastAlignedMalloc(alignment, size);
49+
return tryFastCompactAlignedMalloc(alignment, size);
5050
#endif
5151

5252
}
@@ -71,7 +71,7 @@ void* FastMallocAlignedMemoryAllocator::tryAllocateMemory(size_t size)
7171
#if ENABLE(MALLOC_HEAP_BREAKDOWN)
7272
return m_heap.malloc(size);
7373
#else
74-
return FastMalloc::tryMalloc(size);
74+
return FastCompactMalloc::tryMalloc(size);
7575
#endif
7676
}
7777

@@ -80,7 +80,7 @@ void FastMallocAlignedMemoryAllocator::freeMemory(void* pointer)
8080
#if ENABLE(MALLOC_HEAP_BREAKDOWN)
8181
return m_heap.free(pointer);
8282
#else
83-
FastMalloc::free(pointer);
83+
FastCompactMalloc::free(pointer);
8484
#endif
8585
}
8686

@@ -89,7 +89,7 @@ void* FastMallocAlignedMemoryAllocator::tryReallocateMemory(void* pointer, size_
8989
#if ENABLE(MALLOC_HEAP_BREAKDOWN)
9090
return m_heap.realloc(pointer, size);
9191
#else
92-
return FastMalloc::tryRealloc(pointer, size);
92+
return FastCompactMalloc::tryRealloc(pointer, size);
9393
#endif
9494
}
9595

‎Source/JavaScriptCore/heap/IsoAlignedMemoryAllocator.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void* IsoAlignedMemoryAllocator::tryAllocateMemory(size_t size)
5252
#if ENABLE(MALLOC_HEAP_BREAKDOWN)
5353
return m_heap.malloc(size);
5454
#else
55-
return FastMalloc::tryMalloc(size);
55+
return FastCompactMalloc::tryMalloc(size);
5656
#endif
5757
}
5858

@@ -76,7 +76,7 @@ void* IsoAlignedMemoryAllocator::tryMallocBlock()
7676
#if ENABLE(MALLOC_HEAP_BREAKDOWN)
7777
return m_heap.memalign(MarkedBlock::blockSize, MarkedBlock::blockSize, true);
7878
#else
79-
return tryFastAlignedMalloc(MarkedBlock::blockSize, MarkedBlock::blockSize);
79+
return tryFastCompactAlignedMalloc(MarkedBlock::blockSize, MarkedBlock::blockSize);
8080
#endif
8181
}
8282

‎Source/JavaScriptCore/heap/IsoCellSet.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ IsoCellSet::IsoCellSet(IsoSubspace& subspace)
4242
IsoCellSet::~IsoCellSet()
4343
{
4444
if (isOnList())
45-
PackedRawSentinelNode<IsoCellSet>::remove();
45+
BasicRawSentinelNode<IsoCellSet>::remove();
4646
}
4747

4848
Ref<SharedTask<MarkedBlock::Handle*()>> IsoCellSet::parallelNotEmptyMarkedBlockSource()

0 commit comments

Comments
 (0)