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

ruby-changes:53601

From: k0kubun <ko1@a...>
Date: Tue, 20 Nov 2018 09:04:25 +0900 (JST)
Subject: [ruby-changes:53601] k0kubun:r65817 (trunk): process.c: do not try to pause MJIT

k0kubun	2018-11-20 09:04:19 +0900 (Tue, 20 Nov 2018)

  New Revision: 65817

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65817

  Log:
    process.c: do not try to pause MJIT
    
    while child handler is disabled.
    
    trying to fix [Bug #15320]

  Modified files:
    trunk/process.c
    trunk/test/ruby/test_process.rb
Index: process.c
===================================================================
--- process.c	(revision 65816)
+++ process.c	(revision 65817)
@@ -1502,26 +1502,12 @@ after_exec(void) https://github.com/ruby/ruby/blob/trunk/process.c#L1502
 }
 
 #if defined HAVE_WORKING_FORK || defined HAVE_DAEMON
+#define before_fork_ruby() before_exec()
 static void
-before_fork_ruby(void)
-{
-    if (mjit_enabled) {
-        /* avoid leaving locked mutex and units being modified for child process. */
-        mjit_pause(FALSE);
-    }
-
-    before_exec();
-}
-
-static void
-after_fork_ruby(int parent_p)
+after_fork_ruby(void)
 {
     rb_threadptr_pending_interrupt_clear(GET_THREAD());
     after_exec();
-
-    if (mjit_enabled && parent_p) { /* child is cared by `rb_thread_atfork` */
-        mjit_resume();
-    }
 }
 #endif
 
@@ -4007,12 +3993,14 @@ rb_fork_ruby(int *status) https://github.com/ruby/ruby/blob/trunk/process.c#L3993
 
     while (1) {
 	prefork();
+        if (mjit_enabled) mjit_pause(FALSE); /* Don't leave locked mutex to child. Note: child_handler must be enabled to pause MJIT. */
 	disable_child_handler_before_fork(&old);
 	before_fork_ruby();
 	pid = fork();
 	err = errno;
-        after_fork_ruby(pid > 0);
+        after_fork_ruby();
 	disable_child_handler_fork_parent(&old); /* yes, bad name */
+        if (mjit_enabled && pid > 0) mjit_resume(); /* child (pid == 0) is cared by rb_thread_atfork */
 	if (pid >= 0) /* fork succeed */
 	    return pid;
 	/* fork failed */
@@ -6434,10 +6422,11 @@ rb_daemon(int nochdir, int noclose) https://github.com/ruby/ruby/blob/trunk/process.c#L6422
 {
     int err = 0;
 #ifdef HAVE_DAEMON
+    if (mjit_enabled) mjit_pause(FALSE); /* Don't leave locked mutex to child. */
     before_fork_ruby();
     err = daemon(nochdir, noclose);
-    after_fork_ruby(TRUE);
-    rb_thread_atfork();
+    after_fork_ruby();
+    rb_thread_atfork(); /* calls mjit_resume() */
 #else
     int n;
 
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 65816)
+++ test/ruby/test_process.rb	(revision 65817)
@@ -1724,7 +1724,6 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1724
 
   if Process.respond_to?(:daemon)
     def test_daemon_default
-      skip 'IO.popen deadlocks with MJIT [Bug #15320]' if RubyVM::MJIT.enabled?
       data = IO.popen("-", "r+") do |f|
         break f.read if f
         Process.daemon
@@ -1774,7 +1773,6 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1773
 
     if File.directory?("/proc/self/task") && /netbsd[a-z]*[1-6]/ !~ RUBY_PLATFORM
       def test_daemon_no_threads
-        skip 'IO.popen deadlocks with MJIT [Bug #15320]' if RubyVM::MJIT.enabled?
         pid, data = IO.popen("-", "r+") do |f|
           break f.pid, f.readlines if f
           Process.daemon(true, true)

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

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