Skip to content

Commit def10ce

Browse files
committed
gc: Keep debug statements at beginning of scope where possible
1 parent bbcea3f commit def10ce

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

py/gc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
#if MICROPY_ENABLE_GC
4242

43-
#if 0 // print debugging info
43+
#if 1 // print debugging info
4444
#define DEBUG_PRINT (1)
4545
#define DEBUG_printf DEBUG_printf
4646
#else // don't print debugging info
@@ -113,14 +113,14 @@ STATIC machine_uint_t gc_lock_depth;
113113
void gc_init(void *start, void *end) {
114114
// align end pointer on block boundary
115115
end = (void*)((machine_uint_t)end & (~(BYTES_PER_BLOCK - 1)));
116+
DEBUG_printf("Initializing GC heap: %p..%p = " UINT_FMT " bytes\n", start, end, (byte*)end - (byte*)start);
116117

117118
// calculate parameters for GC (T=total, A=alloc table, F=finaliser table, P=pool; all in bytes):
118119
// T = A + F + P
119120
// F = A * BLOCKS_PER_ATB / BLOCKS_PER_FTB
120121
// P = A * BLOCKS_PER_ATB * BYTES_PER_BLOCK
121122
// => T = A * (1 + BLOCKS_PER_ATB / BLOCKS_PER_FTB + BLOCKS_PER_ATB * BYTES_PER_BLOCK)
122123
machine_uint_t total_byte_len = (byte*)end - (byte*)start;
123-
DEBUG_printf("Initializing GC heap: %p..%p = " UINT_FMT " bytes\n", start, end, total_byte_len);
124124
#if MICROPY_ENABLE_FINALISER
125125
gc_alloc_table_byte_len = total_byte_len * BITS_PER_BYTE / (BITS_PER_BYTE + BITS_PER_BYTE * BLOCKS_PER_ATB / BLOCKS_PER_FTB + BITS_PER_BYTE * BLOCKS_PER_ATB * BYTES_PER_BLOCK);
126126
#else
@@ -348,6 +348,7 @@ void gc_info(gc_info_t *info) {
348348

349349
void *gc_alloc(machine_uint_t n_bytes, bool has_finaliser) {
350350
machine_uint_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK;
351+
DEBUG_printf("gc_alloc(" UINT_FMT " bytes -> " UINT_FMT " blocks)\n", n_bytes, n_blocks);
351352

352353
// check if GC is locked
353354
if (gc_lock_depth > 0) {
@@ -401,7 +402,7 @@ void *gc_alloc(machine_uint_t n_bytes, bool has_finaliser) {
401402

402403
// get pointer to first block
403404
void *ret_ptr = (void*)(gc_pool_start + start_block * WORDS_PER_BLOCK);
404-
DEBUG_printf("gc_alloc(" UINT_FMT " bytes -> " UINT_FMT " blocks ptr %p)\n", n_bytes, n_blocks, ret_ptr);
405+
DEBUG_printf("gc_alloc(%p)\n", ret_ptr);
405406

406407
// zero out the additional bytes of the newly allocated blocks
407408
// This is needed because the blocks may have previously held pointers

0 commit comments

Comments
 (0)