Skip to content

Commit 39d777c

Browse files
stinosdpgeorge
authored andcommitted
py/gc: Differentiate between root and subtree pointers for debug log.
This is more informative when debugging possible gc issues. Signed-off-by: stijn <stijn@ignitron.net>
1 parent eaf03bd commit 39d777c

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

py/gc.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,22 @@ static inline mp_state_mem_area_t *gc_get_ptr_area(const void *ptr) {
383383
&& ptr < (void *)MP_STATE_MEM(area).gc_pool_end /* must be below end of pool */ \
384384
)
385385

386-
#ifndef TRACE_MARK
386+
#ifdef TRACE_MARK
387+
#error "TRACE_MARK is replaced by TRACE_MARK_R and TRACE_MARK_S"
388+
#endif
389+
// R for root pointer, S for subtree.
390+
#ifndef TRACE_MARK_R
391+
#if DEBUG_PRINT
392+
#define TRACE_MARK_R(block, ptr) DEBUG_printf("gc_mark_r(%p)\n", ptr)
393+
#else
394+
#define TRACE_MARK_R(block, ptr)
395+
#endif
396+
#endif
397+
#ifndef TRACE_MARK_S
387398
#if DEBUG_PRINT
388-
#define TRACE_MARK(block, ptr) DEBUG_printf("gc_mark(%p)\n", ptr)
399+
#define TRACE_MARK_S(block, ptr) DEBUG_printf("gc_mark_s(%p)\n", ptr)
389400
#else
390-
#define TRACE_MARK(block, ptr)
401+
#define TRACE_MARK_S(block, ptr)
391402
#endif
392403
#endif
393404

@@ -439,7 +450,7 @@ void gc_collect_root(void **ptrs, size_t len) {
439450
size_t block = BLOCK_FROM_PTR(area, ptr);
440451
if (ATB_GET_KIND(area, block) == AT_HEAD) {
441452
// An unmarked head: mark it, and mark all its children
442-
TRACE_MARK(ptr_block, ptr);
453+
TRACE_MARK_R(ptr_block, ptr);
443454
ATB_HEAD_TO_MARK(area, block);
444455
#if MICROPY_GC_SPLIT_HEAP
445456
gc_mark_subtree(area, block);
@@ -501,7 +512,7 @@ static void gc_mark_subtree(size_t block)
501512
continue;
502513
}
503514
// An unmarked head. Mark it, and push it on gc stack.
504-
TRACE_MARK(ptr_block, ptr);
515+
TRACE_MARK_S(ptr_block, ptr);
505516
ATB_HEAD_TO_MARK(ptr_area, ptr_block);
506517
if (sp < MICROPY_ALLOC_GC_STACK_SIZE) {
507518
MP_STATE_MEM(gc_block_stack)[sp] = ptr_block;

0 commit comments

Comments
 (0)