wasmtime: Implement `table.get` and `table.set`
These instructions have fast, inline JIT paths for the common cases, and only
call out to host VM functions for the slow paths. This required some changes to
`cranelift-wasm`'s `FuncEnvironment`: instead of taking a `FuncCursor` to insert
an instruction sequence within the current basic block,
`FuncEnvironment::translate_table_{get,set}` now take a `&mut FunctionBuilder`
so that they can create whole new basic blocks. This is necessary for
implementing GC read/write barriers that involve branching (e.g. checking for
null, or whether a store buffer is at capacity).
Furthermore, it required that the `load`, `load_complex`, and `store`
instructions handle loading and storing through an `r{32,64}` rather than just
`i{32,64}` addresses. This involved making `r{32,64}` types acceptable
instantiations of the `iAddr` type variable, plus a few new instruction
encodings.
Part of #929
4 years ago
|
|
|
(module
|
|
|
|
(table $t 1 externref)
|
|
|
|
|
|
|
|
(func (export "init") (param externref)
|
|
|
|
(table.set $t (i32.const 0) (local.get 0))
|
|
|
|
)
|
|
|
|
|
|
|
|
(func (export "get-many-externrefs") (param $i i32)
|
|
|
|
(loop $continue
|
|
|
|
;; Exit when our loop counter `$i` reaches zero.
|
|
|
|
(if (i32.eqz (local.get $i))
|
|
|
|
(then (return))
|
wasmtime: Implement `table.get` and `table.set`
These instructions have fast, inline JIT paths for the common cases, and only
call out to host VM functions for the slow paths. This required some changes to
`cranelift-wasm`'s `FuncEnvironment`: instead of taking a `FuncCursor` to insert
an instruction sequence within the current basic block,
`FuncEnvironment::translate_table_{get,set}` now take a `&mut FunctionBuilder`
so that they can create whole new basic blocks. This is necessary for
implementing GC read/write barriers that involve branching (e.g. checking for
null, or whether a store buffer is at capacity).
Furthermore, it required that the `load`, `load_complex`, and `store`
instructions handle loading and storing through an `r{32,64}` rather than just
`i{32,64}` addresses. This involved making `r{32,64}` types acceptable
instantiations of the `iAddr` type variable, plus a few new instruction
encodings.
Part of #929
4 years ago
|
|
|
)
|
|
|
|
|
|
|
|
;; Get an `externref` out of the table. This could cause the
|
|
|
|
;; `VMExternRefActivationsTable`'s bump region to reach full capacity,
|
|
|
|
;; which triggers a GC.
|
|
|
|
;;
|
|
|
|
;; Set the table element back into the table, just so that the element is
|
|
|
|
;; still considered live at the time of the `table.get`, it ends up in the
|
|
|
|
;; stack map, and we poke more of our GC bits.
|
|
|
|
(table.set $t (i32.const 0) (table.get $t (i32.const 0)))
|
|
|
|
|
|
|
|
;; Decrement our loop counter `$i`.
|
|
|
|
(local.set $i (i32.sub (local.get $i) (i32.const 1)))
|
|
|
|
|
|
|
|
;; Continue to the next loop iteration.
|
|
|
|
(br $continue)
|
|
|
|
)
|
|
|
|
unreachable
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
(invoke "init" (ref.extern 1))
|
|
|
|
(invoke "get-many-externrefs" (i32.const 8192))
|