aboutsummaryrefslogtreecommitdiffstats
path: root/gc.c
Commit message (Collapse)AuthorAgeFilesLines
* fix debugging outputAaron Patterson2020-06-081-2/+2
|
* Combine sweeping and movingAaron Patterson2020-05-291-11/+136
| | | | | | | | | | | | | | | | | | | This commit combines the sweep step with moving objects. With this commit, we can do: ```ruby GC.start(compact: true) ``` This code will do the following 3 steps: 1. Fully mark the heap 2. Sweep + Move objects 3. Update references By default, this will compact in order that heap pages are allocated. In other words, objects will be packed towards older heap pages (as opposed to heap pages with more pinned objects like `GC.compact` does).
* Extract "free moved list" functionAaron Patterson2020-05-281-23/+29
| | | | | Extract a function to free the moved list. We'll use this function later on to compact at the same time as sweep.
* Fix origin iclass pointer for modulesJeremy Evans2020-05-221-6/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-11/+6
| | | | | | | 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-6/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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]
* Only marked objects should be considered movableAaron Patterson2020-05-201-1/+1
| | | | | | | | | | | | | | Ruby's GC is incremental, meaning that during the mark phase (and also the sweep phase) programs are allowed to run. This means that programs can allocate objects before the mark or sweep phase have actually completed. Those objects may not have had a chance to be marked, so we can't know if they are movable or not. Something that references the newly created object might have called the pinning function during the mark phase, but since the mark phase hasn't run we can't know if there is a "pinning" relationship. To be conservative, we must only allow objects that are not pinned but also marked to move.
* Allow references stored in the VM stack to moveAaron Patterson2020-05-181-5/+4
| | | | We can update these references too, so lets allow them to move.
* more on NULL versus functions卜部昌平2020-05-111-1/+1
| | | | | | | Function pointers are not void*. See also 115fec062ccf7c6d72c8d5f64b7a5d84c9fb2dd8 ce4ea956d24eab5089a143bba38126f2b11b55b6 8427fca49bd85205f5a8766292dd893f003c0e48
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-1/+1
| | | | To fix build failures.
* sed -i s/ruby3/rbimpl/g卜部昌平2020-05-111-14/+14
|
* sed -i s/RUBY3/RBIMPL/g卜部昌平2020-05-111-1/+1
| | | | | 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-111-1/+1
| | | | This shall fix compile errors.
* Added more NORETURN declarationsNobuyoshi Nakada2020-05-111-0/+2
|
* 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.
* `T_MOVED` should never be pushed on the mark stackAaron Patterson2020-05-071-0/+1
| | | | | | | No objects should ever reference a `T_MOVED` slot. If they do, it's absolutely a bug. If we kill the process when `T_MOVED` is pushed on the mark stack it will make it easier to identify which object holds a reference that hasn't been updated.
* Output compaction stats in one loop / eliminate 0 countsAaron Patterson2020-05-041-4/+6
| | | | | | | | We only need to loop `T_MASK` times once. Also, not every value between 0 and `T_MASK` is an actual Ruby type. Before this change, some integers were being added to the result hash even though they aren't actual types. This patch omits considered / moved entries that total 0, cleaning up the result hash and eliminating these "fake types".
* Rename arguments for ObjectSpace::WeakMap#[]= for clarityBenoit Daloze2020-05-021-8/+8
|
* Fix ObjectSpace::WeakMap#key? to work if the value is nilBenoit Daloze2020-05-021-4/+12
| | | | * Fixes [Bug #16826]
* Mark ruby_memerror as NORETURNNobuyoshi Nakada2020-04-291-1/+2
|
* Remove debugging code from gc.cYusuke Endoh2020-04-291-4/+1
| | | | | | | Partially revert adab82b9a71f60ad1c7f4f8c134a5ae9198ab32a and c63b5c6179d700ceacf5cae8d3ee86da1294c781. The issue that these commits attempt to address was maybe fixed with 1c7f5a57125001447dc6173847dc68aa50bd8e93.
* Fix a typo [ci skip]Kazuhiro NISHIYAMA2020-04-271-1/+1
|
* Assert that typed data is distinguished from non-typedNobuyoshi Nakada2020-04-251-0/+2
|
* rb_memerror: abort immediately卜部昌平2020-04-211-0/+3
| | | | | Ditto for adab82b9a71f60ad1c7f4f8c134a5ae9198ab32a. TRY_WITH_GC was found innocent.
* Fixed a typo [ci skip]Nobuyoshi Nakada2020-04-211-1/+1
|
* TRY_WITH_GC: abort immediately卜部昌平2020-04-211-4/+36
| | | | | NoMemoryError is observed on icc but I fail to reproduce so far. Let me see the backtrace on CI.
* Moved noreturn call to end of noreturn functionNobuyoshi Nakada2020-04-161-1/+1
|
* Suppress -Wswitch warningsNobuyoshi Nakada2020-04-081-0/+12
|
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-113/+63
| | | Split ruby.h
* Bail out before pushing unexpected objectNobuyoshi Nakada2020-04-031-0/+12
|
* fix type castKoichi Sasada2020-03-111-1/+1
|
* show method entry with iseq detailsKoichi Sasada2020-03-111-1/+2
|
* fix compile error w/ -DCALC_EXACT_MALLOC_SIZE卜部昌平2020-03-041-4/+0
|
* kill USE_RGENGC=0卜部昌平2020-02-261-136/+2
| | | | | | This compile-time option has been broken for years (at least since commit 49369ef17316cd5d5819b038f286e1d951972b52, according to git bisect). Let's delete codes that no longer works.
* avoid #if inside of rb_str_new_cstr卜部昌平2020-02-261-2/+3
| | | | | | | | | ISO/IEC 9899:1999 section 6.10.3 paragraph 11 explicitly states that "If there are sequences of preprocessing tokens within the list of arguments that would otherwise act as preprocessing directives, the behavior is undefined." rb_str_new_cstr is in fact a macro. We cannot do this.
* Introduce disposable call-cache.Koichi Sasada2020-02-221-6/+198
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* VALUE size packed callinfo (ci).Koichi Sasada2020-02-221-2/+23
| | | | | | | | | | | | | | | | | | | | 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.
* TestTime#test_memsize: skip when on GC_DEBUG卜部昌平2020-02-201-0/+1
| | | | | GC_DEBUG=1 makes this test fail because it changes the size of struct RVALUE. I don't think the test is useful then. Let's just skip.
* Revert "gc.c: make the stack overflow detection earlier under s390x"Yusuke Endoh2020-02-101-7/+0
| | | | | | | This reverts commit a28c166f787710227c6aac54befd72778f041485. This change didn't help. According to odaira, the issue was fixed by increasing `ulimit -s`.
* Disable GC until VM objects get initialized [Bug #16616]Nobuyoshi Nakada2020-02-091-0/+1
|
* Separate objspace argument for rb_gc_disable and rb_gc_enableNobuyoshi Nakada2020-02-091-6/+24
|
* gc.c: make the stack overflow detection earlier under s390xYusuke Endoh2020-02-091-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On s390x, TestFiber#test_stack_size fails with SEGV. https://rubyci.org/logs/rubyci.s3.amazonaws.com/rhel_zlinux/ruby-master/log/20200205T223421Z.fail.html.gz ``` TestFiber#test_stack_size [/home/chkbuild/build/20200205T223421Z/ruby/test/ruby/test_fiber.rb:356]: pid 23844 killed by SIGABRT (signal 6) (core dumped) | -e:1:in `times': stack level too deep (SystemStackError) | from -e:1:in `rec' | from -e:1:in `block (3 levels) in rec' | from -e:1:in `times' | from -e:1:in `block (2 levels) in rec' | from -e:1:in `times' | from -e:1:in `block in rec' | from -e:1:in `times' | from -e:1:in `rec' | ... 172 levels... | from -e:1:in `block in rec' | from -e:1:in `times' | from -e:1:in `rec' | from -e:1:in `block in <main>' | -e: [BUG] Segmentation fault at 0x0000000000000000 ``` This change tries a similar fix with ef64ab917eec02491f6bf7233a4031a8c35385e3 and 3ddbba84b5b1f001cd575a48cec56d7ce8e5fbb2.
* Removed type-punning pointer casts around `st_data_t`Nobuyoshi Nakada2020-01-311-12/+13
|
* Moved `GC.verify_compaction_references` to gc.rbNobuyoshi Nakada2020-01-271-45/+5
| | | | | And fixed a segfault by coercion of `Qundef`, when any keyword argument without `toward:` option is given.
* Fix syntax error in obj_free with hash size debug counter when ↵Lourens Naudé2020-01-131-1/+1
| | | | USE_DEBUG_COUNTER is enabled
* Introduce BIGNUM_EMBED_P to check BIGNUM_EMBED_FLAG (#2802)Kenta Murata2019-12-311-1/+1
| | | | | | * bignum.h: Add BIGNUM_EMBED_P * bignum.c: Use macros for handling BIGNUM_EMBED_FLAG
* Separate builtin initialization callsNobuyoshi Nakada2019-12-291-1/+0
|
* decouple internal.h headers卜部昌平2019-12-261-40/+65
| | | | | | | | | | | | | | | | | | Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies).
* split internal.h into files卜部昌平2019-12-261-0/+6
| | | | | | | | | One day, I could not resist the way it was written. I finally started to make the code clean. This changeset is the beginning of a series of housekeeping commits. It is a simple refactoring; split internal.h into files, so that we can divide and concur in the upcoming commits. No lines of codes are either added or removed, except the obvious file headers/footers. The generated binary is identical to the one before.
* fix wmap_finalize.Koichi Sasada2019-12-231-2/+16
| | | | | | wmap_finalize expects id2ref() returns a corresponding object even if the object is dead. Make id2ref_obj_tbl() for this purpose.