[#48591] StringValuePtrでnull終止されてない文字列の作り方 — madoka yamamoto <yamamotomadoka@...>
山本ともうします。
5 messages
2014/10/05
[#48598] Re: StringValuePtrでnull終止されてない文字列の作り方
— "NARUSE, Yui" <naruse@...>
2014/10/06
まず、CRubyとしてはStringValuePtrがNUL終端する保証はしていませんから、仮にnull-terminateしてないことにより問題が起きるならば、
[#48666] Re: [ruby-cvs:55171] duerst:r48021 (trunk): common.mk: Added a rule to generate lib/unicode_normalize/tables.rb. — "Martin J. Dürst" <duerst@...>
中田さん、こんにちは。
3 messages
2014/10/19
[ruby-dev:48710] [ruby-trunk - Bug #10431] [Closed] Can't sweep garbage object immediatly when GC_ENABLE_LAZY_SWEEP=0
From:
nobu@...
Date:
2014-10-27 04:40:26 UTC
List:
ruby-dev #48710
Issue #10431 has been updated by Nobuyoshi Nakada.
Status changed from Open to Closed
% Done changed from 0 to 100
Applied in changeset r48150.
----------
gc.c: fix no lazy sweep mode
* gc.c (gc_sweep_rest): sweep rest pages regardless of whether
lazy sweep is enabled or not. based on the patch by Masahiro
Ide at [ruby-dev:48706]. [Bug #10431]
----------------------------------------
Bug #10431: Can't sweep garbage object immediatly when GC_ENABLE_LAZY_SWEEP=0
https://bugs.ruby-lang.org/issues/10431#change-49656
* Author: Masahiro Ide
* Status: Closed
* Priority: Normal
* Assignee:
* Category: core
* Target version: current: 2.2.0
* ruby -v: ruby 2.2.0dev (2014-10-26 trunk 48073) [x86_64-darwin14]
* Backport: 2.0.0: DONTNEED, 2.1: DONTNEED
----------------------------------------
GC_ENABLE_LAZY_SWEEP=0と設定してrubyをビルドし,以下のコードを
実行した場合,GC時にオブジェクトが解放されていないように見えます.
~~~
$ ../configure CFLAGS="-DGC_ENABLE_LAZY_SWEEP=0" && make miniruby
$ cat bug2.rb
GC.disable
10000.times { Object.new }
total_freed_objects1 = GC.stat[:total_freed_objects]
GC.enable
GC.start(full_mark: true, immediate_sweep: true)
total_freed_objects2 = GC.stat[:total_freed_objects]
puts "freed object : #{total_freed_objects2 - total_freed_objects1}"
$ ./miniruby -v
ruby 2.2.0dev (2014-10-26 trunk 48073) [x86_64-darwin14]
$ ./miniruby bug2.rb
freed object : 0
~~~
また,rubyのコンパイルフラグをGC_ENABLE_LAZY_SWEEP=0,
RGENGC_CHECK_MODE=1と設定した上でビルドし,以下のコードを実行すると
assertで落ちます.
~~~
$ ./miniruby -e '10000.times { Object.new }'
Assertion failed: (objspace->flags.stat == gc_stat_none), function gc_start, file ../gc.c, line 5802.
[1] 91336 abort ./miniruby -e '10000.times { Object.new }'
~~~
sweepフェーズにてGC_ENABLE_LAZY_SWEEP!=1の時のみsweepが実行されるのが
原因のようですので,これを修正するパッチを作りました.
~~~diff
diff --git a/gc.c b/gc.c
index a27cc01..979e2e0 100644
--- a/gc.c
+++ b/gc.c
@@ -3314,9 +3314,8 @@ static void
gc_sweep_rest(rb_objspace_t *objspace)
{
rb_heap_t *heap = heap_eden; /* lazy sweep only for eden */
-
- if (is_lazy_sweeping(heap)) {
- while (is_lazy_sweeping(heap)) {
+ if ((heap)->sweep_pages != NULL) {
+ while ((heap)->sweep_pages != NULL) {
gc_sweep_step(objspace, heap);
}
}
~~~
English:
When I tried to compile ruby with GC_ENABLE_LAZY_SWEEP=0,
Ruby does not sweep objects immediatly.
~~~
$ ../configure CFLAGS="-DGC_ENABLE_LAZY_SWEEP=0" && make miniruby
$ cat bug2.rb
GC.disable
10000.times { Object.new }
total_freed_objects1 = GC.stat[:total_freed_objects]
GC.enable
GC.start(full_mark: true, immediate_sweep: true)
total_freed_objects2 = GC.stat[:total_freed_objects]
puts "freed object : #{total_freed_objects2 - total_freed_objects1}"
$ ./miniruby -v
ruby 2.2.0dev (2014-10-26 trunk 48073) [x86_64-darwin14]
$ ./miniruby bug2.rb
freed object : 0
~~~
In addition, when I set GC_ENABLE_LAZY_SWEEP=0 and RGENGC_CHECK_MODE=1
ruby gives me assertion error like this:
~~~
$ ./miniruby -e '10000.times { Object.new }'
Assertion failed: (objspace->flags.stat == gc_stat_none), function gc_start, file ../gc.c, line 5802.
[1] 91336 abort ./miniruby -e '10000.times { Object.new }'
~~~
The following patch fix this problem.
~~~diff
diff --git a/gc.c b/gc.c
index a27cc01..979e2e0 100644
--- a/gc.c
+++ b/gc.c
@@ -3314,9 +3314,8 @@ static void
gc_sweep_rest(rb_objspace_t *objspace)
{
rb_heap_t *heap = heap_eden; /* lazy sweep only for eden */
-
- if (is_lazy_sweeping(heap)) {
- while (is_lazy_sweeping(heap)) {
+ if ((heap)->sweep_pages != NULL) {
+ while ((heap)->sweep_pages != NULL) {
gc_sweep_step(objspace, heap);
}
}
~~~
--
https://bugs.ruby-lang.org/