ruby-changes:68707
From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:12:30 +0900 (JST)
Subject: [ruby-changes:68707] 136bf983be (master): Fix bug with ujit code invalidation
https://git.ruby-lang.org/ruby.git/commit/?id=136bf983be From 136bf983beaf46bebd13026890eda8dafff279ce Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Tue, 19 Jan 2021 13:28:52 -0500 Subject: Fix bug with ujit code invalidation --- ujit_core.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/ujit_core.c b/ujit_core.c index c6ba70bb28..3211643f80 100644 --- a/ujit_core.c +++ b/ujit_core.c @@ -189,8 +189,7 @@ uint8_t* branch_stub_hit(uint32_t branch_idx, uint32_t target_idx) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L189 ctx_t* target_ctx = &branch->target_ctxs[target_idx]; //fprintf(stderr, "\nstub hit, branch idx: %d, target idx: %d\n", branch_idx, target_idx); - //fprintf(stderr, "cb->write_pos=%ld\n", cb->write_pos); - //fprintf(stderr, "branch->end_pos=%d\n", branch->end_pos); + //fprintf(stderr, "blockid.iseq=%p, blockid.idx=%d\n", target.iseq, target.idx); // If either of the target blocks will be placed next if (cb->write_pos == branch->end_pos) @@ -243,6 +242,8 @@ uint8_t* get_branch_target( https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L242 uint32_t target_idx ) { + //fprintf(stderr, "get_branch_target, block (%p, %d)\n", target.iseq, target.idx); + block_t* p_block = find_block_version(target, ctx); if (p_block) @@ -257,8 +258,6 @@ uint8_t* get_branch_target( https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L258 // branch_stub_hit(uint32_t branch_idx, uint32_t target_idx) uint8_t* stub_addr = cb_get_ptr(ocb, ocb->write_pos); - //fprintf(stderr, "REQUESTING STUB FOR IDX: %d\n", target.idx); - // Save the ujit registers push(ocb, REG_CFP); push(ocb, REG_EC); @@ -400,9 +399,14 @@ void gen_direct_jump( https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L399 void invalidate(block_t* block) { fprintf(stderr, "invalidating block (%p, %d)\n", block->blockid.iseq, block->blockid.idx); + fprintf(stderr, "block=%p\n", block); // Remove the version object from the map so we can re-generate stubs - st_delete(version_tbl, (st_data_t*)&block->blockid, NULL); + st_data_t key = (st_data_t)&block->blockid; + int success = st_delete(version_tbl, &key, NULL); + if (!success) { + rb_bug("failed to delete invalidated version"); + } // Get a pointer to the generated code for this block uint8_t* code_ptr = cb_get_ptr(cb, block->start_pos); @@ -413,6 +417,8 @@ void invalidate(block_t* block) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L417 uint32_t branch_idx = block->incoming[i]; branch_t* branch = &branch_entries[branch_idx]; uint32_t target_idx = (branch->dst_addrs[0] == code_ptr)? 0:1; + //fprintf(stderr, "branch_idx=%d, target_idx=%d\n", branch_idx, target_idx); + //fprintf(stderr, "blockid.iseq=%p, blockid.idx=%d\n", block->blockid.iseq, block->blockid.idx); // Create a stub for this branch target branch->dst_addrs[target_idx] = get_branch_target( @@ -427,7 +433,7 @@ void invalidate(block_t* block) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L433 if (target_next) { - // Reset the branch shape + // The new block will no longer be adjacent branch->shape = SHAPE_DEFAULT; } @@ -466,15 +472,17 @@ void invalidate(block_t* block) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L472 // Call continuation addresses on the stack can also be atomically replaced by jumps going to the stub. // For now this isn't an issue - // Free the block version object + // Free the old block version object free(block); + + fprintf(stderr, "invalidation done\n"); } int blockid_cmp(st_data_t arg0, st_data_t arg1) { const blockid_t *block0 = (const blockid_t*)arg0; const blockid_t *block1 = (const blockid_t*)arg1; - return block0->iseq == block1->iseq && block0->idx == block1->idx; + return (block0->iseq == block1->iseq) && (block0->idx == block1->idx); } st_index_t blockid_hash(st_data_t arg) -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/