CompleteSubspace.h [plain text]
#pragma once
#include "Subspace.h"
namespace JSC {
class CompleteSubspace final : public Subspace {
public:
JS_EXPORT_PRIVATE CompleteSubspace(CString name, Heap&, HeapCellType*, AlignedMemoryAllocator*);
JS_EXPORT_PRIVATE ~CompleteSubspace() final;
Allocator allocatorFor(size_t, AllocatorForMode) final;
Allocator allocatorForNonVirtual(size_t, AllocatorForMode);
void* allocate(VM&, size_t, GCDeferralContext*, AllocationFailureMode) final;
void* allocateNonVirtual(VM&, size_t, GCDeferralContext*, AllocationFailureMode);
void* reallocatePreciseAllocationNonVirtual(VM&, HeapCell*, size_t, GCDeferralContext*, AllocationFailureMode);
static ptrdiff_t offsetOfAllocatorForSizeStep() { return OBJECT_OFFSETOF(CompleteSubspace, m_allocatorForSizeStep); }
Allocator* allocatorForSizeStep() { return &m_allocatorForSizeStep[0]; }
private:
JS_EXPORT_PRIVATE Allocator allocatorForSlow(size_t);
JS_EXPORT_PRIVATE void* allocateSlow(VM&, size_t, GCDeferralContext*, AllocationFailureMode);
void* tryAllocateSlow(VM&, size_t, GCDeferralContext*);
std::array<Allocator, MarkedSpace::numSizeClasses> m_allocatorForSizeStep;
Vector<std::unique_ptr<BlockDirectory>> m_directories;
Vector<std::unique_ptr<LocalAllocator>> m_localAllocators;
};
ALWAYS_INLINE Allocator CompleteSubspace::allocatorForNonVirtual(size_t size, AllocatorForMode mode)
{
if (size <= MarkedSpace::largeCutoff) {
Allocator result = m_allocatorForSizeStep[MarkedSpace::sizeClassToIndex(size)];
switch (mode) {
case AllocatorForMode::MustAlreadyHaveAllocator:
RELEASE_ASSERT(result);
break;
case AllocatorForMode::EnsureAllocator:
if (!result)
return allocatorForSlow(size);
break;
case AllocatorForMode::AllocatorIfExists:
break;
}
return result;
}
RELEASE_ASSERT(mode != AllocatorForMode::MustAlreadyHaveAllocator);
return Allocator();
}
}