Truly independent web browser
# Copyright (c) 2026-present, the Ladybird developers.
# SPDX-License-Identifier: BSD-2-Clause
# Typed Flap bytecode semantics for the JavaScript interpreter.
inline fn max(lhs: u32, rhs: u32) -> u32 {
if lhs >= rhs {
lhs
} else {
rhs
}
}
inline fn call_length(
argument_count: u8
) -> u32 {
let mut count: u32;
load8(count, [pb, pc, argument_count]);
# NB: 7 is what a Call takes up before its arguments, which are a byte each. Any call breaks if it goes out of date.
let length: u32 = 7 + count;
length
}
inline fn call_site_info(
argument_count: u8,
dst: out Operand
) -> (u32, u32, u32) {
let instruction_length: u32 = call_length(argument_count);
let mut destination_index: u32;
load8(destination_index, [pb, pc, dst]);
let current_pc: u32 = pc;
let return_pc: u32 = current_pc + instruction_length;
(current_pc, return_pc, destination_index)
}
inline fn check_tag_is_double(tag: inout ValueTag, else failure: Label) {
tag = tag & NAN_BASE_TAG;
guard tag != NAN_BASE_TAG else failure;
}
inline fn box_cell(cell: Environment) -> Value {
let mut bits: u64 = alias(cell);
bits = heap_region_offset(bits);
bits = bits | SHIFTED_IS_CELL_PATTERN;
# FIXME: Use a representation alias once it can coalesce with an inline
# function return without leaving its result uninitialized.
let mut value: Value;
mov(value, bits);
value
}
inline fn box_object(object: Object) -> Value<Object> {
let mut pointer: u64 = alias(object);
pointer = heap_region_offset(pointer);
pointer = pointer | OBJECT_TAG_SHIFTED;
# FIXME: Use a representation alias once it can coalesce with an inline
# function return without leaving its result uninitialized.
let mut value: Value<Object>;
mov(value, pointer);
value
}
# The field a direct getter returns is a compressed cell pointer for a GC::Member, and a full one otherwise.
inline fn load_direct_getter_implementation_value(address: u64, is_compressed: u32) -> u64 {
if is_compressed != 0 {
let mut value: u64;
load_compressed_cell_ptr(value, [address]);
value
} else {
let mut value: u64;
load64(value, [address]);
value
}
}
inline fn load_direct_getter_value(
function: Object,
receiver_object: Object,
else failure: Label
) -> Value {
let direct_getter: DirectGetterFunction = alias(function);
# The validated cache entry only pins the receiver's shape, and an ordinary object created from a wrapper's
# prototype shares that shape while being too small to have an implementation slot.
guard receiver_object.flags has OBJECT_FLAG_IS_PLATFORM_OBJECT else failure;
let wrapper_words: Sequence<u64> = alias(receiver_object);
let implementation = wrapper_words[direct_getter.wrapper_implementation_word_offset];
guard implementation != 0 else failure;
let implementation_words: Sequence<u64> = alias(implementation);
# This first version directly reuses wrappers only in the main world.
let receiver_weak_impl = implementation_words[direct_getter.main_world_wrapper_word_offset];
guard receiver_weak_impl != 0 else failure;
let receiver_weak_impl_words: Sequence<u64> = alias(receiver_weak_impl);
let cached_receiver = receiver_weak_impl_words[direct_getter.weak_impl_value_word_offset];
let receiver_pointer: u64 = alias(receiver_object);
guard cached_receiver == receiver_pointer else failure;
let result_implementation_address: u64 = implementation + alias(direct_getter.implementation_value_offset);
let result_implementation = load_direct_getter_implementation_value(
result_implementation_address,
direct_getter.implementation_value_is_compressed
);
if result_implementation == 0 {
let mut null_value: Value;
mov(null_value, NULL_VALUE);
null_value
} else {
let result_implementation_words: Sequence<u64> = alias(result_implementation);
let result_weak_impl = result_implementation_words[direct_getter.main_world_wrapper_word_offset];
guard result_weak_impl != 0 else failure;
let result_weak_impl_words: Sequence<u64> = alias(result_weak_impl);
let cached_result = result_weak_impl_words[direct_getter.weak_impl_value_word_offset];
guard cached_result != 0 else failure;
let result_object: Object = alias(cached_result);
let result_flags = result_object.flags;
branch_bits_set(result_flags, OBJECT_FLAG_IS_GLOBAL_OBJECT, failure);
let result_value: Value = alias(box_object(result_object));
result_value
}
}
inline fn move_operand(dst: out Operand, src: in Operand) {
let mut dst_index: u32;
load8(dst_index, [pb, pc, dst]);
let mut src_index: u32;
load8(src_index, [pb, pc, src]);
values[dst_index] = values[src_index];
}
inline fn numeric_value_to_f64(value: Value, else failure: Label) -> f64 {
match value {
Value<i32>(integer) => {
to_f64(integer)
},
Value<f64>(number) => {
number
},
_ => failure,
}
}
inline fn numeric_pair_to_f64(
lhs: Value,
rhs: Value,
else failure: Label
) -> (f64, f64) {
guard let lhs_result = numeric_value_to_f64(lhs) else failure;
guard let rhs_result = numeric_value_to_f64(rhs) else failure;
(lhs_result, rhs_result)
}
inline fn integer_value_to_i64(value: Value, else failure: Label) -> i64 {
match value {
Value<i32>(integer) => {
i64(integer)
},
Value<f64>(number) => {
guard let integer = double_to_int64(number) else failure;
integer
},
_ => failure,
}
}
inline fn load_property_lookup_cache(
cache: PropertyLookupCacheIndex,
else fail: Label
) -> PropertyLookupCache {
let executable = exec_ctx.executable;
assert(executable != 0);
let mut property_cache = executable.property_lookup_caches[load(cache)];
guard property_cache != 0 else fail;
and(property_cache, PROPERTY_LOOKUP_CACHE_DATA_POINTER_MASK);
assert(property_cache != 0);
property_cache
}
# The data of the property lookup cache of a keyed access: `empty` if it has none yet, `generic` if the
# access saw too many keys to cache (see PropertyLookupCache::is_keyed_generic()).
inline fn load_keyed_property_lookup_cache(
cache: PropertyLookupCacheIndex,
generic: Label,
else empty: Label
) -> PropertyLookupCache {
let executable = exec_ctx.executable;
assert(executable != 0);
let mut property_cache = executable.property_lookup_caches[load(cache)];
guard property_cache != 0 else empty;
branch_eq(property_cache, PROPERTY_LOOKUP_CACHE_KEYED_GENERIC, generic);
and(property_cache, PROPERTY_LOOKUP_CACHE_DATA_POINTER_MASK);
property_cache
}
inline fn array_index(value: Value, else failure: Label) -> u32 {
guard let Value<i32>(signed_index) = value else failure;
let index = u32(signed_index);
index
}
inline fn load_global_variable_cache(
cache: GlobalVariableCacheIndex
) -> GlobalVariableCache {
let executable = exec_ctx.executable;
assert(executable != 0);
let global_cache = &executable.global_variable_caches[load(cache)];
assert(global_cache != 0);
global_cache
}
inline fn load_initialized_binding(
binding_values: Sequence<Value>,
binding_index: u32,
else failure: Label
) -> Value {
let value = binding_values[binding_index];
guard value is not Value<Empty> else failure;
value
}
inline fn walk_environment_chain(
initial_environment: Environment,
coordinate: EnvironmentCoordinate
) -> (DeclarativeEnvironment, u32) {
let mut environment = initial_environment;
let coordinate = &coordinate;
let mut hops = u32(coordinate.hops);
let binding_index = u32(coordinate.binding_index);
assert(environment != 0);
if hops != 0 {
do {
environment = environment.outer;
assert(environment != 0);
hops = hops - 1;
} while hops != 0;
}
# NB: Static environment coordinates only traverse declarative environments.
assert(environment != 0);
let declarative_environment: DeclarativeEnvironment = alias(environment);
(declarative_environment, binding_index)
}
inline fn load_cached_environment_coordinate(
cache: EnvironmentCoordinateCacheIndex,
else failure: Label
) -> (u32, u32) {
let coordinate = &exec_ctx.executable.environment_coordinate_caches[load(cache)];
let hops = coordinate.hops;
let binding_index = coordinate.binding_index;
guard hops != ENVIRONMENT_COORDINATE_INVALID else failure;
(hops, binding_index)
}
inline fn walk_cached_environment_chain(
initial_environment: Environment,
initial_hops: u32,
else failure: Label
) -> DeclarativeEnvironment {
let mut environment = initial_environment;
let mut hops = initial_hops;
assert(environment != 0);
if hops != 0 {
do {
guard environment.declarative != 0 else failure;
guard environment.permanently_screwed_by_eval == 0 else failure;
environment = environment.outer;
guard environment != 0 else failure;
hops = hops - 1;
} while hops != 0;
}
assert(environment != 0);
guard environment.declarative != 0 else failure;
guard environment.permanently_screwed_by_eval == 0 else failure;
let declarative_environment: DeclarativeEnvironment = alias(environment);
declarative_environment
}
inline fn initialize_binding(
source_operand: in Operand,
cache: EnvironmentCoordinate,
initial_environment: Environment
) {
let [environment, binding_index] = walk_environment_chain(initial_environment, cache);
environment.binding_values[binding_index] = load(source_operand);
dispatch_next;
}
inline fn set_binding(
source_operand: in Operand,
cache: EnvironmentCoordinate,
initial_environment: Environment,
slow: SlowPath
) {
let failure = || @cold {
call_slow_path(slow);
};
let [environment, binding_index] = walk_environment_chain(initial_environment, cache);
let binding_values = environment.binding_values;
guard binding_values[binding_index] is not Value<Empty> else failure;
guard i32(load_binding_flag(environment, binding_index)) has BINDING_FLAG_MUTABLE else failure;
binding_values[binding_index] = load(source_operand);
dispatch_next;
}
inline fn load_binding_flag(
environment: DeclarativeEnvironment,
binding_index: u32
) -> u8 {
let binding_shape = environment.shape;
if binding_shape == 0 {
environment.rare_data.binding_flags[binding_index]
} else {
let shape_size: u64 = alias(binding_shape.binding_flags_size);
if shape_size <= alias(binding_index) {
let local_index: u64 = alias(binding_index) - shape_size;
environment.rare_data.binding_flags[local_index]
} else {
binding_shape.binding_flags[binding_index]
}
}
}
inline fn caged_primitive_storage_address(
cage_base: u64,
cached_offset: u64,
index: u32,
scale: u8
) -> u64 {
cage_base + ((cached_offset + alias(index) * alias(scale)) & PRIMITIVE_STORAGE_CAGE_OFFSET_MASK)
}
inline fn heap_region_offset(pointer: u64) -> u64 {
pointer & HEAP_REGION_OFFSET_MASK
}
inline fn load_caged_u8(cage_base: u64, cached_offset: u64, index: u32) -> u8 {
let values: Sequence<u8> = alias(
caged_primitive_storage_address(cage_base, cached_offset, index, 1)
);
values[0]
}
inline fn load_caged_u16(cage_base: u64, cached_offset: u64, index: u32) -> u16 {
let values: Sequence<u16> = alias(
caged_primitive_storage_address(cage_base, cached_offset, index, 2)
);
values[0]
}
inline fn load_caged_u32(cage_base: u64, cached_offset: u64, index: u32) -> u32 {
let values: Sequence<u32> = alias(
caged_primitive_storage_address(cage_base, cached_offset, index, 4)
);
values[0]
}
inline fn load_caged_i8(cage_base: u64, cached_offset: u64, index: u32) -> i8 {
let values: Sequence<i8> = alias(
caged_primitive_storage_address(cage_base, cached_offset, index, 1)
);
values[0]
}
inline fn load_caged_i16(cage_base: u64, cached_offset: u64, index: u32) -> i16 {
let values: Sequence<i16> = alias(
caged_primitive_storage_address(cage_base, cached_offset, index, 2)
);
values[0]
}
inline fn load_caged_i32(cage_base: u64, cached_offset: u64, index: u32) -> i32 {
let values: Sequence<i32> = alias(
caged_primitive_storage_address(cage_base, cached_offset, index, 4)
);
values[0]
}
inline fn load_caged_f32(cage_base: u64, cached_offset: u64, index: u32) -> f32 {
let values: Sequence<f32> = alias(
caged_primitive_storage_address(cage_base, cached_offset, index, 4)
);
values[0]
}
inline fn current_vm() -> VM {
load_vm()
}
inline fn primitive_storage_cage_base() -> u64 {
let vm = current_vm();
vm.primitive_storage_cage_base
}
inline fn normalize_completion_value(initial_value: Value) -> (Value, Value) {
let mut value = initial_value;
let empty_tag: Value = Value<Empty>;
# FIXME: Use an immutable value-producing if once its result can coalesce
# with an inline function output on AArch64.
if value is Value<Empty> {
value = Value<Undefined>;
}
(value, empty_tag)
}
# Switches to the dispatch table of the executable whose frame the interpreter
# continues in. Only the profiling build switches: the plain build's handlers
# run every frame while the JIT is off, and while it is on, the plain
# handlers' frames keep the table they run with until the next profiling
# handler switches frames (see the executable's interpreter tier).
inline fn switch_dispatch_table(executable: Executable) @profiling {
let dispatch_table_index: u32 = alias(executable.dispatch_table_index);
let vm = current_vm();
let dispatch_table = vm.dispatch_tables[dispatch_table_index & DISPATCH_TABLE_INDEX_MASK];
dispatch = dispatch_table;
}
inline fn return_to_caller(
return_value: Value,
else top_level: Label
) {
let caller_frame = exec_ctx.caller_frame;
guard caller_frame != 0 else top_level;
let mut result = return_value;
# NB: The frame of a derived constructor returns its this value only for undefined.
if exec_ctx.caller_is_construct {
if result is not Value<Object> {
if exec_ctx.caller_is_derived_construct {
if result is Value<Undefined> {
result = exec_ctx.this_value;
}
} else {
result = exec_ctx.this_value;
}
}
}
let return_pc = exec_ctx.caller_return_pc;
let destination_index = exec_ctx.caller_dst_raw;
let returns_to_native_caller = exec_ctx.returns_to_native_caller;
caller_frame.program_counter = return_pc;
caller_frame.slots[destination_index] = result;
let vm = current_vm();
vm.running_execution_context = caller_frame;
vm.interpreter_stack_top = alias(exec_ctx);
inc32_mem([vm, VM_EXECUTION_GENERATION]);
# A caller waiting in native code (JIT code) continues there.
if returns_to_native_caller {
exit;
}
exec_ctx = caller_frame;
let executable = exec_ctx.executable;
assert(executable != 0);
pb = executable.bytecode_data;
switch_dispatch_table(executable);
assert(pb != 0);
values = exec_ctx.slots;
pc = return_pc;
goto_handler(pc);
}
inline fn return_value(initial_value: Value) {
let [value, empty_tag] = normalize_completion_value(initial_value);
return_to_caller(value) else {
values[3] = value;
values[1] = empty_tag;
exit;
};
}
inline fn update_operand(
operand: inout Operand,
integer_operation: CheckedBinaryOperation<i32>,
float_operation: BinaryOperation<f64>,
slow_path: SlowPath,
feedback: ArithFeedbackIndex
) {
let value = load(operand);
guard let mut Value<i32>(integer) = value else slow;
integer_operation(integer, 1) else overflow;
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32);
store(operand, box_i32(integer));
dispatch_next;
let overflow = || @cold {
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32_OVERFLOW);
let overflowed_integer = unbox_i32(load(operand));
let mut result = to_f64(overflowed_integer);
let one = unbox_f64(DOUBLE_ONE);
float_operation(result, one);
store(operand, box_f64(result));
dispatch_next;
};
let slow = || @cold {
record_arith_operand_feedback(feedback, value);
call_slow_path(slow_path);
};
}
inline fn post_update_operand(
dst: out Operand,
operand: inout Operand,
integer_operation: CheckedBinaryOperation<i32>,
float_operation: BinaryOperation<f64>,
slow_path: SlowPath,
feedback: ArithFeedbackIndex
) {
let old = load(operand);
guard let mut Value<i32>(integer) = old else slow;
store(dst, old);
integer_operation(integer, 1) else overflow;
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32);
store(operand, box_i32(integer));
dispatch_next;
let overflow = || @cold {
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32_OVERFLOW);
let overflowed_integer = unbox_i32(load(operand));
let mut result = to_f64(overflowed_integer);
let one = unbox_f64(DOUBLE_ONE);
float_operation(result, one);
store(operand, box_f64(result));
dispatch_next;
};
let slow = || @cold {
record_arith_operand_feedback(feedback, old);
call_slow_path(slow_path);
};
}
inline fn numeric_value_to_i32(value: Value, else failure: Label) -> i32 {
match value {
Value<i32>(integer) => {
integer
},
Value<bool>(boolean) => {
i32(boolean)
},
Value<f64>(number) => @cold {
guard let result = js_to_int32(number) else failure;
result
},
_ => failure,
}
}
inline fn bitwise_binary(
dst: out Operand,
lhs: Value,
rhs: Value,
operation: BinaryOperation<i32>,
slow_path: SlowPath,
feedback: ArithFeedbackIndex
) {
let slow = || @cold {
call_binary_slow_path(slow_path, dst, lhs, rhs);
};
let non_int32 = || @cold {
record_arith_operands_feedback(feedback, lhs, rhs);
guard let mut lhs_integer = numeric_value_to_i32(lhs) else slow;
guard let rhs_integer = numeric_value_to_i32(rhs) else slow;
operation(lhs_integer, rhs_integer);
store(dst, box_i32(lhs_integer));
dispatch_next;
};
guard let mut Value<i32>(lhs_integer) = lhs else non_int32;
guard let Value<i32>(rhs_integer) = rhs else non_int32;
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32);
operation(lhs_integer, rhs_integer);
store(dst, box_i32(lhs_integer));
dispatch_next;
}
inline fn signed_shift(
dst: out Operand,
lhs: Value,
rhs: Value,
operation: BinaryOperation<i32>,
slow_path: SlowPath,
feedback: ArithFeedbackIndex
) {
let slow = || @cold {
record_arith_operands_feedback(feedback, lhs, rhs);
call_binary_slow_path(slow_path, dst, lhs, rhs);
};
guard let mut Value<i32>(integer) = lhs else slow;
guard let mut Value<i32>(count) = rhs else slow;
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32);
count = count & 31;
operation(integer, count);
store(dst, box_i32(integer));
dispatch_next;
}
inline fn store_relational_result(
dst: out Operand,
lhs: Value,
rhs: Value,
integer_condition: IntegerCondition,
float_condition: FloatCondition,
slow_path: SlowPath,
feedback: ArithFeedbackIndex
) {
let store_true = || {
store(dst, Value<True>);
dispatch_next;
};
let store_false = || {
store(dst, Value<False>);
dispatch_next;
};
let slow = || @cold {
call_binary_slow_path(slow_path, dst, lhs, rhs);
};
compare_numeric_values(
lhs,
rhs,
integer_condition,
float_condition,
store_true,
store_false,
feedback
) else slow;
}
inline fn equality_same_tag(
lhs: Value,
rhs: Value,
lhs_tag: inout ValueTag,
equal: Label,
not_equal: Label,
compare_f64: Label,
feedback: ArithFeedbackIndex,
else slow: Label
) {
match lhs_tag {
INT32_TAG | BOOLEAN_TAG => other_compare,
OBJECT_TAG | SYMBOL_TAG => other_compare,
STRING_TAG => string_compare,
BIGINT_TAG => bigint_compare,
_ => check_nullish,
}
let check_nullish = || {
lhs_tag = lhs_tag & 0xfffe;
branch_eq(lhs_tag, UNDEFINED_TAG, other_compare);
goto compare_f64;
};
let string_compare = || {
record_arith_feedback(feedback, ARITH_FEEDBACK_STRING);
guard lhs is not rhs else equal;
goto different_strings;
};
let different_strings = || @cold {
# Two different interned strings never have the same contents.
guard let Value<PrimitiveString>(lhs_string) = lhs else slow;
guard let Value<PrimitiveString>(rhs_string) = rhs else slow;
guard lhs_string.deferred_kind_and_flags has PRIMITIVE_STRING_INTERNED_FLAG else slow;
guard rhs_string.deferred_kind_and_flags has PRIMITIVE_STRING_INTERNED_FLAG else slow;
goto not_equal;
};
let bigint_compare = || {
record_arith_feedback(feedback, ARITH_FEEDBACK_BIGINT);
goto slow;
};
let other_compare = || {
record_identity_equality_feedback(feedback, lhs_tag);
guard lhs is not rhs else equal;
goto not_equal;
};
}
inline fn compare_f64_equality(
lhs: f64,
rhs: f64,
equal: Label,
not_equal: Label
) {
branch_fp_unordered(lhs, rhs, not_equal);
branch_fp_equal(lhs, rhs, equal);
goto not_equal;
}
inline fn strict_equality(
lhs: Value,
rhs: Value,
equal: Label,
not_equal: Label,
feedback: ArithFeedbackIndex,
else slow: Label
) {
let mut rhs_tag = extract_tag(rhs);
branch_eq(rhs_tag, INT32_TAG, rhs_i32);
let mut lhs_tag = extract_tag(lhs);
guard lhs_tag == rhs_tag else different_tags;
equality_same_tag(lhs, rhs, lhs_tag, equal, not_equal, compare_f64, feedback) else slow;
let compare_f64 = || {
record_arith_feedback(feedback, ARITH_FEEDBACK_DOUBLE);
let lhs_number = unbox_f64(lhs);
let rhs_number = unbox_f64(rhs);
compare_f64_equality(lhs_number, rhs_number, equal, not_equal);
};
let other_not_equal = || {
record_arith_feedback(feedback, ARITH_FEEDBACK_OTHER);
goto not_equal;
};
let different_tags = || {
branch_eq(lhs_tag, INT32_TAG, lhs_i32);
check_tag_is_double(lhs_tag) else other_not_equal;
check_tag_is_double(rhs_tag) else other_not_equal;
goto compare_f64;
};
let int32_and_other_not_equal = || {
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32_AND_OTHER);
goto not_equal;
};
let lhs_i32 = || {
check_tag_is_double(rhs_tag) else int32_and_other_not_equal;
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32_AND_DOUBLE);
let integer = unbox_i32(lhs);
let lhs_number = to_f64(integer);
let rhs_number = unbox_f64(rhs);
branch_fp_equal(lhs_number, rhs_number, equal);
goto not_equal;
};
let rhs_i32 = || {
let rhs_integer = unbox_i32(rhs);
match lhs {
Value<i32>(lhs_integer) => {
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32);
branch_eq(lhs_integer, rhs_integer, equal);
goto not_equal;
},
Value<f64>(lhs_double) => @cold {
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32_AND_DOUBLE);
compare_f64_equality(lhs_double, to_f64(rhs_integer), equal, not_equal);
},
_ => int32_and_other_not_equal,
}
};
}
inline fn loose_equality(
lhs: Value,
rhs: Value,
equal: Label,
not_equal: Label,
feedback: ArithFeedbackIndex,
else slow: Label
) {
let mut rhs_tag = extract_tag(rhs);
branch_eq(rhs_tag, INT32_TAG, rhs_i32);
let mut lhs_tag = extract_tag(lhs);
guard lhs_tag == rhs_tag else different_tags;
equality_same_tag(lhs, rhs, lhs_tag, equal, not_equal, compare_f64, feedback) else slow;
let compare_f64 = || {
record_arith_feedback(feedback, ARITH_FEEDBACK_DOUBLE);
let lhs_number = unbox_f64(lhs);
let rhs_number = unbox_f64(rhs);
compare_f64_equality(lhs_number, rhs_number, equal, not_equal);
};
let other_slow = || {
record_arith_feedback(feedback, ARITH_FEEDBACK_OTHER);
goto slow;
};
let different_tags = || {
lhs_tag = lhs_tag & 0xfffe;
guard lhs_tag == UNDEFINED_TAG else try_f64;
record_arith_feedback(feedback, ARITH_FEEDBACK_OTHER);
rhs_tag = rhs_tag & 0xfffe;
guard rhs_tag != UNDEFINED_TAG else equal;
goto slow;
};
let try_f64 = || {
guard lhs is Value<f64> else other_slow;
guard rhs is Value<f64> else other_slow;
goto compare_f64;
};
let int32_and_other_slow = || {
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32_AND_OTHER);
goto slow;
};
let rhs_i32 = || {
let rhs_integer = unbox_i32(rhs);
match lhs {
Value<i32>(lhs_integer) => {
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32);
branch_eq(lhs_integer, rhs_integer, equal);
goto not_equal;
},
Value<f64>(lhs_double) => @cold {
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32_AND_DOUBLE);
compare_f64_equality(lhs_double, to_f64(rhs_integer), equal, not_equal);
},
_ => int32_and_other_slow,
}
};
}
inline fn strict_inequality(
lhs: Value,
rhs: Value,
not_equal: Label,
equal: Label,
feedback: ArithFeedbackIndex,
else slow: Label
) {
strict_equality(lhs, rhs, equal, not_equal, feedback) else slow;
}
inline fn loose_inequality(
lhs: Value,
rhs: Value,
not_equal: Label,
equal: Label,
feedback: ArithFeedbackIndex,
else slow: Label
) {
loose_equality(lhs, rhs, equal, not_equal, feedback) else slow;
}
inline fn store_equality_result(
dst: out Operand,
lhs: Value,
rhs: Value,
operation: EqualityOperation,
slow: SlowPath,
feedback: ArithFeedbackIndex
) {
let failure = || @cold {
call_binary_slow_path(slow, dst, lhs, rhs);
};
let store_true = || {
store(dst, Value<True>);
dispatch_next;
};
let store_false = || {
store(dst, Value<False>);
dispatch_next;
};
operation(lhs, rhs, store_true, store_false, feedback) else failure;
}
inline fn jump_equality(
lhs: Value,
rhs: Value,
true_target: BytecodeOffset,
false_target: BytecodeOffset,
operation: EqualityOperation,
slow: SlowPath,
feedback: ArithFeedbackIndex
) {
let failure = || @cold {
call_jump_slow_path(slow, lhs, rhs, true_target, false_target);
};
let take_true = || {
jump(true_target);
};
let take_false = || {
jump(false_target);
};
operation(lhs, rhs, take_true, take_false, feedback) else failure;
}
inline fn compare_numeric_values(
lhs: Value,
rhs: Value,
integer_condition: IntegerCondition,
float_condition: FloatCondition,
true_result: Label,
false_result: Label,
feedback: ArithFeedbackIndex,
else slow: Label
) {
let compare_double = |lhs: f64, rhs: f64| @cold {
branch_fp_unordered(lhs, rhs, false_result);
float_condition(lhs, rhs, true_result);
goto false_result;
};
match lhs {
Value<i32>(lhs_integer) => {
match rhs {
Value<i32>(rhs_integer) => {
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32);
integer_condition(lhs_integer, rhs_integer, true_result);
goto false_result;
},
Value<f64>(rhs_double) => @cold {
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32_AND_DOUBLE);
goto compare_double(to_f64(lhs_integer), rhs_double);
},
_ => @cold {
record_arith_operands_feedback(feedback, lhs, rhs);
goto slow;
},
}
},
Value<f64>(lhs_double) => @cold {
match rhs {
Value<i32>(rhs_integer) => {
record_arith_feedback(feedback, ARITH_FEEDBACK_INT32_AND_DOUBLE);
goto compare_double(lhs_double, to_f64(rhs_integer));
},
Value<f64>(rhs_double) => {
record_arith_feedback(feedback, ARITH_FEEDBACK_DOUBLE);
goto compare_double(lhs_double, rhs_double);
},
_ => @cold {
record_arith_operands_feedback(feedback, lhs, rhs);
goto slow;
},
}
},
_ => @cold {
record_arith_operands_feedback(feedback, lhs, rhs);
goto slow;
},
}
}
inline fn jump_relational(
lhs: Value,
rhs: Value,
true_target: BytecodeOffset,
false_target: BytecodeOffset,
integer_condition: IntegerCondition,
float_condition: FloatCondition,
slow: SlowPath,
feedback: ArithFeedbackIndex
) {
let failure = || @cold {
call_jump_slow_path(slow, lhs, rhs, true_target, false_target);
};
let take_true = || {
jump(true_target);
};
let take_false = || {
jump(false_target);
};
compare_numeric_values(
lhs,
rhs,
integer_condition,
float_condition,
take_true,
take_false,
feedback
) else failure;
}
inline fn runtime_truthiness(value: Value) -> u64 {
let result: u64 = call_helper(asm_helper_to_boolean, value);
assert(result < 2);
result
}
inline fn box_boolean(value: u64) -> Value {
let bits = value | BOOLEAN_FALSE;
reinterpret_u64_as_value(bits)
}
inline fn load_primitive_string_utf16_code_unit(
string: PrimitiveString,
index: u32,
out_of_bounds: Label,
else failure: Label
) -> u32 {
let deferred_kind_and_flags: u32 = alias(string.deferred_kind_and_flags);
let deferred_kind = deferred_kind_and_flags & PRIMITIVE_STRING_DEFERRED_KIND_MASK;
if deferred_kind == PRIMITIVE_STRING_DEFERRED_KIND_INLINE {
let length = string.length_in_utf16_code_units;
guard length > index else out_of_bounds;
let code_unit: u32 = alias(string.inline_string_storage[index]);
code_unit
} else {
guard deferred_kind == PRIMITIVE_STRING_DEFERRED_KIND_NONE else failure;
let utf16_data = string.utf16_data;
guard utf16_data != 0 else failure;
assert(utf16_data != 0);
let short_string_info = string.utf16_short_string_byte_count_and_flag;
if short_string_info lacks UTF16_SHORT_STRING_FLAG {
let length = utf16_data.length_in_code_units;
guard length > index else out_of_bounds;
if utf16_data.flags has UTF16_STRING_DATA_HAS_UTF16_STORAGE {
let utf16_storage: Sequence<u16> = alias(utf16_data.string_storage);
let code_unit: u32 = alias(utf16_storage[index]);
code_unit
} else {
let code_unit: u32 = alias(utf16_data.string_storage[index]);
code_unit
}
} else {
let wide_short_string_info: u32 = alias(short_string_info);
let byte_count = wide_short_string_info >> UTF16_SHORT_STRING_BYTE_COUNT_SHIFT_COUNT;
guard index < byte_count else out_of_bounds;
let code_unit: u32 = alias(string.utf16_short_string_storage[index]);
code_unit
}
}
}
# All feedback recording goes through this helper, so the feedback base can
# later move into the frame without touching every handler.
inline fn feedback_base() -> ExecutableFeedback {
let executable = exec_ctx.executable;
executable.feedback
}
# The address of the element `index` of `size` bytes of the feedback array at
# `array` (an offset into the primitive storage cage), masked into the cage.
# Shifting the bits outside PRIMITIVE_STORAGE_CAGE_OFFSET_MASK out masks them
# without a 64-bit immediate, which takes another register on x86-64.
inline fn feedback_address(cage_base: u64, array: u64, index: u32, size: u8) -> u64 {
let unmasked: u64 = array + alias(index) * alias(size);
cage_base + ((unmasked << PRIMITIVE_STORAGE_CAGE_OFFSET_SHIFT) >> PRIMITIVE_STORAGE_CAGE_OFFSET_SHIFT)
}
inline fn record_arith_feedback(slot: ArithFeedbackIndex, bits: i32) @profiling {
let feedback = feedback_base();
let arith = feedback_address(primitive_storage_cage_base(), feedback.arith, load(slot), 1);
or8_mem([arith, 0], bits);
}
inline fn record_identity_equality_feedback(slot: ArithFeedbackIndex, tag: ValueTag) @profiling {
let mut bits: i32 = ARITH_FEEDBACK_OTHER;
if tag == OBJECT_TAG {
bits = ARITH_FEEDBACK_OBJECT_PAIR;
}
record_arith_feedback(slot, bits);
}
inline fn arith_feedback_bits(value: Value) -> i32 {
let tag = extract_tag(value);
let mut bits: i32 = ARITH_FEEDBACK_OTHER;
if tag == INT32_TAG {
bits = ARITH_FEEDBACK_INT32;
} else if value is Value<f64> {
bits = ARITH_FEEDBACK_DOUBLE;
} else if tag == STRING_TAG {
bits = ARITH_FEEDBACK_STRING;
} else if tag == BIGINT_TAG {
bits = ARITH_FEEDBACK_BIGINT;
} else if tag == BOOLEAN_TAG {
bits = ARITH_FEEDBACK_BOOLEAN;
}
bits
}
inline fn record_arith_operand_feedback(slot: ArithFeedbackIndex, value: Value) @profiling {
record_arith_feedback(slot, arith_feedback_bits(value));
}
inline fn record_arith_operands_feedback(slot: ArithFeedbackIndex, lhs: Value, rhs: Value) @profiling {
let lhs_bits = arith_feedback_bits(lhs);
let rhs_bits = arith_feedback_bits(rhs);
let bits = lhs_bits | rhs_bits;
record_arith_feedback(slot, bits);
}
# Value feedback stores the bits of the produced value in the instruction's
# bucket. The runtime classifies buckets into ValueFeedback bits later.
inline fn record_value_feedback(slot: ValueFeedbackIndex, value: Value) @profiling {
let feedback = feedback_base();
let buckets: Sequence<Value> = alias(
feedback_address(primitive_storage_cage_base(), feedback.value_buckets, load(slot), 8)
);
buckets[0] = value;
}
# The value buckets of the sites of property lookup caches lie before the
# others, in reverse order: the bucket of cache 0 is the last of them.
inline fn record_cache_value_feedback(cache: ProfiledPropertyLookupCacheIndex, value: Value) @profiling {
let feedback = feedback_base();
let index: u64 = alias(load(cache));
let unmasked: u64 = feedback.value_buckets - (index << 3) - 8;
let cage_base = primitive_storage_cage_base();
let buckets: Sequence<Value> = alias(
cage_base + ((unmasked << PRIMITIVE_STORAGE_CAGE_OFFSET_SHIFT) >> PRIMITIVE_STORAGE_CAGE_OFFSET_SHIFT)
);
buckets[0] = value;
}
# A call site keeps the tag of the value a call returned in its call feedback,
# which holds its value bucket.
inline fn record_call_value_feedback(slot: CallFeedbackIndex, value: Value) @profiling {
let feedback = feedback_base();
let call_feedback: CallFeedback = alias(
feedback_address(primitive_storage_cage_base(), feedback.call, load(slot), CALL_FEEDBACK_SIZE)
);
call_feedback.value_bucket = truncate_u16(i32(extract_tag(value)));
}
# Call feedback only does work when the callee differs from the first one
# recorded at the site.
# Records `function` as a target of the call site, and gives the site's call
# feedback flags in `site_flags`.
inline fn record_call_target(slot: CallFeedbackIndex, function: Object, site_flags: inout i32) @profiling {
let feedback = feedback_base();
let call_feedback: CallFeedback = alias(
feedback_address(primitive_storage_cage_base(), feedback.call, load(slot), CALL_FEEDBACK_SIZE)
);
let function_pointer: u64 = alias(function);
let mut flags: i32 = alias(call_feedback.flags);
if call_feedback.target != function_pointer {
if call_feedback.target == 0 {
call_feedback.target = function_pointer;
} else {
flags = flags | CALL_FEEDBACK_POLYMORPHIC;
# A closure of the first callee's function has its shared data.
# Without native callees, the first callee is an ECMAScript
# function too.
if function.flags lacks OBJECT_FLAG_IS_ECMASCRIPT_FUNCTION_OBJECT {
flags = flags | CALL_FEEDBACK_OTHER_FUNCTIONS;
} else if flags lacks CALL_FEEDBACK_SAW_NATIVE {
# The first callee is a weak reference in the feedback, which is
# decoded into the heap region like a cell value.
let first_bits = call_feedback.target;
let mut first_value: Value;
mov(first_value, first_bits);
let first_object: Object = unbox_object(first_value);
let first: ECMAScriptFunctionObject = alias(first_object);
let closure: ECMAScriptFunctionObject = alias(function);
if first.shared_data != closure.shared_data {
flags = flags | CALL_FEEDBACK_OTHER_FUNCTIONS;
}
}
}
if function.flags lacks OBJECT_FLAG_IS_ECMASCRIPT_FUNCTION_OBJECT {
flags = flags | CALL_FEEDBACK_SAW_NATIVE;
}
call_feedback.flags = truncate_u8(flags);
}
site_flags = flags;
}
inline fn record_keyed_feedback(slot: KeyedFeedbackIndex, bits: u32) @profiling {
record_keyed_feedback_with_cage_base(primitive_storage_cage_base(), slot, bits);
}
# For handlers that have the primitive storage cage base at hand already.
inline fn record_keyed_feedback_with_cage_base(cage_base: u64, slot: KeyedFeedbackIndex, bits: u32) @profiling {
let feedback = feedback_base();
let keyed_feedback = feedback_address(cage_base, feedback.keyed, load(slot), KEYED_FEEDBACK_SIZE);
or32_mem([keyed_feedback, KEYED_FEEDBACK_BITS], bits);
}
inline fn record_typed_array_keyed_feedback(cage_base: u64, slot: KeyedFeedbackIndex, kind: u8) @profiling {
let mut bits: u32 = 1;
let shift: u32 = alias(kind);
let mut count = shift + KEYED_FEEDBACK_TYPED_ARRAY_SHIFT;
shl(bits, count);
bits = bits | KEYED_FEEDBACK_INT32_INDEX;
record_keyed_feedback_with_cage_base(cage_base, slot, bits);
}
# Runs the frame that just became the running execution context in its
# executable's JIT code, if it has some. Only the profiling build checks:
# JIT code exists only while the JIT is enabled, which selects that build.
inline fn enter_jit_code_if_any(executable: Executable) @profiling {
if executable.jit_compile_state == JIT_COMPILE_STATE_INSTALLED {
let control: i32 = call_helper(asm_helper_enter_jit_code, current_vm());
guard control >= 0 else @cold {
exit;
};
if control > 0 {
# The code returned: its frame is still the running execution context, and the return value is in the
# frame's return value register.
let returned_vm = current_vm();
exec_ctx = returned_vm.running_execution_context;
values = exec_ctx.slots;
return_value(values[3]);
}
continue_running_execution_context();
}
}
# Continues interpreting the running execution context at its program
# counter, after JIT code ran.
inline fn continue_running_execution_context() @profiling {
let resumed_vm = current_vm();
exec_ctx = resumed_vm.running_execution_context;
assert(exec_ctx != 0);
values = exec_ctx.slots;
let resumed_executable = exec_ctx.executable;
assert(resumed_executable != 0);
pb = resumed_executable.bytecode_data;
switch_dispatch_table(resumed_executable);
pc = exec_ctx.program_counter;
goto_handler(pc);
}
# Continues the running frame in its executable's JIT code after the Catch
# that just ran, if the code has an entry there. Like at loop back edges, an
# exit from that code resumes after the Catch, so the frame always makes
# progress.
inline fn enter_jit_code_after_catch() @profiling {
let executable = exec_ctx.executable;
if executable.jit_compile_state == JIT_COMPILE_STATE_INSTALLED {
let control: i32 = call_helper_with_two_arguments(asm_helper_enter_jit_code_after_catch, current_vm(), pc);
if control != 0 {
guard control > 0 else @cold {
exit;
};
continue_running_execution_context();
}
}
}
# Starts running the frame that just became the running execution context,
# at its entry: in its executable's JIT code if it has some, and in the
# interpreter otherwise.
inline fn enter_new_frame(executable: Executable) {
enter_jit_code_if_any(executable);
pc = 0;
goto_handler(pc);
}
# Counts the executable's tier-up budget down by cost and runs the tier-up
# policy once it is used up.
inline fn consume_tier_up_budget(cost: i32, target_pc: u32, is_loop: u32) @profiling {
let executable = exec_ctx.executable;
sub32_mem([executable, EXECUTABLE_TIER_UP_BUDGET], cost);
if executable.tier_up_budget <= 0 {
let shifted_pc = target_pc << 1;
let encoded_pc = shifted_pc | is_loop;
# NB: When the policy moves the executable to other handlers at a
# function entry, the running frame keeps its handlers until the
# interpreter enters another frame. At a loop back edge, the frame
# switches to them, or continues in JIT code (on-stack
# replacement).
let control: i32 = call_helper_with_two_arguments(asm_helper_tier_up_check, current_vm(), encoded_pc);
if control != 0 {
guard control > 0 else @cold {
exit;
};
continue_running_execution_context();
}
}
}
# Loop back edges consume tier-up budget each time they run.
inline fn count_loop_iteration() {
consume_tier_up_budget(TIER_UP_LOOP_ITERATION_COST, pc, 1);
}
# Handlers whose complete semantics live in their slow path.
# Bytecode handlers are kept in native layout order.
inline fn enter_frame() {
consume_tier_up_budget(TIER_UP_FUNCTION_ENTRY_COST, pc, 0);
let executable = exec_ctx.executable;
assert(executable != 0);
# NB: Only a collection makes the count nonzero, so the store is rare.
if executable.idle_collection_count != 0 {
executable.idle_collection_count = 0;
}
let registers_and_locals_count = executable.registers_and_locals_count;
let empty_tag: Value = Value<Empty>;
let mut slot_index: u64 = RESERVED_REGISTER_COUNT;
while slot_index + 1 < alias(registers_and_locals_count) {
let next_slot_index = slot_index + 1;
values[slot_index] = empty_tag;
values[next_slot_index] = empty_tag;
slot_index = slot_index + 2;
}
if slot_index < alias(registers_and_locals_count) {
values[slot_index] = empty_tag;
}
let constant_count: u32 = executable.registers_and_locals_and_constants_count - registers_and_locals_count;
let constant_data = executable.constants_data;
let mut write_index: u64 = alias(registers_and_locals_count);
let mut constant_index: u64 = 0;
while constant_index < alias(constant_count) {
assert(constant_data != 0);
values[write_index] = constant_data[constant_index];
constant_index = constant_index + 1;
write_index = write_index + 1;
}
exec_ctx.frame_initialized = true;
}
handler Enter() {
enter_frame();
dispatch_next;
}
# NB: Callers pass the this value as it is, and the runtime binds it for a sloppy function that uses it: to an object,
# or the global this value for null and undefined.
inline fn coerce_this() {
let _: i32 = call_helper(asm_helper_coerce_this, current_vm());
}
# NB: Sloppy functions that use their this value start with this. Null and undefined become the global this value of
# the current realm, which is the function's, as a call of an ECMAScript function of another realm goes through
# the runtime.
handler EnterCoercingThis() {
let this_value = exec_ctx.this_value_register;
if this_value is not Value<Object> {
if this_value is Value<Nullish> {
let realm_vm = current_vm();
let global_this: Value = alias(box_object(realm_vm.current_realm.global_environment.global_this_value));
exec_ctx.this_value_register = global_this;
exec_ctx.this_value = global_this;
} else {
coerce_this();
}
}
enter_frame();
dispatch_next;
}
# NB: Code that makes private or variable environments starts with this, and its frames keep their running private
# and variable environments from here on. Others read them from their function.
handler EnterWithOwnEnvironments() {
if exec_ctx.this_value_register is not Value<Object> {
let this_function = exec_ctx.function;
if this_function != 0 {
let this_ecmascript_function: ECMAScriptFunctionObject = alias(this_function);
let metadata = this_ecmascript_function.shared_data.asm_call_metadata;
if metadata has SHARED_FUNCTION_INSTANCE_DATA_ASM_CALL_METADATA_USES_THIS {
if metadata lacks SHARED_FUNCTION_INSTANCE_DATA_ASM_CALL_METADATA_STRICT {
coerce_this();
}
}
}
}
let function = exec_ctx.function;
if function != 0 {
let ecmascript_function: ECMAScriptFunctionObject = alias(function);
exec_ctx.private_environment = null;
if function.class_bits has ECMASCRIPT_FUNCTION_FLAG_HAS_RARE_DATA {
exec_ctx.private_environment = ecmascript_function.private_environment;
}
# NB: The variable environment of a frame starts out as its lexical environment.
exec_ctx.variable_environment = exec_ctx.lexical_environment;
}
enter_frame();
dispatch_next;
}
handler Mov(
dst: out Operand,
src: in Operand
) {
store(dst, load(src));
dispatch_next;
}
specialize Mov(src: Undefined);
# NB: The only way to reach the frame slots that no other instruction can name.
handler MovWide(
dst_slot: u32,
src_slot: u32
) {
values[load(dst_slot)] = values[load(src_slot)];
dispatch_next;
}
# The name table indices of the next instruction that are too large for its fields. Only what reads that instruction
# looks at them.
handler WideNameIndices(
first: u32,
second: u32
) {
dispatch_next;
}
specialize Add(lhs: Int32);
specialize Add(rhs: Int32);
specialize Sub(rhs: Int32);
specialize Mul(rhs: Int32);
specialize Exp(rhs: Int32);
specialize Div(rhs: Int32);
specialize BitwiseXor(rhs: Int32);
specialize BitwiseAnd(rhs: Int32);
specialize BitwiseOr(rhs: Int32);
specialize LeftShift(rhs: Int32);
specialize RightShift(rhs: Int32);
specialize UnsignedRightShift(rhs: Int32);
specialize Mod(rhs: Int32);
specialize LessThan(rhs: Int32);
specialize LessThanEquals(rhs: Int32);
specialize GreaterThan(rhs: Int32);
specialize GreaterThanEquals(rhs: Int32);
specialize JumpLessThan(rhs: Int32);
specialize JumpLessThanEquals(rhs: Int32);
specialize JumpGreaterThan(rhs: Int32);
specialize JumpGreaterThanEquals(rhs: Int32);
specialize StrictlyEquals(rhs: Int32);
specialize StrictlyInequals(rhs: Int32);
specialize LooselyEquals(rhs: Int32);
specialize LooselyInequals(rhs: Int32);
specialize JumpStrictlyEquals(rhs: Int32);
specialize JumpStrictlyInequals(rhs: Int32);
specialize JumpLooselyEquals(rhs: Int32);
specialize JumpLooselyInequals(rhs: Int32);
specialize JumpLessThanLoop(rhs: Int32);
specialize JumpLessThanEqualsLoop(rhs: Int32);
specialize JumpGreaterThanLoop(rhs: Int32);
specialize JumpGreaterThanEqualsLoop(rhs: Int32);
specialize JumpStrictlyEqualsLoop(rhs: Int32);
specialize JumpStrictlyInequalsLoop(rhs: Int32);
specialize JumpLooselyEqualsLoop(rhs: Int32);
specialize JumpLooselyInequalsLoop(rhs: Int32);
handler Add(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) {
let lhs_value = load(lhs);
let rhs_value = load(rhs);
let slow = || @cold {
record_arith_operands_feedback(arith_feedback, lhs_value, rhs_value);
call_binary_slow_path(add_values, dst, lhs_value, rhs_value);
};
let add_double = |lhs: f64, rhs: f64| @cold {
store(dst, box_number(lhs + rhs));
dispatch_next;
};
match lhs_value {
Value<i32>(lhs_integer) => {
match rhs_value {
Value<i32>(rhs_integer) => {
guard let sum = checked_add(lhs_integer, rhs_integer) else @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_OVERFLOW);
store(dst, box_f64(to_f64(lhs_integer) + to_f64(rhs_integer)));
dispatch_next;
};
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32);
store(dst, box_i32(sum));
dispatch_next;
},
Value<f64>(rhs_double) => @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_AND_DOUBLE);
goto add_double(to_f64(lhs_integer), rhs_double);
},
_ => slow,
}
},
Value<f64>(lhs_double) => @cold {
match rhs_value {
Value<i32>(rhs_integer) => {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_AND_DOUBLE);
goto add_double(lhs_double, to_f64(rhs_integer));
},
Value<f64>(rhs_double) => {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_DOUBLE);
goto add_double(lhs_double, rhs_double);
},
_ => slow,
}
},
_ => slow,
}
}
handler Sub(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) {
let lhs_value = load(lhs);
let rhs_value = load(rhs);
let slow = || @cold {
record_arith_operands_feedback(arith_feedback, lhs_value, rhs_value);
call_binary_slow_path(sub_values, dst, lhs_value, rhs_value);
};
let subtract_double = |lhs: f64, rhs: f64| @cold {
store(dst, box_number(lhs - rhs));
dispatch_next;
};
match lhs_value {
Value<i32>(lhs_integer) => {
match rhs_value {
Value<i32>(rhs_integer) => {
guard let difference = checked_sub(lhs_integer, rhs_integer) else @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_OVERFLOW);
store(dst, box_f64(to_f64(lhs_integer) - to_f64(rhs_integer)));
dispatch_next;
};
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32);
store(dst, box_i32(difference));
dispatch_next;
},
Value<f64>(rhs_double) => @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_AND_DOUBLE);
goto subtract_double(to_f64(lhs_integer), rhs_double);
},
_ => slow,
}
},
Value<f64>(lhs_double) => @cold {
match rhs_value {
Value<i32>(rhs_integer) => {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_AND_DOUBLE);
goto subtract_double(lhs_double, to_f64(rhs_integer));
},
Value<f64>(rhs_double) => {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_DOUBLE);
goto subtract_double(lhs_double, rhs_double);
},
_ => slow,
}
},
_ => slow,
}
}
handler Mul(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) {
let lhs_value = load(lhs);
let rhs_value = load(rhs);
let slow = || @cold {
record_arith_operands_feedback(arith_feedback, lhs_value, rhs_value);
call_binary_slow_path(mul_values, dst, lhs_value, rhs_value);
};
let multiply_double = |lhs: f64, rhs: f64| @cold {
store(dst, box_number(lhs * rhs));
dispatch_next;
};
match lhs_value {
Value<i32>(lhs_integer) => {
match rhs_value {
Value<i32>(rhs_integer) => {
let negative_zero = || @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_OVERFLOW);
store(dst, Value<NegativeZero>);
dispatch_next;
};
guard let product = checked_mul(lhs_integer, rhs_integer) else @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_OVERFLOW);
store(dst, box_f64(to_f64(lhs_integer) * to_f64(rhs_integer)));
dispatch_next;
};
if product == 0 {
let sign_check = lhs_integer | rhs_integer;
guard sign_check >= 0 else negative_zero;
}
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32);
store(dst, box_i32(product));
dispatch_next;
},
Value<f64>(rhs_double) => @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_AND_DOUBLE);
goto multiply_double(to_f64(lhs_integer), rhs_double);
},
_ => slow,
}
},
Value<f64>(lhs_double) => @cold {
match rhs_value {
Value<i32>(rhs_integer) => {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_AND_DOUBLE);
goto multiply_double(lhs_double, to_f64(rhs_integer));
},
Value<f64>(rhs_double) => {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_DOUBLE);
goto multiply_double(lhs_double, rhs_double);
},
_ => slow,
}
},
_ => slow,
}
}
handler Exp(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) @cold {
let lhs_value = load(lhs);
let rhs_value = load(rhs);
record_arith_operands_feedback(arith_feedback, lhs_value, rhs_value);
call_binary_slow_path(exp_values, dst, lhs_value, rhs_value);
}
handler ConcatString(
dst: inout Operand,
src: Operand
) @cold = call_slow_path(concat_string);
handler CopyObjectExcludingProperties(
dst: out Operand,
from_object: Operand,
excluded_names_are_in_array: bool,
excluded_names_count: u8,
excluded_names: Operand[]
) @cold = call_slow_path(copy_object_excluding_properties);
handler ImportCall(
dst: out Operand,
specifier: Operand,
options: Operand
) @cold = call_slow_path(import_call);
handler GetClassFieldInitializerName(
dst: out Operand
) @cold = call_slow_path(get_class_field_initializer_name);
handler GetClassProtoParent(
dst: out Operand,
super_class: Operand
) @cold = call_slow_path(get_class_proto_parent);
handler NewClass(
dst: out Operand,
super_class: Optional<Operand>,
proto_parent: Optional<Operand>,
class_environment: Operand,
class_blueprint_index: u32,
lhs_name: Optional<IdentifierTableIndex>,
computed_name: Optional<Operand>,
element_keys_are_in_array: bool,
element_keys_count: u8,
element_keys: Optional<Operand>[]
) @cold = call_slow_path(new_class);
handler Jump(
target: BytecodeOffset
) @terminator = jump(target);
inline fn jump_if(
condition: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) {
let value = load(condition);
let take_false = || {
jump(false_target);
};
let take_true = || {
jump(true_target);
};
match value {
Value<bool> => {
branch_bits_set(value, 1, take_true);
goto take_false;
},
Value<i32> => {
branch_nonzero32(value, take_true);
goto take_false;
},
_ => {
let runtime = || {
guard runtime_truthiness(value) == 0 else take_true;
goto take_false;
};
guard let Value<Object>(object) = value else runtime;
guard object.flags lacks OBJECT_FLAG_IS_HTMLDDA else take_false;
goto take_true;
},
}
}
handler JumpIf(
condition: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator = jump_if(condition, true_target, false_target);
inline fn jump_true(
condition: in Operand,
target: BytecodeOffset
) {
let value = load(condition);
let take = || {
jump(target);
};
match value {
Value<bool> => {
branch_bits_set(value, 1, take);
dispatch_next;
},
Value<i32> => {
branch_nonzero32(value, take);
dispatch_next;
},
_ => {
let runtime = || {
guard runtime_truthiness(value) == 0 else take;
dispatch_next;
};
guard let Value<Object>(object) = value else runtime;
guard object.flags has OBJECT_FLAG_IS_HTMLDDA else take;
dispatch_next;
},
}
}
handler JumpTrue(
condition: in Operand,
target: BytecodeOffset
) @terminator @fallthrough = jump_true(condition, target);
inline fn jump_false(
condition: in Operand,
target: BytecodeOffset
) {
let value = load(condition);
let take = || {
jump(target);
};
match value {
Value<bool> => {
branch_bits_clear(value, 1, take);
dispatch_next;
},
Value<i32> => {
branch_zero32(value, take);
dispatch_next;
},
_ => {
let runtime = || {
guard runtime_truthiness(value) != 0 else take;
dispatch_next;
};
guard let Value<Object>(object) = value else runtime;
guard object.flags lacks OBJECT_FLAG_IS_HTMLDDA else take;
dispatch_next;
},
}
}
handler JumpFalse(
condition: in Operand,
target: BytecodeOffset
) @terminator @fallthrough = jump_false(condition, target);
handler JumpNullish(
condition: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator {
if load(condition) is Value<Nullish> {
jump(true_target);
}
jump(false_target);
}
handler JumpUndefined(
condition: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator {
if load(condition) is Value<Undefined> {
jump(true_target);
}
jump(false_target);
}
handler JumpLessThan(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator = jump_relational(
load(lhs),
load(rhs),
true_target,
false_target,
branch_lt_signed,
branch_fp_less,
jump_less_than_values,
arith_feedback
);
handler JumpGreaterThan(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator = jump_relational(
load(lhs),
load(rhs),
true_target,
false_target,
branch_gt_signed,
branch_fp_greater,
jump_greater_than_values,
arith_feedback
);
handler JumpLessThanEquals(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator = jump_relational(
load(lhs),
load(rhs),
true_target,
false_target,
branch_le_signed,
branch_fp_less_or_equal,
jump_less_than_equals_values,
arith_feedback
);
handler JumpGreaterThanEquals(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator = jump_relational(
load(lhs),
load(rhs),
true_target,
false_target,
branch_ge_signed,
branch_fp_greater_or_equal,
jump_greater_than_equals_values,
arith_feedback
);
handler JumpLooselyEquals(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator = jump_equality(
load(lhs),
load(rhs),
true_target,
false_target,
loose_equality,
jump_loosely_equals_values,
arith_feedback
);
handler JumpLooselyInequals(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator = jump_equality(
load(lhs),
load(rhs),
true_target,
false_target,
loose_inequality,
jump_loosely_inequals_values,
arith_feedback
);
handler JumpStrictlyEquals(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator = jump_equality(
load(lhs),
load(rhs),
true_target,
false_target,
strict_equality,
jump_strictly_equals_values,
arith_feedback
);
handler JumpStrictlyInequals(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator = jump_equality(
load(lhs),
load(rhs),
true_target,
false_target,
strict_inequality,
jump_strictly_inequals_values,
arith_feedback
);
# Loop back edges. The bytecode generator emits these variants for jumps to
# an earlier block, and they consume tier-up budget each time they run.
handler JumpLoop(
target: BytecodeOffset
) @terminator {
count_loop_iteration();
jump(target);
}
handler JumpIfLoop(
condition: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator {
count_loop_iteration();
jump_if(condition, true_target, false_target);
}
handler JumpTrueLoop(
condition: in Operand,
target: BytecodeOffset
) @terminator @fallthrough {
count_loop_iteration();
jump_true(condition, target);
}
handler JumpFalseLoop(
condition: in Operand,
target: BytecodeOffset
) @terminator @fallthrough {
count_loop_iteration();
jump_false(condition, target);
}
handler JumpLessThanLoop(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator {
count_loop_iteration();
jump_relational(
load(lhs),
load(rhs),
true_target,
false_target,
branch_lt_signed,
branch_fp_less,
jump_less_than_values,
arith_feedback
);
}
handler JumpGreaterThanLoop(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator {
count_loop_iteration();
jump_relational(
load(lhs),
load(rhs),
true_target,
false_target,
branch_gt_signed,
branch_fp_greater,
jump_greater_than_values,
arith_feedback
);
}
handler JumpLessThanEqualsLoop(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator {
count_loop_iteration();
jump_relational(
load(lhs),
load(rhs),
true_target,
false_target,
branch_le_signed,
branch_fp_less_or_equal,
jump_less_than_equals_values,
arith_feedback
);
}
handler JumpGreaterThanEqualsLoop(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator {
count_loop_iteration();
jump_relational(
load(lhs),
load(rhs),
true_target,
false_target,
branch_ge_signed,
branch_fp_greater_or_equal,
jump_greater_than_equals_values,
arith_feedback
);
}
handler JumpLooselyEqualsLoop(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator {
count_loop_iteration();
jump_equality(
load(lhs),
load(rhs),
true_target,
false_target,
loose_equality,
jump_loosely_equals_values,
arith_feedback
);
}
handler JumpLooselyInequalsLoop(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator {
count_loop_iteration();
jump_equality(
load(lhs),
load(rhs),
true_target,
false_target,
loose_inequality,
jump_loosely_inequals_values,
arith_feedback
);
}
handler JumpStrictlyEqualsLoop(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator {
count_loop_iteration();
jump_equality(
load(lhs),
load(rhs),
true_target,
false_target,
strict_equality,
jump_strictly_equals_values,
arith_feedback
);
}
handler JumpStrictlyInequalsLoop(
arith_feedback: ArithFeedbackIndex,
lhs: in Operand,
rhs: in Operand,
true_target: BytecodeOffset,
false_target: BytecodeOffset
) @terminator {
count_loop_iteration();
jump_equality(
load(lhs),
load(rhs),
true_target,
false_target,
strict_inequality,
jump_strictly_inequals_values,
arith_feedback
);
}
handler Increment(
arith_feedback: ArithFeedbackIndex,
dst: inout Operand
) = update_operand(dst, checked_add, add_f64, increment, arith_feedback);
handler Decrement(
arith_feedback: ArithFeedbackIndex,
dst: inout Operand
) = update_operand(dst, checked_sub, sub_f64, decrement, arith_feedback);
handler Not(
dst: out Operand,
src: in Operand
) {
let value = load(src);
let store_true = || {
store(dst, Value<True>);
dispatch_next;
};
let store_false = || {
store(dst, Value<False>);
dispatch_next;
};
# FIXME: Branch through a distinct continuation to retain the Boolean-first
# layout until value-match placement uses profile information.
let store_false_from_boolean = || {
goto store_false;
};
match value {
Value<bool> => {
# FIXME: Toggle bit 0 and store boolean inputs directly once result
# sinks can preserve that strictly better fast-path layout.
branch_bits_clear(value, 1, store_true);
goto store_false_from_boolean;
},
Value<i32> => {
branch_zero32(value, store_true);
goto store_false;
},
_ => {
let runtime = || {
guard runtime_truthiness(value) != 0 else store_true;
goto store_false;
};
guard value is not Value<Nullish> else store_true;
guard let Value<Object>(object) = value else runtime;
guard object.flags lacks OBJECT_FLAG_IS_HTMLDDA else store_true;
goto store_false;
},
}
}
handler ToBoolean(
dst: out Operand,
value: in Operand
) {
store(dst, box_boolean(runtime_truthiness(load(value))));
dispatch_next;
}
handler Catch(
value_feedback: ValueFeedbackIndex,
dst: out Operand
) {
let exception = exec_ctx.exception;
record_value_feedback(value_feedback, exception);
store(dst, exception);
exec_ctx.exception = Value<Empty>;
enter_jit_code_after_catch();
dispatch_next;
}
handler Return(
value: in Operand
) @terminator = return_value(load(value));
handler End(
value: in Operand
) @terminator {
let value = load(value);
assert(extract_tag(value) != extract_tag(Value<Empty>));
return_to_caller(value) else {
values[3] = value;
exit;
};
}
handler GetLexicalEnvironment(
dst: out Operand
) {
let environment = exec_ctx.lexical_environment;
assert(environment != 0);
store(dst, box_cell(environment));
dispatch_next;
}
handler GetImportMeta(
dst: out Operand
) @cold = call_slow_path(get_import_meta);
handler GetImport(
dst: out Operand,
identifier: IdentifierTableIndex,
import_index: u32
) @cold = call_slow_path(get_import);
handler GetNewTarget(
dst: out Operand
) @cold = call_slow_path(get_new_target);
handler GetSuperConstructor(
dst: out Operand
) @cold = call_slow_path(get_super_constructor);
handler SetLexicalEnvironment(
environment: in Operand
) {
let environment_value = load(environment);
assert(extract_tag(environment_value) == IS_CELL_PATTERN);
let environment: Environment = unbox_object(environment_value);
exec_ctx.lexical_environment = environment;
dispatch_next;
}
handler GetBinding(
value_feedback: ValueFeedbackIndex,
dst: out Operand,
identifier: IdentifierTableIndex,
cache: EnvironmentCoordinate
) {
let [environment, binding_index] =
walk_environment_chain(exec_ctx.lexical_environment, cache);
guard let value = load_initialized_binding(environment.binding_values, binding_index) else @cold {
call_slow_path(get_binding);
};
record_value_feedback(value_feedback, value);
store(dst, value);
dispatch_next;
}
handler DynamicGetBinding(
value_feedback: ValueFeedbackIndex,
dst: out Operand,
identifier: IdentifierTableIndex,
cache: EnvironmentCoordinateCacheIndex
) {
let slow = || @cold {
call_slow_path(dynamic_get_binding);
};
guard let [hops, binding_index] = load_cached_environment_coordinate(cache) else slow;
guard let environment = walk_cached_environment_chain(
exec_ctx.lexical_environment,
hops
) else slow;
guard let value = load_initialized_binding(environment.binding_values, binding_index) else slow;
record_value_feedback(value_feedback, value);
store(dst, value);
dispatch_next;
}
handler GetInitializedBinding(
value_feedback: ValueFeedbackIndex,
dst: out Operand,
identifier: IdentifierTableIndex,
cache: EnvironmentCoordinate
) {
let [environment, binding_index] =
walk_environment_chain(exec_ctx.lexical_environment, cache);
let value = environment.binding_values[binding_index];
record_value_feedback(value_feedback, value);
store(dst, value);
dispatch_next;
}
handler DynamicGetInitializedBinding(
value_feedback: ValueFeedbackIndex,
dst: out Operand,
identifier: IdentifierTableIndex,
cache: EnvironmentCoordinateCacheIndex
) {
let slow = || @cold {
call_slow_path(dynamic_get_initialized_binding);
};
guard let [hops, binding_index] = load_cached_environment_coordinate(cache) else slow;
guard let environment = walk_cached_environment_chain(
exec_ctx.lexical_environment,
hops
) else slow;
let value = environment.binding_values[binding_index];
record_value_feedback(value_feedback, value);
store(dst, value);
dispatch_next;
}
handler InitializeLexicalBinding(
identifier: IdentifierTableIndex,
src: in Operand,
cache: EnvironmentCoordinate
) = initialize_binding(src, cache, exec_ctx.lexical_environment);
handler InitializeVariableBinding(
identifier: IdentifierTableIndex,
src: in Operand,
cache: EnvironmentCoordinate
) = initialize_binding(src, cache, exec_ctx.variable_environment);
handler DynamicInitializeLexicalBinding(
identifier: IdentifierTableIndex,
src: in Operand,
cache: EnvironmentCoordinateCacheIndex
) {
let slow = || @cold {
call_slow_path(dynamic_initialize_lexical_binding);
};
guard let [hops, binding_index] = load_cached_environment_coordinate(cache) else slow;
guard let environment = walk_cached_environment_chain(
exec_ctx.lexical_environment,
hops
) else slow;
environment.binding_values[binding_index] = load(src);
dispatch_next;
}
handler DynamicInitializeVariableBinding(
identifier: IdentifierTableIndex,
src: in Operand,
cache: EnvironmentCoordinateCacheIndex
) {
let slow = || @cold {
call_slow_path(dynamic_initialize_variable_binding);
};
guard let [hops, binding_index] = load_cached_environment_coordinate(cache) else slow;
guard let environment = walk_cached_environment_chain(
exec_ctx.variable_environment,
hops
) else slow;
environment.binding_values[binding_index] = load(src);
dispatch_next;
}
handler SetLexicalBinding(
identifier: IdentifierTableIndex,
src: in Operand,
cache: EnvironmentCoordinate
) = set_binding(src, cache, exec_ctx.lexical_environment, set_lexical_binding);
handler SetVariableBinding(
identifier: IdentifierTableIndex,
src: in Operand,
cache: EnvironmentCoordinate
) = set_binding(src, cache, exec_ctx.variable_environment, set_variable_binding);
handler DynamicSetLexicalBinding(
identifier: IdentifierTableIndex,
src: in Operand,
cache: EnvironmentCoordinateCacheIndex
) {
let failure = || @cold {
call_slow_path(dynamic_set_lexical_binding);
};
guard let [hops, binding_index] = load_cached_environment_coordinate(cache) else failure;
guard let environment = walk_cached_environment_chain(
exec_ctx.lexical_environment,
hops
) else failure;
let binding_values = environment.binding_values;
guard binding_values[binding_index] is not Value<Empty> else failure;
guard i32(load_binding_flag(environment, binding_index)) has BINDING_FLAG_MUTABLE else failure;
binding_values[binding_index] = load(src);
dispatch_next;
}
# Evaluates a block function in the code of a script or an eval, which stores it into the var of its name if the checks
# of declaration instantiation still pass. program_environment_depth is how many environments out from the running one
# the environment of the program's own code is.
handler SetVariableBindingOfBlockFunction(
identifier: IdentifierTableIndex,
src: in Operand,
program_environment_depth: u32
) @cold = call_slow_path(asm_slow_path_set_variable_binding_of_block_function);
handler DynamicSetVariableBinding(
identifier: IdentifierTableIndex,
src: in Operand,
cache: EnvironmentCoordinateCacheIndex
) {
let failure = || @cold {
call_slow_path(dynamic_set_variable_binding);
};
guard let [hops, binding_index] = load_cached_environment_coordinate(cache) else failure;
guard let environment = walk_cached_environment_chain(
exec_ctx.variable_environment,
hops
) else failure;
let binding_values = environment.binding_values;
guard binding_values[binding_index] is not Value<Empty> else failure;
guard i32(load_binding_flag(environment, binding_index)) has BINDING_FLAG_MUTABLE else failure;
binding_values[binding_index] = load(src);
dispatch_next;
}
handler ResolveBinding(
dst: out Operand,
identifier: IdentifierTableIndex
) @cold = call_slow_path(resolve_binding);
handler ResolveSuperBase(
dst: out Operand
) @cold = call_slow_path(resolve_super_base);
handler GetResolvedBinding(
dst: out Operand,
environment: Operand,
identifier: IdentifierTableIndex
) @cold = call_slow_path(get_resolved_binding);
handler SetResolvedBinding(
environment: Operand,
identifier: IdentifierTableIndex,
src: Operand
) @cold = call_slow_path(set_resolved_binding);
handler TypeofBinding(
dst: out Operand,
identifier: IdentifierTableIndex,
cache: EnvironmentCoordinate
) @cold = call_slow_path(typeof_binding);
handler DynamicTypeofBinding(
dst: out Operand,
identifier: IdentifierTableIndex,
cache: EnvironmentCoordinateCacheIndex
) @cold = call_slow_path(dynamic_typeof_binding);
# `typeof` of a global variable, which finds it through the global variable
# cache of GetGlobal, and is "undefined" for unresolvable ones.
handler TypeofGlobal(
dst: out Operand,
identifier: IdentifierTableIndex,
cache: GlobalVariableCacheIndex
) @cold = call_slow_path(typeof_global);
handler VerifyEnvironmentCoordinate(
identifier: IdentifierTableIndex,
coordinate: EnvironmentCoordinate,
mode: EnvironmentMode
) @cold = call_slow_path(verify_environment_coordinate);
handler HasPrivateId(
dst: out Operand,
base: Operand,
property: IdentifierTableIndex
) @cold = call_slow_path(has_private_id);
handler SetFunctionName(
function: Operand,
name: Operand,
prefix: FunctionNamePrefix
) @cold = call_slow_path(set_function_name);
handler NewArrayWithLength(
dst: out Operand,
array_length: Operand
) @cold = call_slow_path(new_array_with_length);
handler ArrayAppend(
dst: in Operand,
src: Operand,
is_spread: bool
) @cold = call_slow_path(array_append);
handler CreateVariable(
identifier: IdentifierTableIndex,
mode: EnvironmentMode,
is_immutable: bool,
is_global: bool,
is_strict: bool
) @cold = call_slow_path(create_variable);
handler EnterObjectEnvironment(
dst: out Operand,
object: Operand
) @cold = call_slow_path(enter_object_environment);
handler PostfixIncrement(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
src: inout Operand
) = post_update_operand(dst, src, checked_add, add_f64, postfix_increment, arith_feedback);
handler Div(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) {
let lhs = load(lhs);
let rhs = load(rhs);
record_arith_operands_feedback(arith_feedback, lhs, rhs);
guard let [lhs_number, rhs_number] = numeric_pair_to_f64(lhs, rhs) else @cold {
call_binary_slow_path(div_values, dst, lhs, rhs);
};
let quotient = lhs_number / rhs_number;
guard let integer = double_to_int32(quotient) else store_f64;
guard integer != 0 else check_negative_zero;
goto store_i32(integer);
let check_negative_zero = || {
let bits = box_f64(quotient);
branch_value_bits_negative(bits, store_f64);
goto store_i32(integer);
};
let store_i32 = |integer: i32| @hot {
store(dst, box_i32(integer));
dispatch_next;
};
let store_f64 = || {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_OVERFLOW);
store(dst, canonicalize_nan(quotient));
dispatch_next;
};
}
handler LessThan(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = store_relational_result(
dst,
load(lhs),
load(rhs),
branch_lt_signed,
branch_fp_less,
less_than_values,
arith_feedback
);
handler LessThanEquals(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = store_relational_result(
dst,
load(lhs),
load(rhs),
branch_le_signed,
branch_fp_less_or_equal,
less_than_equals_values,
arith_feedback
);
handler GreaterThan(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = store_relational_result(
dst,
load(lhs),
load(rhs),
branch_gt_signed,
branch_fp_greater,
greater_than_values,
arith_feedback
);
handler GreaterThanEquals(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = store_relational_result(
dst,
load(lhs),
load(rhs),
branch_ge_signed,
branch_fp_greater_or_equal,
greater_than_equals_values,
arith_feedback
);
handler BitwiseXor(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = bitwise_binary(dst, load(lhs), load(rhs), xor, bitwise_xor_values, arith_feedback);
handler UnaryPlus(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
src: in Operand
) {
let value = load(src);
match value {
Value<i32> => {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32);
store(dst, value);
dispatch_next;
},
Value<f64> => @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_DOUBLE);
store(dst, value);
dispatch_next;
},
_ => @cold {
record_arith_operand_feedback(arith_feedback, value);
call_slow_path(unary_plus);
},
}
}
handler ThrowIfTDZ(
src: in Operand
) {
guard load(src) is not Value<Empty> else @cold {
call_slow_path(throw_if_tdz);
};
dispatch_next;
}
handler ThrowIfNotObject(
src: in Operand
) {
guard load(src) is Value<Object> else @cold {
call_slow_path(throw_if_not_object);
};
dispatch_next;
}
handler ThrowIfNullish(
src: in Operand
) {
guard load(src) is not Value<Nullish> else @cold {
call_slow_path(throw_if_nullish);
};
dispatch_next;
}
handler ThrowConstAssignment() @cold = call_slow_path(throw_const_assignment);
handler ThrowNotAFunction(
src: Operand
) @cold = call_slow_path(throw_not_a_function);
handler GetArgumentCount(
dst: out Operand
) {
let count = exec_ctx.passed_argument_count;
guard count <= INT32_MAX else {
call_slow_path(get_argument_count);
};
store(dst, box_i32(assume_i32(count)));
dispatch_next;
}
# `arguments[index]` of a function that has no arguments object, which reads the passed argument from the frame.
handler GetArgument(
dst: out Operand,
index: in Operand,
kind: ArgumentsKind
) {
let slow = || @cold {
call_slow_path(get_argument);
};
let key = load(index);
guard extract_tag(key) == INT32_TAG else slow;
let signed_index = unbox_i32(key);
guard signed_index >= 0 else slow;
let argument_index = assume_u32(signed_index);
guard argument_index < exec_ctx.passed_argument_count else slow;
let first_argument: u32 = exec_ctx.slot_count - exec_ctx.argument_count;
store(dst, values[first_argument + argument_index]);
dispatch_next;
}
handler Throw(
src: Operand
) @terminator @cold = call_slow_path(throw);
handler Debugger() @cold = call_slow_path(debugger);
handler Await(
continuation_label: BytecodeOffset,
argument: Operand
) @terminator @cold = call_slow_path(await);
handler Yield(
continuation_label: Optional<Label>,
value: Operand
) @terminator @cold = call_slow_path(yield);
handler YieldIteratorResult(
continuation_label: BytecodeOffset,
value: Operand
) @terminator @cold = call_slow_path(yield_iterator_result);
handler ToString(
dst: out Operand,
value: Operand
) @cold = call_slow_path(to_string);
handler ToPrimitiveWithStringHint(
dst: out Operand,
value: in Operand
) {
let primitive = load(value);
guard primitive is not Value<Object> else @cold {
call_slow_path(to_primitive_with_string_hint);
};
store(dst, primitive);
dispatch_next;
}
handler ToObject(
dst: out Operand,
value: Operand
) @cold = call_slow_path(to_object);
handler ToLength(
dst: out Operand,
value: Operand
) @cold = call_slow_path(to_length);
handler BitwiseNot(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
src: in Operand
) {
let value = load(src);
match value {
Value<i32>(integer) => {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32);
let result = ~integer;
store(dst, box_i32(result));
dispatch_next;
},
_ => @cold {
record_arith_operand_feedback(arith_feedback, value);
call_slow_path(bitwise_not);
},
}
}
handler BitwiseAnd(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = bitwise_binary(dst, load(lhs), load(rhs), and, bitwise_and_values, arith_feedback);
handler BitwiseOr(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = bitwise_binary(dst, load(lhs), load(rhs), or, bitwise_or_values, arith_feedback);
handler LeftShift(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = signed_shift(dst, load(lhs), load(rhs), shl, left_shift_values, arith_feedback);
handler RightShift(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = signed_shift(dst, load(lhs), load(rhs), sar, right_shift_values, arith_feedback);
handler UnsignedRightShift(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) {
let lhs = load(lhs);
let rhs = load(rhs);
let slow = || @cold {
record_arith_operands_feedback(arith_feedback, lhs, rhs);
call_binary_slow_path(unsigned_right_shift_values, dst, lhs, rhs);
};
guard let Value<i32>(integer) = lhs else slow;
guard let mut Value<i32>(count) = rhs else slow;
let mut value = u32(integer);
let as_double = || @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_OVERFLOW);
store(dst, box_f64(u32_to_f64(value)));
dispatch_next;
};
count = count & 31;
value = value >> u32(count);
branch_bit_set(value, 31, as_double);
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32);
store(dst, box_i32(assume_i32(value)));
dispatch_next;
}
handler Mod(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) {
let lhs = load(lhs);
let slow = || @cold {
let rhs_value = load(rhs);
record_arith_operands_feedback(arith_feedback, lhs, rhs_value);
call_binary_slow_path(mod_values, dst, lhs, rhs_value);
};
let try_int64 = || @cold {
let rhs_value = load(rhs);
record_arith_operands_feedback(arith_feedback, lhs, rhs_value);
guard let lhs_integer = integer_value_to_i64(lhs) else slow;
guard let rhs_integer = integer_value_to_i64(load(rhs)) else slow;
guard rhs_integer != 0 else slow;
let zero = || @cold {
let negative_zero = || @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_OVERFLOW);
store(dst, Value<NegativeZero>);
dispatch_next;
};
guard lhs_integer >= 0 else negative_zero;
branch_value_bits_negative(lhs, negative_zero);
let zero_value: Value = INT32_TAG_SHIFTED;
store(dst, zero_value);
dispatch_next;
};
# NB: Avoid signed division overflow for INT64_MIN % -1.
let zero_integer: i64 = 0;
let negative_one = zero_integer - 1;
guard rhs_integer != negative_one else zero;
let remainder = mod_i64(lhs_integer, rhs_integer);
guard remainder != 0 else zero;
let remainder_int32 = i32(remainder);
let widened_remainder = i64(remainder_int32);
guard widened_remainder == remainder else @cold {
store(dst, box_f64(i64_to_f64(remainder)));
dispatch_next;
};
store(dst, box_i32(remainder_int32));
dispatch_next;
};
guard let Value<i32>(lhs_int) = lhs else try_int64;
guard let Value<i32>(rhs_int) = load(rhs) else try_int64;
guard rhs_int != 0 else slow;
guard lhs_int >= 0 else try_int64;
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32);
let [_, remainder] = divmod(lhs_int, rhs_int);
store(dst, box_i32(remainder));
dispatch_next;
}
handler StrictlyEquals(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = store_equality_result(
dst,
load(lhs),
load(rhs),
strict_equality,
strictly_equals_values,
arith_feedback
);
handler StrictlyInequals(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = store_equality_result(
dst,
load(lhs),
load(rhs),
strict_inequality,
strictly_inequals_values,
arith_feedback
);
handler GetCalleeAndThisFromEnvironment(
value_feedback: ValueFeedbackIndex,
callee: out Operand,
this_value: out Operand,
identifier: IdentifierTableIndex,
cache: EnvironmentCoordinate
) {
let [environment, binding_index] =
walk_environment_chain(exec_ctx.lexical_environment, cache);
guard let value = load_initialized_binding(environment.binding_values, binding_index) else @cold {
call_slow_path(get_callee_and_this);
};
record_value_feedback(value_feedback, value);
store(callee, value);
store(this_value, Value<Undefined>);
dispatch_next;
}
handler DynamicGetCalleeAndThisFromEnvironment(
value_feedback: ValueFeedbackIndex,
callee: out Operand,
this_value: out Operand,
identifier: IdentifierTableIndex,
cache: EnvironmentCoordinateCacheIndex
) {
let slow = || @cold {
call_slow_path(dynamic_get_callee_and_this);
};
guard let [hops, binding_index] = load_cached_environment_coordinate(cache) else slow;
guard let environment = walk_cached_environment_chain(
exec_ctx.lexical_environment,
hops
) else slow;
guard let value = load_initialized_binding(environment.binding_values, binding_index) else slow;
record_value_feedback(value_feedback, value);
store(callee, value);
store(this_value, Value<Undefined>);
dispatch_next;
}
handler LooselyEquals(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = store_equality_result(
dst,
load(lhs),
load(rhs),
loose_equality,
loosely_equals_values,
arith_feedback
);
handler LooselyInequals(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
lhs: in Operand,
rhs: in Operand
) = store_equality_result(
dst,
load(lhs),
load(rhs),
loose_inequality,
loosely_inequals_values,
arith_feedback
);
handler UnaryMinus(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
src: in Operand
) {
let mut value = load(src);
match value {
Value<i32>(mut integer) => {
let negative_zero = || @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_OVERFLOW);
store(dst, Value<NegativeZero>);
dispatch_next;
};
let overflow = || @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32_OVERFLOW);
neg(integer);
let unsigned_integer: u32 = alias(integer);
store(dst, box_f64(u32_to_f64(unsigned_integer)));
dispatch_next;
};
guard integer != 0 else negative_zero;
neg32_overflow(integer) else overflow;
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32);
store(dst, box_i32(integer));
dispatch_next;
},
Value<f64> => @cold {
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_DOUBLE);
toggle_bit(value, 63);
store(dst, value);
dispatch_next;
},
_ => @cold {
record_arith_operand_feedback(arith_feedback, value);
call_slow_path(unary_minus);
},
}
}
handler PostfixDecrement(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
src: inout Operand
) = post_update_operand(dst, src, checked_sub, sub_f64, postfix_decrement, arith_feedback);
handler ToInt32(
arith_feedback: ArithFeedbackIndex,
dst: out Operand,
value: in Operand
) {
let loaded_value = load(value);
let slow = || @cold {
call_slow_path(to_int32);
};
let tag = extract_tag(loaded_value);
guard tag == INT32_TAG else @cold {
record_arith_operand_feedback(arith_feedback, loaded_value);
guard let integer = numeric_value_to_i32(load(value)) else slow;
store(dst, box_i32(integer));
dispatch_next;
};
record_arith_feedback(arith_feedback, ARITH_FEEDBACK_INT32);
store(dst, loaded_value);
dispatch_next;
}
handler PutByValue(
keyed_feedback: KeyedFeedbackIndex,
base: in Operand,
property: in Operand,
src: in Operand,
kind: PutKind,
cache: PropertyLookupCacheIndex
) {
let slow = || @cold {
call_slow_path(put_by_value);
};
let slow_without_cache = || @cold {
call_slow_path(put_by_value_uncached);
};
let try_cache = || @cold {
guard call_interp(asm_try_put_by_value_cache) == 0 else slow;
dispatch_next;
};
guard load(kind) == PUT_KIND_NORMAL else slow;
let key = load(property);
guard extract_tag(key) == INT32_TAG else {
# Keys that are not array indices: the property lookup cache remembers the shapes and keys it has
# seen, and matches string and symbol keys by identity.
guard let property_cache = load_keyed_property_lookup_cache(cache, slow_without_cache) else slow;
guard let Value<Object>(object) = load(base) else slow;
guard property_cache.key is key else try_cache;
let shape = object.shape;
guard property_cache.shape == shape else try_cache;
guard property_cache.prototype == 0 else try_cache;
guard property_cache.shape_dictionary_generation == shape.dictionary_generation else try_cache;
# NB: Addition entries have no slot at their offset.
guard property_cache.writes_data_property != 0 else try_cache;
guard object.named_properties[property_cache.property_offset] is not Value<Accessor> else try_cache;
object.named_properties[property_cache.property_offset] = load(src);
dispatch_next;
};
guard let Value<Object>(object) = load(base) else slow;
let index = u32(unbox_i32(key));
let flags = object.flags;
if flags lacks OBJECT_FLAG_IS_TYPED_ARRAY {
let try_holey_array_slow = || @cold {
guard call_interp(asm_try_put_by_value_holey_array) == 0 else slow;
dispatch_next;
};
guard flags lacks OBJECT_FLAG_MAY_INTERFERE else slow;
match object.indexed_storage_kind {
INDEXED_STORAGE_KIND_PACKED => @hot {
guard index < object.indexed_array_like_size else slow;
let indexed_elements = object.indexed_elements;
assert(indexed_elements != 0);
# The size above lives on the object while the capacity lives with the buffer, so
# bound the access by the buffer that is really being addressed.
guard index < indexed_elements.capacity else slow;
record_keyed_feedback(keyed_feedback, KEYED_FEEDBACK_INT32_INDEX_PACKED);
indexed_elements[index] = load(src);
dispatch_next;
},
INDEXED_STORAGE_KIND_HOLEY => {
guard index < object.indexed_array_like_size else slow;
let indexed_elements = object.indexed_elements;
guard indexed_elements != 0 else try_holey_array_slow;
guard index < indexed_elements.capacity else try_holey_array_slow;
guard indexed_elements[index] is not Value<Empty> else try_holey_array_slow;
record_keyed_feedback(keyed_feedback, KEYED_FEEDBACK_INT32_INDEX_HOLEY);
indexed_elements[index] = load(src);
dispatch_next;
},
_ => slow,
}
}
let try_typed_array_slow = || @cold {
guard call_interp(asm_try_put_by_value_typed_array) == 0 else slow;
dispatch_next;
};
let cached_offset = object.typed_array_cached_data_offset;
guard cached_offset != TYPED_ARRAY_CACHED_DATA_OFFSET_INVALID else try_typed_array_slow;
let elements = primitive_storage_cage_base();
# NB: A negative key wraps to an index below a length of 2^32.
let signed_index = unbox_i32(key);
guard signed_index >= 0 else slow;
let element_index: u64 = alias(index);
guard element_index < object.typed_array_array_length else slow;
let typed_array_kind = object.typed_array_kind;
record_typed_array_keyed_feedback(elements, keyed_feedback, typed_array_kind);
let source = load(src);
let store_non_integer = || {
match typed_array_kind {
TYPED_ARRAY_KIND_FLOAT32 => @hot {
guard let Value<f64>(source_f64) = source else try_typed_array_slow;
# FIXME: Sink this conversion into the store once lowering
# still schedules it ahead of caged address formation.
let source_f32 = to_f32(source_f64);
let values: Sequence<f32> = alias(
caged_primitive_storage_address(elements, cached_offset, index, 4)
);
values[0] = source_f32;
dispatch_next;
},
TYPED_ARRAY_KIND_FLOAT64 => {
guard source is Value<f64> else try_typed_array_slow;
let values: Sequence<Value> = alias(
caged_primitive_storage_address(elements, cached_offset, index, 8)
);
values[0] = source;
dispatch_next;
},
TYPED_ARRAY_KIND_UINT8 | TYPED_ARRAY_KIND_INT8 => {
guard let converted = numeric_value_to_i32(source) else try_typed_array_slow;
let values: Sequence<u8> = alias(
caged_primitive_storage_address(elements, cached_offset, index, 1)
);
values[0] = truncate_u8(converted);
dispatch_next;
},
TYPED_ARRAY_KIND_UINT16 | TYPED_ARRAY_KIND_INT16 => {
guard let converted = numeric_value_to_i32(source) else try_typed_array_slow;
let values: Sequence<u16> = alias(
caged_primitive_storage_address(elements, cached_offset, index, 2)
);
values[0] = truncate_u16(converted);
dispatch_next;
},
# Uint8Clamped is deliberately not handled here: it rounds half to even and clamps rather than truncating,
# so it keeps using the general path.
TYPED_ARRAY_KIND_INT32 | TYPED_ARRAY_KIND_UINT32 => {
guard let converted = numeric_value_to_i32(source) else try_typed_array_slow;
let values: Sequence<i32> = alias(
caged_primitive_storage_address(elements, cached_offset, index, 4)
);
values[0] = converted;
dispatch_next;
},
_ => try_typed_array_slow,
}
};
guard let mut Value<i32>(source_i32) = source else store_non_integer;
match typed_array_kind {
TYPED_ARRAY_KIND_UINT8 | TYPED_ARRAY_KIND_INT8 => {
let values: Sequence<u8> = alias(
caged_primitive_storage_address(elements, cached_offset, index, 1)
);
values[0] = truncate_u8(source_i32);
dispatch_next;
},
TYPED_ARRAY_KIND_UINT16 | TYPED_ARRAY_KIND_INT16 => {
let values: Sequence<u16> = alias(
caged_primitive_storage_address(elements, cached_offset, index, 2)
);
values[0] = truncate_u16(source_i32);
dispatch_next;
},
TYPED_ARRAY_KIND_UINT8_CLAMPED => {
let values: Sequence<u8> = alias(
caged_primitive_storage_address(elements, cached_offset, index, 1)
);
if source_i32 < 0 {
source_i32 = 0;
} else if source_i32 >= 255 {
source_i32 = 255;
}
values[0] = truncate_u8(source_i32);
dispatch_next;
},
TYPED_ARRAY_KIND_INT32 | TYPED_ARRAY_KIND_UINT32 => {
let values: Sequence<i32> = alias(
caged_primitive_storage_address(elements, cached_offset, index, 4)
);
values[0] = source_i32;
dispatch_next;
},
TYPED_ARRAY_KIND_FLOAT32 => {
# FIXME: Sink these conversions into the store once lowering
# still schedules them ahead of caged address formation.
let source_f64 = to_f64(source_i32);
let source_f32 = to_f32(source_f64);
let values: Sequence<f32> = alias(
caged_primitive_storage_address(elements, cached_offset, index, 4)
);
values[0] = source_f32;
dispatch_next;
},
TYPED_ARRAY_KIND_FLOAT64 => {
let source_f64 = to_f64(source_i32);
let values: Sequence<Value> = alias(
caged_primitive_storage_address(elements, cached_offset, index, 8)
);
values[0] = box_f64(source_f64);
dispatch_next;
},
_ => try_typed_array_slow,
}
}
handler GetById(
dst: out Operand,
base: in Operand,
property: PropertyKeyTableIndex,
cache: ProfiledPropertyLookupCacheIndex
) {
let try_cache = || @cold {
let executable = exec_ctx.executable;
let caches: u64 = alias(executable.property_lookup_caches);
let cache_index: u64 = alias(load(cache));
let cache_pointer = caches + cache_index * PROPERTY_LOOKUP_CACHE_SIZE;
let result: Value = call_helper_with_two_arguments(asm_try_get_by_id_cache, load(base), cache_pointer);
guard result is not Value<Empty> else slow;
store(dst, result);
record_cache_value_feedback(cache, result);
dispatch_next;
};
let slow = || @cold {
call_slow_path(get_by_id);
};
let invoke_accessor_slow = || @cold {
guard call_interp(asm_try_inline_get_by_id_accessor) == 0 else {
call_slow_path(get_by_id_cached_accessor);
};
let inline_vm = current_vm();
exec_ctx = inline_vm.running_execution_context;
assert(exec_ctx != 0);
values = exec_ctx.slots;
let inline_executable = exec_ctx.executable;
assert(inline_executable != 0);
pb = inline_executable.bytecode_data;
switch_dispatch_table(inline_executable);
pc = 0;
goto_handler(pc);
};
let invoke_accessor = |accessor_value: Value, receiver_object: Object, property_cache: PropertyLookupCache| @cold {
let accessor: Accessor = unbox_object(accessor_value);
let getter = accessor.getter;
guard getter != 0 else {
let produced: Value = Value<Undefined>;
record_cache_value_feedback(cache, produced);
store(dst, produced);
dispatch_next;
};
let function: Object = alias(getter);
let flags = function.flags;
guard flags has OBJECT_FLAG_IS_RAW_NATIVE_FUNCTION else invoke_accessor_slow;
if flags has OBJECT_FLAG_IS_DIRECT_GETTER_FUNCTION {
if property_cache.getter == getter {
guard let result = load_direct_getter_value(function, receiver_object) else invoke_accessor_slow;
record_cache_value_feedback(cache, result);
store(dst, result);
dispatch_next;
}
goto invoke_accessor_slow();
}
let raw_native_function: RawNativeFunction = alias(function);
let native_function_index = raw_native_function.native_function_index;
let native_table_vm = current_vm();
let native_function_entry = &native_table_vm.native_function_table[native_function_index & NATIVE_FUNCTION_TABLE_INDEX_MASK];
let native_function_type = native_function_entry.type;
assert(native_function_type < NATIVE_FUNCTION_TYPE_COUNT);
# Construct the lightweight zero-argument frame used by raw native getters.
let native_stack_vm = current_vm();
let frame_base = native_stack_vm.interpreter_stack_top;
let native_stack_limit = native_stack_vm.interpreter_stack_limit;
let native_frame: ExecutionContext = alias(frame_base);
let native_frame_end: u64 = frame_base + SIZEOF_EXECUTION_CONTEXT;
assert(native_frame_end >= frame_base);
guard native_frame_end <= native_stack_limit else invoke_accessor_slow;
let native_limit_vm = current_vm();
let machine_stack_limit: u64 = native_limit_vm.stack_base + VM_STACK_SPACE_LIMIT;
assert(machine_stack_limit >= native_limit_vm.stack_base);
guard machine_stack_limit <= fp else invoke_accessor_slow;
let native_stack_update_vm = current_vm();
native_stack_update_vm.interpreter_stack_top = native_frame_end;
# RawNativeFunction is the zero-valued native function table type.
native_frame.slot_count = native_function_type;
native_frame.argument_count = native_function_type;
native_frame.passed_argument_count = 0;
native_frame.function = function;
let lexical_environment = exec_ctx.lexical_environment;
assert(lexical_environment != 0);
native_frame.lexical_environment = lexical_environment;
let receiver: Value = alias(box_object(receiver_object));
native_frame.this_value = receiver;
native_frame.executable = null;
native_frame.program_counter = 0;
native_frame.frame_id = 0;
native_frame.caller_is_construct = false;
native_frame.frame_initialized = false;
native_frame.returns_to_native_caller = false;
native_frame.runs_jit_code = false;
native_frame.caller_is_derived_construct = false;
let undefined_new_target_1: Value = Value<Undefined>;
native_frame.new_target = undefined_new_target_1;
let native_pc: u32 = pc;
let mut destination_offset: u32;
load8(destination_offset, [pb, pc, dst]);
exec_ctx.program_counter = native_pc;
native_frame.caller_frame = exec_ctx;
# The exception helper only needs a PC within the current instruction.
native_frame.caller_return_pc = native_pc + 1;
native_frame.caller_dst_raw = destination_offset;
let native_running_vm = current_vm();
native_running_vm.running_execution_context = native_frame;
# The getter runs in its own realm, as in call_raw_native_function().
native_frame.realm_without_function = native_running_vm.current_realm;
native_running_vm.current_realm = function.shape.realm;
exec_ctx = native_frame;
values = exec_ctx.slots;
let native_function = native_function_entry.function;
let mut [native_return, variant] = call_raw_native(native_function);
let native_payload = native_return;
variant = variant & 255;
assert(variant < 2);
guard variant == 0 else @cold {
let helper_argument = native_payload;
let exception_pc: i32 = call_helper_with_two_arguments(
asm_helper_handle_raw_native_exception,
current_vm(),
helper_argument
);
guard exception_pc >= 0 else @cold {
exit;
};
let exception_vm = current_vm();
exec_ctx = exception_vm.running_execution_context;
assert(exec_ctx != 0);
values = exec_ctx.slots;
let exception_executable = exec_ctx.executable;
assert(exception_executable != 0);
pb = exception_executable.bytecode_data;
switch_dispatch_table(exception_executable);
pc = exec_ctx.program_counter;
goto_handler(pc);
};
let caller_frame = exec_ctx.caller_frame;
assert(caller_frame != 0);
let return_vm = current_vm();
return_vm.running_execution_context = caller_frame;
return_vm.current_realm = exec_ctx.realm_without_function;
return_vm.interpreter_stack_top = alias(exec_ctx);
exec_ctx = caller_frame;
values = exec_ctx.slots;
record_cache_value_feedback(cache, native_payload);
store(dst, native_payload);
dispatch_next;
};
# The other entries of a polymorphic cache (the first one did not match). Accessors and missing
# properties are left to the runtime's probe.
let try_polymorphic_entries = |object: Object, shape: Shape| {
let polymorphic_executable = exec_ctx.executable;
let tagged_cache: u64 = alias(polymorphic_executable.property_lookup_caches[load(cache)]);
let cache_tag = tagged_cache & PROPERTY_LOOKUP_CACHE_DATA_TAG_MASK;
guard cache_tag == PROPERTY_LOOKUP_CACHE_POLYMORPHIC_DATA_TAG else try_cache;
let first_entry: u64 = tagged_cache & PROPERTY_LOOKUP_CACHE_DATA_POINTER_MASK;
let second_entry_address: u64 = first_entry + PROPERTY_LOOKUP_CACHE_ENTRY_SIZE;
let second_entry: PropertyLookupCache = alias(second_entry_address);
guard second_entry.shape != shape else use_polymorphic_entry(object, second_entry, shape);
let third_entry_address: u64 = second_entry_address + PROPERTY_LOOKUP_CACHE_ENTRY_SIZE;
let third_entry: PropertyLookupCache = alias(third_entry_address);
guard third_entry.shape != shape else use_polymorphic_entry(object, third_entry, shape);
let fourth_entry_address: u64 = third_entry_address + PROPERTY_LOOKUP_CACHE_ENTRY_SIZE;
let fourth_entry: PropertyLookupCache = alias(fourth_entry_address);
guard fourth_entry.shape != shape else use_polymorphic_entry(object, fourth_entry, shape);
goto try_cache;
};
let use_polymorphic_entry = |object: Object, entry: PropertyLookupCache, shape: Shape| {
guard entry.entry_type != PROPERTY_LOOKUP_CACHE_ENTRY_TYPE_GET_MISSING_PROPERTY else try_cache;
guard entry.shape_dictionary_generation == shape.dictionary_generation else try_cache;
let entry_prototype = entry.prototype;
guard entry_prototype == 0 else @cold {
let entry_prototype_chain_validity = entry.prototype_chain_validity;
guard entry_prototype_chain_validity != 0 else try_cache;
guard entry_prototype_chain_validity.valid != 0 else try_cache;
goto load_polymorphic_value(entry_prototype, entry);
};
goto load_polymorphic_value(object, entry);
};
let load_polymorphic_value = |holder: Object, entry: PropertyLookupCache| {
let polymorphic_value = holder.named_properties[entry.property_offset];
guard polymorphic_value is not Value<Accessor> else try_cache;
record_cache_value_feedback(cache, polymorphic_value);
store(dst, polymorphic_value);
dispatch_next;
};
# Primitive bases find their properties through the prototype of their kind, which the cache remembers.
let try_primitive = || @cold {
guard call_interp(asm_try_get_by_id_cache_on_primitive) == 0 else slow;
dispatch_next;
};
guard let Value<Object>(object) = load(base) else try_primitive;
let shape = object.shape;
guard let property_cache = load_property_lookup_cache(cache) else try_cache;
guard property_cache.shape == shape else try_polymorphic_entries(object, shape);
guard property_cache.entry_type != PROPERTY_LOOKUP_CACHE_ENTRY_TYPE_GET_MISSING_PROPERTY else try_cache;
let load_cached_value = |holder: Object, object: Object, property_cache: PropertyLookupCache, shape: Shape| {
guard property_cache.shape_dictionary_generation == shape.dictionary_generation else try_cache;
let value = holder.named_properties[property_cache.property_offset];
guard value is not Value<Accessor> else invoke_accessor(value, object, property_cache);
record_cache_value_feedback(cache, value);
store(dst, value);
dispatch_next;
};
let cached_prototype = property_cache.prototype;
guard cached_prototype == 0 else @cold {
let prototype_chain_validity = property_cache.prototype_chain_validity;
guard prototype_chain_validity != 0 else try_cache;
guard prototype_chain_validity.valid != 0 else try_cache;
goto load_cached_value(cached_prototype, object, property_cache, shape);
};
goto load_cached_value(object, object, property_cache, shape);
}
handler GetByIdWithThis(
dst: out Operand,
base: in Operand,
property: PropertyKeyTableIndex,
this_value: Operand,
cache: ProfiledPropertyLookupCacheIndex
) {
let slow = || @cold {
call_slow_path(get_by_id_with_this);
};
# Data properties found through the cache of the base, whose value does not depend on the receiver. Getters run in
# the slow path with the this value.
let load_cached_value = |holder: Object, property_cache: PropertyLookupCache| {
let value = holder.named_properties[property_cache.property_offset];
guard value is not Value<Accessor> else slow;
record_cache_value_feedback(cache, value);
store(dst, value);
dispatch_next;
};
guard let Value<Object>(object) = load(base) else slow;
let shape = object.shape;
guard let property_cache = load_property_lookup_cache(cache) else slow;
guard property_cache.shape == shape else slow;
guard property_cache.entry_type != PROPERTY_LOOKUP_CACHE_ENTRY_TYPE_GET_MISSING_PROPERTY else slow;
guard property_cache.shape_dictionary_generation == shape.dictionary_generation else slow;
let cached_prototype = property_cache.prototype;
guard cached_prototype == 0 else @cold {
let prototype_chain_validity = property_cache.prototype_chain_validity;
guard prototype_chain_validity != 0 else slow;
guard prototype_chain_validity.valid != 0 else slow;
goto load_cached_value(cached_prototype, property_cache);
};
goto load_cached_value(object, property_cache);
}
handler PutById(
base: in Operand,
property: PropertyKeyTableIndex,
src: in Operand,
kind: PutKind,
cache: PropertyLookupCacheIndex
) {
let slow = || @cold {
call_slow_path(put_by_id);
};
let try_cache = || @cold {
guard call_interp(asm_try_put_by_id_cache) == 0 else slow;
dispatch_next;
};
guard let Value<Object>(object) = load(base) else try_cache;
let shape = object.shape;
guard let property_cache = load_property_lookup_cache(cache) else try_cache;
guard property_cache.shape == shape else try_cache;
guard property_cache.prototype == 0 else try_cache;
guard property_cache.shape_dictionary_generation == shape.dictionary_generation else try_cache;
# NB: Addition entries have no slot at their offset.
guard property_cache.writes_data_property != 0 else try_cache;
guard object.named_properties[property_cache.property_offset] is not Value<Accessor> else try_cache;
object.named_properties[property_cache.property_offset] = load(src);
dispatch_next;
}
handler PutByIdWithThis(
base: Operand,
this_value: Operand,
property: PropertyKeyTableIndex,
src: Operand,
kind: PutKind,
cache: PropertyLookupCacheIndex
) @cold = call_slow_path(put_by_id_with_this);
handler GetByValue(
keyed_feedback: KeyedFeedbackIndex,
dst: out Operand,
base: in Operand,
property: in Operand,
cache: ProfiledPropertyLookupCacheIndex
) {
let slow = || @cold {
call_slow_path(get_by_value);
};
let slow_without_cache = || @cold {
call_slow_path(get_by_value_uncached);
};
# Accesses that saw too many keys for their own cache look up own data properties in the VM's keyed property
# lookup cache, like the runtime does: the entry is at the top bits of the Fibonacci hash of the shape and the
# identity of the name, the word of the storage of a fly string.
let try_vm_keyed_property_lookup_cache = |keyed_object: Object| @cold {
guard let Value<PrimitiveString>(name_string) = load(property) else slow_without_cache;
let keyed_name: u64 = alias(name_string.utf16_data);
let keyed_shape = keyed_object.shape;
let keyed_shape_bits: u64 = alias(keyed_shape);
let keyed_mixed = u32(keyed_shape_bits ^ keyed_name);
let keyed_hash: u32 = keyed_mixed * KEYED_PROPERTY_LOOKUP_CACHE_HASH_MULTIPLIER;
let keyed_index: u64 = alias(keyed_hash >> KEYED_PROPERTY_LOOKUP_CACHE_INDEX_SHIFT);
let keyed_vm = current_vm();
let keyed_entry_address: u64 = keyed_vm.keyed_property_lookup_cache_entries + (keyed_index << KEYED_PROPERTY_LOOKUP_CACHE_ENTRY_SIZE_SHIFT);
let keyed_entry: KeyedPropertyLookupCacheEntry = alias(keyed_entry_address);
guard keyed_entry.property_name == keyed_name else slow_without_cache;
guard keyed_entry.shape == keyed_shape else slow_without_cache;
guard keyed_entry.entry_type == PROPERTY_LOOKUP_CACHE_ENTRY_TYPE_GET_OWN_PROPERTY else slow_without_cache;
guard keyed_entry.shape_dictionary_generation == keyed_shape.dictionary_generation else slow_without_cache;
let keyed_value = keyed_object.named_properties[keyed_entry.property_offset];
guard keyed_value is not Value<Accessor> else slow_without_cache;
# NB: The runtime recorded multiple keys before the access gave up on its own cache.
record_keyed_feedback(keyed_feedback, KEYED_FEEDBACK_MULTIPLE_STRING_KEYS);
record_cache_value_feedback(cache, keyed_value);
store(dst, keyed_value);
dispatch_next;
};
let try_cache = || @cold {
guard call_interp(asm_try_get_by_value_cache) == 0 else slow;
dispatch_next;
};
let try_typed_array_slow = || @cold {
guard call_interp(asm_try_get_by_value_typed_array) == 0 else slow;
dispatch_next;
};
let key = load(property);
guard extract_tag(key) == INT32_TAG else {
# Keys that are not array indices: the property lookup cache remembers the shapes and keys it has
# seen, and matches string and symbol keys by identity.
guard let Value<Object>(object) = load(base) else slow;
let keyed_executable = exec_ctx.executable;
let tagged_cache: u64 = alias(keyed_executable.property_lookup_caches[load(cache)]);
guard tagged_cache != PROPERTY_LOOKUP_CACHE_KEYED_GENERIC else try_vm_keyed_property_lookup_cache(object);
guard let property_cache = load_keyed_property_lookup_cache(cache, slow_without_cache) else slow;
guard property_cache.key is key else try_cache;
let shape = object.shape;
guard property_cache.shape == shape else try_cache;
guard property_cache.entry_type != PROPERTY_LOOKUP_CACHE_ENTRY_TYPE_GET_MISSING_PROPERTY else try_cache;
guard property_cache.shape_dictionary_generation == shape.dictionary_generation else try_cache;
# Values found in the prototype chain go through try_cache, which checks the chain's validity.
guard property_cache.prototype == 0 else try_cache;
let value = object.named_properties[property_cache.property_offset];
guard value is not Value<Accessor> else slow;
record_cache_value_feedback(cache, value);
store(dst, value);
dispatch_next;
};
# The code unit of a string at an index, as a string. Only ASCII code units have a string ready.
let string_index_slow = || @cold {
call_slow_path(get_by_value);
};
let string_index = || {
guard let Value<PrimitiveString>(string) = load(base) else slow;
let signed_index = unbox_i32(key);
guard signed_index >= 0 else slow;
let unsigned_index = assume_u32(signed_index);
guard let code_unit = load_primitive_string_utf16_code_unit(string, unsigned_index, string_index_slow) else slow;
guard code_unit < 0x80 else slow;
let signed_code_unit: i32 = alias(code_unit);
let result: Value = call_helper_with_two_arguments(asm_helper_single_ascii_character_string, current_vm(), signed_code_unit);
assert(extract_tag(result) == STRING_TAG);
record_keyed_feedback(keyed_feedback, KEYED_FEEDBACK_PRIMITIVE_BASE);
record_cache_value_feedback(cache, result);
store(dst, result);
dispatch_next;
};
guard let Value<Object>(object) = load(base) else string_index;
let index = u32(unbox_i32(key));
let flags = object.flags;
if flags lacks OBJECT_FLAG_IS_TYPED_ARRAY {
branch_bits_set(flags, OBJECT_FLAG_MAY_INTERFERE, slow);
match object.indexed_storage_kind {
INDEXED_STORAGE_KIND_PACKED => @hot {
guard index < object.indexed_array_like_size else slow;
let indexed_elements = object.indexed_elements;
assert(indexed_elements != 0);
# The size above lives on the object while the capacity lives with the buffer, so
# bound the access by the buffer that is really being addressed.
guard index < indexed_elements.capacity else slow;
let value = indexed_elements[index];
record_keyed_feedback(keyed_feedback, KEYED_FEEDBACK_INT32_INDEX_PACKED);
record_cache_value_feedback(cache, value);
store(dst, value);
dispatch_next;
},
INDEXED_STORAGE_KIND_HOLEY => {
guard index < object.indexed_array_like_size else slow;
let indexed_elements = object.indexed_elements;
guard indexed_elements != 0 else slow;
guard index < indexed_elements.capacity else slow;
let value = indexed_elements[index];
guard value is not Value<Empty> else slow;
record_keyed_feedback(keyed_feedback, KEYED_FEEDBACK_INT32_INDEX_HOLEY);
record_cache_value_feedback(cache, value);
store(dst, value);
dispatch_next;
},
_ => slow,
}
}
# FIXME: Refine object to TypedArray once nominal pointer refinements
# can alias their source without adding a move on either backend.
let cached_offset = object.typed_array_cached_data_offset;
guard cached_offset != TYPED_ARRAY_CACHED_DATA_OFFSET_INVALID else try_typed_array_slow;
let elements = primitive_storage_cage_base();
# NB: A negative key wraps to an index below a length of 2^32.
let signed_index = unbox_i32(key);
guard signed_index >= 0 else try_typed_array_slow;
let element_index: u64 = alias(index);
guard element_index < object.typed_array_array_length else try_typed_array_slow;
let kind = object.typed_array_kind;
record_typed_array_keyed_feedback(elements, keyed_feedback, kind);
let typed_array_f64_as_int = |raw: i32| {
let produced: Value = box_i32(raw);
record_cache_value_feedback(cache, produced);
store(dst, produced);
dispatch_next;
};
let typed_array_f64_as_double = |slot_f64: f64| {
let result = canonicalize_nan(slot_f64);
record_cache_value_feedback(cache, result);
store(dst, result);
dispatch_next;
};
# FIXME: Giving each integer kind its own box-and-dispatch tail removes
# one taken branch per load but duplicates about 30 instructions
# in this hot handler. Revisit with profile data or cost-aware layout.
let typed_array_box_int32 = |raw: i32| {
let produced: Value = box_i32(raw);
record_cache_value_feedback(cache, produced);
store(dst, produced);
dispatch_next;
};
match kind {
TYPED_ARRAY_KIND_UINT8 | TYPED_ARRAY_KIND_UINT8_CLAMPED => @hot {
let value = load_caged_u8(elements, cached_offset, index);
let widened: i32 = alias(value);
let produced: Value = box_i32(widened);
record_cache_value_feedback(cache, produced);
store(dst, produced);
dispatch_next;
},
TYPED_ARRAY_KIND_INT32 => {
goto typed_array_box_int32(load_caged_i32(elements, cached_offset, index));
},
TYPED_ARRAY_KIND_UINT16 => {
goto typed_array_box_int32(alias(load_caged_u16(elements, cached_offset, index)));
},
TYPED_ARRAY_KIND_INT8 => {
goto typed_array_box_int32(alias(load_caged_i8(elements, cached_offset, index)));
},
TYPED_ARRAY_KIND_INT16 => {
goto typed_array_box_int32(alias(load_caged_i16(elements, cached_offset, index)));
},
TYPED_ARRAY_KIND_UINT32 => {
let raw_u32 = load_caged_u32(elements, cached_offset, index);
let uint32_to_double = || @cold {
let slot_f64 = u32_to_f64(raw_u32);
let result = box_f64(slot_f64);
record_cache_value_feedback(cache, result);
store(dst, result);
dispatch_next;
};
guard raw_u32 <= INT32_MAX else uint32_to_double;
goto typed_array_box_int32(assume_i32(raw_u32));
},
TYPED_ARRAY_KIND_FLOAT32 => {
let value = load_caged_f32(elements, cached_offset, index);
let slot_f64 = float_to_double(value);
let slot = box_f64(slot_f64);
guard slot is not Value<NegativeZero> else typed_array_f64_as_double(slot_f64);
guard let raw = double_to_int32(slot_f64) else typed_array_f64_as_double(slot_f64);
goto typed_array_f64_as_int(raw);
},
TYPED_ARRAY_KIND_FLOAT64 => {
let values: Sequence<Value> = alias(
caged_primitive_storage_address(elements, cached_offset, index, 8)
);
let slot = values[0];
let slot_f64 = unbox_f64(slot);
guard slot is not Value<NegativeZero> else typed_array_f64_as_double(slot_f64);
guard let raw = double_to_int32(slot_f64) else typed_array_f64_as_double(slot_f64);
goto typed_array_f64_as_int(raw);
},
_ => try_typed_array_slow,
}
}
handler GetByValueWithThis(
value_feedback: ValueFeedbackIndex,
dst: out Operand,
base: Operand,
property: Operand,
this_value: Operand
) @cold = call_slow_path(get_by_value_with_this);
handler PutByValueWithThis(
base: Operand,
property: Operand,
this_value: Operand,
src: Operand,
kind: PutKind
) @cold = call_slow_path(put_by_value_with_this);
handler PutBySpread(
base: Operand,
src: Operand
) @cold = call_slow_path(put_by_spread);
handler GetLength(
keyed_feedback: KeyedFeedbackIndex,
dst: out Operand,
base: in Operand,
cache: ProfiledPropertyLookupCacheIndex
) {
let slow = || @cold {
call_slow_path(get_length);
};
let not_object = || {
record_keyed_feedback(keyed_feedback, KEYED_FEEDBACK_OTHER_ELEMENTS);
guard let Value<PrimitiveString>(string) = load(base) else slow;
let length = string.length_in_utf16_code_units;
guard length <= INT32_MAX else slow;
let produced: Value = box_i32(assume_i32(length));
record_cache_value_feedback(cache, produced);
store(dst, produced);
dispatch_next;
};
guard let Value<Object>(object) = load(base) else not_object;
if object.flags has OBJECT_FLAG_HAS_MAGICAL_LENGTH {
record_keyed_feedback(keyed_feedback, KEYED_FEEDBACK_MAGICAL_LENGTH);
let length = object.indexed_array_like_size;
let length_double = || @cold {
let produced: Value = box_f64(u32_to_f64(length));
record_cache_value_feedback(cache, produced);
store(dst, produced);
dispatch_next;
};
guard length <= INT32_MAX else length_double;
let produced: Value = box_i32(assume_i32(length));
record_cache_value_feedback(cache, produced);
store(dst, produced);
dispatch_next;
}
record_keyed_feedback(keyed_feedback, KEYED_FEEDBACK_OTHER_ELEMENTS);
let shape = object.shape;
guard let property_cache = load_property_lookup_cache(cache) else slow;
guard property_cache.shape == shape else slow;
guard property_cache.entry_type != PROPERTY_LOOKUP_CACHE_ENTRY_TYPE_GET_MISSING_PROPERTY else slow;
guard property_cache.prototype == 0 else slow;
guard property_cache.shape_dictionary_generation == shape.dictionary_generation else slow;
let value = object.named_properties[property_cache.property_offset];
guard value is not Value<Accessor> else slow;
record_cache_value_feedback(cache, value);
store(dst, value);
dispatch_next;
}
handler GetLengthWithThis(
dst: out Operand,
base: Operand,
this_value: Operand,
cache: ProfiledPropertyLookupCacheIndex
) @cold = call_slow_path(get_length_with_this);
handler GetMethod(
dst: out Operand,
object: Operand,
property: PropertyKeyTableIndex,
cache: PropertyLookupCacheIndex
) @cold = call_slow_path(get_method);
handler GetIterator(
dst_iterator_object: out Operand,
dst_iterator_next: out Operand,
dst_iterator_done: out Operand,
iterable: Operand,
hint: IteratorHint,
fast_array_mode_allowed: bool,
cache: PropertyLookupCacheIndex
) @cold = call_slow_path(get_iterator);
handler GetGlobal(
value_feedback: ValueFeedbackIndex,
dst: out Operand,
identifier: IdentifierTableIndex,
cache: GlobalVariableCacheIndex
) {
let slow = || @cold {
call_slow_path(get_global);
};
let realm_vm = current_vm();
let realm = realm_vm.current_realm;
let global_object = realm.global_object;
let environment = realm.global_declarative_environment;
let global_cache = load_global_variable_cache(cache);
guard global_cache.environment_serial_number == environment.serial_number else slow;
let try_environment = || {
guard global_cache.has_environment_binding_index != 0 else slow;
guard let value = load_initialized_binding(
environment.binding_values,
global_cache.environment_binding_index
) else slow;
record_value_feedback(value_feedback, value);
store(dst, value);
dispatch_next;
};
let shape = global_object.shape;
guard global_cache.shape == shape else try_environment;
guard global_cache.shape_dictionary_generation == shape.dictionary_generation else try_environment;
let value = global_object.named_properties[global_cache.property_offset];
guard value is not Value<Accessor> else slow;
record_value_feedback(value_feedback, value);
store(dst, value);
dispatch_next;
}
handler ResolveGlobalBinding(
dst: out Operand,
identifier: IdentifierTableIndex,
cache: GlobalVariableCacheIndex
) {
let slow = || @cold {
call_slow_path(resolve_global_binding);
};
# A binding the cache of the SetGlobal or GetGlobal of the identifier still finds exists.
let realm_vm = current_vm();
let realm = realm_vm.current_realm;
let global_object = realm.global_object;
let environment = realm.global_declarative_environment;
let global_cache = load_global_variable_cache(cache);
guard global_cache.environment_serial_number == environment.serial_number else slow;
let try_environment = || {
guard global_cache.has_environment_binding_index != 0 else slow;
store(dst, Value<True>);
dispatch_next;
};
let shape = global_object.shape;
guard global_cache.shape == shape else try_environment;
guard global_cache.shape_dictionary_generation == shape.dictionary_generation else try_environment;
store(dst, Value<True>);
dispatch_next;
}
handler SetGlobal(
identifier: IdentifierTableIndex,
src: in Operand,
cache: GlobalVariableCacheIndex
) {
let slow = || @cold {
call_slow_path(set_global);
};
let realm_vm = current_vm();
let realm = realm_vm.current_realm;
let global_object = realm.global_object;
let environment = realm.global_declarative_environment;
let global_cache = load_global_variable_cache(cache);
guard global_cache.environment_serial_number == environment.serial_number else slow;
let try_environment = || {
guard global_cache.has_environment_binding_index != 0 else slow;
let binding_index = global_cache.environment_binding_index;
let binding_values = environment.binding_values;
guard binding_values[binding_index] is not Value<Empty> else slow;
guard i32(load_binding_flag(environment, binding_index)) has BINDING_FLAG_MUTABLE else slow;
binding_values[binding_index] = load(src);
dispatch_next;
};
let shape = global_object.shape;
guard global_cache.shape == shape else try_environment;
guard global_cache.shape_dictionary_generation == shape.dictionary_generation else try_environment;
guard global_object.named_properties[global_cache.property_offset] is not Value<Accessor> else slow;
guard global_cache.writes_data_property != 0 else slow;
global_object.named_properties[global_cache.property_offset] = load(src);
dispatch_next;
}
# The argument count of the call instruction whose argument_count field is
# `argument_count`.
inline fn call_argument_count(
argument_count: u8
) -> u32 {
let mut count: u32;
load8(count, [pb, pc, argument_count]);
count
}
# Constructs the frame of a call of the ECMAScript function `function`, whose
# executable is `executable_pointer` and asm call metadata `metadata`, and
# enters it.
inline fn enter_ecmascript_function_call(
function: Object,
executable_pointer: Executable,
metadata: u64,
dst: out Operand,
this_value: in Operand,
argument_count: u8,
argument_operand_indices: Sequence<u8>,
slow: Label
) {
let ecmascript_function: ECMAScriptFunctionObject = alias(function);
let mut receiver: Value = Value<Empty>;
# NB: A sloppy callee binds it itself (see EnterCoercingThis).
if metadata has SHARED_FUNCTION_INSTANCE_DATA_ASM_CALL_METADATA_USES_THIS {
receiver = load(this_value);
}
# NB: This form keeps the extra arguments case on the fallthrough path.
let passed_count = call_argument_count(argument_count);
let mut formal_count: u32 = u32(metadata);
if passed_count > formal_count {
formal_count = passed_count;
}
# Construct an interpreter frame for an inline ECMAScript call.
assert(executable_pointer != 0);
let registers_and_locals_count = executable_pointer.registers_and_locals_count;
let callee_slot_count = executable_pointer.registers_and_locals_and_constants_count;
assert(callee_slot_count >= registers_and_locals_count);
let maximum_slot_count: u32 = 4294967295;
let available_argument_slot_count: u32 = maximum_slot_count - callee_slot_count;
guard available_argument_slot_count >= formal_count else slow;
let frame_slot_count: u32 = callee_slot_count + formal_count;
# FIXME: Keep frame size materialization before the VM loads until nested
# arithmetic preserves that independent scheduling opportunity.
let frame_size: u64 = alias(frame_slot_count) * SIZEOF_VALUE + SIZEOF_EXECUTION_CONTEXT;
let stack_vm = current_vm();
let frame_base = stack_vm.interpreter_stack_top;
let stack_limit = stack_vm.interpreter_stack_limit;
let frame: ExecutionContext = alias(frame_base);
let frame_end: u64 = frame_base + frame_size;
assert(frame_end >= frame_base);
guard frame_end <= stack_limit else slow;
let stack_update_vm = current_vm();
stack_update_vm.interpreter_stack_top = frame_end;
let frame_values = frame.slots;
frame.slot_count = frame_slot_count;
frame.argument_count = formal_count;
frame.passed_argument_count = call_argument_count(argument_count);
frame.function = function;
let lexical_environment = ecmascript_function.environment;
assert(lexical_environment != 0);
frame.lexical_environment = lexical_environment;
frame.this_value = receiver;
frame.executable = executable_pointer;
let empty_tag: Value = Value<Empty>;
frame.accumulator = empty_tag;
frame.exception = empty_tag;
frame.this_value_register = receiver;
frame.return_value = empty_tag;
frame.saved_lexical_environment = empty_tag;
frame.program_counter = 0;
# NB: Frames get their id when something first asks (see Vm::frame_id_of()).
frame.frame_id = 0;
# NB: Only frames of code that can yield or await have yield fields, and the runtime makes those.
frame.caller_is_construct = false;
frame.frame_initialized = false;
frame.returns_to_native_caller = false;
frame.runs_jit_code = false;
frame.caller_is_derived_construct = false;
let undefined_new_target_3: Value = Value<Undefined>;
frame.new_target = undefined_new_target_3;
frame.caller_frame = exec_ctx;
let [current_pc, return_pc, return_destination] = call_site_info(argument_count, dst);
# NB: Stack traces show the caller at its program counter.
exec_ctx.program_counter = current_pc;
frame.caller_return_pc = return_pc;
frame.caller_dst_raw = return_destination;
let actual_argument_count = call_argument_count(argument_count);
assert(formal_count >= actual_argument_count);
let mut write_index: u64 = alias(callee_slot_count);
let caller_values = exec_ctx.slots;
let mut argument_index: u32 = 0;
while argument_index < actual_argument_count {
frame_values[write_index] = caller_values[u32(argument_operand_indices[argument_index])];
argument_index = argument_index + 1;
write_index = write_index + 1;
}
let fill_end: u64 = write_index + alias(formal_count) - alias(actual_argument_count);
# FIXME: Keep this value outside the loop until nested constants are
# loop-invariant instead of being rematerialized on every iteration.
let undefined_slot: Value = Value<Undefined>;
while write_index < fill_end {
frame_values[write_index] = undefined_slot;
write_index = write_index + 1;
}
# FIXME: Reuse executable_pointer once keeping it live across frame
# construction does not exhaust the x86-64 register allocator.
let direct_executable = frame.executable;
assert(direct_executable != 0);
pb = direct_executable.bytecode_data;
switch_dispatch_table(direct_executable);
let direct_vm = current_vm();
direct_vm.running_execution_context = frame;
exec_ctx = frame;
values = exec_ctx.slots;
enter_new_frame(direct_executable);
}
# Calls the raw native function `function`, whose entry in the native function
# table is `native_function_index`, on the lightweight frame of raw native
# functions.
inline fn call_raw_native_function(
function: Object,
native_function_index: u32,
call_feedback: CallFeedbackIndex,
dst: out Operand,
this_value: in Operand,
argument_count: u8,
argument_operand_indices: Sequence<u8>,
else slow: Label
) {
let actual_argument_count = call_argument_count(argument_count);
let native_frame_size: u64 = alias(actual_argument_count) * SIZEOF_VALUE + SIZEOF_EXECUTION_CONTEXT;
let native_stack_vm = current_vm();
let frame_base = native_stack_vm.interpreter_stack_top;
let native_stack_limit = native_stack_vm.interpreter_stack_limit;
let native_frame: ExecutionContext = alias(frame_base);
let native_frame_end: u64 = frame_base + native_frame_size;
assert(native_frame_end >= frame_base);
guard native_frame_end <= native_stack_limit else slow;
let native_limit_vm = current_vm();
let machine_stack_limit: u64 = native_limit_vm.stack_base + VM_STACK_SPACE_LIMIT;
assert(machine_stack_limit >= native_limit_vm.stack_base);
guard machine_stack_limit <= fp else slow;
let native_stack_update_vm = current_vm();
native_stack_update_vm.interpreter_stack_top = native_frame_end;
native_frame.slot_count = actual_argument_count;
native_frame.argument_count = actual_argument_count;
native_frame.passed_argument_count = actual_argument_count;
native_frame.function = function;
let lexical_environment = exec_ctx.lexical_environment;
assert(lexical_environment != 0);
native_frame.lexical_environment = lexical_environment;
let receiver = load(this_value);
native_frame.this_value = receiver;
# Raw native frames deliberately have no executable.
native_frame.executable = null;
native_frame.program_counter = 0;
native_frame.frame_id = 0;
native_frame.caller_is_construct = false;
native_frame.frame_initialized = false;
native_frame.returns_to_native_caller = false;
native_frame.runs_jit_code = false;
native_frame.caller_is_derived_construct = false;
let undefined_new_target_2: Value = Value<Undefined>;
native_frame.new_target = undefined_new_target_2;
let [native_pc, after_pc, destination_offset] = call_site_info(argument_count, dst);
exec_ctx.program_counter = native_pc;
native_frame.caller_frame = exec_ctx;
native_frame.caller_return_pc = after_pc;
native_frame.caller_dst_raw = destination_offset;
let native_caller_values = exec_ctx.slots;
let native_frame_values = native_frame.slots;
let mut argument_index: u32 = 0;
while argument_index < actual_argument_count {
native_frame_values[argument_index] = native_caller_values[u32(argument_operand_indices[argument_index])];
argument_index = argument_index + 1;
}
let native_running_vm = current_vm();
native_running_vm.running_execution_context = native_frame;
# The function runs in its own realm, which may be another one. The
# frame keeps the caller's realm, which the return makes current again,
# as does the runtime when it unwinds the frame of a function that threw.
native_frame.realm_without_function = native_running_vm.current_realm;
native_running_vm.current_realm = function.shape.realm;
exec_ctx = native_frame;
values = exec_ctx.slots;
let native_function_entry = &native_running_vm.native_function_table[native_function_index & NATIVE_FUNCTION_TABLE_INDEX_MASK];
assert(native_function_entry.type < NATIVE_FUNCTION_TYPE_COUNT);
let native_function = native_function_entry.function;
# FIXME: Bind native_payload directly once the allocator can keep the
# ABI-pinned result live alongside the native result variant.
let mut [native_return, variant] = call_raw_native(native_function);
let native_payload = native_return;
variant = variant & 255;
assert(variant < 2);
guard variant == 0 else @cold {
# FIXME: Pass native_payload directly once the allocator can
# satisfy the helper ABI without conflicting with variant.
let helper_argument = native_payload;
let exception_pc: i32 = call_helper_with_two_arguments(
asm_helper_handle_raw_native_exception,
current_vm(),
helper_argument
);
guard exception_pc >= 0 else @cold {
exit;
};
let exception_vm = current_vm();
exec_ctx = exception_vm.running_execution_context;
assert(exec_ctx != 0);
values = exec_ctx.slots;
let exception_executable = exec_ctx.executable;
assert(exception_executable != 0);
pb = exception_executable.bytecode_data;
switch_dispatch_table(exception_executable);
pc = exec_ctx.program_counter;
goto_handler(pc);
};
let caller_frame = exec_ctx.caller_frame;
assert(caller_frame != 0);
let return_vm = current_vm();
return_vm.running_execution_context = caller_frame;
return_vm.current_realm = exec_ctx.realm_without_function;
return_vm.interpreter_stack_top = alias(exec_ctx);
exec_ctx = caller_frame;
values = exec_ctx.slots;
store(dst, native_payload);
record_call_value_feedback(call_feedback, native_payload);
let length: u32 = call_length(argument_count);
dispatch_variable(length);
}
# The call cache of a call site of a frame that runs the profiling handlers:
# the function that the site called last, which it calls again with no
# checks. Frames of executables in the plain tier have no call caches, and
# their calls do all the checks.
inline fn call_cache_of_site(slot: CallFeedbackIndex) -> CallCache {
let call_caches = exec_ctx.executable.call_caches;
assert(call_caches != 0);
let index: u32 = load(slot);
let call_cache: CallCache = alias(call_caches + alias(index) * CALL_CACHE_SIZE);
call_cache
}
# Calls the function that the site's call cache is linked to, if that is
# `callee`, with no checks.
inline fn call_through_call_cache(
call_feedback: CallFeedbackIndex,
callee: in Operand,
dst: out Operand,
this_value: in Operand,
argument_count: u8,
arguments: Operand[],
slow: Label
) @profiling {
let call_cache = call_cache_of_site(call_feedback);
let callee_value = load(callee);
let mut callee_bits: u64;
mov(callee_bits, callee_value);
if callee_bits == call_cache.callee {
let function: Object = unbox_object(callee_value);
let target = call_cache.target;
if target has CALL_CACHE_TARGET_NATIVE_FUNCTION {
let native_function_index: u32 = u32(target >> CALL_CACHE_TARGET_INDEX_SHIFT);
let argument_operand_indices = &arguments;
call_raw_native_function(function, native_function_index, call_feedback, dst, this_value, argument_count, argument_operand_indices) else slow;
}
let mut executable: Executable;
mov(executable, target);
let argument_operand_indices = &arguments;
enter_ecmascript_function_call(function, executable, executable.call_metadata, dst, this_value, argument_count, argument_operand_indices, slow);
}
}
# Links the site's call cache to `callee`, whose call target is `target`,
# unless the call feedback flags `site_flags` mark the site as polymorphic:
# relinking there would cost every call a store.
inline fn link_call_cache(call_feedback: CallFeedbackIndex, callee: in Operand, target: u64, site_flags: i32) @profiling {
if site_flags lacks CALL_FEEDBACK_POLYMORPHIC {
let call_cache = call_cache_of_site(call_feedback);
let mut callee_bits: u64;
mov(callee_bits, load(callee));
call_cache.target = target;
call_cache.callee = callee_bits;
}
}
handler Call(
call_feedback: CallFeedbackIndex,
dst: out Operand,
callee: in Operand,
this_value: in Operand,
argument_count: u8,
arguments: Operand[]
) {
let slow = || @cold {
call_slow_path(asm_slow_path_call);
};
call_through_call_cache(call_feedback, callee, dst, this_value, argument_count, arguments, slow);
guard let Value<Object>(function) = load(callee) else slow;
let flags = function.flags;
guard flags has OBJECT_FLAG_IS_FUNCTION else slow;
let mut call_site_flags: i32 = 0;
record_call_target(call_feedback, function, call_site_flags);
guard flags has OBJECT_FLAG_IS_ECMASCRIPT_FUNCTION_OBJECT else invoke_try_native;
let ecmascript_function: ECMAScriptFunctionObject = alias(function);
let shared_data = ecmascript_function.shared_data;
let executable_pointer = shared_data.executable;
let metadata = shared_data.asm_call_metadata;
guard metadata has SHARED_FUNCTION_INSTANCE_DATA_ASM_CALL_METADATA_CAN_INLINE_CALL else slow;
guard metadata lacks SHARED_FUNCTION_INSTANCE_DATA_ASM_CALL_METADATA_NEEDS_ENVIRONMENT_OR_THIS_VALUE_RESOLUTION else invoke_interp_inline;
# NB: A call of an ECMAScript function of another realm is the runtime's,
# which changes the current realm. A site's call cache is never linked
# to such a callee.
let callee_realm = function.shape.realm;
let realm_vm = current_vm();
guard callee_realm == realm_vm.current_realm else slow;
link_call_cache(call_feedback, callee, alias(executable_pointer), call_site_flags);
let argument_operand_indices = &arguments;
enter_ecmascript_function_call(function, executable_pointer, metadata, dst, this_value, argument_count, argument_operand_indices, slow);
let invoke_interp_inline = || {
# Let the interpreter resolve the cases that cannot use the direct
# frame construction above, then enter the resolved callee.
guard call_interp(asm_try_inline_call) == 0 else slow;
let inline_vm = current_vm();
exec_ctx = inline_vm.running_execution_context;
assert(exec_ctx != 0);
values = exec_ctx.slots;
let inline_executable = exec_ctx.executable;
assert(inline_executable != 0);
pb = inline_executable.bytecode_data;
switch_dispatch_table(inline_executable);
enter_new_frame(inline_executable);
};
let invoke_try_native = || {
# Construct the lightweight frame used by raw native functions.
let flags = function.flags;
guard flags has OBJECT_FLAG_IS_RAW_NATIVE_FUNCTION else slow;
let raw_native_function: RawNativeFunction = alias(function);
let native_function_index = raw_native_function.native_function_index;
let native_target: u64 = (alias(native_function_index) << CALL_CACHE_TARGET_INDEX_SHIFT) | CALL_CACHE_TARGET_NATIVE_FUNCTION;
link_call_cache(call_feedback, callee, native_target, call_site_flags);
let argument_operand_indices = &arguments;
call_raw_native_function(function, native_function_index, call_feedback, dst, this_value, argument_count, argument_operand_indices) else slow;
};
}
handler GetObjectPropertyIterator(
dst_keys: out Operand,
dst_receiver: out Operand,
object: Operand,
cache: ObjectPropertyIteratorCacheIndex
) @cold = call_slow_path(get_object_property_iterator);
handler ObjectPropertyIteratorNext(
dst_value: out Operand,
dst_done: out Operand,
receiver: in Operand,
keys: in Operand,
cursor: inout Operand
) {
let slow = || @cold {
call_slow_path(object_property_iterator_next);
};
# The receiver is the object being enumerated, the keys cell is the flattened
# key snapshot for this bytecode site, and the cursor is a plain integer index
# into that snapshot. None of this state lives in a script-visible object.
guard let Value<Object>(receiver_value) = load(receiver) else slow;
let receiver_object: Object = alias(receiver_value);
let keys_value = load(keys);
assert(extract_tag(keys_value) == IS_CELL_PATTERN);
let cache: ObjectPropertyIteratorCacheData = unbox_object(keys_value);
let fast_path = cache.fast_path;
guard fast_path != OBJECT_PROPERTY_ITERATOR_FAST_PATH_NONE else slow;
let cached_shape = cache.shape;
assert(cached_shape != 0);
let current_shape = receiver_object.shape;
guard current_shape == cached_shape else slow;
if cache.shape_is_dictionary {
guard current_shape.dictionary_generation == cache.shape_dictionary_generation else slow;
}
if fast_path == OBJECT_PROPERTY_ITERATOR_FAST_PATH_PACKED_INDEXED {
guard receiver_object.indexed_storage_kind == INDEXED_STORAGE_KIND_PACKED else slow;
guard receiver_object.indexed_array_like_size == cache.indexed_property_count else slow;
}
let validity = cache.prototype_chain_validity;
if validity != 0 {
guard validity.valid else slow;
}
# The cursor is a Number. It stays an int32 while it fits, which is the only case this fast path
# handles; the slow path widens it to a double once it no longer fits, so a snapshot larger than
# the int32 range still enumerates to the end.
guard let Value<i32>(cursor_index) = load(cursor) else slow;
guard cursor_index >= 0 else slow;
guard let next_cursor_index = checked_add(cursor_index, 1) else slow;
let cursor_wide: i64 = i64(cursor_index);
let unsigned_cursor: u64 = alias(cursor_wide);
let property_value_count: u64 = alias(cache.property_value_count);
if unsigned_cursor < property_value_count {
let property_values = cache.property_values;
assert(property_values != 0);
store(dst_value, property_values[unsigned_cursor]);
store(cursor, box_i32(next_cursor_index));
store(dst_done, Value<False>);
dispatch_next;
}
store(dst_done, Value<True>);
dispatch_next;
}
handler IteratorClose(
iterator_object: Operand,
iterator_next: Operand,
iterator_done: Operand,
completion_type: Completion::Type,
completion_value: Operand,
cache: PropertyLookupCacheIndex
) {
let slow = || @cold {
call_slow_path(iterator_close);
};
# An iterator without a return method closes without doing anything, for every completion type: the
# instruction that follows a close for a throw completion throws it again.
# In fast array mode, the iterator register holds a number. A watchpoint set of the realm tells if array
# iterators have a return method.
if extract_tag(load(iterator_object)) == INT32_TAG {
let watchpoint_vm = current_vm();
let return_watchpoint_set = watchpoint_vm.current_realm.array_iterator_return_watchpoint_set;
guard return_watchpoint_set != 0 else slow;
guard return_watchpoint_set.valid else slow;
dispatch_next;
}
# Other iterators: the cache of the site tells if the method is missing.
let executable = exec_ctx.executable;
let caches: u64 = alias(executable.property_lookup_caches);
let cache_index: u64 = alias(load(cache));
let cache_pointer = caches + cache_index * PROPERTY_LOOKUP_CACHE_SIZE;
let return_method: Value = call_helper_with_two_arguments(asm_try_get_by_id_cache, load(iterator_object), cache_pointer);
guard return_method is Value<Nullish> else slow;
dispatch_next;
}
handler IteratorNext(
dst: out Operand,
iterator_object: Operand,
iterator_next: Operand,
iterator_done: inout Operand
) @cold = call_slow_path(asm_slow_path_iterator_next);
# IteratorStep, which unlike IteratorNextUnpack does not read the value of the result.
handler IteratorStep(
dst_done: out Operand,
iterator_object: inout Operand,
iterator_next: Operand,
iterator_done: inout Operand
) @cold = call_slow_path(asm_slow_path_iterator_step);
handler IteratorNextUnpack(
dst_value: out Operand,
dst_done: out Operand,
iterator_object: inout Operand,
iterator_next: Operand,
iterator_done: inout Operand
) {
let slow = || @cold {
call_slow_path(iterator_next_unpack);
};
# In fast array mode, the iterator register holds the index of the next element as a number, and the next
# register holds the array (see get_iterator() in the runtime). Holes, iterations that are done and all other
# iterators take the slow path.
guard let Value<i32>(index) = load(iterator_object) else slow;
guard index >= 0 else slow;
# NB: The done register holds a boolean.
let iteration_done = load(iterator_done);
branch_bits_set(iteration_done, 1, slow);
guard let Value<Object>(array) = load(iterator_next) else slow;
let flags = array.flags;
guard flags has OBJECT_FLAG_HAS_MAGICAL_LENGTH else slow;
guard flags lacks OBJECT_FLAG_MAY_INTERFERE else slow;
let unsigned_index = assume_u32(index);
# The array iterator reads the length of the array at each step. After the last element, the done register
# keeps the iteration done, also if the array grows.
if unsigned_index >= array.indexed_array_like_size {
store(dst_value, Value<Undefined>);
store(dst_done, Value<True>);
store(iterator_done, Value<True>);
dispatch_next;
}
let next_element = || {
let indexed_elements = array.indexed_elements;
guard indexed_elements != 0 else slow;
guard unsigned_index < indexed_elements.capacity else slow;
let value = indexed_elements[unsigned_index];
guard value is not Value<Empty> else slow;
guard let next_index = checked_add(index, 1) else slow;
store(dst_value, value);
store(dst_done, Value<False>);
store(iterator_object, box_i32(next_index));
dispatch_next;
};
match array.indexed_storage_kind {
INDEXED_STORAGE_KIND_PACKED => next_element,
INDEXED_STORAGE_KIND_HOLEY => next_element,
_ => slow,
}
}
handler IteratorToArray(
dst: out Operand,
iterator_object: Operand,
iterator_next_method: Operand,
iterator_done_property: inout Operand
) @cold = call_slow_path(iterator_to_array);
handler CallConstruct(
call_feedback: CallFeedbackIndex,
dst: out Operand,
callee: Operand,
argument_count: u8,
arguments: Operand[]
) @cold = call_slow_path(call_construct);
handler CallDirectEval(
call_feedback: CallFeedbackIndex,
dst: out Operand,
callee: Operand,
this_value: Operand,
argument_count: u8,
arguments: Operand[]
) @cold = call_slow_path(call_direct_eval);
handler CallWithArgumentArray(
call_feedback: CallFeedbackIndex,
dst: out Operand,
callee: Operand,
this_value: Operand,
arguments: Operand
) @cold = call_slow_path(call_with_argument_array);
handler CallDirectEvalWithArgumentArray(
call_feedback: CallFeedbackIndex,
dst: out Operand,
callee: Operand,
this_value: Operand,
arguments: Operand
) @cold = call_slow_path(call_direct_eval_with_argument_array);
handler CallConstructWithArgumentArray(
call_feedback: CallFeedbackIndex,
dst: out Operand,
callee: Operand,
this_value: Operand,
arguments: Operand
) @cold = call_slow_path(call_construct_with_argument_array);
handler SuperCallWithArgumentArray(
call_feedback: CallFeedbackIndex,
dst: out Operand,
super_constructor: Operand,
arguments: Operand
) @cold = call_slow_path(super_call_with_argument_array);
handler SuperCall(
call_feedback: CallFeedbackIndex,
dst: out Operand,
super_constructor: Operand,
argument_count: u8,
arguments: Operand[]
) @cold = call_slow_path(super_call);
handler SuperCallWithForwardedArguments(
call_feedback: CallFeedbackIndex,
dst: out Operand,
super_constructor: Operand
) @cold = call_slow_path(super_call_with_forwarded_arguments);
handler BindThisFromSuperCall(
result: Operand
) @cold = call_slow_path(bind_this_from_super_call);
handler NewObject(
dst: out Operand,
cache: ObjectShapeCacheIndex
) @cold = call_slow_path(new_object);
handler NewObjectWithNoPrototype(
dst: out Operand
) @cold = call_slow_path(new_object_with_no_prototype);
handler CacheObjectShape(
object: Operand,
cache: ObjectShapeCacheIndex
) @cold = call_slow_path(cache_object_shape);
handler InitObjectLiteralProperty(
object: Operand,
property: PropertyKeyTableIndex,
src: Operand,
shape_cache_index: ObjectShapeCacheIndex,
property_slot: u16
) @cold = call_slow_path(init_object_literal_property);
handler NewArray(
dst: out Operand,
element_count: u8,
elements: Operand[]
) @cold = call_slow_path(new_array);
handler NewPrimitiveArray(
dst: out Operand,
element_count: u32,
elements: Value[]
) @cold = call_slow_path(new_primitive_array);
handler NewRegExp(
dst: out Operand,
source_index: StringTableIndex,
flags_index: StringTableIndex
) @cold = call_slow_path(new_regexp);
handler NewReferenceError(
dst: out Operand,
error_string: StringTableIndex
) @cold = call_slow_path(new_reference_error);
handler NewTypeError(
dst: out Operand,
error_string: StringTableIndex
) @cold = call_slow_path(new_type_error);
handler InstanceOf(
dst: out Operand,
lhs: Operand,
rhs: Operand
) @cold = call_slow_path(instance_of);
handler In(
dst: out Operand,
lhs: Operand,
rhs: Operand
) @cold = call_slow_path(in);
handler IsCallable(
dst: out Operand,
value: in Operand
) {
let not_callable = || {
store(dst, Value<False>);
dispatch_next;
};
guard let Value<Object>(object) = load(value) else not_callable;
guard object.flags has OBJECT_FLAG_IS_FUNCTION else not_callable;
store(dst, Value<True>);
dispatch_next;
}
handler IsConstructor(
dst: out Operand,
value: Operand
) @cold = call_slow_path(is_constructor);
handler AddPrivateName(
name: IdentifierTableIndex
) @cold = call_slow_path(add_private_name);
handler CreateAsyncFromSyncIterator(
dst: out Operand,
iterator: Operand,
next_method: Operand,
done: Operand
) @cold = call_slow_path(create_async_from_sync_iterator);
handler CreateDataPropertyOrThrow(
object: Operand,
property: Operand,
value: Operand
) @cold = call_slow_path(create_data_property_or_throw);
handler CreateImmutableBinding(
environment: Operand,
identifier: IdentifierTableIndex,
strict_binding: bool
) @cold = call_slow_path(create_immutable_binding);
handler CreateMutableBinding(
environment: Operand,
identifier: IdentifierTableIndex,
can_be_deleted: bool
) @cold = call_slow_path(create_mutable_binding);
handler CreateRestParams(
dst: out Operand,
rest_index: u32
) @cold = call_slow_path(create_rest_params);
handler CreateArguments(
dst: out Optional<Operand>,
kind: ArgumentsKind,
is_immutable: bool,
creates_parameter_bindings: bool
) @cold = call_slow_path(create_arguments);
handler CreateLexicalEnvironment(
dst: out Operand,
parent: Operand,
capacity: u32,
shape_cache: EnvironmentShapeCacheIndex,
is_catch_environment: bool
) @cold = call_slow_path(create_lexical_environment);
handler CreatePrivateEnvironment() @cold = call_slow_path(create_private_environment);
handler CreateVariableEnvironment(
capacity: u32
) @cold = call_slow_path(create_variable_environment);
handler DeleteById(
dst: out Operand,
base: Operand,
property: PropertyKeyTableIndex
) @cold = call_slow_path(delete_by_id);
handler DeleteByValue(
dst: out Operand,
base: Operand,
property: Operand
) @cold = call_slow_path(delete_by_value);
handler DeleteVariable(
dst: out Operand,
identifier: IdentifierTableIndex
) @cold = call_slow_path(delete_variable);
handler NewDisposableResourceStack(
dst: out Operand
) @cold = call_slow_path(new_disposable_resource_stack);
handler AddDisposableResource(
stack: Operand,
value: Operand,
hint: u32
) @cold = call_slow_path(add_disposable_resource);
handler DisposeResources(
stack: Operand,
completion_type: Operand,
completion_value: Operand
) @cold = call_slow_path(dispose_resources);
handler AsyncDisposeResourcesStep(
done: out Operand,
awaited_value: out Operand,
stack: Operand,
completion_type: Operand,
completion_value: Operand,
await_completion_type: Operand,
await_completion_value: Operand
) @cold = call_slow_path(async_dispose_resources_step);
handler GetCompletionFields(
type_dst: out Operand,
value_dst: out Operand,
completion: Operand
) @cold = call_slow_path(get_completion_fields);
handler SetCompletionType(
completion: Operand,
completion_type: Completion::Type
) @cold = call_slow_path(set_completion_type);
handler GetTemplateObject(
dst: out Operand,
strings_are_in_array: bool,
strings_count: u8,
cache: TemplateObjectCacheIndex,
strings: Operand[]
) @cold = call_slow_path(get_template_object);
handler NewFunction(
dst: out Operand,
shared_function_data_index: u16,
lhs_name: Optional<IdentifierTableIndex>,
home_object: Optional<Operand>
) @cold = call_slow_path(new_function);
# NB: A NewFunction for the functions of an executable past its first 65536, whose index takes four bytes.
handler NewFunctionWide(
dst: out Operand,
shared_function_data_index: u32,
lhs_name: Optional<IdentifierTableIndex>,
home_object: Optional<Operand>
) @cold = call_slow_path(new_function_wide);
handler Typeof(
dst: out Operand,
src: Operand
) @cold = call_slow_path(typeof);
handler LeavePrivateEnvironment() {
let private_environment = exec_ctx.private_environment;
assert(private_environment != 0);
exec_ctx.private_environment = private_environment.outer;
dispatch_next;
}
handler ResolveThisBinding() {
guard exec_ctx.this_value_register is not Value<Empty> else @cold {
call_slow_path(resolve_this_binding);
};
dispatch_next;
}
handler GetPrivateById(
dst: out Operand,
base: Operand,
property: IdentifierTableIndex
) @cold = call_slow_path(get_private_by_id);
handler PutPrivateById(
base: Operand,
property: IdentifierTableIndex,
src: Operand
) @cold = call_slow_path(put_private_by_id);