From 9fadab1aa8331e48f4cf6d2cce12a96fa20e0c4b Mon Sep 17 00:00:00 2001 From: k0kubun Date: Thu, 9 Aug 2018 09:58:07 +0000 Subject: mjit.c: add :wait option to RubyVM::MJIT.pause and wait until JIT queue is flushed when wait option is not passed or `wait: true` is passed. vm.c: ditto test/ruby/test_rubyvm_mjit.rb: added test for pause/resume test/lib/jit_support.rb: allow retrying MJIT on JITSupport level test/ruby/test_jit.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- mjit.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'mjit.c') diff --git a/mjit.c b/mjit.c index 148d4a9f1f..a3a6304850 100644 --- a/mjit.c +++ b/mjit.c @@ -1782,8 +1782,19 @@ stop_worker(void) /* Stop JIT-compiling methods but compiled code is kept available. */ VALUE -mjit_pause(void) +mjit_pause(int argc, VALUE *argv, VALUE recv) { + VALUE options = Qnil; + VALUE wait = Qtrue; + rb_scan_args(argc, argv, "0:", &options); + + if (!NIL_P(options)) { + static ID keyword_ids[1]; + if (!keyword_ids[0]) + keyword_ids[0] = rb_intern("wait"); + rb_get_kwargs(options, keyword_ids, 0, 1, &wait); + } + if (!mjit_enabled) { rb_raise(rb_eRuntimeError, "MJIT is not enabled"); } @@ -1791,6 +1802,20 @@ mjit_pause(void) return Qfalse; } + /* Flush all queued units with `wait: true` (default) */ + if (RTEST(wait)) { + struct timeval tv; + tv.tv_sec = 0; + tv.tv_usec = 1000; + + while (unit_queue.length > 0) { + CRITICAL_SECTION_START(3, "in mjit_pause for a worker wakeup"); + rb_native_cond_broadcast(&mjit_worker_wakeup); + CRITICAL_SECTION_FINISH(3, "in mjit_pause for a worker wakeup"); + rb_thread_wait_for(tv); + } + } + stop_worker(); return Qtrue; } -- cgit v1.2.3