feat: 添加 Kernel 与 VM 分层结构化日志

This commit is contained in:
爱特每羊队
2026-06-13 18:59:41 +08:00
parent 0e6b1b8b3b
commit 6144e51c1c
15 changed files with 415 additions and 6 deletions
+4
View File
@@ -1,5 +1,6 @@
use crate::native::{NativeFn, NativeResult};
use crate::vm::{native_fn_ptr_to_fn, FrameContinuation, Vm};
use oxide_kernel::{builtins_debug, builtins_trace};
use oxide_types::object::JsObject;
use oxide_types::value::JsValue;
@@ -24,6 +25,7 @@ impl Vm {
}
let (args_buf, len) = Self::build_native_args(first_arg_reg, arg_count, this_reg);
let args_slice = &args_buf[..len];
builtins_debug!("native_call depth={} args={}", self.native_call_depth, arg_count);
// SAFETY: native_fn was set via set_native_fn with a valid NativeFn pointer;
// native_fn_ptr_to_fn is the single coercion point for NativeFnPtr → NativeFn.
@@ -33,6 +35,7 @@ impl Vm {
match func(self, args_slice) {
NativeResult::Ok(val) => {
self.native_call_depth -= 1;
builtins_trace!("native_call ok depth={}", self.native_call_depth);
self.regs[0] = val;
Ok(())
}
@@ -49,6 +52,7 @@ impl Vm {
} else {
format!("{err_val}")
};
builtins_debug!("native_call err={}", msg);
(crate::builtins::error::create_error(self, &msg), "Error")
};
self.exception_value = Some(error);
+14
View File
@@ -1,5 +1,6 @@
use oxide_compiler::opcode::OpCode;
use oxide_kernel::prop_forge::PropTemplate;
use oxide_kernel::{ic_debug, ic_trace};
use oxide_types::object::JsObject;
use crate::vm::Vm;
@@ -71,18 +72,28 @@ impl Vm {
if cached_shape_id != 0 && cached_shape_id == obj.shape_id() && cached_slot < obj.prop_vec_len() as u32 {
self.regs[a] = obj.get_prop_at(cached_slot);
ic_trace!("IC_GET hit shape={} slot={}", cached_shape_id, cached_slot);
} else if let Some(template) = self.kernel.prop_forge().get_template(obj.shape_id()) {
if template.prop_name == prop_name_si {
if template.position < obj.prop_vec_len() as u32 {
self.write_ic_back(obj.shape_id(), template.position);
ic_debug!(
"IC_GET propforge hit shape={} prop={} slot={}",
obj.shape_id(),
prop_name_si,
template.position
);
self.regs[a] = obj.get_prop_at(template.position);
} else {
ic_debug!("IC_GET miss shape={} prop={}", obj.shape_id(), prop_name_si);
self.regs[a] = self.ordinary_get(obj, prop_name_si, val)?;
}
} else {
ic_debug!("IC_GET miss shape={} prop={}", obj.shape_id(), prop_name_si);
self.regs[a] = self.ordinary_get(obj, prop_name_si, val)?;
}
} else {
ic_debug!("IC_GET miss shape={} prop={}", obj.shape_id(), prop_name_si);
let resolved = self.ordinary_get(obj, prop_name_si, val)?;
if let Some(pos) = self.kernel.shape_forge().lookup_position(obj.shape_id(), prop_name_si) {
self.write_ic_back(obj.shape_id(), pos);
@@ -127,15 +138,18 @@ impl Vm {
if cached_shape_id != 0 && cached_shape_id == obj.shape_id() && cached_slot < obj.prop_vec_len() as u32 {
obj.set_prop_at(cached_slot, value);
ic_trace!("IC_SET hit shape={} slot={}", cached_shape_id, cached_slot);
} else if let Some(pos) = self.kernel.shape_forge().lookup_position(obj.shape_id(), prop_name_si) {
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 {
let old_shape = obj.shape_id();
self.ordinary_set_dispatch(obj, prop_name_si, value, receiver)?;
if old_shape != obj.shape_id() {
if let Some(pos) = self.kernel.shape_forge().lookup_position(obj.shape_id(), prop_name_si) {
self.write_ic_back(obj.shape_id(), pos);
ic_debug!("IC_SET write-back shape={} slot={}", obj.shape_id(), pos);
self.kernel.prop_forge().upsert(
obj.shape_id(),
PropTemplate {
+13
View File
@@ -12,6 +12,7 @@ use crate::coercion;
use crate::native::{NativeFn, NativeResult};
use oxide_kernel::kernel::{KernelConfig, OxideKernel};
use oxide_kernel::shape_forge::EMPTY_SHAPE_ID;
use oxide_kernel::{vm_debug, vm_trace};
use oxide_types::mem::{Epoch, P};
use oxide_types::object::{JsObject, NativeFnPtr, PropAttributes};
use oxide_types::value::JsValue;
@@ -1355,6 +1356,13 @@ impl Vm {
let ext = self.bytecode[self.pc];
self.pc += 1;
let arg_count = (ext & 0xFF) as usize;
vm_debug!(
"CALL rd={} this={} args={} depth={}",
rd,
this_reg,
arg_count,
self.frames.len()
);
if obj.native_fn().is_some() {
match self.dispatch_native_call(obj, callee, this_reg, first_arg_reg, arg_count) {
@@ -1405,6 +1413,7 @@ impl Vm {
let ext = self.bytecode[self.pc];
self.pc += 1;
let arg_count = (ext & 0xFF) as usize;
vm_debug!("CALL_NATIVE rd={} args={}", rd, arg_count);
self.dispatch_native_call(obj, callee, this_reg, first_arg_reg, arg_count)?;
}
@@ -1412,6 +1421,7 @@ impl Vm {
OpCode::NEW_EXPRESSION => {
let constructor_reg = a;
let first_arg_reg = b as u8;
vm_debug!("NEW_EXPRESSION rd={}", rd);
let constructor = self.regs[constructor_reg];
if !constructor.is_object() {
@@ -1780,6 +1790,7 @@ impl Vm {
OpCode::RETURN => {
let result = self.regs[rd];
vm_debug!("RETURN depth={}", self.frames.len());
if let Some(frame) = self.frames.pop() {
let construct_result_reg = frame.construct_result_reg;
let constructed_this = frame.constructed_this;
@@ -2156,6 +2167,7 @@ impl Vm {
}
OpCode::THROW => {
vm_debug!("THROW pc={}", self.pc);
let exc_value = self.regs[rd];
self.exception_value = Some(exc_value);
self.pending_error_kind = Some(self.thrown_error_kind(exc_value));
@@ -2166,6 +2178,7 @@ impl Vm {
}
OpCode::TRY_BEGIN => {
vm_trace!("TRY_BEGIN frame_depth={}", self.frames.len());
let offset = opcode::offset16(instr) as isize;
let catch_pc = if offset == 0 {
None