feat: server 执行请求路径,六段纯函数加每请求步数覆盖

This commit is contained in:
2026-10-06 15:02:47 +00:00
parent 196bb77516
commit 635c8144f6
10 changed files with 314 additions and 47 deletions
+3 -1
View File
@@ -92,7 +92,9 @@ impl Vm {
pub(crate) fn dispatch(&mut self) -> Result<JsValue, String> {
// config.max_steps / max_alloc_bytes 逐指令只读且循环内不变:提到循环外,
// 免每次经 kernel_core Arc 指针追寻读取(热点内仅有的 config 访问)。
let max_steps = self.kernel_core.config.max_steps;
// 步数上限取每请求覆盖值.or(内核配置):覆盖优先、None 回退内核配置,
// 未设覆盖的宿主(CLI/REPL/bench/test262)读到的值与改动前逐位一致。
let max_steps = self.max_steps_override.or(self.kernel_core.config.max_steps);
let max_alloc_bytes = self.kernel_core.config.max_alloc_bytes;
let mut steps: u64 = 0;
// 小重入泵送盲区:native 终端循环泵送短 JS 重入时,顶层 steps 不推进、
+11
View File
@@ -391,6 +391,10 @@ pub struct Vm {
/// `pc/opcode/flat_id/frames`,供监督者超时/崩溃杀子进程后读回挂死点;
/// 默认 None(零输出零分配)。
pub(crate) pc_watch: Option<PathBuf>,
/// 每请求步数上限覆盖:执行路径按请求设置,None 回退内核配置。
/// 池回收的 `full_reset` 路径清位;`run()` 入口的 `clear_execution_state`
/// 刻意不清(清在那会把执行路径刚设的覆盖抹掉)。
pub(crate) max_steps_override: Option<u64>,
}
impl Drop for Vm {
@@ -467,6 +471,13 @@ impl Vm {
self.pc_watch = path;
}
/// 设置每请求步数上限覆盖:dispatch 主循环取 `覆盖值.or(内核配置)`,
/// 覆盖优先、None 回退内核配置。执行路径按请求必设(含 None),池回收的
/// `full_reset` 路径清位。
pub fn set_max_steps(&mut self, limit: Option<u64>) {
self.max_steps_override = limit;
}
/// 设置指令周期采样周期(2 的幂,0 关闭)。开启后 dispatch 主循环每
/// `period` 条指令记一条样本(flat_id、pc、opcode、frames 深度),run 末
/// 按 flat_id 聚合并向 stderr 输出 top-K 直方图;关闭时热路径仅一次