Project

General

Profile

Bug #5439

Bug #5350: WeakRef で謎の NoMethodError

r33361以降sample/test.rb:systemがFになる

Added by ngoto (Naohisa Goto) over 6 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-dev:44596]

Description

r33361の変更により、ccでコンパイルすると、プログラム終了時にfinalizerが呼ばれなくなり、sample/test.rb:system にFが出ます。
(Solaris 10, sparc, Sun Studio 11 にて確認)

% make test
(中略)
sample/test.rb:eval .............................
sample/test.rb:system .FFFF.F.
sample/test.rb:const .....
(中略)
sample/test.rb:path .......................
sample/test.rb:gc ....make: *** [yes-test-sample] Error 1

Fが出ているテストの1つは以下です。
test_ok(./miniruby -e 'print "foobar"' == 'foobar')

r33361の変更で、以下の文が2か所に追加されています。
if (ATOMIC_SET(finalizing, 1)) return;
マクロ ATOMIC_SET() は、gccの場合(ただしWindows以外)、
# define ATOMIC_SET(var, val) __sync_lock_test_and_set(&(var), (val))
に展開され、http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html によるとこの関数は

returns the previous contents of *ptr.
つまり、その変数に以前セットされていた値を返しますが、
gccおよびWIN32以外(Solarisのccなど)では、
# define ATOMIC_SET(var, val) ((var) = (val))
に展開される、つまり、新しく代入した値を返すため、
if (ATOMIC_SET(finalizing, 1)) return;
は、ATOMIC_SET(finalizing, 1)が必ず1を返すため、常にreturnしてしまいます。
このため、多くのfinalizerが呼ばれないままプログラムが終了し、rb_io_fptr_finalizeなどで行われているバッファのフラッシュも行われないためFになったと推測します。

Associated revisions

Revision c180eabf
Added by nobu (Nobuyoshi Nakada) over 6 years ago

  • gc.c (rb_gc_finalize_deferred, rb_objspace_call_finalizer): should use ATOMIC_EXCHANGE() to check the previous value. [Bug #5439]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 33460
Added by nobu (Nobuyoshi Nakada) over 6 years ago

  • gc.c (rb_gc_finalize_deferred, rb_objspace_call_finalizer): should use ATOMIC_EXCHANGE() to check the previous value. [Bug #5439]

Revision 33460
Added by nobu (Nobuyoshi Nakada) over 6 years ago

  • gc.c (rb_gc_finalize_deferred, rb_objspace_call_finalizer): should use ATOMIC_EXCHANGE() to check the previous value. [Bug #5439]

Revision 33460
Added by nobu (Nobuyoshi Nakada) over 6 years ago

  • gc.c (rb_gc_finalize_deferred, rb_objspace_call_finalizer): should use ATOMIC_EXCHANGE() to check the previous value. [Bug #5439]

Revision 33460
Added by nobu (Nobuyoshi Nakada) over 6 years ago

  • gc.c (rb_gc_finalize_deferred, rb_objspace_call_finalizer): should use ATOMIC_EXCHANGE() to check the previous value. [Bug #5439]

Revision 33460
Added by nobu (Nobuyoshi Nakada) over 6 years ago

  • gc.c (rb_gc_finalize_deferred, rb_objspace_call_finalizer): should use ATOMIC_EXCHANGE() to check the previous value. [Bug #5439]

Revision 123645aa
Added by kosaki (Motohiro KOSAKI) over 6 years ago

  • atomic.h(ATOMIC_SET): add cast to void to prevent misuse. [Bug #5439]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 33462
Added by kosaki (Motohiro KOSAKI) over 6 years ago

  • atomic.h(ATOMIC_SET): add cast to void to prevent misuse. [Bug #5439]

Revision 33462
Added by kosaki (Motohiro KOSAKI) over 6 years ago

  • atomic.h(ATOMIC_SET): add cast to void to prevent misuse. [Bug #5439]

Revision 33462
Added by kosaki (Motohiro KOSAKI) over 6 years ago

  • atomic.h(ATOMIC_SET): add cast to void to prevent misuse. [Bug #5439]

Revision 33462
Added by kosaki (Motohiro KOSAKI) over 6 years ago

  • atomic.h(ATOMIC_SET): add cast to void to prevent misuse. [Bug #5439]

Revision 33462
Added by kosaki (Motohiro KOSAKI) over 6 years ago

  • atomic.h(ATOMIC_SET): add cast to void to prevent misuse. [Bug #5439]

Revision 5558de40
Added by ngoto (Naohisa Goto) over 6 years ago

  • atomic.h (ATOMIC_*): use atomic_ops(3C) when SunStudio on Solaris. [Bug #5439]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 33463
Added by ngoto (Naohisa Goto) over 6 years ago

  • atomic.h (ATOMIC_*): use atomic_ops(3C) when SunStudio on Solaris. [Bug #5439]

Revision 33463
Added by ngoto (Naohisa Goto) over 6 years ago

  • atomic.h (ATOMIC_*): use atomic_ops(3C) when SunStudio on Solaris. [Bug #5439]

Revision 33463
Added by ngoto (Naohisa Goto) over 6 years ago

  • atomic.h (ATOMIC_*): use atomic_ops(3C) when SunStudio on Solaris. [Bug #5439]

Revision 33463
Added by ngoto (Naohisa Goto) over 6 years ago

  • atomic.h (ATOMIC_*): use atomic_ops(3C) when SunStudio on Solaris. [Bug #5439]

Revision 33463
Added by ngoto (Naohisa Goto) over 6 years ago

  • atomic.h (ATOMIC_*): use atomic_ops(3C) when SunStudio on Solaris. [Bug #5439]

Revision c96c193e
Added by nobu (Nobuyoshi Nakada) over 6 years ago

  • atomic.h (ATOMIC_INC, ATOMIC_DEC): return old values. [Bug #5439]
  • signal.c (ruby_atomic_exchange): no needs to define on the platforms where atomic.h is available.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33464 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 33464
Added by nobu (Nobuyoshi Nakada) over 6 years ago

  • atomic.h (ATOMIC_INC, ATOMIC_DEC): return old values. [Bug #5439]
  • signal.c (ruby_atomic_exchange): no needs to define on the platforms where atomic.h is available.

Revision 33464
Added by nobu (Nobuyoshi Nakada) over 6 years ago

  • atomic.h (ATOMIC_INC, ATOMIC_DEC): return old values. [Bug #5439]
  • signal.c (ruby_atomic_exchange): no needs to define on the platforms where atomic.h is available.

Revision 33464
Added by nobu (Nobuyoshi Nakada) over 6 years ago

  • atomic.h (ATOMIC_INC, ATOMIC_DEC): return old values. [Bug #5439]
  • signal.c (ruby_atomic_exchange): no needs to define on the platforms where atomic.h is available.

Revision 33464
Added by nobu (Nobuyoshi Nakada) over 6 years ago

  • atomic.h (ATOMIC_INC, ATOMIC_DEC): return old values. [Bug #5439]
  • signal.c (ruby_atomic_exchange): no needs to define on the platforms where atomic.h is available.

Revision 33464
Added by nobu (Nobuyoshi Nakada) over 6 years ago

  • atomic.h (ATOMIC_INC, ATOMIC_DEC): return old values. [Bug #5439]
  • signal.c (ruby_atomic_exchange): no needs to define on the platforms where atomic.h is available.

Revision 2e574a53
Added by usa (Usaku NAKAMURA) over 4 years ago

merge revision(s) 33361,33460: [Backport #9463]

* gc.c (slot_sweep, rb_gc_finalize_deferred)
  (rb_objspace_call_finalizer, rb_gc): run finalizers
  sequencially.  

* gc.c (rb_gc_finalize_deferred, rb_objspace_call_finalizer):
  should use ATOMIC_EXCHANGE() to check the previous value.
   [Bug #5439]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@44762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

History

#1 [ruby-dev:44597] Updated by shyouhei (Shyouhei Urabe) over 6 years ago

その他のコンパイラの場合はそれはそれで修正すべきと思いますが、sparc上のccにはatomic test and setみたいなインストラクション(があるのか存じ上げませんが)を生成する方法はないのでしょうか? あるのならそちらを使うようにするのが筋という気がします。

#2 [ruby-dev:44598] Updated by kosaki (Motohiro KOSAKI) over 6 years ago

代入前の値を知りたいときは ATOMIC_EXCHANGE 使わないとダメ。

やらないといけないことが3つあって
1.ATOMIC_SETに void キャストいれて、戻り値使おうとしたらコンパイルエラーになるようにする
2.指摘されてる間違った ATOMIC_SEC を ATOMIC_EXCHANGEに変換
3.いまatomicに対応してるのはgccとVCだけなので、#if defined(__SUNPRO_CC) だったら
http://www.unix.com/man-page/OpenSolaris/9f/atomic_ops/
の命令つかって、atomicに動くように実装する

1と2はこちらでさっくり出来そうですが、3はこちらではコンパイルテストすら出来ないので
協力していただけると助かります

#3 [ruby-dev:44599] Updated by ngoto (Naohisa Goto) over 6 years ago

3.いまatomicに対応してるのはgccとVCだけなので、#if defined(__SUNPRO_CC) だったら http://www.unix.com/man-page/OpenSolaris/9f/atomic_ops/ の命令つかって、atomicに動くように実装する

Solaris10ではヘッダの場所が #include となっているのがOpenSolarisと違いますが、関数の仕様は同じのようです。(もっとも、Solaris10 の atomic.h を覗いたら、単に #include しているだけでしたが)

https://sites.google.com/a/diviware.com/unix/unix-page/solaris-page/solaris-man-pages/3c/atomic_ops

NetBSDなど他のOSにも同等/類似の関数があるようですので、configureで判別するほうが幸せかもしれません。
http://www.daemon-systems.org/man/atomic_ops.3.html

#4 Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r33460.
Naohisa, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • gc.c (rb_gc_finalize_deferred, rb_objspace_call_finalizer): should use ATOMIC_EXCHANGE() to check the previous value. [Bug #5439]

Also available in: Atom PDF