Skip to content

Commit 31d1d2e

Browse files
committed
Extra asserts for testing in prod
1 parent cd5fe9d commit 31d1d2e

File tree

13 files changed

+40
-74
lines changed

13 files changed

+40
-74
lines changed

Source/JavaScriptCore/heap/MarkedBlock.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,9 @@ void MarkedBlock::Handle::removeFromDirectory()
318318

319319
void MarkedBlock::Handle::didAddToDirectory(BlockDirectory* directory, unsigned index)
320320
{
321-
ASSERT(m_index == std::numeric_limits<unsigned>::max());
322-
ASSERT(!m_directory);
321+
RELEASE_ASSERT(m_index == std::numeric_limits<unsigned>::max());
322+
RELEASE_ASSERT(WTF::opaque(!m_directory));
323+
RELEASE_ASSERT(WTF::opaque(directory));
323324

324325
RELEASE_ASSERT(directory->subspace()->alignedMemoryAllocator() == m_alignedMemoryAllocator);
325326

@@ -348,21 +349,19 @@ void MarkedBlock::Handle::didAddToDirectory(BlockDirectory* directory, unsigned
348349

349350
void MarkedBlock::Handle::didRemoveFromDirectory()
350351
{
351-
ASSERT(m_index != std::numeric_limits<unsigned>::max());
352-
ASSERT(m_directory);
352+
RELEASE_ASSERT(m_index != std::numeric_limits<unsigned>::max());
353+
RELEASE_ASSERT(m_directory);
353354

354355
m_index = std::numeric_limits<unsigned>::max();
355356
m_directory = nullptr;
356357
blockFooter().m_subspace = nullptr;
357358
}
358359

359-
#if ASSERT_ENABLED
360360
void MarkedBlock::assertValidCell(VM& vm, HeapCell* cell) const
361361
{
362362
RELEASE_ASSERT(&vm == &this->vm());
363363
RELEASE_ASSERT(const_cast<MarkedBlock*>(this)->handle().cellAlign(cell) == cell);
364364
}
365-
#endif // ASSERT_ENABLED
366365

367366
void MarkedBlock::Handle::dumpState(PrintStream& out)
368367
{
@@ -488,4 +487,3 @@ void printInternal(PrintStream& out, JSC::MarkedBlock::Handle::SweepMode mode)
488487
}
489488

490489
} // namespace WTF
491-

Source/JavaScriptCore/heap/MarkedBlock.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,7 @@ class MarkedBlock {
354354

355355
bool hasAnyMarked() const;
356356
void noteMarked();
357-
#if ASSERT_ENABLED
358357
void assertValidCell(VM&, HeapCell*) const;
359-
#else
360-
void assertValidCell(VM&, HeapCell*) const { }
361-
#endif
362358

363359
WeakSet& weakSet();
364360

Source/JavaScriptCore/heap/PreciseAllocation.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,11 @@ void PreciseAllocation::dump(PrintStream& out) const
253253
out.print(RawPointer(this), ":(cell at ", RawPointer(cell()), " with size ", m_cellSize, " and attributes ", m_attributes, ")");
254254
}
255255

256-
#if ASSERT_ENABLED
257256
void PreciseAllocation::assertValidCell(VM& vm, HeapCell* cell) const
258257
{
259-
ASSERT(&vm == &this->vm());
260-
ASSERT(cell == this->cell());
261-
ASSERT(m_hasValidCell);
258+
RELEASE_ASSERT(&vm == &this->vm());
259+
RELEASE_ASSERT(cell == this->cell());
260+
RELEASE_ASSERT(m_hasValidCell);
262261
}
263-
#endif
264262

265263
} // namespace JSC
266-

Source/JavaScriptCore/heap/PreciseAllocation.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,7 @@ class PreciseAllocation : public PackedRawSentinelNode<PreciseAllocation> {
139139

140140
void noteMarked() { }
141141

142-
#if ASSERT_ENABLED
143142
void assertValidCell(VM&, HeapCell*) const;
144-
#else
145-
void assertValidCell(VM&, HeapCell*) const { }
146-
#endif
147143

148144
void sweep();
149145

@@ -182,4 +178,3 @@ inline void* PreciseAllocation::basePointer() const
182178
}
183179

184180
} // namespace JSC
185-

Source/JavaScriptCore/heap/SlotVisitor.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ static void validate(JSCell* cell)
7878
SlotVisitor::SlotVisitor(Heap& heap, CString codeName)
7979
: Base(heap, codeName, heap.m_opaqueRoots)
8080
, m_markingVersion(MarkedSpace::initialVersion)
81-
#if ASSERT_ENABLED
8281
, m_isCheckingForDefaultMarkViolation(false)
83-
#endif
8482
{
8583
}
8684

@@ -139,7 +137,7 @@ void SlotVisitor::appendJSCellOrAuxiliary(HeapCell* heapCell)
139137
if (!heapCell)
140138
return;
141139

142-
ASSERT(!m_isCheckingForDefaultMarkViolation);
140+
RELEASE_ASSERT(!m_isCheckingForDefaultMarkViolation);
143141

144142
auto validateCell = [&] (JSCell* jsCell) {
145143
StructureID structureID = jsCell->structureID();
@@ -235,7 +233,7 @@ void SlotVisitor::appendHiddenSlow(JSCell* cell, Dependency dependency)
235233

236234
ALWAYS_INLINE void SlotVisitor::appendHiddenSlowImpl(JSCell* cell, Dependency dependency)
237235
{
238-
ASSERT(!m_isCheckingForDefaultMarkViolation);
236+
RELEASE_ASSERT(!m_isCheckingForDefaultMarkViolation);
239237

240238
#if ENABLE(GC_VALIDATION)
241239
validate(cell);
@@ -274,14 +272,14 @@ void SlotVisitor::appendToMarkStack(JSCell* cell)
274272
template<typename ContainerType>
275273
ALWAYS_INLINE void SlotVisitor::appendToMarkStack(ContainerType& container, JSCell* cell)
276274
{
277-
ASSERT(m_heap.isMarked(cell));
278-
#if CPU(X86_64)
275+
RELEASE_ASSERT(m_heap.isMarked(cell));
276+
279277
if (UNLIKELY(Options::dumpZappedCellCrashData())) {
280278
if (UNLIKELY(cell->isZapped()))
281279
reportZappedCellAndCrash(m_heap, cell);
282280
}
283-
#endif
284-
ASSERT(!cell->isZapped());
281+
282+
RELEASE_ASSERT(!cell->isZapped());
285283

286284
container.noteMarked();
287285

@@ -295,7 +293,7 @@ void SlotVisitor::markAuxiliary(const void* base)
295293
{
296294
HeapCell* cell = bitwise_cast<HeapCell*>(base);
297295

298-
ASSERT(cell->heap() == heap());
296+
RELEASE_ASSERT(cell->heap() == heap());
299297

300298
if (Heap::testAndSetMarked(m_markingVersion, cell))
301299
return;
@@ -344,7 +342,7 @@ class SetCurrentCellScope {
344342

345343
ALWAYS_INLINE void SlotVisitor::visitChildren(const JSCell* cell)
346344
{
347-
ASSERT(m_heap.isMarked(cell));
345+
RELEASE_ASSERT(m_heap.isMarked(cell));
348346

349347
SetCurrentCellScope currentCellScope(*this, cell);
350348

@@ -380,7 +378,6 @@ ALWAYS_INLINE void SlotVisitor::visitChildren(const JSCell* cell)
380378
default:
381379
// FIXME: This could be so much better.
382380
// https://bugs.webkit.org/show_bug.cgi?id=162462
383-
#if CPU(X86_64)
384381
if (UNLIKELY(Options::dumpZappedCellCrashData())) {
385382
Structure* structure = cell->structure();
386383
if (LIKELY(structure)) {
@@ -390,7 +387,6 @@ ALWAYS_INLINE void SlotVisitor::visitChildren(const JSCell* cell)
390387
}
391388
reportZappedCellAndCrash(m_heap, const_cast<JSCell*>(cell));
392389
}
393-
#endif
394390
cell->methodTable()->visitChildren(const_cast<JSCell*>(cell), *this);
395391
break;
396392
}

Source/JavaScriptCore/heap/SlotVisitor.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class SlotVisitor final : public AbstractSlotVisitor {
6464

6565
class DefaultMarkingViolationAssertionScope {
6666
public:
67-
#if ASSERT_ENABLED
6867
DefaultMarkingViolationAssertionScope(SlotVisitor& visitor)
6968
: m_visitor(visitor)
7069
{
@@ -80,9 +79,6 @@ class SlotVisitor final : public AbstractSlotVisitor {
8079
private:
8180
SlotVisitor& m_visitor;
8281
bool m_wasCheckingForDefaultMarkViolation;
83-
#else
84-
DefaultMarkingViolationAssertionScope(SlotVisitor&) { }
85-
#endif
8682
};
8783

8884
SlotVisitor(Heap&, CString codeName);
@@ -238,9 +234,7 @@ class SlotVisitor final : public AbstractSlotVisitor {
238234

239235
// Put padding here to mitigate false sharing between multiple SlotVisitors.
240236
char padding[64];
241-
#if ASSERT_ENABLED
242237
bool m_isCheckingForDefaultMarkViolation { false };
243-
#endif
244238
};
245239

246240
class ParallelModeEnabler {

Source/JavaScriptCore/runtime/JSCast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ template<typename To, typename From>
3333
inline To jsCast(From* from)
3434
{
3535
static_assert(std::is_base_of<JSCell, typename std::remove_pointer<To>::type>::value && std::is_base_of<JSCell, typename std::remove_pointer<From>::type>::value, "JS casting expects that the types you are casting to/from are subclasses of JSCell");
36-
#if (ASSERT_ENABLED || ENABLE(SECURITY_ASSERTIONS)) && CPU(X86_64)
36+
#if (ASSERT_ENABLED || ENABLE(SECURITY_ASSERTIONS))
3737
if (from && !from->JSCell::inherits(std::remove_pointer<To>::type::info()))
3838
reportZappedCellAndCrash(*from->JSCell::heap(), from);
3939
#else

Source/JavaScriptCore/runtime/JSCell.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ void JSCellLock::unlockSlow()
259259
IndexingTypeLockAlgorithm::unlockSlow(*lock);
260260
}
261261

262-
#if CPU(X86_64)
263262
NEVER_INLINE NO_RETURN_DUE_TO_CRASH NOT_TAIL_CALLED void reportZappedCellAndCrash(Heap& heap, const JSCell* cell)
264263
{
265264
MarkedBlock::Handle* foundBlockHandle = nullptr;
@@ -336,6 +335,5 @@ NEVER_INLINE NO_RETURN_DUE_TO_CRASH NOT_TAIL_CALLED void reportZappedCellAndCras
336335

337336
CRASH_WITH_INFO(cellAddress, headerWord, zapReasonAndMore, subspaceHash, cellSize, foundBlock, variousState);
338337
}
339-
#endif // CPU(X86_64)
340338

341339
} // namespace JSC

Source/JavaScriptCore/runtime/JSCell.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,6 @@ inline auto subspaceForConcurrently(VM& vm)
297297
return Type::template subspaceFor<Type, SubspaceAccess::Concurrently>(vm);
298298
}
299299

300-
#if CPU(X86_64)
301300
JS_EXPORT_PRIVATE NEVER_INLINE NO_RETURN_DUE_TO_CRASH NOT_TAIL_CALLED void reportZappedCellAndCrash(Heap&, const JSCell*);
302-
#endif
303301

304302
} // namespace JSC

Source/JavaScriptCore/runtime/JSCellInlines.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace JSC {
5252
inline JSCell::JSCell(CreatingEarlyCellTag)
5353
: m_cellState(CellState::DefinitelyWhite)
5454
{
55-
ASSERT(!isCompilationThread());
55+
RELEASE_ASSERT(!isCompilationThread());
5656
}
5757

5858
inline JSCell::JSCell(VM&, Structure* structure)
@@ -62,7 +62,7 @@ inline JSCell::JSCell(VM&, Structure* structure)
6262
, m_flags(structure->typeInfo().inlineTypeFlags())
6363
, m_cellState(CellState::DefinitelyWhite)
6464
{
65-
ASSERT(!isCompilationThread());
65+
RELEASE_ASSERT(!isCompilationThread());
6666

6767
// Note that in the constructor initializer list above, we are only using values
6868
// inside structure but not necessarily the structure pointer itself. All these
@@ -84,18 +84,18 @@ inline void JSCell::finishCreation(VM& vm)
8484
// to make sure that none of our stores sink below here.
8585
vm.mutatorFence();
8686
#if ENABLE(GC_VALIDATION)
87-
ASSERT(vm.isInitializingObject());
87+
RELEASE_ASSERT(vm.isInitializingObject());
8888
vm.setInitializingObjectClass(0);
8989
#else
9090
UNUSED_PARAM(vm);
9191
#endif
92-
ASSERT(m_structureID);
92+
RELEASE_ASSERT(m_structureID);
9393
}
9494

9595
inline void JSCell::finishCreation(VM& vm, Structure* structure, CreatingEarlyCellTag)
9696
{
9797
#if ENABLE(GC_VALIDATION)
98-
ASSERT(vm.isInitializingObject());
98+
RELEASE_ASSERT(vm.isInitializingObject());
9999
vm.setInitializingObjectClass(0);
100100
if (structure) {
101101
#endif
@@ -109,7 +109,7 @@ inline void JSCell::finishCreation(VM& vm, Structure* structure, CreatingEarlyCe
109109
UNUSED_PARAM(vm);
110110
#endif
111111
// Very first set of allocations won't have a real structure.
112-
ASSERT(m_structureID || !vm.structureStructure);
112+
RELEASE_ASSERT(m_structureID || !vm.structureStructure);
113113
}
114114

115115
inline JSType JSCell::type() const
@@ -170,15 +170,15 @@ inline Allocator allocatorForConcurrently(VM& vm, size_t allocationSize, Allocat
170170
template<typename T, AllocationFailureMode failureMode>
171171
ALWAYS_INLINE void* tryAllocateCellHelper(VM& vm, size_t size, GCDeferralContext* deferralContext)
172172
{
173-
ASSERT(deferralContext || vm.heap.isDeferred() || !DisallowGC::isInEffectOnCurrentThread());
174-
ASSERT(size >= sizeof(T));
173+
RELEASE_ASSERT(deferralContext || vm.heap.isDeferred() || !DisallowGC::isInEffectOnCurrentThread());
174+
RELEASE_ASSERT(size >= sizeof(T));
175175
JSCell* result = static_cast<JSCell*>(subspaceFor<T>(vm)->allocate(vm, size, deferralContext, failureMode));
176176
if constexpr (failureMode == AllocationFailureMode::ReturnNull) {
177177
if (!result)
178178
return nullptr;
179179
}
180180
#if ENABLE(GC_VALIDATION)
181-
ASSERT(!vm.isInitializingObject());
181+
RELEASE_ASSERT(!vm.isInitializingObject());
182182
vm.setInitializingObjectClass(T::info());
183183
#endif
184184
result->clearStructure();
@@ -298,16 +298,16 @@ inline bool JSCell::isAPIValueWrapper() const
298298

299299
ALWAYS_INLINE void JSCell::setStructure(VM& vm, Structure* structure)
300300
{
301-
ASSERT(structure->classInfoForCells() == this->structure()->classInfoForCells());
302-
ASSERT(!this->structure()
301+
RELEASE_ASSERT(structure->classInfoForCells() == this->structure()->classInfoForCells());
302+
RELEASE_ASSERT(!this->structure()
303303
|| this->structure()->transitionWatchpointSetHasBeenInvalidated()
304304
|| structure->id().decode() == structure);
305305
m_structureID = structure->id();
306306
m_flags = TypeInfo::mergeInlineTypeFlags(structure->typeInfo().inlineTypeFlags(), m_flags);
307307
m_type = structure->typeInfo().type();
308308
IndexingType newIndexingType = structure->indexingModeIncludingHistory();
309309
if (m_indexingTypeAndMisc != newIndexingType) {
310-
ASSERT(!(newIndexingType & ~AllArrayTypesAndHistory));
310+
RELEASE_ASSERT(!(newIndexingType & ~AllArrayTypesAndHistory));
311311
for (;;) {
312312
IndexingType oldValue = m_indexingTypeAndMisc;
313313
IndexingType newValue = (oldValue & ~AllArrayTypesAndHistory) | structure->indexingModeIncludingHistory();
@@ -321,10 +321,8 @@ ALWAYS_INLINE void JSCell::setStructure(VM& vm, Structure* structure)
321321
inline const MethodTable* JSCell::methodTable() const
322322
{
323323
Structure* structure = this->structure();
324-
#if ASSERT_ENABLED
325324
if (Structure* rootStructure = structure->structure())
326-
ASSERT(rootStructure == rootStructure->structure());
327-
#endif
325+
RELEASE_ASSERT(rootStructure == rootStructure->structure());
328326
return &structure->classInfoForCells()->methodTable;
329327
}
330328

@@ -362,7 +360,7 @@ ALWAYS_INLINE const ClassInfo* JSCell::classInfo() const
362360
// destructing the object. The GC thread or JIT threads, unlike the mutator thread, are able to access classInfo
363361
// independent of whether the mutator thread is sweeping or not. Hence, we also check for !currentThreadIsHoldingAPILock()
364362
// to allow the GC thread or JIT threads to pass this assertion.
365-
ASSERT(vm().heap.mutatorState() != MutatorState::Sweeping || !vm().currentThreadIsHoldingAPILock());
363+
RELEASE_ASSERT(vm().heap.mutatorState() != MutatorState::Sweeping || !vm().currentThreadIsHoldingAPILock());
366364
return structure()->classInfoForCells();
367365
}
368366

0 commit comments

Comments
 (0)