Fix gc on ia32
authorSimon Hausmann <simon.hausmann@digia.com>
Sat, 8 Dec 2012 04:18:22 +0000 (05:18 +0100)
committerLars Knoll <lars.knoll@digia.com>
Sat, 8 Dec 2012 04:27:33 +0000 (05:27 +0100)
* 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 <lars.knoll@digia.com>
qv4mm.cpp
qv4mm.h

index 4be7219..8fe3815 100644 (file)
--- a/qv4mm.cpp
+++ b/qv4mm.cpp
@@ -37,6 +37,7 @@
 #include <QLinkedList>
 
 #include <iostream>
+#include <malloc.h>
 
 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 (file)
--- 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