feat: 添加基准测试基础设施
This commit is contained in:
@@ -203,8 +203,10 @@ impl Vm {
|
||||
|
||||
if let Some(value) = ic_get_hit(obj, cached_shape_id, cached_slot) {
|
||||
self.regs[a] = value;
|
||||
self.ic_hits.set(self.ic_hits.get() + 1);
|
||||
ic_trace!("IC_GET hit shape={} slot={}", cached_shape_id, cached_slot);
|
||||
} else if let Some(template) = self.kernel_core.prop_forge().get_template(obj.shape_id()) {
|
||||
self.ic_misses.set(self.ic_misses.get() + 1);
|
||||
prop_cache_miss();
|
||||
if template.prop_name == prop_name_si {
|
||||
if template.position < obj.prop_vec_len() as u32 {
|
||||
@@ -271,13 +273,16 @@ impl Vm {
|
||||
let cached_slot = ext1;
|
||||
|
||||
if ic_set_hit(obj, cached_shape_id, cached_slot, value) {
|
||||
self.ic_hits.set(self.ic_hits.get() + 1);
|
||||
ic_trace!("IC_SET hit shape={} slot={}", cached_shape_id, cached_slot);
|
||||
} else if let Some(pos) = self.kernel_core.shape_forge().lookup_position(obj.shape_id(), prop_name_si) {
|
||||
self.ic_misses.set(self.ic_misses.get() + 1);
|
||||
prop_cache_miss();
|
||||
obj.set_prop_at(pos, value);
|
||||
self.write_ic_back(obj.shape_id(), pos);
|
||||
ic_debug!("IC_SET write-back shape={} slot={}", obj.shape_id(), pos);
|
||||
} else {
|
||||
self.ic_misses.set(self.ic_misses.get() + 1);
|
||||
prop_cache_miss();
|
||||
let old_shape = obj.shape_id();
|
||||
self.ordinary_set_dispatch(obj, prop_name_si, value, receiver)?;
|
||||
|
||||
@@ -180,6 +180,9 @@ pub struct Vm {
|
||||
/// The dispatch loop checks this flag and skips writing `regs[target_reg]` from the
|
||||
/// call result — the value will be delivered by the RETURN handler instead.
|
||||
pub(crate) accessor_frame_target_reg: Option<u8>,
|
||||
pub(crate) ic_hits: std::cell::Cell<u64>,
|
||||
pub(crate) ic_misses: std::cell::Cell<u64>,
|
||||
pub(crate) instruction_count: u64,
|
||||
}
|
||||
|
||||
impl Vm {
|
||||
@@ -328,6 +331,43 @@ impl Vm {
|
||||
&self.session_gc
|
||||
}
|
||||
|
||||
pub fn session_object_count(&self) -> usize {
|
||||
self.session_object_ptrs.len()
|
||||
}
|
||||
|
||||
pub fn session_bytes_allocated(&self) -> usize {
|
||||
self.session_bytes_allocated
|
||||
}
|
||||
|
||||
pub fn epoch_object_count(&self) -> usize {
|
||||
self.epoch_object_ptrs.len()
|
||||
}
|
||||
|
||||
pub fn ic_hit_rate(&self) -> f64 {
|
||||
let total = self.ic_hits.get() + self.ic_misses.get();
|
||||
if total == 0 {
|
||||
0.0
|
||||
} else {
|
||||
self.ic_hits.get() as f64 / total as f64
|
||||
}
|
||||
}
|
||||
|
||||
pub fn instruction_count(&self) -> u64 {
|
||||
self.instruction_count
|
||||
}
|
||||
|
||||
pub fn symbol_registry_len(&self) -> usize {
|
||||
self.symbol_registry.len()
|
||||
}
|
||||
|
||||
pub fn ic_hit_count(&self) -> u64 {
|
||||
self.ic_hits.get()
|
||||
}
|
||||
|
||||
pub fn ic_miss_count(&self) -> u64 {
|
||||
self.ic_misses.get()
|
||||
}
|
||||
|
||||
pub(crate) fn checked_object_ptr(
|
||||
&mut self, val: JsValue, error_msg: &str,
|
||||
) -> Result<Option<*mut JsObject>, String> {
|
||||
@@ -649,10 +689,12 @@ impl Vm {
|
||||
steps += 1;
|
||||
if let Some(max_steps) = self.kernel_core.config.max_steps {
|
||||
if steps > max_steps {
|
||||
self.instruction_count = steps;
|
||||
return Err(format!("VM step limit exceeded at pc={}", self.pc));
|
||||
}
|
||||
}
|
||||
if self.pc >= self.bytecode.len() {
|
||||
self.instruction_count = steps;
|
||||
return Err("program counter out of bounds".into());
|
||||
}
|
||||
|
||||
@@ -666,7 +708,10 @@ impl Vm {
|
||||
match op {
|
||||
OpCode::NOP => {}
|
||||
|
||||
OpCode::HALT => return Ok(self.regs[0]),
|
||||
OpCode::HALT => {
|
||||
self.instruction_count = steps;
|
||||
return Ok(self.regs[0]);
|
||||
}
|
||||
|
||||
OpCode::LOAD_CONST => {
|
||||
self.dispatch_load_const(rd, instr)?;
|
||||
|
||||
@@ -54,6 +54,9 @@ impl Vm {
|
||||
active_reg_limit: 0,
|
||||
native_call_depth: 0,
|
||||
accessor_frame_target_reg: None,
|
||||
ic_hits: std::cell::Cell::new(0),
|
||||
ic_misses: std::cell::Cell::new(0),
|
||||
instruction_count: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +99,9 @@ impl Vm {
|
||||
active_reg_limit: 0,
|
||||
native_call_depth: 0,
|
||||
accessor_frame_target_reg: None,
|
||||
ic_hits: std::cell::Cell::new(0),
|
||||
ic_misses: std::cell::Cell::new(0),
|
||||
instruction_count: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user