diff options
Diffstat (limited to 'Source/JavaScriptCore/heap/CopiedBlock.h')
-rw-r--r-- | Source/JavaScriptCore/heap/CopiedBlock.h | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/Source/JavaScriptCore/heap/CopiedBlock.h b/Source/JavaScriptCore/heap/CopiedBlock.h index 431b86c38..b408aa40b 100644 --- a/Source/JavaScriptCore/heap/CopiedBlock.h +++ b/Source/JavaScriptCore/heap/CopiedBlock.h @@ -38,32 +38,51 @@ class CopiedBlock : public HeapBlock { friend class CopiedSpace; friend class CopiedAllocator; public: - CopiedBlock(PageAllocationAligned& allocation) - : HeapBlock(allocation) - , m_offset(payload()) - , m_isPinned(false) - { - ASSERT(is8ByteAligned(static_cast<void*>(m_offset))); -#if USE(JSVALUE64) - char* offset = static_cast<char*>(m_offset); - memset(static_cast<void*>(offset), 0, static_cast<size_t>((reinterpret_cast<char*>(this) + allocation.size()) - offset)); -#else - JSValue emptyValue; - JSValue* limit = reinterpret_cast_ptr<JSValue*>(reinterpret_cast<char*>(this) + allocation.size()); - for (JSValue* currentValue = reinterpret_cast<JSValue*>(m_offset); currentValue < limit; currentValue++) - *currentValue = emptyValue; -#endif - } + static CopiedBlock* create(const PageAllocationAligned&); + static PageAllocationAligned destroy(CopiedBlock*); char* payload(); size_t size(); size_t capacity(); private: + CopiedBlock(const PageAllocationAligned&); + void* m_offset; uintptr_t m_isPinned; }; +inline CopiedBlock* CopiedBlock::create(const PageAllocationAligned& allocation) +{ + return new(NotNull, allocation.base()) CopiedBlock(allocation); +} + +inline PageAllocationAligned CopiedBlock::destroy(CopiedBlock* block) +{ + PageAllocationAligned allocation; + swap(allocation, block->m_allocation); + + block->~CopiedBlock(); + return allocation; +} + +inline CopiedBlock::CopiedBlock(const PageAllocationAligned& allocation) + : HeapBlock(allocation) + , m_offset(payload()) + , m_isPinned(false) +{ + ASSERT(is8ByteAligned(static_cast<void*>(m_offset))); +#if USE(JSVALUE64) + char* offset = static_cast<char*>(m_offset); + memset(static_cast<void*>(offset), 0, static_cast<size_t>((reinterpret_cast<char*>(this) + allocation.size()) - offset)); +#else + JSValue emptyValue; + JSValue* limit = reinterpret_cast_ptr<JSValue*>(reinterpret_cast<char*>(this) + allocation.size()); + for (JSValue* currentValue = reinterpret_cast<JSValue*>(m_offset); currentValue < limit; currentValue++) + *currentValue = emptyValue; +#endif +} + inline char* CopiedBlock::payload() { return reinterpret_cast<char*>(this) + ((sizeof(CopiedBlock) + 7) & ~7); |