What's the problem?
autoload is thread unsafe. When we define a constant to be
autoloaded, we expect the constant construction is invariant. But
current autoload implementation allows other threads to access the
constant while the first thread is loading a file.
What's happening inside?
The current implementation uses Qundef as a marker of autoload in
Constant table. Once the first thread find Qundef as a value at
constant lookup, it starts loading a defined feature. Generally a
loaded file overrides the Qundef in Constant table by module/class
declaration at very beginning lines of the file, so other threads
can see the new Module/Class object before feature loading is
finished. It breaks invariant construction.
How to solve?
To ensure invariant constant construction, we need to override
Qundef with defined Object after the feature loading. For keeping
Qundef in Constant table, I expanded autoload_data struct in
Module to have a slot for keeping the defined object while feature
loading. And changed Module's constant lookup/update logic a
little so that the slot is only visible from the thread which
invokes feature loading. (== the first thread which accessed the
autoload constant)
Evaluation?
All test passes (bootstrap test, test-all and RubySpec) and added
8 tests for threading behavior. Extra logics are executed only
when Qundef is found, so no perf drop should happen except
autoloading.
* variable.c (rb_autoload): Prepare new autoload_data struct.
* variable.c (rb_autoload_load): Load feature and update Constant
table after feature loading is finished.
* variable.c (rb_const_get_0): When the fetched constant is under
autoloading, it returns the object only for the thread which starts
autoloading.
* variable.c (rb_const_defined_0): Ditto.
* variable.c (rb_const_set): When the specified constant is under
autoloading, it sets the object only for the thread which starts
autoloading. Otherwise, simply overrides Qundef with constant
override warning.
* vm_insnhelper.c (vm_get_ev_const): Apply same change as
rb_const_get_0 in variable.c.
* test/ruby/test_autoload.rb: Added tests for threading behavior.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
RCLASS_IV_TBL, not in a RCLASS_CONST_TBL, so take back the table
changed in r29600. And an autoload entry keeps not a
rb_const_entry_t but a NODE so remove rb_const_entry_t thing added
in r29602.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
NameError for undefined method.
* load.c (rb_mod_autoload_p), object.c (rb_mod_const_get),
variable.c (rb_f_untrace_var, set_const_visibility), vm_method.c
(rb_mod_{remove,undef,alias}_method, set_method_visibility):
remove inadvertent symbol creation. based on the first patch by
Jeremy Evans at [ruby-core:38447]. [Feature #5089]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
based on the second patch by Jeremy Evans at [ruby-core:38447]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32684 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
with the name string but not ID.
* object.c, proc.c, variable.c: more removal of inadvertent symbol
creation. [Feature #5079]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
explicitly.
* variable.c (rb_const_defined_0): should not check for
superclasses as const_get.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
the second optional argument is given for #const_get().
fix [Bug #3422] [Bug #3423]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
RSTRING_PTR() for function calls since it evaluates the argument
a couple of times.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
private constants. see [ruby-core:32912].
* test/ruby/test_module.rb (test_constants_with_private_constant): add
a test for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
visibility. see [ruby-core:32912].
* test/ruby/test_module.rb: add a test for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
not raise an exception even when the constant is private. Instead,
rb_public_const_get_* and rb_public_const_defined_* are introduced,
which raise an exception when the referring constant is private.
see [ruby-core:32912].
* vm_insnhelper.c (vm_get_ev_const): use rb_public_const_get_* instead
of rb_const_get_* to follow the constant visibility when user code
refers a constant.
* test/ruby/test_marshal.rb (test_marshal_private_class): add a test.
This test had failed because of incompatibility of rb_const_get.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
vm_insnhelper.c: use struct rb_constant_entry_t as entry of
RCLASS_CONST_TBL. RCLASS_CONST_TBL has contained VALUE of constant
directly. Now instead rb_const_entry_t is contained in
RCLASS_CONST_TBL, rb_const_entry_t is managed by malloc, and
have not only the value itself but also visibility flag.
This is another preparation for private constant (see
[ruby-dev:39685][ruby-core:32698]).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
include/ruby/ruby.h: separate RCLASS_CONST_TBL from RCLASS_IV_TBL.
RCLASS_IV_TBL has contained not only instance variable table but
also constant table. Now the two table are separated to
RCLASS_CONST_TBL and RCLASS_IV_TBL. This is a preparation for
private constant (see [ruby-dev:39685][ruby-core:32698]).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29600 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
transcode.c, variable.c, vm.c, vm_insnhelper.c, vm_method.c:
replace calls to rb_error_frozen() with rb_check_frozen(). a
patch from Run Paint Run Run at [ruby-core:32014]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* defs/dtrace.d: new file. defined a dtrace provider "ruby".
* include/ruby/ruby.h (LIKELY): moved from vm.c.
(UNLIKELY): ditto.
(OBJSETUP): probe "object-create".
(RUBY_EVENT_RESCUE): new event.
* vm_exec.c (DEBUG_ENTER_INSN): embeded a probe insn-entry into it.
(DEBUG_END_INSN): insn-return.
* vm.c (LIKELY): moved into ruby.h.
(UNLIKELY): ditto.
(Init_BareVM): embeded a probe "raise" into it.
* variable.c (rb_class2name_without_alloc): new utility function.
* tool/rbinstall.rb (install?(:ext, :arch, :'ext-arch')): installs
dtrace.d if necessary.
* thread_pthread.c (add_signal_thread_list): probe "raise".
(rb_thread_create_timer_thread): ditto.
* thread.c (rb_thread_schedule_rec): probes "thread-enter" and
"thread-leave",
(thread_start_func_2): ditto.
(thread_cleanup_func): probe "thread-term"
* lib/mkmf.rb: supports dtrace postprocessor on making an extension.
* iseq.c (rb_vm_insn_name): new utility function.
(rb_vm_insn_len): ditto.
* insns.def (hook): probes "method-etnry", "method-return", "line",
and "rescue".
* compile.c (iseq_compile_each): adds a trace op for "rescue" probe.
* gc.c (garbage_collect): probes "gc-begin" and "gc-end".
(obj_free): probe "object-free"
(garbage_collect_with_gvl): probe "raise"
(negative_size_allocation_error): ditto.
(rb_memerror): ditto.
* eval.c (rb_rescue2): probe "rescue"
(rb_longjmp): probe "raise"
* ext/probe/probe.c: new extension for application defined probes.
* ext/probe/extconf.rb: ditto.
* configure.in (--with-tracing-model): new option to choose a tracing
mechanism.
(DTRACE): new substitution. name of dtrace(1).
(RUBY_TRACING_MODEL): new substitution.
(DTRACE_OBJ): ditto.
(MINIDTRACE_OBJ): ditto.
(GOLFDTRACE_OBJ): ditto.
(LIBRUBY_DTRACE_OBJ): ditto.
(RUBY_DTRACE_POSTPROCESS): new macro. checks whether the dtrace on
the system needs postprocessing.
(RUBY_DTRACE_BSD_BROKEN): new macro. checks whether the dtrace
supports USDT.
* Makefile.in:
(DTRACE): new variable. name of dtrace(1).
(TRACING_MODEL): new variable. name of the chosen tracing mechanism.
(DTRACE_OBJ): same as the one in configure.in.
(MINIDTRACE_OBJ): ditto.
(GOLFDTRACE_OBJ): ditto.
(LIBRUBY_DTRACE_OBJ): ditto.
(CPPOUTFILE): new substitution. necessary for generating dtrace.d
(trace_none.h): new target for TRACING_MODEL=none
(RUBY_H_INCLUDES): appended a header for tracing.
(distclean-local): also removes preprocessed version of dtrace.d
($(LIBRUBY_A)): needs $(LIBRUBY_DTRACE_OBJ) if dtrace needs
postprocessing.
($(PROGRAM)): ditto.
(golf): ditto.
(miniruby): ditto.
($(arch_hdrdir)/ruby/dtrace.d): new target. preprocessed verson
of defs/dtrace.d. generated if necessary.
($(arch_hdrdir)/ruby/trace_dtrace.h): new target.
definition of probes.
($(LIBRUBY_DTRACE_OBJ)): new target. generated if dtrace needs
postprocessing.
($(DTRACE_OBJ)): ditto.
($(MINIDTRACE_OBJ)): ditto.
($(GOLFDTRACE_OBJ)): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
deal with non-ascii class path. [ruby-core:24790]
* marshal.c (r_unique, path2class, path2module, obj_alloc_by_path),
(r_object0): ditto.
* variable.c (rb_path_to_class): new encoding-aware function to
get a class from its name.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
names. [ruby-core:24600]
* variable.c (rb_set_class_path_string): set class path with a
string value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e