summaryrefslogtreecommitdiff
path: root/cont.c
AgeCommit message (Collapse)Author
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
2017-06-28move storages to ec.ko1
* vm_core.h (rb_thread_t): move storages to rb_execution_context_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-26move several fields from rb_thread_t to rb_execution_context_t.ko1
* vm_core.h (rb_thread_t): move several fields which are copied at cont.c to rb_execution_context_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-26copy ec on Fiber.ko1
* cont.c (cont_restore_thread): on Fiber we only need to copy ec struct. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-26add "FIBER_" prefix.ko1
* cont.c (enum fiber_status): add "FIBER_" prefix for all names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-26Do not store/restore Thread#status on fiber switching.ko1
* cont.c (cont_restore_thread): On Fiber switching, thread status shold be THREAD_RUNNABLE so that we don't need to store/restore this field. * cont.c (cont_save_thread): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23move "state" to rb_vm_tag.ko1
* vm_core.h (rb_thread_t::tag_state): move to "rb_vm_tag::state". Lifetime of "state" should be same as current tag. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23rename th->state to th->tag_state.ko1
* vm_core.h (rb_thread_t): rename rb_thread_t::state to tag_state to make it clear. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23use "enum ruby_tag_type" and TAG_NONE.ko1
Return value of EXEC_TAG() is saved by "int state". Instead of "int", use "enum ruby_tag_type". First EXEC_TAG() value should be 0, so that define TAG_NONE (= 0) and use it. Some code used "status" instead of "state". To make them clear, rename them to state. We can change variable name from "state" to "tag_state", but this ticket doesn't contain it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-09rb_execution_context_t: move stack, stack_size and cfp from rb_thread_tnormal
The goal is to reduce rb_context_t and rb_fiber_t size by removing the need to store the entire rb_thread_t in there. [ruby-core:81045] Work-in-progress: soon, we will move more fields here. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-17remove branches in dmark and dfree GC callbacksnormal
dmark and dfree callbacks are never called in gc.c for NULL DATA_PTR values, not even for zombie objects. * compile.c (ibf_loader_mark): remove branch for pointer validity * compile.c (ibf_loader_free): ditto * cont.c (cont_free): ditto * cont.c (fiber_free): ditto * dir.c (dir_free): ditto * ext/stringio/stringio.c (strio_mark): ditto * proc.c (binding_free): ditto * thread_sync.c (mutex_free): ditto * vm.c (thread_free): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-14Fiber also has same issue. [Bug #13313]ko1
* thread.c (rb_vm_proc_local_ep): added. * cont.c (rb_fiber_start): use rb_vm_proc_local_ep(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-13cont.c: avoid needless branch for dmark callbacksnormal
gc.c (gc_mark_children, case T_DATA) does not use the dmark function pointer if DATA_PTR is NULL * cont.c (cont_mark, fiber_mark): remove branch, ptr is never NULL git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-27cont.c: change fiber stack size doc [ci skip]normal
It's many years since we had tiny 4KB fiber stacks :< point to the manpage instead for current, larger sizes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-07Add volatile to a suppress warning.shugo
Without the fix, the following warning is shown: compiling cont.c cont.c: In function ‘rb_callcc’: cont.c:949:39: warning: passing argument 1 of ‘cont_capture’ discards ‘volatile’ qualifier from pointer target type [-Wdiscarded-qualifiers] volatile VALUE val = cont_capture(&called); ^ cont.c:473:1: note: expected ‘int * volatile’ but argument is of type ‘volatile int *’ cont_capture(int *volatile stat) ^ git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-07Add clang volatile fixes from FreeBSD and NetBSD.shugo
Use volatile instead of optnone to avoid optimization which causes segmentation faults. Patch by Dimitry Andric. [ruby-core:78531] [Bug #13014] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05* vm_trace.c (tracepoint_attr_callee_id, rb_tracearg_callee_id):ktsj
add TracePoint#callee_id. [ruby-core:77241] [Feature #12747] * cont.c, eval.c, gc.c, include/ruby/intern.h, insns.def, thread.c, vm.c, vm_backtrace.c, vm_core.h, vm_eval.c, vm_insnhelper.c, vm_trace.c: ditto. * test/ruby/test_settracefunc.rb: tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05* cont.c (cont_new): disable optimization if clang's version isshugo
3.8.0. [ruby-core:77894] [Bug #12893] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-03* vm_core.h: introduce VM_FRAME_RUBYFRAME_P()ko1
and VM_FRAME_CFRAME_P(). Most of case, RUBY_VM_NORMAL_ISEQ_P() is no longer needed. * vm_core.h: introduce rb_obj_is_iseq(). * cont.c, vm.c: VM_FRAME_MAGIC_DUMMY with VM_FRAME_FLAG_CFRAME. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55804 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-28* vm_core.h: revisit the structure of frame, block and env.ko1
[Bug #12628] This patch introduce many changes. * Introduce concept of "Block Handler (BH)" to represent passed blocks. * move rb_control_frame_t::flag to ep[0] (as a special local variable). This flags represents not only frame type, but also env flags such as escaped. * rename `rb_block_t` to `struct rb_block`. * Make Proc, Binding and RubyVM::Env objects wb-protected. Check [Bug #12628] for more details. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-01* cont.c, hash.c, random.c, win32/win32.c: cleanup some Win9x/ME/NT4usa
support leftovers. [fix GH-1328] patched by @cremno git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-14cont.c: wrong _MSC_VER checknobu
* cont.c (fiber_initialize_machine_stack_context): fix wrong _MSC_VER check, should be decimal but not hexadecimal. [ruby-core:74936] [Bug #12279] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-24fix common misspelling [ci skip]nobu
* compile.c, cont.c, doc, man: fix common misspelling. [ruby-core:72466] [Bug #11870] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-10* cont.c: fix a double word typo.hsbt
[Bug #11313][ruby-core:69749] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-09* *.c (*_memsize): do not check ptr.ko1
NULL checking is finished Before call of memsize functions. See r52979. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-20cont.c: append to continuations doc [ci skip]nobu
* cont.c (rb_callcc): [DOC] append continuations example accros methods. [Fix GH-1026] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51906 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-21* include/ruby/ruby.h, cont.c, vm_trace.c: add a new eventko1
fiber_switch. We need more discussion about this feature so that I don't write it on NEWS. [Feature #11348] * test/ruby/test_settracefunc.rb: add tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-21cont.c: CreateFiberEx fallbacknobu
* cont.c (fiber_initialize_machine_stack_context): fallback definition of CreateFiberEx for VC6. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51315 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-13remove needless volatilenobu
* array.c (rb_ary_each): remove needless volatile for outdated clang 3.0. revert r32201. * cont.c (cont_capture): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-07* cont.c (cont_free): remove mysterious fflush()ko1
introduced at r19890, maybe accidentaly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-06* cont.c (fiber_init): initialize control frame correctly.ko1
This fix does not affect any ordinal execution, but affects debug prints. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-03* method.h: introduce rb_callable_method_entry_t to removeko1
rb_control_frame_t::klass. [Bug #11278], [Bug #11279] rb_method_entry_t data belong to modules/classes. rb_method_entry_t::owner points defined module or class. module M def foo; end end In this case, owner is M. rb_callable_method_entry_t data belong to only classes. For modules, MRI creates corresponding T_ICLASS internally. rb_callable_method_entry_t can also belong to T_ICLASS. rb_callable_method_entry_t::defined_class points T_CLASS or T_ICLASS. rb_method_entry_t data for classes (not for modules) are also rb_callable_method_entry_t data because it is completely same data. In this case, rb_method_entry_t::owner == rb_method_entry_t::defined_class. For example, there are classes C and D, and incldues M, class C; include M; end class D; include M; end then, two T_ICLASS objects for C's super class and D's super class will be created. When C.new.foo is called, then M#foo is searcheed and rb_callable_method_t data is used by VM to invoke M#foo. rb_method_entry_t data is only one for M#foo. However, rb_callable_method_entry_t data are two (and can be more). It is proportional to the number of including (and prepending) classes (the number of T_ICLASS which point to the module). Now, created rb_callable_method_entry_t are collected when the original module M was modified. We can think it is a cache. We need to select what kind of method entry data is needed. To operate definition, then you need to use rb_method_entry_t. You can access them by the following functions. * rb_method_entry(VALUE klass, ID id); * rb_method_entry_with_refinements(VALUE klass, ID id); * rb_method_entry_without_refinements(VALUE klass, ID id); * rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me); To invoke methods, then you need to use rb_callable_method_entry_t which you can get by the following APIs corresponding to the above listed functions. * rb_callable_method_entry(VALUE klass, ID id); * rb_callable_method_entry_with_refinements(VALUE klass, ID id); * rb_callable_method_entry_without_refinements(VALUE klass, ID id); * rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me); VM pushes rb_callable_method_entry_t, so that rb_vm_frame_method_entry() returns rb_callable_method_entry_t. You can check a super class of current method by rb_callable_method_entry_t::defined_class. * method.h: renamed from rb_method_entry_t::klass to rb_method_entry_t::owner. * internal.h: add rb_classext_struct::callable_m_tbl to cache rb_callable_method_entry_t data. We need to consider abotu this field again because it is only active for T_ICLASS. * class.c (method_entry_i): ditto. * class.c (rb_define_attr): rb_method_entry() does not takes defiend_class_ptr. * gc.c (mark_method_entry): mark RCLASS_CALLABLE_M_TBL() for T_ICLASS. * cont.c (fiber_init): rb_control_frame_t::klass is removed. * proc.c: fix `struct METHOD' data structure because rb_callable_method_t has all information. * vm_core.h: remove several fields. * rb_control_frame_t::klass. * rb_block_t::klass. And catch up changes. * eval.c: catch up changes. * gc.c: ditto. * insns.def: ditto. * vm.c: ditto. * vm_args.c: ditto. * vm_backtrace.c: ditto. * vm_dump.c: ditto. * vm_eval.c: ditto. * vm_insnhelper.c: ditto. * vm_method.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-02* method.h: make rb_method_entry_t a VALUE.ko1
Motivation and new data structure are described in [Bug #11203]. This patch also solve the following issues. * [Bug #11200] Memory leak of method entries * [Bug #11046] __callee__ returns incorrect method name in orphan proc * test/ruby/test_method.rb: add a test for [Bug #11046]. * vm_core.h: remvoe rb_control_frame_t::me. me is located at value stack. * vm_core.h, gc.c, vm_method.c: remove unlinked_method... codes because method entries are simple VALUEs. * method.h: Now, all method entries has own independent method definititons. Strictly speaking, this change is not essential, but for future changes. * rb_method_entry_t::flag is move to rb_method_definition_t::flag. * rb_method_definition_t::alias_count is now rb_method_definition_t::alias_count_ptr, a pointer to the counter. * vm_core.h, vm_insnhelper.c (rb_vm_frame_method_entry) added to search the current method entry from value stack. * vm_insnhelper.c (VM_CHECK_MODE): introduced to enable/disable assertions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-30cont.c: Check ruby_current_threadnobu
* cont.c (cont_free): check if ruby_current_thread is still valid. [Fix GH-914] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e