GCIncomingRefCountedSetInlines.h [plain text]
#pragma once
#include "GCIncomingRefCountedSet.h"
#include "VM.h"
namespace JSC {
template<typename T>
GCIncomingRefCountedSet<T>::GCIncomingRefCountedSet()
: m_bytes(0)
{
}
template<typename T>
void GCIncomingRefCountedSet<T>::lastChanceToFinalize()
{
for (size_t i = m_vector.size(); i--;)
m_vector[i]->filterIncomingReferences(removeAll);
}
template<typename T>
bool GCIncomingRefCountedSet<T>::addReference(JSCell* cell, T* object)
{
if (!object->addIncomingReference(cell)) {
ASSERT(object->isDeferred());
ASSERT(object->numberOfIncomingReferences());
return false;
}
m_vector.append(object);
m_bytes += object->gcSizeEstimateInBytes();
ASSERT(object->isDeferred());
ASSERT(object->numberOfIncomingReferences());
return true;
}
template<typename T>
void GCIncomingRefCountedSet<T>::sweep()
{
for (size_t i = 0; i < m_vector.size(); ++i) {
T* object = m_vector[i];
size_t size = object->gcSizeEstimateInBytes();
ASSERT(object->isDeferred());
ASSERT(object->numberOfIncomingReferences());
if (!object->filterIncomingReferences(removeDead))
continue;
m_bytes -= size;
m_vector[i--] = m_vector.last();
m_vector.removeLast();
}
}
template<typename T>
bool GCIncomingRefCountedSet<T>::removeAll(JSCell*)
{
return false;
}
template<typename T>
bool GCIncomingRefCountedSet<T>::removeDead(JSCell* cell)
{
return Heap::isMarked(cell);
}
}