ruby-changes:60848
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 21 Apr 2020 12:59:56 +0900 (JST)
Subject: [ruby-changes:60848] adab82b9a7 (master): TRY_WITH_GC: abort immediately
https://git.ruby-lang.org/ruby.git/commit/?id=adab82b9a7 From adab82b9a71f60ad1c7f4f8c134a5ae9198ab32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= <shyouhei@r...> Date: Tue, 21 Apr 2020 12:57:33 +0900 Subject: TRY_WITH_GC: abort immediately NoMemoryError is observed on icc but I fail to reproduce so far. Let me see the backtrace on CI. diff --git a/gc.c b/gc.c index 115afa1..82f00f7 100644 --- a/gc.c +++ b/gc.c @@ -9594,6 +9594,7 @@ ruby_memerror_body(void *dummy) https://github.com/ruby/ruby/blob/trunk/gc.c#L9594 return 0; } +RUBY3_ATTR_MAYBE_UNUSED() static void ruby_memerror(void) { @@ -9854,7 +9855,37 @@ objspace_malloc_fixup(rb_objspace_t *objspace, void *mem, size_t size) https://github.com/ruby/ruby/blob/trunk/gc.c#L9855 return mem; } -#define TRY_WITH_GC(alloc) do { \ +#if defined(__GNUC__) /* && RUBY_DEBUG */ +#define RB_BUG_INSTEAD_OF_RB_MEMERROR +#endif + +#ifdef RB_BUG_INSTEAD_OF_RB_MEMERROR +#define TRY_WITH_GC(siz, expr) do { \ + const gc_profile_record_flag gpr = \ + GPR_FLAG_FULL_MARK | \ + GPR_FLAG_IMMEDIATE_MARK | \ + GPR_FLAG_IMMEDIATE_SWEEP | \ + GPR_FLAG_MALLOC; \ + objspace_malloc_gc_stress(objspace); \ + \ + if (LIKELY((expr))) { \ + /* Success on 1st try */ \ + } \ + else if (!garbage_collect_with_gvl(objspace, gpr)) { \ + /* @shyouhei thinks this doesn't happen */ \ + rb_bug("TRY_WITH_GC: could not GC"); \ + } \ + else if ((expr)) { \ + /* Suucess on 2nd try */ \ + } \ + else { \ + rb_bug("TRY_WITH_GC: could not allocate:" \ + "%"PRIdSIZE" bytes for %s", \ + siz, # expr); \ + } \ + } while (0) +#else +#define TRY_WITH_GC(siz, alloc) do { \ objspace_malloc_gc_stress(objspace); \ if (!(alloc) && \ (!garbage_collect_with_gvl(objspace, GPR_FLAG_FULL_MARK | \ @@ -9864,6 +9895,7 @@ objspace_malloc_fixup(rb_objspace_t *objspace, void *mem, size_t size) https://github.com/ruby/ruby/blob/trunk/gc.c#L9895 ruby_memerror(); \ } \ } while (0) +#endif /* these shouldn't be called directly. * objspace_* functinos do not check allocation size. @@ -9874,7 +9906,7 @@ objspace_xmalloc0(rb_objspace_t *objspace, size_t size) https://github.com/ruby/ruby/blob/trunk/gc.c#L9906 void *mem; size = objspace_malloc_prepare(objspace, size); - TRY_WITH_GC(mem = malloc(size)); + TRY_WITH_GC(size, mem = malloc(size)); RB_DEBUG_COUNTER_INC(heap_xmalloc); return objspace_malloc_fixup(objspace, mem, size); } @@ -9945,7 +9977,7 @@ objspace_xrealloc(rb_objspace_t *objspace, void *ptr, size_t new_size, size_t ol https://github.com/ruby/ruby/blob/trunk/gc.c#L9977 #endif old_size = objspace_malloc_size(objspace, ptr, old_size); - TRY_WITH_GC(mem = realloc(ptr, new_size)); + TRY_WITH_GC(new_size, mem = realloc(ptr, new_size)); new_size = objspace_malloc_size(objspace, mem, new_size); #if CALC_EXACT_MALLOC_SIZE @@ -10127,7 +10159,7 @@ objspace_xcalloc(rb_objspace_t *objspace, size_t size) https://github.com/ruby/ruby/blob/trunk/gc.c#L10159 void *mem; size = objspace_malloc_prepare(objspace, size); - TRY_WITH_GC(mem = calloc1(size)); + TRY_WITH_GC(size, mem = calloc1(size)); return objspace_malloc_fixup(objspace, mem, size); } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/