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

ruby-changes:67079

From: Nobuyoshi <ko1@a...>
Date: Sun, 8 Aug 2021 17:15:17 +0900 (JST)
Subject: [ruby-changes:67079] 587f501c7c (master): Make bit flags `reason` unsigned

https://git.ruby-lang.org/ruby.git/commit/?id=587f501c7c

From 587f501c7cc63730f6e03af50ec99bb6624d93dd Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 8 Aug 2021 15:24:55 +0900
Subject: Make bit flags `reason` unsigned

---
 gc.c | 52 ++++++++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/gc.c b/gc.c
index a44d100..560eaff 100644
--- a/gc.c
+++ b/gc.c
@@ -514,7 +514,7 @@ typedef enum { https://github.com/ruby/ruby/blob/trunk/gc.c#L514
 } gc_profile_record_flag;
 
 typedef struct gc_profile_record {
-    int flags;
+    unsigned int flags;
 
     double gc_time;
     double gc_invoke_time;
@@ -755,7 +755,7 @@ typedef struct rb_objspace { https://github.com/ruby/ruby/blob/trunk/gc.c#L755
 
     struct {
 	int run;
-	int latest_gc_info;
+	unsigned int latest_gc_info;
 	gc_profile_record *records;
 	gc_profile_record *current_record;
 	size_t next_index;
@@ -1055,9 +1055,9 @@ static void init_mark_stack(mark_stack_t *stack); https://github.com/ruby/ruby/blob/trunk/gc.c#L1055
 
 static int ready_to_gc(rb_objspace_t *objspace);
 
-static int garbage_collect(rb_objspace_t *, int reason);
+static int garbage_collect(rb_objspace_t *, unsigned int reason);
 
-static int  gc_start(rb_objspace_t *objspace, int reason);
+static int  gc_start(rb_objspace_t *objspace, unsigned int reason);
 static void gc_rest(rb_objspace_t *objspace);
 
 enum gc_enter_event {
@@ -1113,7 +1113,7 @@ static void gc_stress_set(rb_objspace_t *objspace, VALUE flag); https://github.com/ruby/ruby/blob/trunk/gc.c#L1113
 static VALUE gc_disable_no_rest(rb_objspace_t *);
 
 static double getrusage_time(void);
-static inline void gc_prof_setup_new_record(rb_objspace_t *objspace, int reason);
+static inline void gc_prof_setup_new_record(rb_objspace_t *objspace, unsigned int reason);
 static inline void gc_prof_timer_start(rb_objspace_t *);
 static inline void gc_prof_timer_stop(rb_objspace_t *);
 static inline void gc_prof_mark_timer_start(rb_objspace_t *);
@@ -8880,7 +8880,7 @@ gc_reset_malloc_info(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L8880
 }
 
 static int
-garbage_collect(rb_objspace_t *objspace, int reason)
+garbage_collect(rb_objspace_t *objspace, unsigned int reason)
 {
     int ret;
 
@@ -8904,18 +8904,18 @@ garbage_collect(rb_objspace_t *objspace, int reason) https://github.com/ruby/ruby/blob/trunk/gc.c#L8904
 }
 
 static int
-gc_start(rb_objspace_t *objspace, int reason)
+gc_start(rb_objspace_t *objspace, unsigned int reason)
 {
-    unsigned int do_full_mark = !!((unsigned)reason & GPR_FLAG_FULL_MARK);
+    unsigned int do_full_mark = !!(reason & GPR_FLAG_FULL_MARK);
 #if GC_ENABLE_INCREMENTAL_MARK
-    unsigned int immediate_mark = (unsigned)reason & GPR_FLAG_IMMEDIATE_MARK;
+    unsigned int immediate_mark = reason & GPR_FLAG_IMMEDIATE_MARK;
 #endif
 
     /* reason may be clobbered, later, so keep set immediate_sweep here */
-    objspace->flags.immediate_sweep = !!((unsigned)reason & GPR_FLAG_IMMEDIATE_SWEEP);
+    objspace->flags.immediate_sweep = !!(reason & GPR_FLAG_IMMEDIATE_SWEEP);
 
     /* Explicitly enable compaction (GC.compact) */
-    objspace->flags.during_compacting = (!!((unsigned)reason & GPR_FLAG_COMPACT) << 1);
+    objspace->flags.during_compacting = (!!(reason & GPR_FLAG_COMPACT) << 1);
 
     if (!heap_allocated_pages) return FALSE; /* heap is not ready */
     if (!(reason & GPR_FLAG_METHOD) && !ready_to_gc(objspace)) return TRUE; /* GC is not allowed */
@@ -8972,7 +8972,7 @@ gc_start(rb_objspace_t *objspace, int reason) https://github.com/ruby/ruby/blob/trunk/gc.c#L8972
 
     if (objspace->flags.immediate_sweep) reason |= GPR_FLAG_IMMEDIATE_SWEEP;
 
-    gc_report(1, objspace, "gc_start(reason: %d) => %u, %d, %d\n",
+    gc_report(1, objspace, "gc_start(reason: %x) => %u, %d, %d\n",
 	      reason,
 	      do_full_mark, !is_incremental_marking(objspace), objspace->flags.immediate_sweep);
 
@@ -9042,7 +9042,7 @@ gc_rest(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L9042
 
 struct objspace_and_reason {
     rb_objspace_t *objspace;
-    int reason;
+    unsigned int reason;
 };
 
 static void
@@ -9202,7 +9202,7 @@ gc_with_gvl(void *ptr) https://github.com/ruby/ruby/blob/trunk/gc.c#L9202
 }
 
 static int
-garbage_collect_with_gvl(rb_objspace_t *objspace, int reason)
+garbage_collect_with_gvl(rb_objspace_t *objspace, unsigned int reason)
 {
     if (dont_gc_val()) return TRUE;
     if (ruby_thread_has_gvl_p()) {
@@ -9227,10 +9227,10 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L9227
 gc_start_internal(rb_execution_context_t *ec, VALUE self, VALUE full_mark, VALUE immediate_mark, VALUE immediate_sweep, VALUE compact)
 {
     rb_objspace_t *objspace = &rb_objspace;
-    int reason = GPR_FLAG_FULL_MARK |
-                 GPR_FLAG_IMMEDIATE_MARK |
-                 GPR_FLAG_IMMEDIATE_SWEEP |
-                 GPR_FLAG_METHOD;
+    unsigned int reason = (GPR_FLAG_FULL_MARK |
+                           GPR_FLAG_IMMEDIATE_MARK |
+                           GPR_FLAG_IMMEDIATE_SWEEP |
+                           GPR_FLAG_METHOD);
 
     /* For now, compact implies full mark / sweep, so ignore other flags */
     if (RTEST(compact)) {
@@ -10244,7 +10244,7 @@ void https://github.com/ruby/ruby/blob/trunk/gc.c#L10244
 rb_gc(void)
 {
     rb_objspace_t *objspace = &rb_objspace;
-    int reason = GPR_DEFAULT_REASON;
+    unsigned int reason = GPR_DEFAULT_REASON;
     garbage_collect(objspace, reason);
 }
 
@@ -10285,7 +10285,7 @@ gc_count(rb_execution_context_t *ec, VALUE self) https://github.com/ruby/ruby/blob/trunk/gc.c#L10285
 }
 
 static VALUE
-gc_info_decode(rb_objspace_t *objspace, const VALUE hash_or_key, const int orig_flags)
+gc_info_decode(rb_objspace_t *objspace, const VALUE hash_or_key, const unsigned int orig_flags)
 {
     static VALUE sym_major_by = Qnil, sym_gc_by, sym_immediate_sweep, sym_have_finalizer, sym_state;
     static VALUE sym_nofree, sym_oldgen, sym_shady, sym_force, sym_stress;
@@ -10296,7 +10296,7 @@ gc_info_decode(rb_objspace_t *objspace, const VALUE hash_or_key, const int orig_ https://github.com/ruby/ruby/blob/trunk/gc.c#L10296
     static VALUE sym_none, sym_marking, sym_sweeping;
     VALUE hash = Qnil, key = Qnil;
     VALUE major_by;
-    VALUE flags = orig_flags ? orig_flags : objspace->profile.latest_gc_info;
+    unsigned int flags = orig_flags ? orig_flags : objspace->profile.latest_gc_info;
 
     if (SYMBOL_P(hash_or_key)) {
         key = hash_or_key;
@@ -11220,8 +11220,8 @@ static void https://github.com/ruby/ruby/blob/trunk/gc.c#L11220
 objspace_malloc_gc_stress(rb_objspace_t *objspace)
 {
     if (ruby_gc_stressful && ruby_native_thread_p()) {
-        int reason = GPR_FLAG_IMMEDIATE_MARK | GPR_FLAG_IMMEDIATE_SWEEP |
-                                     GPR_FLAG_STRESS | GPR_FLAG_MALLOC;
+        unsigned int reason = (GPR_FLAG_IMMEDIATE_MARK | GPR_FLAG_IMMEDIATE_SWEEP |
+                               GPR_FLAG_STRESS | GPR_FLAG_MALLOC);
 
         if (gc_stress_full_mark_after_malloc_p()) {
             reason |= GPR_FLAG_FULL_MARK;
@@ -12355,7 +12355,7 @@ getrusage_time(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L12355
 }
 
 static inline void
-gc_prof_setup_new_record(rb_objspace_t *objspace, int reason)
+gc_prof_setup_new_record(rb_objspace_t *objspace, unsigned int reason)
 {
     if (objspace->profile.run) {
 	size_t index = objspace->profile.next_index;
@@ -12659,9 +12659,9 @@ gc_profile_record_get(VALUE _) https://github.com/ruby/ruby/blob/trunk/gc.c#L12659
 #define MAJOR_REASON_MAX 0x10
 
 static char *
-gc_profile_dump_major_reason(int flags, char *buff)
+gc_profile_dump_major_reason(unsigned int flags, char *buff)
 {
-    int reason = flags & GPR_FLAG_MAJOR_MASK;
+    unsigned int reason = flags & GPR_FLAG_MAJOR_MASK;
     int i = 0;
 
     if (reason == GPR_FLAG_NONE) {
-- 
cgit v1.1


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

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