Skip to content
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

Add Optional JIT compilation #91

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

richardpringle
Copy link

Closes #25

Will add more of a description later

Richard Pringle and others added 4 commits November 19, 2024 14:55
let cache = cache.clone();

move || {
let context = Box::leak(Box::new(revmc::llvm::Context::create()));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I leak this, does that make sense? I guess I shouldn't need to since context will live for the whole while loop below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to use with_llvm_context and nest the implementation inside of the closure

dbg!("compiled", &name);

let result =
unsafe { compiler.jit(&name, &code, spec_id) }.expect("catastrophe");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused as to the relationship between a compiler, a module, and a contract.
Should I be compiling all the code with the same compiler?


cache.lock().unwrap().insert(hash, result);

unsafe { compiler.clear().expect("could not clear") };
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this is wrong, as the functions that I'm storing in the hashmap are just linked back to this compiler. When I call clear and try to call the cached function, it's a use-after-free and I segfault.

I'm obviously thinking about using the compiler the wrong way, how should I be thinking about it?

I've read over your code here, but I believe that's for aot compilation instead of jit since you're writing everything out to files.

Should I just be creating a new compiler every time and storing the compiler as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I just be creating a new compiler every time and storing the compiler as well?

Yes that's right

let cache = cache.clone();

move || {
let context = Box::leak(Box::new(revmc::llvm::Context::create()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to use with_llvm_context and nest the implementation inside of the closure


cache.lock().unwrap().insert(hash, result);

unsafe { compiler.clear().expect("could not clear") };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I just be creating a new compiler every time and storing the compiler as well?

Yes that's right

// TODO: not sure if this is correct, I don't see a call-site for this method
let spec_id = revm_spec(chain_spec, &Head::default());

compiler::ExternalContext::new(spec_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec ID should also be dynamic and received from the channel

I thought that the context was created once per config, but that was not the case. This commit moves the compiler thread initialization to the config initialization and it all seems to work.
@onbjerg onbjerg added C-enhancement New feature or request A-node labels Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-node C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate revmc jit
3 participants