Skip to content

Commit 6a6e0b7

Browse files
committed
py/gc: Be sure to count last allocated block at heap end in stats.
Previously, if there was chain of allocated blocks ending with the last block of heap, it wasn't included in number of 1/2-block or max block size stats.
1 parent 6907496 commit 6a6e0b7

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

py/gc.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,9 @@ void gc_info(gc_info_t *info) {
327327
info->num_1block = 0;
328328
info->num_2block = 0;
329329
info->max_block = 0;
330-
for (size_t block = 0, len = 0; block < MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB; block++) {
330+
bool finish = false;
331+
for (size_t block = 0, len = 0; !finish;) {
331332
size_t kind = ATB_GET_KIND(block);
332-
if (kind == AT_FREE || kind == AT_HEAD) {
333-
if (len == 1) {
334-
info->num_1block += 1;
335-
} else if (len == 2) {
336-
info->num_2block += 1;
337-
}
338-
if (len > info->max_block) {
339-
info->max_block = len;
340-
}
341-
}
342333
switch (kind) {
343334
case AT_FREE:
344335
info->free += 1;
@@ -359,6 +350,24 @@ void gc_info(gc_info_t *info) {
359350
// shouldn't happen
360351
break;
361352
}
353+
354+
block++;
355+
finish = (block == MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB);
356+
// Get next block type if possible
357+
if (!finish) {
358+
kind = ATB_GET_KIND(block);
359+
}
360+
361+
if (finish || kind == AT_FREE || kind == AT_HEAD) {
362+
if (len == 1) {
363+
info->num_1block += 1;
364+
} else if (len == 2) {
365+
info->num_2block += 1;
366+
}
367+
if (len > info->max_block) {
368+
info->max_block = len;
369+
}
370+
}
362371
}
363372

364373
info->used *= BYTES_PER_BLOCK;

0 commit comments

Comments
 (0)