summaryrefslogtreecommitdiff
path: root/gc.c
AgeCommit message (Collapse)Author
2019-10-10make rb_raise a GVL-only function again卜部昌平
Requested by ko1 that ability of calling rb_raise from anywhere outside of GVL is "too much". Give up that part, move the GVL aquisition routine into gc.c, and make our new gc_raise().
2019-10-10negative_size_allocation_error never returnsNobuyoshi Nakada
2019-10-10allow rb_raise from outside of GVL卜部昌平
Now that allocation routines like ALLOC_N() can raise exceptions on integer overflows. This is a problem when the calling thread has no GVL. Memory allocations has been allowed without it, but can still fail. Let's just relax rb_raise's restriction so that we can call it with or without GVL. With GVL the behaviour is unchanged. With no GVL, wait for it. Also, integer overflows can theoretically occur during GC when we expand the object space. We cannot do so much then. Call rb_memerror and let that routine abort the process.
2019-10-10fix memory corruption in old GCC卜部昌平
This typo introduced memory corruption when __builtin_add_overflow is not available but uint128_t is. GCC before 5 are one of such situatins. See also https://rubyci.org/logs/rubyci.s3.amazonaws.com/opensuseleap/ruby-master/log/20191009T120004Z.log.html.gz
2019-10-09Prefer st_is_member over st_lookup with 0Ben Woosley
The st_is_member DEFINE has simpler semantics, for more readable code. Notes: Merged: https://github.com/ruby/ruby/pull/1622
2019-10-09avoid returning NULL from xrealloc卜部昌平
This changeset is to kill future possibility of bugs similar to CVE-2019-11932. The vulnerability occurs when reallocarray(3) (which is a variant of realloc(3) and roughly resembles our ruby_xmalloc2()) returns NULL. In our C API, ruby_xmalloc() never returns NULL to raise NoMemoryError instead. ruby_xfree() does not return NULL by definition. ruby_xrealloc() on the other hand, _did_ return NULL, _and_ also raised sometimes. It is very confusing. Let's not do that. x-series APIs shall raise on error and shall not return NULL. Notes: Merged: https://github.com/ruby/ruby/pull/2540
2019-10-09avoid overflow in integer multiplication卜部昌平
This changeset basically replaces `ruby_xmalloc(x * y)` into `ruby_xmalloc2(x, y)`. Some convenient functions are also provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates x * y + z byes. Notes: Merged: https://github.com/ruby/ruby/pull/2540
2019-10-07Do not free too many pages.Aaron Patterson
Sweep step checks `heap_pages_freeable_pages`, so compaction should do the same.
2019-10-07Move empty pages to the tombAaron Patterson
I think we need to be moving empty pages to the tomb after they become empty.
2019-10-07Eliminate second GC pass for eliminating T_MOVEDAaron Patterson
`T_MOVED` is a linked list, so we can just iterate through the `T_MOVED` objects, clearing them out and adding them to respective free lists.
2019-10-04IMEMO objects don't have a class, so return earlyAaron Patterson
IMEMO objects don't have a class field to update, so we need to return early, otherwise it can cause a segv.
2019-10-04Don't allocate objects in `gc_compact`Aaron Patterson
I'd like to call `gc_compact` after major GC, but before the GC finishes. This means we can't allocate any objects inside `gc_compact`. So in this commit I'm just pulling the compaction statistics allocation outside the `gc_compact` function so we can safely call it.
2019-10-05Fix potential memory leaks by `rb_imemo_tmpbuf_auto_free_pointer`Nobuyoshi Nakada
This function has been used wrongly always at first, "allocate a buffer then wrap it with tmpbuf". This order can cause a memory leak, as tmpbuf creation also can raise a NoMemoryError exception. The right order is "create a tmpbuf then allocate&wrap a buffer". So the argument of this function is rather harmful than just useless. TODO: * Rename this function to more proper name, as it is not used "temporary" (function local) purpose. * Allocate and wrap at once safely, like `ALLOCV`.
2019-10-03Revert https://github.com/ruby/ruby/pull/2486卜部昌平
This reverts commits: 10d6a3aca7 8ba48c1b85 fba8627dc1 dd883de5ba 6c6a25feca 167e6b48f1 7cb96d41a5 3207979278 595b3c4fdd 1521f7cf89 c11c5e69ac cf33608203 3632a812c0 f56506be0d 86427a3219 . The reason for the revert is that we observe ABA problem around inline method cache. When a cache misshits, we search for a method entry. And if the entry is identical to what was cached before, we reuse the cache. But the commits we are reverting here introduced situations where a method entry is freed, then the identical memory region is used for another method entry. An inline method cache cannot detect that ABA. Here is a code that reproduce such situation: ```ruby require 'prime' class << Integer alias org_sqrt sqrt def sqrt(n) raise end GC.stress = true Prime.each(7*37){} rescue nil # <- Here we populate CC class << Object.new; end # These adjacent remove-then-alias maneuver # frees a method entry, then immediately # reuses it for another. remove_method :sqrt alias sqrt org_sqrt end Prime.each(7*37).to_a # <- SEGV ```
2019-09-30refactor constify most of rb_method_entry_t卜部昌平
Now that we have eliminated most destructive operations over the rb_method_entry_t / rb_callable_method_entry_t, let's make them mostly immutabe and mark them const. One exception is rb_export_method(), which destructively modifies visibilities of method entries. I have left that operation as is because I suspect that destructiveness is the nature of that function. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-09-30refactor constify most of rb_method_definition_t卜部昌平
Most (if not all) of the fields of rb_method_definition_t are never meant to be modified once after they are stored. Marking them const makes it possible for compilers to warn on unintended modifications. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-09-27Adjusted spaces [ci skip]Nobuyoshi Nakada
2019-09-26Add compaction support to `rb_ast_t`Aaron Patterson
This commit adds compaction support to `rb_ast_t`.
2019-08-29Allow non-finalizable objects in ObjectSpace::WeakMapJean Boussier
[feature #16035] This goes one step farther than what nobu did in [feature #13498] With this patch, special objects such as static symbols, integers, etc can be used as either key or values inside WeakMap. They simply don't have a finalizer defined on them. This is useful if you need to deduplicate value objects Notes: Merged: https://github.com/ruby/ruby/pull/2313
2019-08-29drop-in type check for rb_define_singleton_method卜部昌平
We can check the function pointer passed to rb_define_singleton_method like how we do so in rb_define_method. Doing so revealed many arity mismatches.
2019-08-27st_foreach now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from st_foreach. I strongly believe that this commit should have had come with b0af0592fdd9e9d4e4b863fde006d67ccefeac21, which added extra parameter to st_foreach callbacks.
2019-08-27rb_proc_new / rb_fiber_new now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_proc_new / rb_fiber_new, and applies RB_BLOCK_CALL_FUNC_ARGLIST wherever necessary.
2019-08-27rb_ensure now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_ensure, which also revealed many arity / type mismatches.
2019-08-26this iv table should also use the new update functionAaron Patterson
2019-08-26Try only updating hash value referencesAaron Patterson
I'm afraid the keys to this hash are just integers, and those integers may look like VALUE pointers when they are not. Since we don't mark the keys to this hash, it's probably safe to say that none of them have moved, so we shouldn't try to update the references either.
2019-08-26Make `gc_update_table_refs` match `mark_tbl_no_pin` a little more closelyAaron Patterson
This commit just makes `gc_update_table_refs` match `mark_tbl_no_pin` more closely.
2019-08-21`rp(obj)` shows func, file and line. (#2394)Koichi Sasada
rp() macro for debug also shows file location and function name such as: [OBJ_INFO:rb_call_inits@inits.c:73] 0x000056147741b248 ... Notes: Merged-By: ko1
2019-08-18Fix document of `GC.start` (#2382)Masataka Pocke Kuwabara
2019-08-13* expand tabs.git
2019-08-13Removed non-VM_OBJSPACE codeNobuyoshi Nakada
It has not been used for 4 years, since r60856, e33b1690d06f867e45750bd8e3e8b06d78b5bc26.
2019-08-13Refactored `objspace_each_objects`Nobuyoshi Nakada
As `rb_objspace_each_objects_without_setup` doesn't reset and restore `dont_incremental` flag, renamed the bare iterator as `objspace_each_objects_without_setup`. `objspace_each_objects` calls it when called with the flag disabled, wrap the arguments otherwise only.
2019-08-13Move rb_objspace_t* in objspace_reachable_objects_from_root to an argumentNobuyoshi Nakada
2019-08-13* expand tabs.git
2019-08-13Hoisted out GPR_DEFAULT_REASONNobuyoshi Nakada
2019-08-13Move rb_objspace_t* in gc_verify_internal_consistency to an argumentNobuyoshi Nakada
2019-08-13Renamed ruby_finalize_{0,1}Nobuyoshi Nakada
And pass rb_execution_context_t as an argument.
2019-08-12Rename rb_gc_mark_no_pin -> rb_gc_mark_movableAaron Patterson
Renaming this function. "No pin" leaks some implementation details. We just want users to know that if they mark this object, the reference may move and they'll need to update the reference accordingly.
2019-08-12also unpin `final` on weak mapsAaron Patterson
2019-08-09gc.c: Double STACKFRAME_FOR_CALL_CFUNC (1024->2048)Yusuke Endoh
ef64ab917eec02491f6bf7233a4031a8c35385e3 didn't fix the issue, so the size seems not enough yet. https://rubyci.org/logs/rubyci.s3.amazonaws.com/osx1014/ruby-master/log/20190809T114503Z.fail.html.gz
2019-08-09gc.c: Increase STACKFRAME_FOR_CALL_CFUNCYusuke Endoh
On macOS Mojave, the child process invoked in TestFiber#test_stack_size gets stuck because the stack overflow detection is too late. (ko1 figured out the mechanism of the failure.) This change attempts to detect stack overflow earlier.
2019-08-06Extracted wmap_live_pNobuyoshi Nakada
2019-08-05Let prev EP move againAaron Patterson
The last time we committed this, we were asking the VM to write to the ep. But VM assertions check if the ENV data is the correct type, which if it's a T_MOVED pointer it's not the correct type. So the vm assertions would fail. This time we just directly write to it from the GC and that bypasses the vm assertion checks.
2019-08-06* expand tabs.git
2019-08-05add compaction support to weak mapsAaron Patterson
2019-08-02add debug_counters to check details.Koichi Sasada
add debug_counters to check the Hash object statistics.
2019-08-01Fix assertion failure when VM_CHECK_MODENobuyoshi Nakada
Some VM frames (dummy and top pushed by `rb_vm_call_cfunc`) has iseq but has no pc.
2019-08-01fix tracepoint + backtrace SEGV卜部昌平
PC modification in gc_event_hook_body was careless. There are (so to say) abnormal iseqs stored in the cfp. We have to check sanity before we touch the PC. This has not been fixed because there was no way to (ab)use the setup from pure-Ruby. However by using our official C APIs it is possible to touch such frame(s), resulting in SEGV. Fixes [Bug #14834].
2019-07-31Revert "Let prev EP move"Aaron Patterson
This reverts commit e352445863588b90f7af6cdf6c1b6dc432ee33ab. This is breaking CI and I'm not sure why yet, so I'll revert for now.
2019-07-31Let prev EP moveAaron Patterson
This commit allows the previos EP pointer to move, then updates its location
2019-07-26pass to obj_info().Koichi Sasada
obj_info() has a routine to show SPECIAL_CONST_P() objects so we don't need to check it here.