Stream: cranelift

Topic: Stackmap and GC roots


view this post on Zulip playX (Jun 09 2020 at 13:33):

I would like to use Cranelift as baseline JIT and instead of placing VM registers on heap allocated stack I would like to use real registers and machine stack, but I can't find any information/tutorial/documentation on how to use stackmaps in cranelift, is there any information?

view this post on Zulip playX (Jun 09 2020 at 13:35):

P.S My languge is dynamically typed and uses nan-boxing so I need to place all values to stackmap and VM Value can be stored in just I64 on both 32 bit and 64 bit machines

view this post on Zulip Notification Bot (Jun 09 2020 at 13:40):

This topic was moved here from #general > Stackmap and GC roots by Till Schneidereit

view this post on Zulip Till Schneidereit (Jun 09 2020 at 13:41):

(I moved this for more visibility to Cranelift folks)

view this post on Zulip Till Schneidereit (Jun 09 2020 at 13:41):

@playX does https://github.com/bytecodealliance/wasmtime/pull/1832 help, by any chance?

For host VM code, we use plain reference counting, where cloning increments the reference count, and dropping decrements it. We can avoid many of the on-stack increment/decrement operations that ty...

view this post on Zulip playX (Jun 09 2020 at 13:48):

@Till Schneidereit helps a litte, but there is no good explanation on how to use these stackmaps, how to get them e.g with SimpleJITBackend and Idk where and when I should use reference type vs just i32/i64

view this post on Zulip Till Schneidereit (Jun 09 2020 at 14:12):

@fitzgen (he/him) might be able to answer some of this, but it seems plausible that for now using this does require digging into the code quite a bit

view this post on Zulip fitzgen (he/him) (Jun 09 2020 at 16:40):

@playX, I recently landed a PR that improved the docs for Stackmap a bit and cleared up questions that I had when implementing their integration into Wasmtime: https://github.com/bytecodealliance/wasmtime/pull/1824/files#diff-97dbc08ed429dd9faefe70055a6c2009

Note that Cranelift's stack map support assumes that references are pointer-sized, so using r64 on 32-bit architectures won't work right now.

One of the new tests introduced here is not passing yet, because it looks like Cranelift is generating incorrect stack frames / stack maps, but I'd like to get a second set of eyes on whether t...

view this post on Zulip fitzgen (he/him) (Jun 09 2020 at 16:40):

@playX ^

view this post on Zulip playX (Jun 09 2020 at 16:55):

This documentation is cool but still does not show any example code, maybe it's worth adding some examples on how to use it and how to get frame pointers etc.

view this post on Zulip fitzgen (he/him) (Jun 09 2020 at 20:34):

to get the stack pointers, you need to use something like libunwind to walk the stack, or your own stack walker

there is a WIP pr to add SP support to the backtrace crate here: https://github.com/rust-lang/backtrace-rs/pull/341

r? @alexcrichton

view this post on Zulip playX (Jun 15 2020 at 01:37):

@fitzgen (he/him) I'll probably go with conservative on stack GC right now because in my project roots might be located anywhere, but for JITed functions when I'll learn more about stackmaps I'll use them :)


Last updated: Nov 22 2024 at 16:03 UTC