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

571 Коммитов

Автор SHA1 Сообщение Дата
Koichi Sasada fa3670e6e4 remove Ractor#close
close_incoming by antoher ractor means there is no other messages
will be sent to the ractor, so Ractor.receive will block forever,
and it should raise and stop.

close_outgoing by antoher ractor means, ... I don't have good idea
to use it. It can be a private method.

Ractor#close calls both, but it does not make sense to call
different purpose methods, so I remove it.
2020-11-11 18:11:09 +09:00
Koichi Sasada deed21bb08 ignore yield_atexit if outgoing port is closed
If outgoing_port is closed, Ractor.yield never successes.
[Bug #17310]
2020-11-11 18:10:43 +09:00
Koichi Sasada db31ace934 Threads in a ractor will be killed with the ractor
If a terminating ractor has child threads, then kill all child
threads.
2020-11-11 15:49:02 +09:00
Koichi Sasada 5fefb53249 Copy for Ractor.send() without marshal.
Now copying objects do not need marshal protocol.
2020-11-02 03:31:58 +09:00
Koichi Sasada 89c8ca32d0 add a test of define_method with shareable Proc.
a method defined by define_method with normal Proc can not cross
ractors because the normal Proc is not shareable. However,
shareable Proc can be crossed between ractors, so the method with
shareable Proc should be called correctly.
2020-10-30 16:52:09 +09:00
Koichi Sasada 5d97bdc2dc Ractor.make_shareable(a_proc)
Ractor.make_shareable() supports Proc object if
(1) a Proc only read outer local variables (no assignments)
(2) read outer local variables are shareable.

Read local variables are stored in a snapshot, so after making
shareable Proc, any assignments are not affeect like that:

```ruby
a = 1
pr = Ractor.make_shareable(Proc.new{p a})
pr.call #=> 1
a = 2
pr.call #=> 1 # `a = 2` doesn't affect
```

[Feature #17284]
2020-10-30 03:12:09 +09:00
Marc-Andre Lafortune 9c8f0a34df Use 'shareable' with an 'e' [ci skip] 2020-10-25 18:10:14 -04:00
Marc-Andre Lafortune 5e6f9fd83a Tweak a few Ractor tests that were missing comments [ci skip] 2020-10-25 16:44:59 -04:00
Marc-Andre Lafortune ee54075a94 Remove trailing whitespace [ci skip] 2020-10-25 16:38:37 -04:00
Koichi Sasada 0c0d0752f1 allow to access ivars of frozen shareable objects
Accessing a shareable object is prohibitted because it can cause
race condition, but if the shareable object is frozen, there is no
problem to access ivars.
2020-10-22 00:43:44 +09:00
Koichi Sasada 2f50936cb9 Ractor.make_shareable(obj)
Introduce new method Ractor.make_shareable(obj) which tries to make
obj shareable object. Protocol is here.

(1) If obj is shareable, it is shareable.
(2) If obj is not a shareable object and if obj can be shareable
    object if it is frozen, then freeze obj. If obj has reachable
    objects (rs), do rs.each{|o| Ractor.make_shareable(o)}
    recursively (recursion is not Ruby-level, but C-level).
(3) Otherwise, raise Ractor::Error. Now T_DATA is not a shareable
    object even if the object is frozen.

If the method finished without error, given obj is marked as
a sharable object.

To allow makng a shareable frozen T_DATA object, then set
`RUBY_TYPED_FROZEN_SHAREABLE` as type->flags. On default,
this flag is not set. It means user defined T_DATA objects are
not allowed to become shareable objects when it is frozen.

You can make any object  shareable by setting FL_SHAREABLE flag,
so if you know that the T_DATA object is shareable (== thread-safe),
set this flag, at creation time for example. `Ractor` object is one
example, which is not a frozen, but a shareable object.
2020-10-21 07:59:24 +09:00
Koichi Sasada 512752ba19 fix condition 2020-10-20 23:48:20 +09:00
Koichi Sasada 67c25a34a7 skip `echo foo` on Solaris
On Solaris, it seems to access ENV in ``, so skip it now.

```
stderr output is not empty
   Exception `NameError' at bootstraptest.tmp.rb:7 - can not access non-sharable objects in constant Object::ENV by non-main Ractor.
   #<Thread:0x0044cdf0 run> terminated with exception (report_on_exception is true):
   bootstraptest.tmp.rb:7:in ``': can not access non-sharable objects in constant Object::ENV by non-main Ractor. (NameError)
   Exception `Ractor::RemoteError' at <internal:ractor>:130 - thrown by remote Ractor.
   <internal:ractor>:130:in `take': thrown by remote Ractor. (Ractor::RemoteError)
           from bootstraptest.tmp.rb:55:in `<main>'
   bootstraptest.tmp.rb:7:in ``': can not access non-sharable objects in constant Object::ENV by non-main Ractor. (NameError)
           from bootstraptest.tmp.rb:7:in `ractor_local_globals'
           from bootstraptest.tmp.rb:54:in `block in <main>'
```
2020-10-20 17:57:20 +09:00
Koichi Sasada ade411465d ObjectSpace.each_object with Ractors
Unshareable objects should not be touched from multiple ractors
so ObjectSpace.each_object should be restricted. On multi-ractor
mode, ObjectSpace.each_object only iterates shareable objects.
[Feature #17270]
2020-10-20 15:39:37 +09:00
Koichi Sasada 99310e3eb5 Some global variables can be accessed from ractors
Some global variables should be used from non-main Ractors.
[Bug #17268]

```ruby
     # ractor-local (derived from created ractor): debug
     '$DEBUG' => $DEBUG,
     '$-d' => $-d,

     # ractor-local (derived from created ractor): verbose
     '$VERBOSE' => $VERBOSE,
     '$-w' => $-w,
     '$-W' => $-W,
     '$-v' => $-v,

     # process-local (readonly): other commandline parameters
     '$-p' => $-p,
     '$-l' => $-l,
     '$-a' => $-a,

     # process-local (readonly): getpid
     '$$'  => $$,

     # thread local: process result
     '$?'  => $?,

     # scope local: match
     '$~'  => $~.inspect,
     '$&'  => $&,
     '$`'  => $`,
     '$\''  => $',
     '$+'  => $+,
     '$1'  => $1,

     # scope local: last line
     '$_' => $_,

     # scope local: last backtrace
     '$@' => $@,
     '$!' => $!,

     # ractor local: stdin, out, err
     '$stdin'  => $stdin.inspect,
     '$stdout' => $stdout.inspect,
     '$stderr' => $stderr.inspect,
```
2020-10-20 15:38:54 +09:00
Koichi Sasada fad97f1f96 sync generic_ivtbl
generic_ivtbl is a process global table to maintain instance variables
for non T_OBJECT/T_CLASS/... objects. So we need to protect them
for multi-Ractor exection.

Hint: we can make them Ractor local for unshareable objects, but
      now it is premature optimization.
2020-10-14 16:36:55 +09:00
Koichi Sasada 11c2f0f36c sync enc_table and rb_encoding_list
enc_table which manages Encoding information. rb_encoding_list
also manages Encoding objects. Both are accessed/modified by ractors
simultaneously so that they should be synchronized.

For enc_table, this patch introduced GLOBAL_ENC_TABLE_ENTER/LEAVE/EVAL
to access this table with VM lock. To make shortcut, three new global
variables global_enc_ascii, global_enc_utf_8, global_enc_us_ascii are
also introduced.

For rb_encoding_list, we split it to rb_default_encoding_list (256 entries)
and rb_additional_encoding_list. rb_default_encoding_list is fixed sized Array
so we don't need to synchronized (and most of apps only needs it). To manage
257 or more encoding objects, they are stored into rb_additional_encoding_list.
To access rb_additional_encoding_list., VM lock is needed.
2020-10-14 14:02:06 +09:00
Benoit Daloze bfc1c7205d Add Ractor#receive and Ractor.receive and use it in all places
* Keep Ractor#recv/Ractor.recv as an alias for now.
2020-10-10 12:48:09 +02:00
Koichi Sasada 5e91b4bdb3 fix typo [ci skip] 2020-09-27 09:49:16 +09:00
Koichi Sasada 0096d2b895 freeze all Range objects.
Matz want to try to freeze all Range objects.
[Feature #15504]
2020-09-25 22:16:55 +09:00
Koichi Sasada caaa36b4e6 prohibi method call by defined_method in other racotrs
We can not call a non-isolated Proc in multiple ractors.
2020-09-25 20:37:38 +09:00
Koichi Sasada 25cfb0c040 Range is based on Struct.
Range can be shareable because it is implemented by Struct.
2020-09-25 16:00:13 +09:00
Koichi Sasada 96739c4222 Frozen Struct can be shareable.
A frozen Struct object which refers to shareable objects should be
shareable.
2020-09-25 16:00:13 +09:00
Koichi Sasada 6081ba4a87 refactoring a test code.
make a test more clear.
2020-09-25 13:07:07 +09:00
Koichi Sasada d247dedade Ractor.yield should raise if out-port is closed
Ractor.yield should raise Ractor::ClosedError if current Ractor's
outgoing-port is closed.
2020-09-25 12:53:58 +09:00
Koichi Sasada 5286526346 frozen T_OBJECT can be shareable.
If an T_OBJECT object is frozen and all ivars are shareable,
the object should be shareable.
2020-09-25 12:52:53 +09:00
Koichi Sasada 7ad3aff48d Ractor#close_outgoping cancel Ractor.yield
Ractor#close_outgoing should cancel waiting Ractor.yield. However,
yield a value by the Ractor's block should not cancel (to recognize
terminating Ractor, introduce rb_ractor_t::yield_atexit flag).
2020-09-25 00:25:38 +09:00
Michael Lindley e06f4a3b1f Remove test for putiseq insn
putiseq was removed from instruction set in 2b5bb8a0
2020-09-24 09:56:12 +09:00
Quang-Minh Nguyen be2efb118f Fulfill missing tests and stabilize tests 2020-09-20 23:10:44 +09:00
Quang-Minh Nguyen 398da71175 Validate name during initialization 2020-09-20 23:10:44 +09:00
Quang-Minh Nguyen d5fa66156a Add status to Ractor#inspect 2020-09-20 23:10:44 +09:00
Benoit Daloze 9b535f3ff7 Interpolated strings are no longer frozen with frozen-string-literal: true
* Remove freezestring instruction since this was the only usage for it.
* [Feature #17104]
2020-09-15 21:32:35 +02:00
Koichi Sasada e81d7189a0 sync fstring pool
fstring pool should be sync with other Ractors.
2020-09-15 00:04:59 +09:00
Kazuhiro NISHIYAMA 3bdf8efd81
Fix typos [ci skip] 2020-09-13 12:35:06 +09:00
Koichi Sasada 3f922f3b77 don't use toplevel return
Toplevel return is supported after Ruby 2.4, so don't use it
for older BASERUBY.
2020-09-04 04:07:34 +09:00
Koichi Sasada b52513e2a1 skip Ractor tests on Compiler tests
This implementation has memory corruption errors so and
it causes BUG on rare occasions. This commit skips
suspect tests on Github actions Compiler tests.
2020-09-03 21:11:06 +09:00
Koichi Sasada 79df14c04b Introduce Ractor mechanism for parallel execution
This commit introduces Ractor mechanism to run Ruby program in
parallel. See doc/ractor.md for more details about Ractor.
See ticket [Feature #17100] to see the implementation details
and discussions.

[Feature #17100]

This commit does not complete the implementation. You can find
many bugs on using Ractor. Also the specification will be changed
so that this feature is experimental. You will see a warning when
you make the first Ractor with `Ractor.new`.

I hope this feature can help programmers from thread-safety issues.
2020-09-03 21:11:06 +09:00
Koichi Sasada ed22bf47cc display stderr output even if core dump files
On btest, stderr messages are not displayed if core files are
generated. There is no reason to skip it, so this patch display
stderr and check core files.
2020-07-29 18:45:39 +09:00
Takashi Kokubun e544a3a23c
Remove obsoleted opt_call_c_function insn (#3232)
* Remove obsoleted opt_call_c_function insn

* Keep opt_call_c_function with DEFINE_INSN_IF
2020-06-17 09:16:01 -07:00
Jeremy Evans f3e927b0cc Make proc/Proc.new without block an error instead of warning
The warning for these was added in 2.7.
2020-06-10 17:49:54 -07:00
Nobuyoshi Nakada 6009790e40
Moved already resolved test
Couldn't figure out failed/fixed versions.
2020-04-27 10:39:07 +09:00
Nobuyoshi Nakada c180c58fc1
Removed already resolved test [ci skip]
That bug has been fixed by ec0c394b9e, and the test has been
added by 181ffea5e0.
2020-04-27 10:39:07 +09:00
Nobuyoshi Nakada a9567cc2bf Added test for `debug_level:` option of `RubyVM::InstructionSequence.compile` 2020-04-15 16:06:48 +09:00
Jeremy Evans 900e83b501 Turn class variable warnings into exceptions
This changes the following warnings:

* warning: class variable access from toplevel
* warning: class variable @foo of D is overtaken by C

into RuntimeErrors.  Handle defined?(@@foo) at toplevel
by returning nil instead of raising an exception (the previous
behavior warned before returning nil when defined? was used).

Refactor the specs to avoid the warnings even in older versions.
The specs were checking for the warnings, but the purpose of
the related specs as evidenced from their description is to
test for behavior, not for warnings.

Fixes [Bug #14541]
2020-04-10 00:29:05 -07:00
Koichi Sasada fd0222caed should check pending interrupts correctly.
rb_uninterruptible() disables any interrupts using handle_interrupt
feature (This function is used by `p`).
After this function, pending interrupts should be checked correctly,
however there is no chance to setup interrupt flag of working
threads, it means that nobody checks pending interrupts.
For example, it ignores terminate signal delivered at the end
of main thread and program can't stop.

This patch set interrupt flag if there are pending interrupts.
2020-04-09 12:51:51 +09:00
Koichi Sasada 21d8e69248 disable to show the maximum number of threads.
On Deiban 9 environment, the thread tests failed and
this maximum threads information can finish up the machine
resources. To check it, I turned-off showing this information.
2020-03-23 11:32:20 +09:00
Jeremy Evans 7a288df7b8 Make yield in singleton class definitions in methods a SyntaxError
This behavior was deprecated in 2.7 and scheduled to be removed
in 3.0.

Calling yield in a class definition outside a method is now a
SyntaxError instead of a LocalJumpError, as well.
2020-02-11 12:44:23 -08:00
Jeremy Evans e91c39f1c0 Remove special handling of $SAFE and related C-APIs
These were all deprecated in Ruby 2.7.
2020-01-22 09:09:47 -08:00
Nobuyoshi Nakada 93b27c69cc
Show the failed message too 2019-12-12 23:26:35 +09:00
Nobuyoshi Nakada 0afee4d803
Show the failed message 2019-12-11 14:27:21 +09:00