-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SimpleJIT hot code swapping #2403
SimpleJIT hot code swapping #2403
Conversation
This ensures that all functions can be replaced without having to perform relocations again.
bbc2afb
to
86d3dc9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this work - it may be time to drop the Simple
from the name of this JIT ;) ! This is a bit over my head right now, I need to spend more time reading and understanding this and may need to pull in another reviewer who is more familiar.
@@ -129,9 +131,13 @@ pub struct SimpleJITModule { | |||
libcall_names: Box<dyn Fn(ir::LibCall) -> String>, | |||
memory: MemoryHandle, | |||
declarations: ModuleDeclarations, | |||
function_got_entries: SecondaryMap<FuncId, Option<NonNull<*const u8>>>, | |||
function_plt_entries: SecondaryMap<FuncId, Option<NonNull<[u8; 16]>>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not clear on how 16 bytes was arrived at, and how platform specific this is - is it due to 16-byte function call alignment on x86_64? does some other sequence of instructions have to fit in here besides the plt_val at line 179?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future I may extend it to be more like the lazy symbol binding used by ELF. In that case the GOT entry will initially point just after the jump instruction in the PLT. After this jump instruction it pushes a specific value to the stack depending on which PLT entry it is and then it jumps to a function common between all entries in a module. This function then resolves the symbol. This avoids having to create a new wrapper function for each lazily compiled function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. a comment to this effect would be appreciated :)
It seems that the new x64 backend doesn't have support for position independent code. |
Please do create an issue! I will look into this at some point as part of the transition-to-new-backend effort. |
Done: #2417 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dan and I walked through this today and I'm now more confident I understand this design space. I'll merge this as soon as CI gets fixed up
321dae1
to
2fea300
Compare
2fea300
to
937a3fd
Compare
@pchickey I have restored support for non-pic code in SimpleJIT to fix x64. Hot code swapping needs to be disabled in that case though. I have tested it with cg_clif in the non-pic, pic and hotswapping configuration. |
Excellent, that is even better. Want to make a follow-up PR dropping the |
Sure |
This includes bytecodealliance/wasmtime#2403 which enables hotswapping with SimpleJIT
This makes it possible to change functions when using SimpleJIT without having to recompile everything or even restart the jitted code. When a changed function is currently on the stack, the old version will be returned to, but all new calls will be redirected to the new version. It is not yet possible to swap data objects.
This is a prerequisite of https://github.com/bjorn3/rustc_codegen_cranelift/issues/1087.
I have tested this PR by implementing lazy compilation in cg_clif as suggested by @flodiebold in https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/cranelift.20backend.20work/near/187645798 in February.
r? @pchickey (By the way, is it deliberate that you are marked as unavailable on zulip? I sent you a PM)
cc https://bytecodealliance.zulipchat.com/#narrow/stream/217117-cranelift/topic/hot.20code.20swapping.20for.20simplejit/near/216403611