ruby-changes:4537
From: ko1@a...
Date: Tue, 15 Apr 2008 16:54:31 +0900 (JST)
Subject: [ruby-changes:4537] kazu - Ruby:r16030 (ruby_1_8): * signal.c, gc.c: New methods: GC.stress, GC.stress=;
kazu 2008-04-15 16:54:11 +0900 (Tue, 15 Apr 2008)
New Revision: 16030
Modified files:
branches/ruby_1_8/ChangeLog
branches/ruby_1_8/NEWS
branches/ruby_1_8/gc.c
branches/ruby_1_8/signal.c
Log:
* signal.c, gc.c: New methods: GC.stress, GC.stress=;
backported from 1.9. a patch from Tadashi Saito
in [ruby-dev:34394] and bug#19000
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16030&r2=16029&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/signal.c?r1=16030&r2=16029&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/NEWS?r1=16030&r2=16029&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/gc.c?r1=16030&r2=16029&diff_format=u
Index: ruby_1_8/NEWS
===================================================================
--- ruby_1_8/NEWS (revision 16029)
+++ ruby_1_8/NEWS (revision 16030)
@@ -139,6 +139,11 @@
Return an enumerator if no block is given.
+ * GC.stress
+ * GC.stress=
+
+ New methods.
+
* Integer#ord
* Integer#odd?
* Integer#even?
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog (revision 16029)
+++ ruby_1_8/ChangeLog (revision 16030)
@@ -1,3 +1,9 @@
+Tue Apr 15 16:47:48 2008 Kazuhiro NISHIYAMA <zn@m...>
+
+ * signal.c, gc.c: New methods: GC.stress, GC.stress=;
+ backported from 1.9. a patch from Tadashi Saito
+ in [ruby-dev:34394] and bug#19000
+
Tue Apr 15 12:35:44 2008 Nobuyoshi Nakada <nobu@r...>
* rubyio.h (rb_io_t): renamed from OpenFile.
Index: ruby_1_8/signal.c
===================================================================
--- ruby_1_8/signal.c (revision 16029)
+++ ruby_1_8/signal.c (revision 16030)
@@ -628,6 +628,8 @@
}
#endif
+ extern int ruby_gc_stress;
+ ruby_gc_stress = 0;
rb_bug("Segmentation fault");
}
#endif
Index: ruby_1_8/gc.c
===================================================================
--- ruby_1_8/gc.c (revision 16029)
+++ ruby_1_8/gc.c (revision 16030)
@@ -76,6 +76,8 @@
static VALUE nomem_error;
static void garbage_collect();
+int ruby_gc_stress = 0;
+
void
rb_memerror()
{
@@ -89,6 +91,41 @@
rb_exc_raise(nomem_error);
}
+/*
+ * call-seq:
+ * GC.stress => true or false
+ *
+ * returns current status of GC stress mode.
+ */
+
+static VALUE
+gc_stress_get(self)
+ VALUE self;
+{
+ return ruby_gc_stress ? Qtrue : Qfalse;
+}
+
+/*
+ * call-seq:
+ * GC.stress = bool => bool
+ *
+ * updates GC stress mode.
+ *
+ * When GC.stress = true, GC is invoked for all GC opportunity:
+ * all memory and object allocation.
+ *
+ * Since it makes Ruby very slow, it is only for debugging.
+ */
+
+static VALUE
+gc_stress_set(self, bool)
+ VALUE self, bool;
+{
+ rb_secure(2);
+ ruby_gc_stress = RTEST(bool);
+ return bool;
+}
+
void *
ruby_xmalloc(size)
long size;
@@ -101,7 +138,7 @@
if (size == 0) size = 1;
malloc_increase += size;
- if (malloc_increase > malloc_limit) {
+ if (ruby_gc_stress || malloc_increase > malloc_limit) {
garbage_collect();
}
RUBY_CRITICAL(mem = malloc(size));
@@ -141,6 +178,7 @@
if (!ptr) return xmalloc(size);
if (size == 0) size = 1;
malloc_increase += size;
+ if (ruby_gc_stress) garbage_collect();
RUBY_CRITICAL(mem = realloc(ptr, size));
if (!mem) {
garbage_collect();
@@ -383,7 +421,7 @@
if (during_gc)
rb_bug("object allocation during garbage collection phase");
- if (!freelist) garbage_collect();
+ if (ruby_gc_stress || !freelist) garbage_collect();
obj = (VALUE)freelist;
freelist = freelist->as.free.next;
@@ -2037,6 +2075,8 @@
rb_define_singleton_method(rb_mGC, "start", rb_gc_start, 0);
rb_define_singleton_method(rb_mGC, "enable", rb_gc_enable, 0);
rb_define_singleton_method(rb_mGC, "disable", rb_gc_disable, 0);
+ rb_define_singleton_method(rb_mGC, "stress", gc_stress_get, 0);
+ rb_define_singleton_method(rb_mGC, "stress=", gc_stress_set, 1);
rb_define_method(rb_mGC, "garbage_collect", rb_gc_start, 0);
rb_mObSpace = rb_define_module("ObjectSpace");
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/