summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2020-03-20 06:12:36 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2020-03-20 06:12:36 +0000
commitc01e52eb715c1583f594a1c6e19de249f8e9b439 (patch)
treea21e6bcf4aef2cce913e1a107787d20a3e4d1e3e
parent1e4174b45c4b9c3d27ef68e532d58aae22457bbf (diff)
merge revision(s) adcf0316d1ecedae2a9157ad941550e0c0fb510b: [Backport #16664]
Prevent unloading methods used in root_fiber while calling another Fiber (#2939) Fixing SEGVs like: http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/2744905 http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/2744420 http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/2741400 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--cont.c21
-rw-r--r--internal.h2
-rw-r--r--mjit.c3
-rw-r--r--test/ruby/test_jit.rb32
-rw-r--r--version.h2
5 files changed, 51 insertions, 9 deletions
diff --git a/cont.c b/cont.c
index da469b6cd5..c19bcdd447 100644
--- a/cont.c
+++ b/cont.c
@@ -627,6 +627,15 @@ cont_save_thread(rb_context_t *cont, rb_thread_t *th)
}
static void
+cont_init_mjit_cont(rb_context_t *cont)
+{
+ VM_ASSERT(cont->mjit_cont == NULL);
+ if (mjit_enabled) {
+ cont->mjit_cont = mjit_cont_new(&(cont->saved_ec));
+ }
+}
+
+static void
cont_init(rb_context_t *cont, rb_thread_t *th)
{
/* save thread context */
@@ -635,9 +644,7 @@ cont_init(rb_context_t *cont, rb_thread_t *th)
cont->saved_ec.local_storage = NULL;
cont->saved_ec.local_storage_recursive_hash = Qnil;
cont->saved_ec.local_storage_recursive_hash_for_trace = Qnil;
- if (mjit_enabled) {
- cont->mjit_cont = mjit_cont_new(&cont->saved_ec);
- }
+ cont_init_mjit_cont(cont);
}
static rb_context_t *
@@ -654,6 +661,14 @@ cont_new(VALUE klass)
return cont;
}
+void
+rb_fiber_init_mjit_cont(struct rb_fiber_struct *fiber)
+{
+ // Currently this function is meant for root_fiber. Others go through cont_new.
+ // XXX: Is this mjit_cont `mjit_cont_free`d?
+ cont_init_mjit_cont(&fiber->cont);
+}
+
#if 0
void
show_vm_stack(const rb_execution_context_t *ec)
diff --git a/internal.h b/internal.h
index e1e4cc057d..9583e8388e 100644
--- a/internal.h
+++ b/internal.h
@@ -1384,9 +1384,11 @@ VALUE rb_dbl_complex_new_polar_pi(double abs, double ang);
struct rb_thread_struct;
/* cont.c */
+struct rb_fiber_struct;
VALUE rb_obj_is_fiber(VALUE);
void rb_fiber_reset_root_local_storage(struct rb_thread_struct *);
void ruby_register_rollback_func_for_ensure(VALUE (*ensure_func)(ANYARGS), VALUE (*rollback_func)(ANYARGS));
+void rb_fiber_init_mjit_cont(struct rb_fiber_struct *fiber);
/* debug.c */
PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
diff --git a/mjit.c b/mjit.c
index a0310ae96c..b547277126 100644
--- a/mjit.c
+++ b/mjit.c
@@ -655,6 +655,9 @@ mjit_init(struct mjit_options *opts)
rb_native_cond_initialize(&mjit_worker_wakeup);
rb_native_cond_initialize(&mjit_gc_wakeup);
+ /* Make sure root_fiber's saved_ec is scanned by mark_ec_units */
+ rb_fiber_init_mjit_cont(GET_EC()->fiber_ptr);
+
/* Initialize class_serials cache for compilation */
valid_class_serials = rb_hash_new();
rb_obj_hide(valid_class_serials);
diff --git a/test/ruby/test_jit.rb b/test/ruby/test_jit.rb
index 0155d3fd86..37dc18f1bf 100644
--- a/test/ruby/test_jit.rb
+++ b/test/ruby/test_jit.rb
@@ -12,6 +12,10 @@ class TestJIT < Test::Unit::TestCase
IGNORABLE_PATTERNS = [
/\ASuccessful MJIT finish\n\z/,
]
+ MAX_CACHE_PATTERNS = [
+ /\AJIT compaction \([^)]+\): .+\n\z/,
+ /\ANo units can be unloaded -- .+\n\z/,
+ ]
# trace_* insns are not compiled for now...
TEST_PENDING_INSNS = RubyVM::INSTRUCTION_NAMES.select { |n| n.start_with?('trace_') }.map(&:to_sym) + [
@@ -568,11 +572,7 @@ class TestJIT < Test::Unit::TestCase
end
def test_nothing_to_unload_with_jit_wait
- ignorable_patterns = [
- /\AJIT compaction \([^)]+\): .+\n\z/,
- /\ANo units can be unloaded -- .+\n\z/,
- ]
- assert_eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", stdout: 'hello', success_count: 11, max_cache: 10, ignorable_patterns: ignorable_patterns)
+ assert_eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", stdout: 'hello', success_count: 11, max_cache: 10, ignorable_patterns: MAX_CACHE_PATTERNS)
begin;
def a1() a2() end
def a2() a3() end
@@ -589,6 +589,28 @@ class TestJIT < Test::Unit::TestCase
end;
end
+ def test_unload_units_on_fiber
+ assert_eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", stdout: 'hello', success_count: 12, max_cache: 10, ignorable_patterns: MAX_CACHE_PATTERNS)
+ begin;
+ def a1() a2(false); a2(true) end
+ def a2(a) a3(a) end
+ def a3(a) a4(a) end
+ def a4(a) a5(a) end
+ def a5(a) a6(a) end
+ def a6(a) a7(a) end
+ def a7(a) a8(a) end
+ def a8(a) a9(a) end
+ def a9(a) a10(a) end
+ def a10(a)
+ if a
+ Fiber.new { a11 }.resume
+ end
+ end
+ def a11() print('hello') end
+ a1
+ end;
+ end
+
def test_unload_units_and_compaction
Dir.mktmpdir("jit_test_unload_units_") do |dir|
# MIN_CACHE_SIZE is 10
diff --git a/version.h b/version.h
index 83bdf8b727..864bd34b06 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.6.6"
#define RUBY_RELEASE_DATE "2020-03-20"
-#define RUBY_PATCHLEVEL 137
+#define RUBY_PATCHLEVEL 138
#define RUBY_RELEASE_YEAR 2020
#define RUBY_RELEASE_MONTH 3