diff options
Diffstat (limited to 'src/qml/memory/qv4mm_p.h')
-rw-r--r-- | src/qml/memory/qv4mm_p.h | 73 |
1 files changed, 13 insertions, 60 deletions
diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h index fb21481d5b..7dc73bdacc 100644 --- a/src/qml/memory/qv4mm_p.h +++ b/src/qml/memory/qv4mm_p.h @@ -70,51 +70,6 @@ namespace QV4 { struct ChunkAllocator; -template<typename T> -struct StackAllocator { - Q_STATIC_ASSERT(sizeof(T) < Chunk::DataSize); - static const uint requiredSlots = (sizeof(T) + sizeof(HeapItem) - 1)/sizeof(HeapItem); - - StackAllocator(ChunkAllocator *chunkAlloc); - - T *allocate() { - HeapItem *m = nextFree; - if (Q_UNLIKELY(nextFree == lastInChunk)) { - nextChunk(); - } else { - nextFree += requiredSlots; - } -#if MM_DEBUG || !defined(QT_NO_DEBUG) || defined(QT_FORCE_ASSERTS) - Chunk *c = m->chunk(); - Chunk::setBit(c->objectBitmap, m - c->realBase()); -#endif - return m->as<T>(); - } - void free() { - if (Q_UNLIKELY(nextFree == firstInChunk)) { - prevChunk(); - } else { - nextFree -= requiredSlots; - } -#if MM_DEBUG || !defined(QT_NO_DEBUG) || defined(QT_FORCE_ASSERTS) - Chunk *c = nextFree->chunk(); - Chunk::clearBit(c->objectBitmap, nextFree - c->realBase()); -#endif - } - - void nextChunk(); - void prevChunk(); - - void freeAll(); - - ChunkAllocator *chunkAllocator; - HeapItem *nextFree = 0; - HeapItem *firstInChunk = 0; - HeapItem *lastInChunk = 0; - std::vector<Chunk *> chunks; - uint currentChunk = 0; -}; - struct BlockAllocator { BlockAllocator(ChunkAllocator *chunkAllocator, ExecutionEngine *engine) : chunkAllocator(chunkAllocator), engine(engine) @@ -202,23 +157,10 @@ public: Q_DECL_CONSTEXPR static inline std::size_t align(std::size_t size) { return (size + Chunk::SlotSize - 1) & ~(Chunk::SlotSize - 1); } - QV4::Heap::CallContext *allocSimpleCallContext() - { - Heap::CallContext *ctxt = stackAllocator.allocate(); - memset(ctxt, 0, sizeof(Heap::SimpleCallContext)); - ctxt->internalClass = SimpleCallContext::defaultInternalClass(engine); - Q_ASSERT(ctxt->internalClass && ctxt->internalClass->vtable); - ctxt->init(); - return ctxt; - - } - void freeSimpleCallContext() - { stackAllocator.free(); } - template<typename ManagedType> inline typename ManagedType::Data *allocManaged(std::size_t size) { - V4_ASSERT_IS_TRIVIAL(typename ManagedType::Data) + Q_STATIC_ASSERT(std::is_trivial< typename ManagedType::Data >::value); size = align(size); Heap::Base *o = allocData(size); InternalClass *ic = ManagedType::defaultInternalClass(engine); @@ -228,6 +170,18 @@ public: return static_cast<typename ManagedType::Data *>(o); } + template<typename ManagedType> + inline typename ManagedType::Data *allocManaged(std::size_t size, InternalClass *ic) + { + Q_STATIC_ASSERT(std::is_trivial< typename ManagedType::Data >::value); + size = align(size); + Heap::Base *o = allocData(size); + o->internalClass = ic; + Q_ASSERT(o->internalClass && o->internalClass->vtable); + Q_ASSERT(ic->vtable == ManagedType::staticVTable()); + return static_cast<typename ManagedType::Data *>(o); + } + template <typename ObjectType> typename ObjectType::Data *allocateObject(InternalClass *ic) { @@ -452,7 +406,6 @@ private: public: QV4::ExecutionEngine *engine; ChunkAllocator *chunkAllocator; - StackAllocator<Heap::CallContext> stackAllocator; BlockAllocator blockAllocator; HugeItemAllocator hugeItemAllocator; PersistentValueStorage *m_persistentValues; |