NoMemoryError is better than rb_bug, of course.
Patch by Eric Wong. [ruby-core:38572][ruby-core:38594].
* signal.c (rb_register_sigaltstack): ditto.
* vm_core.h: moved ALT_STACK_SIZE definition from signal.c.
* vm.c (thread_free): use xfree() instead of free().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32749 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
(rb_gc_mark_unlinked_live_method_entries): fix SEGV bug.
rb_method_entry_t was free'd even when the method is still on the
stack if it is BMETHOD (i.e., Method#call). This is because
rb_method_entry_t is embedded in struct METHOD. This commit
separates them and marks the live method entries.
See [ruby-core:38449] in detail. fix [Bug #5047] [ruby-core:38171]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32669 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
'inhibit_thread_createion' field.
* thread.c (rb_thread_terminate_all): set inhibit_thread_creation.
* thread.c (thread_s_new): don't permit to create new thread
if the VM is under destruction. Otherwise evil finalizer code
can make SEGV. [Bug #4992][ruby-core:37858]
* bootstraptest/test_objectspace.rb: new test for this fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (rb_threadptr_execute_interrupts_common): check signal
deliverly if it is main thread.
fixes [ruby-dev:44005] [Ruby 1.9 - Bug #4950]
* bootstraptest/test_fork.rb: add a test for above.
* signal.c (rb_get_next_signal): skip if signal_buff is empty.
(check signal_buff.size first)
* vm_core.h: remove unused variable rb_thread_t::exec_signal.
* thread.c (rb_thread_check_trap_pending): check
rb_signal_buff_size() because rb_thread_t::exec_signal
is no longer available.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
no waiting thread. If there are 2 or more runnable threads,
the timer thread does polling. Avoid polling makes power save
for several computers (0.2W per a Ruby process, when I measured).
If outside-event such as signal or Thread#kill was occuerred
when the timer thread does not do polling, then wake-up
the timer thread using communication-pipe (the timer thread
waits this communication-pipe with select(2)).
The discussion about this modification can be found from the post
[ruby-core:33456] and other related posts.
Note that Eric Wong and KOSAKI Motohiro give us the huge
contributions for this modification. Thanks.
* thread_pthread.c (rb_thread_wakeup_timer_thread): add a function.
This function wakes up the timer thread using communication-pipe.
* thread.c (rb_thread_stop_timer_thread): add a parameter which
specify closing communication-pipe or not.
* thread.c (rb_thread_terminate_all): do not stop timer thread here
(ruby_cleanup() terminate timer thread).
* signal.c: wake up timer thread using
rb_thread_wakeup_timer_thread() from signal handler.
* eval.c (ruby_cleanup): use rb_thread_stop_timer_thread(1).
* process.c: use rb_thread_stop_timer_thread(0)
(reuse communication-pipe).
* thread_win32.c (rb_thread_wakeup_timer_thread): add a dummy
function.
* vm_core.h: add and fix decl. of functions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
ruby_vm_global_state_version and related macros
from vm_core.h to vm_insnhelper.h.
* vm.c (vm_clear_all_cache): added. This function is called
when ruby_vm_global_state_version overflows.
TODO: vm_clear_all_inline_method_cache() is only place holder.
We need to implement it ASAP.
* vm_method.c (vm_clear_global_method_cache): added.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32056 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
based on the patch by Eric Wong. [ruby-core:36156]
* vm_core.h (rb_thread_call_with_gvl): don't declare here.
* thread.c: include internal.h.
(rb_thread_execute_interrupts): new function.
* internal.h (rb_thread_execute_interrupts): declared.
(rb_thread_call_with_gvl): declared.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
blocking region with GIL released, for fd.
* thread.c (rb_thread_fd_close): implement. [ruby-core:35203]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30852 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
CoreDataFromValue() because we need type check. Otherwise,
type mismatch can cause segmentation fault crash.
[ruby-core:35086] [Ruby 1.9-Bug#4367]
* vm.c (thread_data_type): remove static.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
vm_insnhelper.c (caller_setup_args): reverted r30241 and r30243
except for the test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
hook a VM termination. Right now, because the VM we have is
process global, most extensions do not deallocate resources and
leave them to Operating System's reaping userland processes. But
in a future we plan to have multiple VMs to run simultaneously in
a single process (MVM project). At that stage we can no longer
rely on OSes and have to manage every resources to be reclaimed
properly. So it is. For a forward-compatibility reason this API
is introduced now, encouraging you to be as gentle as you can for
your resources; that is, tidy up your room.
* include/ruby/vm.h: ditto.
* vm_core.h (rb_vm_struct): new field.
* vm.c (vm_init2): initialize above new field.
* eval.c (ruby_cleanup): trigger those hooks.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
APIs to modularize GVL implementation.
* thread_pthread.c, thread_pthread.h: Two GVL implementations.
(1) Simple locking GVL which is same as existing GVL.
(2) Wake-up queued threads. The wake-up order is simple FIFO.
(We can make several queues to support exact priorities, however
this causes some issues such as priority inversion and so on.)
This impl. prevents spin-loop (*1) caused on SMP environemnts.
*1: Only one Ruby thread acqures GVL again and again.
Bug #2359 [ruby-core:26694]
* thread_win32.c, thread_win32.h: Using simple lock
not by CRITICAL_SECTION but by Mutex.
Bug #3890 [ruby-dev:42315]
* vm.c (ruby_vm_destruct): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
vm_throw): allow "return" and "yield" even in singleton class
definition. based on a patch from wanabe <s.wanabe AT gmail.com>
for "return". [ruby-core:21379] [ruby-dev:40975]
* insns.def (defineclass): ditto (straightforwardly push block ptr,
instead of dfp ptr with special flag).
* vm_core.h (RUBY_VM_CLASS_SPECIAL_P): ditto (no longer needed).
* proc.c (proc_new): ditto (remove handling for special flag).
* bootstraptest/test_jump.rb: add tests for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
added. Unlinked method entries are collected to
vm->unlinked_method_entry_list. On the GC timing, mark all method
entries which are on all living threads. Only non-marked method
entries are collected. This hack prevents releasing living method
entry.
[Performance Consideration] Since this Method Entry GC (MEGC)
doesn't occuer frequently, MEGC will not be a performance bottleneck.
However, to traverse living method entries, every control frame push
needs to clear cfp->me field. This will be a performance issue
(because pushing control frame is occurred frequently).
Bug #2777 [ruby-dev:40457]
* cont.c (fiber_init): init cfp->me.
* gc.c (garbage_collect): kick rb_sweep_method_entry().
* method.h (rb_method_entry_t): add a mark field.
* vm.c (invoke_block_from_c): set passed me.
* vm.c (rb_thread_mark): mark cfp->me.
* vm_core.h (rb_thread_t): add a field passed_me.
* vm_core.h (rb_vm_t): add a field unlinked_method_entry_list.
* vm_insnhelper.c (vm_push_frame): clear cfp->me at all times.
* vm_insnhelper.c (vm_call_bmethod): pass me.
* bootstraptest/test_method.rb: add a test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
path field into rb_iseq_t. The field contains a string representing
a path to corresponding source file. or nil when the iseq is created
from -e, stdin, eval, etc. This field is used for require_relative.
[ruby-dev:40004]
* load.c (rb_f_require_relative): add C implementation of
require_relative.
* prelude.rb (require_relative): get rid of Ruby implementation of
require_relative.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
it seems not to make sense. [ruby-dev:40121]
* vm_core.h, eval.c (rb_protect): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e