From 9b168b5d5222954626ce35741a0dcf3242729908 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Tue, 14 May 2024 00:16:02 +0800 Subject: [PATCH] :memo: move andy_gc_test to test dir --- makefile | 1 + src/nasal_dbg.cpp | 11 ++++++----- src/nasal_dbg.h | 13 ++++++------- src/nasal_gc.cpp | 11 +++++++++-- src/nasal_gc.h | 1 + {tools => test}/andy_gc_test.nas | 0 test/gc_test.nas | 2 +- 7 files changed, 24 insertions(+), 15 deletions(-) rename {tools => test}/andy_gc_test.nas (100%) diff --git a/makefile b/makefile index 7bbc56c..47c12b4 100644 --- a/makefile +++ b/makefile @@ -255,6 +255,7 @@ clean: .PHONY: test test:nasal + @ ./nasal -t -d test/andy_gc_test.nas @ ./nasal test/argparse_test.nas @ ./nasal -e test/ascii-art.nas @ ./nasal -t -d test/bfs.nas diff --git a/src/nasal_dbg.cpp b/src/nasal_dbg.cpp index a1afd3d..8ac3489 100644 --- a/src/nasal_dbg.cpp +++ b/src/nasal_dbg.cpp @@ -108,7 +108,7 @@ std::vector dbg::parse(const std::string& cmd) { } u16 dbg::file_index(const std::string& filename) const { - for(u16 i = 0; i\n" << " h, help | get help\n" @@ -141,7 +141,7 @@ void dbg::help() { } void dbg::list_file() const { - for(usize i = 0; i parse(const std::string&); u16 file_index(const std::string&) const; - void err(); - void help(); + void err() const; + void help() const; void list_file() const; void step_info(); void interact(); public: - dbg(): - next(true), fsize(0), - break_file_index(0), break_line(0), - do_operand_count(false) {} + dbg(): next(true), file_list_size(0), + break_file_index(0), break_line(0), + do_operand_count(false) {} void run(const codegen&, const linker&, const std::vector&, diff --git a/src/nasal_gc.cpp b/src/nasal_gc.cpp index bbbf3b0..d5a06ee 100644 --- a/src/nasal_gc.cpp +++ b/src/nasal_gc.cpp @@ -1,4 +1,5 @@ #include "nasal_gc.h" +#include namespace nasal { @@ -22,7 +23,10 @@ void gc::do_mark_sweep() { void gc::mark() { std::vector bfs; mark_context_root(bfs); - if (memory.size()>8192 && bfs.size()>4) { + + // concurrent mark, experimental + if (memory.size()>UINT16_MAX && bfs.size()>8192) { + flag_concurrent_mark_triggered = true; usize size = bfs.size(); std::thread t0(&gc::concurrent_mark, this, std::ref(bfs), 0, size/4); std::thread t1(&gc::concurrent_mark, this, std::ref(bfs), size/4, size/2); @@ -34,7 +38,8 @@ void gc::mark() { t3.join(); return; } - + + // normal mark while(!bfs.empty()) { var value = bfs.back(); bfs.pop_back(); @@ -340,6 +345,8 @@ void gc::info() const { std::clog << " | " << max_mark_time*1.0/den*1000 << " ms\n"; std::clog << " " << left << setw(indent) << setfill(' ') << "max sweep"; std::clog << " | " << max_sweep_time*1.0/den*1000 << " ms\n"; + std::clog << " " << left << setw(indent) << setfill(' ') << "concurrent"; + std::clog << " | " << (flag_concurrent_mark_triggered? "true\n":"false\n"); std::clog << last_line << "\n"; } diff --git a/src/nasal_gc.h b/src/nasal_gc.h index daf5fa9..3daee2b 100644 --- a/src/nasal_gc.h +++ b/src/nasal_gc.h @@ -60,6 +60,7 @@ struct gc { i64 max_time = 0; i64 max_mark_time = 0; i64 max_sweep_time = 0; + bool flag_concurrent_mark_triggered = false; void set(context* _ctx, var* _global, usize _size) { running_context = _ctx; diff --git a/tools/andy_gc_test.nas b/test/andy_gc_test.nas similarity index 100% rename from tools/andy_gc_test.nas rename to test/andy_gc_test.nas diff --git a/test/gc_test.nas b/test/gc_test.nas index 8263c77..804fe00 100644 --- a/test/gc_test.nas +++ b/test/gc_test.nas @@ -17,7 +17,7 @@ var test_func = func(test_processes...) { info = runtime.gc.info(); println("[", os.time(), "] ", duration, " ms, gc ", (info.total-gc_total)*100/duration, "%, ", - int(1000/duration), " cps"); + 1000/duration, " cps"); gc_total = info.total; }