aboutsummaryrefslogtreecommitdiffstats
path: root/mjit.c
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-09 09:58:07 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-09 09:58:07 +0000
commit9fadab1aa8331e48f4cf6d2cce12a96fa20e0c4b (patch)
tree29f7ccc04cc36acd612f395800b09ba933514a82 /mjit.c
parent04740c0cb015fc0f85691b06e61b76557db06c34 (diff)
downloadruby-9fadab1aa8331e48f4cf6d2cce12a96fa20e0c4b.tar.gz
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
Diffstat (limited to 'mjit.c')
-rw-r--r--mjit.c27
1 files changed, 26 insertions, 1 deletions
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;
}