Hooked the GC back in B)

This commit is contained in:
Samuel Hammersberg 2023-05-05 18:50:05 +02:00
parent dead9eb75a
commit a388f480e5
24 changed files with 1404 additions and 227 deletions

View file

@ -1,17 +1,16 @@
#pragma once
#include <assert.h>
#include <iostream>
#include <setjmp.h>
#include <list>
#include <stdlib.h>
#include <vector>
#include <unordered_map>
#include "chunk.hpp"
#include "profiler.hpp"
#define HEAP_SIZE 2097152 //65536
#define FREE_THRESH (uint) 100000
#define DEBUG
#define HEAP_SIZE 320//65536
#define FREE_THRESH (uint) 0
// #define HEAP_DEBUG
namespace GC
{
@ -20,11 +19,18 @@ namespace GC
* collection (mark/sweep/free/all).
*/
enum CollectOption {
MARK=0x1,
SWEEP=0x2,
MARK_SWEEP = 0x3,
FREE=0x4,
COLLECT_ALL=0x7
MARK = 1 << 0,
SWEEP = 1 << 1,
MARK_SWEEP = 1 << 2,
FREE = 1 << 3,
COLLECT_ALL = 0b1111 // all flags above
};
struct AddrRange
{
const uintptr_t *start, *end;
AddrRange(uintptr_t *_start, uintptr_t *_end) : start(_start), end(_end) {}
};
/**
@ -53,6 +59,8 @@ namespace GC
std::vector<Chunk *> m_allocated_chunks;
std::vector<Chunk *> m_freed_chunks;
std::list<Chunk *> m_free_list;
std::unordered_map<uintptr_t, Chunk*> m_chunk_table;
static bool profiler_enabled();
// static Chunk *get_at(std::vector<Chunk *> &list, size_t n);
@ -62,14 +70,17 @@ namespace GC
void free(Heap &heap);
void free_overlap(Heap &heap);
void mark(uintptr_t *start, const uintptr_t *end, std::vector<Chunk *> &worklist);
void mark_hash(uintptr_t *start, const uintptr_t *end);
Chunk* find_pointer_hash(uintptr_t *start, const uintptr_t *end);
void create_table();
void print_line(Chunk *chunk);
void print_worklist(std::vector<Chunk *> &list);
void mark_step(uintptr_t start, uintptr_t end, std::vector<Chunk *> &worklist);
void mark_range(std::vector<AddrRange *> &ranges, std::vector<Chunk *> &worklist);
// Temporary
Chunk *try_recycle_chunks_new(size_t size);
void free_overlap_new(Heap &heap);
public:
/**
* These are the only five functions which are exposed
@ -84,12 +95,13 @@ namespace GC
static void dispose();
static void *alloc(size_t size);
void set_profiler(bool mode);
void set_profiler_log_options(RecordOption flags);
// Stop the compiler from generating copy-methods
Heap(Heap const&) = delete;
Heap& operator=(Heap const&) = delete;
#ifdef DEBUG
#ifdef HEAP_DEBUG
void collect(CollectOption flags); // conditional collection
void check_init(); // print dummy things
void print_contents(); // print dummy things