Fix failing assertions in GC on ia32
authorSimon Hausmann <simon.hausmann@digia.com>
Fri, 14 Dec 2012 08:46:25 +0000 (09:46 +0100)
committerLars Knoll <lars.knoll@digia.com>
Fri, 14 Dec 2012 12:00:32 +0000 (13:00 +0100)
We currently round up allocation sizes to 16-bytes on 32 and 64-bit.
When recursively calling alloc() after the allocation of a new heap chunk,
make sure to adjust the requested size parameter again to its original value,
to ensure 16 byte alignment.

Change-Id: Ie8cd29d60639bf43023a310b7be6f772305fa826
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
qv4mm.cpp

index abfd120..322ad97 100644 (file)
--- a/qv4mm.cpp
+++ b/qv4mm.cpp
@@ -96,7 +96,8 @@ MemoryManager::MMObject *MemoryManager::alloc(std::size_t size)
     willAllocate(size);
 #endif // DETAILED_MM_STATS
 
-    size += align(sizeof(MMInfo));
+    const std::size_t alignedSizeOfMMInfo = align(sizeof(MMInfo));
+    size += alignedSizeOfMMInfo;
 
     assert(size >= 16);
     assert(size % 16 == 0);
@@ -139,7 +140,7 @@ MemoryManager::MMObject *MemoryManager::alloc(std::size_t size)
             m_d->fallbackObject->info.markBit = 0;
             m_d->fallbackObject->info.size = allocSize;
         }
-        return alloc(size - sizeof(MMInfo));
+        return alloc(size - alignedSizeOfMMInfo);
     }
 
     MMObject *m = it.value();