diff options
Diffstat (limited to 'src/qml/memory/qv4mm_p.h')
-rw-r--r-- | src/qml/memory/qv4mm_p.h | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h index 921fea3956..40670bcdc7 100644 --- a/src/qml/memory/qv4mm_p.h +++ b/src/qml/memory/qv4mm_p.h @@ -58,8 +58,6 @@ #include <private/qv4mmdefs_p.h> #include <QVector> -//#define DETAILED_MM_STATS - #define QV4_MM_MAXBLOCK_SHIFT "QV4_MM_MAXBLOCK_SHIFT" #define QV4_MM_MAX_CHUNK_SIZE "QV4_MM_MAX_CHUNK_SIZE" #define QV4_MM_STATS "QV4_MM_STATS" @@ -71,15 +69,13 @@ QT_BEGIN_NAMESPACE namespace QV4 { struct ChunkAllocator; +struct MemorySegment; struct BlockAllocator { - BlockAllocator(ChunkAllocator *chunkAllocator) - : chunkAllocator(chunkAllocator) + BlockAllocator(ChunkAllocator *chunkAllocator, ExecutionEngine *engine) + : chunkAllocator(chunkAllocator), engine(engine) { memset(freeBins, 0, sizeof(freeBins)); -#if MM_DEBUG - memset(allocations, 0, sizeof(allocations)); -#endif } enum { NumBins = 8 }; @@ -88,10 +84,6 @@ struct BlockAllocator { return nSlots >= NumBins ? NumBins - 1 : nSlots; } -#if MM_DEBUG - void stats(); -#endif - HeapItem *allocate(size_t size, bool forceAllocation = false); size_t totalSlots() const { @@ -108,26 +100,25 @@ struct BlockAllocator { return used; } - void sweep(ClassDestroyStatsCallback classCountPtr); + void sweep(); void freeAll(); void resetBlackBits(); void collectGrayItems(MarkStack *markStack); // bump allocations - HeapItem *nextFree = 0; + HeapItem *nextFree = nullptr; size_t nFree = 0; size_t usedSlotsAfterLastSweep = 0; HeapItem *freeBins[NumBins]; ChunkAllocator *chunkAllocator; + ExecutionEngine *engine; std::vector<Chunk *> chunks; -#if MM_DEBUG - uint allocations[NumBins]; -#endif + uint *allocationStats = nullptr; }; struct HugeItemAllocator { - HugeItemAllocator(ChunkAllocator *chunkAllocator) - : chunkAllocator(chunkAllocator) + HugeItemAllocator(ChunkAllocator *chunkAllocator, ExecutionEngine *engine) + : chunkAllocator(chunkAllocator), engine(engine) {} HeapItem *allocate(size_t size); @@ -144,7 +135,9 @@ struct HugeItemAllocator { } ChunkAllocator *chunkAllocator; + ExecutionEngine *engine; struct HugeChunk { + MemorySegment *segment; Chunk *chunk; size_t size; }; @@ -169,7 +162,7 @@ public: 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); @@ -182,7 +175,7 @@ public: template<typename ManagedType> inline typename ManagedType::Data *allocManaged(std::size_t size, InternalClass *ic) { - 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); o->internalClass = ic; @@ -238,7 +231,7 @@ public: { Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic)); - Q_ASSERT(t->internalClass()->prototype == (prototype ? prototype->d() : 0)); + Q_ASSERT(t->internalClass()->prototype == (prototype ? prototype->d() : nullptr)); Q_UNUSED(prototype); t->d_unchecked()->init(); return t->d(); @@ -249,7 +242,7 @@ public: { Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic)); - Q_ASSERT(t->internalClass()->prototype == (prototype ? prototype->d() : 0)); + Q_ASSERT(t->internalClass()->prototype == (prototype ? prototype->d() : nullptr)); Q_UNUSED(prototype); t->d_unchecked()->init(arg1); return t->d(); @@ -260,7 +253,7 @@ public: { Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic)); - Q_ASSERT(t->internalClass()->prototype == (prototype ? prototype->d() : 0)); + Q_ASSERT(t->internalClass()->prototype == (prototype ? prototype->d() : nullptr)); Q_UNUSED(prototype); t->d_unchecked()->init(arg1, arg2); return t->d(); @@ -271,7 +264,7 @@ public: { Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic)); - Q_ASSERT(t->internalClass()->prototype == (prototype ? prototype->d() : 0)); + Q_ASSERT(t->internalClass()->prototype == (prototype ? prototype->d() : nullptr)); Q_UNUSED(prototype); t->d_unchecked()->init(arg1, arg2, arg3); return t->d(); @@ -282,7 +275,7 @@ public: { Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic)); - Q_ASSERT(t->internalClass()->prototype == (prototype ? prototype->d() : 0)); + Q_ASSERT(t->internalClass()->prototype == (prototype ? prototype->d() : nullptr)); Q_UNUSED(prototype); t->d_unchecked()->init(arg1, arg2, arg3, arg4); return t->d(); @@ -405,10 +398,6 @@ protected: Heap::Base *allocData(std::size_t size); Heap::Object *allocObjectWithMemberData(const QV4::VTable *vtable, uint nMembers); -#ifdef DETAILED_MM_STATS - void willAllocate(std::size_t size); -#endif // DETAILED_MM_STATS - private: void collectFromJSStack(MarkStack *markStack) const; void mark(); @@ -432,6 +421,14 @@ public: bool gcBlocked = false; bool aggressiveGC = false; bool gcStats = false; + bool gcCollectorStats = false; + + struct { + size_t maxReservedMem = 0; + size_t maxAllocatedMem = 0; + size_t maxUsedMem = 0; + uint allocations[BlockAllocator::NumBins]; + } statistics; }; } |