Skip to content

Commit

Permalink
Fix assertions in invalidate_block_version(), add small repro (#14)
Browse files Browse the repository at this point in the history
* Fix block invalidation assertions

* Add Alan's small repro for double invalidation bug
  • Loading branch information
maximecb authored and noahgibbs committed Oct 1, 2021
1 parent 7878492 commit 0d25867
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
22 changes: 22 additions & 0 deletions bootstraptest/test_yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ def alias_then_hash(klass, method_to_redefine)
retval
}

# Code invalidation and opt_getinlinecache
assert_normal_exit %q{
class Foo; end
# Uses the class constant Foo
def use_constant(arg)
[Foo.new, arg]
end
def propagate_type
i = Array.new
i.itself # make it remember that i is on-heap
use_constant(i)
end
propagate_type
propagate_type
use_constant(Foo.new)
class Jo; end # bump global constant state
use_constant(3)
}

# Method redefinition (code invalidation) and GC
assert_equal '7', %q{
def bar()
Expand Down
9 changes: 5 additions & 4 deletions yjit_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,11 @@ invalidate_block_version(block_t* block)
{
branch_t* branch = rb_darray_get(block->incoming, incoming_idx);
uint32_t target_idx = (branch->dst_addrs[0] == code_ptr)? 0:1;
RUBY_ASSERT(!branch->blocks[target_idx] || branch->blocks[target_idx] == block);
RUBY_ASSERT(branch->dst_addrs[target_idx] == code_ptr);
RUBY_ASSERT(branch->blocks[target_idx] == block);

// Mark this target as being a stub
branch->blocks[target_idx] = NULL;

// Create a stub for this branch target
branch->dst_addrs[target_idx] = get_branch_target(
Expand All @@ -898,9 +902,6 @@ invalidate_block_version(block_t* block)
target_idx
);

// Mark this target as being a stub
branch->blocks[target_idx] = NULL;

// Check if the invalidated block immediately follows
bool target_next = block->start_pos == branch->end_pos;

Expand Down

0 comments on commit 0d25867

Please sign in to comment.