aboutsummaryrefslogtreecommitdiffstats
path: root/cont.c
Commit message (Collapse)AuthorAgeFilesLines
* Prevent unloading methods used in root_fiber while calling another Fiber (#2939)Takashi Kokubun2020-03-151-3/+18
| | | | | | | | | | 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 [Bug #16664] (cherry picked from commit adcf0316d1ecedae2a9157ad941550e0c0fb510b)
* Fixed misspellingsNobuyoshi Nakada2019-12-201-1/+1
| | | | Fixed misspellings reported at [Bug #16437], only in ruby and rubyspec.
* Suppress strict-aliasing warning by x86_64-w64-mingw32-gcc 7.4.0Nobuyoshi Nakada2019-11-281-2/+2
|
* Fix a typo [ci skip]Kazuhiro NISHIYAMA2019-11-041-1/+1
|
* ruby_mimmalloc can return NULL卜部昌平2019-11-011-0/+3
| | | | malloc can fail. Should treat such situations.
* Fix continuation mark / compactAaron Patterson2019-10-281-0/+6
|
* Fix documentation for Fiber#transfer [ci skip]Jeremy Evans2019-10-261-6/+13
| | | | | | | | | | | | | | | | | Fiber#transfer prevents calling Fiber#resume on the receiver of the transfer method, not the fiber calling transfer. Transfering back to a fiber does not allow later calling resume on the fiber. Once transfer has been called on a fiber, you can never call resume on the fiber. Calling resume on a transferred fiber is not a double resume error, it is a different FiberError (cannot resume transferred Fiber). For details on the differences between transferred fibers and regular fibers, see Sasada-san's RubyKaigi 2017 presentation (in short, Fiber#transfer is for coroutine, Fiber#resume is for semi-coroutine).
* show "transferred" attribute on Fiber#to_sKoichi Sasada2019-10-241-4/+10
| | | | | | | If a fiber is invoked with transfer method (such as "f.transfer"), then the invoked fiber ("f") is labeled as "transferred" and this fiber can not be invoked with Fiber#resume. This patch adds transferred attribute for "Fiber#to_s" (and inspect).
* Revert "Fix Fiber#transfer"Koichi Sasada2019-10-241-2/+1
| | | | | | This reverts commit fa8ac91e957a076f6df1adaecad7896817138009. Previous behavior is intentional.
* Fix Fiber#transferJeremy Evans2019-10-211-1/+2
| | | | | | | | | | | | | Fiber#transfer previously made it impossible to resume the fiber if it was transferred to (no resuming the target of Fiber#transfer). However, the documentation specifies that you cannot resume a fiber that has transferred to another fiber (no resuming the source of Fiber#transfer), unless control is transferred back. Fix the code by setting the transferred flag on the current/source fiber, and unsetting the transferred flag on the target fiber. Fixes [Bug #9664] Fixes [Bug #12555]
* Add rb_adjust_argv_kw_splat to internal.hJeremy Evans2019-09-261-1/+0
| | | | | We are calling this in a few other files, it is better to have it in a header than adding prototypes to the other files.
* Fix clang errors when pendantic errors enabledAaron Patterson2019-09-261-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | I've been compiling with: ``` set -lx cflags '-std=c99 -Werror=pedantic -pedantic-errors' ``` But compilation would fail with the following: ``` cont.c:296:90: error: format specifies type 'void *' but the argument has type 'struct fiber_pool_stack *' [-Werror,-Wformat-pedantic] if (DEBUG) fprintf(stderr, "fiber_pool_stack_alloca(%p): %"PRIuSIZE"/%"PRIuSIZE"\n", stack, offset, stack->available); ~~ ^~~~~ cont.c:467:24: error: format specifies type 'void *' but the argument has type 'struct fiber_pool *' [-Werror,-Wformat-pedantic] count, fiber_pool, fiber_pool->used, fiber_pool->count, size, fiber_pool->vm_stack_size); ^~~~~~~~~~ cont.c:588:83: error: format specifies type 'void *' but the argument has type 'struct fiber_pool_vacancy *' [-Werror,-Wformat-pedantic] if (DEBUG) fprintf(stderr, "fiber_pool_stack_acquire: %p used=%"PRIuSIZE"\n", fiber_pool->vacancies, fiber_pool->used); ~~ ^~~~~~~~~~~~~~~~~~~~~ cont.c:736:76: error: format specifies type 'void *' but the argument has type 'rb_fiber_t *' (aka 'struct rb_fiber_struct *') [-Werror,-Wformat-pedantic] if (DEBUG) fprintf(stderr, "fiber_stack_release: %p, stack.base=%p\n", fiber, fiber->stack.base); ``` This commit just fixes the pedantic errors
* Fix keyword argument separation issues in Fiber#resumeJeremy Evans2019-09-261-11/+30
|
* Add VM_NO_KEYWORDSJeremy Evans2019-09-051-1/+1
| | | | | I think this is easier to read than using literal 0 with comments in every case where it is used.
* Propagate kw_splat informationYusuke Endoh2019-09-051-1/+1
| | | | | | | The kw_splat flag is whether the original call passes keyword or not. Some types of methods (e.g., bmethod and sym_proc) drops the information. This change tries to propagate the flag to the final callee, as far as I can.
* rb_proc_new / rb_fiber_new now free from ANYARGS卜部昌平2019-08-271-1/+1
| | | | | | | 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.
* rb_ensure now free from ANYARGS卜部昌平2019-08-271-7/+9
| | | | | | 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.
* cont.c: remove unused STACK_GROW_DIR_DETECTIONYusuke Endoh2019-08-191-2/+0
| | | | to suppress a waring for "unused variable"
* Use more different arguments in Fiber.yield documentation to make it clear ↵Iain Barnett2019-08-171-3/+3
| | | | | | | | | | | | (#2170) https://github.com/ruby/ruby/pull/2170#issuecomment-489880700 Documentation is for those who don't know, remember, or understand (to any degree) the language, it should attempt to be clear above all other things. The example given is needlessly unclear because if you use a block it's common for arguments to be reused on every entry to the block. In Fiber's case this is not so. First time round 10 goes in, 12 comes out. Second time round 14 goes in, 14 comes out… was that because 14 is 12 + 2 or because it's "the return value of the call to Fiber.yield". It's the latter because it says so but why does the example need to make anyone think the former? Using different numbers makes it immediately clear what's happening whether the description is there or not.
* Rename rb_gc_mark_no_pin -> rb_gc_mark_movableAaron Patterson2019-08-121-3/+3
| | | | | | 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.
* Fix a typo [ci skip]Kazuhiro NISHIYAMA2019-08-131-1/+1
|
* Fix unused variableKazuhiro NISHIYAMA2019-07-291-3/+3
|
* Use PRIuSIZE instead of "%zu"Nobuyoshi Nakada2019-07-251-7/+10
|
* Add documentation to `fiber_pool_allocate_memory`.Samuel Williams2019-07-191-0/+7
|
* Fix 32-bit build and typo.Samuel Williams2019-07-191-2/+2
| | | | | "Therefore, `fiber_pool_stack_free(&vacancy->stack)` can do the wrong thing..." should be "... `fiber_pool_stack_free(stack)` ...".
* Ensure that madvise does not clobber vacancy data.Samuel Williams2019-07-191-5/+19
| | | | | | | | | After calling `fiber_pool_vacancy_reset`, `vacancy->stack` and `stack` are no longer in sync. Therefore, `fiber_pool_stack_free(&vacancy->stack)` can do the wrong thing and clobber the vacancy data. Additionally, when testing using VM_CHECK_MODE > 0, use MADV_DONTNEED if possible, to catch issues w.r.t. clobbered vacancy data earlier.
* Better usage of `rb_ec_clear_vm_stack` to maintain invariants.Samuel Williams2019-07-191-6/+7
|
* Improve ec assertions.Samuel Williams2019-07-191-8/+0
|
* initialize only Fiber's cfp.Koichi Sasada2019-07-191-0/+1
| | | | | | | fiber->cont.saved_ec.cfp should be initialized by NULL because no vm_stack is allocated. However, cont_init() captures current Fiber's cfp for continuation, so it should only initialize fibers.
* Revert "Ensure cfp is initialized to NULL."Samuel Williams2019-07-191-6/+0
| | | | This reverts commit d7fdf45a4ae1bcb6fac30a24b025d4f20149ba0a.
* Ensure cfp is initialized to NULL.Samuel Williams2019-07-191-0/+6
| | | | | | | `cont_init` didn't initialize `cont->saved_ec.cfp`. Calling `cont_mark` would result in an invalid `cfp` in `rb_execution_context_mark`. Because fibers lazy-initialize the stack, fibers that are created but not resumed could cause this problem to occur.
* Remove `rb_vm_push_frame` as it is no longer used.Samuel Williams2019-07-191-12/+0
|
* Adjust styles and indentsNobuyoshi Nakada2019-07-191-21/+33
|
* check saved_ec.cfpKoichi Sasada2019-07-181-1/+3
|
* Ensure we don't have dangling cfp.Samuel Williams2019-07-191-0/+1
|
* * remove trailing spaces.git2019-07-181-1/+1
|
* Improve `fiber_pool_expand` allocation strategy.Samuel Williams2019-07-181-23/+47
| | | | | | | | If `mmap` fails to allocate memory, try half the size, and so on. Limit FIBER_POOL_ALLOCATION_MAXIMUM_SIZE to 1024 stacks. In typical configurations this limits the memory mapped region to ~128MB per allocation.
* Add experimental `RUBY_SHARED_FIBER_POOL_FREE_STACKS` to control madvise.Samuel Williams2019-07-181-0/+5
|
* Make fiber_pool more conservative on platforms with limited address space.Samuel Williams2019-07-181-12/+12
| | | | | | | We use COROUTINE_LIMITED_ADDRESS_SPACE to select platforms where address space is 32-bits or less. Fiber pool implementation enables more book keeping, and reduces upper limits, in order to minimise address space utilisation.
* Add `struct fiber_pool {int free_stacks;}` to control usage of madvise.Samuel Williams2019-07-181-1/+10
| | | | | | | `madvise(free)` and similar operations are good because they avoid swap usage by clearing the dirty bit on memory pages which are mapped but no longer needed. However, there is some performance penalty if there is no memory pressure. Therefore, we do it by default, but it can be avoided.
* Add FIBER_POOL_ALLOCATION_FREE to control allocation/free strategy.Samuel Williams2019-07-181-8/+43
|
* Limit expansion of fiber pool on 32-bit platforms.Samuel Williams2019-07-181-46/+150
| | | | | | | | | On 32-bit platforms, expanding the fiber pool by a large amount may fail, even if a smaller amount may succeed. We limit the maximum size of a single allocation to maximise the number of fibers that can be allocated. Additionally, we implement the book-keeping required to free allocations when their usage falls to zero.
* Enable `madvise` to release stack space back to OS.Samuel Williams2019-07-181-98/+142
|
* Improve build process and coroutine implementation selection.Samuel Williams2019-07-181-6/+1
|
* Stack copying implementation of coroutines.Samuel Williams2019-07-181-2/+23
|
* Implement fiber pool for reduced fiber allocation overhead.Samuel Williams2019-07-181-192/+508
| | | | | | | Replace previous stack cache with fiber pool cache. The fiber pool allocates many stacks in a single memory region. Stack allocation becomes O(log N) and fiber creation is amortized O(1). Around 10x performance improvement was measured in micro-benchmarks.
* Make FIBER_USE_NATIVE the default and reformat code.Samuel Williams2019-07-181-518/+252
|
* * expand tabs.git2019-07-081-35/+35
|
* Fix indentNobuyoshi Nakada2019-07-081-4/+4
|
* Renamed fib to fiberNobuyoshi Nakada2019-07-081-244/+244
|