diff --git a/src/GC/include/cheap.h b/src/GC/include/cheap.h new file mode 100644 index 0000000..2db2b8d --- /dev/null +++ b/src/GC/include/cheap.h @@ -0,0 +1,22 @@ +#ifndef __CHEAP_H__ +#define __CHEAP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +struct cheap; +typedef struct cheap cheap_t; + +cheap_t *cheap_the(); +void cheap_init(); +void cheap_dispose(); +void *cheap_alloc(unsigned long size); +void cheap_set_profiler(bool mode); + +#ifdef __cplusplus +} +#endif + + +#endif /* __CHEAP_H__ */ \ No newline at end of file diff --git a/src/GC/lib/cheap.cpp b/src/GC/lib/cheap.cpp new file mode 100644 index 0000000..f9f7172 --- /dev/null +++ b/src/GC/lib/cheap.cpp @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "heap.hpp" +#include "cheap.h" + +struct cheap { + void *obj; +}; + +cheap_t *cheap_the() { + cheap_t *c; + GC::Heap *heap; + + c = (cheap_t *)malloc(sizeof(*c)); + heap = &GC::Heap::the(); + c->obj = heap; + + return c; +} + +void cheap_init() { + GC::Heap::init(); +} \ No newline at end of file diff --git a/src/GC/lib/event.cpp b/src/GC/lib/event.cpp new file mode 100644 index 0000000..185c613 --- /dev/null +++ b/src/GC/lib/event.cpp @@ -0,0 +1,75 @@ +// #include +// #include +// #include + +#include "chunk.hpp" +#include "event.hpp" + +namespace GC +{ + /** + * @returns The type of the event + */ + GCEventType GCEvent::get_type() + { + return m_type; + } + + /** + * @returns The time the event happened in + * the form of time_t. + */ + std::time_t GCEvent::get_time_stamp() + { + return m_timestamp; + } + + /** + * If the event is related to a chunk, this + * function returns the chunk that it is + * related to. If the event is independent + * of a chunk, it returns the nullptr. + * + * @returns A chunk pointer or the nullptr. + */ + const Chunk *GCEvent::get_chunk() + { + return m_chunk; + } + + /** + * If the event is an AllocStart event, this + * returns the size of the alloc() request. + * otherwise this returns 0. + * + * @returns A number representing the number + * of bytes requested to alloc() + * or 0 if the event is not an + * AllocStart event. + */ + size_t GCEvent::get_size() + { + return m_size; + } + + /** + * @returns The string conversion of the event type. + */ + const char *GCEvent::type_to_string() + { + switch (m_type) + { + case HeapInit: return "HeapInit"; + case AllocStart: return "AllocStart"; + case CollectStart: return "CollectStart"; + case MarkStart: return "MarkStart"; + case ChunkMarked: return "ChunkMarked"; + case ChunkSwept: return "ChunkSwept"; + case ChunkFreed: return "ChunkFreed"; + case NewChunk: return "NewChunk"; + case ReusedChunk: return "ReusedChunk"; + case ProfilerDispose: return "ProfilerDispose"; + default: return "[Unknown]"; + } + } +} \ No newline at end of file