From: Simon Hausmann Date: Sat, 8 Dec 2012 04:18:22 +0000 (+0100) Subject: Fix gc on ia32 X-Git-Tag: upstream/5.2.1~669^2~659^2~738 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=852cc7f443f2321b0c53077f3fc0cee577903199;p=platform%2Fupstream%2Fqtdeclarative.git Fix gc on ia32 * size += sizeof(MMInfo) risk unaligning size, to run it through align() again * Don't rely on new returning an aligned pointer, use memalign * Enable #ifdefs for 32-bit MMInfo/MMObject Change-Id: If22abb9e0d77ece385793ea5e92540f177d3a07c Reviewed-by: Lars Knoll --- diff --git a/qv4mm.cpp b/qv4mm.cpp index 4be7219..8fe3815 100644 --- a/qv4mm.cpp +++ b/qv4mm.cpp @@ -37,6 +37,7 @@ #include #include +#include using namespace QQmlJS::VM; @@ -93,7 +94,7 @@ MemoryManager::MMObject *MemoryManager::alloc(std::size_t size) willAllocate(size); #endif // DETAILED_MM_STATS - size += sizeof(MMInfo); + size += align(sizeof(MMInfo)); assert(size >= 16); assert(size % 16 == 0); @@ -126,7 +127,7 @@ MemoryManager::MMObject *MemoryManager::alloc(std::size_t size) return alloc(size - sizeof(MMInfo)); std::size_t allocSize = std::max(size, CHUNK_SIZE); - char *ptr = new char[allocSize]; + char *ptr = (char*)memalign(16, allocSize); m_d->heapChunks.append(qMakePair(ptr, allocSize)); // qDebug("Allocated new chunk of %lu bytes @ %p", allocSize, ptr); diff --git a/qv4mm.h b/qv4mm.h index ece3765..85395b9 100644 --- a/qv4mm.h +++ b/qv4mm.h @@ -106,8 +106,8 @@ public: void dumpStats() const; protected: -#if 1 // 64bit and x86: struct MMObject; +#if CPU(X86_64) // 64bit and x86: struct MMInfo { std::size_t inUse : 1; std::size_t markBit : 1; @@ -119,20 +119,17 @@ protected: MMInfo info; std::size_t data; }; -#endif -#if 0 // for 32bits: - // untested! +#elif CPU(X86) // for 32bits: struct MMInfo { std::size_t inUse : 1; std::size_t markBit : 1; - std::size_t size : 30; + std::size_t needsManagedDestructorCall : 1; + std::size_t size : 29; + struct MMObject *next; }; struct MMObject { MMInfo info; - union { - struct MMObject *next; - char data[1]; - } + std::size_t data; }; #endif