Truly independent web browser
LibJS/JIT: Name the allocation each virtual object stands for
Andreas Kling4ef3cc5863b5
diff --git a/Libraries/LibJS/JIT/Rust/src/code.rs b/Libraries/LibJS/JIT/Rust/src/code.rsindex 5314c6bd7df..7ff7c50b319 100644--- a/Libraries/LibJS/JIT/Rust/src/code.rs+++ b/Libraries/LibJS/JIT/Rust/src/code.rs@@ -202,6 +202,10 @@ pub enum SiteKind {#[derive(Debug, Clone, PartialEq, Eq)]pub struct VirtualObjectDescriptor {pub shape: CellId,+ /// The node index of the allocation the object stands for, which is the+ /// same at every site of the code: the runtime may have created the+ /// object at another site of the same frame already, and then uses that.+ pub allocation: u32,pub properties: Vec<ValueLocation>,}diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/sites.rs b/Libraries/LibJS/JIT/Rust/src/codegen/sites.rsindex a75494e5649..85c21c41e9c 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/sites.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/sites.rs@@ -92,7 +92,7 @@ pub(crate) fn site(let objects = objects.iter().map(|object| {- let Op::VirtualObject { shape } = graph.node(*object).op else {+ let Op::VirtualObject { shape, allocation } = graph.node(*object).op else {unreachable!("virtual objects are VirtualObject nodes");};let properties = graph@@ -101,7 +101,11 @@ pub(crate) fn site(.iter().map(|property| location_of(*property).1).collect();- VirtualObjectDescriptor { shape, properties }+ VirtualObjectDescriptor {+ shape,+ allocation: allocation.0,+ properties,+ }}).collect();let inlined_frame_bytes = match graph.node(node).op {diff --git a/Libraries/LibJS/JIT/Rust/src/ir/dump.rs b/Libraries/LibJS/JIT/Rust/src/ir/dump.rsindex 929888e7093..9e5252e89e5 100644--- a/Libraries/LibJS/JIT/Rust/src/ir/dump.rs+++ b/Libraries/LibJS/JIT/Rust/src/ir/dump.rs@@ -217,7 +217,7 @@ fn op_text(layout: &FrameLayout, op: &Op, inputs: &str) -> String {}Op::InitializeNamed { offset } => with_inputs(&format!("InitializeNamed +{offset}")),Op::AllocateArray { count } => format!("AllocateArray with {count} elements"),- Op::VirtualObject { shape } => with_inputs(&format!("VirtualObject {:#x}", shape.0)),+ Op::VirtualObject { shape, .. } => with_inputs(&format!("VirtualObject {:#x}", shape.0)),Op::AllocateEnvironment { shape_cache, capacity } => {with_inputs(&format!("AllocateEnvironment {shape_cache} capacity {capacity}"))}diff --git a/Libraries/LibJS/JIT/Rust/src/ir/mod.rs b/Libraries/LibJS/JIT/Rust/src/ir/mod.rsindex bd2ac7aba13..1302bb0965f 100644--- a/Libraries/LibJS/JIT/Rust/src/ir/mod.rs+++ b/Libraries/LibJS/JIT/Rust/src/ir/mod.rs@@ -716,9 +716,12 @@ pub enum Op {/// properties (the inputs, in offset order), as an exit needs it: the/// runtime creates it with `shape` when the exit is taken. Frame states/// refer to it; it is in no block and has no code. An input may be- /// another virtual object.+ /// another virtual object. Every frame state refers to the object the+ /// `AllocateObject` node `allocation` made with a virtual object of its+ /// own, and `allocation` tells the runtime they are the same object.VirtualObject {shape: CellId,+ allocation: NodeId,},/// A new array of `count` packed elements, all `undefined`, of the/// realm of the compiled code (see `ArrayAllocationInfo`). Like@@ -2359,13 +2362,19 @@ mod tests {let mut graph = Graph::default();let value = graph.add_node(Node::new(Op::Constant(value::UNDEFINED), vec![], Some(Repr::Tagged), 0));let inner = graph.add_node(Node::new(- Op::VirtualObject { shape: CellId(1) },+ Op::VirtualObject {+ shape: CellId(1),+ allocation: NodeId(0),+ },vec![value],Some(Repr::Tagged),0,));let outer = graph.add_node(Node::new(- Op::VirtualObject { shape: CellId(2) },+ Op::VirtualObject {+ shape: CellId(2),+ allocation: NodeId(1),+ },vec![inner, value],Some(Repr::Tagged),0,diff --git a/Libraries/LibJS/JIT/Rust/src/passes/dce.rs b/Libraries/LibJS/JIT/Rust/src/passes/dce.rsindex 1c41cd3d4c0..8ca29a58758 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/dce.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/dce.rs@@ -82,7 +82,7 @@ fn remove_dead_nodes(graph: &mut Graph) {mod tests {use super::*;use crate::code::{Repr, ResumeMode};- use crate::ir::{BinaryOp, Block, FrameState};+ use crate::ir::{BinaryOp, Block, FrameState, NodeId};use crate::snapshot::CellId;#[test]@@ -122,7 +122,10 @@ mod tests {0,));let object = graph.add_node(crate::ir::Node::new(- Op::VirtualObject { shape: CellId(1) },+ Op::VirtualObject {+ shape: CellId(1),+ allocation: NodeId(0),+ },vec![boxed],Some(Repr::Tagged),0,diff --git a/Libraries/LibJS/JIT/Rust/src/passes/escape_analysis.rs b/Libraries/LibJS/JIT/Rust/src/passes/escape_analysis.rsindex d41b23b0649..982265447a8 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/escape_analysis.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/escape_analysis.rs@@ -531,7 +531,10 @@ fn virtualize_frame_state(}let (shape, _) = shapes[&root];let object = graph.add_node(Node::new(- Op::VirtualObject { shape },+ Op::VirtualObject {+ shape,+ allocation: root,+ },Vec::new(),Some(Repr::Tagged),graph.node(root).pc,