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

YJIT: Fix leak in compilation loop #5229

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions bootstraptest/test_yjit.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
assert_normal_exit %q{
# regression test for a leak caught by an asert on --yjit-call-threshold=2
Foo = 1

eval("def foo = [#{(['Foo,']*256).join}]")

foo
foo

Object.send(:remove_const, :Foo)
}

assert_equal '[nil, nil, nil, nil, nil, nil]', %q{
[NilClass, TrueClass, FalseClass, Integer, Float, Symbol].each do |klass|
klass.class_eval("def foo = @foo")
Expand Down
13 changes: 8 additions & 5 deletions yjit_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,15 +747,14 @@ gen_block_version(blockid_t blockid, const ctx_t *start_ctx, rb_execution_contex

// Generate code for the first block
block = gen_single_block(blockid, start_ctx, ec);
batch_success = block && compiled_count < MAX_PER_BATCH;

if (batch_success) {
if (block) {
// Track the block
add_block_version(block);

batch[compiled_count] = block;
compiled_count++;
}
batch_success = block;

// For each successor block to compile
while (batch_success) {
Expand All @@ -780,8 +779,12 @@ gen_block_version(blockid_t blockid, const ctx_t *start_ctx, rb_execution_contex
// Generate code for the current block using context from the last branch.
blockid_t requested_id = last_branch->targets[0];
const ctx_t *requested_ctx = &last_branch->target_ctxs[0];
block = gen_single_block(requested_id, requested_ctx, ec);
batch_success = block && compiled_count < MAX_PER_BATCH;

batch_success = compiled_count < MAX_PER_BATCH;
if (batch_success) {
block = gen_single_block(requested_id, requested_ctx, ec);
batch_success = block;
}

// If the batch failed, stop
if (!batch_success) {
Expand Down