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

Fix block invalidation with new backend. Enable more btests on x86 #359

Merged
merged 2 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/yjit-new-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,25 @@ jobs:
bootstraptest/test_gc.rb \
bootstraptest/test_io.rb \
bootstraptest/test_jump.rb \
bootstraptest/test_literal.rb \
bootstraptest/test_literal_suffix.rb \
bootstraptest/test_load.rb \
bootstraptest/test_marshal.rb \
bootstraptest/test_massign.rb \
bootstraptest/test_method.rb \
bootstraptest/test_objectspace.rb \
bootstraptest/test_proc.rb \
bootstraptest/test_string.rb \
bootstraptest/test_struct.rb \
bootstraptest/test_thread.rb \
bootstraptest/test_yjit_new_backend.rb \
bootstraptest/test_yjit_rust_port.rb

# These are the btests we can't run yet on x86:
#bootstraptest/test_block.rb (missing opt_send)
#bootstraptest/test_insns.rb (missing opt_send)
#bootstraptest/test_literal.rb (bug in x86_split pass)
#bootstraptest/test_proc.rb (bug in x86_split pass)
#bootstraptest/test_ractor.rb (splitting error?)
#bootstraptest/test_syntax.rb (missing opt_send)
#bootstraptest/test_thread.rb (deadlock)
#bootstraptest/test_yjit.rb (multiple bugs)
#bootstraptest/test_yjit_30k_ifelse.rb (missing opt_send)
#bootstraptest/test_yjit_30k_methods.rb (missing opt_send)
Expand Down
61 changes: 37 additions & 24 deletions bootstraptest/test_yjit_new_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@
# To look up Ruby snippets using specific instructions, see:
# https://kddnewton.com/yarv/

# Microbenchmark with a loop, opt_lt
assert_equal '55', %q{
def foo(n)
i = 0
s = 0
while i < n do
i += 1
s += i
end
s
end
foo(10)
}

# Small recursive microbenchmark
assert_equal '21', %q{
def fib(n)
if n < 2
return n
end
return fib(n-1) + fib(n-2)
end
fib(8)
}

assert_equal '1', %q{
def foo()
1
Expand Down Expand Up @@ -303,32 +328,20 @@ def bar
[Foo.new.foo, bar]
}

# BOP redefinition works on Integer#<
assert_equal 'false', %q{
def less_than x
maximecb marked this conversation as resolved.
Show resolved Hide resolved
x < 10
end

less_than 2
less_than 2




# Microbenchmark with a loop, opt_lt
assert_equal '55', %q{
def foo(n)
i = 0
s = 0
while i < n do
i += 1
s += i
end
s
class Integer
def < x
false
end
foo(10)
}
end

# Small recursive microbenchmark
assert_equal '21', %q{
def fib(n)
if n < 2
return n
end
return fib(n-1) + fib(n-2)
end
fib(8)
less_than 2
}
15 changes: 8 additions & 7 deletions yjit/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ pub fn invalidate_block_version(blockref: &BlockRef) {
// machine code that some other thread is running.

let block = blockref.borrow();
let cb = CodegenGlobals::get_inline_cb();
let mut cb = CodegenGlobals::get_inline_cb();
let ocb = CodegenGlobals::get_outlined_cb();

verify_blockid(block.blockid);
Expand Down Expand Up @@ -2069,11 +2069,13 @@ pub fn invalidate_block_version(blockref: &BlockRef) {
// if (block.start_addr >= cb_get_ptr(cb, yjit_codepage_frozen_bytes)) // Don't patch frozen code region

// Patch in a jump to block.entry_exit.

let cur_pos = cb.get_write_ptr();
cb.set_write_ptr(block_start);

//jmp_ptr(cb, block_entry_exit);
todo!("jmp_ptr with new assembler");
let mut asm = Assembler::new();
asm.jmp(block_entry_exit.into());
asm.compile(&mut cb);

assert!(
cb.get_write_ptr() < block_end,
Expand Down Expand Up @@ -2154,13 +2156,12 @@ pub fn invalidate_block_version(blockref: &BlockRef) {
// change this in the future when we support optional parameters because
// they enter the function with a non-zero PC
if block.blockid.idx == 0 {
// TODO:
// We could reset the exec counter to zero in rb_iseq_reset_jit_func()
// so that we eventually compile a new entry point when useful
unsafe { rb_iseq_reset_jit_func(block.blockid.iseq) };
}

// TODO:
// May want to recompile a new entry point (for interpreter entry blocks)
// This isn't necessary for correctness

// FIXME:
// Call continuation addresses on the stack can also be atomically replaced by jumps going to the stub.

Expand Down