Skip to content

feat(vm): Singleton VM - #995

Open
aapoalas wants to merge 7 commits into
mainfrom
perf/vm-move-vm-inside-agent
Open

aapoalas wants to merge 7 commits into
mainfrom
perf/vm-move-vm-inside-agent

Conversation

@aapoalas

Copy link
Copy Markdown
Member

Stop allocating a VM per function call, instead run all functions in the same VM with a form of stack frames keeping the count to make sure we stay valid with that. The result and reference registers are now actively clobbered: it's quite possible that there is a lot of places (odd JavaSccript, especially get/set methods throwing in the middle of member path evaluation or such, where the result is still invalidly clobbered, but at least the test262 tests have not regressed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Compilation failures and unresolved reference-preservation, destructuring, and iterator-cleanup regressions block approval.

8 open issues
What changed in this PR

This PR replaces per-call VM allocation with one VM owned by each agent. Execution contexts track stack frames and executables, while bytecode explicitly preserves values and references across nested calls.

Changes:

  • Introduces shared VM stacks, frame boundaries, and suspension/resumption handling.
  • Updates bytecode generation and execution for shared registers and iterator cleanup.
  • Moves executable ownership and garbage-collection tracing into execution contexts.
File Description
nova_vm/​src/​engine/​bytecode/​vm/​execute_instructions.rs Runs instructions against the agent’s shared VM.
nova_vm/​src/​engine/​bytecode/​vm/​binding_methods.rs Adapts destructuring to shared stacks and frame-relative slots.
nova_vm/​src/​engine/​bytecode/​vm.rs Implements shared frames, suspension, and register handling.
nova_vm/​src/​engine/​bytecode/​iterator.rs Accesses active iterators through the shared VM.
nova_vm/​src/​engine/​bytecode/​instructions.rs Updates reference instructions and stack-slot addressing.
nova_vm/​src/​engine/​bytecode/​executable.rs Exposes executable accessors and removes scoped wrappers.
nova_vm/​src/​engine/​bytecode/​bytecode_compiler/​for_in_of_statement.rs Revises async iteration and cleanup bytecode.
nova_vm/​src/​engine/​bytecode/​bytecode_compiler/​assignment.rs Preserves assignment references across nested execution.
nova_vm/​src/​engine/​bytecode/​bytecode_compiler.rs Updates calls, optional chains, and delegated yields.
nova_vm/​src/​ecmascript/​types/​spec/​reference.rs Adds reference comparison and expression detection.
nova_vm/​src/​ecmascript/​types/​language/​object.rs Allows shape-based object creation through the heap.
nova_vm/​src/​ecmascript/​syntax_directed_operations/​function_definitions.rs Executes function bodies through the agent.
nova_vm/​src/​ecmascript/​scripts_and_modules/​script.rs Associates script executables with execution contexts.
nova_vm/​src/​ecmascript/​scripts_and_modules/​module/​module_semantics/​source_text_module_records.rs Migrates module execution to the shared VM.
nova_vm/​src/​ecmascript/​execution/​execution_context.rs Stores and traces executable and frame state.
nova_vm/​src/​ecmascript/​execution/​agent.rs Owns the VM and coordinates execution-context transitions.
nova_vm/​src/​ecmascript/​builtins/​global_object.rs Migrates eval execution to the agent.
nova_vm/​src/​ecmascript/​builtins/​ecmascript_function.rs Initializes frame state for ordinary calls.
nova_vm/​src/​ecmascript/​builtins/​control_abstraction_objects/​generator_objects.rs Resumes generators through the agent.
nova_vm/​src/​ecmascript/​builtins/​control_abstraction_objects/​async_generator_objects/​async_generator_abstract_operations.rs Routes async-generator resumptions through the agent.
nova_vm/​src/​ecmascript/​builtins/​control_abstraction_objects/​async_generator_objects.rs Removes separate async-generator executable storage.
nova_vm/​src/​ecmascript/​builtins/​control_abstraction_objects/​async_function_objects/​await_reaction.rs Uses saved execution contexts when resuming awaits.
nova_vm/​src/​ecmascript/​builtins/​builtin_function.rs Makes scoped argument handles cloneable.
nova_vm/​src/​ecmascript/​builtins/​arguments.rs Accepts scoped argument handles by value.
nova_vm/​src/​ecmascript/​abstract_operations/​operations_on_objects.rs Runs instance initializers through the shared VM.

Review effort: Balanced

Comment on lines +2022 to +2024
if ctx.is_call_optional_chain_this {
// Move kept reference into register.
ctx.add_instruction(Instruction::PopReference);
Comment on lines +528 to +530
agent.vm.ip = ip as usize;
agent.set_current_lexical_environment(lexical_environment);
agent.vm.result = Some(err.value().unbind());
Comment thread nova_vm/src/engine/bytecode/vm.rs Resolved
Comment thread nova_vm/src/engine/bytecode/vm.rs Resolved
let mut idx = 0u32;
while let Some(result) = iterator
.step_value(agent, gc.reborrow())
.unbind()?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants