diff options
Diffstat (limited to 'src/qml/memory')
-rw-r--r-- | src/qml/memory/qv4mm.cpp | 46 | ||||
-rw-r--r-- | src/qml/memory/qv4mm_p.h | 46 |
2 files changed, 44 insertions, 48 deletions
diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp index 854ede2e48..c85aa8c2f8 100644 --- a/src/qml/memory/qv4mm.cpp +++ b/src/qml/memory/qv4mm.cpp @@ -219,7 +219,8 @@ bool sweepChunk(MemoryManager::Data::ChunkHeader *header, uint *itemsInUse, Exec } // namespace MemoryManager::MemoryManager(ExecutionEngine *engine) - : m_d(new Data) + : engine(engine) + , m_d(new Data) , m_persistentValues(new PersistentValueStorage(engine)) , m_weakValues(new PersistentValueStorage(engine)) { @@ -265,7 +266,7 @@ Heap::Base *MemoryManager::allocData(std::size_t size, std::size_t unmanagedSize // we use malloc for this MemoryManager::Data::LargeItem *item = static_cast<MemoryManager::Data::LargeItem *>( - malloc(Q_V4_PROFILE_ALLOC(m_d->engine, size + sizeof(MemoryManager::Data::LargeItem), + malloc(Q_V4_PROFILE_ALLOC(engine, size + sizeof(MemoryManager::Data::LargeItem), Profiling::LargeItem))); memset(item, 0, size + sizeof(MemoryManager::Data::LargeItem)); item->next = m_d->largeItems; @@ -301,7 +302,7 @@ Heap::Base *MemoryManager::allocData(std::size_t size, std::size_t unmanagedSize std::size_t allocSize = m_d->maxChunkSize*(size_t(1) << shift); allocSize = roundUpToMultipleOf(WTF::pageSize(), allocSize); PageAllocation allocation = PageAllocation::allocate( - Q_V4_PROFILE_ALLOC(m_d->engine, allocSize, Profiling::HeapPage), + Q_V4_PROFILE_ALLOC(engine, allocSize, Profiling::HeapPage), OSAllocator::JSGCHeapPages); m_d->heapChunks.append(allocation); @@ -335,7 +336,7 @@ Heap::Base *MemoryManager::allocData(std::size_t size, std::size_t unmanagedSize #ifdef V4_USE_VALGRIND VALGRIND_MEMPOOL_ALLOC(this, m, size); #endif - Q_V4_PROFILE_ALLOC(m_d->engine, size, Profiling::SmallItem); + Q_V4_PROFILE_ALLOC(engine, size, Profiling::SmallItem); ++m_d->allocCount[pos]; ++m_d->totalAlloc; @@ -356,11 +357,11 @@ static void drainMarkStack(QV4::ExecutionEngine *engine, Value *markBase) void MemoryManager::mark() { - Value *markBase = m_d->engine->jsStackTop; + Value *markBase = engine->jsStackTop; - m_d->engine->markObjects(); + engine->markObjects(); - m_persistentValues->mark(m_d->engine); + m_persistentValues->mark(engine); collectFromJSStack(); @@ -391,13 +392,13 @@ void MemoryManager::mark() } if (keepAlive) - qobjectWrapper->mark(m_d->engine); + qobjectWrapper->mark(engine); - if (m_d->engine->jsStackTop >= m_d->engine->jsStackLimit) - drainMarkStack(m_d->engine, markBase); + if (engine->jsStackTop >= engine->jsStackLimit) + drainMarkStack(engine, markBase); } - drainMarkStack(m_d->engine, markBase); + drainMarkStack(engine, markBase); } void MemoryManager::sweep(bool lastSweep) @@ -416,7 +417,7 @@ void MemoryManager::sweep(bool lastSweep) (*it) = Primitive::undefinedValue(); } - if (MultiplyWrappedQObjectMap *multiplyWrappedQObjects = m_d->engine->m_multiplyWrappedQObjects) { + if (MultiplyWrappedQObjectMap *multiplyWrappedQObjects = engine->m_multiplyWrappedQObjects) { for (MultiplyWrappedQObjectMap::Iterator it = multiplyWrappedQObjects->begin(); it != multiplyWrappedQObjects->end();) { if (!it.value().isNullOrUndefined()) it = multiplyWrappedQObjects->erase(it); @@ -432,7 +433,7 @@ void MemoryManager::sweep(bool lastSweep) for (int i = 0; i < m_d->heapChunks.size(); ++i) { Data::ChunkHeader *header = reinterpret_cast<Data::ChunkHeader *>(m_d->heapChunks[i].base()); - chunkIsEmpty[i] = sweepChunk(header, &itemsInUse[header->itemSize >> 4], m_d->engine, &m_d->unmanagedHeapSize); + chunkIsEmpty[i] = sweepChunk(header, &itemsInUse[header->itemSize >> 4], engine, &m_d->unmanagedHeapSize); } QVector<PageAllocation>::iterator chunkIter = m_d->heapChunks.begin(); @@ -444,7 +445,7 @@ void MemoryManager::sweep(bool lastSweep) // Release that chunk if it could have been spared since the last GC run without any difference. if (chunkIsEmpty[i] && m_d->availableItems[pos] - decrease >= itemsInUse[pos]) { - Q_V4_PROFILE_DEALLOC(m_d->engine, 0, chunkIter->size(), Profiling::HeapPage); + Q_V4_PROFILE_DEALLOC(engine, 0, chunkIter->size(), Profiling::HeapPage); #ifdef V4_USE_VALGRIND VALGRIND_MEMPOOL_FREE(this, header); #endif @@ -476,17 +477,17 @@ void MemoryManager::sweep(bool lastSweep) m->vtable()->destroy(m); *last = i->next; - free(Q_V4_PROFILE_DEALLOC(m_d->engine, i, i->size + sizeof(Data::LargeItem), + free(Q_V4_PROFILE_DEALLOC(engine, i, i->size + sizeof(Data::LargeItem), Profiling::LargeItem)); i = *last; } // some execution contexts are allocated on the stack, make sure we clear their markBit as well if (!lastSweep) { - QV4::ExecutionContext *ctx = engine()->currentContext; + QV4::ExecutionContext *ctx = engine->currentContext; while (ctx) { ctx->d()->clearMarkBit(); - ctx = engine()->parentContext(ctx); + ctx = engine->parentContext(ctx); } } } @@ -594,10 +595,7 @@ MemoryManager::~MemoryManager() #endif } -ExecutionEngine *MemoryManager::engine() const -{ - return m_d->engine; -} + void MemoryManager::dumpStats() const { @@ -627,13 +625,13 @@ void MemoryManager::willAllocate(std::size_t size) void MemoryManager::collectFromJSStack() const { - Value *v = m_d->engine->jsStackBase; - Value *top = m_d->engine->jsStackTop; + Value *v = engine->jsStackBase; + Value *top = engine->jsStackTop; while (v < top) { Managed *m = v->as<Managed>(); if (m && m->inUse()) // Skip pointers to already freed objects, they are bogus as well - m->mark(m_d->engine); + m->mark(engine); ++v; } } diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h index 94abf491f3..c77d5e503d 100644 --- a/src/qml/memory/qv4mm_p.h +++ b/src/qml/memory/qv4mm_p.h @@ -106,10 +106,10 @@ public: template <typename ObjectType> typename ObjectType::Data *allocateObject() { - InternalClass *ic = ObjectType::defaultInternalClass(engine()); + InternalClass *ic = ObjectType::defaultInternalClass(engine); const int size = (sizeof(typename ObjectType::Data) + (sizeof(Value) - 1)) & ~(sizeof(Value) - 1); typename ObjectType::Data *o = allocManaged<ObjectType>(size + ic->size*sizeof(Value)); - Object *prototype = ObjectType::defaultPrototype(engine()); + Object *prototype = ObjectType::defaultPrototype(engine); o->internalClass = ic; o->prototype = prototype->d(); o->inlineMemberSize = ic->size; @@ -120,7 +120,7 @@ public: template <typename ManagedType, typename Arg1> typename ManagedType::Data *allocWithStringData(std::size_t unmanagedSize, Arg1 arg1) { - Scope scope(engine()); + Scope scope(engine); Scoped<ManagedType> t(scope, allocManaged<ManagedType>(sizeof(typename ManagedType::Data), unmanagedSize)); (void)new (t->d()) typename ManagedType::Data(this, arg1); return t->d(); @@ -129,7 +129,7 @@ public: template <typename ObjectType> typename ObjectType::Data *allocObject(InternalClass *ic) { - Scope scope(engine()); + Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic)); (void)new (t->d()) typename ObjectType::Data(); return t->d(); @@ -138,7 +138,7 @@ public: template <typename ObjectType> typename ObjectType::Data *allocObject(InternalClass *ic, Object *prototype) { - Scope scope(engine()); + Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic)); t->d()->prototype = prototype->d(); (void)new (t->d()) typename ObjectType::Data(); @@ -148,7 +148,7 @@ public: template <typename ObjectType, typename Arg1> typename ObjectType::Data *allocObject(InternalClass *ic, Object *prototype, Arg1 arg1) { - Scope scope(engine()); + Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic)); t->d()->prototype = prototype->d(); (void)new (t->d()) typename ObjectType::Data(arg1); @@ -158,7 +158,7 @@ public: template <typename ObjectType, typename Arg1, typename Arg2> typename ObjectType::Data *allocObject(InternalClass *ic, Object *prototype, Arg1 arg1, Arg2 arg2) { - Scope scope(engine()); + Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic)); t->d()->prototype = prototype->d(); (void)new (t->d()) typename ObjectType::Data(arg1, arg2); @@ -168,7 +168,7 @@ public: template <typename ObjectType, typename Arg1, typename Arg2, typename Arg3> typename ObjectType::Data *allocObject(InternalClass *ic, Object *prototype, Arg1 arg1, Arg2 arg2, Arg3 arg3) { - Scope scope(engine()); + Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic)); t->d()->prototype = prototype->d(); (void)new (t->d()) typename ObjectType::Data(arg1, arg2, arg3); @@ -178,7 +178,7 @@ public: template <typename ObjectType, typename Arg1, typename Arg2, typename Arg3, typename Arg4> typename ObjectType::Data *allocObject(InternalClass *ic, Object *prototype, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) { - Scope scope(engine()); + Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>(ic)); t->d()->prototype = prototype->d(); (void)new (t->d()) typename ObjectType::Data(arg1, arg2, arg3, arg4); @@ -188,7 +188,7 @@ public: template <typename ObjectType> typename ObjectType::Data *allocObject() { - Scope scope(engine()); + Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>()); (void)new (t->d()) typename ObjectType::Data(); return t->d(); @@ -197,7 +197,7 @@ public: template <typename ObjectType, typename Arg1> typename ObjectType::Data *allocObject(Arg1 arg1) { - Scope scope(engine()); + Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>()); (void)new (t->d()) typename ObjectType::Data(arg1); return t->d(); @@ -206,7 +206,7 @@ public: template <typename ObjectType, typename Arg1, typename Arg2> typename ObjectType::Data *allocObject(Arg1 arg1, Arg2 arg2) { - Scope scope(engine()); + Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>()); (void)new (t->d()) typename ObjectType::Data(arg1, arg2); return t->d(); @@ -215,7 +215,7 @@ public: template <typename ObjectType, typename Arg1, typename Arg2, typename Arg3> typename ObjectType::Data *allocObject(Arg1 arg1, Arg2 arg2, Arg3 arg3) { - Scope scope(engine()); + Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>()); (void)new (t->d()) typename ObjectType::Data(arg1, arg2, arg3); return t->d(); @@ -224,7 +224,7 @@ public: template <typename ObjectType, typename Arg1, typename Arg2, typename Arg3, typename Arg4> typename ObjectType::Data *allocObject(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) { - Scope scope(engine()); + Scope scope(engine); Scoped<ObjectType> t(scope, allocateObject<ObjectType>()); (void)new (t->d()) typename ObjectType::Data(arg1, arg2, arg3, arg4); return t->d(); @@ -234,7 +234,7 @@ public: template <typename ManagedType> typename ManagedType::Data *alloc() { - Scope scope(engine()); + Scope scope(engine); Scoped<ManagedType> t(scope, allocManaged<ManagedType>(sizeof(typename ManagedType::Data))); (void)new (t->d()) typename ManagedType::Data(); return t->d(); @@ -243,7 +243,7 @@ public: template <typename ManagedType, typename Arg1> typename ManagedType::Data *alloc(Arg1 arg1) { - Scope scope(engine()); + Scope scope(engine); Scoped<ManagedType> t(scope, allocManaged<ManagedType>(sizeof(typename ManagedType::Data))); (void)new (t->d()) typename ManagedType::Data(arg1); return t->d(); @@ -252,7 +252,7 @@ public: template <typename ManagedType, typename Arg1, typename Arg2> typename ManagedType::Data *alloc(Arg1 arg1, Arg2 arg2) { - Scope scope(engine()); + Scope scope(engine); Scoped<ManagedType> t(scope, allocManaged<ManagedType>(sizeof(typename ManagedType::Data))); (void)new (t->d()) typename ManagedType::Data(arg1, arg2); return t->d(); @@ -261,7 +261,7 @@ public: template <typename ManagedType, typename Arg1, typename Arg2, typename Arg3> typename ManagedType::Data *alloc(Arg1 arg1, Arg2 arg2, Arg3 arg3) { - Scope scope(engine()); + Scope scope(engine); Scoped<ManagedType> t(scope, allocManaged<ManagedType>(sizeof(typename ManagedType::Data))); (void)new (t->d()) typename ManagedType::Data(arg1, arg2, arg3); return t->d(); @@ -270,7 +270,7 @@ public: template <typename ManagedType, typename Arg1, typename Arg2, typename Arg3, typename Arg4> typename ManagedType::Data *alloc(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) { - Scope scope(engine()); + Scope scope(engine); Scoped<ManagedType> t(scope, allocManaged<ManagedType>(sizeof(typename ManagedType::Data))); (void)new (t->d()) typename ManagedType::Data(arg1, arg2, arg3, arg4); return t->d(); @@ -279,7 +279,7 @@ public: template <typename ManagedType, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> typename ManagedType::Data *alloc(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5) { - Scope scope(engine()); + Scope scope(engine); Scoped<ManagedType> t(scope, allocManaged<ManagedType>(sizeof(typename ManagedType::Data))); (void)new (t->d()) typename ManagedType::Data(arg1, arg2, arg3, arg4, arg5); return t->d(); @@ -289,8 +289,6 @@ public: void setGCBlocked(bool blockGC); void runGC(); - ExecutionEngine *engine() const; - void dumpStats() const; size_t getUsedMem() const; @@ -313,9 +311,9 @@ private: void mark(); void sweep(bool lastSweep = false); -protected: - QScopedPointer<Data> m_d; public: + QV4::ExecutionEngine *engine; + QScopedPointer<Data> m_d; PersistentValueStorage *m_persistentValues; PersistentValueStorage *m_weakValues; }; |