From 43396b50cdb57d8316e8022a43c64d11219c9b66 Mon Sep 17 00:00:00 2001 From: Victor Olin Date: Wed, 22 Mar 2023 13:58:27 +0100 Subject: [PATCH] More documentation --- src/GC/docs/lib/chunk.md | 26 ++++++++++++++++++++ src/GC/docs/lib/event.md | 47 +++++++++++++++++++++++++++++++++++++ src/GC/docs/lib/heap.md | 12 ++++++++++ src/GC/docs/lib/profiler.md | 12 ++++++++++ src/GC/include/chunk.hpp | 2 +- 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 src/GC/docs/lib/chunk.md create mode 100644 src/GC/docs/lib/event.md create mode 100644 src/GC/docs/lib/heap.md create mode 100644 src/GC/docs/lib/profiler.md diff --git a/src/GC/docs/lib/chunk.md b/src/GC/docs/lib/chunk.md new file mode 100644 index 0000000..97230f5 --- /dev/null +++ b/src/GC/docs/lib/chunk.md @@ -0,0 +1,26 @@ +# chunk.hpp + +A chunk struct object is the basic element of what can be +stored on the heap. When `Heap::alloc` is called a +chunk may be created to represent the space of memory +that was allocated on the heap by `alloc`. + +## Members +`bool m_marked`: A boolean flag to mark an object during mark/sweep. + +`uintptr_t *const m_start`: A constant pointer pointing to the start +address of the memory space that was allocated. + +`const size_t m_size`: The size of the memory space that was allocated. + +## Constructors +There are three constructors for a chunk. One regular constructor +and two copy constructors. + +`Chunk(size_t size, uintptr_t *start)`: Used for creating new chunks in +`Heap::alloc`. + +`Chunk(const Chunk *const c)`: A copy constructor used by the profiler +to store chunk data after the initial chunk is deleted. + +`Chunk(const Chunk &c)`: A secondary copy constructor used for debugging. \ No newline at end of file diff --git a/src/GC/docs/lib/event.md b/src/GC/docs/lib/event.md new file mode 100644 index 0000000..8884205 --- /dev/null +++ b/src/GC/docs/lib/event.md @@ -0,0 +1,47 @@ +# event.hpp & event.cpp + +An event class used by the profiler to track actions +on the heap. + +## Members +`const GCEventType m_type`: The type of event recorded. + +`const std::time_t m_timestamp`: The timestamp of the event, +initialized to the current time by `std::time(NULL)`. + +`const Chunk *m_chunk`: The chunk an event is related to. +For example, in `alloc` when a new chunk is created, a +new event is recorded with the type of `NewChunk` and +`m_chunk` then contains a copied version of that new chunk. +If an event is not related to a chunk this member is initialized +to a nullptr. + +`const size_t m_size`: In an `AllocStart` event, this member +stores the amount of bytes requested to `alloc`. Otherwise +this member is initialized to 0. + +## Constructors +`GCEvent(GCEventType type)`: Used for creating events that are +independent of a chunk and size (like `ProfilerDispose`). + +`GCEvent(GCEventType type, Chunk *chunk)`: Used for creating events +that are connected to a chunk (like `ChunkMarked`). + +`GCEvent(GCEventType type, size_t size)`: Used for creating events +that are related to a size (only `AllocStart`). + +## Destructors +`~GCEvent()`: Default destructor and also frees the member +`m_chunk` if it's not the `nullptr`. + +## Functions +`GCEventType get_type()`: Getter for the type of the event. + +`std::time_t get_time_stamp()`: Getter for the timestamp of +the event. + +`const Chunk *get_chunk()`: Getter for the Chunk the event +is related to. The chunk data is constant. + +`const char *type_to_string()`: Translates the type of the +event to a string. \ No newline at end of file diff --git a/src/GC/docs/lib/heap.md b/src/GC/docs/lib/heap.md new file mode 100644 index 0000000..d1d3f49 --- /dev/null +++ b/src/GC/docs/lib/heap.md @@ -0,0 +1,12 @@ +# heap.hpp & heap.cpp + +## Members + + +## Constructors + + +## Destructors + + +## Functions \ No newline at end of file diff --git a/src/GC/docs/lib/profiler.md b/src/GC/docs/lib/profiler.md new file mode 100644 index 0000000..d1c8995 --- /dev/null +++ b/src/GC/docs/lib/profiler.md @@ -0,0 +1,12 @@ +# profiler.hpp & profiler.cpp + +## Members + + +## Constructors + + +## Destructors + + +## Functions \ No newline at end of file diff --git a/src/GC/include/chunk.hpp b/src/GC/include/chunk.hpp index 50e13fe..1e63869 100644 --- a/src/GC/include/chunk.hpp +++ b/src/GC/include/chunk.hpp @@ -20,6 +20,6 @@ namespace GC Chunk(size_t size, uintptr_t *start) : m_size(size), m_start(start) {} Chunk(const Chunk *const c) : m_marked(c->m_marked), m_start(c->m_start), m_size(c->m_size) {} - Chunk(const Chunk& c) : m_marked(c.m_marked), m_start(c.m_start), m_size(c.m_size) {} + Chunk(const Chunk &c) : m_marked(c.m_marked), m_start(c.m_start), m_size(c.m_size) {} }; } \ No newline at end of file