Граф коммитов

318 Коммитов

Автор SHA1 Сообщение Дата
normal c6b85fcd01 timer_thread: do not close pipes around fork
There's actually no need to close the pipes used by the
sleepy timer thread before forking, only to stop the timer
thread itself.

Instead, we only close the parent pipes in the child process,
either via close-on-exec flag or when reinitializing the timer
thread.

This change will be necessary when we allow
rb_wait_for_single_fd and rb_thread_fd_select to wait on the
timer_thread_pipe.normal[0] directly and eliminate timer thread.

I don't anticipate compatibility problems with this change
alone.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-12 23:23:25 +00:00
normal b205642518 thread_pthread: avoid redundant error message on pipe2() fail
Seeing one error for pipe creation is enough.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-11 08:49:23 +00:00
normal 23f4ba46de thread_pthread.c: use mask for timer implementation
timer-thread will continue to be supported, but future
"timer" implementation may not be a thread.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-11 08:49:18 +00:00
normal c93adfc170 mjit: get rid of memory leak in pause+resume loop
pthread_atfork is not idempotent and repeatedly calling it
causes it to register the same hook repeatedly; leading to
unbound memory growth.

Ruby already has a (confusing-named) internal API for to call
in the forked child process: rb_thread_atfork
Call the MJIT child_after_fork hook inside that to prevent
unbound growth with the following loop:

    loop do
      RubyVM::MJIT.pause
      RubyVM::MJIT.resume
    end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63884 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-08 07:27:24 +00:00
normal 44fc3d08eb unrevert r63852 but keep SIGCHLD path disabled for win32
Reading win32/win32.c waitpid implementation, maybe waitpid(-1, ...)
on that platform will never conflict with mjit use of waitpid.

In any case, I've added WAITPID_USE_SIGCHLD macro to vm_core.h
so it can be easy for Linux/BSD users to test (hopefully!)
win32-compatible code.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-05 03:02:33 +00:00
naruse df4a126d65 Revert r63758 and related commits
The change is unstable on Windows. Please re-commit it when it correctly
supports Windows.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63852 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-04 15:08:56 +00:00
normal d9dac20bb3 thread_pthread.c: pass rb_vm_t to timer_thread_sleep
I love `container_of' for generic data structures, but
in this case it's unnecessary and slightly harder-to-read.

This will make "Timeout in VM" slightly easier-to-read:
https://bugs.ruby-lang.org/issues/14859

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-04 01:26:31 +00:00
normal 45cdc834c4 thread_pthread.c (native_thread_destroy): clear native TSD pointer
mwrap <https://80x24.org/mwrap/> interposes malloc functions and
checks for GVL existence to determine Ruby source locations of
malloc calls.  pthread_getattr_np (from get_stack) may call
realloc to get the CPU set size; so when using the thread-cache,
ruby_thread_has_gvl_p() may hit a false positive on reused
threads with lingering rb_thread_t in thread-specific data.

This was causing mwrap to call rb_source_location_cstr() and
crash because it was pointed to a zero ec->cfp->iseq.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-03 08:30:16 +00:00
normal ce2a3b40ed use SIGCHLD_LOSSY to enable waitpid polling mode
Some systems lack SIGCHLD or have incomplete SIGCHLD
implementations.  So enable polling mode for them.

[ruby-core:87705] [Bug #14867]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-30 00:51:57 +00:00
normal 054a412d54 hijack SIGCHLD handler for internal use
Use a global SIGCHLD handler to guard all callers of rb_waitpid.
To work safely with multi-threaded programs, we introduce a
VM-wide waitpid_lock to be acquired BEFORE fork/vfork spawns the
process.  This is to be combined with the new ruby_waitpid_locked
function used by mjit.c in a non-Ruby thread.

Ruby-level SIGCHLD handlers registered with Signal.trap(:CHLD)
continues to work as before and there should be no regressions
in any existing use cases.

Splitting the wait queues for PID > 0 and groups (PID <= 0)
ensures we favor PID > 0 callers.

The disabling of SIGCHLD in rb_f_system is longer necessary,
as we use deferred signal handling and no longer make ANY
blocking waitpid syscalls in other threads which could "beat"
the waitpid call made by rb_f_system.

We prevent SIGCHLD from firing in normal Ruby Threads and only
enable it in the timer-thread, to prevent spurious wakeups
from in test/-ext-/gvl/test_last_thread.rb with MJIT enabled.

I've tried to guard as much of the code for RUBY_SIGCHLD==0
using C "if" statements rather than CPP "#if" so to reduce
the likelyhood of portability problems as the compiler will
see more code.

We also work to suppress false-positives from
Process.wait(-1, Process::WNOHANG) to quiets warnings from
spec/ruby/core/process/wait2_spec.rb with MJIT enabled.

Lastly, we must implement rb_grantpt for ext/pty.  We need a
MJIT-compatible way of supporting grantpt(3) which may spawn
the `pt_chown' binary and call waitpid(2) on it.

[ruby-core:87605] [Ruby trunk Bug#14867]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-27 03:14:30 +00:00
k0kubun ea0cede5aa mjit.c: initial cygwin support
thread_pthread.c: Drop pthread_attr_setscope usage. It seems that,
at least on Linux and macOS, PTHREAD_SCOPE_PROCESS is not supported
and thus PTHREAD_SCOPE_SYSTEM should be used by default.

Let's just stop calling this until we find some platform that needs
`pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM)`.

[Misc #14854]

From: fd0 (Daisuke Fujimura)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-23 07:21:12 +00:00
normal b445543974 thread_pthread.c (native_sleep): do not clear unblock.arg
It is unnecessary to clear unblock.arg once unblock.func is
cleared, and unblock_function_clear in thread.c doesn't
touch it, either.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-23 03:47:54 +00:00
normal 48efa44719 thread_pthread.c: fix non-sleepy timer-thread with fork
This fixes bootstraptest/test_fork.rb for systems with
sleepy timer thread disabled.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-20 23:38:21 +00:00
normal 0e2ba8495e thread_pthread.c: microptimize vm->gvl.waiting checks
"gvl.waiting" is volatile, so the compiler won't perform
these optimizations for us.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-17 03:27:45 +00:00
normal cc6342fec3 thread_pthread.c: fix non-sleepy timer thread build
I guess everybody has poll() and fcntl() nowadays, as
the non-sleepy timer thread build has been broken for
years, now.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-17 02:56:28 +00:00
normal 832b601e49 Initialize condattr_monotonic via pthread_condattr_init
Some operating systems will work without calling
pthread_condattr_init, but some won't (such as OpenBSD). Prior
to r63238, pthread_condattr_init was always called before
calling pthread_condattr_setclock.

From: Jeremy Evans <code@jeremyevans.net>
[ruby-core:87345] [Ruby trunk Bug#14807]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-01 21:56:11 +00:00
normal 72ad081145 thread_pthread.c: avoid reading th pointer for thread cache
I suspect GC may free the rb_thread_t (th) pointer by the time
we call register_cached_thread_and_wait.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-24 02:52:46 +00:00
normal fa31e1a418 thread_pthread.c: enable thread cache by default
Since r62466 ("thread_pthread.c: shorten and fix thread cache implementation"),
our thread cache is no longer buggy with programs using fork.
This makes significant improvements in vm_thread_alive_check1
and vm_thread_create_join benchmarks and does not introduce
regressions.

Unlike old thread cache, I've changed the cache to only last 3
seconds since per-thread setup in most programs rarely takes
more than a few milliseconds to re-establish things like network
connections.  This is configurable by changing the THREAD_CACHE_TIME
variable.

I hope this allows users to simplify their code by removing the
need for thread pools in many cases.

vm_thread_alive_check1 10.872   0.150
vm_thread_close         1.988   2.027
vm_thread_condvar1      0.751   0.767
vm_thread_condvar2      0.744   0.752
vm_thread_create_join   5.296   2.343
vm_thread_mutex1        1.911   1.892
vm_thread_mutex2        1.902   1.896
vm_thread_mutex3        2.389   2.313
vm_thread_pass          0.271   0.272
vm_thread_pass_flood    0.175   0.179
vm_thread_pipe          0.460   0.436
vm_thread_queue         0.453   0.446
vm_thread_sized_queue   0.547   0.547
vm_thread_sized_queue2  1.417   1.413
vm_thread_sized_queue3  1.410   1.426
vm_thread_sized_queue4  0.787   0.791

Speedup ratio: compare with the result of `trunk' (greater is better)
name    built
vm_thread_alive_check1 72.456
vm_thread_close         0.981
vm_thread_condvar1      0.979
vm_thread_condvar2      0.990
vm_thread_create_join   2.260
vm_thread_mutex1        1.010
vm_thread_mutex2        1.003
vm_thread_mutex3        1.033
vm_thread_pass          0.994
vm_thread_pass_flood    0.980
vm_thread_pipe          1.055
vm_thread_queue         1.016
vm_thread_sized_queue   0.999
vm_thread_sized_queue2  1.003
vm_thread_sized_queue3  0.989
vm_thread_sized_queue4  0.995

[ruby-core:87030] [Feature #14757]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-23 21:16:56 +00:00
normal 0f0311df0a thread: reduce GET_THREAD calls
This allows native_sleep to use less stack (80 -> 64 bytes on
x86-64) for GVL_UNLOCK_BEGIN/END.  For future APIs, we will pass
`ec` or `th` around anyways, so the BLOCKING_REGION change
should be beneficial in the future.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-16 21:54:42 +00:00
nobu 1222560ad1 thread_pthread.c: fallback to CLOCK_REALTIME
* thread_pthread.c (Init_native_thread): fallback to the default
  CLOCK_REALTIME when failed to set to CLOCK_MONOTONIC, e.g. on
  Solaris.  [Misc #14497]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-23 02:07:11 +00:00
normal ed590bdbfc thread*: all condvars are monotonic
There's no reason to use CLOCK_REALTIME for any condvars in Ruby.
Indeed, we initialized all condvars with RB_CONDATTR_CLOCK_MONOTONIC
anyway; so simplify our code and reduce ifdefs.

[ruby-core:85639] [Misc #14497]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-22 12:09:07 +00:00
normal 475b4aa40b simplify altstack and enable reuse with thread cache
Instead of allocating and registering the altstack in different
places, do it together to reduce code and improve readability.
When thread cache is enabled, storing altstack in rb_thread_t
is wasteful and we may reuse altstack in the same pthread.

This also lets us clearly allow use of xmalloc to allow GC to
recover from ENOMEM.

[ruby-core:85621] [Feature #14487]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-20 21:38:27 +00:00
nobu 2311087b68 Tiny Fix for ASYNC BUG error message copying
The previous logic would overwrite the error message, replacing the message with the `fd` number.

This tiny update will print the message in full.

(I'm trying to debug an issue with the timer thread on my machine and the lack of error messages makes it really hard).

[Fix GH-1829]

From: Bo <bo@bowild.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-05 06:56:09 +00:00
normal 92dd6d8445 thread_pthread.c: spelling ("cancellation")
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-19 09:28:56 +00:00
normal 4651ef77d2 thread_pthread.c: fix thread cache for non-monotonic clock
I noticed this because of https://bugs.ruby-lang.org/issues/14494

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62484 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-19 09:28:51 +00:00
normal 3cadd10ac5 thread_pthread.c (native_thread_create): remove needless attrp
Followup-to: r61719 (commit e8f40bd8f8)
  ("thread_pthread: remove HAVE_PTHREAD_ATTR_INIT ifdefs")
  [ruby-core:84758] [Misc #14342]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-19 00:30:43 +00:00
normal cfeb344bf2 thread_pthread.c (rb_thread_create_mjit_thread): destroy attr
This is required on some platforms to avoid leaks.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-19 00:23:00 +00:00
normal bff57efca1 thread_pthread.c (thread cache): destroy cond after unlock
No need to hold a lock while destroying a condition variable.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18 23:58:35 +00:00
normal 7a8460ed5a thread_pthread.c (rb_thread_create_mjit): set detach before create
This should be slightly cheaper on NPTL as it does not rely on
atomics to set pd->joinid.   We already use pthread_attr_setdetachstate,
so it won't introduce new problems by using a function we did not
use before.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18 23:58:30 +00:00
nobu ae62ab3302 adjust indent
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18 09:23:47 +00:00
normal 4a57b88b19 thread_pthread.c: shorten and fix thread cache implementation
Update to use ccan/list for constant-time delete on expiry and
avoid malloc.  We must also initialize th->thread_id upon thread
reuse so Thread#name= works immediately upon thread creation.

We must also reinitialize the cache mutex and list_head on
fork like we do with GVL and timer thread mutexes.
While we're at it, use monotonic clock for timeout to avoid
system time changes.

"make exam TESTS='-x test_time_tz'" passes with USE_THREAD_CACHE
enabled (but remains off, here).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18 07:54:10 +00:00
normal 8f47542d58 thread_pthread.c (native_cond_timeout): simplify
Rely on getclockofday for CLOCK_MONOTONIC, avoid needless
variables, and rely on overflow protection from timespec_add
instead of coding our own.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-18 02:12:23 +00:00
mame 50700c4d3c thread_pthread.c: Use `getpagesize()` when `pthread_attr_getguardsize` is unavailable
This is also for emscripten.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-15 01:59:16 +00:00
nobu b0cf1c234c fix up r62272
* thread.c (timeval_for): tv_usec is suseconds_t which may be
  smaller than long.

* thread_pthread.c (native_cond_timeout): ret is now used in
  CLOCK_MONOTONIC case only.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-07 06:14:56 +00:00
normal 0abd9b7f25 thread.c: favor timespec internally
This results in fewer conversion on common modern systems with
support for clock_gettime, pthread_cond_timedwait and ppoll.
gettimeofday is declared obsolete by POSIX.1-2008, so it is yet
another reason to move away from it.  This also appears to result
in the reduction of compatibility code required for dealing
with inconsistent implementations of "struct timeval".tv_sec

In the future, this will also result in fewer conversions for
kqueue and pselect if we elect to use them.

[ruby-core:85416] [Feature #14452]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62272 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-07 01:57:14 +00:00
nobu 1f003810c2 thread_pthread.c: cast inside rb_thread_create_mjit_thread
* thread_pthread.c (rb_thread_create_mjit_thread): cast
  worker_func pointer to void pointer inside.  adjusted to the
  declaration in mjit.c and the definition in thread_win32.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-06 01:42:38 +00:00
shyouhei 8427fca49b assigning void* to a function pointer is a POSIXism
No implicit cast is defined between these types.  Should be explicit.
Also, NULL is defined to be ((void*)0) so not usable as a function
pointer value.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-05 04:17:44 +00:00
k0kubun fd44a5777f mjit.c: merge MJIT infrastructure
that allows to JIT-compile Ruby methods by generating C code and
using C compiler.  See the first comment of mjit.c to know what this
file does.

mjit.c is authored by Vladimir Makarov <vmakarov@redhat.com>.
After he invented great method JIT infrastructure for MRI as MJIT,
Lars Kanis <lars@greiz-reinsdorf.de> sent the patch to support MinGW
in MJIT. In addition to merging it, I ported pthread to Windows native
threads. Now this MJIT infrastructure can be compiled on Visual Studio.

This commit simplifies mjit.c to decrease code at initial merge. For
example, this commit does not provide multiple JIT threads support.
We can resurrect them later if we really want them, but I wanted to minimize
diff to make it easier to review this patch.

`/tmp/_mjitXXX` file is renamed to `/tmp/_ruby_mjitXXX` because non-Ruby
developers may not know the name "mjit" and the file name should make
sure it's from Ruby and not from some harmful programs.  TODO: it may be
better to store this to some temporary directory which Ruby is already using
by Tempfile, if it's not bad for performance.

mjit.h: New. It has `mjit_exec` interface similar to `vm_exec`, which is
for triggering MJIT. This drops interface for AOT compared to the original
MJIT.

Makefile.in: define macros to let MJIT know the path of MJIT header.
Probably we can refactor this to reduce the number of macros (TODO).
win32/Makefile.sub: ditto.

common.mk: compile mjit.o and mjit_compile.o. Unlike original MJIT, this
commit separates MJIT infrastructure and JIT compiler code as independent
object files. As initial patch is NOT going to have ultra-fast JIT compiler,
it's likely to replace JIT compiler, e.g. original MJIT's compiler or some
future JIT impelementations which are not public now.

inits.c: define MJIT module. This is added because `MJIT.enabled?` was
necessary for testing.
test/lib/zombie_hunter.rb: skip if `MJIT.enabled?`. Obviously this
wouldn't work with current code when JIT is enabled.
test/ruby/test_io.rb: skip this too. This would make no sense with MJIT.

ruby.c: define MJIT CLI options. As major difference from original MJIT,
"-j:l"/"--jit:llvm" are renamed to "--jit-cc" because I want to support
not only gcc/clang but also cl.exe (Visual Studio) in the future. But it
takes only "--jit-cc=gcc", "--jit-cc=clang" for now. And only long "--jit"
options are allowed since some Ruby committers preferred it at Ruby
developers Meeting on January, and some of options are renamed.
This file also triggers to initialize MJIT thread and variables.
eval.c: finalize MJIT worker thread and variables.
test/ruby/test_rubyoptions.rb: fix number of CLI options for --jit.

thread_pthread.c: change for pthread abstraction in MJIT. Prefix rb_ for
functions which are used by other files.
thread_win32.c: ditto, for Windows.  Those pthread porting is one of major
works that YARV-MJIT created, which is my fork of MJIT, in Feature 14235.
thread.c: follow rb_ prefix changes

vm.c: trigger MJIT call on VM invocation. Also trigger `mjit_mark` to avoid
SEGV by race between JIT and GC of ISeq. The improvement was provided by
wanabe <s.wanabe@gmail.com>.
In JIT compiler I created and am going to add in my next commit, I found
that having `mjit_exec` after `vm_loop_start:` is harmful because the
JIT-ed function doesn't proceed other ISeqs on RESTORE_REGS of leave insn.
Executing non-FINISH frame is unexpected for my JIT compiler and
`exception_handler` triggers executions of such ISeqs. So `mjit_exec`
here should be executed only when it directly comes from `vm_exec` call.
`RubyVM::MJIT` module and `.enabled?` method is added so that we can skip
some tests which don't expect JIT threads or compiler file descriptors.

vm_insnhelper.h: trigger MJIT on method calls during VM execution.

vm_core.h: add fields required for mjit.c. `bp` must be `cfp[6]` because
rb_control_frame_struct is likely to be casted to another struct. The
last position is the safest place to add the new field.
vm_insnhelper.c: save initial value of cfp->ep as cfp->bp. This is an
optimization which are done in both MJIT and YARV-MJIT. So this change
is added in this commit. Calculating bp from ep is a little heavy work,
so bp is kind of cache for it.

iseq.c: notify ISeq GC to MJIT. We should know which iseq in MJIT queue
is GCed to avoid SEGV.  TODO: unload some GCed units in some safe way.

gc.c: add hooks so that MJIT can wait GC, and vice versa. Simultaneous
JIT and GC executions may cause SEGV and so we should synchronize them.

cont.c: save continuation information in MJIT worker. As MJIT shouldn't
unload JIT-ed code which is being used, MJIT wants to know full list of
saved execution contexts for continuation and detect ISeqs in use.

mjit_compile.c: added empty JIT compiler so that you can reuse this commit
to build your own JIT compiler. This commit tries to compile ISeqs but
all of them are considered as not supported in this commit. So you can't
use JIT compiler in this commit yet while we added --jit option now.

Patch author: Vladimir Makarov <vmakarov@redhat.com>.

Contributors:
Takashi Kokubun <takashikkbn@gmail.com>.
wanabe <s.wanabe@gmail.com>.
Lars Kanis <lars@greiz-reinsdorf.de>.

Part of Feature 12589 and 14235.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 06:58:09 +00:00
normal 0c60f22ec5 thread_pthread.c: remove dead code around "get_stack_of"
"get_stack_of" was only in a proposed patch for [Feature #8793]
https://bugs.ruby-lang.org/issues/8793 and never applied.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61750 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 23:47:19 +00:00
nobu 0b3dfa087b thread_pthread.c: round stack size
* thread_pthread.c (rb_thread_create_timer_thread): round up
  additional stack size to PTHREAD_STACK_MIN, to get rid of
  EINVAL at pthread_attr_setstacksize().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 11:52:17 +00:00
normal 043e1fd559 thread_pthread: remove checks for pthread_cond*_init
These were added for NaCL support in r36022, and we dropped NaCL
in r60374.

IMHO, any pthreads implementation without these basic functions
is not worth the time to support.

[ruby-core:84758] [Misc #14342]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61720 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 08:26:43 +00:00
normal e8f40bd8f8 thread_pthread: remove HAVE_PTHREAD_ATTR_INIT ifdefs
ifdefs make code confusing for my easily-confused mind :<
These were added for NaCL support in r36022, and we dropped NaCL
in r60374.  There are more #ifdefs to remove...

[ruby-core:84758] [Misc #14342]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 08:26:38 +00:00
mame 3ecd8ab825 Fix the position of VM_ASSERT for "pthread_create failed for time"
Fix r61706.  Thank you, Eric Wong. [ruby-core:84756]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61717 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 07:33:38 +00:00
normal 66e42f4aa6 thread_pthread: more diagnostics around timer thread creation failures
However, I don't think EAGAIN on pthread_create can really
be fixed in our code.  I suspect test machines are overloaded.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 07:15:44 +00:00
mame 6c3bf2df0d Explicit failure in VM_CHECK_MODE when failing to create timer thread
"warning: pthread_create failed for timer: Resource temporarily
unavailable, scheduling broken" still occurs randomly.  This change will
allow us to debug the issue.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 03:47:22 +00:00
normal 2244bf5716 thread_pthread.c: use container_of
It's easier to read this macro from ccan than open-coding pointer
arithmetic.

thread_pthread.c (ubf_wakeup_all_threads): use container_of

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 21:23:47 +00:00
shyouhei 5471bf9cc2 offsetof(type, foo.bar) is (arguably) a GCCism
TL;DR see http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2031.htm

Suppose we have:

struct X {
  struct Y {
    z_t z;
  } y;
} x;

then, you _cant_ infer offsetof(struct X, y.z). The ISO C99 section
7.17 says nothing about such situation. At least clang warns this
being an extension to the language (-Wextended-offsetof).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 06:41:56 +00:00
ko1 5dfdaa9299 move rb_thread_t::interrupt_flag and mask
to rb_execution_context_t.

* vm_core.h (rb_thread_t): move
  `rb_thread_t::interrupt_flag` and
  `rb_thread_t::interrupt_mask` to rb_execution_context_t.

  RUBY_VM_CHECK_INTS() accepts `ec` instead of `th`.

* cont.c (rb_fiber_terminate): to propagate interrupt information,
  add new parameter `need_interrupt`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-06 07:44:28 +00:00
ko1 837fd5e494 Use rb_execution_context_t instead of rb_thread_t
to represent execution context [Feature #14038]

* vm_core.h (rb_thread_t): rb_thread_t::ec is now a pointer.
  There are many code using `th` to represent execution context
  (such as cfp, VM stack and so on). To access `ec`, they need to
  use `th->ec->...` (adding one indirection) so that we need to
  replace them by passing `ec` instead of `th`.

* vm_core.h (GET_EC()): introduced to access current ec. Also
  remove `ruby_current_thread` global variable.

* cont.c (rb_context_t): introduce rb_context_t::thread_ptr instead of
  rb_context_t::thread_value.

* cont.c (ec_set_vm_stack): added to update vm_stack explicitly.

* cont.c (ec_switch): added to switch ec explicitly.

* cont.c (rb_fiber_close): added to terminate fibers explicitly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26 08:32:49 +00:00
normal 73c397acb5 thread_pthread: do not corrupt stack
This fixes stuck test/ruby/test_io.rb with FIBER_USE_NATIVE=0 on
GNU/Linux because linked-list pointers used by glibc get
corrupted when fiber stacks are copied.

Thanks to wanabe for finding the bug and original patch.

* thread_pthread (native_thread_init_stack): fix stack corruption
  [ruby-core:82737] [Bug #13387]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 21:50:08 +00:00