Permalink
Browse files

Add GC debug helper to "find" a pointer.

Discovers which, if any, fromspace/tospace region or gen2 allocator
page it exists within. Only compiled in if GC debugging is enabled.
  • Loading branch information...
1 parent ee0b54e commit c63d64987c0c8276fdc183f30cb077b3f8e7bce3 @jnthn jnthn committed Nov 30, 2016
Showing with 45 additions and 0 deletions.
  1. +1 −0 build/Makefile.in
  2. +44 −0 src/gc/debug.c
View
@@ -101,6 +101,7 @@ OBJECTS = src/core/callsite@obj@ \
src/gc/wb@obj@ \
src/gc/objectid@obj@ \
src/gc/finalize@obj@ \
+ src/gc/debug@obj@ \
src/io/io@obj@ \
src/io/eventloop@obj@ \
src/io/syncfile@obj@ \
View
@@ -0,0 +1,44 @@
+#include "moar.h"
+
+#if MVM_GC_DEBUG
+/* Takes a pointer of a GC-allocated object, and goes through all of the
+ * alive thread's fromspace/tospace regions and all gen2 pages to try and
+ * find the region the pointer is part of. */
+void MVM_gc_debug_find_region(MVMThreadContext *tc, void *ptr) {
+ MVMThread *cur_thread = tc->instance->threads;
+ while (cur_thread) {
+ MVMThreadContext *thread_tc = cur_thread->body.tc;
+ if (thread_tc) {
+ if (ptr >= thread_tc->nursery_fromspace &&
+ ptr < thread_tc->nursery_fromspace + MVM_NURSERY_SIZE) {
+ printf("In fromspace of thread %d\n", cur_thread->body.thread_id);
+ return;
+ }
+ if (ptr >= thread_tc->nursery_tospace &&
+ ptr < thread_tc->nursery_tospace + MVM_NURSERY_SIZE) {
+ printf("In tospace of thread %d\n", cur_thread->body.thread_id);
+ return;
+ }
+ if (thread_tc->gen2) {
+ MVMGen2Allocator *gen2 = thread_tc->gen2;
+ MVMint32 bin;
+ for (bin = 0; bin < MVM_GEN2_BINS; bin++) {
+ MVMGen2SizeClass *szc = &(gen2->size_classes[bin]);
+ MVMint32 page;
+ for (page = 0; page < szc->num_pages; page++) {
+ char *page_start = szc->pages[page];
+ size_t page_size = MVM_GEN2_PAGE_ITEMS * ((bin + 1) << MVM_GEN2_BIN_BITS);
+ char *page_end = page_start + page_size;
+ if (ptr >= (void*)page_start && ptr < (void*)page_end) {
+ printf("In gen2 bin of thread %d", cur_thread->body.thread_id);
+ return;
+ }
+ }
+ }
+ }
+ }
+ cur_thread = cur_thread->body.next;
+ }
+ printf("Not found\n");
+}
+#endif

0 comments on commit c63d649

Please sign in to comment.