summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-30 11:04:17 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-30 11:04:17 +0000
commit858a5ba2ef16dde41085ab3e622f155fcf9b5be8 (patch)
treec63ccd2337cad1ceed312913b8b72b213b733b8a
parent2e574a5315e611ae2f5375bffb3827c64e1a0f17 (diff)
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
-rw-r--r--ChangeLog6
-rw-r--r--gc.c5
-rw-r--r--ruby_atomic.h7
-rw-r--r--test/ruby/test_gc.rb14
-rw-r--r--version.h2
5 files changed, 30 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 2a03620e4d..960823b737 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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):
diff --git a/gc.c b/gc.c
index c32a189dcc..6eaf4ae491 100644
--- a/gc.c
+++ b/gc.c
@@ -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);
}
}
diff --git a/ruby_atomic.h b/ruby_atomic.h
index 920c304116..81990620ef 100644
--- a/ruby_atomic.h
+++ b/ruby_atomic.h
@@ -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 */
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index f04e7e0255..381fcd4d18 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -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
diff --git a/version.h b/version.h
index c069e2c1e0..e4f3b26568 100644
--- a/version.h
+++ b/version.h
@@ -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