stage2 提供近乎完整的功能但出现严重性能问题 添加stage0的原生性能记录 stage1添加更多内置函数 nob重构代码使其更加健壮

This commit is contained in:
zzy committed 2026-09-19 18:08:43 +08:00
1 parent b5a7a811b3
commit e02b0c633a
35 files changed
+14018 -216

No files matched your search

+22 -5
View File
@@ -3,6 +3,7 @@
#ifndef __SPL_VM_H__
#define __SPL_VM_H__
#include "include/core_map.h"
#include "include/core_vec.h"
#include "spl_mcode.h"
#include <stdint.h>
@@ -19,19 +20,28 @@ typedef struct {
typedef VEC(spl_vm_val_t) spl_stack_vec_t;
typedef VEC(spl_callframe_t) spl_frame_vec_t;
typedef struct {
MAP(const char *, usize) stacks;
VEC(usize) self_samples;
usize samples;
} spl_prof_t;
typedef struct spl_vm {
spl_stack_vec_t stacks;
spl_frame_vec_t frames;
uintptr_t gp; // global pointer
uintptr_t sp; // stack pointer
uintptr_t fp; // frame pointer
uintptr_t cp; // call pointer
uintptr_t ip; // instr pointer
uintptr_t gp; // global pointer
uintptr_t sp; // stack pointer
uintptr_t fp; // frame pointer
uintptr_t cp; // call pointer
uintptr_t ip; // instr pointer
uint64_t steps; // 已执行指令数(供性能分析参考)
int exit_code;
int trace; /* non-zero to print each instruction */
int debug; /* non-zero to enable canary checks */
int debug_addr; /* non-zero to check for low-address memory access */
int skip_bp; /* non-zero: run_once 忽略下一次断点(continue 越过当前断点指令) */
spl_prof_t *profile; /* native 采样 profiler 状态(spl_prof_t*),NULL = 关闭 */
usize profile_interval; /* 采样间隔(指令数) */
VEC(usize) breakpoints; /* ip 断点(执行到该指令前暂停,run_once 返回 2) */
VEC(char *) fn_breakpoints; /* 函数名断点(CALL/CALLI 目标函数入口暂停) */
spl_prog_t *prog;
@@ -73,6 +83,13 @@ void spl_vm_clear_breakpoints(spl_vm_t *vm);
/* 让 run_once 执行当前指令(忽略一次断点命中);continue 越过当前断点用 */
void spl_vm_skip_breakpoint(spl_vm_t *vm);
/* ---- native 采样 profiler ----
* 每隔 interval 条指令记录一次当前调用栈(折叠格式),用于生成火焰图。
* 必须在 prog 加载后调用 enable;dump 输出折叠栈/函数表,再 drop 时释放。 */
void spl_vm_profile_enable(spl_vm_t *vm, usize interval);
void spl_vm_profile_dump_folded(spl_vm_t *vm, const char *path);
void spl_vm_profile_dump_table(spl_vm_t *vm, const char *path);
void spl_vm_dump_instr(spl_vm_t *vm, spl_vm_val_t ip);
void spl_vm_stackdump(spl_vm_t *vm, spl_vm_val_t sp);
int spl_vm_backtrace(spl_vm_t *vm, spl_vm_val_t fp);