Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include <sys/mman.h>
#include "gc.h"

extern void error(char *fmt, ...);
extern void error(char *fmt, int line_num, ...);
extern filepos_t filepos;

// The pointer pointing to the beginning of the current heap
void *memory;
Expand All @@ -15,7 +16,7 @@ void *memory;
static void *from_space;

// The number of bytes allocated from the heap
static size_t mem_nused = 0;
size_t mem_nused = 0;

// Flags to debug GC
bool gc_running = false;
Expand Down Expand Up @@ -63,7 +64,7 @@ Obj *alloc(void *root, int type, size_t size) {
// Terminate the program if we couldn't satisfy the memory request. This can happen if the
// requested size was too large or the from-space was filled with too many live objects.
if (MEMORY_SIZE < mem_nused + size)
error("Memory exhausted");
error("Memory exhausted", filepos.line_num);

// Allocate the object.
Obj *obj = memory + mem_nused;
Expand Down Expand Up @@ -115,6 +116,11 @@ void *alloc_semispace() {
return mmap(NULL, MEMORY_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
}

void free_semispace(void *ptr){
if (ptr) munmap(ptr, MEMORY_SIZE);
mem_nused = 0;
}

// Copies the root objects.
static void forward_root_objects(void *root) {
Symbols = forward(Symbols);
Expand Down
Loading
Loading