aboutsummaryrefslogtreecommitdiffstats
path: root/internal
Commit message (Collapse)AuthorAgeFilesLines
* Disable deprecation warning by the default [Feature #16345]Nobuyoshi Nakada2020-09-251-0/+1
| | | | And `-w` option turns it on.
* Make `Thread#join` non-blocking.Samuel Williams2020-09-211-1/+1
|
* When setting current thread scheduler to nil, invoke `#close`.Samuel Williams2020-09-211-0/+2
|
* Rename scheduler.{mutex_lock,mutex_unlock} to {block,unblock}Benoit Daloze2020-09-171-2/+2
| | | | * Move #kernel_sleep next to #block as it is similar
* Make Mutex per-Fiber instead of per-ThreadBenoit Daloze2020-09-142-0/+5
| | | | | | | | | * Enables Mutex to be used as synchronization between multiple Fibers of the same Thread. * With a Fiber scheduler we can yield to another Fiber on contended Mutex#lock instead of blocking the entire thread. * This also makes the behavior of Mutex consistent across CRuby, JRuby and TruffleRuby. * [Feature #16792]
* Add support for hooking `IO#read`.Samuel Williams2020-09-141-2/+5
|
* Standardised scheduler interface.Samuel Williams2020-09-142-0/+29
|
* Add `rb_thread_current_scheduler()`.Samuel Williams2020-09-141-2/+4
|
* Introduce Ractor mechanism for parallel executionKoichi Sasada2020-09-031-0/+1
| | | | | | | | | | | | | | | | 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.
* Initialize new T_OBJECT as ROBJECT_EMBEDJohn Hawthorn2020-09-021-0/+1
| | | | | | | | | | | | | | | | | | | | | | Previously, when an object is first initialized, ROBJECT_EMBED isn't set. This means that for brand new objects, ROBJECT_NUMIV(obj) is 0 and ROBJECT_IV_INDEX_TBL(obj) is NULL. Previously, this combination meant that the inline cache would never be initialized when setting an ivar on an object for the first time since iv_index_tbl was NULL, and if it were it would never be used because ROBJECT_NUMIV was 0. Both cases always fell through to the generic rb_ivar_set which would then set the ROBJECT_EMBED flag and initialize the ivar array. This commit changes rb_class_allocate_instance to set the ROBJECT_EMBED flag on the object initially and to initialize all members of the embedded array to Qundef. This allows the inline cache to be set correctly on first use and to be used on future uses. This moves rb_class_allocate_instance to gc.c, so that it has access to newobj_of. This seems appropriate given that there are other allocating methods in this file (ex. rb_data_object_wrap, rb_imemo_new).
* include/ruby/backward/2/r_cast.h: deprecate卜部昌平2020-08-277-7/+7
| | | | | Remove all usages of RCAST() so that the header file can be excluded from ruby/ruby.h's dependency.
* RClassDeprecated: delete卜部昌平2020-08-271-4/+0
| | | | It has been deprecated for 5 years since 1f2255604087e9a7d7efcb2df61b5ca0e2daa200.
* rb_deprecated_classext_struct: delete卜部昌平2020-08-271-4/+0
| | | | Used from nowhere any longer.
* RHASH_EMPTY_P: convert into an inline function卜部昌平2020-08-191-0/+11
|
* RHASH_TBL: is now ext-only卜部昌平2020-08-191-5/+0
| | | | | It seems almost no internal codes use RHASH_TBL any longer. Why not just eliminate it entirely, so that the macro can be purely ext-only.
* ROBJECT_IV_INDEX_TBL: convert into an inline function卜部昌平2020-08-191-0/+22
| | | | | | | Former ROBJECT_IV_INDEX_TBL macro included RCLASS_IV_INDEX_TBL, which is not disclosed to extension libraies. The macro was kind of broken. Why not just deprecate it, and convert the internal use into an inline function.
* Remove write barrier exemption for T_ICLASSAlan Wu2020-08-171-0/+6
| | | | | | | | | | | | | | | | | | | Before this commit, iclasses were "shady", or not protected by write barriers. Because of that, the GC needs to spend more time marking these objects than otherwise. Applications that make heavy use of modules should see reduction in GC time as they have a significant number of live iclasses on the heap. - Put logic for iclass method table ownership into a function - Remove calls to WB_UNPROTECT and insert write barriers for iclasses This commit relies on the following invariant: for any non oirigin iclass `I`, `RCLASS_M_TBL(I) == RCLASS_M_TBL(RBasic(I)->klass)`. This invariant did not hold prior to 98286e9 for classes and modules that have prepended modules. [Feature #16984]
* Expose ec -> backtrace (internal) and use it to implement fiber backtrace.Samuel Williams2020-08-181-0/+2
| | | | See <https://bugs.ruby-lang.org/issues/16815> for more details.
* RARRAY_AREF: convert into an inline function卜部昌平2020-08-151-0/+11
| | | | | | RARRAY_AREF has been a macro for reasons. We might not be able to change that for public APIs, but why not relax the situation internally to make it an inline function.
* Lazily insert origins on prepend to save memoryAlan Wu2020-07-221-1/+0
| | | | | | | | | | | | | | | | 98286e9850936e27e8ae5e4f20858cc9c13d2dde made it so that `Module#include` allocates an origin iclass on each use. Since `include` is widely used, the extra allocation can contribute significantly to memory usage. Instead of always allocating in anticipation of prepend, this change takes a different approach. The new setup inserts a origin iclass into the super chains of all the children of the module when prepend happens for the first time. rb_ensure_origin is made static again since now that adding an origin now means walking over all usages, we want to limit the number of places where we do it.
* Move declarations to private `internal/thread.h` header.Samuel Williams2020-07-201-0/+4
|
* fix MJIT link error卜部昌平2020-07-131-1/+2
|
* inline Primitive.cexpr!卜部昌平2020-07-132-1/+4
| | | | | We can obtain the verbatim source code of Primitive.cexpr!. Why not paste that content into the JITed program.
* Fix missing imemo cases in objspace_dump by refactoringAlan Wu2020-07-101-0/+1
| | | | | | imemo_callcache and imemo_callinfo were not handled by the `objspace` module and were showing up as "unknown" in the dump. Extract the code for naming imemos and use that in both the GC and the `objspace` module.
* Use ID instead of GENTRY for gvars. (#3278)Koichi Sasada2020-07-031-15/+5
| | | | | | | | | | | | Use ID instead of GENTRY for gvars. Global variables are compiled into GENTRY (a pointer to struct rb_global_entry). This patch replace this GENTRY to ID and make the code simple. We need to search GENTRY from ID every time (st_lookup), so additional overhead will be introduced. However, the performance of accessing global variables is not important now a day and this simplicity helps Ractor development.
* Renamed `nurat_sub` compliant with `rb_rational_plus`Nobuyoshi Nakada2020-07-011-0/+1
|
* Properly resolve refinements in defined? on private call [Bug #16932]Nobuyoshi Nakada2020-06-041-0/+6
|
* Ensure origins for all included, prepended, and refined modulesJeremy Evans2020-06-031-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes various issues when a module is included in or prepended to a module or class, and then refined, or refined and then included or prepended to a module or class. Implement by renaming ensure_origin to rb_ensure_origin, making it non-static, and calling it when refining a module. Fix Module#initialize_copy to handle origins correctly. Previously, Module#initialize_copy did not handle origins correctly. For example, this code: ```ruby module B; end class A def b; 2 end prepend B end a = A.dup.new class A def b; 1 end end p a.b ``` Printed 1 instead of 2. This is because the super chain for a.singleton_class was: ``` a.singleton_class A.dup B(iclass) B(iclass origin) A(origin) # not A.dup(origin) ``` The B iclasses would not be modified, so the includer entry would be still be set to A and not A.dup. This modifies things so that if the class/module has an origin, all iclasses between the class/module and the origin are duplicated and have the correct includer entry set, and the correct origin is created. This requires other changes to make sure all tests still pass: * rb_undef_methods_from doesn't automatically handle classes with origins, so pass it the origin for Comparable when undefing methods in Complex. This fixed a failure in the Complex tests. * When adding a method, the method cache was not cleared correctly if klass has an origin. Clear the method cache for the klass before switching to the origin of klass. This fixed failures in the autoload tests related to overridding require, without breaking the optimization tests. Also clear the method cache for both the module and origin when removing a method. * Module#include? is fixed to skip origin iclasses. * Refinements are fixed to use the origin class of the module that has an origin. * RCLASS_REFINED_BY_ANY is removed as it was only used in a single place and is no longer needed. * Marshal#dump is fixed to skip iclass origins. * rb_method_entry_make is fixed to handled overridden optimized methods for modules that have origins. Fixes [Bug #16852]
* Allow Dir.home to work for non-login procs when $HOME not setAlan D. Salewski2020-05-231-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allow the 'Dir.home' method to reliably locate the user's home directory when all three of the following are true at the same time: 1. Ruby is running on a Unix-like OS 2. The $HOME environment variable is not set 3. The process is not a descendant of login(1) (or a work-alike) The prior behavior was that the lookup could only work for login-descended processes. This is accomplished by looking up the user's record in the password database by uid (getpwuid_r(3)) as a fallback to the lookup by name (getpwname_r(3)) which is still attempted first (based on the name, if any, returned by getlogin_r(3)). If getlogin_r(3), getpwnam_r(3), and/or getpwuid_r(3) is not available at compile time, will fallback on using their respective non-*_r() variants: getlogin(3), getpwnam(3), and/or getpwuid(3). The rationale for attempting to do the lookup by name prior to doing it by uid is to accommodate the possibility of multiple login names (each with its own record in the password database, so each with a potentially different home directory) being mapped to the same uid (as is explicitly allowed for by POSIX; see getlogin(3posix)). Preserves the existing behavior for login-descended processes, and adds the new capability of having Dir.home being able to find the user's home directory for non-login-descended processes. Fixes [Bug #16787] Related discussion: https://bugs.ruby-lang.org/issues/16787 https://github.com/ruby/ruby/pull/3034
* Fix origin iclass pointer for modulesJeremy Evans2020-05-221-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a module has an origin, and that module is included in another module or class, previously the iclass created for the module had an origin pointer to the module's origin instead of the iclass's origin. Setting the origin pointer correctly requires using a stack, since the origin iclass is not created until after the iclass itself. Use a hidden ruby array to implement that stack. Correctly assigning the origin pointers in the iclass caused a use-after-free in GC. If a module with an origin is included in a class, the iclass shares a method table with the module and the iclass origin shares a method table with module origin. Mark iclass origin with a flag that notes that even though the iclass is an origin, it shares a method table, so the method table should not be garbage collected. The shared method table will be garbage collected when the module origin is garbage collected. I've tested that this does not introduce a memory leak. This change caused a VM assertion failure, which was traced to callable method entries using the incorrect defined_class. Update rb_vm_check_redefinition_opt_method and find_defined_class_by_owner to treat iclass origins different than class origins to avoid this issue. This also includes a fix for Module#included_modules to skip iclasses with origins. Fixes [Bug #16736]
* Revert "Fix origin iclass pointer for modules"Jeremy Evans2020-05-221-9/+1
| | | | | | | This reverts commit c745a60634260ba2080d35af6fdeaaae86fe5193. This triggers a VM assertion. Reverting until the issue can be debugged.
* Fix origin iclass pointer for modulesJeremy Evans2020-05-221-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | If a module has an origin, and that module is included in another module or class, previously the iclass created for the module had an origin pointer to the module's origin instead of the iclass's origin. Setting the origin pointer correctly requires using a stack, since the origin iclass is not created until after the iclass itself. Use a hidden ruby array to implement that stack. Correctly assigning the origin pointers in the iclass caused a use-after-free in GC. If a module with an origin is included in a class, the iclass shares a method table with the module and the iclass origin shares a method table with module origin. Mark iclass origin with a flag that notes that even though the iclass is an origin, it shares a method table, so the method table should not be garbage collected. The shared method table will be garbage collected when the module origin is garbage collected. I've tested that this does not introduce a memory leak. This also includes a fix for Module#included_modules to skip iclasses with origins. Fixes [Bug #16736]
* Fix a typo [ci skip]Kazuhiro NISHIYAMA2020-05-181-1/+1
|
* Merge pull request #3047 from mame/suppress-backtraceYusuke Endoh2020-05-151-0/+1
| | | Add `--suppress-backtrace=num` option to limit the backtrace length
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-1128-44/+44
| | | | To fix build failures.
* sed -i s/RUBY3/RBIMPL/g卜部昌平2020-05-116-16/+16
| | | | | Devs do not love "3". The only exception is RUBY3_KEYWORDS in parse.y, which seems unrelated to our interests.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-1128-44/+44
| | | | This shall fix compile errors.
* Allow global variables to moveAaron Patterson2020-05-071-0/+1
| | | | | | | | | | This patch allows global variables that have been assigned in Ruby to move. I added a new function for the GC to call that will update global references and introduced a new callback in the global variable struct for updating references. Only pure Ruby global variables are supported right now, other references will be pinned.
* internal/process.h: forgot to guard "#ifdef HAVE_WORKING_FORK"Yusuke Endoh2020-05-021-0/+2
|
* internal/process.h: add a no-warning simple wrapper for fork(2)Yusuke Endoh2020-05-021-0/+12
| | | | | | | | | | | | As fork(2) is deprecated, its calls must be guarded by `COMPILER_WARNING_IGNORED(-Wdeprecated-declarations)`. All usages of fork(2) in process have been alread guarded. A new call to fork(2) was added in ruby.c with f22c4ff359498ab342e4b6d6feb21af6004ee270. This caused a build failure on Solaris 11. It may hide a bug to guard big code unnecessarily, so this change introduces a simple wrapper "rb_fork" whose definition is guarded, and replaces all calls to fork(2) with the wrapper function.
* __GNUC__ is too lax卜部昌平2020-04-211-1/+1
| | | | Ditto for 4b853932eaa7fa4acf8a0f0c9b7c695bb4f5e76d
* Added rb_syserr_new_pathNobuyoshi Nakada2020-04-151-0/+3
| | | | | Similar to rb_syserr_fail_path, but just returns the created exception instance instead of raising it.
* delete CACHELINE卜部昌平2020-04-131-11/+0
| | | | | Since https://github.com/ruby/ruby/pull/2888 this macro is no longer used in any place.
* add #include guard hack卜部昌平2020-04-1351-152/+156
| | | | | | | | | | | | | | | | | | | | | | According to MSVC manual (*1), cl.exe can skip including a header file when that: - contains #pragma once, or - starts with #ifndef, or - starts with #if ! defined. GCC has a similar trick (*2), but it acts more stricter (e. g. there must be _no tokens_ outside of #ifndef...#endif). Sun C lacked #pragma once for a looong time. Oracle Developer Studio 12.5 finally implemented it, but we cannot assume such recent version. This changeset modifies header files so that each of them include strictly one #ifndef...#endif. I believe this is the most portable way to trigger compiler optimizations. [Bug #16770] *1: https://docs.microsoft.com/en-us/cpp/preprocessor/once *2: https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html
* PAGER without fork&exec too [Feature #16754]Nobuyoshi Nakada2020-04-121-0/+1
|
* internal/bits.h: Suppress "uninitialized variable"Yusuke Endoh2020-04-091-1/+1
| | | | | Coverity Scan says "Using uninitialized value c.fixnum when calling __builtin_mul_overflow_p."
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-0852-560/+328
| | | Split ruby.h
* Export `rb_deprecate_constant`Nobuyoshi Nakada2020-04-021-1/+1
|
* Removed non-RUBY_INTEGER_UNIFICATION codeNobuyoshi Nakada2020-03-211-8/+2
|
* hash.c: Do not use the fast path (rb_yield_values) for lambda blocksYusuke Endoh2020-03-161-0/+1
| | | | | | | | | | | | | | | | | As a semantics, Hash#each yields a 2-element array (pairs of keys and values). So, `{ a: 1 }.each(&->(k, v) { })` should raise an exception due to lambda's arity check. However, the optimization that avoids Array allocation by using rb_yield_values for blocks whose arity is more than 1 (introduced at b9d29603375d17c3d1d609d9662f50beaec61fa1 and some commits), seemed to overlook the lambda case, and wrongly allowed the code above to work. This change experimentally attempts to make it strict; now the code above raises an ArgumentError. This is an incompatible change; if the compatibility issue is bigger than our expectation, it may be reverted (until Ruby 3.0 release). [Bug #12706]