| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#ifndef gc_StoreBuffer_inl_h |
| 8 |
#define gc_StoreBuffer_inl_h |
| 9 |
|
| 10 |
#include "gc/StoreBuffer.h" |
| 11 |
|
| 12 |
#include "gc/Cell.h" |
| 13 |
#include "gc/Heap.h" |
| 14 |
|
| 15 |
#include "gc/Heap-inl.h" |
| 16 |
|
| 17 |
namespace js { |
| 18 |
namespace gc { |
| 19 |
|
| 20 |
inline /* static */ size_t ArenaCellSet::getCellIndex(const TenuredCell* cell) { |
| 21 |
uintptr_t cellOffset = uintptr_t(cell) & ArenaMask; |
| 22 |
MOZ_ASSERT(cellOffset % ArenaCellIndexBytes == 0); |
| 23 |
return cellOffset / ArenaCellIndexBytes; |
| 24 |
} |
| 25 |
|
| 26 |
inline /* static */ void ArenaCellSet::getWordIndexAndMask(size_t cellIndex, |
| 27 |
size_t* wordp, |
| 28 |
uint32_t* maskp) { |
| 29 |
BitArray<MaxArenaCellIndex>::getIndexAndMask(cellIndex, wordp, maskp); |
| 30 |
} |
| 31 |
|
| 32 |
inline bool ArenaCellSet::hasCell(size_t cellIndex) const { |
| 33 |
MOZ_ASSERT(cellIndex < MaxArenaCellIndex); |
| 34 |
return bits.get(cellIndex); |
| 35 |
} |
| 36 |
|
| 37 |
inline void ArenaCellSet::putCell(size_t cellIndex) { |
| 38 |
MOZ_ASSERT(cellIndex < MaxArenaCellIndex); |
| 39 |
MOZ_ASSERT(arena); |
| 40 |
|
| 41 |
bits.set(cellIndex); |
| 42 |
check(); |
| 43 |
} |
| 44 |
|
| 45 |
inline void ArenaCellSet::check() const { |
| 46 |
#ifdef DEBUG |
| 47 |
bool bitsZero = bits.isAllClear(); |
| 48 |
MOZ_ASSERT(isEmpty() == bitsZero); |
| 49 |
MOZ_ASSERT(isEmpty() == !arena); |
| 50 |
if (!isEmpty()) { |
| 51 |
MOZ_ASSERT(IsCellPointerValid(arena)); |
| 52 |
JSRuntime* runtime = arena->zone()->runtimeFromMainThread(); |
| 53 |
uint64_t minorGCCount = runtime->gc.minorGCCount(); |
| 54 |
MOZ_ASSERT(minorGCCount == minorGCNumberAtCreation || |
| 55 |
minorGCCount == minorGCNumberAtCreation + 1); |
| 56 |
} |
| 57 |
#endif |
| 58 |
} |
| 59 |
|
| 60 |
inline void StoreBuffer::WholeCellBuffer::put(const Cell* cell) { |
| 61 |
if (cell != last_) { |
| 62 |
putDontCheckLast(cell); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
inline void StoreBuffer::WholeCellBuffer::putDontCheckLast(const Cell* cell) { |
| 67 |
// This can still be called when |cell == last_| if the caller didn't check |
| 68 |
// and that's OK. |
| 69 |
|
| 70 |
MOZ_ASSERT(cell->isTenured()); |
| 71 |
|
| 72 |
// BigInts don't have any children, so shouldn't show up here. |
| 73 |
MOZ_ASSERT(cell->getTraceKind() != JS::TraceKind::BigInt); |
| 74 |
|
| 75 |
Arena* arena = cell->asTenured().arena(); |
| 76 |
ArenaCellSet* cells = arena->bufferedCells(); |
| 77 |
if (cells->isEmpty()) { |
| 78 |
cells = allocateCellSet(arena); |
| 79 |
if (!cells) { |
| 80 |
return; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
cells->putCell(&cell->asTenured()); |
| 85 |
cells->check(); |
| 86 |
|
| 87 |
last_ = cell; |
| 88 |
} |
| 89 |
|
| 90 |
/* static */ |
| 91 |
inline bool StoreBuffer::isInWholeCellBuffer(Cell* cell) { |
| 92 |
TenuredCell* tenured = &cell->asTenured(); |
| 93 |
gc::ArenaCellSet* cells = tenured->arena()->bufferedCells(); |
| 94 |
return cells && cells->hasCell(tenured); |
| 95 |
} |
| 96 |
|
| 97 |
inline void StoreBuffer::putWholeCell(Cell* cell) { bufferWholeCell.put(cell); } |
| 98 |
inline void StoreBuffer::putWholeCellDontCheckLast(Cell* cell) { |
| 99 |
bufferWholeCell.putDontCheckLast(cell); |
| 100 |
} |
| 101 |
|
| 102 |
} // namespace gc |
| 103 |
} // namespace js |
| 104 |
|
| 105 |
#endif // gc_StoreBuffer_inl_h |