Add the "-Xgc:[no]overwritefree" flags. When set, the GC will clobber the
memory of freed objects.
diff --git a/vm/alloc/MarkSweep.c b/vm/alloc/MarkSweep.c
index 70b5269..4070f48 100644
--- a/vm/alloc/MarkSweep.c
+++ b/vm/alloc/MarkSweep.c
@@ -1118,6 +1118,7 @@
sweepBitmapCallback(size_t numPtrs, void **ptrs, const void *finger, void *arg)
{
const ClassObject *const classJavaLangClass = gDvm.classJavaLangClass;
+ const bool overwriteFree = gDvm.overwriteFree;
size_t i;
void **origPtrs = ptrs;
@@ -1147,18 +1148,16 @@
dvmFreeClassInnards((ClassObject *)obj);
}
-#if 0
/* Overwrite the to-be-freed object to make stale references
* more obvious.
*/
- {
+ if (overwriteFree) {
int chunklen;
ClassObject *clazz = obj->clazz;
chunklen = dvmHeapSourceChunkSize(obj);
memset(hc, 0xa5, chunklen);
obj->clazz = (ClassObject *)((uintptr_t)clazz ^ 0xffffffff);
}
-#endif
}
// TODO: dvmHeapSourceFreeList has a loop, just like the above
// does. Consider collapsing the two loops to save overhead.