[前][次][番号順一覧][スレッド一覧]

ruby-changes:35384

From: ko1 <ko1@a...>
Date: Tue, 9 Sep 2014 13:57:15 +0900 (JST)
Subject: [ruby-changes:35384] ko1:r47466 (trunk): * gc.c: add rb_objspace_t::flags::gc_stressfull and

ko1	2014-09-09 13:56:55 +0900 (Tue, 09 Sep 2014)

  New Revision: 47466

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47466

  Log:
    * gc.c: add rb_objspace_t::flags::gc_stressfull and
      ruby_gc_stressfull macro.
      Rename objspace->gc_stress to objspace->gc_stress_mode.
      If objspace->gc_stress_mode is true (!nil and !false) then
      ruby_gc_stressfull becomes TRUE.
      ruby_gc_stressfull will speedup newobj_of() slightly.
    * gc.c: initialize ruby_gc_stress(full|_mode) by gc_params.gc_stress
      even if ENABLE_VM_OBJSPACE is false.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47465)
+++ ChangeLog	(revision 47466)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Sep  9 13:51:32 2014  Koichi Sasada  <ko1@a...>
+
+	* gc.c: add rb_objspace_t::flags::gc_stressfull and
+	  ruby_gc_stressfull macro.
+	  Rename objspace->gc_stress to objspace->gc_stress_mode.
+
+	  If objspace->gc_stress_mode is true (!nil and !false) then
+	  ruby_gc_stressfull becomes TRUE.
+
+	  ruby_gc_stressfull will speedup newobj_of() slightly.
+
+	* gc.c: initialize ruby_gc_stress(full|_mode) by gc_params.gc_stress
+	  even if ENABLE_VM_OBJSPACE is false.
+
 Tue Sep  9 13:05:50 2014  Koichi Sasada  <ko1@a...>
 
 	* gc.c: remvoe ruby_disable_gc_stress and add ruby_disable_gc
Index: gc.c
===================================================================
--- gc.c	(revision 47465)
+++ gc.c	(revision 47466)
@@ -168,9 +168,7 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/gc.c#L168
     size_t oldmalloc_limit_min;
     size_t oldmalloc_limit_max;
     double oldmalloc_limit_growth_factor;
-#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
     VALUE gc_stress;
-#endif
 } ruby_gc_params_t;
 
 static ruby_gc_params_t gc_params = {
@@ -466,6 +464,7 @@ typedef struct rb_objspace { https://github.com/ruby/ruby/blob/trunk/gc.c#L464
 
     struct {
 	enum gc_stat stat : 2;
+	unsigned int  gc_stressfull: 1;
 	unsigned int immediate_sweep : 1;
 	unsigned int dont_gc : 1;
 	unsigned int dont_incremental : 1;
@@ -554,13 +553,14 @@ typedef struct rb_objspace { https://github.com/ruby/ruby/blob/trunk/gc.c#L553
     } profile;
     struct gc_list *global_list;
     rb_event_flag_t hook_events; /* this place may be affinity with memory cache */
-    VALUE gc_stress;
 
     struct mark_func_data_struct {
 	void *data;
 	void (*mark_func)(VALUE v, void *data);
     } *mark_func_data;
 
+    VALUE gc_stress_mode;
+
 #if USE_RGENGC
     struct {
 	VALUE parent_object;
@@ -657,13 +657,13 @@ struct heap_page { https://github.com/ruby/ruby/blob/trunk/gc.c#L657
 /* Aliases */
 #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
 #define rb_objspace (*GET_VM()->objspace)
-#define ruby_initial_gc_stress	gc_params.gc_stress
-VALUE *ruby_initial_gc_stress_ptr = &ruby_initial_gc_stress;
 #else
 static rb_objspace_t rb_objspace = {{GC_MALLOC_LIMIT_MIN}};
-VALUE *ruby_initial_gc_stress_ptr = &rb_objspace.gc_stress;
 #endif
 
+#define ruby_initial_gc_stress	gc_params.gc_stress
+VALUE *ruby_initial_gc_stress_ptr = &ruby_initial_gc_stress;
+
 #define malloc_limit		objspace->malloc_params.limit
 #define malloc_increase 	objspace->malloc_params.increase
 #define malloc_allocated_size 	objspace->malloc_params.allocated_size
@@ -685,7 +685,8 @@ VALUE *ruby_initial_gc_stress_ptr = &rb_ https://github.com/ruby/ruby/blob/trunk/gc.c#L685
 #define finalizing		objspace->atomic_flags.finalizing
 #define finalizer_table 	objspace->finalizer_table
 #define global_list		objspace->global_list
-#define ruby_gc_stress		objspace->gc_stress
+#define ruby_gc_stressfull	objspace->flags.gc_stressfull
+#define ruby_gc_stress_mode     objspace->gc_stress_mode
 
 #define is_marking(objspace)             ((objspace)->flags.stat == gc_stat_marking)
 #define is_sweeping(objspace)            ((objspace)->flags.stat == gc_stat_sweeping)
@@ -784,6 +785,8 @@ static VALUE gc_verify_internal_consiste https://github.com/ruby/ruby/blob/trunk/gc.c#L785
 static int gc_verify_heap_page(rb_objspace_t *objspace, struct heap_page *page, VALUE obj);
 static int gc_verify_heap_pages(rb_objspace_t *objspace);
 
+static void gc_stress_set(rb_objspace_t *objspace, VALUE flag);
+
 static double getrusage_time(void);
 static inline void gc_prof_setup_new_record(rb_objspace_t *objspace, int reason);
 static inline void gc_prof_timer_start(rb_objspace_t *);
@@ -1176,8 +1179,6 @@ rb_objspace_t * https://github.com/ruby/ruby/blob/trunk/gc.c#L1179
 rb_objspace_alloc(void)
 {
     rb_objspace_t *objspace = calloc(1, sizeof(rb_objspace_t));
-    ruby_gc_stress = ruby_initial_gc_stress;
-
     malloc_limit = gc_params.malloc_limit_min;
 
     return objspace;
@@ -1599,7 +1600,7 @@ newobj_of(VALUE klass, VALUE flags, VALU https://github.com/ruby/ruby/blob/trunk/gc.c#L1600
 	rb_bug("object allocation during garbage collection phase");
     }
 
-    if (UNLIKELY(ruby_gc_stress)) {
+    if (UNLIKELY(ruby_gc_stressfull)) {
 	if (!garbage_collect(objspace, FALSE, FALSE, FALSE, GPR_FLAG_NEWOBJ)) {
 	    rb_memerror();
 	}
@@ -2000,6 +2001,8 @@ Init_heap(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L2001
 {
     rb_objspace_t *objspace = &rb_objspace;
 
+    gc_stress_set(objspace, ruby_initial_gc_stress);
+
 #if RGENGC_ESTIMATE_OLDMALLOC
     objspace->rgengc.oldmalloc_increase_limit = gc_params.oldmalloc_limit_min;
 #endif
@@ -5664,7 +5667,7 @@ enum { https://github.com/ruby/ruby/blob/trunk/gc.c#L5667
 };
 
 #define gc_stress_full_mark_after_malloc_p() \
-    (FIXNUM_P(ruby_gc_stress) && (FIX2LONG(ruby_gc_stress) & (1<<gc_stress_full_mark_after_malloc)))
+    (FIXNUM_P(ruby_gc_stress_mode) && (FIX2LONG(ruby_gc_stress_mode) & (1<<gc_stress_full_mark_after_malloc)))
 
 static void
 heap_ready_to_gc(rb_objspace_t *objspace, rb_heap_t *heap)
@@ -5794,8 +5797,8 @@ gc_start(rb_objspace_t *objspace, const https://github.com/ruby/ruby/blob/trunk/gc.c#L5797
 
     gc_enter(objspace, "gc_start");
 
-    if (ruby_gc_stress) {
-	int flag = FIXNUM_P(ruby_gc_stress) ? FIX2INT(ruby_gc_stress) : 0;
+    if (ruby_gc_stressfull) {
+	int flag = FIXNUM_P(ruby_gc_stress_mode) ? FIX2INT(ruby_gc_stress_mode) : 0;
 
 	if ((flag & (1<<gc_stress_no_major)) == 0) {
 	    do_full_mark = TRUE;
@@ -6483,7 +6486,14 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L6486
 gc_stress_get(VALUE self)
 {
     rb_objspace_t *objspace = &rb_objspace;
-    return ruby_gc_stress;
+    return ruby_gc_stress_mode;
+}
+
+static void
+gc_stress_set(rb_objspace_t *objspace, VALUE flag)
+{
+    objspace->flags.gc_stressfull = RTEST(flag);
+    objspace->gc_stress_mode = flag;
 }
 
 /*
@@ -6504,11 +6514,11 @@ gc_stress_get(VALUE self) https://github.com/ruby/ruby/blob/trunk/gc.c#L6514
  */
 
 static VALUE
-gc_stress_set(VALUE self, VALUE flag)
+gc_stress_set_m(VALUE self, VALUE flag)
 {
     rb_objspace_t *objspace = &rb_objspace;
     rb_secure(2);
-    ruby_gc_stress = FIXNUM_P(flag) ? flag : (RTEST(flag) ? Qtrue : Qfalse);
+    gc_stress_set(objspace, flag);
     return flag;
 }
 
@@ -6929,7 +6939,7 @@ atomic_sub_nounderflow(size_t *var, size https://github.com/ruby/ruby/blob/trunk/gc.c#L6939
 static void
 objspace_malloc_gc_stress(rb_objspace_t *objspace)
 {
-    if (ruby_gc_stress && ruby_native_thread_p()) {
+    if (ruby_gc_stressfull && ruby_native_thread_p()) {
 	garbage_collect_with_gvl(objspace, gc_stress_full_mark_after_malloc_p(), TRUE, TRUE, GPR_FLAG_STRESS | GPR_FLAG_MALLOC);
     }
 }
@@ -7740,7 +7750,7 @@ gc_prof_setup_new_record(rb_objspace_t * https://github.com/ruby/ruby/blob/trunk/gc.c#L7750
 	MEMZERO(record, gc_profile_record, 1);
 
 	/* setup before-GC parameter */
-	record->flags = reason | (ruby_gc_stress ? GPR_FLAG_STRESS : 0);
+	record->flags = reason | (ruby_gc_stressfull ? GPR_FLAG_STRESS : 0);
 #if MALLOC_ALLOCATED_SIZE
 	record->allocated_size = malloc_allocated_size;
 #endif
@@ -8519,7 +8529,7 @@ Init_GC(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L8529
     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_singleton_method(rb_mGC, "stress=", gc_stress_set_m, 1);
     rb_define_singleton_method(rb_mGC, "count", gc_count, 0);
     rb_define_singleton_method(rb_mGC, "stat", gc_stat, -1);
     rb_define_singleton_method(rb_mGC, "latest_gc_info", gc_latest_gc_info, -1);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]