From 12c503530eee3c061e2d043358c3ae063629ff44 Mon Sep 17 00:00:00 2001 From: Andriy Berestovskyy Date: Tue, 13 Jun 2023 07:59:54 +0000 Subject: [PATCH] [hotfix] RUN-668 Fix `QueryCache::push()` crash --- rs/config/src/embedders.rs | 2 +- .../tests/snapshots/instrumentation__app.snap | 75 +---------- .../snapshots/instrumentation__app2.snap | 81 ++--------- .../snapshots/instrumentation__basic.snap | 71 +--------- .../instrumentation__basic_import.snap | 73 +--------- .../instrumentation__basic_import_call.snap | 73 +--------- .../instrumentation__control_flow.snap | 101 +++----------- .../snapshots/instrumentation__element.snap | 84 ++---------- ...strumentation__export_mutable_globals.snap | 67 +--------- .../tests/snapshots/instrumentation__fac.snap | 71 +--------- .../snapshots/instrumentation__fizzbuzz.snap | 80 ++--------- .../instrumentation__memory_fill.snap | 71 +--------- .../instrumentation__memory_grow.snap | 71 +--------- .../instrumentation__nested_ifs.snap | 69 +--------- .../snapshots/instrumentation__recursive.snap | 71 +--------- .../instrumentation__simple_loop.snap | 71 +--------- .../snapshots/instrumentation__start.snap | 76 +---------- .../instrumentation__zero_cost_ops.snap | 71 +--------- .../src/execution/install_code/tests.rs | 4 +- .../src/query_handler/query_cache.rs | 33 ++++- .../src/query_handler/tests.rs | 126 +++++++++++++++++- .../execution_environment/src/lib.rs | 9 +- 22 files changed, 272 insertions(+), 1178 deletions(-) diff --git a/rs/config/src/embedders.rs b/rs/config/src/embedders.rs index d585bb0f748..ccca9fc4d16 100644 --- a/rs/config/src/embedders.rs +++ b/rs/config/src/embedders.rs @@ -75,7 +75,7 @@ impl FeatureFlags { Self { rate_limiting_of_debug_prints: FlagStatus::Enabled, write_barrier: FlagStatus::Disabled, - wasm_native_stable_memory: FlagStatus::Enabled, + wasm_native_stable_memory: FlagStatus::Disabled, } } } diff --git a/rs/embedders/tests/snapshots/instrumentation__app.snap b/rs/embedders/tests/snapshots/instrumentation__app.snap index 0a18791aefe..7eb09bf32f0 100644 --- a/rs/embedders/tests/snapshots/instrumentation__app.snap +++ b/rs/embedders/tests/snapshots/instrumentation__app.snap @@ -6,17 +6,10 @@ expression: out (type (;0;) (func (param i32) (result i32))) (type (;1;) (func)) (type (;2;) (func (param i32 i32 i32) (result i32))) - (type (;3;) (func (param i64 i64 i32) (result i64))) - (type (;4;) (func (param i32))) - (type (;5;) (func (param i64 i64 i64))) - (type (;6;) (func (param i64) (result i64))) - (type (;7;) (func (param i32 i32) (result i32 i32))) + (type (;3;) (func (param i64) (result i64))) (import "__" "out_of_instructions" (func $compute (;0;) (type 1))) (import "__" "update_available_memory" (func $double (;1;) (type 2))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 3))) - (import "__" "internal_trap" (func (;3;) (type 4))) - (import "__" "stable_read_first_access" (func (;4;) (type 5))) - (func (;5;) (type 0) (param i32) (result i32) + (func (;2;) (type 0) (param i32) (result i32) (local i32 i32) global.get 0 i64.const 18 @@ -104,7 +97,7 @@ expression: out i32.const 100 i32.div_s ) - (func (;6;) (type 0) (param i32) (result i32) + (func (;3;) (type 0) (param i32) (result i32) global.get 0 i64.const 3 i64.sub @@ -119,7 +112,7 @@ expression: out local.get 0 i32.mul ) - (func (;7;) (type 6) (param i64) (result i64) + (func (;4;) (type 3) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -141,66 +134,10 @@ expression: out end local.get 0 ) - (func (;8;) (type 7) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 2 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) (memory (;0;) 17) - (memory (;1;) i64 0 1048576) - (memory (;2;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) (export "memory" (memory 0)) - (export "compute" (func 5)) - (export "double" (func 6)) - (export "stable_memory" (memory 1)) - (export "stable_bytemap_memory" (memory 2)) + (export "compute" (func 2)) + (export "double" (func 3)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__app2.snap b/rs/embedders/tests/snapshots/instrumentation__app2.snap index 2c57c28b1b3..26298d4109c 100644 --- a/rs/embedders/tests/snapshots/instrumentation__app2.snap +++ b/rs/embedders/tests/snapshots/instrumentation__app2.snap @@ -6,16 +6,9 @@ expression: out (type (;0;) (func (param i64) (result i64))) (type (;1;) (func)) (type (;2;) (func (param i32 i32 i32) (result i32))) - (type (;3;) (func (param i64 i64 i32) (result i64))) - (type (;4;) (func (param i32))) - (type (;5;) (func (param i64 i64 i64))) - (type (;6;) (func (param i32 i32) (result i32 i32))) (import "__" "out_of_instructions" (func $compute (;0;) (type 1))) (import "__" "update_available_memory" (func $tenfold (;1;) (type 2))) - (import "__" "try_grow_stable_memory" (func $inc (;2;) (type 3))) - (import "__" "internal_trap" (func (;3;) (type 4))) - (import "__" "stable_read_first_access" (func (;4;) (type 5))) - (func (;5;) (type 0) (param i64) (result i64) + (func $inc (;2;) (type 0) (param i64) (result i64) (local i64) global.get 0 i64.const 6 @@ -30,7 +23,7 @@ expression: out local.get 0 i64.const 3 i64.mul - call 7 + call 4 local.set 1 block ;; label = @1 global.get 0 @@ -96,12 +89,12 @@ expression: out end end local.get 1 - call 6 + call 3 local.set 1 end local.get 1 ) - (func (;6;) (type 0) (param i64) (result i64) + (func (;3;) (type 0) (param i64) (result i64) global.get 0 i64.const 3 i64.sub @@ -116,7 +109,7 @@ expression: out local.get 0 i64.mul ) - (func (;7;) (type 0) (param i64) (result i64) + (func (;4;) (type 0) (param i64) (result i64) global.get 0 i64.const 3 i64.sub @@ -131,7 +124,7 @@ expression: out i64.const 1 i64.add ) - (func (;8;) (type 0) (param i64) (result i64) + (func (;5;) (type 0) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -153,65 +146,9 @@ expression: out end local.get 0 ) - (func (;9;) (type 6) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 1 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) - (memory (;0;) i64 0 1048576) - (memory (;1;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "compute" (func 5)) - (export "tenfold" (func 6)) - (export "inc" (func 7)) - (export "stable_memory" (memory 0)) - (export "stable_bytemap_memory" (memory 1)) + (export "compute" (func $inc)) + (export "tenfold" (func 3)) + (export "inc" (func 4)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__basic.snap b/rs/embedders/tests/snapshots/instrumentation__basic.snap index bb14baad493..b834eae2a04 100644 --- a/rs/embedders/tests/snapshots/instrumentation__basic.snap +++ b/rs/embedders/tests/snapshots/instrumentation__basic.snap @@ -6,17 +6,10 @@ expression: out (type (;0;) (func (param i32 i32) (result i32))) (type (;1;) (func)) (type (;2;) (func (param i32 i32 i32) (result i32))) - (type (;3;) (func (param i64 i64 i32) (result i64))) - (type (;4;) (func (param i32))) - (type (;5;) (func (param i64 i64 i64))) - (type (;6;) (func (param i64) (result i64))) - (type (;7;) (func (param i32 i32) (result i32 i32))) + (type (;3;) (func (param i64) (result i64))) (import "__" "out_of_instructions" (func $addTwo (;0;) (type 1))) (import "__" "update_available_memory" (func (;1;) (type 2))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 3))) - (import "__" "internal_trap" (func (;3;) (type 4))) - (import "__" "stable_read_first_access" (func (;4;) (type 5))) - (func (;5;) (type 0) (param i32 i32) (result i32) + (func (;2;) (type 0) (param i32 i32) (result i32) global.get 0 i64.const 3 i64.sub @@ -31,7 +24,7 @@ expression: out local.get 1 i32.add ) - (func (;6;) (type 6) (param i64) (result i64) + (func (;3;) (type 3) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -53,63 +46,7 @@ expression: out end local.get 0 ) - (func (;7;) (type 7) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 1 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) - (memory (;0;) i64 0 1048576) - (memory (;1;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "addTwo" (func 5)) - (export "stable_memory" (memory 0)) - (export "stable_bytemap_memory" (memory 1)) + (export "addTwo" (func 2)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__basic_import.snap b/rs/embedders/tests/snapshots/instrumentation__basic_import.snap index c841a88c861..9bf8c0d4c03 100644 --- a/rs/embedders/tests/snapshots/instrumentation__basic_import.snap +++ b/rs/embedders/tests/snapshots/instrumentation__basic_import.snap @@ -7,18 +7,11 @@ expression: out (type $b (;1;) (func (result i32))) (type (;2;) (func)) (type (;3;) (func (param i32 i32 i32) (result i32))) - (type (;4;) (func (param i64 i64 i32) (result i64))) - (type (;5;) (func (param i32))) - (type (;6;) (func (param i64 i64 i64))) - (type (;7;) (func (param i64) (result i64))) - (type (;8;) (func (param i32 i32) (result i32 i32))) + (type (;4;) (func (param i64) (result i64))) (import "__" "out_of_instructions" (func (;0;) (type 2))) (import "__" "update_available_memory" (func $addTwo (;1;) (type 3))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 4))) - (import "__" "internal_trap" (func (;3;) (type 5))) - (import "__" "stable_read_first_access" (func (;4;) (type 6))) - (import "ic0" "msg_arg_data_size" (func (;5;) (type $b))) - (func (;6;) (type $a) (param i32 i32) (result i32) + (import "ic0" "msg_arg_data_size" (func (;2;) (type $b))) + (func (;3;) (type $a) (param i32 i32) (result i32) global.get 0 i64.const 3 i64.sub @@ -33,7 +26,7 @@ expression: out local.get 1 i32.add ) - (func (;7;) (type 7) (param i64) (result i64) + (func (;4;) (type 4) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -55,63 +48,7 @@ expression: out end local.get 0 ) - (func (;8;) (type 8) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 1 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) - (memory (;0;) i64 0 1048576) - (memory (;1;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "addTwo" (func 6)) - (export "stable_memory" (memory 0)) - (export "stable_bytemap_memory" (memory 1)) + (export "addTwo" (func 3)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__basic_import_call.snap b/rs/embedders/tests/snapshots/instrumentation__basic_import_call.snap index 52ba9ed73e6..969be6788d4 100644 --- a/rs/embedders/tests/snapshots/instrumentation__basic_import_call.snap +++ b/rs/embedders/tests/snapshots/instrumentation__basic_import_call.snap @@ -7,17 +7,10 @@ expression: out (type $b (;1;) (func (param i64) (result i64))) (type (;2;) (func)) (type (;3;) (func (param i32 i32 i32) (result i32))) - (type (;4;) (func (param i64 i64 i32) (result i64))) - (type (;5;) (func (param i32))) - (type (;6;) (func (param i64 i64 i64))) - (type (;7;) (func (param i32 i32) (result i32 i32))) (import "__" "out_of_instructions" (func $cycles_accept (;0;) (type 2))) (import "__" "update_available_memory" (func $addTwo (;1;) (type 3))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 4))) - (import "__" "internal_trap" (func (;3;) (type 5))) - (import "__" "stable_read_first_access" (func (;4;) (type 6))) - (import "ic0" "msg_cycles_accept" (func (;5;) (type $b))) - (func (;6;) (type $a) (param i32 i32) (result i32) + (import "ic0" "msg_cycles_accept" (func (;2;) (type $b))) + (func (;3;) (type $a) (param i32 i32) (result i32) global.get 0 i64.const 6 i64.sub @@ -32,10 +25,10 @@ expression: out local.get 1 i32.add i64.const 0 - call 5 + call 2 drop ) - (func (;7;) (type $b) (param i64) (result i64) + (func (;4;) (type $b) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -57,63 +50,7 @@ expression: out end local.get 0 ) - (func (;8;) (type 7) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 1 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) - (memory (;0;) i64 0 1048576) - (memory (;1;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "addTwo" (func 6)) - (export "stable_memory" (memory 0)) - (export "stable_bytemap_memory" (memory 1)) + (export "addTwo" (func 3)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__control_flow.snap b/rs/embedders/tests/snapshots/instrumentation__control_flow.snap index 05503a1ab94..0e739162e36 100644 --- a/rs/embedders/tests/snapshots/instrumentation__control_flow.snap +++ b/rs/embedders/tests/snapshots/instrumentation__control_flow.snap @@ -6,19 +6,12 @@ expression: out (type (;0;) (func (param i64))) (type (;1;) (func)) (type (;2;) (func (param i32 i32 i32) (result i32))) - (type (;3;) (func (param i64 i64 i32) (result i64))) - (type (;4;) (func (param i32))) - (type (;5;) (func (param i64 i64 i64))) - (type (;6;) (func (param i64) (result i64))) - (type (;7;) (func (param i32 i32) (result i32 i32))) + (type (;3;) (func (param i64) (result i64))) (import "__" "out_of_instructions" (func $cycles_add (;0;) (type 1))) (import "__" "update_available_memory" (func (;1;) (type 2))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 3))) - (import "__" "internal_trap" (func (;3;) (type 4))) - (import "__" "stable_read_first_access" (func (;4;) (type 5))) - (import "ic0" "call_cycles_add" (func (;5;) (type 0))) - (func (;6;) (type 1) - (local i64) + (import "ic0" "call_cycles_add" (func (;2;) (type 0))) + (func (;3;) (type 1) + (local $i i64) global.get 0 i64.const 2 i64.sub @@ -30,7 +23,7 @@ expression: out call $cycles_add end i64.const 0 - local.set 0 + local.set $i block ;; label = @1 loop ;; label = @2 global.get 0 @@ -43,7 +36,7 @@ expression: out if ;; label = @3 call $cycles_add end - local.get 0 + local.get $i i64.const 10 i64.eq br_if 1 (;@1;) @@ -51,17 +44,17 @@ expression: out i64.const 7 i64.sub global.set 0 - local.get 0 - call 5 - local.get 0 + local.get $i + call 2 + local.get $i i64.const 1 i64.add - local.set 0 + local.set $i br 0 (;@2;) end end ) - (func (;7;) (type 0) (param i64) + (func (;4;) (type 0) (param i64) (local i64) global.get 0 i64.const 2 @@ -87,7 +80,7 @@ expression: out call $cycles_add end local.get 1 - call 5 + call 2 local.get 1 i64.const 1 i64.add @@ -98,7 +91,7 @@ expression: out br_if 0 (;@1;) end ) - (func (;8;) (type 0) (param i64) + (func (;5;) (type 0) (param i64) global.get 0 i64.const 4 i64.sub @@ -118,17 +111,17 @@ expression: out i64.sub global.set 0 i64.const 3 - call 5 + call 2 else global.get 0 i64.const 2 i64.sub global.set 0 i64.const 5 - call 5 + call 2 end ) - (func (;9;) (type 6) (param i64) (result i64) + (func (;6;) (type 3) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -150,67 +143,11 @@ expression: out end local.get 0 ) - (func (;10;) (type 7) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 2 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) (memory (;0;) 1) - (memory (;1;) i64 0 1048576) - (memory (;2;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "loop" (func 6)) - (export "countTo" (func 7)) - (export "if_then_else" (func 8)) + (export "loop" (func 3)) + (export "countTo" (func 4)) + (export "if_then_else" (func 5)) (export "memory" (memory 0)) - (export "stable_memory" (memory 1)) - (export "stable_bytemap_memory" (memory 2)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__element.snap b/rs/embedders/tests/snapshots/instrumentation__element.snap index a10c15e4b7b..784506954d1 100644 --- a/rs/embedders/tests/snapshots/instrumentation__element.snap +++ b/rs/embedders/tests/snapshots/instrumentation__element.snap @@ -8,17 +8,11 @@ expression: out (type (;2;) (func (param i64) (result i64))) (type (;3;) (func (param i32))) (type (;4;) (func (param i32 i32 i32) (result i32))) - (type (;5;) (func (param i64 i64 i32) (result i64))) - (type (;6;) (func (param i64 i64 i64))) - (type (;7;) (func (param i32 i32) (result i32 i32))) (import "__" "out_of_instructions" (func (;0;) (type 0))) (import "__" "update_available_memory" (func (;1;) (type 4))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 5))) - (import "__" "internal_trap" (func (;3;) (type 3))) - (import "__" "stable_read_first_access" (func (;4;) (type 6))) - (import "ic0" "msg_cycles_accept" (func (;5;) (type 2))) - (import "ic0" "msg_cycles_available" (func (;6;) (type 1))) - (func (;7;) (type 1) (result i64) + (import "ic0" "msg_cycles_accept" (func (;2;) (type 2))) + (import "ic0" "msg_cycles_available" (func (;3;) (type 1))) + (func (;4;) (type 1) (result i64) global.get 0 i64.const 1 i64.sub @@ -31,7 +25,7 @@ expression: out end i64.const 5 ) - (func (;8;) (type 2) (param i64) (result i64) + (func (;5;) (type 2) (param i64) (result i64) global.get 0 i64.const 2 i64.sub @@ -43,9 +37,9 @@ expression: out call 0 end local.get 0 - call 5 + call 2 ) - (func (;9;) (type 3) (param i32) + (func (;6;) (type 3) (param i32) global.get 0 i64.const 2 i64.sub @@ -59,7 +53,7 @@ expression: out local.get 0 call_indirect (type 0) ) - (func (;10;) (type 2) (param i64) (result i64) + (func (;7;) (type 2) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -81,68 +75,12 @@ expression: out end local.get 0 ) - (func (;11;) (type 7) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 1 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) (table (;0;) 5 5 funcref) - (memory (;0;) i64 0 1048576) - (memory (;1;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "Mt.call" (func 5)) - (export "call Mt.call" (func 8)) - (export "call" (func 9)) + (export "Mt.call" (func 2)) + (export "call Mt.call" (func 5)) + (export "call" (func 6)) (export "table" (table 0)) - (export "stable_memory" (memory 0)) - (export "stable_bytemap_memory" (memory 1)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) - (elem (;0;) (i32.const 0) func 7 7 7 6 5) + (elem (;0;) (i32.const 0) func 4 4 4 3 2) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__export_mutable_globals.snap b/rs/embedders/tests/snapshots/instrumentation__export_mutable_globals.snap index 0d9082cf8ae..2b33d32fc78 100644 --- a/rs/embedders/tests/snapshots/instrumentation__export_mutable_globals.snap +++ b/rs/embedders/tests/snapshots/instrumentation__export_mutable_globals.snap @@ -5,17 +5,10 @@ expression: out (module (type (;0;) (func)) (type (;1;) (func (param i32 i32 i32) (result i32))) - (type (;2;) (func (param i64 i64 i32) (result i64))) - (type (;3;) (func (param i32))) - (type (;4;) (func (param i64 i64 i64))) - (type (;5;) (func (param i64) (result i64))) - (type (;6;) (func (param i32 i32) (result i32 i32))) + (type (;2;) (func (param i64) (result i64))) (import "__" "out_of_instructions" (func (;0;) (type 0))) (import "__" "update_available_memory" (func (;1;) (type 1))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 2))) - (import "__" "internal_trap" (func (;3;) (type 3))) - (import "__" "stable_read_first_access" (func (;4;) (type 4))) - (func (;5;) (type 5) (param i64) (result i64) + (func (;2;) (type 2) (param i64) (result i64) (local i64) global.get 4 local.get 0 @@ -37,69 +30,13 @@ expression: out end local.get 0 ) - (func (;6;) (type 6) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 1 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) - (memory (;0;) i64 0 1048576) - (memory (;1;) 256 256) (global (;0;) (mut i32) i32.const 0) (global (;1;) i32 i32.const 1) (global (;2;) i32 i32.const 2) (global (;3;) (mut i32) i32.const 3) (global (;4;) (mut i64) i64.const 0) - (global (;5;) (mut i64) i64.const 0) - (global (;6;) (mut i64) i64.const 0) (export "_g_0" (global 0)) (export "_g_1" (global 1)) - (export "stable_memory" (memory 0)) - (export "stable_bytemap_memory" (memory 1)) (export "__persistent_mutable_global_3" (global 3)) (export "canister counter_instructions" (global 4)) - (export "canister counter_dirty_pages" (global 5)) - (export "canister counter_accessed_pages" (global 6)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__fac.snap b/rs/embedders/tests/snapshots/instrumentation__fac.snap index 8d2dc8fe53e..b460dbe3502 100644 --- a/rs/embedders/tests/snapshots/instrumentation__fac.snap +++ b/rs/embedders/tests/snapshots/instrumentation__fac.snap @@ -6,16 +6,9 @@ expression: out (type (;0;) (func (param i64) (result i64))) (type (;1;) (func)) (type (;2;) (func (param i32 i32 i32) (result i32))) - (type (;3;) (func (param i64 i64 i32) (result i64))) - (type (;4;) (func (param i32))) - (type (;5;) (func (param i64 i64 i64))) - (type (;6;) (func (param i32 i32) (result i32 i32))) (import "__" "out_of_instructions" (func $fac (;0;) (type 1))) (import "__" "update_available_memory" (func (;1;) (type 2))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 3))) - (import "__" "internal_trap" (func (;3;) (type 4))) - (import "__" "stable_read_first_access" (func (;4;) (type 5))) - (func (;5;) (type 0) (param i64) (result i64) + (func (;2;) (type 0) (param i64) (result i64) global.get 0 i64.const 4 i64.sub @@ -44,11 +37,11 @@ expression: out local.get 0 i64.const 1 i64.sub - call 5 + call 2 i64.mul end ) - (func (;6;) (type 0) (param i64) (result i64) + (func (;3;) (type 0) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -70,63 +63,7 @@ expression: out end local.get 0 ) - (func (;7;) (type 6) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 1 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) - (memory (;0;) i64 0 1048576) - (memory (;1;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "fac" (func 5)) - (export "stable_memory" (memory 0)) - (export "stable_bytemap_memory" (memory 1)) + (export "fac" (func 2)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__fizzbuzz.snap b/rs/embedders/tests/snapshots/instrumentation__fizzbuzz.snap index e4cb884469f..3daaf11c652 100644 --- a/rs/embedders/tests/snapshots/instrumentation__fizzbuzz.snap +++ b/rs/embedders/tests/snapshots/instrumentation__fizzbuzz.snap @@ -7,17 +7,11 @@ expression: out (type (;1;) (func (param i32))) (type (;2;) (func)) (type (;3;) (func (param i32 i32 i32) (result i32))) - (type (;4;) (func (param i64 i64 i32) (result i64))) - (type (;5;) (func (param i64 i64 i64))) - (type (;6;) (func (param i64) (result i64))) - (type (;7;) (func (param i32 i32) (result i32 i32))) + (type (;4;) (func (param i64) (result i64))) (import "__" "out_of_instructions" (func $println (;0;) (type 2))) (import "__" "update_available_memory" (func (;1;) (type 3))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 4))) - (import "__" "internal_trap" (func (;3;) (type 1))) - (import "__" "stable_read_first_access" (func (;4;) (type 5))) - (import "ic0" "debug_print" (func (;5;) (type 0))) - (func (;6;) (type 1) (param i32) + (import "ic0" "debug_print" (func (;2;) (type 0))) + (func (;3;) (type 1) (param i32) (local i32 i32 i32) global.get 0 i64.const 6 @@ -66,7 +60,7 @@ expression: out global.set 0 i32.const 8 i32.const 8 - call 5 + call 2 else global.get 0 i64.const 3 @@ -74,7 +68,7 @@ expression: out global.set 0 i32.const 0 i32.const 4 - call 5 + call 2 end else global.get 0 @@ -92,7 +86,7 @@ expression: out global.set 0 i32.const 4 i32.const 4 - call 5 + call 2 else global.get 0 i64.const 20 @@ -133,7 +127,7 @@ expression: out local.get 3 i32.const 15 i32.sub - call 5 + call 2 end end local.get 1 @@ -146,7 +140,7 @@ expression: out br_if 0 (;@1;) end ) - (func (;7;) (type 6) (param i64) (result i64) + (func (;4;) (type 4) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -168,65 +162,9 @@ expression: out end local.get 0 ) - (func (;8;) (type 7) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 2 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) (memory (;0;) 1) - (memory (;1;) i64 0 1048576) - (memory (;2;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "fizzbuzz" (func 6)) + (export "fizzbuzz" (func 3)) (export "memory" (memory 0)) - (export "stable_memory" (memory 1)) - (export "stable_bytemap_memory" (memory 2)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__memory_fill.snap b/rs/embedders/tests/snapshots/instrumentation__memory_fill.snap index 23bf3ea3d21..10895193ec4 100644 --- a/rs/embedders/tests/snapshots/instrumentation__memory_fill.snap +++ b/rs/embedders/tests/snapshots/instrumentation__memory_fill.snap @@ -5,17 +5,10 @@ expression: out (module (type (;0;) (func)) (type (;1;) (func (param i32 i32 i32) (result i32))) - (type (;2;) (func (param i64 i64 i32) (result i64))) - (type (;3;) (func (param i32))) - (type (;4;) (func (param i64 i64 i64))) - (type (;5;) (func (param i64) (result i64))) - (type (;6;) (func (param i32 i32) (result i32 i32))) + (type (;2;) (func (param i64) (result i64))) (import "__" "out_of_instructions" (func (;0;) (type 0))) (import "__" "update_available_memory" (func (;1;) (type 1))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 2))) - (import "__" "internal_trap" (func (;3;) (type 3))) - (import "__" "stable_read_first_access" (func (;4;) (type 4))) - (func (;5;) (type 0) + (func (;2;) (type 0) global.get 0 i64.const 4 i64.sub @@ -30,11 +23,11 @@ expression: out i32.const 1 i32.const 16 i64.extend_i32_u - call 6 + call 3 i32.wrap_i64 memory.fill ) - (func (;6;) (type 5) (param i64) (result i64) + (func (;3;) (type 2) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -56,64 +49,8 @@ expression: out end local.get 0 ) - (func (;7;) (type 6) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 2 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) (memory (;0;) 1) - (memory (;1;) i64 0 1048576) - (memory (;2;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) (export "memory" (memory 0)) - (export "stable_memory" (memory 1)) - (export "stable_bytemap_memory" (memory 2)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__memory_grow.snap b/rs/embedders/tests/snapshots/instrumentation__memory_grow.snap index 2524b81d3cc..128a5829334 100644 --- a/rs/embedders/tests/snapshots/instrumentation__memory_grow.snap +++ b/rs/embedders/tests/snapshots/instrumentation__memory_grow.snap @@ -6,17 +6,10 @@ expression: out (type (;0;) (func (param i32) (result i32))) (type (;1;) (func)) (type (;2;) (func (param i32 i32 i32) (result i32))) - (type (;3;) (func (param i64 i64 i32) (result i64))) - (type (;4;) (func (param i32))) - (type (;5;) (func (param i64 i64 i64))) - (type (;6;) (func (param i64) (result i64))) - (type (;7;) (func (param i32 i32) (result i32 i32))) + (type (;3;) (func (param i64) (result i64))) (import "__" "out_of_instructions" (func $grow (;0;) (type 1))) (import "__" "update_available_memory" (func (;1;) (type 2))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 3))) - (import "__" "internal_trap" (func (;3;) (type 4))) - (import "__" "stable_read_first_access" (func (;4;) (type 5))) - (func (;5;) (type 0) (param i32) (result i32) + (func (;2;) (type 0) (param i32) (result i32) (local i32 i32 i32) global.get 0 i64.const 2 @@ -35,7 +28,7 @@ expression: out i32.const 65536 call 1 ) - (func (;6;) (type 6) (param i64) (result i64) + (func (;3;) (type 3) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -57,65 +50,9 @@ expression: out end local.get 0 ) - (func (;7;) (type 7) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 2 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) (memory (;0;) 17 100) - (memory (;1;) i64 0 1048576) - (memory (;2;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) (export "memory" (memory 0)) - (export "grow" (func 5)) - (export "stable_memory" (memory 1)) - (export "stable_bytemap_memory" (memory 2)) + (export "grow" (func 2)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__nested_ifs.snap b/rs/embedders/tests/snapshots/instrumentation__nested_ifs.snap index 9174840f868..d95e52c3b48 100644 --- a/rs/embedders/tests/snapshots/instrumentation__nested_ifs.snap +++ b/rs/embedders/tests/snapshots/instrumentation__nested_ifs.snap @@ -6,16 +6,9 @@ expression: out (type (;0;) (func (param i64) (result i64))) (type (;1;) (func)) (type (;2;) (func (param i32 i32 i32) (result i32))) - (type (;3;) (func (param i64 i64 i32) (result i64))) - (type (;4;) (func (param i32))) - (type (;5;) (func (param i64 i64 i64))) - (type (;6;) (func (param i32 i32) (result i32 i32))) (import "__" "out_of_instructions" (func $compute (;0;) (type 1))) (import "__" "update_available_memory" (func (;1;) (type 2))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 3))) - (import "__" "internal_trap" (func (;3;) (type 4))) - (import "__" "stable_read_first_access" (func (;4;) (type 5))) - (func (;5;) (type 0) (param i64) (result i64) + (func (;2;) (type 0) (param i64) (result i64) global.get 0 i64.const 6 i64.sub @@ -99,7 +92,7 @@ expression: out end local.get 0 ) - (func (;6;) (type 0) (param i64) (result i64) + (func (;3;) (type 0) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -121,63 +114,7 @@ expression: out end local.get 0 ) - (func (;7;) (type 6) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 1 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) - (memory (;0;) i64 0 1048576) - (memory (;1;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "compute" (func 5)) - (export "stable_memory" (memory 0)) - (export "stable_bytemap_memory" (memory 1)) + (export "compute" (func 2)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__recursive.snap b/rs/embedders/tests/snapshots/instrumentation__recursive.snap index 7c105c29fa8..2b27b07d7d5 100644 --- a/rs/embedders/tests/snapshots/instrumentation__recursive.snap +++ b/rs/embedders/tests/snapshots/instrumentation__recursive.snap @@ -6,16 +6,9 @@ expression: out (type (;0;) (func (param i64) (result i64))) (type (;1;) (func)) (type (;2;) (func (param i32 i32 i32) (result i32))) - (type (;3;) (func (param i64 i64 i32) (result i64))) - (type (;4;) (func (param i32))) - (type (;5;) (func (param i64 i64 i64))) - (type (;6;) (func (param i32 i32) (result i32 i32))) (import "__" "out_of_instructions" (func $fac (;0;) (type 1))) (import "__" "update_available_memory" (func (;1;) (type 2))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 3))) - (import "__" "internal_trap" (func (;3;) (type 4))) - (import "__" "stable_read_first_access" (func (;4;) (type 5))) - (func (;5;) (type 0) (param i64) (result i64) + (func (;2;) (type 0) (param i64) (result i64) global.get 0 i64.const 8 i64.sub @@ -48,11 +41,11 @@ expression: out local.get 0 i64.const 1 i64.sub - call 5 + call 2 i64.mul end ) - (func (;6;) (type 0) (param i64) (result i64) + (func (;3;) (type 0) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -74,63 +67,7 @@ expression: out end local.get 0 ) - (func (;7;) (type 6) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 1 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) - (memory (;0;) i64 0 1048576) - (memory (;1;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "fac" (func 5)) - (export "stable_memory" (memory 0)) - (export "stable_bytemap_memory" (memory 1)) + (export "fac" (func 2)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__simple_loop.snap b/rs/embedders/tests/snapshots/instrumentation__simple_loop.snap index 25058fc5140..74868a21b08 100644 --- a/rs/embedders/tests/snapshots/instrumentation__simple_loop.snap +++ b/rs/embedders/tests/snapshots/instrumentation__simple_loop.snap @@ -5,17 +5,10 @@ expression: out (module (type (;0;) (func)) (type (;1;) (func (param i32 i32 i32) (result i32))) - (type (;2;) (func (param i64 i64 i32) (result i64))) - (type (;3;) (func (param i32))) - (type (;4;) (func (param i64 i64 i64))) - (type (;5;) (func (param i64) (result i64))) - (type (;6;) (func (param i32 i32) (result i32 i32))) + (type (;2;) (func (param i64) (result i64))) (import "__" "out_of_instructions" (func $test (;0;) (type 0))) (import "__" "update_available_memory" (func (;1;) (type 1))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 2))) - (import "__" "internal_trap" (func (;3;) (type 3))) - (import "__" "stable_read_first_access" (func (;4;) (type 4))) - (func (;5;) (type 0) + (func (;2;) (type 0) global.get 0 i64.const 0 i64.sub @@ -40,7 +33,7 @@ expression: out br 0 (;@1;) end ) - (func (;6;) (type 5) (param i64) (result i64) + (func (;3;) (type 2) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -62,65 +55,9 @@ expression: out end local.get 0 ) - (func (;7;) (type 6) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 2 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) (memory $memory (;0;) 1) - (memory (;1;) i64 0 1048576) - (memory (;2;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "canister_update test" (func 5)) + (export "canister_update test" (func 2)) (export "memory" (memory $memory)) - (export "stable_memory" (memory 1)) - (export "stable_bytemap_memory" (memory 2)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__start.snap b/rs/embedders/tests/snapshots/instrumentation__start.snap index 4bf08e0114e..47a285eaaa5 100644 --- a/rs/embedders/tests/snapshots/instrumentation__start.snap +++ b/rs/embedders/tests/snapshots/instrumentation__start.snap @@ -8,17 +8,11 @@ expression: out (type (;2;) (func (param i64) (result i64))) (type (;3;) (func)) (type (;4;) (func (param i32 i32 i32) (result i32))) - (type (;5;) (func (param i64 i64 i32) (result i64))) - (type (;6;) (func (param i64 i64 i64))) - (type (;7;) (func (param i32 i32) (result i32 i32))) (import "__" "out_of_instructions" (func (;0;) (type 3))) (import "__" "update_available_memory" (func (;1;) (type 4))) - (import "__" "try_grow_stable_memory" (func $foo (;2;) (type 5))) - (import "__" "internal_trap" (func (;3;) (type 0))) - (import "__" "stable_read_first_access" (func (;4;) (type 6))) - (import "ic0" "msg_cycles_available" (func (;5;) (type 1))) - (import "ic0" "msg_cycles_accept" (func (;6;) (type 2))) - (func (;7;) (type 3) + (import "ic0" "msg_cycles_available" (func $foo (;2;) (type 1))) + (import "ic0" "msg_cycles_accept" (func (;3;) (type 2))) + (func (;4;) (type 3) global.get 0 i64.const 0 i64.sub @@ -30,7 +24,7 @@ expression: out call 0 end ) - (func (;8;) (type 3) + (func (;5;) (type 3) global.get 0 i64.const 2 i64.sub @@ -44,7 +38,7 @@ expression: out i32.const 42 drop ) - (func (;9;) (type 2) (param i64) (result i64) + (func (;6;) (type 2) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -66,68 +60,12 @@ expression: out end local.get 0 ) - (func (;10;) (type 7) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 2 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) (table (;0;) 0 1 funcref) (memory (;0;) 1 1) - (memory (;1;) i64 0 1048576) - (memory (;2;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "e" (func 6)) + (export "e" (func 3)) (export "table" (table 0)) (export "memory" (memory 0)) - (export "stable_memory" (memory 1)) - (export "stable_bytemap_memory" (memory 2)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) - (export "canister_start" (func 7)) + (export "canister_start" (func 4)) ) diff --git a/rs/embedders/tests/snapshots/instrumentation__zero_cost_ops.snap b/rs/embedders/tests/snapshots/instrumentation__zero_cost_ops.snap index 8d2dc8fe53e..b460dbe3502 100644 --- a/rs/embedders/tests/snapshots/instrumentation__zero_cost_ops.snap +++ b/rs/embedders/tests/snapshots/instrumentation__zero_cost_ops.snap @@ -6,16 +6,9 @@ expression: out (type (;0;) (func (param i64) (result i64))) (type (;1;) (func)) (type (;2;) (func (param i32 i32 i32) (result i32))) - (type (;3;) (func (param i64 i64 i32) (result i64))) - (type (;4;) (func (param i32))) - (type (;5;) (func (param i64 i64 i64))) - (type (;6;) (func (param i32 i32) (result i32 i32))) (import "__" "out_of_instructions" (func $fac (;0;) (type 1))) (import "__" "update_available_memory" (func (;1;) (type 2))) - (import "__" "try_grow_stable_memory" (func (;2;) (type 3))) - (import "__" "internal_trap" (func (;3;) (type 4))) - (import "__" "stable_read_first_access" (func (;4;) (type 5))) - (func (;5;) (type 0) (param i64) (result i64) + (func (;2;) (type 0) (param i64) (result i64) global.get 0 i64.const 4 i64.sub @@ -44,11 +37,11 @@ expression: out local.get 0 i64.const 1 i64.sub - call 5 + call 2 i64.mul end ) - (func (;6;) (type 0) (param i64) (result i64) + (func (;3;) (type 0) (param i64) (result i64) (local i64) global.get 0 local.get 0 @@ -70,63 +63,7 @@ expression: out end local.get 0 ) - (func (;7;) (type 6) (param i32 i32) (result i32 i32) - (local i32 i32 i32 i32) - local.get 0 - local.get 1 - i32.ge_u - if ;; label = @1 - i32.const 0 - i32.const 0 - return - end - local.get 0 - local.set 2 - loop ;; label = @1 - local.get 2 - i32.load8_u 1 - local.tee 3 - i32.const 1 - i32.and - local.get 4 - i32.add - local.set 4 - local.get 3 - i32.const 1 - i32.shr_u - i32.const 1 - i32.and - local.get 5 - i32.add - local.set 5 - local.get 2 - i32.const 1 - i32.add - local.tee 2 - local.get 1 - i32.lt_u - br_if 0 (;@1;) - end - local.get 1 - local.get 0 - i32.sub - local.get 4 - i32.sub - local.get 1 - local.get 0 - i32.sub - local.get 5 - i32.sub - ) - (memory (;0;) i64 0 1048576) - (memory (;1;) 256 256) (global (;0;) (mut i64) i64.const 0) - (global (;1;) (mut i64) i64.const 0) - (global (;2;) (mut i64) i64.const 0) - (export "fac" (func 5)) - (export "stable_memory" (memory 0)) - (export "stable_bytemap_memory" (memory 1)) + (export "fac" (func 2)) (export "canister counter_instructions" (global 0)) - (export "canister counter_dirty_pages" (global 1)) - (export "canister counter_accessed_pages" (global 2)) ) diff --git a/rs/execution_environment/src/execution/install_code/tests.rs b/rs/execution_environment/src/execution/install_code/tests.rs index 7f3d55171e0..f66379da7b0 100644 --- a/rs/execution_environment/src/execution/install_code/tests.rs +++ b/rs/execution_environment/src/execution/install_code/tests.rs @@ -86,7 +86,7 @@ fn install_code_fails_on_invalid_memory_allocation() { #[test] fn dts_resume_works_in_install_code() { - const INSTRUCTION_LIMIT: u64 = 3_000_000; + const INSTRUCTION_LIMIT: u64 = 2_000_000; let mut test = ExecutionTestBuilder::new() .with_install_code_instruction_limit(INSTRUCTION_LIMIT) .with_install_code_slice_instruction_limit(1_000) @@ -137,7 +137,7 @@ fn dts_resume_works_in_install_code() { #[test] fn dts_abort_works_in_install_code() { - const INSTRUCTION_LIMIT: u64 = 3_000_000; + const INSTRUCTION_LIMIT: u64 = 2_000_000; let mut test = ExecutionTestBuilder::new() .with_install_code_instruction_limit(INSTRUCTION_LIMIT) .with_install_code_slice_instruction_limit(1_000) diff --git a/rs/execution_environment/src/query_handler/query_cache.rs b/rs/execution_environment/src/query_handler/query_cache.rs index e97604acc17..9c548c6cf67 100644 --- a/rs/execution_environment/src/query_handler/query_cache.rs +++ b/rs/execution_environment/src/query_handler/query_cache.rs @@ -185,7 +185,11 @@ impl EntryValue { } fn elapsed_seconds(&self, now: Time) -> f64 { - (now - self.env.batch_time).as_secs_f64() + if now > self.env.batch_time { + (now - self.env.batch_time).as_secs_f64() + } else { + 0.0 + } } } @@ -274,3 +278,30 @@ impl QueryCache { evicted_entries } } + +#[cfg(test)] +mod tests { + use std::time::Duration; + + use ic_state_machine_tests::WasmResult; + use ic_types::{time, Cycles}; + + use super::{EntryEnv, EntryValue}; + + #[test] + fn query_cache_entry_value_elapsed_seconds() { + let current_time = time::GENESIS; + let entry_env = EntryEnv { + batch_time: current_time, + canister_version: 1, + canister_balance: Cycles::new(0), + }; + let entry_value = EntryValue::new(entry_env, Result::Ok(WasmResult::Reply(vec![]))); + let forward_time = current_time + Duration::from_secs(2); + assert_eq!(2.0, entry_value.elapsed_seconds(forward_time)); + + // Negative time differences should give just 0. + let backward_time = current_time - Duration::from_secs(2); + assert_eq!(0.0, entry_value.elapsed_seconds(backward_time)); + } +} diff --git a/rs/execution_environment/src/query_handler/tests.rs b/rs/execution_environment/src/query_handler/tests.rs index 676d25305fa..5cb5d296826 100644 --- a/rs/execution_environment/src/query_handler/tests.rs +++ b/rs/execution_environment/src/query_handler/tests.rs @@ -10,7 +10,9 @@ use ic_test_utilities::{ universal_canister::{call_args, wasm}, }; use ic_test_utilities_execution_environment::{ExecutionTest, ExecutionTestBuilder}; -use ic_types::{ingress::WasmResult, messages::UserQuery, CountBytes, Cycles, NumInstructions}; +use ic_types::{ + ingress::WasmResult, messages::UserQuery, time, CountBytes, Cycles, NumInstructions, +}; use std::{sync::Arc, time::Duration}; const CYCLES_BALANCE: Cycles = Cycles::new(100_000_000_000_000); @@ -289,6 +291,75 @@ fn query_cache_metrics_evicted_entries_count_bytes_work() { assert!(REPLY_SIZE * 2 > count_bytes); } +#[test] +fn query_cache_metrics_evicted_entries_negative_duration_works() { + const REPLY_SIZE: usize = 10_000; + const QUERY_CACHE_SIZE: usize = 1; + // Plus some room for the keys, headers etc. + const QUERY_CACHE_CAPACITY: usize = REPLY_SIZE * QUERY_CACHE_SIZE + REPLY_SIZE; + + let mut test = ExecutionTestBuilder::new() + .with_query_caching() + .with_query_cache_capacity(QUERY_CACHE_CAPACITY as u64) + .build(); + + // As there are no updates, the default system time is unix epoch, so we explicitly set it here. + test.state_mut().metadata.batch_time = time::GENESIS; + + let canister_id = test.universal_canister_with_cycles(CYCLES_BALANCE).unwrap(); + + // Run the first query. + let output = test.query( + UserQuery { + source: user_test_id(1), + receiver: canister_id, + method_name: "query".into(), + // The bytes are stored twice: as a payload in key and as a reply in value. + method_payload: wasm().reply_data(&[1; REPLY_SIZE / 2]).build(), + ingress_expiry: 0, + nonce: None, + }, + Arc::new(test.state().clone()), + vec![], + ); + assert_eq!(output, Ok(WasmResult::Reply([1; REPLY_SIZE / 2].into()))); + + // Move the time backward. + test.state_mut().metadata.batch_time = + test.state_mut().metadata.batch_time - Duration::from_secs(2); + + // The second query should evict the first one, as there is no room in the cache for two queries. + let output = test.query( + UserQuery { + // The query should be different, so we evict, not invalidate. + source: user_test_id(2), + receiver: canister_id, + method_name: "query".into(), + // The bytes are stored twice: as a payload in key and as a reply in value. + method_payload: wasm().reply_data(&[2; REPLY_SIZE / 2]).build(), + ingress_expiry: 0, + nonce: None, + }, + Arc::new(test.state().clone()), + vec![], + ); + assert_eq!(output, Ok(WasmResult::Reply([2; REPLY_SIZE / 2].into()))); + + let metrics = &downcast_query_handler(test.query_handler()) + .query_cache + .metrics; + // Negative durations should give just 0. + assert_eq!( + 0, + metrics.evicted_entries_duration.get_sample_sum() as usize + ); + // One entry should be evicted. + assert_eq!( + 1, + metrics.evicted_entries_duration.get_sample_count() as usize + ); +} + #[test] fn query_cache_metrics_invalidated_entries_work() { const ITERATIONS: usize = 5; @@ -569,6 +640,59 @@ fn query_cache_env_different_batch_time_returns_different_results() { } } +#[test] +fn query_cache_env_invalidated_entries_negative_duration_works() { + let mut test = ExecutionTestBuilder::new().with_query_caching().build(); + + // As there are no updates, the default system time is unix epoch, so we explicitly set it here. + test.state_mut().metadata.batch_time = time::GENESIS; + + let canister_id = test.universal_canister_with_cycles(CYCLES_BALANCE).unwrap(); + let output_1 = test.query( + UserQuery { + source: user_test_id(1), + receiver: canister_id, + method_name: "query".into(), + method_payload: wasm().reply_data(&[42]).build(), + ingress_expiry: 0, + nonce: None, + }, + Arc::new(test.state().clone()), + vec![], + ); + // Move the time backward. + test.state_mut().metadata.batch_time = + test.state_mut().metadata.batch_time - Duration::from_secs(1); + let output_2 = test.query( + UserQuery { + source: user_test_id(1), + receiver: canister_id, + method_name: "query".into(), + method_payload: wasm().reply_data(&[42]).build(), + ingress_expiry: 0, + nonce: None, + }, + Arc::new(test.state().clone()), + vec![], + ); + { + let metrics = &downcast_query_handler(test.query_handler()) + .query_cache + .metrics; + assert_eq!(output_1, output_2); + assert_eq!(1, metrics.invalidated_entries_by_time.get()); + // Negative durations should give just 0. + assert_eq!( + 0, + metrics.invalidated_entries_duration.get_sample_sum() as usize + ); + assert_eq!( + 1, + metrics.invalidated_entries_duration.get_sample_count() as usize + ); + } +} + #[test] fn query_cache_env_different_canister_version_returns_different_results() { let mut test = ExecutionTestBuilder::new().with_query_caching().build(); diff --git a/rs/test_utilities/execution_environment/src/lib.rs b/rs/test_utilities/execution_environment/src/lib.rs index 569f1f2da37..90034c04956 100644 --- a/rs/test_utilities/execution_environment/src/lib.rs +++ b/rs/test_utilities/execution_environment/src/lib.rs @@ -1435,6 +1435,7 @@ pub struct ExecutionTestBuilder { cost_to_compile_wasm_instruction: u64, max_query_call_graph_instructions: NumInstructions, stable_memory_dirty_page_limit: NumPages, + time: Time, } impl Default for ExecutionTestBuilder { @@ -1494,6 +1495,7 @@ impl Default for ExecutionTestBuilder { max_query_call_graph_instructions: max_instructions_per_composite_query_call, stable_memory_dirty_page_limit: ic_config::execution_environment::Config::default() .stable_memory_dirty_page_limit, + time: mock_time(), } } } @@ -1750,6 +1752,11 @@ impl ExecutionTestBuilder { self } + pub fn with_time(mut self, time: Time) -> Self { + self.time = time; + self + } + pub fn build(self) -> ExecutionTest { let own_range = CanisterIdRange { start: CanisterId::from(CANISTER_IDS_PER_SUBNET), @@ -1936,7 +1943,7 @@ impl ExecutionTestBuilder { self.subnet_message_memory, self.subnet_wasm_custom_sections_memory, ), - time: mock_time(), + time: self.time, instruction_limits: InstructionLimits::new( deterministic_time_slicing, self.instruction_limit,