summaryrefslogtreecommitdiff
path: root/cont.c
AgeCommit message (Collapse)Author
2018-02-04mjit.c: merge MJIT infrastructurek0kubun
that allows to JIT-compile Ruby methods by generating C code and using C compiler. See the first comment of mjit.c to know what this file does. mjit.c is authored by Vladimir Makarov <vmakarov@redhat.com>. After he invented great method JIT infrastructure for MRI as MJIT, Lars Kanis <lars@greiz-reinsdorf.de> sent the patch to support MinGW in MJIT. In addition to merging it, I ported pthread to Windows native threads. Now this MJIT infrastructure can be compiled on Visual Studio. This commit simplifies mjit.c to decrease code at initial merge. For example, this commit does not provide multiple JIT threads support. We can resurrect them later if we really want them, but I wanted to minimize diff to make it easier to review this patch. `/tmp/_mjitXXX` file is renamed to `/tmp/_ruby_mjitXXX` because non-Ruby developers may not know the name "mjit" and the file name should make sure it's from Ruby and not from some harmful programs. TODO: it may be better to store this to some temporary directory which Ruby is already using by Tempfile, if it's not bad for performance. mjit.h: New. It has `mjit_exec` interface similar to `vm_exec`, which is for triggering MJIT. This drops interface for AOT compared to the original MJIT. Makefile.in: define macros to let MJIT know the path of MJIT header. Probably we can refactor this to reduce the number of macros (TODO). win32/Makefile.sub: ditto. common.mk: compile mjit.o and mjit_compile.o. Unlike original MJIT, this commit separates MJIT infrastructure and JIT compiler code as independent object files. As initial patch is NOT going to have ultra-fast JIT compiler, it's likely to replace JIT compiler, e.g. original MJIT's compiler or some future JIT impelementations which are not public now. inits.c: define MJIT module. This is added because `MJIT.enabled?` was necessary for testing. test/lib/zombie_hunter.rb: skip if `MJIT.enabled?`. Obviously this wouldn't work with current code when JIT is enabled. test/ruby/test_io.rb: skip this too. This would make no sense with MJIT. ruby.c: define MJIT CLI options. As major difference from original MJIT, "-j:l"/"--jit:llvm" are renamed to "--jit-cc" because I want to support not only gcc/clang but also cl.exe (Visual Studio) in the future. But it takes only "--jit-cc=gcc", "--jit-cc=clang" for now. And only long "--jit" options are allowed since some Ruby committers preferred it at Ruby developers Meeting on January, and some of options are renamed. This file also triggers to initialize MJIT thread and variables. eval.c: finalize MJIT worker thread and variables. test/ruby/test_rubyoptions.rb: fix number of CLI options for --jit. thread_pthread.c: change for pthread abstraction in MJIT. Prefix rb_ for functions which are used by other files. thread_win32.c: ditto, for Windows. Those pthread porting is one of major works that YARV-MJIT created, which is my fork of MJIT, in Feature 14235. thread.c: follow rb_ prefix changes vm.c: trigger MJIT call on VM invocation. Also trigger `mjit_mark` to avoid SEGV by race between JIT and GC of ISeq. The improvement was provided by wanabe <s.wanabe@gmail.com>. In JIT compiler I created and am going to add in my next commit, I found that having `mjit_exec` after `vm_loop_start:` is harmful because the JIT-ed function doesn't proceed other ISeqs on RESTORE_REGS of leave insn. Executing non-FINISH frame is unexpected for my JIT compiler and `exception_handler` triggers executions of such ISeqs. So `mjit_exec` here should be executed only when it directly comes from `vm_exec` call. `RubyVM::MJIT` module and `.enabled?` method is added so that we can skip some tests which don't expect JIT threads or compiler file descriptors. vm_insnhelper.h: trigger MJIT on method calls during VM execution. vm_core.h: add fields required for mjit.c. `bp` must be `cfp[6]` because rb_control_frame_struct is likely to be casted to another struct. The last position is the safest place to add the new field. vm_insnhelper.c: save initial value of cfp->ep as cfp->bp. This is an optimization which are done in both MJIT and YARV-MJIT. So this change is added in this commit. Calculating bp from ep is a little heavy work, so bp is kind of cache for it. iseq.c: notify ISeq GC to MJIT. We should know which iseq in MJIT queue is GCed to avoid SEGV. TODO: unload some GCed units in some safe way. gc.c: add hooks so that MJIT can wait GC, and vice versa. Simultaneous JIT and GC executions may cause SEGV and so we should synchronize them. cont.c: save continuation information in MJIT worker. As MJIT shouldn't unload JIT-ed code which is being used, MJIT wants to know full list of saved execution contexts for continuation and detect ISeqs in use. mjit_compile.c: added empty JIT compiler so that you can reuse this commit to build your own JIT compiler. This commit tries to compile ISeqs but all of them are considered as not supported in this commit. So you can't use JIT compiler in this commit yet while we added --jit option now. Patch author: Vladimir Makarov <vmakarov@redhat.com>. Contributors: Takashi Kokubun <takashikkbn@gmail.com>. wanabe <s.wanabe@gmail.com>. Lars Kanis <lars@greiz-reinsdorf.de>. Part of Feature 12589 and 14235. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-30ia64: update ia64-specific code to use execution contexthsbt
This change follows commit 837fd5e494731d7d44786f29e7d6e8c27029806f in '#ifdef __ia64' branches. Noticed as a build failure by John Paul Adrian Glaubitz: ``` cont.c:502:50: error: 'rb_thread_t {aka struct rb_thread_struct}' has no member named 'machine' size = cont->machine.register_stack_size = th->machine.register_stack_end - th->machine.register_stack_start; ^~ ``` The change is trivial: update 'th->machine' usage to 'th->ec->machine'. Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62106 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02explicit cast to void* required for %pshyouhei
These functions take variadic arguments so no automatic type promotion is expected. You have to do it by hand. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02suppress warning for clangshyouhei
In this function, "volatile" is specified twice in macro-expanded `VAR_INITIALIZED(cont)` part. That is a problem in fact. However I don't want to touch this line because it is already a messy workaround for clang SEGV. Let me just ignore. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-28`$SAFE` as a process global state. [Feature #14250]ko1
* vm_core.h (rb_vm_t): move `rb_execution_context_t::safe_level` to `rb_vm_t::safe_level_` because `$SAFE` is a process (VM) global state. * vm_core.h (rb_proc_t): remove `rb_proc_t::safe_level` because `Proc` objects don't need to keep `$SAFE` at the creation. Also make `is_from_method` and `is_lambda` as 1 bit fields. * cont.c (cont_restore_thread): no need to keep `$SAFE` for Continuation. * eval.c (ruby_cleanup): use `rb_set_safe_level_force()` instead of access `vm->safe_level_` directly. * eval_jump.c: End procs `END{}` doesn't keep `$SAFE`. * proc.c (proc_dup): removed and introduce `rb_proc_dup` in vm.c. * safe.c (rb_set_safe_level): don't check `$SAFE` 1 -> 0 changes. * safe.c (safe_setter): use `rb_set_safe_level()`. * thread.c (rb_thread_safe_level): `Thread#safe_level` returns `$SAFE`. It should be obsolete. * transcode.c (load_transcoder_entry): `rb_safe_level()` only returns 0 or 1 so that this check is not needed. * vm.c (vm_proc_create_from_captured): don't need to keep `$SAFE` for Proc. * vm.c (rb_proc_create): renamed to `proc_create`. * vm.c (rb_proc_dup): moved from proc.c. * vm.c (vm_invoke_proc): do not need to set and restore `$SAFE` for `Proc#call`. * vm_eval.c (rb_eval_cmd): rename a local variable to represent clearer meaning. * lib/drb/drb.rb: restore `$SAFE`. * lib/erb.rb: restore `$SAFE`, too. * test/lib/leakchecker.rb: check `$SAFE == 0` at the end of tests. * test/rubygems/test_gem.rb: do not set `$SAFE = 1`. * bootstraptest/test_proc.rb: catch up this change. * spec/ruby/optional/capi/string_spec.rb: ditto. * test/bigdecimal/test_bigdecimal.rb: ditto. * test/fiddle/test_func.rb: ditto. * test/fiddle/test_handle.rb: ditto. * test/net/imap/test_imap_response_parser.rb: ditto. * test/pathname/test_pathname.rb: ditto. * test/readline/test_readline.rb: ditto. * test/ruby/test_file.rb: ditto. * test/ruby/test_optimization.rb: ditto. * test/ruby/test_proc.rb: ditto. * test/ruby/test_require.rb: ditto. * test/ruby/test_thread.rb: ditto. * test/rubygems/test_gem_specification.rb: ditto. * test/test_tempfile.rb: ditto. * test/test_tmpdir.rb: ditto. * test/win32ole/test_win32ole.rb: ditto. * test/win32ole/test_win32ole_event.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-25cont.c: fix comment to follow field name changek0kubun
saved_thread was renamed to saved_ec in r59831 [ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-06cont.c: update comment for ec refactoringnormal
* cont.c (fiber_switch): update comment (ec.fiber => ec->fiber_ptr) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-06remove `PUSH_TAG`/`EXEC_AG`/`POP_TAG`/`JUMO_TAG`.ko1
* eval_intern.h: remove non-`EC_` prefix *_TAG() macros. Use `EC_` prefix macros explicitly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16fix up r60782 and r60783.ko1
* cont.c (cont_restore_thread): re-check a condition (pointed by nobu). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16avoid duplicated-cond compile error.ko1
* cont.c (cont_restore_thread): fix duplicated-cond compile error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60783 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16cleanup hook cleanup code.ko1
* vm_trace.c: before this patch, deleted hooks are remvoed at *the beggining* of hooks (exec_hooks_precheck). This patch cleanup deleted hooks at (1) just after hook is deleted (TracePoint#disable and so on) (2) just after executing hooks (exec_hooks_postcheck) Most of time (1) is enough, but if some threads running hooks, we need to wait cleaning up deleted hooks until threads finish running the hooks. This is why (2) is introduced (and this is why current impl cleanup deleted hooks at the beggining of hooks). * test/lib/tracepointchecker.rb: check also the number of delete waiting hooks. * cont.c (cont_restore_thread): fix VM->trace_running count. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-06use `GET_EC()` directly.ko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-06move rb_thread_t::interrupt_flag and maskko1
to rb_execution_context_t. * vm_core.h (rb_thread_t): move `rb_thread_t::interrupt_flag` and `rb_thread_t::interrupt_mask` to rb_execution_context_t. RUBY_VM_CHECK_INTS() accepts `ec` instead of `th`. * cont.c (rb_fiber_terminate): to propagate interrupt information, add new parameter `need_interrupt`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-06renmae ec::fiber to ec::fiber_ptr.ko1
* vm_core.h (rb_execution_context_t): renmae ec::fiber to ec::fiber_ptr make consistent with ec::thread_ptr. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29EXEC_EVENT_HOOK(ec, ...)ko1
* vm_core.h (EXEC_EVENT_HOOK): accepts `ec` instead of `th`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29`ec` has `thread_ptr`.ko1
* cont.c (rb_context_struct): move rb_context_t::thread_ptr to rb_execution_context_t::thread_ptr. * cont.c (rb_fiberptr_thread_ptr): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-28`th` -> `ec` for some functions.ko1
* vm.c (rb_vm_get_binding_creatable_next_cfp): accepts `ec` instead of `th`. * vm.c (rb_vm_stack_to_heap): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27`th` -> `ec` for block related functions.ko1
* vm.c: the following functions accept `ec` instead of `th`. * invoke_block * invoke_bmethod * invoke_iseq_block_from_c * invoke_block_from_c_bh * check_block_handler * vm_yield_with_cref * vm_yield * vm_yield_with_block * vm_yield_force_blockarg * invoke_block_from_c_proc * vm_invoke_proc * vm_invoke_bmethod * rb_vm_invoke_proc * vm_insnhelper.c: ditto. * vm_yield_with_cfunc * vm_yield_with_symbol * vm_callee_setup_block_arg * vm_yield_setup_args * vm_invoke_iseq_block * vm_invoke_symbol_block * vm_invoke_ifunc_block * vm_invoke_block git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26make root fiber at switching.ko1
* cont.c (fiber_switch): make sure the root fiber object is available before the first switching. * test/ruby/test_fiber.rb: remove "skip". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26fix freeing `th->ec` bugs.ko1
* vm.c (thread_free): simply call rb_threadptr_root_fiber_release(). * cont.c (rb_threadptr_root_fiber_release): release th->ec (ec->fiber) iff root_fiber is NULL. If root_fiber is available, then ignore it and root fiber object will free th->ec too. * cont.c (rb_threadptr_root_fiber_setup): do not set th->root_fiber. th->root_fiber will be set if a root fiber object is created. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26introduce EC_*_TAG() instead of TH_*_TAG()ko1
* eval_intern.h: introduce EC_*_TAG() macros instead of TH_*_TAG() macros. * TH_PUSH_TAG() -> EC_PUSH_TAG() * TH_POP_TAG() -> EC_POP_TAG() * TH_TMPPOP_TAG() -> EC_TMPPOP_TAG() * TH_REPUSH_TAG() -> EC_REPUSH_TAG() * TH_EXEC_TAG() -> EC_EXEC_TAG() * TH_JUMP_TAG() -> EC_JUMP_TAG() rb_threadptr_tag_state() , rb_ec_tag_jump() also accept `ec` instead of `th`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26fix commentsko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60442 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26Use rb_execution_context_t instead of rb_thread_tko1
to represent execution context [Feature #14038] * vm_core.h (rb_thread_t): rb_thread_t::ec is now a pointer. There are many code using `th` to represent execution context (such as cfp, VM stack and so on). To access `ec`, they need to use `th->ec->...` (adding one indirection) so that we need to replace them by passing `ec` instead of `th`. * vm_core.h (GET_EC()): introduced to access current ec. Also remove `ruby_current_thread` global variable. * cont.c (rb_context_t): introduce rb_context_t::thread_ptr instead of rb_context_t::thread_value. * cont.c (ec_set_vm_stack): added to update vm_stack explicitly. * cont.c (ec_switch): added to switch ec explicitly. * cont.c (rb_fiber_close): added to terminate fibers explicitly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-12cont.c: update comment to match r59776 [ci skip]normal
* cont.c (fiber_switch): th->fiber => th->ec.fiber in comment git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-10store ec instead of thread in rb_context_t.ko1
* cont.c (rb_context_t): introduce saved_ec instaad of saved_thread. We only need to transfer ec data (not all of thread data). Introduce `thread_value` field to point creation thread. To acccess this field, `cont_thread_value()` is introduced. * vm.c (rb_execution_context_mark): remove `static` and use it from cont.c (use this function instead of `rb_thread_mark`). * vm_insnhelper.c (rb_vm_push_frame): accept ec instead of th. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-10avoid false positive on fiber_verify().ko1
* cont.c (fiber_store): move `cont_save_machine_stack()` timing to avoid `fiber_verify()` false positive on `FIBER_USE_NATIVE == 0` and `GC.stress = true`. This patch is very dirty and it should be removed soon. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-10clear `stack_end`.ko1
* cont.c (cont_save_thread): clear only `stack_end`. Clearing tells GC mark function to ignore this macine stack (not allocated yet). `stack_start` will be used by machine stack store/restore phase (on FIBER_USE_NATIVE == 0), so that only `stack_end` is cleared. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-10cont.c: fix typo [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-10move th->machine to ec->machine.ko1
* vm_core.h: move rb_thread_t::machine to rb_execution_context_t::machine. * vm_core.h, gc.c (rb_gc_mark_machine_stack): accept ec instead of th. it enables to call this func from rb_execution_context_mark() in vm.c. * cont.c (fiber_setcontext): catch up this fix. fiber_restore_thread() restores machine stack information too. * gc.c: catch up structure layout changes. * thread.c: ditto. * thread_pthread.c: ditto. * thread_win32.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-08fiber: fix machine stack marking when FIBER_USE_NATIVE is 0normal
* cont.c (cont_mark): mark Fiber machine stack correctly when FIBER_USE_NATIVE is 0 * test/ruby/test_fiber.rb (test_mark_fiber): new test [Bug #13875] [ruby-core:82681] This bug appears to be introduced with r59557. ("refactoring Fiber status") git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-08fix up r59776nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-08move th->fiber to ec->fiber.ko1
* vm_core.h (rb_thread_t::fiber): move fiber field to rb_execution_context_t::fiber. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-02cont.c: fix root fiber to_snobu
* cont.c (fiber_to_s): fix Fiber#to_s on root fibers which have no procs. [ruby-core:82629] [Bug #13859] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-23remove debug code.ko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-22split out struct cont_saved_vm_stack.ko1
* cont.c: introduce `struct cont_saved_vm_stack` which was part of `struct rb_context_struct`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-10fix a typo in comment.nagachika
* cont.c (typedef struct rb_context_struct): fix a typo in comment. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-10use VM_UNREACHABLE() instead of rb_bug().ko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-10introduce fiber_restore_thread.ko1
* cont.c (fiber_restore_thread): added (separate from cont_restore_thread). * cont.c (fiber_setcontext): call fiber_restore_thread() directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-10rename rb_execution_context_t::stack(_size) to vm_stack(_size).ko1
* vm_core.h: Ruby processes run with two stacks, a machine stack and a VM stack. To make it clear, this fix renames rb_execution_context_t::stack(_size) to vm_stack(_size). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-10cont.c: fix up r59557 for !FIBER_USE_NATIVEnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-10constify some variables.ko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-10remove additional newline.ko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-10Fiber#to_s (#inspect) return richer information.ko1
* cont.c (fiber_to_s): return with block and status information. * proc.c (proc_to_s_): removed and introduce rb_block_to_s() function to return block information string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-10refactoring Fiber status.ko1
* cont.c: revisit fiber status. "FIBER_RUNNING" status represents fiber is resumed or suspended. This fix separate these two status explicitly. FIBER_CREATED: Just after Fiber.new. Not resumed yet. FIBER_RESUMED (new): Fiber#resumed. Now this fiber is running. FIBER_SUSPENDED (new): Suspended by Fiber.yield. Not running. FIBER_TERMINATED: Terminated. Add sevral assertions to check consistency with these status. * cont.c (fiber_status_set): added to change status. * cont.c (FIBER_xxx_P): added to check fiber status. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-02fix stack storing for root fibers.ko1
* cont.c (root_fiber_alloc): this function is called by fiber_current() and fiber_store(). fiber_current() should clear VM stack information in a fiber data because runnning thread knows stack information and has responsibility to manage it. However fiber_store() requires to remain VM stack information in a fiber data because the responsibility to manage VM stack is moved to the Fiber from the Thread (and switch to another fiber). * cont.c (root_fiber_alloc): save thread's fiber and root_fiber information. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-02release VM stack properly.ko1
* cont.c: r55766 change the handling method of Fiber's VM stack. Resumed Fiber points NULL as VM stack and running Thread has responsibility to manage it (marking and releasing). However, thread_start_func_2()@thread.c and thread_free()@vm.c doesn't free the VM stack if corresponding root Fiber is exist. This causes memory leak. [Bug #13772] * cont.c (root_fiber_alloc): fib->cont.saved_thread.ec.stack should be NULL because running thread has responsibility to manage this stack. * vm.c (rb_thread_recycle_stack_release): assert given stack is not NULL (callers should care it). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-28introduce rb_fiber_t::first_proc.ko1
* cont.c (rb_fiber_t): add rb_fiber_t::first_proc and do not use rb_thread_t::first_proc which should be thread local. [Bug #13689] * test/ruby/test_thread.rb: test for [Bug #13689]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-28move fields to ec.ko1
* vm_core.h (rb_thread.h): move errinfo and trace_arg to rb_execution_context_t. * cont.c (fiber_switch, rb_cont_call): do not restore "trace_arg" here. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-28move fields to ec.ko1
* vm_core.h (rb_thread_t): move root_lep, root_svar and ensure_list to rb_execution_context_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-28introduce rb_thread_ptr() to replace GetThreadPtr().ko1
* vm_core.h (rb_thread_ptr): added to replace GetThreadPtr() macro. * thread.c (in some functions: use "target_th" instead of "th" to make clear that it is not a current thread. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e