diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2016-07-25 17:09:38 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2016-07-28 11:03:25 +0000 |
commit | 901b975fb5be147b9bb446c7b9f61c2d448a94ab (patch) | |
tree | 48edb0198ef109c7d3ea7faa0a83fadc6a80c185 /src | |
parent | c685165038e10464da877896d1accb7b75d9086e (diff) |
V4: Don't pass size and pointer through allocation trackers
By not relying on the return value of the macros we can #define them
away later, when compiling with -no-qml-debug
Change-Id: I24d50fa3f5d8e8765a42b050c81ddfae20f20a23
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4profiling_p.h | 41 | ||||
-rw-r--r-- | src/qml/memory/qv4mm.cpp | 24 |
2 files changed, 32 insertions, 33 deletions
diff --git a/src/qml/jsruntime/qv4profiling_p.h b/src/qml/jsruntime/qv4profiling_p.h index a422dd0fb6..c684d48368 100644 --- a/src/qml/jsruntime/qv4profiling_p.h +++ b/src/qml/jsruntime/qv4profiling_p.h @@ -59,6 +59,22 @@ QT_BEGIN_NAMESPACE +#define Q_V4_PROFILE_ALLOC(engine, size, type)\ + (engine->profiler &&\ + (engine->profiler->featuresEnabled & (1 << Profiling::FeatureMemoryAllocation)) ?\ + engine->profiler->trackAlloc(size, type) : false) + +#define Q_V4_PROFILE_DEALLOC(engine, size, type) \ + (engine->profiler &&\ + (engine->profiler->featuresEnabled & (1 << Profiling::FeatureMemoryAllocation)) ?\ + engine->profiler->trackDealloc(size, type) : false) + +#define Q_V4_PROFILE(engine, function)\ + (engine->profiler &&\ + (engine->profiler->featuresEnabled & (1 << Profiling::FeatureFunctionCall)) ?\ + Profiling::FunctionCallProfiler::profileCall(engine->profiler, engine, function) :\ + function->code(engine, function->codeData)) + namespace QV4 { namespace Profiling { @@ -150,25 +166,8 @@ private: qint64 m_end; }; -#define Q_V4_PROFILE_ALLOC(engine, size, type)\ - (engine->profiler &&\ - (engine->profiler->featuresEnabled & (1 << Profiling::FeatureMemoryAllocation)) ?\ - engine->profiler->trackAlloc(size, type) : size) - -#define Q_V4_PROFILE_DEALLOC(engine, pointer, size, type) \ - (engine->profiler &&\ - (engine->profiler->featuresEnabled & (1 << Profiling::FeatureMemoryAllocation)) ?\ - engine->profiler->trackDealloc(pointer, size, type) : pointer) - -#define Q_V4_PROFILE(engine, function)\ - (engine->profiler &&\ - (engine->profiler->featuresEnabled & (1 << Profiling::FeatureFunctionCall)) ?\ - Profiling::FunctionCallProfiler::profileCall(engine->profiler, engine, function) :\ - function->code(engine, function->codeData)) - class Q_QML_EXPORT Profiler : public QObject { Q_OBJECT - Q_DISABLE_COPY(Profiler) public: struct SentMarker { SentMarker() : m_function(nullptr) {} @@ -212,18 +211,18 @@ public: Profiler(QV4::ExecutionEngine *engine); - size_t trackAlloc(size_t size, MemoryType type) + bool trackAlloc(size_t size, MemoryType type) { MemoryAllocationProperties allocation = {m_timer.nsecsElapsed(), (qint64)size, type}; m_memory_data.append(allocation); - return size; + return true; } - void *trackDealloc(void *pointer, size_t size, MemoryType type) + bool trackDealloc(size_t size, MemoryType type) { MemoryAllocationProperties allocation = {m_timer.nsecsElapsed(), -(qint64)size, type}; m_memory_data.append(allocation); - return pointer; + return true; } quint64 featuresEnabled; diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp index a8d5624550..a6d7c3b1ed 100644 --- a/src/qml/memory/qv4mm.cpp +++ b/src/qml/memory/qv4mm.cpp @@ -185,7 +185,7 @@ struct MemoryManager::Data ~Data() { for (std::vector<PageAllocation>::iterator i = heapChunks.begin(), ei = heapChunks.end(); i != ei; ++i) { - Q_V4_PROFILE_DEALLOC(engine, 0, i->size(), Profiling::HeapPage); + Q_V4_PROFILE_DEALLOC(engine, i->size(), Profiling::HeapPage); i->deallocate(); } } @@ -239,7 +239,7 @@ bool sweepChunk(MemoryManager::Data::ChunkHeader *header, uint *itemsInUse, Exec #ifdef V4_USE_HEAPTRACK heaptrack_report_free(m); #endif - Q_V4_PROFILE_DEALLOC(engine, m, header->itemSize, Profiling::SmallItem); + Q_V4_PROFILE_DEALLOC(engine, header->itemSize, Profiling::SmallItem); ++(*itemsInUse); } // Relink all free blocks to rewrite references to any released chunk. @@ -302,10 +302,11 @@ Heap::Base *MemoryManager::allocData(std::size_t size, std::size_t unmanagedSize runGC(); // we use malloc for this - MemoryManager::Data::LargeItem *item = static_cast<MemoryManager::Data::LargeItem *>( - malloc(Q_V4_PROFILE_ALLOC(engine, size + sizeof(MemoryManager::Data::LargeItem), - Profiling::LargeItem))); - memset(item, 0, size + sizeof(MemoryManager::Data::LargeItem)); + const size_t totalSize = size + sizeof(MemoryManager::Data::LargeItem); + Q_V4_PROFILE_ALLOC(engine, totalSize, Profiling::LargeItem); + MemoryManager::Data::LargeItem *item = + static_cast<MemoryManager::Data::LargeItem *>(malloc(totalSize)); + memset(item, 0, totalSize); item->next = m_d->largeItems; item->size = size; m_d->largeItems = item; @@ -338,9 +339,8 @@ Heap::Base *MemoryManager::allocData(std::size_t size, std::size_t unmanagedSize shift = m_d->maxShift; std::size_t allocSize = m_d->maxChunkSize*(size_t(1) << shift); allocSize = roundUpToMultipleOf(m_d->pageSize, allocSize); - PageAllocation allocation = PageAllocation::allocate( - Q_V4_PROFILE_ALLOC(engine, allocSize, Profiling::HeapPage), - OSAllocator::JSGCHeapPages); + Q_V4_PROFILE_ALLOC(engine, allocSize, Profiling::HeapPage); + PageAllocation allocation = PageAllocation::allocate(allocSize, OSAllocator::JSGCHeapPages); m_d->heapChunks.push_back(allocation); header = reinterpret_cast<Data::ChunkHeader *>(allocation.base()); @@ -507,7 +507,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(engine, 0, chunkIter->size(), Profiling::HeapPage); + Q_V4_PROFILE_DEALLOC(engine, chunkIter->size(), Profiling::HeapPage); #ifdef V4_USE_VALGRIND VALGRIND_MEMPOOL_FREE(this, header); #endif @@ -542,8 +542,8 @@ void MemoryManager::sweep(bool lastSweep) m->vtable()->destroy(m); *last = i->next; - free(Q_V4_PROFILE_DEALLOC(engine, i, i->size + sizeof(Data::LargeItem), - Profiling::LargeItem)); + Q_V4_PROFILE_DEALLOC(engine, i->size + sizeof(Data::LargeItem), Profiling::LargeItem); + free(i); i = *last; } |