Permalink
Browse files

GC: changed the heap walk API to also report the offset of referenced…

… objects.
  • Loading branch information...
1 parent 5ea94df commit 328b795c2e7a1063e8fa42fa408a2bafeb5d875e @illupus illupus committed Nov 12, 2010
Showing with 7 additions and 3 deletions.
  1. +1 −1 mono/metadata/mono-gc.h
  2. +6 −2 mono/metadata/sgen-gc.c
View
@@ -9,7 +9,7 @@
MONO_BEGIN_DECLS
-typedef int (*MonoGCReferences) (MonoObject *obj, MonoClass *klass, uintptr_t size, uintptr_t num, MonoObject **refs, void *data);
+typedef int (*MonoGCReferences) (MonoObject *obj, MonoClass *klass, uintptr_t size, uintptr_t num, MonoObject **refs, uintptr_t *offsets, void *data);
void mono_gc_collect (int generation);
int mono_gc_max_generation (void);
View
@@ -6329,16 +6329,18 @@ typedef struct {
int count;
int called;
MonoObject *refs [REFS_SIZE];
+ uintptr_t offsets [REFS_SIZE];
} HeapWalkInfo;
#undef HANDLE_PTR
#define HANDLE_PTR(ptr,obj) do { \
if (*(ptr)) { \
if (hwi->count == REFS_SIZE) { \
- hwi->callback ((MonoObject*)start, mono_object_class (start), hwi->called? 0: size, hwi->count, hwi->refs, hwi->data); \
+ hwi->callback ((MonoObject*)start, mono_object_class (start), hwi->called? 0: size, hwi->count, hwi->refs, hwi->offsets, hwi->data); \
hwi->count = 0; \
hwi->called = 1; \
} \
+ hwi->offsets [hwi->count] = (char*)(ptr)-(char*)start; \
hwi->refs [hwi->count++] = *(ptr); \
} \
} while (0)
@@ -6357,7 +6359,7 @@ walk_references (char *start, size_t size, void *data)
hwi->count = 0;
collect_references (hwi, start, size);
if (hwi->count || !hwi->called)
- hwi->callback ((MonoObject*)start, mono_object_class (start), hwi->called? 0: size, hwi->count, hwi->refs, hwi->data);
+ hwi->callback ((MonoObject*)start, mono_object_class (start), hwi->called? 0: size, hwi->count, hwi->refs, hwi->offsets, hwi->data);
}
/**
@@ -6369,6 +6371,8 @@ walk_references (char *start, size_t size, void *data)
* This function can be used to iterate over all the live objects in the heap:
* for each object, @callback is invoked, providing info about the object's
* location in memory, its class, its size and the objects it references.
+ * For each referenced object it's offset from the object address is
+ * reported in the offsets array.
* The object references may be buffered, so the callback may be invoked
* multiple times for the same object: in all but the first call, the size
* argument will be zero.

0 comments on commit 328b795

Please sign in to comment.