refactor: 对象分配统一入口并新增会话分配入口

This commit is contained in:
2026-09-29 14:23:07 +00:00
parent f70de8cb43
commit 87d43cd180
6 changed files with 53 additions and 37 deletions
+3 -13
View File
@@ -805,12 +805,7 @@ impl Vm {
// 函数对象直接 session 分配:寿命从调用级延至 session 级(session GC
// mark/sweep 回收)。若按 epoch 分配,写入全局等逃逸根时 promote 屏障会
// 深克隆进 session,全局属性与局部槽指针分裂、严格相等恒 false。
obj.set_session_epoch(true);
let obj_ptr = self.gc_state.session_epoch.alloc(obj) as *mut JsObject;
self.gc_state.session_object_ptrs.push(obj_ptr);
// 直 session 分配计入堆账目(与 promote 同式:对象头 + 对象堆数据)。
self.gc_state.session_bytes_allocated += std::mem::size_of::<JsObject>()
+ crate::session_gc::SessionGc::object_heap_data_bytes(unsafe { &*obj_ptr }) as usize;
let obj_ptr = self.alloc_session_object(obj);
let func_val = JsValue::object(obj_ptr as *mut u8);
if !is_arrow && !(is_async && !is_generator) {
@@ -826,13 +821,8 @@ impl Vm {
// prototype 子对象与函数本体同走 session 分配:`f.prototype ===
// globalThis.f.prototype` 要求两侧同一对象,epoch 分配会在逃逸写时
// 被递归克隆出第二份。
let mut prototype = JsObject::new_empty(EMPTY_SHAPE_ID, proto_of_proto);
prototype.set_session_epoch(true);
let prototype_obj = self.gc_state.session_epoch.alloc(prototype) as *mut JsObject;
self.gc_state.session_object_ptrs.push(prototype_obj);
// 直 session 分配计入堆账目(与 promote 同式:对象头 + 对象堆数据)。
self.gc_state.session_bytes_allocated += std::mem::size_of::<JsObject>()
+ crate::session_gc::SessionGc::object_heap_data_bytes(unsafe { &*prototype_obj }) as usize;
let prototype = JsObject::new_empty(EMPTY_SHAPE_ID, proto_of_proto);
let prototype_obj = self.alloc_session_object(prototype);
let prototype_val = JsValue::from_js_object(prototype_obj);
if !is_generator {