mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-05 22:38:44 +00:00
Added conditional debug output for GC related operations
This commit is contained in:
parent
bcc85384c3
commit
05e4c15fe2
3 changed files with 18 additions and 6 deletions
18
runtime/gc.c
18
runtime/gc.c
|
|
@ -1,5 +1,7 @@
|
|||
#define _GNU_SOURCE 1
|
||||
|
||||
// #define DEBUG_PRINT
|
||||
|
||||
#include "gc.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
|
||||
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));
|
||||
fflush(stdout);
|
||||
#endif
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
@ -188,7 +192,9 @@ void *gc_alloc_on_existing_heap (size_t size) {
|
|||
}
|
||||
|
||||
void *gc_alloc (size_t size) {
|
||||
#ifdef DEBUG_PRINT
|
||||
printf("Reallocation!\n");
|
||||
#endif
|
||||
fflush(stdout);
|
||||
#if defined(DEBUG_VERSION) && defined(DEBUG_PRINT)
|
||||
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);
|
||||
|
||||
memory_chunk old_heap = heap;
|
||||
heap.begin = NULL;
|
||||
// mremap(
|
||||
// heap.begin, WORDS_TO_BYTES(heap.size), WORDS_TO_BYTES(next_heap_pseudo_size), MREMAP_MAYMOVE);
|
||||
heap.begin = mremap(heap.begin, WORDS_TO_BYTES(heap.size), WORDS_TO_BYTES(next_heap_pseudo_size), MREMAP_MAYMOVE);
|
||||
if (heap.begin == MAP_FAILED) {
|
||||
perror("ERROR: compact_phase: mremap failed\n");
|
||||
exit(1);
|
||||
|
|
@ -885,7 +889,9 @@ void *alloc_string (auint len) {
|
|||
obj->id = cur_id;
|
||||
#endif
|
||||
obj->forward_address = 0;
|
||||
#ifdef DEBUG_PRINT
|
||||
printf("Allocated string\n");
|
||||
#endif
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
@ -899,7 +905,9 @@ void *alloc_array (auint len) {
|
|||
obj->id = cur_id;
|
||||
#endif
|
||||
obj->forward_address = 0;
|
||||
#ifdef DEBUG_PRINT
|
||||
printf("Allocated array\n");
|
||||
#endif
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
@ -914,7 +922,9 @@ void *alloc_sexp (auint members) {
|
|||
#endif
|
||||
obj->forward_address = 0;
|
||||
obj->tag = 0;
|
||||
#ifdef DEBUG_PRINT
|
||||
printf("Allocated sexp\n");
|
||||
#endif
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
@ -929,6 +939,8 @@ void *alloc_closure (auint captured) {
|
|||
obj->id = cur_id;
|
||||
#endif
|
||||
obj->forward_address = 0;
|
||||
#ifdef DEBUG_PRINT
|
||||
printf("Allocated closure\n");
|
||||
#endif
|
||||
return obj;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@
|
|||
// # define MINIMUM_HEAP_CAPACITY (1 << 2)
|
||||
//#define MINIMUM_HEAP_CAPACITY (1 << 30)
|
||||
//#define MINIMUM_HEAP_CAPACITY (30)
|
||||
#define MINIMUM_HEAP_CAPACITY (30)
|
||||
#define MINIMUM_HEAP_CAPACITY (100)
|
||||
// #endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ auint; // adaptive unsigned int
|
|||
#define CLOSURE_TAG 0x00000007
|
||||
#define UNBOXED_TAG 0x00000009 // Not actually a data_header; used to return from LkindOf
|
||||
#ifdef X86_64
|
||||
#define LEN_MASK (UINT64_MAX-7)
|
||||
#define LEN_MASK (UINT64_MAX^7)
|
||||
#else
|
||||
#define LEN_MASK (UINT32_MAX-7)
|
||||
#define LEN_MASK (UINT32_MAX^7)
|
||||
#endif
|
||||
#define LEN(x) (ptrt)(((ptrt)x & LEN_MASK) >> 3)
|
||||
#define TAG(x) (x & 7)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue