More debugging

This commit is contained in:
valtermiari 2023-02-16 18:37:02 +01:00
parent 5157e6b41d
commit 72a044cd59
5 changed files with 48 additions and 10 deletions

View file

@ -1,16 +1,17 @@
mkfile_path = $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir = $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
PWD_V = /Users/valtermiari/Desktop/DV/Bachelors/code/language/src/GC/include
CC = clang++
PWD = /home/virre/dev/systemF/org/language/src/GC/include
CFLAGS = -Wall -Wextra -v -g -std=gnu++20 -stdlib=libc++ -I
VGFLAGS = --leak-check=full --show-leak-kinds=all
heap:
$(CC) $(CFLAGS)$(PWD) lib/heap.cpp
$(CC) $(CFLAGS)$(PWD_V) lib/heap.cpp
h_test:
rm -f tests/h_test.out
$(CC) $(CFLAGS)$(PWD) tests/h_test.cpp lib/heap.cpp -o tests/h_test.out
$(CC) $(CFLAGS)$(PWD_V) tests/h_test.cpp lib/heap.cpp -o tests/h_test.out
h_test_vg:
make h_test
@ -18,7 +19,7 @@ h_test_vg:
linker:
rm -f tests/linker.out
$(CC) $(CFLAGS)$(PWD) tests/linker.cpp lib/heap.cpp -o tests/linker.out
$(CC) $(CFLAGS)$(PWD_V) tests/linker.cpp lib/heap.cpp -o tests/linker.out
linker_vg:
make linker

View file

@ -119,13 +119,25 @@ namespace GC {
// Not optimal for now, it doesn't have to loop over all objects
// but mark needs some refinements before this can be optimised
// sweep apparently only sweeps chunks of odd size, eventhough the're not marked
void Heap::sweep() {
for (size_t i = 0; i < m_allocated_chunks.size(); i++) {
/* for (char i = 0; i < m_allocated_chunks.size();) {
auto chunk = m_allocated_chunks.at(i);
std::cout << "Current chunk: " << chunk->start << std::endl;
if (chunk->marked == false) {
std::cout << "The current chunk was removed" << std::endl;
m_allocated_chunks.erase(m_allocated_chunks.begin() + i);
m_freed_chunks.push_back(chunk);
}
} */
// This captures the wierd behavior or my lack of knowledge of vectors
for (auto chunk : m_allocated_chunks) {
if (!chunk->marked) {
auto it = std::find(m_allocated_chunks.begin(), m_allocated_chunks.end(), chunk);
if (it != m_allocated_chunks.end())
m_allocated_chunks.erase(it);
m_freed_chunks.push_back(chunk);
}
}
}
@ -168,20 +180,20 @@ namespace GC {
*/
// For testing purposes
void Heap::print_line(Chunk *chunk) {
std::cout << "Marked: " << chunk->marked << "\nStart adr: " << chunk->start << "\nSize: " << chunk->size << " B" << std::endl;
std::cout << "Marked: " << chunk->marked << "\nStart adr: " << chunk->start << "\nSize: " << chunk->size << " B\n" << std::endl;
}
void Heap::print_contents() {
if (m_allocated_chunks.size()) {
std::cout << "ALLOCATED CHUNKS" << std::endl;
std::cout << "\nALLOCATED CHUNKS #" << m_allocated_chunks.size() << std::endl;
for (auto chunk : m_allocated_chunks) {
print_line(chunk);
}
} else {
std::cout << "NO ALLOCATIONS" << std::endl;
std::cout << "NO ALLOCATIONS\n" << std::endl;
}
if (m_freed_chunks.size()) {
std::cout << "FREED CHUNKS" << std::endl;
std::cout << "\nFREED CHUNKS #" << m_freed_chunks.size() << std::endl;
for (auto fchunk : m_freed_chunks) {
print_line(fchunk);
}

View file

@ -12,11 +12,16 @@ void init() {
auto temp1 = gc->alloc(sizeof(a_ptr));
auto temp2 = gc->alloc(sizeof(live_int_vec));
auto temp3 = gc->alloc(sizeof(dead_int_vec));
a_ptr = nullptr;
// *arr, *temp1, *temp2 and *temp3 should all be on the stack
//a_ptr = nullptr;
}
int main() {
init();
//init();
for (int i = 1; i < 10; i++) {
gc->alloc(sizeof(i));
}
gc->collect(MARK | SWEEP);
gc->print_contents();
//delete gc;

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.h_test.out</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>