merge revision(s) 43994,44000: [Backport #9205]

* gc.c (finalize_deferred): flush all deferred finalizers while other
	  finalizers can get ready to run newly by lazy sweep.
	  [ruby-core:58833] [Bug #9205]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@44764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2014-01-30 11:04:17 +00:00
parent 2e574a5315
commit 858a5ba2ef
5 changed files with 30 additions and 4 deletions

View file

@ -1,3 +1,9 @@
Thu Jan 30 19:54:16 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* gc.c (finalize_deferred): flush all deferred finalizers while other
finalizers can get ready to run newly by lazy sweep.
[ruby-core:58833] [Bug #9205]
Thu Jan 30 19:08:00 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* gc.c (rb_gc_finalize_deferred, rb_objspace_call_finalizer):

5
gc.c
View file

@ -3044,10 +3044,9 @@ run_final(rb_objspace_t *objspace, VALUE obj)
static void
finalize_deferred(rb_objspace_t *objspace)
{
RVALUE *p = deferred_final_list;
deferred_final_list = 0;
RVALUE *p;
if (p) {
while ((p = ATOMIC_PTR_EXCHANGE(deferred_final_list, 0)) != 0) {
finalize_list(objspace, p);
}
}

View file

@ -19,6 +19,7 @@ typedef unsigned int rb_atomic_t; /* Anything OK */
# define ATOMIC_SIZE_INC(var) __sync_fetch_and_add(&(var), 1)
# define ATOMIC_SIZE_DEC(var) __sync_fetch_and_sub(&(var), 1)
# define ATOMIC_SIZE_EXCHANGE(var, val) __sync_lock_test_and_set(&(var), (val))
# define ATOMIC_PTR_EXCHANGE(var, val) __atomic_exchange_n(&(var), (val), __ATOMIC_SEQ_CST)
#elif defined _WIN32
#if defined _MSC_VER && _MSC_VER > 1200
@ -112,4 +113,10 @@ atomic_size_exchange(size_t *ptr, size_t val)
}
#endif
#ifndef ATOMIC_PTR_EXCHANGE
# if SIZEOF_VOIDP == SIZEOF_SIZE_T
# define ATOMIC_PTR_EXCHANGE(var, val) (void *)ATOMIC_SIZE_EXCHANGE(*(size_t *)&(var), (size_t)(val))
# endif
#endif
#endif /* RUBY_ATOMIC_H */

View file

@ -112,4 +112,18 @@ class TestGc < Test::Unit::TestCase
ObjectSpace.define_finalizer(Thread.main) { p 'finalize' }
EOS
end
def test_sweep_in_finalizer
bug9205 = '[ruby-core:58833] [Bug #9205]'
2.times do
assert_ruby_status([], <<-'end;', bug9205)
raise_proc = proc do |id|
GC.start
end
1000.times do
ObjectSpace.define_finalizer(Object.new, raise_proc)
end
end;
end
end
end

View file

@ -1,5 +1,5 @@
#define RUBY_VERSION "1.9.3"
#define RUBY_PATCHLEVEL 506
#define RUBY_PATCHLEVEL 507
#define RUBY_RELEASE_DATE "2014-01-30"
#define RUBY_RELEASE_YEAR 2014