Truly independent web browser
LibJS: Give the call sites of warm executables call caches
Andreas Klingc4dad1fd2b29
diff --git a/Libraries/LibJS/Flap/src/hir/mod.rs b/Libraries/LibJS/Flap/src/hir/mod.rsindex 6b7c6df2df1..86a48200688 100644--- a/Libraries/LibJS/Flap/src/hir/mod.rs+++ b/Libraries/LibJS/Flap/src/hir/mod.rs@@ -3047,6 +3047,7 @@ fn field_width(ty: &Type, allow_pointer: bool) -> Option<FieldWidth> {| Type::EnvironmentShape| Type::DeclarativeEnvironmentRareData| Type::GlobalVariableCache+ | Type::CallCache| Type::PropertyLookupCache| Type::ObjectPropertyIteratorCacheData| Type::ObjectPropertyIteratorCachediff --git a/Libraries/LibJS/Flap/src/types.rs b/Libraries/LibJS/Flap/src/types.rsindex 6ee851d813d..668de71640b 100644--- a/Libraries/LibJS/Flap/src/types.rs+++ b/Libraries/LibJS/Flap/src/types.rs@@ -214,6 +214,7 @@ define_named_types! {EnvironmentShape => "EnvironmentShape", Some(8), true;DeclarativeEnvironmentRareData => "DeclarativeEnvironmentRareData", Some(8), true;GlobalVariableCache => "GlobalVariableCache", Some(8), true;+ CallCache => "CallCache", Some(8), true;PropertyLookupCache => "PropertyLookupCache", Some(8), true;KeyedPropertyLookupCacheEntry => "KeyedPropertyLookupCacheEntry", Some(8), true;ExecutableFeedback => "ExecutableFeedback", Some(8), true;diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.Sindex d25e109df8c..514c7d50548 100644--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S@@ -6216,16 +6216,16 @@ asm_handler_Call:1:tbnz x0, #33, .Lasm_Call.ssa_block_2movz x6, #0x7ffb, lsl #48- tbz x0, #34, .Lasm_Call.ssa_block_9+ tbz x0, #34, .Lasm_Call.ssa_block_15ldrb w3, [x21, #5]ldr x6, [x27, x3, lsl #3]- tbnz x0, #35, .Lasm_Call.ssa_block_9+ tbnz x0, #35, .Lasm_Call.ssa_block_15lsr x3, x6, #48mov x4, x3and w4, w4, #0xfffemov w9, #32766cmp w4, w9- b.ne .Lasm_Call.ssa_block_13+ b.ne .Lasm_Call.ssa_block_19ldr w3, [x1, #20]cbz x3, .Lasm_Call.assert_failure_1add x3, x24, w3, uxtw #3@@ -6238,22 +6238,17 @@ asm_handler_Call:and x6, x6, #0x7ffffffffmovz x3, #0xfff9, lsl #48orr x6, x6, x3- b .Lasm_Call.ssa_block_9-.Lasm_Call.ssa_block_13:- mov w9, #65529- cmp w3, w9- b.ne .Lasm_Call.ssa_block_2-.Lasm_Call.ssa_block_9:+.Lasm_Call.ssa_block_15:ldrb w4, [x21, #6]mov w3, w0- cmp x3, x4- b.hs .Lasm_Call.ssa_block_29+ cmp x4, x3+ b.ls .Lasm_Call.ssa_block_23mov x3, x4-.Lasm_Call.ssa_block_29:- cbz x2, .Lasm_Call.assert_predicate_failure_377+.Lasm_Call.ssa_block_23:+ cbz x2, .Lasm_Call.assert_predicate_failure_263ldp w0, w4, [x2, #12]cmp x4, x0- b.lo .Lasm_Call.assert_predicate_failure_383+ b.lo .Lasm_Call.assert_predicate_failure_269movn w0, #0subs x0, x0, x4cmp x0, x3@@ -6268,7 +6263,7 @@ asm_handler_Call:add x5, x5, #136adds x5, x5, x0cmp x5, x0- b.lo .Lasm_Call.assert_predicate_failure_398+ b.lo .Lasm_Call.assert_predicate_failure_283cmp x5, x8b.hi .Lasm_Call.ssa_block_1mov x8, x20@@ -6287,19 +6282,19 @@ asm_handler_Call:add x9, x24, w5, uxtw #3cmp w5, #0csel x5, x9, xzr, ne- cbz x5, .Lasm_Call.assert_predicate_failure_425+ cbz x5, .Lasm_Call.assert_predicate_failure_310stp x5, x5, [x0, #32]str xzr, [x0, #48]ldrb w9, [x1, #15]mov w10, #8tst x9, x10- b.eq .Lasm_Call.ssa_block_16+ b.eq .Lasm_Call.ssa_block_27ldr w5, [x1, #76]add x9, x24, w5, uxtw #3cmp w5, #0csel x5, x9, xzr, nestr x5, [x0, #48]-.Lasm_Call.ssa_block_16:+.Lasm_Call.ssa_block_27:stp x6, x2, [x0, #80]movz x2, #0x7ffb, lsl #48stp x2, x2, [x0, #136]@@ -6340,33 +6335,33 @@ asm_handler_Call:stp w1, w5, [x0, #108]ldrb w2, [x21, #6]cmp x3, x2- b.lo .Lasm_Call.assert_predicate_failure_285- add x6, x28, #136- add x7, x21, #7+ b.lo .Lasm_Call.assert_predicate_failure_397+ add x6, x21, #7add x5, x0, #136+ add x7, x28, #136mov x1, #0-.Lasm_Call.ssa_block_19:+.Lasm_Call.ssa_block_30:cmp x1, x2- b.hs .Lasm_Call.ssa_block_18- ldrb w8, [x7, x1]- ldr x8, [x6, x8, lsl #3]+ b.hs .Lasm_Call.ssa_block_29+ ldrb w8, [x6, x1]+ ldr x8, [x7, x8, lsl #3]str x8, [x5, x4, lsl #3]add x1, x1, #1add x4, x4, #1- b .Lasm_Call.ssa_block_19-.Lasm_Call.ssa_block_18:+ b .Lasm_Call.ssa_block_30+.Lasm_Call.ssa_block_29:movz x1, #0x7ffe, lsl #48adds x3, x3, x4subs x3, x3, x2-.Lasm_Call.ssa_block_22:+.Lasm_Call.ssa_block_33:cmp x4, x3- b.hs .Lasm_Call.ssa_block_21+ b.hs .Lasm_Call.ssa_block_32str x1, [x5, x4, lsl #3]add x4, x4, #1- b .Lasm_Call.ssa_block_22-.Lasm_Call.ssa_block_21:+ b .Lasm_Call.ssa_block_33+.Lasm_Call.ssa_block_32:ldr x1, [x0, #88]- cbz x1, .Lasm_Call.assert_predicate_failure_309+ cbz x1, .Lasm_Call.assert_predicate_failure_420ldr x26, [x1, #40]cbz x26, .Lasm_Call.assert_failure_10mov x1, x20@@ -6378,131 +6373,10 @@ asm_handler_Call:ldrb w9, [x21]ldr x10, [x19, x9, lsl #3]br x10-.Lasm_Call.ssa_block_3:- tbnz x0, #1, 1f- b .Lasm_Call.ssa_block_1-1:- ldrb w3, [x21, #6]- mov x0, x20- ldp x0, x4, [x0, #16]- cbz x0, .Lasm_Call.assert_failure_11- cbz x4, .Lasm_Call.assert_failure_12- lsl x2, x3, #3- add x2, x2, #136- adds x2, x2, x0- cmp x2, x0- b.lo .Lasm_Call.assert_predicate_failure_36- cmp x2, x4- b.hi .Lasm_Call.ssa_block_1- mov x4, x20- ldr x5, [x4, #40]- mov x4, x5- add x4, x4, #8, lsl #12- cmp x4, x5- b.lo .Lasm_Call.assert_predicate_failure_44- cmp x4, x29- b.hi .Lasm_Call.ssa_block_1- mov x4, x20- str x2, [x4, #16]- stp w3, w3, [x0, #116]- str w3, [x0, #104]- ldr w2, [x1, #20]- cbz x2, .Lasm_Call.assert_failure_13- add x2, x24, w2, uxtw #3- ldr w2, [x2, #12]- cbz x2, .Lasm_Call.assert_failure_14- add x2, x24, w2, uxtw #3- stp x1, x2, [x0, #0]- ldp x2, x4, [x28, #32]- cbz x2, .Lasm_Call.assert_predicate_failure_69- cbz x4, .Lasm_Call.assert_predicate_failure_71- stp x2, x4, [x0, #32]- ldr x2, [x28, #48]- str x2, [x0, #48]- ldrb w2, [x21, #5]- ldr x2, [x27, x2, lsl #3]- str x2, [x0, #80]- str xzr, [x0, #16]- str xzr, [x0, #88]- str wzr, [x0, #64]- mov x4, x20- ldr x2, [x4, #32]- cbz x2, .Lasm_Call.assert_failure_15- str x2, [x0, #56]- add x2, x2, #1- str x2, [x4, #32]- str wzr, [x0, #68]- movn w9, #0- str w9, [x0, #72]- strb wzr, [x0, #76]- strb wzr, [x0, #77]- strb wzr, [x0, #78]- strb wzr, [x0, #79]- strb wzr, [x0, #124]- strb wzr, [x0, #125]- strb wzr, [x0, #126]- movz x2, #0x7ffe, lsl #48- str x2, [x0, #128]- ldrb w4, [x21, #6]- mov w2, #7- adds x2, x2, x4- ldrb w5, [x21, #3]- sub w4, w21, w26- adds x2, x2, x4- str w4, [x28, #64]- str x28, [x0, #96]- stp w2, w5, [x0, #108]- add x4, x28, #136- add x5, x21, #7- add x6, x0, #136- mov x2, #0-.Lasm_Call.ssa_block_25:- cmp x2, x3- b.hs .Lasm_Call.ssa_block_24- ldrb w7, [x5, x2]- ldr x7, [x4, x7, lsl #3]- str x7, [x6, x2, lsl #3]- add x2, x2, #1- b .Lasm_Call.ssa_block_25-.Lasm_Call.ssa_block_24:- mov x2, x20- str x0, [x2]- mov x28, x0- add x27, x28, #136- ldr w0, [x1, #92]- ldr x1, [x2, #80]- cbz x1, .Lasm_Call.assert_failure_16- and w0, w0, #0xffff- lsl x0, x0, #4- adds x0, x0, x1- ldr w1, [x0, #8]- cmp x1, #1- b.hs .Lasm_Call.assert_predicate_failure_345- ldr x2, [x0]- cbz x2, .Lasm_Call.assert_failure_17- mov x9, x2- mov x0, x20- blr x9- and x1, x1, #0xff- cmp x1, #2- b.hs .Lasm_Call.assert_predicate_failure_352- cbnz x1, .Lasm_Call.ssa_block_4- ldr x1, [x28, #96]- cbz x1, .Lasm_Call.assert_predicate_failure_358- mov x2, x20- str x1, [x2]- str x28, [x2, #16]- mov x28, x1- add x27, x28, #136- ldrb w9, [x21, #3]- str x0, [x27, x9, lsl #3]- ldrb w1, [x21, #6]- mov w0, #7- adds x0, x0, x1- add x21, x21, w0, uxtw- ldrb w9, [x21]- ldr x10, [x19, x9, lsl #3]- br x10+.Lasm_Call.ssa_block_19:+ mov w9, #65529+ cmp w3, w9+ b.eq .Lasm_Call.ssa_block_15.Lasm_Call.ssa_block_2:add x9, sp, #0ldrb w10, [x21, #6]@@ -6514,42 +6388,42 @@ asm_handler_Call:mov w13, #32768add x12, x12, x13cmp x14, x12- b.hs .Lasm_Call.values_allocate_19+ b.hs .Lasm_Call.values_allocate_12mov w0, #1- b .Lasm_Call.values_call_done_18-.Lasm_Call.values_allocate_19:-.Lasm_Call.values_probe_20:+ b .Lasm_Call.values_call_done_11+.Lasm_Call.values_allocate_12:+.Lasm_Call.values_probe_13:sub x10, sp, #1, lsl #12cmp x10, x14- b.ls .Lasm_Call.values_allocated_21+ b.ls .Lasm_Call.values_allocated_14add sp, x10, #0str xzr, [sp]- b .Lasm_Call.values_probe_20-.Lasm_Call.values_allocated_21:+ b .Lasm_Call.values_probe_13+.Lasm_Call.values_allocated_14:add sp, x14, #0str x9, [sp]ldrb w12, [x21, #4]ldr x11, [x27, x12, lsl #3]-.Lasm_Call.value_ready_22:+.Lasm_Call.value_ready_15:str x11, [sp, #24]ldrb w12, [x21, #5]ldr x11, [x27, x12, lsl #3]-.Lasm_Call.value_ready_23:+.Lasm_Call.value_ready_16:str x11, [sp, #32]mov w9, #0ldrb w10, [x21, #6]add x14, sp, #40add x3, x21, #7-.Lasm_Call.array_value_next_24:+.Lasm_Call.array_value_next_17:cmp x9, x10- b.hs .Lasm_Call.array_values_end_26+ b.hs .Lasm_Call.array_values_end_19ldrb w12, [x3, x9]ldr x11, [x27, x12, lsl #3]-.Lasm_Call.array_value_ready_25:+.Lasm_Call.array_value_ready_18:str x11, [x14, x9, lsl #3]add x9, x9, #1- b .Lasm_Call.array_value_next_24-.Lasm_Call.array_values_end_26:+ b .Lasm_Call.array_value_next_17+.Lasm_Call.array_values_end_19:mov x0, x20sub w1, w21, w26mov x2, x21@@ -6557,18 +6431,18 @@ asm_handler_Call:bl CSYM(asm_try_inline_call)ldr x9, [x20]cmp x9, x28- b.ne .Lasm_Call.values_restore_stack_27- cbnz x0, .Lasm_Call.values_exceptional_outputs_28+ b.ne .Lasm_Call.values_restore_stack_20+ cbnz x0, .Lasm_Call.values_exceptional_outputs_21ldrb w12, [x21, #3]ldr x11, [sp, #16]str x11, [x27, x12, lsl #3]-.Lasm_Call.skip_output_value_29:- b .Lasm_Call.values_restore_stack_27-.Lasm_Call.values_exceptional_outputs_28:-.Lasm_Call.values_restore_stack_27:+.Lasm_Call.skip_output_value_22:+ b .Lasm_Call.values_restore_stack_20+.Lasm_Call.values_exceptional_outputs_21:+.Lasm_Call.values_restore_stack_20:ldr x9, [sp]add sp, x9, #0-.Lasm_Call.values_call_done_18:+.Lasm_Call.values_call_done_11:cbnz w0, .Lasm_Call.ssa_block_1mov x0, x20ldr x28, [x0]@@ -6577,12 +6451,137 @@ asm_handler_Call:ldr x0, [x28, #88]cbz x0, .Lasm_Call.assert_predicate_failure_17ldr x26, [x0, #40]- cbz x26, .Lasm_Call.assert_failure_30+ cbz x26, .Lasm_Call.assert_failure_23mov w25, #0add x21, x26, w25, uxtwldrb w9, [x21]ldr x10, [x19, x9, lsl #3]br x10+.Lasm_Call.ssa_block_3:+ tbnz x0, #1, 1f+ b .Lasm_Call.ssa_block_1+1:+ ldr w4, [x1, #92]+ ldrb w2, [x21, #6]+ mov x0, x20+ ldp x0, x5, [x0, #16]+ cbz x0, .Lasm_Call.assert_failure_24+ cbz x5, .Lasm_Call.assert_failure_25+ lsl x3, x2, #3+ add x3, x3, #136+ adds x3, x3, x0+ cmp x3, x0+ b.lo .Lasm_Call.assert_predicate_failure_41+ cmp x3, x5+ b.hi .Lasm_Call.ssa_block_1+ mov x5, x20+ ldr x6, [x5, #40]+ mov x5, x6+ add x5, x5, #8, lsl #12+ cmp x5, x6+ b.lo .Lasm_Call.assert_predicate_failure_91+ cmp x5, x29+ b.hi .Lasm_Call.ssa_block_1+ mov x5, x20+ str x3, [x5, #16]+ stp w2, w2, [x0, #116]+ str w2, [x0, #104]+ ldr w3, [x1, #20]+ cbz x3, .Lasm_Call.assert_failure_26+ add x3, x24, w3, uxtw #3+ ldr w3, [x3, #12]+ cbz x3, .Lasm_Call.assert_failure_27+ add x3, x24, w3, uxtw #3+ stp x1, x3, [x0, #0]+ ldp x1, x3, [x28, #32]+ cbz x1, .Lasm_Call.assert_predicate_failure_115+ cbz x3, .Lasm_Call.assert_predicate_failure_117+ stp x1, x3, [x0, #32]+ ldr x1, [x28, #48]+ str x1, [x0, #48]+ ldrb w1, [x21, #5]+ ldr x1, [x27, x1, lsl #3]+ str x1, [x0, #80]+ str xzr, [x0, #16]+ str xzr, [x0, #88]+ str wzr, [x0, #64]+ mov x3, x20+ ldr x1, [x3, #32]+ cbz x1, .Lasm_Call.assert_failure_28+ str x1, [x0, #56]+ add x1, x1, #1+ str x1, [x3, #32]+ str wzr, [x0, #68]+ movn w9, #0+ str w9, [x0, #72]+ strb wzr, [x0, #76]+ strb wzr, [x0, #77]+ strb wzr, [x0, #78]+ strb wzr, [x0, #79]+ strb wzr, [x0, #124]+ strb wzr, [x0, #125]+ strb wzr, [x0, #126]+ movz x1, #0x7ffe, lsl #48+ str x1, [x0, #128]+ ldrb w3, [x21, #6]+ mov w1, #7+ adds x1, x1, x3+ ldrb w5, [x21, #3]+ sub w3, w21, w26+ adds x1, x1, x3+ str w3, [x28, #64]+ str x28, [x0, #96]+ stp w1, w5, [x0, #108]+ add x3, x21, #7+ add x5, x28, #136+ add x6, x0, #136+ mov x1, #0+.Lasm_Call.ssa_block_12:+ cmp x1, x2+ b.hs .Lasm_Call.ssa_block_11+ ldrb w7, [x3, x1]+ ldr x7, [x5, x7, lsl #3]+ str x7, [x6, x1, lsl #3]+ add x1, x1, #1+ b .Lasm_Call.ssa_block_12+.Lasm_Call.ssa_block_11:+ mov x1, x20+ str x0, [x1]+ mov x28, x0+ add x27, x28, #136+ ldr x0, [x1, #80]+ cbz x0, .Lasm_Call.assert_failure_29+ and w4, w4, #0xffff+ lsl x4, x4, #4+ adds x4, x4, x0+ ldr w0, [x4, #8]+ cmp x0, #1+ b.hs .Lasm_Call.assert_predicate_failure_208+ ldr x2, [x4]+ cbz x2, .Lasm_Call.assert_failure_30+ mov x9, x2+ mov x0, x20+ blr x9+ and x1, x1, #0xff+ cmp x1, #2+ b.hs .Lasm_Call.assert_predicate_failure_215+ cbnz x1, .Lasm_Call.ssa_block_6+ ldr x1, [x28, #96]+ cbz x1, .Lasm_Call.assert_predicate_failure_221+ mov x2, x20+ str x1, [x2]+ str x28, [x2, #16]+ mov x28, x1+ add x27, x28, #136+ ldrb w9, [x21, #3]+ str x0, [x27, x9, lsl #3]+ ldrb w1, [x21, #6]+ mov w0, #7+ adds x0, x0, x1+ add x21, x21, w0, uxtw+ ldrb w9, [x21]+ ldr x10, [x19, x9, lsl #3]+ br x10asm_handler_Call_hot_end:.p2align 4@@ -15759,19 +15758,19 @@ asm_handler_SetGlobal_cold:asm_handler_SetGlobal_cold_end:asm_handler_Call_cold:// Cold paths for Call-.Lasm_Call.ssa_block_4:+.Lasm_Call.ssa_block_6:mov x1, x0mov x0, x20bl CSYM(asm_helper_handle_raw_native_exception)tbz w0, #31, 1f- b .Lasm_Call.ssa_block_5+ b .Lasm_Call.ssa_block_71:mov x0, x20ldr x28, [x0]- cbz x28, .Lasm_Call.assert_predicate_failure_151+ cbz x28, .Lasm_Call.assert_predicate_failure_73add x27, x28, #136ldr x0, [x28, #88]- cbz x0, .Lasm_Call.assert_predicate_failure_157+ cbz x0, .Lasm_Call.assert_predicate_failure_79ldr x26, [x0, #40]cbz x26, .Lasm_Call.assert_failure_31ldr w25, [x28, #64]@@ -15876,7 +15875,7 @@ asm_handler_Call_cold:ldrb w9, [x21]ldr x10, [x19, x9, lsl #3]br x10-.Lasm_Call.ssa_block_5:+.Lasm_Call.ssa_block_7:b .Lexitasm_handler_Call_cold_end:.p2align 4@@ -21583,69 +21582,69 @@ asm_assertion_failure_traps:brk #0.Lasm_Call.assert_failure_3:brk #0-.Lasm_Call.assert_predicate_failure_377:+.Lasm_Call.assert_predicate_failure_263:brk #0-.Lasm_Call.assert_predicate_failure_383:+.Lasm_Call.assert_predicate_failure_269:brk #0.Lasm_Call.assert_failure_4:brk #0.Lasm_Call.assert_failure_5:brk #0-.Lasm_Call.assert_predicate_failure_398:+.Lasm_Call.assert_predicate_failure_283:brk #0.Lasm_Call.assert_failure_6:brk #0.Lasm_Call.assert_failure_7:brk #0-.Lasm_Call.assert_predicate_failure_425:+.Lasm_Call.assert_predicate_failure_310:brk #0.Lasm_Call.assert_failure_8:brk #0.Lasm_Call.assert_failure_9:brk #0-.Lasm_Call.assert_predicate_failure_285:+.Lasm_Call.assert_predicate_failure_397:brk #0-.Lasm_Call.assert_predicate_failure_309:+.Lasm_Call.assert_predicate_failure_420:brk #0.Lasm_Call.assert_failure_10:brk #0-.Lasm_Call.assert_failure_11:+.Lasm_Call.assert_predicate_failure_11:brk #0-.Lasm_Call.assert_failure_12:+.Lasm_Call.assert_predicate_failure_17:brk #0-.Lasm_Call.assert_predicate_failure_36:+.Lasm_Call.assert_failure_23:brk #0-.Lasm_Call.assert_predicate_failure_44:+.Lasm_Call.assert_failure_24:brk #0-.Lasm_Call.assert_failure_13:+.Lasm_Call.assert_failure_25:brk #0-.Lasm_Call.assert_failure_14:+.Lasm_Call.assert_predicate_failure_41:brk #0-.Lasm_Call.assert_predicate_failure_69:+.Lasm_Call.assert_predicate_failure_91:brk #0-.Lasm_Call.assert_predicate_failure_71:+.Lasm_Call.assert_failure_26:brk #0-.Lasm_Call.assert_failure_15:+.Lasm_Call.assert_failure_27:brk #0-.Lasm_Call.assert_failure_16:+.Lasm_Call.assert_predicate_failure_115:brk #0-.Lasm_Call.assert_predicate_failure_345:+.Lasm_Call.assert_predicate_failure_117:brk #0-.Lasm_Call.assert_failure_17:+.Lasm_Call.assert_failure_28:brk #0-.Lasm_Call.assert_predicate_failure_352:+.Lasm_Call.assert_failure_29:brk #0-.Lasm_Call.assert_predicate_failure_358:+.Lasm_Call.assert_predicate_failure_208:brk #0-.Lasm_Call.assert_predicate_failure_11:+.Lasm_Call.assert_failure_30:brk #0-.Lasm_Call.assert_predicate_failure_17:+.Lasm_Call.assert_predicate_failure_215:brk #0-.Lasm_Call.assert_failure_30:+.Lasm_Call.assert_predicate_failure_221:brk #0-.Lasm_Call.assert_predicate_failure_151:+.Lasm_Call.assert_predicate_failure_73:brk #0-.Lasm_Call.assert_predicate_failure_157:+.Lasm_Call.assert_predicate_failure_79:brk #0.Lasm_Call.assert_failure_31:brk #0diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.Sindex bdae720c6fd..d25cf0eb2b6 100644--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S@@ -6266,17 +6266,17 @@ asm_handler_Call:jc .Lasm_Call.ssa_block_2movabs r9, 9221964661971222528bt rax, 34- jnc .Lasm_Call.ssa_block_9+ jnc .Lasm_Call.ssa_block_15movzx esi, BYTE PTR [r14 + r13 + 5]mov r9, QWORD PTR [rbx + rsi * 8]bt rax, 35- jc .Lasm_Call.ssa_block_9+ jc .Lasm_Call.ssa_block_15mov rsi, r9shr rsi, 48mov rdi, rsiand di, 65534cmp di, 32766- jne .Lasm_Call.ssa_block_13+ jne .Lasm_Call.ssa_block_19mov esi, DWORD PTR [rcx + 20]test rsi, rsijz .Lasm_Call.assert_failure_1@@ -6293,23 +6293,19 @@ asm_handler_Call:and r9, rsimovabs rsi, -1970324836974592or r9, rsi- jmp .Lasm_Call.ssa_block_9-.Lasm_Call.ssa_block_13:- cmp si, 65529- jne .Lasm_Call.ssa_block_2-.Lasm_Call.ssa_block_9:+.Lasm_Call.ssa_block_15:movzx edi, BYTE PTR [r14 + r13 + 6]mov esi, eax- cmp rsi, rdi- jae .Lasm_Call.ssa_block_29+ cmp rdi, rsi+ jbe .Lasm_Call.ssa_block_23mov rsi, rdi-.Lasm_Call.ssa_block_29:+.Lasm_Call.ssa_block_23:test rdx, rdx- jz .Lasm_Call.assert_predicate_failure_377+ jz .Lasm_Call.assert_predicate_failure_263mov eax, DWORD PTR [rdx + 12]mov edi, DWORD PTR [rdx + 16]cmp rdi, rax- jb .Lasm_Call.assert_predicate_failure_383+ jb .Lasm_Call.assert_predicate_failure_269mov eax, 4294967295sub rax, rdicmp rax, rsi@@ -6328,7 +6324,7 @@ asm_handler_Call:lea r8, [r8 + 136]add r8, raxcmp r8, rax- jb .Lasm_Call.assert_predicate_failure_398+ jb .Lasm_Call.assert_predicate_failure_283cmp r8, r11ja .Lasm_Call.ssa_block_1mov r11, QWORD PTR [rbp - 48]@@ -6352,18 +6348,18 @@ asm_handler_Call:test r8d, r8dcmovnz r8, r11test r8, r8- jz .Lasm_Call.assert_predicate_failure_425+ jz .Lasm_Call.assert_predicate_failure_310mov QWORD PTR [rax + 32], r8mov QWORD PTR [rax + 40], r8mov QWORD PTR [rax + 48], 0test BYTE PTR [rcx + 15], 8- jz .Lasm_Call.ssa_block_16+ jz .Lasm_Call.ssa_block_27mov r8d, DWORD PTR [rcx + 76]lea r11, [r15 + r8 * 8]test r8d, r8dcmovnz r8, r11mov QWORD PTR [rax + 48], r8-.Lasm_Call.ssa_block_16:+.Lasm_Call.ssa_block_27:mov QWORD PTR [rax + 80], r9mov QWORD PTR [rax + 88], rdxmovabs rdx, 9221964661971222528@@ -6410,34 +6406,34 @@ asm_handler_Call:mov DWORD PTR [rax + 112], r8dmovzx edx, BYTE PTR [r14 + r13 + 6]cmp rsi, rdx- jb .Lasm_Call.assert_predicate_failure_285- lea r9, [rbx]- lea r10, [r14 + r13 + 7]+ jb .Lasm_Call.assert_predicate_failure_397+ lea r9, [r14 + r13 + 7]lea r8, [rax + 136]+ lea r10, [rbx]xor rcx, rcx-.Lasm_Call.ssa_block_19:+.Lasm_Call.ssa_block_30:cmp rcx, rdx- jae .Lasm_Call.ssa_block_18- movzx r11d, BYTE PTR [r10 + rcx]- mov r11, QWORD PTR [r9 + r11 * 8]+ jae .Lasm_Call.ssa_block_29+ movzx r11d, BYTE PTR [r9 + rcx]+ mov r11, QWORD PTR [r10 + r11 * 8]mov QWORD PTR [r8 + rdi * 8], r11lea rcx, [rcx + 1]lea rdi, [rdi + 1]- jmp .Lasm_Call.ssa_block_19-.Lasm_Call.ssa_block_18:+ jmp .Lasm_Call.ssa_block_30+.Lasm_Call.ssa_block_29:movabs rcx, 9222809086901354496add rsi, rdisub rsi, rdx-.Lasm_Call.ssa_block_22:+.Lasm_Call.ssa_block_33:cmp rdi, rsi- jae .Lasm_Call.ssa_block_21+ jae .Lasm_Call.ssa_block_32mov QWORD PTR [r8 + rdi * 8], rcxlea rdi, [rdi + 1]- jmp .Lasm_Call.ssa_block_22-.Lasm_Call.ssa_block_21:+ jmp .Lasm_Call.ssa_block_33+.Lasm_Call.ssa_block_32:mov rcx, QWORD PTR [rax + 88]test rcx, rcx- jz .Lasm_Call.assert_predicate_failure_309+ jz .Lasm_Call.assert_predicate_failure_420mov r14, QWORD PTR [rcx + 40]test r14, r14jz .Lasm_Call.assert_failure_10@@ -6447,147 +6443,9 @@ asm_handler_Call:mov r13d, 0movzx eax, BYTE PTR [r14 + r13]jmp [r12 + rax * 8]-.Lasm_Call.ssa_block_3:- test eax, 2- jz .Lasm_Call.ssa_block_1- movzx esi, BYTE PTR [r14 + r13 + 6]- mov rax, QWORD PTR [rbp - 48]- mov rdi, QWORD PTR [rax + 24]- mov rax, QWORD PTR [rax + 16]- test rax, rax- jz .Lasm_Call.assert_failure_11- test rdi, rdi- jz .Lasm_Call.assert_failure_12- mov rdx, rsi- shl rdx, 3- lea rdx, [rdx + 136]- add rdx, rax- cmp rdx, rax- jb .Lasm_Call.assert_predicate_failure_36- cmp rdx, rdi- ja .Lasm_Call.ssa_block_1- mov rdi, QWORD PTR [rbp - 48]- mov r8, QWORD PTR [rdi + 40]- mov rdi, r8- add rdi, 32768- cmp rdi, r8- jb .Lasm_Call.assert_predicate_failure_44- cmp rdi, rbp- ja .Lasm_Call.ssa_block_1- mov rdi, QWORD PTR [rbp - 48]- mov QWORD PTR [rdi + 16], rdx- mov DWORD PTR [rax + 116], esi- mov DWORD PTR [rax + 120], esi- mov DWORD PTR [rax + 104], esi- mov edx, DWORD PTR [rcx + 20]- test rdx, rdx- jz .Lasm_Call.assert_failure_13- lea rdx, [r15 + rdx * 8]- mov edx, DWORD PTR [rdx + 12]- test rdx, rdx- jz .Lasm_Call.assert_failure_14- lea rdx, [r15 + rdx * 8]- mov QWORD PTR [rax], rcx- mov QWORD PTR [rax + 8], rdx- mov rdx, QWORD PTR [rbx - 104]- mov rdi, QWORD PTR [rbx - 96]- test rdx, rdx- jz .Lasm_Call.assert_predicate_failure_69- test rdi, rdi- jz .Lasm_Call.assert_predicate_failure_71- mov QWORD PTR [rax + 32], rdx- mov QWORD PTR [rax + 40], rdi- mov rdx, QWORD PTR [rbx - 88]- mov QWORD PTR [rax + 48], rdx- movzx edx, BYTE PTR [r14 + r13 + 5]- mov rdx, QWORD PTR [rbx + rdx * 8]- mov QWORD PTR [rax + 80], rdx- mov QWORD PTR [rax + 16], 0- mov QWORD PTR [rax + 88], 0- mov DWORD PTR [rax + 64], 0- mov rdi, QWORD PTR [rbp - 48]- mov rdx, QWORD PTR [rdi + 32]- test rdx, rdx- jz .Lasm_Call.assert_failure_15- mov QWORD PTR [rax + 56], rdx- lea rdx, [rdx + 1]- mov QWORD PTR [rdi + 32], rdx- mov DWORD PTR [rax + 68], 0- mov DWORD PTR [rax + 72], 4294967295- mov BYTE PTR [rax + 76], 0- mov BYTE PTR [rax + 77], 0- mov BYTE PTR [rax + 78], 0- mov BYTE PTR [rax + 79], 0- mov BYTE PTR [rax + 124], 0- mov BYTE PTR [rax + 125], 0- mov BYTE PTR [rax + 126], 0- movabs rdx, 9222809086901354496- mov QWORD PTR [rax + 128], rdx- movzx edi, BYTE PTR [r14 + r13 + 6]- mov rdx, 7- add rdx, rdi- movzx r8d, BYTE PTR [r14 + r13 + 3]- mov edi, r13d- add rdx, rdi- mov DWORD PTR [rbx - 72], edi- lea r11, [rbx - 136]- mov QWORD PTR [rax + 96], r11- mov DWORD PTR [rax + 108], edx- mov DWORD PTR [rax + 112], r8d- lea rdi, [rbx]- lea r8, [r14 + r13 + 7]- lea r9, [rax + 136]- xor rdx, rdx-.Lasm_Call.ssa_block_25:- cmp rdx, rsi- jae .Lasm_Call.ssa_block_24- movzx r10d, BYTE PTR [r8 + rdx]- mov r10, QWORD PTR [rdi + r10 * 8]- mov QWORD PTR [r9 + rdx * 8], r10- lea rdx, [rdx + 1]- jmp .Lasm_Call.ssa_block_25-.Lasm_Call.ssa_block_24:- mov rdx, QWORD PTR [rbp - 48]- mov QWORD PTR [rdx], rax- lea rbx, [rax + 136]- mov eax, DWORD PTR [rcx + 92]- mov rcx, QWORD PTR [rdx + 80]- test rcx, rcx- jz .Lasm_Call.assert_failure_16- and eax, 65535- shl rax, 4- add rax, rcx- mov ecx, DWORD PTR [rax + 8]- cmp rcx, 1- jae .Lasm_Call.assert_predicate_failure_345- mov rdx, QWORD PTR [rax]- test rdx, rdx- jz .Lasm_Call.assert_failure_17- mov r11, rdx- mov rdi, QWORD PTR [rbp - 48]- call r11- mov rcx, rdx- and rcx, 255- cmp rcx, 2- jae .Lasm_Call.assert_predicate_failure_352- test rcx, rcx- jnz .Lasm_Call.ssa_block_4- mov rcx, QWORD PTR [rbx - 40]- test rcx, rcx- jz .Lasm_Call.assert_predicate_failure_358- mov rdx, QWORD PTR [rbp - 48]- mov QWORD PTR [rdx], rcx- lea r11, [rbx - 136]- mov QWORD PTR [rdx + 16], r11- lea rbx, [rcx + 136]- movzx r11d, BYTE PTR [r14 + r13 + 3]- mov QWORD PTR [rbx + r11 * 8], rax- movzx eax, BYTE PTR [r14 + r13 + 6]- mov rcx, 7- add rcx, rax- add r13d, ecx- movzx eax, BYTE PTR [r14 + r13]- jmp [r12 + rax * 8]+.Lasm_Call.ssa_block_19:+ cmp si, 65529+ je .Lasm_Call.ssa_block_15.Lasm_Call.ssa_block_2:lea rcx, [r14 + r13]mov r11, rsp@@ -6601,40 +6459,40 @@ asm_handler_Call:mov rdx, QWORD PTR [rdx + 40]add rdx, 32768cmp rax, rdx- jae .Lasm_Call.values_allocate_19+ jae .Lasm_Call.values_allocate_12mov eax, 1- jmp .Lasm_Call.values_call_done_18-.Lasm_Call.values_allocate_19:-.Lasm_Call.values_probe_20:+ jmp .Lasm_Call.values_call_done_11+.Lasm_Call.values_allocate_12:+.Lasm_Call.values_probe_13:lea r10, [rsp - 4096]cmp r10, rax- jbe .Lasm_Call.values_allocated_21+ jbe .Lasm_Call.values_allocated_14mov rsp, r10mov QWORD PTR [rsp], 0- jmp .Lasm_Call.values_probe_20-.Lasm_Call.values_allocated_21:+ jmp .Lasm_Call.values_probe_13+.Lasm_Call.values_allocated_14:mov rsp, raxmov QWORD PTR [rsp], r11movzx r10d, BYTE PTR [rcx + 4]mov rax, QWORD PTR [rbx + r10 * 8]-.Lasm_Call.value_ready_22:+.Lasm_Call.value_ready_15:mov QWORD PTR [rsp + 24], raxmovzx r10d, BYTE PTR [rcx + 5]mov rax, QWORD PTR [rbx + r10 * 8]-.Lasm_Call.value_ready_23:+.Lasm_Call.value_ready_16:mov QWORD PTR [rsp + 32], raxmov r11d, 0movzx r10d, BYTE PTR [rcx + 6]-.Lasm_Call.array_value_next_24:+.Lasm_Call.array_value_next_17:cmp r11, r10- jae .Lasm_Call.array_values_end_26+ jae .Lasm_Call.array_values_end_19movzx edx, BYTE PTR [rcx + r11 + 7]mov rax, QWORD PTR [rbx + rdx * 8]-.Lasm_Call.array_value_ready_25:+.Lasm_Call.array_value_ready_18:mov QWORD PTR [rsp + r11 * 8 + 40], raxadd r11, 1- jmp .Lasm_Call.array_value_next_24-.Lasm_Call.array_values_end_26:+ jmp .Lasm_Call.array_value_next_17+.Lasm_Call.array_values_end_19:mov rdi, QWORD PTR [rbp - 48]mov esi, r13dlea rdx, [r14 + r13]@@ -6644,19 +6502,19 @@ asm_handler_Call:mov r10, QWORD PTR [r10]add r10, 136cmp r10, rbx- jne .Lasm_Call.values_restore_stack_27+ jne .Lasm_Call.values_restore_stack_20test rax, rax- jne .Lasm_Call.values_exceptional_outputs_28+ jne .Lasm_Call.values_exceptional_outputs_21lea rcx, [r14 + r13]movzx r10d, BYTE PTR [rcx + 3]mov r11, QWORD PTR [rsp + 16]mov QWORD PTR [rbx + r10 * 8], r11-.Lasm_Call.skip_output_value_29:- jmp .Lasm_Call.values_restore_stack_27-.Lasm_Call.values_exceptional_outputs_28:-.Lasm_Call.values_restore_stack_27:+.Lasm_Call.skip_output_value_22:+ jmp .Lasm_Call.values_restore_stack_20+.Lasm_Call.values_exceptional_outputs_21:+.Lasm_Call.values_restore_stack_20:mov rsp, QWORD PTR [rsp]-.Lasm_Call.values_call_done_18:+.Lasm_Call.values_call_done_11:test eax, eaxjnz .Lasm_Call.ssa_block_1mov rax, QWORD PTR [rbp - 48]@@ -6669,10 +6527,151 @@ asm_handler_Call:jz .Lasm_Call.assert_predicate_failure_17mov r14, QWORD PTR [rax + 40]test r14, r14- jz .Lasm_Call.assert_failure_30+ jz .Lasm_Call.assert_failure_23mov r13d, 0movzx eax, BYTE PTR [r14 + r13]jmp [r12 + rax * 8]+.Lasm_Call.ssa_block_3:+ test eax, 2+ jz .Lasm_Call.ssa_block_1+ mov edi, DWORD PTR [rcx + 92]+ movzx edx, BYTE PTR [r14 + r13 + 6]+ mov rax, QWORD PTR [rbp - 48]+ mov r8, QWORD PTR [rax + 24]+ mov rax, QWORD PTR [rax + 16]+ test rax, rax+ jz .Lasm_Call.assert_failure_24+ test r8, r8+ jz .Lasm_Call.assert_failure_25+ mov rsi, rdx+ shl rsi, 3+ lea rsi, [rsi + 136]+ add rsi, rax+ cmp rsi, rax+ jb .Lasm_Call.assert_predicate_failure_41+ cmp rsi, r8+ ja .Lasm_Call.ssa_block_1+ mov r8, QWORD PTR [rbp - 48]+ mov r9, QWORD PTR [r8 + 40]+ mov r8, r9+ add r8, 32768+ cmp r8, r9+ jb .Lasm_Call.assert_predicate_failure_91+ cmp r8, rbp+ ja .Lasm_Call.ssa_block_1+ mov r8, QWORD PTR [rbp - 48]+ mov QWORD PTR [r8 + 16], rsi+ mov DWORD PTR [rax + 116], edx+ mov DWORD PTR [rax + 120], edx+ mov DWORD PTR [rax + 104], edx+ mov esi, DWORD PTR [rcx + 20]+ test rsi, rsi+ jz .Lasm_Call.assert_failure_26+ lea rsi, [r15 + rsi * 8]+ mov esi, DWORD PTR [rsi + 12]+ test rsi, rsi+ jz .Lasm_Call.assert_failure_27+ lea rsi, [r15 + rsi * 8]+ mov QWORD PTR [rax], rcx+ mov QWORD PTR [rax + 8], rsi+ mov rcx, QWORD PTR [rbx - 104]+ mov rsi, QWORD PTR [rbx - 96]+ test rcx, rcx+ jz .Lasm_Call.assert_predicate_failure_115+ test rsi, rsi+ jz .Lasm_Call.assert_predicate_failure_117+ mov QWORD PTR [rax + 32], rcx+ mov QWORD PTR [rax + 40], rsi+ mov rcx, QWORD PTR [rbx - 88]+ mov QWORD PTR [rax + 48], rcx+ movzx ecx, BYTE PTR [r14 + r13 + 5]+ mov rcx, QWORD PTR [rbx + rcx * 8]+ mov QWORD PTR [rax + 80], rcx+ mov QWORD PTR [rax + 16], 0+ mov QWORD PTR [rax + 88], 0+ mov DWORD PTR [rax + 64], 0+ mov rsi, QWORD PTR [rbp - 48]+ mov rcx, QWORD PTR [rsi + 32]+ test rcx, rcx+ jz .Lasm_Call.assert_failure_28+ mov QWORD PTR [rax + 56], rcx+ lea rcx, [rcx + 1]+ mov QWORD PTR [rsi + 32], rcx+ mov DWORD PTR [rax + 68], 0+ mov DWORD PTR [rax + 72], 4294967295+ mov BYTE PTR [rax + 76], 0+ mov BYTE PTR [rax + 77], 0+ mov BYTE PTR [rax + 78], 0+ mov BYTE PTR [rax + 79], 0+ mov BYTE PTR [rax + 124], 0+ mov BYTE PTR [rax + 125], 0+ mov BYTE PTR [rax + 126], 0+ movabs rcx, 9222809086901354496+ mov QWORD PTR [rax + 128], rcx+ movzx esi, BYTE PTR [r14 + r13 + 6]+ mov rcx, 7+ add rcx, rsi+ movzx r8d, BYTE PTR [r14 + r13 + 3]+ mov esi, r13d+ add rcx, rsi+ mov DWORD PTR [rbx - 72], esi+ lea r11, [rbx - 136]+ mov QWORD PTR [rax + 96], r11+ mov DWORD PTR [rax + 108], ecx+ mov DWORD PTR [rax + 112], r8d+ lea rsi, [r14 + r13 + 7]+ lea r8, [rbx]+ lea r9, [rax + 136]+ xor rcx, rcx+.Lasm_Call.ssa_block_12:+ cmp rcx, rdx+ jae .Lasm_Call.ssa_block_11+ movzx r10d, BYTE PTR [rsi + rcx]+ mov r10, QWORD PTR [r8 + r10 * 8]+ mov QWORD PTR [r9 + rcx * 8], r10+ lea rcx, [rcx + 1]+ jmp .Lasm_Call.ssa_block_12+.Lasm_Call.ssa_block_11:+ mov rcx, QWORD PTR [rbp - 48]+ mov QWORD PTR [rcx], rax+ lea rbx, [rax + 136]+ mov rax, QWORD PTR [rcx + 80]+ test rax, rax+ jz .Lasm_Call.assert_failure_29+ and edi, 65535+ shl rdi, 4+ add rdi, rax+ mov eax, DWORD PTR [rdi + 8]+ cmp rax, 1+ jae .Lasm_Call.assert_predicate_failure_208+ mov rdx, QWORD PTR [rdi]+ test rdx, rdx+ jz .Lasm_Call.assert_failure_30+ mov r11, rdx+ mov rdi, QWORD PTR [rbp - 48]+ call r11+ mov rcx, rdx+ and rcx, 255+ cmp rcx, 2+ jae .Lasm_Call.assert_predicate_failure_215+ test rcx, rcx+ jnz .Lasm_Call.ssa_block_6+ mov rcx, QWORD PTR [rbx - 40]+ test rcx, rcx+ jz .Lasm_Call.assert_predicate_failure_221+ mov rdx, QWORD PTR [rbp - 48]+ mov QWORD PTR [rdx], rcx+ lea r11, [rbx - 136]+ mov QWORD PTR [rdx + 16], r11+ lea rbx, [rcx + 136]+ movzx r11d, BYTE PTR [r14 + r13 + 3]+ mov QWORD PTR [rbx + r11 * 8], rax+ movzx eax, BYTE PTR [r14 + r13 + 6]+ mov rcx, 7+ add rcx, rax+ add r13d, ecx+ movzx eax, BYTE PTR [r14 + r13]+ jmp [r12 + rax * 8]asm_handler_Call_hot_end:.p2align 6@@ -15328,22 +15327,22 @@ asm_handler_SetGlobal_cold:asm_handler_SetGlobal_cold_end:asm_handler_Call_cold:# Cold paths for Call-.Lasm_Call.ssa_block_4:+.Lasm_Call.ssa_block_6:mov rdx, raxmov rcx, QWORD PTR [rbp - 48]mov rdi, rcxmov rsi, rdxcall CSYM(asm_helper_handle_raw_native_exception)test eax, eax- js .Lasm_Call.ssa_block_5+ js .Lasm_Call.ssa_block_7mov rax, QWORD PTR [rbp - 48]mov rbx, QWORD PTR [rax]add rbx, 136test rbx, rbx- jz .Lasm_Call.assert_predicate_failure_151+ jz .Lasm_Call.assert_predicate_failure_73mov rax, QWORD PTR [rbx - 48]test rax, rax- jz .Lasm_Call.assert_predicate_failure_157+ jz .Lasm_Call.assert_predicate_failure_79mov r14, QWORD PTR [rax + 40]test r14, r14jz .Lasm_Call.assert_failure_31@@ -15439,7 +15438,7 @@ asm_handler_Call_cold:mov r13d, eaxmovzx eax, BYTE PTR [r14 + r13]jmp [r12 + rax * 8]-.Lasm_Call.ssa_block_5:+.Lasm_Call.ssa_block_7:jmp .Lexitasm_handler_Call_cold_end:.p2align 4@@ -20969,69 +20968,69 @@ asm_assertion_failure_traps:ud2.Lasm_Call.assert_failure_3:ud2-.Lasm_Call.assert_predicate_failure_377:+.Lasm_Call.assert_predicate_failure_263:ud2-.Lasm_Call.assert_predicate_failure_383:+.Lasm_Call.assert_predicate_failure_269:ud2.Lasm_Call.assert_failure_4:ud2.Lasm_Call.assert_failure_5:ud2-.Lasm_Call.assert_predicate_failure_398:+.Lasm_Call.assert_predicate_failure_283:ud2.Lasm_Call.assert_failure_6:ud2.Lasm_Call.assert_failure_7:ud2-.Lasm_Call.assert_predicate_failure_425:+.Lasm_Call.assert_predicate_failure_310:ud2.Lasm_Call.assert_failure_8:ud2.Lasm_Call.assert_failure_9:ud2-.Lasm_Call.assert_predicate_failure_285:+.Lasm_Call.assert_predicate_failure_397:ud2-.Lasm_Call.assert_predicate_failure_309:+.Lasm_Call.assert_predicate_failure_420:ud2.Lasm_Call.assert_failure_10:ud2-.Lasm_Call.assert_failure_11:+.Lasm_Call.assert_predicate_failure_11:ud2-.Lasm_Call.assert_failure_12:+.Lasm_Call.assert_predicate_failure_17:ud2-.Lasm_Call.assert_predicate_failure_36:+.Lasm_Call.assert_failure_23:ud2-.Lasm_Call.assert_predicate_failure_44:+.Lasm_Call.assert_failure_24:ud2-.Lasm_Call.assert_failure_13:+.Lasm_Call.assert_failure_25:ud2-.Lasm_Call.assert_failure_14:+.Lasm_Call.assert_predicate_failure_41:ud2-.Lasm_Call.assert_predicate_failure_69:+.Lasm_Call.assert_predicate_failure_91:ud2-.Lasm_Call.assert_predicate_failure_71:+.Lasm_Call.assert_failure_26:ud2-.Lasm_Call.assert_failure_15:+.Lasm_Call.assert_failure_27:ud2-.Lasm_Call.assert_failure_16:+.Lasm_Call.assert_predicate_failure_115:ud2-.Lasm_Call.assert_predicate_failure_345:+.Lasm_Call.assert_predicate_failure_117:ud2-.Lasm_Call.assert_failure_17:+.Lasm_Call.assert_failure_28:ud2-.Lasm_Call.assert_predicate_failure_352:+.Lasm_Call.assert_failure_29:ud2-.Lasm_Call.assert_predicate_failure_358:+.Lasm_Call.assert_predicate_failure_208:ud2-.Lasm_Call.assert_predicate_failure_11:+.Lasm_Call.assert_failure_30:ud2-.Lasm_Call.assert_predicate_failure_17:+.Lasm_Call.assert_predicate_failure_215:ud2-.Lasm_Call.assert_failure_30:+.Lasm_Call.assert_predicate_failure_221:ud2-.Lasm_Call.assert_predicate_failure_151:+.Lasm_Call.assert_predicate_failure_73:ud2-.Lasm_Call.assert_predicate_failure_157:+.Lasm_Call.assert_predicate_failure_79:ud2.Lasm_Call.assert_failure_31:ud2diff --git a/Libraries/LibJS/Flap/tests/interpreter-layout.conf b/Libraries/LibJS/Flap/tests/interpreter-layout.confindex 15c03b925d0..212a813a5b9 100644--- a/Libraries/LibJS/Flap/tests/interpreter-layout.conf+++ b/Libraries/LibJS/Flap/tests/interpreter-layout.conf@@ -313,6 +313,18 @@ const EXECUTABLE_DISPATCH_TABLE_INDEX = 56field Executable.dispatch_table_index u8 EXECUTABLE_DISPATCH_TABLE_INDEX nullable scalarconst EXECUTABLE_PROPERTY_LOOKUP_CACHES_DATA = 152field Executable.property_lookup_caches PropertyLookupCaches EXECUTABLE_PROPERTY_LOOKUP_CACHES_DATA nonnull scalar+const EXECUTABLE_CALL_CACHES = 224+field Executable.call_caches u64 EXECUTABLE_CALL_CACHES nullable scalar+const EXECUTABLE_CALL_METADATA = 232+field Executable.call_metadata u64 EXECUTABLE_CALL_METADATA nullable scalar+const CALL_CACHE_CALLEE = 0+const CALL_CACHE_TARGET = 8+const CALL_CACHE_SIZE = 16+field CallCache.callee u64 CALL_CACHE_CALLEE nullable scalar+field CallCache.target u64 CALL_CACHE_TARGET nullable scalar+const CALL_CACHE_TARGET_TAG_MASK = 7+const CALL_CACHE_TARGET_NATIVE_FUNCTION = 1+const CALL_CACHE_TARGET_INDEX_SHIFT = 3const EXECUTABLE_GLOBAL_VARIABLE_CACHES_DATA = 176field Executable.global_variable_caches GlobalVariableCaches EXECUTABLE_GLOBAL_VARIABLE_CACHES_DATA nonnull scalarconst EXECUTABLE_ENVIRONMENT_COORDINATE_CACHES_DATA = 200diff --git a/Libraries/LibJS/Interpreter/interpreter.flap b/Libraries/LibJS/Interpreter/interpreter.flapindex 3e34761d3aa..e0958a2aefa 100644--- a/Libraries/LibJS/Interpreter/interpreter.flap+++ b/Libraries/LibJS/Interpreter/interpreter.flap@@ -1123,14 +1123,16 @@ inline fn record_call_value_feedback(slot: CallFeedbackIndex, value: Value) @pro# Call feedback only does work when the callee differs from the first one# recorded at the site.-inline fn record_call_target(slot: CallFeedbackIndex, function: Object) @profiling {+# 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 {- let mut flags: i32 = alias(call_feedback.flags);if call_feedback.target == 0 {call_feedback.target = function_pointer;} else {@@ -1159,6 +1161,7 @@ inline fn record_call_target(slot: CallFeedbackIndex, function: Object) @profili}call_feedback.flags = truncate_u8(flags);}+ site_flags = flags;}inline fn record_keyed_feedback(slot: KeyedFeedbackIndex, bits: u32) @profiling {@@ -3964,29 +3967,31 @@ handler SetGlobal(dispatch_next;}-handler Call(- call_feedback: CallFeedbackIndex,+# 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,- callee: in Operand,this_value: in Operand,argument_count: u8,- arguments: Operand[]+ argument_operand_indices: Sequence<u8>,+ slow: Label,+ else resolve: Label) {- let slow = || @cold {- call_slow_path(asm_slow_path_call);- };-- guard let Value<Object>(function) = load(callee) else slow;- let flags = function.flags;- guard flags has OBJECT_FLAG_IS_FUNCTION else slow;- record_call_target(call_feedback, function);- 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;let mut receiver: Value = Value<Empty>;if metadata has SHARED_FUNCTION_INSTANCE_DATA_ASM_CALL_METADATA_USES_THIS {receiver = load(this_value);@@ -3994,11 +3999,16 @@ handler Call(if receiver is Value<Nullish> {receiver = alias(box_object(function.shape.realm.global_environment.global_this_value));} else {- guard receiver is Value<Object> else invoke_interp_inline;+ guard receiver is Value<Object> else resolve;}}}- let formal_count: u32 = max(u32(metadata), u32(load(argument_count)));+ # 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;@@ -4023,7 +4033,7 @@ handler Call(let frame_values = frame.slots;frame.slot_count = frame_slot_count;frame.argument_count = formal_count;- frame.passed_argument_count = u32(load(argument_count));+ frame.passed_argument_count = call_argument_count(argument_count);let realm = function.shape.realm;frame.function = function;frame.realm = realm;@@ -4068,11 +4078,10 @@ handler Call(exec_ctx.program_counter = current_pc;frame.caller_return_pc = return_pc;frame.caller_dst_raw = return_destination;- let actual_argument_count = u32(load(argument_count));+ 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 argument_operand_indices = &arguments;let mut argument_index: u32 = 0;while argument_index < actual_argument_count {frame_values[write_index] = caller_values[u32(argument_operand_indices[argument_index])];@@ -4098,6 +4107,217 @@ handler Call(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;+ let realm = function.shape.realm;+ native_frame.function = function;+ native_frame.realm = realm;+ let lexical_environment = exec_ctx.lexical_environment;+ let variable_environment = exec_ctx.variable_environment;+ assert(lexical_environment != 0);+ assert(variable_environment != 0);+ native_frame.lexical_environment = lexical_environment;+ native_frame.variable_environment = variable_environment;+ let private_environment = exec_ctx.private_environment;+ native_frame.private_environment = private_environment;+ let receiver = load(this_value);+ native_frame.this_value = receiver;+ native_frame.script_or_module = 0;+ # Raw native frames deliberately have no executable.+ native_frame.executable = null;+ native_frame.program_counter = 0;+ let native_frame_id_vm = current_vm();+ let native_frame_id = native_frame_id_vm.interpreter_stack_next_frame_id;+ native_frame.frame_id = native_frame_id;+ native_frame_id_vm.interpreter_stack_next_frame_id = native_frame_id + 1;+ native_frame.skip_when_determining_incumbent_counter = 0;+ native_frame.yield_continuation = EXECUTION_CONTEXT_NO_YIELD_CONTINUATION;+ native_frame.yield_is_await = false;+ native_frame.yield_value_is_iterator_result = false;+ 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;+ 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.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,+ else resolve: 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) else resolve;+ }+}++# 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) else invoke_interp_inline;++ 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;+ 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) else invoke_interp_inline;let invoke_interp_inline = || {# Let the interpreter resolve the cases that cannot use the direct# frame construction above, then enter the resolved callee.@@ -4116,118 +4336,12 @@ handler Call(# 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 actual_argument_count = u32(load(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;- let realm = function.shape.realm;- native_frame.function = function;- native_frame.realm = realm;- let lexical_environment = exec_ctx.lexical_environment;- let variable_environment = exec_ctx.variable_environment;- assert(lexical_environment != 0);- assert(variable_environment != 0);- native_frame.lexical_environment = lexical_environment;- native_frame.variable_environment = variable_environment;- let private_environment = exec_ctx.private_environment;- native_frame.private_environment = private_environment;- let receiver = load(this_value);- native_frame.this_value = receiver;- native_frame.script_or_module = 0;- # Raw native frames deliberately have no executable.- native_frame.executable = null;- native_frame.program_counter = 0;- let native_frame_id_vm = current_vm();- let native_frame_id = native_frame_id_vm.interpreter_stack_next_frame_id;- native_frame.frame_id = native_frame_id;- native_frame_id_vm.interpreter_stack_next_frame_id = native_frame_id + 1;- native_frame.skip_when_determining_incumbent_counter = 0;- native_frame.yield_continuation = EXECUTION_CONTEXT_NO_YIELD_CONTINUATION;- native_frame.yield_is_await = false;- native_frame.yield_value_is_iterator_result = false;- 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_argument_operand_indices = &arguments;- 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(native_argument_operand_indices[argument_index])];- argument_index = argument_index + 1;- }- let native_running_vm = current_vm();- native_running_vm.running_execution_context = native_frame;- exec_ctx = native_frame;- values = exec_ctx.slots;let raw_native_function: RawNativeFunction = alias(function);let native_function_index = raw_native_function.native_function_index;- 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.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);+ 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;};}diff --git a/Libraries/LibJS/Rust/generate/layout_table.rs b/Libraries/LibJS/Rust/generate/layout_table.rsindex 1d1378ab8e6..b0cd10473a4 100644--- a/Libraries/LibJS/Rust/generate/layout_table.rs+++ b/Libraries/LibJS/Rust/generate/layout_table.rs@@ -441,6 +441,17 @@ pub fn generate(configuration: &LayoutConfiguration) -> LayoutWriter {w.line("field Executable.global_variable_caches GlobalVariableCaches EXECUTABLE_GLOBAL_VARIABLE_CACHES_DATA nonnull scalar");offset!(w, "EXECUTABLE_ENVIRONMENT_COORDINATE_CACHES_DATA", ExecutableHead, environment_coordinate_caches.data);w.line("field Executable.environment_coordinate_caches Sequence<EnvironmentCoordinateEntry> EXECUTABLE_ENVIRONMENT_COORDINATE_CACHES_DATA nullable scalar");+ field!(w, "EXECUTABLE_CALL_CACHES", "Executable.call_caches", "u64", ExecutableHead, call_caches, 8, "nullable", "scalar");+ field!(w, "EXECUTABLE_CALL_METADATA", "Executable.call_metadata", "u64", ExecutableHead, call_metadata, 8, "nullable", "scalar");+ w.section("CallCache layout");+ offset!(w, "CALL_CACHE_CALLEE", CallCache, callee);+ offset!(w, "CALL_CACHE_TARGET", CallCache, target);+ size!(w, "CALL_CACHE_SIZE", CallCache);+ w.line("field CallCache.callee u64 CALL_CACHE_CALLEE nullable scalar");+ w.line("field CallCache.target u64 CALL_CACHE_TARGET nullable scalar");+ w.constant("CALL_CACHE_TARGET_TAG_MASK", CALL_CACHE_TARGET_TAG_MASK);+ w.constant("CALL_CACHE_TARGET_NATIVE_FUNCTION", CALL_CACHE_TARGET_NATIVE_FUNCTION);+ w.constant("CALL_CACHE_TARGET_INDEX_SHIFT", CALL_CACHE_TARGET_INDEX_SHIFT);offset!(w, "OBJECT_PROPERTY_ITERATOR_CACHE_DATA_PROPERTY_VALUES_DATA", ObjectPropertyIteratorCacheData, property_values.data);offset!(w, "OBJECT_PROPERTY_ITERATOR_CACHE_DATA_PROPERTY_VALUES_SIZE", ObjectPropertyIteratorCacheData, property_values.size);w.line("field ObjectPropertyIteratorCacheData.property_values Sequence<Value> OBJECT_PROPERTY_ITERATOR_CACHE_DATA_PROPERTY_VALUES_DATA nullable scalar");diff --git a/Libraries/LibJS/Rust/src/bytecode/executable.rs b/Libraries/LibJS/Rust/src/bytecode/executable.rsindex 332b043c036..a891ac50d58 100644--- a/Libraries/LibJS/Rust/src/bytecode/executable.rs+++ b/Libraries/LibJS/Rust/src/bytecode/executable.rs@@ -5,6 +5,7 @@*/use core::cell::{Cell, OnceCell, RefCell};+use core::ptr::NonNull;use std::collections::HashMap;use std::io::Write;use std::rc::Rc;@@ -33,7 +34,9 @@ use crate::jit::InterpreterTier;use crate::jit::code::ExecutableJitState;use crate::layout::buffer::{BlockSlice, InterpreterBuffer, ThinSlice};use crate::layout::cell::{CellHeader, CellHeaderTail, Gc};-use crate::layout::executable::ExecutableHead;+use crate::layout::executable::{+ CALL_CACHE_EMPTY_CALLEE, CALL_CACHE_TARGET_EXECUTABLE, CALL_CACHE_TARGET_TAG_MASK, CallCache, ExecutableHead,+};use crate::layout::feedback::ExecutableFeedbackHead;use crate::layout::function_object::FunctionObject;use crate::layout::member::NullableMember;@@ -1355,7 +1358,7 @@ pub struct Executable {}// NB: Every function that was called has these bytes.-const _: () = assert!(size_of::<Executable>() == 184);+const _: () = assert!(size_of::<Executable>() == 200);define_cell!(Executable, Other, external_memory_size: external_memory_size);@@ -1372,7 +1375,7 @@ impl ExternalMemorySize for Executable {};let cache_data_size =self.head.property_lookup_caches.len().min(UNCACHED_SITE as usize) * size_of::<MonomorphicData>();- code_size + self.tables_memory_size() + cache_data_size+ code_size + self.tables_memory_size() + cache_data_size + size_of_val(self.call_caches())}}@@ -1390,6 +1393,29 @@ struct DebuggerBreakpointSite {const _: () = assert!(core::mem::offset_of!(Executable, head) == 0);+impl CallCache {+ /// Whether the callee or the executable of the entry died in this collection, or moves in it.+ fn has_dead_cell(&self, sweep: &Sweep<'_>) -> bool {+ let callee = self.callee.get();+ if callee == CALL_CACHE_EMPTY_CALLEE {+ return false;+ }+ if sweep.is_dead_or_moving(Value::from_bits(callee).as_cell()) {+ return true;+ }+ let target = self.target.get();+ if target & CALL_CACHE_TARGET_TAG_MASK != CALL_CACHE_TARGET_EXECUTABLE {+ return false;+ }+ let executable = NonNull::new(core::ptr::with_exposed_provenance_mut::<ExecutableHead>(+ target as usize,+ ))+ .expect("a linked call cache has an executable");+ // SAFETY: The entry was linked to a live executable, which stays intact until the sweep after it died.+ sweep.is_dead_or_moving(Executable::from_head(unsafe { Gc::from_non_null(executable) }))+ }+}+impl Executable {pub fn property_lookup_cache(&self, index: usize) -> &PropertyLookupCache {&self.head.property_lookup_caches[index]@@ -1463,6 +1489,11 @@ impl Executable {{cache.entry.clear_if_it_has_a_dead_cell(sweep);}+ for cache in self.call_caches() {+ if cache.has_dead_cell(sweep) {+ cache.clear();+ }+ }for cache in &self.object_shape_caches {if cache.shape.get().is_some_and(|shape| sweep.is_dead_or_moving(shape)) {cache.shape.set(None);@@ -1515,6 +1546,8 @@ impl Executable {global_variable_caches,// The interpreter only reads the caches, which slow paths update through their cells.environment_coordinate_caches,+ call_caches: Cell::new(core::ptr::null()),+ call_metadata: Cell::new(0),};let object_shape_caches = tables.slice((0..cache_counts.object_shape).map(|_| ObjectShapeCache::default()));Self {@@ -2000,6 +2033,17 @@ impl Executable {&caches[index as usize]}+ /// The call caches, which are empty until the executable gets its feedback.+ pub fn call_caches(&self) -> &[CallCache] {+ self.feedback().map_or(&[], ExecutableFeedback::call_caches)+ }++ fn clear_call_caches(&self) {+ for cache in self.call_caches() {+ cache.clear();+ }+ }+pub fn interpreter_tier(&self) -> InterpreterTier {self.interpreter_tier.get()}@@ -2011,6 +2055,9 @@ impl Executable {#[cfg(feature = "jit")]InterpreterTier::Profiling => {self.ensure_feedback();+ // NB: A call that hits its call cache records no call feedback, as the call that linked the entry did.+ // The calls that linked the entries in another tier did not.+ self.clear_call_caches();}#[cfg(feature = "jit")]_ => {@@ -2041,6 +2088,7 @@ impl Executable {unreachable!("the feedback is made once");}let feedback = self.feedback.get().expect("the feedback was just made");+ self.head.call_caches.set(feedback.call_caches().as_ptr());self.point_interpreter_at_feedback(feedback);feedback}diff --git a/Libraries/LibJS/Rust/src/bytecode/feedback.rs b/Libraries/LibJS/Rust/src/bytecode/feedback.rsindex f5e331376b6..c543fd9e772 100644--- a/Libraries/LibJS/Rust/src/bytecode/feedback.rs+++ b/Libraries/LibJS/Rust/src/bytecode/feedback.rs@@ -20,6 +20,7 @@ use crate::build_configuration::HEAP_REGION_OFFSET_MASK;use crate::gc::primitive_storage::{OwnedPrimitiveStorage, ZeroFillNewBytes};use crate::gc::sweep::Sweep;use crate::layout::cell::{CellHeader, Gc};+use crate::layout::executable::CallCache;pub use crate::layout::feedback::*;use crate::layout::object::Object;use crate::runtime::ecmascript_function_object::as_ecmascript_function_object;@@ -73,9 +74,12 @@ pub struct ExecutableFeedback {/// The value buckets of the sites of the property lookup caches, the last one first, then the other value buckets,/// once the profiling tier needs them. The interpreter finds both kinds from the start of the others.value_bucket_storage: OnceCell<OwnedPrimitiveStorage>,+ /// The call cache of each call site, which `ExecutableHead::call_caches` points at. They hold pointers that the+ /// interpreter trusts, so they are not in the primitive storage.+ call_caches: Box<[CallCache]>,}-const _: () = assert!(size_of::<ExecutableFeedback>() == 104);+const _: () = assert!(size_of::<ExecutableFeedback>() == 120);impl ExecutableFeedback {/// Where the call feedback starts in the storage.@@ -241,6 +245,7 @@ impl ExecutableFeedback {counts,property_lookup_cache_count,value_bucket_storage: OnceCell::new(),+ call_caches: (0..counts.call).map(|_| CallCache::default()).collect(),};feedback.storage = allocate_feedback_storage(feedback.cache_value_offset() + size_of::<Cell<u16>>() * property_lookup_cache_count as usize,@@ -252,6 +257,10 @@ impl ExecutableFeedback {feedback}+ pub fn call_caches(&self) -> &[CallCache] {+ &self.call_caches+ }+/// Makes the value buckets, if they are not there yet. The interpreter has to be pointed at them.pub fn ensure_value_buckets(&self) {if self.has_value_buckets() {diff --git a/Libraries/LibJS/Rust/src/layout/executable.rs b/Libraries/LibJS/Rust/src/layout/executable.rsindex acf1f5edf4c..85151762dce 100644--- a/Libraries/LibJS/Rust/src/layout/executable.rs+++ b/Libraries/LibJS/Rust/src/layout/executable.rs@@ -43,6 +43,51 @@ pub struct ExecutableHead {pub property_lookup_caches: BlockSlice<PropertyLookupCache>,pub global_variable_caches: BlockSlice<GlobalVariableCache>,pub environment_coordinate_caches: BlockSlice<Cell<EnvironmentCoordinate>>,+ /// The call caches, one for each call feedback index of the bytecode, or null. The executable gets them with+ /// its feedback, when it becomes warm.+ pub call_caches: Cell<*const CallCache>,+ /// The `asm_call_metadata` of the executable's function, which calls of it read from here. Its closure and construct+ /// counts can be behind those of the function, as calls do not read them.+ pub call_metadata: Cell<u64>,}-const _: () = assert!(size_of::<ExecutableHead>() == 96);+const _: () = assert!(size_of::<ExecutableHead>() == 112);++/// The bits of `CallCache::callee` while the cache is empty: a reserved tag that no value has.+pub const CALL_CACHE_EMPTY_CALLEE: u64 = super::feedback::value_feedback::EMPTY_VALUE_BUCKET;++/// The tag in the low bits of `CallCache::target`. An executable is 8-aligned, so its pointer has tag 0.+pub const CALL_CACHE_TARGET_TAG_MASK: u64 = 7;+pub const CALL_CACHE_TARGET_EXECUTABLE: u64 = 0;+/// The target is a native function table index, shifted left by `CALL_CACHE_TARGET_INDEX_SHIFT`.+pub const CALL_CACHE_TARGET_NATIVE_FUNCTION: u64 = 1;+pub const CALL_CACHE_TARGET_INDEX_SHIFT: u64 = 3;++/// The function that a call site called last. The interpreter links an entry only to a function that it can call+/// without the help of the runtime, so a call whose callee value has the bits of `callee` needs no checks.+///+/// Nothing in it is traced. The VM's sweep callback clears the entry when the callee or its executable dies or moves.+#[repr(C)]+pub struct CallCache {+ /// The bits of the callee value, or `CALL_CACHE_EMPTY_CALLEE`.+ pub callee: Cell<u64>,+ /// The callee's executable, or its tagged native function table index (see `CALL_CACHE_TARGET_TAG_MASK`).+ pub target: Cell<u64>,+}++const _: () = assert!(size_of::<CallCache>() == 16);++impl Default for CallCache {+ fn default() -> Self {+ Self {+ callee: Cell::new(CALL_CACHE_EMPTY_CALLEE),+ target: Cell::new(0),+ }+ }+}++impl CallCache {+ pub fn clear(&self) {+ self.callee.set(CALL_CACHE_EMPTY_CALLEE);+ }+}diff --git a/Libraries/LibJS/Rust/src/runtime/shared_function_instance_data.rs b/Libraries/LibJS/Rust/src/runtime/shared_function_instance_data.rsindex 13d68a590a4..e63256fe5bc 100644--- a/Libraries/LibJS/Rust/src/runtime/shared_function_instance_data.rs+++ b/Libraries/LibJS/Rust/src/runtime/shared_function_instance_data.rs@@ -384,6 +384,9 @@ impl SharedFunctionInstanceData {metadata |= asm_call_metadata::NEEDS_ENVIRONMENT_OR_THIS_VALUE_RESOLUTION;}self.asm_call_metadata.set(metadata);+ if let Some(executable) = self.executable() {+ executable.head.call_metadata.set(metadata);+ }}/// Creates the shared data of a function the frontend described, which is strict if `strict`.@@ -533,6 +536,7 @@ impl SharedFunctionInstanceData {self.executable.get().map(Executable::from_head)}+ /// Also gives `executable` the function's metadata, which calls of it read from the executable.pub fn set_executable(&self, executable: Option<Gc<Executable>>) {self.executable.set(executable.map(Executable::head));self.update_can_inline_call();diff --git a/Tests/LibJS/Runtime/call-site-caches.js b/Tests/LibJS/Runtime/call-site-caches.jsnew file mode 100644index 00000000000..f468d9042fa--- /dev/null+++ b/Tests/LibJS/Runtime/call-site-caches.js@@ -0,0 +1,144 @@+// A call site remembers the function it called last, with what a call of it needs. Calls through the same site have+// to behave as if nothing were remembered.++describe("call site caches", () => {+ test("closures of one function keep their own environments", () => {+ function makeCounter(start) {+ let count = start;+ return () => ++count;+ }+ function callIt(f) {+ return f();+ }+ const first = makeCounter(0);+ const second = makeCounter(100);+ for (let i = 1; i <= 5; ++i) {+ expect(callIt(first)).toBe(i);+ expect(callIt(second)).toBe(100 + i);+ }+ });++ test("one site that calls functions and native functions in turn", () => {+ function callIt(f, value) {+ return f(value);+ }+ const twice = value => value * 2;+ for (let i = 0; i < 5; ++i) {+ expect(callIt(Math.abs, -i)).toBe(i);+ expect(callIt(twice, i)).toBe(i * 2);+ expect(callIt(String, i)).toBe(String(i));+ }+ });++ test("a callee that died, and a function that came after it", () => {+ function callIt(f) {+ return f();+ }+ function make(value) {+ return function () {+ return value;+ };+ }+ for (let i = 0; i < 20; ++i) {+ expect(callIt(make(i))).toBe(i);+ gc();+ }+ });++ test("sloppy functions see the global object as this for every receiver", () => {+ function sloppy() {+ return this;+ }+ function strict() {+ "use strict";+ return this;+ }+ function callIt(f, receiver) {+ return f.call(receiver);+ }+ function callPlain(f) {+ return f();+ }+ for (let i = 0; i < 3; ++i) {+ expect(callPlain(sloppy)).toBe(globalThis);+ expect(callPlain(strict)).toBeUndefined();+ expect(typeof callIt(sloppy, 1)).toBe("object");+ expect(callIt(strict, 1)).toBe(1);+ }+ });++ test("a class constructor called without new throws every time", () => {+ class C {}+ function callIt(f) {+ return f();+ }+ function plain() {+ return 1;+ }+ expect(callIt(plain)).toBe(1);+ for (let i = 0; i < 3; ++i) {+ expect(() => callIt(C)).toThrowWithMessage(TypeError, "must be called with 'new'");+ expect(callIt(plain)).toBe(1);+ }+ });++ // NB: As in code-flushing.js, the body runs once and never in JIT code, which would hold the code of the callee.+ let flushedTestRan = false;+ test("a callee whose code was flushed compiles again", function run() {+ if (flushedTestRan) return;+ flushedTestRan = true;+ function add(a, b) {+ return a + b;+ }+ function callIt(a, b) {+ return add(a, b);+ }+ if (typeof jit !== "undefined") {+ jit.neverCompile(run);+ jit.neverCompile(callIt);+ }+ expect(callIt(1, 2)).toBe(3);+ flushCode();+ expect(isCodeFlushed(add)).toBeTrue();+ expect(callIt(3, 4)).toBe(7);+ expect(callIt(5, 6)).toBe(11);+ });+});++// NB: The callee is only reachable through a slot that the collector rewrites, so a collection that moves cells moves+// it, and the call site never runs in JIT code, which would keep the callee where it is.+function callThroughSite(f) {+ return f();+}+function makeReturning(value) {+ return function () {+ return value;+ };+}+// NB: The functions that may take the address of the callee that moved have other code, which a call through an entry+// that still had the old address would not run.+function makeDoubling(value) {+ return function () {+ return value * 2;+ };+}+if (typeof jit !== "undefined") jit.neverCompile(callThroughSite);+const movingCallee = { f: makeReturning("moved") };+for (let i = 0; i < 20; ++i) callThroughSite(movingCallee.f);+const movingCalleeAddress = addressOf(movingCallee.f);++runAfterMovingCollection(() => {+ test("a callee that moved, and a function that took its address", () => {+ expect(addressOf(movingCallee.f)).not.toBe(movingCalleeAddress);+ const functions = [];+ for (let i = 0; i < 2000; ++i) {+ const f = makeDoubling(i);+ functions.push(f);+ if (addressOf(f) === movingCalleeAddress) {+ expect(callThroughSite(f)).toBe(i * 2);+ break;+ }+ }+ expect(callThroughSite(movingCallee.f)).toBe("moved");+ });+});