From eeb126ab656715406e1318084198a1bef74bc8a2 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Wed, 12 Mar 2025 21:37:29 +0800 Subject: [PATCH] :bug: fix global/local debug index --- src/nasal_vm.cpp | 33 +++++++++++++++++++++----- test/gc_test.nas | 60 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 68 insertions(+), 25 deletions(-) diff --git a/src/nasal_vm.cpp b/src/nasal_vm.cpp index 84df332..0dcfaaa 100644 --- a/src/nasal_vm.cpp +++ b/src/nasal_vm.cpp @@ -225,12 +225,24 @@ void vm::function_call_trace() { std::stack functions; std::stack callsite; - // load call trace + // load call trace, from bottom to top for(var* i = bottom; i <= top; ++i) { // i-1 is the callsite program counter of this function - if (i->is_addr() && i+2<=top && - (i+1)->is_ret() && (i+1)->ret()>0 && - (i+2)->is_func()) { + // +-------+----------------+ + // | func | func() {..} | <-- i + 2 + // +-------+----------------+ + // | ret | 0x3bf | <-- i + 1 (value should not be 0x0) + // +-------+----------------+ + // | addr | 0x7ff5f61ae020 | <-- i + // +-------+----------------+ + // TODO: op_cnt may destroy the order, so maybe this need refact + if (i + 2 > top) { + continue; + } + if (!i->is_addr()) { + continue; + } + if ((i+1)->is_ret() && (i+1)->ret()>0 && (i+2)->is_func()) { functions.push(&(i+2)->func()); callsite.push((i+1)->ret()); } @@ -239,10 +251,18 @@ void vm::function_call_trace() { // another condition may exist // have ret pc on stack, but no function at the top of the ret pc for(var * i = top; i >= bottom; --i) { + // +-------+----------------+ + // | xxxx | xxxx | <-- i + 2 (not function or not exist) + // +-------+----------------+ + // | ret | 0x3bf | <-- i + 1 (value should not be 0x0) + // +-------+----------------+ + // | addr | 0x7ff5f61ae020 | <-- i + // +-------+----------------+ if ((i->is_addr() && i+2<=top && (i+1)->is_ret() && !(i+2)->is_func()) || (i->is_addr() && i+1<=top && i+2>top && (i+1)->is_ret())) { functions.push(&ctx.funcr.func()); callsite.push((i+1)->ret()); + break; } } @@ -370,7 +390,7 @@ void vm::global_state() { << reinterpret_cast(global) << ")\n" << std::dec; for(usize i = 0; i(i) << std::dec << " "; auto name = global_symbol_name[i]; if (name.length()>=10) { @@ -379,7 +399,8 @@ void vm::global_state() { } std::clog << "| " << std::left << std::setw(10) - << std::setfill(' ') << name << " "; + << std::setfill(' ') << name << " " + << std::internal; value_info(global[i]); } } diff --git a/test/gc_test.nas b/test/gc_test.nas index 804fe00..c8f526d 100644 --- a/test/gc_test.nas +++ b/test/gc_test.nas @@ -9,15 +9,18 @@ var test_func = func(test_processes...) { var info = runtime.gc.info(); var gc_total = info.total; var duration = 0; - foreach(var f; test_processes) { - println("[", os.time(), "] testing ", id(f)); + foreach (var t; test_processes) { + var name = t[0]; + var f = t[1]; + print("[", os.time(), "] testing ", name, " : "); time_stamp.stamp(); f(); duration = time_stamp.elapsedMSec(); info = runtime.gc.info(); - println("[", os.time(), "] ", duration, " ms, gc ", + println(duration, " ms, gc ", (info.total-gc_total)*100/duration, "%, ", - 1000/duration, " cps"); + 1000/duration, " count/sec" + ); gc_total = info.total; } @@ -34,23 +37,25 @@ var test_func = func(test_processes...) { println("---------------------"); } +var MAX_ITER_NUM = 2e5; + var append_vec = func { var res = []; - for(var i=0; i<1e6; i+=1) { - append(res, [1]); + for(var i=0; i", append_vec_in_vec], + ["vec", append_hash_in_vec], + ["hash", append_vec_in_hash], + ["hash", append_hash_in_hash] ); } \ No newline at end of file