From 354af224d9e81f43520ea7a5134653d05750a9ce Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Sat, 28 Jun 2025 00:19:57 +0100 Subject: [PATCH 1/5] Added missing DebugLogs on Collect() methods Signed-off-by: Stefan Marr --- src/memory/GenerationalCollector.cpp | 1 + src/memory/MarkSweepCollector.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/memory/GenerationalCollector.cpp b/src/memory/GenerationalCollector.cpp index 91c3248f..c4270803 100644 --- a/src/memory/GenerationalCollector.cpp +++ b/src/memory/GenerationalCollector.cpp @@ -124,6 +124,7 @@ void GenerationalCollector::MajorCollection() { } void GenerationalCollector::Collect() { + DebugLog("GenGC Collect\n"); Timer::GCTimer.Resume(); // reset collection trigger heap->resetGCTrigger(); diff --git a/src/memory/MarkSweepCollector.cpp b/src/memory/MarkSweepCollector.cpp index 07266c44..9d0e0a60 100644 --- a/src/memory/MarkSweepCollector.cpp +++ b/src/memory/MarkSweepCollector.cpp @@ -4,6 +4,7 @@ #include #include "../memory/Heap.h" +#include "../misc/debug.h" #include "../vm/Universe.h" #include "../vmobjects/AbstractObject.h" #include "../vmobjects/IntegerBox.h" @@ -14,6 +15,8 @@ #define GC_MARKED 3456 void MarkSweepCollector::Collect() { + DebugLog("MarkSweep Collect\n"); + auto* heap = GetHeap(); Timer::GCTimer.Resume(); // reset collection trigger From 6b8d82aceddc8519be460ba678e9608d9893091b Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Sat, 28 Jun 2025 00:20:55 +0100 Subject: [PATCH 2/5] Added a few missing bytecodes to disassembler Signed-off-by: Stefan Marr --- src/compiler/Disassembler.cpp | 82 +++++++++++++++++++++++------------ src/compiler/Disassembler.h | 1 + 2 files changed, 55 insertions(+), 28 deletions(-) diff --git a/src/compiler/Disassembler.cpp b/src/compiler/Disassembler.cpp index 077960be..e77a45b9 100644 --- a/src/compiler/Disassembler.cpp +++ b/src/compiler/Disassembler.cpp @@ -116,6 +116,26 @@ void Disassembler::DumpMethod(MethodGenerationContext* mgenc, dumpMethod(bytecodes.data(), bytecodes.size(), indent, nullptr, true); } +static void PrintFieldAccess(VMMethod* method, bool printObjects, + uint8_t const fieldIdx) { + if (method != nullptr && printObjects) { + auto* holder = dynamic_cast((VMObject*)method->GetHolder()); + if (holder != nullptr) { + VMSymbol* name = holder->GetInstanceFieldName(fieldIdx); + if (name != nullptr) { + DebugPrint("(index: %d) field: %s\n", fieldIdx, + name->GetStdString().c_str()); + } else { + DebugPrint("(index: %d) field: !nullptr!: error!\n", fieldIdx); + } + } else { + DebugPrint("(index: %d) block holder is not a class!!\n", fieldIdx); + } + } else { + DebugPrint("(index: %d)\n", fieldIdx); + } +} + void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes, const char* indent, VMMethod* method, bool printObjects) { @@ -152,7 +172,8 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes, switch (bytecode) { case BC_PUSH_0: case BC_PUSH_1: - case BC_PUSH_NIL: { + case BC_PUSH_NIL: + case BC_RETURN_SELF: { // no more details to be printed break; } @@ -260,26 +281,12 @@ void Disassembler::dumpMethod(uint8_t* bytecodes, size_t numberOfBytecodes, case BC_POP_FIELD: case BC_PUSH_FIELD: { uint8_t const fieldIdx = bytecodes[bc_idx + 1]; - if (method != nullptr && printObjects) { - auto* holder = - dynamic_cast((VMObject*)method->GetHolder()); - if (holder != nullptr) { - VMSymbol* name = holder->GetInstanceFieldName(fieldIdx); - if (name != nullptr) { - DebugPrint("(index: %d) field: %s\n", fieldIdx, - name->GetStdString().c_str()); - } else { - DebugPrint("(index: %d) field: !nullptr!: error!\n", - fieldIdx); - } - } else { - DebugPrint( - "(index: %d) block holder is not a class!!\n", - fieldIdx); - } - } else { - DebugPrint("(index: %d)\n", fieldIdx); - } + PrintFieldAccess(method, printObjects, fieldIdx); + break; + } + case BC_POP_FIELD_1: + case BC_PUSH_FIELD_1: { + PrintFieldAccess(method, printObjects, 1); break; } case BC_SEND: @@ -399,6 +406,16 @@ void Disassembler::printNth(uint8_t idx, VMFrame* frame, const char* op) { DebugPrint(">\n"); } +void Disassembler::printConstantAccess(vm_oop_t constant, uint8_t index) { + VMClass* c = CLASS_OF(constant); + VMSymbol* cname = c->GetName(); + + DebugPrint("(index: %d) value: (%s) ", index, + cname->GetStdString().c_str()); + dispatch(constant); + DebugPrint("\n"); +} + /** * Dump bytecode from the frame running */ @@ -528,13 +545,22 @@ void Disassembler::DumpBytecode(VMFrame* frame, VMMethod* method, } case BC_PUSH_CONSTANT: { vm_oop_t constant = method->GetConstant(bc_idx); - VMClass* c = CLASS_OF(constant); - VMSymbol* cname = c->GetName(); - - DebugPrint("(index: %d) value: (%s) ", BC_1, - cname->GetStdString().c_str()); - dispatch(constant); - DebugPrint("\n"); + printConstantAccess(constant, BC_1); + break; + } + case BC_PUSH_CONSTANT_0: { + vm_oop_t constant = method->GetIndexableField(0); + printConstantAccess(constant, 0); + break; + } + case BC_PUSH_CONSTANT_1: { + vm_oop_t constant = method->GetIndexableField(1); + printConstantAccess(constant, 1); + break; + } + case BC_PUSH_CONSTANT_2: { + vm_oop_t constant = method->GetIndexableField(2); + printConstantAccess(constant, 2); break; } case BC_PUSH_GLOBAL: { diff --git a/src/compiler/Disassembler.h b/src/compiler/Disassembler.h index 3bf0dc07..3e1613c4 100644 --- a/src/compiler/Disassembler.h +++ b/src/compiler/Disassembler.h @@ -53,4 +53,5 @@ class Disassembler { VMFrame* frame); static void printPopLocal(uint8_t idx, uint8_t ctx, VMFrame* frame); static void printNth(uint8_t idx, VMFrame* frame, const char* op); + static void printConstantAccess(vm_oop_t constant, uint8_t index); }; From ab8c1e6228d752d8060fdcd1a66adc7f2757569c Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Sat, 28 Jun 2025 00:33:45 +0100 Subject: [PATCH 3/5] Added DebugDumpMethodWithObjects(method) method Signed-off-by: Stefan Marr --- src/misc/debug.cpp | 4 ++++ src/misc/debug.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/misc/debug.cpp b/src/misc/debug.cpp index 0168f03d..8cc96e62 100644 --- a/src/misc/debug.cpp +++ b/src/misc/debug.cpp @@ -16,6 +16,10 @@ std::string DebugGetClassName(gc_oop_t obj) { return CLASS_OF(obj)->GetName()->GetStdString(); } +void DebugDumpMethodWithObjects(VMInvokable* method) { + Disassembler::DumpMethod((VMMethod*)method, "", true); +} + void DebugDumpMethod(VMInvokable* method) { Disassembler::DumpMethod((VMMethod*)method, "", false); } diff --git a/src/misc/debug.h b/src/misc/debug.h index 77093d3d..ef2d7f13 100644 --- a/src/misc/debug.h +++ b/src/misc/debug.h @@ -100,4 +100,5 @@ static inline void DebugTrace(const char* fmt, ...) { std::string DebugGetClassName(vm_oop_t /*obj*/); std::string DebugGetClassName(gc_oop_t /*obj*/); void DebugDumpMethod(VMInvokable* method); +void DebugDumpMethodWithObjects(VMInvokable* method); void DebugDumpMethod(MethodGenerationContext* mgenc); From 55401534b4a0d681cba0f8301b01650ede9cb7cc Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Fri, 30 May 2025 14:20:24 +0100 Subject: [PATCH 4/5] Remoe some unused tidys, and parallelize ./lint.sh Signed-off-by: Stefan Marr --- .clang-tidy | 2 ++ lint.sh | 31 ++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 39bb4218..46dfcb3a 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,6 +2,7 @@ Checks: '*, -altera-id-dependent-backward-branch, -altera-unroll-loops, + -android-*, -boost-use-ranges, -bugprone-casting-through-void, -bugprone-easily-swappable-parameters, @@ -40,6 +41,7 @@ Checks: '*, -google-default-arguments, -google-global-names-in-headers, -google-readability-casting, + -google-upgrade-googletest-case, -hicpp-avoid-c-arrays, -hicpp-no-array-decay, -hicpp-no-malloc, diff --git a/lint.sh b/lint.sh index 0c75e6fa..ad973e5b 100755 --- a/lint.sh +++ b/lint.sh @@ -1,7 +1,28 @@ #!/bin/sh -clang-format-mp-19 -i --style=file --Werror src/*.cpp src/**/*.cpp src/**/*.h -clang-tidy-mp-19 --config-file=.clang-tidy src/**/*.cpp \ - --fix \ + +CLANG_FORMAT="clang-format-mp-19 -i --style=file --Werror src/*.cpp src/**/*.cpp src/**/*.h" +$CLANG_FORMAT + +## The check --enable-check-profile flag gives an overview of where clang-tidy spends its time +# --enable-check-profile + +CLANG_START="clang-tidy-mp-19 --config-file=.clang-tidy" +CLANG_END="--fix \ -- -I/opt/local/include/ -fdiagnostics-absolute-paths \ - -DGC_TYPE=GENERATIONAL -DUSE_TAGGING=false -DCACHE_INTEGER=false -DUNITTESTS -clang-format-mp-19 -i --style=file --Werror src/*.cpp src/**/*.cpp src/**/*.h + -DGC_TYPE=GENERATIONAL -DUSE_TAGGING=false -DCACHE_INTEGER=false -DUNITTESTS" + + +$CLANG_START src/*.cpp $CLANG_END & +$CLANG_START src/compiler/*.cpp $CLANG_END & +$CLANG_START src/interpreter/*.cpp $CLANG_END & +$CLANG_START src/memory/*.cpp $CLANG_END & +$CLANG_START src/misc/*.cpp $CLANG_END & +$CLANG_START src/primitives/*.cpp $CLANG_END & +$CLANG_START src/primitivesCore/*.cpp $CLANG_END & +$CLANG_START src/unitTests/*.cpp $CLANG_END & +$CLANG_START src/vm/*.cpp $CLANG_END & +$CLANG_START src/vmobjects/*.cpp $CLANG_END & + +wait +$CLANG_FORMAT + From 858f10fdd1b3028c9cf70953a4c76ca534579756 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Tue, 8 Jul 2025 13:54:59 +0100 Subject: [PATCH 5/5] Apply clang-tidy to Main.cpp Signed-off-by: Stefan Marr --- src/Main.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 88d9a247..6a19055c 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -22,21 +22,15 @@ THE SOFTWARE. */ -#include +#include #include -#include "compiler/ClassGenerationContext.h" -#include "memory/Heap.h" #include "misc/defs.h" +#include "vm/Print.h" #include "vm/Universe.h" -#include "vmobjects/ObjectFormats.h" -#include "vmobjects/VMArray.h" -#include "vmobjects/VMMethod.h" -#include "vmobjects/VMObject.h" -#include "vmobjects/VMString.h" int32_t main(int32_t argc, char** argv) { - cout << "This is SOM++" << endl; + cout << "This is SOM++" << '\n'; Universe::Start(argc, argv);