summaryrefslogtreecommitdiff
path: root/internal
AgeCommit message (Collapse)Author
2020-09-14Make Mutex per-Fiber instead of per-ThreadBenoit Daloze
* 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] Notes: Merged: https://github.com/ruby/ruby/pull/3434
2020-09-14Add support for hooking `IO#read`.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3434
2020-09-14Standardised scheduler interface.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3434
2020-09-14Add `rb_thread_current_scheduler()`.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3434
2020-09-03Introduce Ractor mechanism for parallel executionKoichi Sasada
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. Notes: Merged: https://github.com/ruby/ruby/pull/3365
2020-09-02Initialize new T_OBJECT as ROBJECT_EMBEDJohn Hawthorn
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). Notes: Merged: https://github.com/ruby/ruby/pull/3486
2020-08-27include/ruby/backward/2/r_cast.h: deprecate卜部昌平
Remove all usages of RCAST() so that the header file can be excluded from ruby/ruby.h's dependency. Notes: Merged: https://github.com/ruby/ruby/pull/3346
2020-08-27RClassDeprecated: delete卜部昌平
It has been deprecated for 5 years since 1f2255604087e9a7d7efcb2df61b5ca0e2daa200. Notes: Merged: https://github.com/ruby/ruby/pull/3341
2020-08-27rb_deprecated_classext_struct: delete卜部昌平
Used from nowhere any longer. Notes: Merged: https://github.com/ruby/ruby/pull/3340
2020-08-19RHASH_EMPTY_P: convert into an inline function卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/3426
2020-08-19RHASH_TBL: is now ext-only卜部昌平
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. Notes: Merged: https://github.com/ruby/ruby/pull/3426
2020-08-19ROBJECT_IV_INDEX_TBL: convert into an inline function卜部昌平
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. Notes: Merged: https://github.com/ruby/ruby/pull/3427
2020-08-17Remove write barrier exemption for T_ICLASSAlan Wu
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] Notes: Merged: https://github.com/ruby/ruby/pull/3410
2020-08-18Expose ec -> backtrace (internal) and use it to implement fiber backtrace.Samuel Williams
See <https://bugs.ruby-lang.org/issues/16815> for more details. Notes: Merged: https://github.com/ruby/ruby/pull/3422
2020-08-15RARRAY_AREF: convert into an inline function卜部昌平
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. Notes: Merged: https://github.com/ruby/ruby/pull/3419
2020-07-22Lazily insert origins on prepend to save memoryAlan Wu
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. Notes: Merged: https://github.com/ruby/ruby/pull/3331
2020-07-20Move declarations to private `internal/thread.h` header.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3323
2020-07-13fix MJIT link error卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/3305
2020-07-13inline Primitive.cexpr!卜部昌平
We can obtain the verbatim source code of Primitive.cexpr!. Why not paste that content into the JITed program. Notes: Merged: https://github.com/ruby/ruby/pull/3305
2020-07-10Fix missing imemo cases in objspace_dump by refactoringAlan Wu
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. Notes: Merged: https://github.com/ruby/ruby/pull/3304
2020-07-03Use ID instead of GENTRY for gvars. (#3278)Koichi Sasada
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. Notes: Merged-By: ko1 <ko1@atdot.net>
2020-07-01Renamed `nurat_sub` compliant with `rb_rational_plus`Nobuyoshi Nakada
2020-06-04Properly resolve refinements in defined? on private call [Bug #16932]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3180
2020-06-03Ensure origins for all included, prepended, and refined modulesJeremy Evans
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] Notes: Merged: https://github.com/ruby/ruby/pull/3140
2020-05-23Allow Dir.home to work for non-login procs when $HOME not setAlan D. Salewski
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
2020-05-22Fix origin iclass pointer for modulesJeremy Evans
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] Notes: Merged: https://github.com/ruby/ruby/pull/3136
2020-05-22Revert "Fix origin iclass pointer for modules"Jeremy Evans
This reverts commit c745a60634260ba2080d35af6fdeaaae86fe5193. This triggers a VM assertion. Reverting until the issue can be debugged.
2020-05-22Fix origin iclass pointer for modulesJeremy Evans
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] Notes: Merged: https://github.com/ruby/ruby/pull/2978
2020-05-18Fix a typo [ci skip]Kazuhiro NISHIYAMA
2020-05-15Merge pull request #3047 from mame/suppress-backtraceYusuke Endoh
Add `--suppress-backtrace=num` option to limit the backtrace length Notes: Merged-By: mame <mame@ruby-lang.org>
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11sed -i s/RUBY3/RBIMPL/g卜部昌平
Devs do not love "3". The only exception is RUBY3_KEYWORDS in parse.y, which seems unrelated to our interests. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-07Allow global variables to moveAaron Patterson
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.
2020-05-02internal/process.h: forgot to guard "#ifdef HAVE_WORKING_FORK"Yusuke Endoh
2020-05-02internal/process.h: add a no-warning simple wrapper for fork(2)Yusuke Endoh
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.
2020-04-21__GNUC__ is too lax卜部昌平
Ditto for 4b853932eaa7fa4acf8a0f0c9b7c695bb4f5e76d
2020-04-15Added rb_syserr_new_pathNobuyoshi Nakada
Similar to rb_syserr_fail_path, but just returns the created exception instance instead of raising it. Notes: Merged: https://github.com/ruby/ruby/pull/3035
2020-04-13delete CACHELINE卜部昌平
Since https://github.com/ruby/ruby/pull/2888 this macro is no longer used in any place.
2020-04-13add #include guard hack卜部昌平
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 Notes: Merged: https://github.com/ruby/ruby/pull/3023
2020-04-12PAGER without fork&exec too [Feature #16754]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3000
2020-04-09internal/bits.h: Suppress "uninitialized variable"Yusuke Endoh
Coverity Scan says "Using uninitialized value c.fixnum when calling __builtin_mul_overflow_p."
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <shyouhei@ruby-lang.org>
2020-04-02Export `rb_deprecate_constant`Nobuyoshi Nakada
2020-03-21Removed non-RUBY_INTEGER_UNIFICATION codeNobuyoshi Nakada
2020-03-16hash.c: Do not use the fast path (rb_yield_values) for lambda blocksYusuke Endoh
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]
2020-03-11Fix typos (#2958)K.Takata
* Fix a typo * Fix typos in st.[ch] Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2020-02-28Prevent unloading methods used in root_fiber while calling another Fiber (#2939)Takashi Kokubun
Fixing SEGVs like: http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/2744905 http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/2744420 http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/2741400 Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2020-02-22Introduce disposable call-cache.Koichi Sasada
This patch contains several ideas: (1) Disposable inline method cache (IMC) for race-free inline method cache * Making call-cache (CC) as a RVALUE (GC target object) and allocate new CC on cache miss. * This technique allows race-free access from parallel processing elements like RCU. (2) Introduce per-Class method cache (pCMC) * Instead of fixed-size global method cache (GMC), pCMC allows flexible cache size. * Caching CCs reduces CC allocation and allow sharing CC's fast-path between same call-info (CI) call-sites. (3) Invalidate an inline method cache by invalidating corresponding method entries (MEs) * Instead of using class serials, we set "invalidated" flag for method entry itself to represent cache invalidation. * Compare with using class serials, the impact of method modification (add/overwrite/delete) is small. * Updating class serials invalidate all method caches of the class and sub-classes. * Proposed approach only invalidate the method cache of only one ME. See [Feature #16614] for more details. Notes: Merged: https://github.com/ruby/ruby/pull/2888
2020-02-22VALUE size packed callinfo (ci).Koichi Sasada
Now, rb_call_info contains how to call the method with tuple of (mid, orig_argc, flags, kwarg). Most of cases, kwarg == NULL and mid+argc+flags only requires 64bits. So this patch packed rb_call_info to VALUE (1 word) on such cases. If we can not represent it in VALUE, then use imemo_callinfo which contains conventional callinfo (rb_callinfo, renamed from rb_call_info). iseq->body->ci_kw_size is removed because all of callinfo is VALUE size (packed ci or a pointer to imemo_callinfo). To access ci information, we need to use these functions: vm_ci_mid(ci), _flag(ci), _argc(ci), _kwarg(ci). struct rb_call_info_kw_arg is renamed to rb_callinfo_kwarg. rb_funcallv_with_cc() and rb_method_basic_definition_p_with_cc() is temporary removed because cd->ci should be marked. Notes: Merged: https://github.com/ruby/ruby/pull/2888