Added conditional debug output for GC related operations

This commit is contained in:
Egor Sheremetov 2024-02-28 11:01:48 +01:00 committed by Roman Venediktov
parent bcc85384c3
commit 05e4c15fe2
3 changed files with 18 additions and 6 deletions

View file

@ -1,5 +1,7 @@
#define _GNU_SOURCE 1 #define _GNU_SOURCE 1
// #define DEBUG_PRINT
#include "gc.h" #include "gc.h"
#include "runtime_common.h" #include "runtime_common.h"
@ -65,8 +67,10 @@ void *alloc (size_t size) {
// not enough place in the heap, need to perform GC cycle // not enough place in the heap, need to perform GC cycle
p = gc_alloc(size); p = gc_alloc(size);
} }
#ifdef DEBUG_PRINT
printf("Object allocated: content [%p, %p) padding [%p, %p)\n", p, p + obj_size, p + obj_size, p + size * sizeof(size_t)); printf("Object allocated: content [%p, %p) padding [%p, %p)\n", p, p + obj_size, p + obj_size, p + size * sizeof(size_t));
fflush(stdout); fflush(stdout);
#endif
return p; return p;
} }
@ -188,7 +192,9 @@ void *gc_alloc_on_existing_heap (size_t size) {
} }
void *gc_alloc (size_t size) { void *gc_alloc (size_t size) {
#ifdef DEBUG_PRINT
printf("Reallocation!\n"); printf("Reallocation!\n");
#endif
fflush(stdout); fflush(stdout);
#if defined(DEBUG_VERSION) && defined(DEBUG_PRINT) #if defined(DEBUG_VERSION) && defined(DEBUG_PRINT)
fprintf(stderr, "===============================GC cycle has started\n"); fprintf(stderr, "===============================GC cycle has started\n");
@ -271,9 +277,7 @@ void compact_phase (size_t additional_size) {
size_t next_heap_pseudo_size = MAX(next_heap_size, heap.size); size_t next_heap_pseudo_size = MAX(next_heap_size, heap.size);
memory_chunk old_heap = heap; memory_chunk old_heap = heap;
heap.begin = NULL; heap.begin = mremap(heap.begin, WORDS_TO_BYTES(heap.size), WORDS_TO_BYTES(next_heap_pseudo_size), MREMAP_MAYMOVE);
// mremap(
// heap.begin, WORDS_TO_BYTES(heap.size), WORDS_TO_BYTES(next_heap_pseudo_size), MREMAP_MAYMOVE);
if (heap.begin == MAP_FAILED) { if (heap.begin == MAP_FAILED) {
perror("ERROR: compact_phase: mremap failed\n"); perror("ERROR: compact_phase: mremap failed\n");
exit(1); exit(1);
@ -885,7 +889,9 @@ void *alloc_string (auint len) {
obj->id = cur_id; obj->id = cur_id;
#endif #endif
obj->forward_address = 0; obj->forward_address = 0;
#ifdef DEBUG_PRINT
printf("Allocated string\n"); printf("Allocated string\n");
#endif
return obj; return obj;
} }
@ -899,7 +905,9 @@ void *alloc_array (auint len) {
obj->id = cur_id; obj->id = cur_id;
#endif #endif
obj->forward_address = 0; obj->forward_address = 0;
#ifdef DEBUG_PRINT
printf("Allocated array\n"); printf("Allocated array\n");
#endif
return obj; return obj;
} }
@ -914,7 +922,9 @@ void *alloc_sexp (auint members) {
#endif #endif
obj->forward_address = 0; obj->forward_address = 0;
obj->tag = 0; obj->tag = 0;
#ifdef DEBUG_PRINT
printf("Allocated sexp\n"); printf("Allocated sexp\n");
#endif
return obj; return obj;
} }
@ -929,6 +939,8 @@ void *alloc_closure (auint captured) {
obj->id = cur_id; obj->id = cur_id;
#endif #endif
obj->forward_address = 0; obj->forward_address = 0;
#ifdef DEBUG_PRINT
printf("Allocated closure\n"); printf("Allocated closure\n");
#endif
return obj; return obj;
} }

View file

@ -43,7 +43,7 @@
// # define MINIMUM_HEAP_CAPACITY (1 << 2) // # define MINIMUM_HEAP_CAPACITY (1 << 2)
//#define MINIMUM_HEAP_CAPACITY (1 << 30) //#define MINIMUM_HEAP_CAPACITY (1 << 30)
//#define MINIMUM_HEAP_CAPACITY (30) //#define MINIMUM_HEAP_CAPACITY (30)
#define MINIMUM_HEAP_CAPACITY (30) #define MINIMUM_HEAP_CAPACITY (100)
// #endif // #endif
#include <stdbool.h> #include <stdbool.h>

View file

@ -38,9 +38,9 @@ auint; // adaptive unsigned int
#define CLOSURE_TAG 0x00000007 #define CLOSURE_TAG 0x00000007
#define UNBOXED_TAG 0x00000009 // Not actually a data_header; used to return from LkindOf #define UNBOXED_TAG 0x00000009 // Not actually a data_header; used to return from LkindOf
#ifdef X86_64 #ifdef X86_64
#define LEN_MASK (UINT64_MAX-7) #define LEN_MASK (UINT64_MAX^7)
#else #else
#define LEN_MASK (UINT32_MAX-7) #define LEN_MASK (UINT32_MAX^7)
#endif #endif
#define LEN(x) (ptrt)(((ptrt)x & LEN_MASK) >> 3) #define LEN(x) (ptrt)(((ptrt)x & LEN_MASK) >> 3)
#define TAG(x) (x & 7) #define TAG(x) (x & 7)