summaryrefslogtreecommitdiff
path: root/cont.c
AgeCommit message (Collapse)Author
2019-07-18Add FIBER_POOL_ALLOCATION_FREE to control allocation/free strategy.Samuel Williams
2019-07-18Limit expansion of fiber pool on 32-bit platforms.Samuel Williams
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.
2019-07-18Enable `madvise` to release stack space back to OS.Samuel Williams
2019-07-18Improve build process and coroutine implementation selection.Samuel Williams
2019-07-18Stack copying implementation of coroutines.Samuel Williams
2019-07-18Implement fiber pool for reduced fiber allocation overhead.Samuel Williams
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.
2019-07-18Make FIBER_USE_NATIVE the default and reformat code.Samuel Williams
2019-07-08* expand tabs.git
2019-07-08Fix indentNobuyoshi Nakada
2019-07-08Renamed fib to fiberNobuyoshi Nakada
2019-06-26Use native coroutine implementation on OpenBSD-amd64Jeremy Evans
When using native fibers, do not load ucontext, as it isn't needed.
2019-06-26Add `ucontext` coroutine implementation for generic fallback.Samuel Williams
2019-06-24* remove trailing spaces.git
2019-06-24Print warning if not using native coroutine.Samuel Williams
2019-06-20Transition root fiber into state FIBER_TERMINATED.Samuel Williams
During fork, it's possible that threads with root fibers are terminated, but fiber state is not updated. `fiber_verify` will subsequently fail. We forcefully enter the FIBER_TERMINATED state when terminating the root fiber.
2019-06-20Ensure that vm_stack is cleared in `thread_cleanup_func_before_exec`.Samuel Williams
If `vm_stack` is left dangling in a forked process, the gc attempts to scan it, but it is invalid and will cause a segfault. Therefore, we clear it before forking. In order to simplify this, `rb_ec_clear_vm_stack` was introduced.
2019-06-20Revert failed attempt at fixing invalid usage of vm_stack.Samuel Williams
2019-06-20Ensure `vm_stack` is cleared after fork.Samuel Williams
2019-06-20Set `cfp` to null (along with vm_stack) in `rb_fiber_close`.Samuel Williams
2019-06-19Adjust indentNobuyoshi Nakada
2019-06-19Remove IA64 support.Samuel Williams
2019-06-19Use shared implementation of `rb_ec_initialize_vm_stack`.Samuel Williams
2019-06-19Track how stack was allocated for `cont_free`.Samuel Williams
2019-06-19Better handling of root fiber.Samuel Williams
2019-06-12* expand tabs.git
2019-06-11Add compaction support for more types.Aaron Patterson
This commit adds compaction support for: * Fibers * Continuations * Autoload Constants
2019-04-27ia64: Don't clear register_stack_startJames Clarke
r59829 stopped clearing stack_start and enabled the code for !FIBER_USE_NATIVE, but we need to do the same for register_stack_start on ia64, otherwise we end up with NULL in cont_save_machine_stack. Closes: https://github.com/ruby/ruby/pull/2155
2019-03-22[DOC] fix markups [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09Fix styles [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-28Fix #endif annotation.samuel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66612 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-28Don't allow rb_fiber_resume to raise exception on unborn fiber.samuel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-28Implement Fiber#raise. Fixes #10344.samuel
This allows raising exceptions in another fiber, similarly to Thread#raise. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-01Avoid GCing dead stack after switching away from a fibersamuel
Fixes <https://bugs.ruby-lang.org/issues/14561> and discussed <https://bugs.ruby-lang.org/issues/15362>. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26Give up support for cross-callcc set_trace_func.ko1
* cont.c (cont_restore_thread): cause error if trace-status is changed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26Support targetting TracePoint [Feature #15289]ko1
* vm_trace.c (rb_tracepoint_enable_for_target): support targetting TracePoint. [Feature #15289] Tragetting TracePoint is only enabled on specified method, proc and so on, example: `tp.enable(target: code)`. `code` should be consisted of InstructionSeuqnece (iseq) (RubyVM::InstructionSeuqnece.of(code) should not return nil) If code is a tree of iseq, TracePoint is enabled on all of iseqs in a tree. Enabled tragetting TracePoints can not enabled again with and without target. * vm_core.h (rb_iseq_t): introduce `rb_iseq_t::local_hooks` to store local hooks. `rb_iseq_t::aux::trace_events` is renamed to `global_trace_events` to contrast with `local_hooks`. * vm_core.h (rb_hook_list_t): add `rb_hook_list_t::running` to represent how many Threads/Fibers are used this list. If this field is 0, nobody using this hooks and we can delete it. This is why we can remove code from cont.c. * vm_core.h (rb_vm_t): because of above change, we can eliminate `rb_vm_t::trace_running` field. Also renamed from `rb_vm_t::event_hooks` to `global_hooks`. * vm_core.h, vm.c (ruby_vm_event_enabled_global_flags): renamed from `ruby_vm_event_enabled_flags. * vm_core.h, vm.c (ruby_vm_event_local_num): added to count enabled targetting TracePoints. * vm_core.h, vm_trace.c (rb_exec_event_hooks): accepts hook list. * vm_core.h (rb_vm_global_hooks): added for convinience. * method.h (rb_method_bmethod_t): added to maintain Proc and `rb_hook_list_t` for bmethod (defined by define_method). * prelude.rb (TracePoint#enable): extracet a keyword parameter (because it is easy than writing in C). It calls `TracePoint#__enable` internal method written in C. * vm_insnhelper.c (vm_trace): check also iseq->local_hooks. * vm.c (invoke_bmethod): check def->body.bmethod.hooks. * vm.c (hook_before_rewind): check iseq->local_hooks and def->body.bmethod.hooks before rewind by exception. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22Use VirtualAlloc/VirtualProtect/VirtualFree for windows stack allocation.samuel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20Fix conditionnobu
FIBER_USE_NATIVE is always defined as 0 or 1, use `#if` instead of `#ifdef`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20Make fiber_entry staticnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20Fix windows builds.samuel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65878 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20Expose stack functions to coroutine and non-windows implementations.samuel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20Fix exposure of stack allocations.samuel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20Use malloc/free for windows stack allocation.samuel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20Remove trailing whitespace.samuel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20Restore native non-coroutine code path.samuel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20It cannot be const because it is being passed to destructive operation ↵samuel
(destroy). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20Better support for amd64 platformssamuel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20Native implementation of coroutines to improve performance of fiberssamuel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-16Prefix rb_ec_set_vm_stacknobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-13suppress integer overflow warningsshyouhei
* random.c: annotate rb_hash_start with NO_SANITIZE (seed.key.hash + h overflows and that seems intentional) * bignum.c: avoid (size_t)-- * cont.c: ditto * util.c: ditto * vm_insnhelper.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-06cont.c: direct use of rb_thread_tshyouhei
The only usage of rb_fiber_reset_root_local_storage() is from ruby_vm_destruct(), where the object space is already terminated. This `th->self` is not alive. Why not just use `th` itself. See also: https://travis-ci.org/ruby/ruby/jobs/451294954 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e