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
* thread.c (rb_thread_setname): name must be ascii-compatible, as
pthread APIs do not accept legacy wide char strings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* configure.in: separate SET_CURRENT_THREAD_NAME, which can set
the name of current thread only, and SET_ANOTHER_THREAD_NAME,
which can set the name of other threads.
* thread.c (rb_thread_setname): use SET_ANOTHER_THREAD_NAME. OS X
is not possible to set another thread name.
* thread_pthread.c (native_set_thread_name, thread_timer): use
SET_CURRENT_THREAD_NAME.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (rb_thread_setname): pthread_setname_np() on OS X takes
the name only and sets the current thread.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* compile.c: use them.
* iseq.c: ditto.
* iseq.c (rb_iseq_coverage): added.
* thread.c (update_coverage): use rb_iseq_coverage().
* vm_core.h: rename coverage field name to support this fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Nothing outside of thread.c accesses this variable, so avoid
cluttering up the global namespace with it.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (rb_fd_no_init): suppress warnings by applying ASSUME
only if GCC 6 or lator, to get rid of freeze with GCC 4.7.2-5.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (rb_io_s_popen): do not wait the child process during being
killed. [ruby-core:70671] [Bug #11510]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
and ConditionalVariables to thread_tools.c. In other wowrds,
such classes are built-in.
[Feature #8919]
At first, I planned to embed only a Queue class.
However, rubygems requires 'thread.rb' (rubygems are
required at first, when launch MRI without --disable-gems).
So most of people require 'thread.rb' as an embedded library.
Now, ext/thread/thread.c is empty, only for a dummy for
compatibility.
* thread.c: move a definition of Mutex class to thread_tools.c.
And define Mutex class under Thread (so now Mutex is Thread::Mutex).
Because other thread related classes are also defined under Thread.
We remain ::Mutex as Thread::Mutex. Only an inspect result is changed.
* common.mk: add dependency from thread.o to thraed_tools.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Shutting down the timer thread now always closes pipes to free FDs.
In fact, we close the write ends of the pipes is done in the main
RubyVM to signal the timer thread shutdown.
To effectively close pipes, we implement userspace locks via
atomics to force the pipe closing thread to wait on any signal
handlers which may be waking up.
While we're at it, improve robustness during resource exhaustion and
allow it to limp along non-fatally if restarting a timer thread
fails.
This reverts r51268
Note: this change is tested with VM_CHECK_MODE 1 in vm_core.h
* process.c (close_unless_reserved): add extra check
(dup2_with_divert): remove
(redirect_dup2): use dup2 without divert
(before_exec_non_async_signal_safe): adjust call + comment
(rb_f_exec): stop timer thread for all OSes
(rb_exec_without_timer_thread): remove
* eval.c (ruby_cleanup): adjust call
* thread.c (rb_thread_stop_timer_thread): always close pipes
* thread_pthread.c (struct timer_thread_pipe): add writing field,
mark owner_process volatile for signal handlers
(rb_thread_wakeup_timer_thread_fd): check valid FD
(rb_thread_wakeup_timer_thread): set writing flag to prevent close
(rb_thread_wakeup_timer_thread_low): ditto
(CLOSE_INVALIDATE): new macro
(close_invalidate): new function
(close_communication_pipe): removed
(setup_communication_pipe_internal): make errors non-fatal
(setup_communication_pipe): ditto
(thread_timer): close reading ends inside timer thread
(rb_thread_create_timer_thread): make errors non-fatal
(native_stop_timer_thread): close write ends only, always,
wait for signal handlers to finish
(rb_divert_reserved_fd): remove
* thread_win32.c (native_stop_timer_thread): adjust (untested)
(rb_divert_reserved_fd): remove
* vm_core.h: adjust prototype
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (thread_shield_get_mutex): fix object to be shown in
the message, NULL pointer is useless.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (rb_thread_s_handle_interrupt): make identical hash,
to compare masking classes just by their IDs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
All contents of previous rb_iseq_t is in rb_iseq_t::body.
Remove rb_iseq_t::self because rb_iseq_t is an object.
RubyVM::InstructionSequence is wrapper object points T_IMEMO/iseq.
So RubyVM::ISeq.of(something) method returns different wrapper
objects but they point the same T_IMEMO/iseq object.
This patch is big, but most of difference is replacement of
iseq->xxx to iseq->body->xxx.
(previous) rb_iseq_t::compile_data is also located to
rb_iseq_t::compile_data.
It was moved from rb_iseq_body::compile_data.
Now rb_iseq_t has empty two pointers.
I will split rb_iseq_body data into static data and dynamic data.
* compile.c: rename some functions/macros.
Now, we don't need to separate iseq and iseqval (only VALUE).
* eval.c (ruby_exec_internal): `n' is rb_iseq_t (T_IMEMO/iseq).
* ext/objspace/objspace.c (count_imemo_objects): count T_IMEMO/iseq.
* gc.c: check T_IMEMO/iseq.
* internal.h: add imemo_type::imemo_iseq.
* iseq.c: define RubyVM::InstructionSequnce as T_OBJECT.
Methods are implemented by functions named iseqw_....
* load.c (rb_load_internal0): rb_iseq_new_top() returns
rb_iseq_t (T_IMEMO/iesq).
* method.h (rb_add_method_iseq): accept rb_iseq_t (T_IMEMO/iseq).
* vm_core.h (GetISeqPtr): removed because it is not T_DATA now.
* vm_core.h (struct rb_iseq_body): remove padding for
[Bug #10037][ruby-core:63721].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (do_select): replace switch and goto with a loop to
suppress maybe-uninitialized warnings by gcc6.
* thread.c (set_unblock_function, rb_wait_for_single_fd): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (rb_thread_terminate_all): reuse the tag pushed before
a loop, instead of pushing/popping same tag repeatedly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (ppoll): fix the limit, timeout argument of poll(2) is
an int but not a time_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (vm_check_ints_blocking): gather common statements at
the end, and prefer LIKELY for Visual C optimization.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (RUBY_VM_CHECK_INTS_BLOCKING): move from vm_core.h for
the static function rb_threadptr_pending_interrupt_empty_p.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This function now also works in more places if ruby_current_thread
is unset.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Allocation functions do not do anything non-obvious to the
compiler, so there's no reason for volatile here.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51271 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Favor passing VALUE args as-is and using PRisVALUE in format strings
to prevent premature GC. In this case, we are not fixing any real
bug because location path has other references, but this makes code
easier-to-review.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
unless main thread is already exited. Otherwise main thread could be
wrongly interrupted when it uses rb_thread_call_without_gvl(). Patch
by Takehiro Kubo. [Bug #11237][ruby-dev:49044][GH-898]
* test/-ext-/gvl/test_last_thread.rb: new test for the above fix.
* ext/-test-/gvl/call_without_gvl/call_without_gvl.c: new ext for the
above test.
* ext/-test-/gvl/call_without_gvl/extconf.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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
* thread.c (thread_s_new): preserve the encoding of the class name
in an error message.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (struct join_arg): restructure and make smaller
(thread_join_sleep): avoid timeofday() call if forever
(thread_join): pass join_arg.delay directly
(rb_thread_inspect_msg): remove, inline into rb_thread_inspect
(rb_thread_inspect): reduce branching and string creation
* thread_pthread.c (native_set_thread_name): create string directly
to avoid reparsing. [Misc #10723]
This reduces time in benchmark/bm_vm_thread_create_join.rb by
a few percent.
Minor improvements only:
target 0: 2.1.5 (ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux])
target 1: trunk (ruby 2.3.0dev (2015-01-16 trunk 49282) [x86_64-linux])
target 2: built (ruby 2.3.0dev (2015-01-16 trunk 49282) [x86_64-linux])
benchmark results:
minimum results in each 3 measurements.
Execution time (sec)
name 2.1.5 trunk built
vm_thread_create_join 1.049 1.242 1.138
Speedup ratio: compare with the result of `2.1.5' (greater is better)
name trunk built
vm_thread_create_join 0.845 0.923
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (rb_thread_variable_get): fix dynamic symbol keys.
rb_check_id() returns non-zero only for static symbols, whereas
thread local variable keys can be dynamic symbols.
[ruby-core:67185] [Bug #10667]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
entry. [Bug #10623]
* hash.c (rb_hash_delete_entry): try delete and return Qundef if there
are no corresponding entry.
* internal.h: add rb_hash_delete_entry()'s declaration.
* symbol.c: use rb_hash_delete_entry().
* thread.c: use rb_hash_delete_entry().
* ext/-test-/hash/delete.c: use rb_hash_delete_entry().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e