From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 37F2821847; Wed, 2 May 2018 04:52:49 +0000 (UTC) Date: Wed, 2 May 2018 04:52:49 +0000 From: Eric Wong To: spew@80x24.org Subject: [PATCH 6/4] gc.c: allow disabling sleepy GC Message-ID: <20180502045248.GA3949@80x24.org> References: <20180501080844.22751-1-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180501080844.22751-1-e@80x24.org> List-Id: * internal.h: remove prototypes * gc.h: define macros and static inlines for disabling functionality moved prototypes from internal.h * gc.c: adjust for switches, update comments --- gc.c | 12 +++++++----- gc.h | 25 +++++++++++++++++++++++++ internal.h | 4 ---- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/gc.c b/gc.c index 61b5e24f094..f7a3cd9eb43 100644 --- a/gc.c +++ b/gc.c @@ -6518,14 +6518,15 @@ gc_rest(rb_objspace_t *objspace) } } +#if RUBY_GC_SLEEPY_SWEEP || RUBY_GC_SLEEPY_MARK +/* this is just a hint, TOCTOU race may happen */ int rb_gc_inprogress(const rb_execution_context_t *ec) { rb_objspace_t *objspace = rb_ec_vm_ptr(ec)->objspace; - /* TODO: should this check is_incremental_marking() ? */ - return is_lazy_sweeping(&objspace->eden_heap) || - is_incremental_marking(objspace); + return (RUBY_GC_SLEEPY_SWEEP && is_lazy_sweeping(&objspace->eden_heap)) || + (RUBY_GC_SLEEPY_MARK && is_incremental_marking(objspace)); } /* returns true if there is more work to do, false if not */ @@ -6534,12 +6535,12 @@ rb_gc_step(const rb_execution_context_t *ec) { rb_objspace_t *objspace = rb_ec_vm_ptr(ec)->objspace; - if (is_lazy_sweeping(&objspace->eden_heap)) { + if (RUBY_GC_SLEEPY_SWEEP && is_lazy_sweeping(&objspace->eden_heap)) { #if GC_ENABLE_LAZY_SWEEP gc_sweep_continue(objspace, &objspace->eden_heap); #endif } - else if (is_incremental_marking(objspace)) { + else if (RUBY_GC_SLEEPY_MARK && is_incremental_marking(objspace)) { #if GC_ENABLE_INCREMENTAL_MARK gc_marks_continue(objspace, &objspace->eden_heap); #endif @@ -6547,6 +6548,7 @@ rb_gc_step(const rb_execution_context_t *ec) return rb_gc_inprogress(ec); } +#endif /* RUBY_GC_SLEEPY_SWEEP || RUBY_GC_SLEEPY_MARK */ struct objspace_and_reason { rb_objspace_t *objspace; diff --git a/gc.h b/gc.h index 2c91e06620a..1f8a06cdc7e 100644 --- a/gc.h +++ b/gc.h @@ -91,6 +91,31 @@ const char *rb_raw_obj_info(char *buff, const int buff_size, VALUE obj); void rb_obj_info_dump(VALUE obj); struct rb_thread_struct; +struct rb_execution_context_struct; + +#ifndef RUBY_GC_SLEEPY_SWEEP +# define RUBY_GC_SLEEPY_SWEEP 1 +#endif +#ifndef RUBY_GC_SLEEPY_MARK +# define RUBY_GC_SLEEPY_MARK 1 +#endif + +#if RUBY_GC_SLEEPY_SWEEP || RUBY_GC_SLEEPY_MARK +int rb_gc_inprogress(const struct rb_execution_context_struct *); +int rb_gc_step(const struct rb_execution_context_struct *); +#else /* (RUBY_GC_SLEEPY_SWEEP|RUBY_GC_SLEEPY_MARK) == 0 */ +static inline int +rb_gc_inprogress(const struct rb_execution_context_struct *ec) +{ + return 0; +} + +static inline int +rb_gc_step(const struct rb_execution_context_struct *ec) +{ + return 0; +} +#endif /* (RUBY_GC_SLEEPY_SWEEP|RUBY_GC_SLEEPY_MARK) == 0 */ RUBY_SYMBOL_EXPORT_BEGIN diff --git a/internal.h b/internal.h index 43043e6601d..85370ec0d7f 100644 --- a/internal.h +++ b/internal.h @@ -1290,10 +1290,6 @@ void rb_gc_writebarrier_remember(VALUE obj); void ruby_gc_set_params(int safe_level); void rb_copy_wb_protected_attribute(VALUE dest, VALUE obj); -struct rb_execution_context_struct; -int rb_gc_inprogress(const struct rb_execution_context_struct *); -int rb_gc_step(const struct rb_execution_context_struct *); - #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(_WIN32) #define ruby_sized_xrealloc(ptr, new_size, old_size) ruby_xrealloc(ptr, new_size) #define ruby_sized_xrealloc2(ptr, new_count, element_size, old_count) ruby_xrealloc(ptr, new_count, element_size) -- EW