};
QVector<Chunk> heapChunks;
+ QHash<Managed *, uint> protectedObject;
// statistics:
#ifdef DETAILED_MM_STATS
::memset((void *)(obj + 1), c, size - sizeof(Managed));
}
-void MemoryManager::mark(const QVector<Object *> &objects)
+void MemoryManager::mark(const QVector<Managed *> &objects)
{
- foreach (Object *o, objects) {
- if (!o)
+ foreach (Managed *m, objects) {
+ if (!m)
continue;
- o->mark();
+ m->mark();
}
return;
// QTime t; t.start();
// qDebug() << ">>>>>>>>runGC";
- QVector<Object *> roots;
+ QVector<Managed *> roots;
collectRoots(roots);
// std::cerr << "GC: found " << roots.size()
// << " roots in " << t.elapsed()
sweep();
}
-static inline void add(QVector<Object *> &values, const Value &v)
+void MemoryManager::protect(Managed *m)
+{
+ ++m_d->protectedObject[m];
+}
+
+void MemoryManager::unprotect(Managed *m)
+{
+ if (!--m_d->protectedObject[m])
+ m_d->protectedObject.remove(m);
+}
+
+static inline void add(QVector<Managed *> &values, const Value &v)
{
if (Object *o = v.asObject())
values.append(o);
#endif // DETAILED_MM_STATS
-void MemoryManager::collectRoots(QVector<VM::Object *> &roots) const
+void MemoryManager::collectRoots(QVector<Managed *> &roots) const
{
add(roots, m_d->engine->globalObject);
add(roots, m_d->engine->exception);
}
collectRootsOnStack(roots);
+
+ for (QHash<Managed *, uint>::const_iterator it = m_d->protectedObject.begin(); it != m_d->protectedObject.constEnd(); ++it)
+ roots.append(it.key());
}
-void MemoryManager::collectRootsOnStack(QVector<VM::Object *> &roots) const
+void MemoryManager::collectRootsOnStack(QVector<VM::Managed *> &roots) const
{
if (!m_d->heapChunks.count())
return;
MemoryManager();
~MemoryManager();
+ void protect(Managed *m);
+ void unprotect(Managed *m);
+
// TODO: this is only for 64bit (and x86 with SSE/AVX), so exend it for other architectures to be slightly more efficient (meaning, align on 8-byte boundaries).
// Note: all occurances of "16" in alloc/dealloc are also due to the alignment.
static inline std::size_t align(std::size_t size)
void scribble(Managed *obj, int c, int size) const;
- void collectRootsOnStack(QVector<VM::Object *> &roots) const;
+ void collectRootsOnStack(QVector<Managed *> &roots) const;
ExecutionEngine *engine() const;
#endif // DETAILED_MM_STATS
private:
- void collectRoots(QVector<VM::Object *> &roots) const;
- static void mark(const QVector<Object *> &objects);
+ void collectRoots(QVector<VM::Managed *> &roots) const;
+ static void mark(const QVector<Managed *> &objects);
std::size_t sweep();
std::size_t sweep(char *chunkStart, std::size_t chunkSize, size_t size);