Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created January 19, 2018 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenderlove/4e74aebeb308cfa00306a186a26c0b8d to your computer and use it in GitHub Desktop.
Save tenderlove/4e74aebeb308cfa00306a186a26c0b8d to your computer and use it in GitHub Desktop.
diff --git a/gc.c b/gc.c
index 0316cf243b..1ffac2d9b7 100644
--- a/gc.c
+++ b/gc.c
@@ -33,6 +33,7 @@
#include <stdarg.h>
#include <setjmp.h>
#include <sys/types.h>
+#include <dlfcn.h>
#include "ruby_assert.h"
#include "debug_counter.h"
@@ -1058,6 +1059,27 @@ RVALUE_FLAGS_AGE(VALUE flags)
#endif /* USE_RGENGC */
+void
+rb_dump_stack()
+{
+#if HAVE_BACKTRACE
+#define MAX_NATIVE_TRACE 1024
+ int i;
+ static void *trace[MAX_NATIVE_TRACE];
+ int n = (int)backtrace(trace, MAX_NATIVE_TRACE);
+
+ if (n == 0) return;
+
+ for(i = 1; i < n; i++) {
+ Dl_info info;
+ if (dladdr(trace[i], &info) && info.dli_sname) {
+ fputs(info.dli_sname, stderr);
+ if (i < n - 1) fputs(" | ", stderr);
+ }
+ }
+ fputs("\n", stderr);
+#endif
+}
#if RGENGC_CHECK_MODE == 0
static inline VALUE
@@ -1968,13 +1990,18 @@ newobj_of(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, int wb_protect
ruby_gc_stressful ||
gc_event_hook_available_p(objspace)) &&
(obj = heap_get_freeobj_head(objspace, heap_eden)) != Qfalse) {
- return newobj_init(klass, flags, v1, v2, v3, wb_protected, objspace, obj);
+ obj = newobj_init(klass, flags, v1, v2, v3, wb_protected, objspace, obj);
}
else {
- return wb_protected ?
+ obj = wb_protected ?
newobj_slowpath_wb_protected(klass, flags, v1, v2, v3, objspace) :
newobj_slowpath_wb_unprotected(klass, flags, v1, v2, v3, objspace);
}
+ if (getenv("DUMP")) {
+ fprintf(stderr, "%p | ", obj);
+ rb_dump_stack();
+ }
+ return obj;
}
VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment