[前][次][番号順一覧][スレッド一覧]

ruby-changes:70114

From: Alan <ko1@a...>
Date: Thu, 9 Dec 2021 07:00:11 +0900 (JST)
Subject: [ruby-changes:70114] 82bb9cedd3 (master): YJIT: Fix leak in compilation loop

https://git.ruby-lang.org/ruby.git/commit/?id=82bb9cedd3

From 82bb9cedd3fb41fd78d612153c35fdb8c5344d5a Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Wed, 8 Dec 2021 12:24:37 -0500
Subject: YJIT: Fix leak in compilation loop

Previously, when there are too many blocks in a batch, the last block in
the batch is not tracked in the array of batches and not freed.
---
 bootstraptest/test_yjit.rb | 12 ++++++++++++
 yjit_core.c                | 13 ++++++++-----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index e50d78a9dc5..2ac37df0a23 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_yjit.rb#L1
+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")
diff --git a/yjit_core.c b/yjit_core.c
index b226f8bd348..02f629d9ce0 100644
--- a/yjit_core.c
+++ b/yjit_core.c
@@ -747,15 +747,14 @@ gen_block_version(blockid_t blockid, const ctx_t *start_ctx, rb_execution_contex https://github.com/ruby/ruby/blob/trunk/yjit_core.c#L747
 
     // 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) {
@@ -780,8 +779,12 @@ gen_block_version(blockid_t blockid, const ctx_t *start_ctx, rb_execution_contex https://github.com/ruby/ruby/blob/trunk/yjit_core.c#L779
         // 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) {
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]