LargeAllocation.cpp [plain text]
#include "config.h"
#include "LargeAllocation.h"
#include "Heap.h"
#include "JSCInlines.h"
#include "Operations.h"
namespace JSC {
LargeAllocation* LargeAllocation::tryCreate(Heap& heap, size_t size, Subspace* subspace)
{
void* space = tryFastAlignedMalloc(alignment, headerSize() + size);
if (!space)
return nullptr;
if (scribbleFreeCells())
scribble(space, size);
return new (NotNull, space) LargeAllocation(heap, size, subspace);
}
LargeAllocation::LargeAllocation(Heap& heap, size_t size, Subspace* subspace)
: m_cellSize(size)
, m_isNewlyAllocated(true)
, m_hasValidCell(true)
, m_attributes(subspace->attributes())
, m_subspace(subspace)
, m_weakSet(heap.vm(), *this)
{
m_isMarked.store(0);
}
LargeAllocation::~LargeAllocation()
{
if (isOnList())
remove();
}
void LargeAllocation::lastChanceToFinalize()
{
m_weakSet.lastChanceToFinalize();
clearMarked();
clearNewlyAllocated();
sweep();
}
void LargeAllocation::shrink()
{
m_weakSet.shrink();
}
void LargeAllocation::visitWeakSet(SlotVisitor& visitor)
{
m_weakSet.visit(visitor);
}
void LargeAllocation::reapWeakSet()
{
return m_weakSet.reap();
}
void LargeAllocation::flip()
{
ASSERT(heap()->collectionScope() == CollectionScope::Full);
clearMarked();
}
bool LargeAllocation::isEmpty()
{
return !isMarked() && m_weakSet.isEmpty() && !isNewlyAllocated();
}
void LargeAllocation::sweep()
{
m_weakSet.sweep();
if (m_hasValidCell && !isLive()) {
if (m_attributes.destruction == NeedsDestruction)
m_subspace->destroy(*vm(), static_cast<JSCell*>(cell()));
m_hasValidCell = false;
}
}
void LargeAllocation::destroy()
{
this->~LargeAllocation();
fastAlignedFree(this);
}
void LargeAllocation::dump(PrintStream& out) const
{
out.print(RawPointer(this), ":(cell at ", RawPointer(cell()), " with size ", m_cellSize, " and attributes ", m_attributes, ")");
}
#if !ASSERT_DISABLED
void LargeAllocation::assertValidCell(VM& vm, HeapCell* cell) const
{
ASSERT(&vm == this->vm());
ASSERT(cell == this->cell());
ASSERT(m_hasValidCell);
}
#endif
}