ckb-vm icon indicating copy to clipboard operation
ckb-vm copied to clipboard

feat: compile aot code in AsmMachine.load_elf

Open mohanson opened this issue 4 years ago • 7 comments
trafficstars

Rewrite the logic of aot machine when processing reset, now the second program can also be compiled to aot code normally.

  • Add a new structure AsmWrapMachine
  • instruction_cycle_func is now used as a parameter of AotCompilingMachine.compile() instead of a parameter of AotCompilingMachine::new()
  • Remove confusing constructor like machine::latest() or machine::default(): https://github.com/nervosnetwork/ckb-vm/issues/163

mohanson avatar Jun 02 '21 08:06 mohanson

Can we split this into 2 PRs? The changes for latest and default could go first, but the change about AsmWrapMachine is so weird, I do think we should spend more time on that.

xxuejie avatar Jun 09 '21 07:06 xxuejie

Okay, I will split this into two PRs, and then explain why I want to add AsmWrapMachine

mohanson avatar Jun 09 '21 07:06 mohanson

image

mohanson avatar Jun 10 '21 02:06 mohanson

I think the core problem is that we can't compile aot code in syscall, just like we can't clean Trace in syscall.

mohanson avatar Jun 10 '21 02:06 mohanson

we can't compile aot code in syscall

This is an interesting one: why can't we compile aot code within a syscall? What if we just create a new AOT machine, and use it to compile aot code?

xxuejie avatar Jun 10 '21 09:06 xxuejie

What if we just create a new AOT machine, and use it to compile aot code?

First question: How do we know that we are running in aot mode in syscall?

And instruction_cycle_func is needed to compile aot code, this function is not available in syscall.

The last: How to pass the compiled result to the outside? Only Box<AsmCoreMachine> can be accessed in syscall as a SupportMachine, and it does not have the ability to save aot_code

mohanson avatar Jun 10 '21 11:06 mohanson

What if we just create a new AOT machine, and use it to compile aot code?

First question: How do we know that we are running in aot mode in syscall?

I consider syscalls together with the VM initialization code as a unified part. After all, syscall impls are put into VM when initializing the VM. When you are initializing VM, you know for a fact if you use AOT mode, in this sense, a syscall module should already have the information whether current VM uses AOT mode or not.

And instruction_cycle_func is needed to compile aot code, this function is not available in syscall.

Both this function, and the actual syscall modules, are provided by the initialization code to the VM, so it's natural that we can feed this function to a syscall module as well.

The last: How to pass the compiled result to the outside? Only Box<AsmCoreMachine> can be accessed in syscall as a SupportMachine, and it does not have the ability to save aot_code

This will require some careful thinking, I think we need an interface for putting auxillary data or sorts to a SupportMachine instance.

xxuejie avatar Jun 15 '21 04:06 xxuejie