feat: 内核预留 MessagePort 原型与 MessageChannel 构造器槽位

This commit is contained in:
2026-10-09 03:08:52 +00:00
parent ff31e5bfd7
commit 0ea87b8001
9 changed files with 72 additions and 28 deletions
Generated
+19 -19
View File
@@ -1160,7 +1160,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_builtins" name = "oxide_builtins"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"chrono", "chrono",
"fast-float", "fast-float",
@@ -1185,7 +1185,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_bytecode" name = "oxide_bytecode"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"num-bigint", "num-bigint",
"oxide_log", "oxide_log",
@@ -1193,7 +1193,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_cfg" name = "oxide_cfg"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_emit", "oxide_emit",
@@ -1204,7 +1204,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_cli" name = "oxide_cli"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"bumpalo", "bumpalo",
@@ -1226,7 +1226,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_code_cache" name = "oxide_code_cache"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"lru", "lru",
"oxide_bytecode", "oxide_bytecode",
@@ -1235,7 +1235,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_compiler" name = "oxide_compiler"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_cfg", "oxide_cfg",
@@ -1255,7 +1255,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_dce" name = "oxide_dce"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_cfg", "oxide_cfg",
@@ -1269,7 +1269,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_emit" name = "oxide_emit"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"num-bigint", "num-bigint",
"oxc_allocator", "oxc_allocator",
@@ -1284,7 +1284,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_engine" name = "oxide_engine"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_compiler", "oxide_compiler",
@@ -1296,7 +1296,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_ir" name = "oxide_ir"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_log", "oxide_log",
@@ -1305,7 +1305,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_kernel" name = "oxide_kernel"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"dashmap", "dashmap",
@@ -1319,7 +1319,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_liveness" name = "oxide_liveness"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_cfg", "oxide_cfg",
@@ -1331,7 +1331,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_log" name = "oxide_log"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"tracing", "tracing",
"tracing-appender", "tracing-appender",
@@ -1340,7 +1340,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_parser" name = "oxide_parser"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"oxc_allocator", "oxc_allocator",
"oxc_ast", "oxc_ast",
@@ -1355,7 +1355,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_regalloc" name = "oxide_regalloc"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_cfg", "oxide_cfg",
@@ -1371,7 +1371,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_runtime_api" name = "oxide_runtime_api"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"num-bigint", "num-bigint",
"num-traits", "num-traits",
@@ -1384,7 +1384,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_test262" name = "oxide_test262"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_compiler", "oxide_compiler",
@@ -1402,7 +1402,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_types" name = "oxide_types"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"dashmap", "dashmap",
@@ -1415,7 +1415,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_vm" name = "oxide_vm"
version = "0.8.83" version = "0.8.84"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"chrono", "chrono",
+1 -1
View File
@@ -23,7 +23,7 @@ members = [
] ]
[workspace.package] [workspace.package]
version = "0.8.83" version = "0.8.84"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
rust-version = "1.80" rust-version = "1.80"
@@ -502,6 +502,12 @@ impl BuiltinWorld {
let console_object = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())); let console_object = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
// MessagePort 原型与 MessageChannel 构造器的内核接线占位(空对象):
// 真实原型/构造器本体与原型链连线由绑定层后续任务填充,本处只预留
// 槽位使快照/脏检查/收尾枚举覆盖到这两枚 P 字段。
let message_port_proto = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
let message_channel_constructor = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
let (date_proto, date_constructor) = make_named_pair(string_forge, shape_forge, labels, "Date"); let (date_proto, date_constructor) = make_named_pair(string_forge, shape_forge, labels, "Date");
let (set_proto, set_constructor) = make_named_pair(string_forge, shape_forge, labels, "Set"); let (set_proto, set_constructor) = make_named_pair(string_forge, shape_forge, labels, "Set");
let (map_proto, map_constructor) = make_named_pair(string_forge, shape_forge, labels, "Map"); let (map_proto, map_constructor) = make_named_pair(string_forge, shape_forge, labels, "Map");
@@ -649,6 +655,8 @@ impl BuiltinWorld {
async_disposable_stack_proto, async_disposable_stack_proto,
stub_objects, stub_objects,
console_object, console_object,
message_port_proto,
message_channel_constructor,
leaked_objects: std::cell::RefCell::new(Vec::new()), leaked_objects: std::cell::RefCell::new(Vec::new()),
}; };
wire_builtin_world_links(&world); wire_builtin_world_links(&world);
@@ -396,6 +396,16 @@ impl BuiltinWorld {
} else { } else {
current.console_object.clone() current.console_object.clone()
}; };
// MessagePort 原型与 MessageChannel 构造器:脏则换新空对象占位(与
// 全量构造同形),未脏沿用旧指针。
let (message_port_proto, message_channel_constructor) = if dirty.message_channel {
(
P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
)
} else {
(current.message_port_proto.clone(), current.message_channel_constructor.clone())
};
// 迭代器原型与资源栈原型依赖 Object.prototype(链到其上):object 家族重建时 // 迭代器原型与资源栈原型依赖 Object.prototype(链到其上):object 家族重建时
// 一并重建,否则旧原型链指向已释放的 object_proto。 // 一并重建,否则旧原型链指向已释放的 object_proto。
@@ -547,6 +557,8 @@ impl BuiltinWorld {
async_disposable_stack_proto, async_disposable_stack_proto,
stub_objects, stub_objects,
console_object, console_object,
message_port_proto,
message_channel_constructor,
leaked_objects: std::cell::RefCell::new(Vec::new()), leaked_objects: std::cell::RefCell::new(Vec::new()),
}; };
wire_builtin_world_links(&world); wire_builtin_world_links(&world);
+13 -3
View File
@@ -1,5 +1,5 @@
//! 注册表职责:BuiltinWorld 结构(95 固定 P 字段 + stub 族 + Box::into_raw //! 注册表职责:BuiltinWorld 结构(97 固定 P 字段 + stub 族 + Box::into_raw
//! 登记表)、get_by_id 派发、all_p_fields 95 元组枚举(新增 P 字段四处同步 //! 登记表)、get_by_id 派发、all_p_fields 97 元组枚举(新增 P 字段四处同步
//! 约束载体)与登记表 track/find/inherit/teardown。 //! 约束载体)与登记表 track/find/inherit/teardown。
use oxide_types::mem::P; use oxide_types::mem::P;
@@ -138,6 +138,12 @@ pub struct BuiltinWorld {
pub async_disposable_stack_proto: P<JsObject>, pub async_disposable_stack_proto: P<JsObject>,
pub stub_objects: Vec<P<JsObject>>, pub stub_objects: Vec<P<JsObject>>,
pub console_object: P<JsObject>, pub console_object: P<JsObject>,
/// `MessagePort.prototype` 槽位:纯内核接线占位(空对象),真实原型本体
/// 与构造器对由绑定层后续任务填充;脏家族位为 `message_channel`。
pub message_port_proto: P<JsObject>,
/// `MessageChannel` 构造器槽位:纯内核接线占位(空对象),真实构造器
/// 本体由绑定层后续任务填充。
pub message_channel_constructor: P<JsObject>,
/// 释放登记表(`Box::into_raw` 对象的清单,session 收尾统一释放,非内存泄漏): /// 释放登记表(`Box::into_raw` 对象的清单,session 收尾统一释放,非内存泄漏):
/// 绑定层经 `Box::into_raw` 持有的函数/宿主对象(方法 wrapper、访问器、 /// 绑定层经 `Box::into_raw` 持有的函数/宿主对象(方法 wrapper、访问器、
/// 错误构造器、Reflect/Iterator、内建原型构造器、`$262` 宿主等)。 /// 错误构造器、Reflect/Iterator、内建原型构造器、`$262` 宿主等)。
@@ -368,7 +374,7 @@ impl BuiltinWorld {
/// session 收尾(`teardown_heap_data`)与选择性重建收尾(`retire_replaced`) /// session 收尾(`teardown_heap_data`)与选择性重建收尾(`retire_replaced`)
/// 的 P 字段枚举唯一入口:`BuiltinWorld` 新增 P 字段须在此同步补一行,否则 /// 的 P 字段枚举唯一入口:`BuiltinWorld` 新增 P 字段须在此同步补一行,否则
/// 收尾时该字段属性区无法释放、重建原型槽改写/释放漏掉该字段。 /// 收尾时该字段属性区无法释放、重建原型槽改写/释放漏掉该字段。
pub(crate) fn all_p_fields(&self) -> [&P<JsObject>; 95] { pub(crate) fn all_p_fields(&self) -> [&P<JsObject>; 97] {
[ [
&self.object_proto, &self.object_proto,
&self.array_proto, &self.array_proto,
@@ -465,6 +471,8 @@ impl BuiltinWorld {
&self.disposable_stack_proto, &self.disposable_stack_proto,
&self.async_disposable_stack_proto, &self.async_disposable_stack_proto,
&self.console_object, &self.console_object,
&self.message_port_proto,
&self.message_channel_constructor,
] ]
} }
@@ -598,6 +606,8 @@ impl BuiltinWorld {
BuiltinId::BigIntProto => &self.bigint_proto, BuiltinId::BigIntProto => &self.bigint_proto,
BuiltinId::Console => &self.console_object, BuiltinId::Console => &self.console_object,
BuiltinId::AsyncIteratorProto => &self.async_iterator_proto, BuiltinId::AsyncIteratorProto => &self.async_iterator_proto,
BuiltinId::MessagePortProto => &self.message_port_proto,
BuiltinId::MessageChannelCtor => &self.message_channel_constructor,
} }
} }
} }
+14 -5
View File
@@ -1,4 +1,4 @@
//! 内置对象 id 枚举(`BuiltinId` 85 变体 + `ALL` 顺序钉表)、世代快照 //! 内置对象 id 枚举(`BuiltinId` 87 变体 + `ALL` 顺序钉表)、世代快照
//! (`BuiltinSnapshot`)与按家族划分的脏标记位集(`BuiltinDirtySet`); //! (`BuiltinSnapshot`)与按家族划分的脏标记位集(`BuiltinDirtySet`);
//! `NUM_BUILTINS` 文档承载"新增 BuiltinWorld 字段须同步"四处约束注记。 //! `NUM_BUILTINS` 文档承载"新增 BuiltinWorld 字段须同步"四处约束注记。
@@ -11,7 +11,7 @@ use crate::builtin::BuiltinWorld;
/// 维护注意:每个新增的 `BuiltinWorld` 对象字段都必须加到这里以及 /// 维护注意:每个新增的 `BuiltinWorld` 对象字段都必须加到这里以及
/// `KernelSession::dirty_since_snapshot()`,以便选择性重置重建正确的 /// `KernelSession::dirty_since_snapshot()`,以便选择性重置重建正确的
/// builtin 家族。 /// builtin 家族。
pub const NUM_BUILTINS: usize = 85; pub const NUM_BUILTINS: usize = 87;
/// 内置对象枚举 id,与 `BuiltinWorld` 中的存储槽一一对应。 /// 内置对象枚举 id,与 `BuiltinWorld` 中的存储槽一一对应。
/// ///
@@ -105,6 +105,8 @@ pub enum BuiltinId {
SharedArrayBufferConstructor = 82, SharedArrayBufferConstructor = 82,
AtomicsObject = 83, AtomicsObject = 83,
AsyncIteratorProto = 84, AsyncIteratorProto = 84,
MessagePortProto = 85,
MessageChannelCtor = 86,
} }
impl BuiltinId { impl BuiltinId {
@@ -197,6 +199,8 @@ impl BuiltinId {
BuiltinId::SharedArrayBufferConstructor, BuiltinId::SharedArrayBufferConstructor,
BuiltinId::AtomicsObject, BuiltinId::AtomicsObject,
BuiltinId::AsyncIteratorProto, BuiltinId::AsyncIteratorProto,
BuiltinId::MessagePortProto,
BuiltinId::MessageChannelCtor,
]; ];
} }
@@ -272,6 +276,7 @@ pub struct BuiltinDirtySet {
pub stubs: bool, pub stubs: bool,
pub global: bool, pub global: bool,
pub console: bool, pub console: bool,
pub message_channel: bool,
} }
impl BuiltinDirtySet { impl BuiltinDirtySet {
@@ -305,6 +310,7 @@ impl BuiltinDirtySet {
stubs: true, stubs: true,
global: true, global: true,
console: true, console: true,
message_channel: true,
} }
} }
@@ -332,6 +338,7 @@ impl BuiltinDirtySet {
|| self.temporal || self.temporal
|| self.stubs || self.stubs
|| self.console || self.console
|| self.message_channel
} }
/// 是否存在任何污染(builtin world 或 global object)。 /// 是否存在任何污染(builtin world 或 global object)。
@@ -344,19 +351,21 @@ impl BuiltinDirtySet {
mod tests { mod tests {
use super::*; use super::*;
/// 槽对齐面:ALL 表与判别值 0..84 严格同序,快照数组随 NUM_BUILTINS /// 槽对齐面:ALL 表与判别值 0..86 严格同序,快照数组随 NUM_BUILTINS
/// 自动扩维、逐槽对齐。 /// 自动扩维、逐槽对齐。
#[test] #[test]
fn builtin_snapshot_all_slots_aligned() { fn builtin_snapshot_all_slots_aligned() {
assert_eq!(NUM_BUILTINS, 85); assert_eq!(NUM_BUILTINS, 87);
assert_eq!(BuiltinId::ALL.len(), NUM_BUILTINS); assert_eq!(BuiltinId::ALL.len(), NUM_BUILTINS);
for i in 0..84usize { for i in 0..86usize {
assert_eq!(BuiltinId::ALL[i] as usize, i); assert_eq!(BuiltinId::ALL[i] as usize, i);
} }
assert_eq!(BuiltinId::ALL[81], BuiltinId::SharedArrayBufferProto); assert_eq!(BuiltinId::ALL[81], BuiltinId::SharedArrayBufferProto);
assert_eq!(BuiltinId::ALL[82], BuiltinId::SharedArrayBufferConstructor); assert_eq!(BuiltinId::ALL[82], BuiltinId::SharedArrayBufferConstructor);
assert_eq!(BuiltinId::ALL[83], BuiltinId::AtomicsObject); assert_eq!(BuiltinId::ALL[83], BuiltinId::AtomicsObject);
assert_eq!(BuiltinId::ALL[84], BuiltinId::AsyncIteratorProto); assert_eq!(BuiltinId::ALL[84], BuiltinId::AsyncIteratorProto);
assert_eq!(BuiltinId::ALL[85], BuiltinId::MessagePortProto);
assert_eq!(BuiltinId::ALL[86], BuiltinId::MessageChannelCtor);
// 快照经 session 全量构造路径采集,generations 数组维度 = 槽数。 // 快照经 session 全量构造路径采集,generations 数组维度 = 槽数。
use crate::kernel::{KernelConfig, KernelCore, KernelSession}; use crate::kernel::{KernelConfig, KernelCore, KernelSession};
@@ -196,6 +196,8 @@ impl KernelSession {
|| gen(BuiltinId::BigIntProto) != snap(BuiltinId::BigIntProto), || gen(BuiltinId::BigIntProto) != snap(BuiltinId::BigIntProto),
global: BuiltinSnapshot::gen(&self.global_object) != snapshot.global_object_generation, global: BuiltinSnapshot::gen(&self.global_object) != snapshot.global_object_generation,
console: gen(BuiltinId::Console) != snap(BuiltinId::Console), console: gen(BuiltinId::Console) != snap(BuiltinId::Console),
message_channel: gen(BuiltinId::MessagePortProto) != snap(BuiltinId::MessagePortProto)
|| gen(BuiltinId::MessageChannelCtor) != snap(BuiltinId::MessageChannelCtor),
}; };
// wrapper 本体被写不落在任何家族位上(写的是 wrapper 自身而非所属 P // wrapper 本体被写不落在任何家族位上(写的是 wrapper 自身而非所属 P
// 对象):收缩为全脏,强制重建全部家族与 global,使被写的可复用 // 对象):收缩为全脏,强制重建全部家族与 global,使被写的可复用
+2
View File
@@ -100,6 +100,8 @@ pub enum ProtoKind {
Float64ArrayConstructor, Float64ArrayConstructor,
BigInt64ArrayConstructor, BigInt64ArrayConstructor,
BigUint64ArrayConstructor, BigUint64ArrayConstructor,
// 消息通道原型
MessagePortProto,
} }
/// builtins 依赖的 `Vm` 能力集合。 /// builtins 依赖的 `Vm` 能力集合。
+1
View File
@@ -142,6 +142,7 @@ impl oxide_runtime_api::VmHost for Vm {
ProtoKind::Float64ArrayConstructor => &world.float64array_constructor, ProtoKind::Float64ArrayConstructor => &world.float64array_constructor,
ProtoKind::BigInt64ArrayConstructor => &world.bigint64array_constructor, ProtoKind::BigInt64ArrayConstructor => &world.bigint64array_constructor,
ProtoKind::BigUint64ArrayConstructor => &world.biguint64array_constructor, ProtoKind::BigUint64ArrayConstructor => &world.biguint64array_constructor,
ProtoKind::MessagePortProto => &world.message_port_proto,
}; };
P::as_ptr(p) as *mut JsObject P::as_ptr(p) as *mut JsObject
} }