* 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>
#include <QLinkedList>
#include <iostream>
+#include <malloc.h>
using namespace QQmlJS::VM;
willAllocate(size);
#endif // DETAILED_MM_STATS
- size += sizeof(MMInfo);
+ size += align(sizeof(MMInfo));
assert(size >= 16);
assert(size % 16 == 0);
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);
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;
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