Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Last active April 28, 2019 19:28
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 MasterDuke17/768644375e173390a6f2ca3ad1be78c4 to your computer and use it in GitHub Desktop.
Save MasterDuke17/768644375e173390a6f2ca3ad1be78c4 to your computer and use it in GitHub Desktop.
diff --git a/src/gc/allocation.c b/src/gc/allocation.c
index 06a37ffad..30901b7ab 100644
--- a/src/gc/allocation.c
+++ b/src/gc/allocation.c
@@ -4,6 +4,7 @@
* its REPR gc_free routine. */
#include "moar.h"
+#include "memdebug.h"
/* Allocate the specified amount of memory from the nursery. Will
* trigger a GC run if there is not enough. */
@@ -88,6 +89,9 @@ MVMObject * MVM_gc_allocate_object(MVMThreadContext *tc, MVMSTable *st) {
MVMObject *obj;
MVMROOT(tc, st, {
obj = MVM_gc_allocate_zeroed(tc, st->size);
+#ifdef MVM_VALGRIND_SUPPORT
+ VALGRIND_CREATE_BLOCK(obj, st->size, st->debug_name);
+#endif
obj->header.size = (MVMuint16)st->size;
obj->header.owner = tc->thread_id;
MVM_ASSIGN_REF(tc, &(obj->header), obj->st, st);
diff --git a/src/gc/debug.h b/src/gc/debug.h
index 1dd4f17bb..6daf4c9ef 100644
--- a/src/gc/debug.h
+++ b/src/gc/debug.h
@@ -3,7 +3,7 @@
* 1 = Checks on reference assignments and other relatively cheap cases
* 2 = Checks on every object register access (slow)
*/
-#define MVM_GC_DEBUG 0
+#define MVM_GC_DEBUG 2
#if MVM_GC_DEBUG
#define MVM_ASSERT_NOT_FROMSPACE(tc, c) do { \
diff --git a/src/gc/worklist.h b/src/gc/worklist.h
index 062f383d8..9725ca934 100644
--- a/src/gc/worklist.h
+++ b/src/gc/worklist.h
@@ -1,3 +1,4 @@
+#include "memdebug.h"
/* A worklist holds the current set of pointers we have got in the queue
* to scan. We hide away the details of it behind this abstraction since
* the order in which we hand things back from it can have a big influence
@@ -48,9 +49,12 @@ struct MVMGCWorklist {
else if (((*item_to_add)->flags & MVM_CF_STABLE) == 0 && !STABLE(*item_to_add)) \
MVM_panic(1, "NULL STable in item added to GC worklist"); \
if ((char *)*item_to_add >= (char *)tc->nursery_alloc && \
- (char *)*item_to_add < (char *)tc->nursery_alloc_limit) \
+ (char *)*item_to_add < (char *)tc->nursery_alloc_limit) { \
+ char command[128]; snprintf(&command, 128, "who_points_at %p", *item_to_add); VALGRIND_MONITOR_COMMAND(command); \
+ VALGRIND_PRINTF_BACKTRACE("valgrind gc_worklist_add: Adding pointer %p to past fromspace to GC worklist", *item_to_add); \
MVM_panic(1, "Adding pointer %p to past fromspace to GC worklist", \
*item_to_add); \
+ } \
} \
if (*item_to_add && (worklist->include_gen2 || !((*item_to_add)->flags & MVM_CF_SECOND_GEN))) { \
if (worklist->items == worklist->alloc) \
[dan@alexandria p6-mqtt]$ MVM_JIT_DISABLE=1 pv6 --profile -I lib/ t/regex.t
================================================================================================
This is Rakudo Perl 6 running in valgrind, a tool for debugging and profiling programs.
Running a program in valgrind usually takes *a lot* more time than running it directly,
so please be patient.
Valgrind options can be added with MVM_VALGRIND_OPTS environment variable.
This Rakudo version is 2019.03.1.248.g.4.e.677.f.048 built on MoarVM version 2019.03.102.g.423.a.9.cc.7.d,
running on arch (5.0.8.arch.1.1.arch) / linux (1.SMP.PREEMPT.Wed.Mar.27.17.53.10.UTC.2019)
------------------------------------------------------------------------------------------------
==13645== Memcheck, a memory error detector
==13645== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==13645== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==13645== Command: /home/dan/Source/perl6/install/bin/perl6-m --profile -I lib/ t/regex.t
==13645==
ok 1 - 4.7.1.2, 'sport/tennis/player1' should match 'sport/tennis/player1/ \#'
ok 2 - 4.7.1.2, 'sport/tennis/player1/ranking' should match 'sport/tennis/player1/ \#'
ok 3 - 4.7.1.2, 'sport/tennis/player1/wimbledon' should match 'sport/tennis/player1/ \#'
ok 4 - 4.7.1.2, 'sport' should match 'sport/ \#'
ok 5 - 4.7.1.3, 'sport/tennis/player1' should match 'sport/tennis/+'
ok 6 - 4.7.1.3, 'sport/tennis/player2' should match 'sport/tennis/+'
ok 7 - 4.7.1.3, 'sport/tennis/player1/ranking' should not match 'sport/tennis/+'
ok 8 - 4.7.1.3, 'sport' should not match 'sport/+'
ok 9 - 4.7.1.3, 'sport/' should match 'sport/+'
ok 10 - 4.7.2.1, '$SYS/something' should not match ' \#'
ok 11 - 4.7.2.1, '$SYS/monitor/Clients' should not match '+/monitor/Clients'
==13645== Searching for pointers to 0x5981148
==13645== *0x59810f8 points at 0x5981148
==13645== Address 0x59810f8 is 8 bytes inside a BOOTCode of size 72 client-defined
==13645== at 0x4A7B8E7: MVM_gc_allocate_object (allocation.c:90)
==13645== by 0x4A563AB: MVM_frame_takeclosure (frame.c:1195)
==13645== by 0x4A40E47: MVM_interp_run (interp.c:1230)
==13645== by 0x4B5DFA4: MVM_vm_run_file (moar.c:444)
==13645== by 0x109FB8: main (main.c:341)
==13645== *0xc2f2920 points at 0x5981148
==13645== Address 0xc2f2920 is 1,632 bytes inside a block of size 2,112 alloc'd
==13645== at 0x483AD7B: realloc (vg_replace_malloc.c:826)
==13645== by 0x4B568E8: MVM_realloc (alloc.h:20)
==13645== by 0x4B568E8: MVM_profiler_log_gc_deallocate (log.c:320)
==13645== by 0x4A840D0: MVM_gc_collect_free_nursery_uncopied (collect.c:628)
==13645== by 0x4A7A6CE: finish_gc (orchestrate.c:237)
==13645== by 0x4A7A6CE: run_gc (orchestrate.c:412)
==13645== by 0x4A7B1CE: MVM_gc_enter_from_allocator (orchestrate.c:525)
==13645== by 0x4A7B545: MVM_gc_allocate_nursery (allocation.c:36)
==13645== by 0x4A7B890: MVM_gc_allocate_object (allocation.c:90)
==13645== by 0x4A1E171: MVM_args_set_result_str (args.c:543)
==13645== by 0x4A2CED2: MVM_interp_run (interp.c:528)
==13645== by 0x4B5DFA4: MVM_vm_run_file (moar.c:444)
==13645== by 0x109FB8: main (main.c:341)
==13645== tid 1 register R11 pointing at 0x5981148
**13645** valgrind gc_worklist_add: Adding pointer 0x5981148 to past fromspace to GC worklist at 0x4B53425: VALGRIND_PRINTF_BACKTRACE.constprop.6 (valgrind.h:6306)
==13645== by 0x4B55B49: mark_gc_entries (instrument.c:807)
==13645== by 0x4B55B49: MVM_profile_instrumented_mark_data (instrument.c:830)
==13645== by 0x4A7E967: MVM_gc_root_add_tc_roots_to_worklist (roots.c:191)
==13645== by 0x4A83A37: MVM_gc_collect (collect.c:121)
==13645== by 0x4A7A5AE: run_gc (orchestrate.c:408)
==13645== by 0x4A7B1CE: MVM_gc_enter_from_allocator (orchestrate.c:525)
==13645== by 0x4A7B545: MVM_gc_allocate_nursery (allocation.c:36)
==13645== by 0x4A7B890: MVM_gc_allocate_object (allocation.c:90)
==13645== by 0x4A39E46: MVM_interp_run (interp.c:1869)
==13645== by 0x4B5DFA4: MVM_vm_run_file (moar.c:444)
==13645== by 0x109FB8: main (main.c:341)
MoarVM panic: Adding pointer 0x5981148 to past fromspace to GC worklist
==13645==
==13645== HEAP SUMMARY:
==13645== in use at exit: 94,844,289 bytes in 312,884 blocks
==13645== total heap usage: 900,937 allocs, 355,987 frees, 389,570,882 bytes allocated
==13645==
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment