ruby-changes:70100
From: Alan <ko1@a...>
Date: Wed, 8 Dec 2021 07:20:53 +0900 (JST)
Subject: [ruby-changes:70100] 286c07f0dc (master): YJIT: Remove guard_self_is_heap()
https://git.ruby-lang.org/ruby.git/commit/?id=286c07f0dc From 286c07f0dcd7999bfb9cb4889125ebce59dca4cc Mon Sep 17 00:00:00 2001 From: Alan Wu <XrXr@u...> Date: Tue, 7 Dec 2021 15:37:32 -0500 Subject: YJIT: Remove guard_self_is_heap() It's superseded by functionality added to jit_guard_known_klass(). In weird situations such as the ones in the included test, guard_self_is_heap() triggered assertions. Co-authored-by: Jemma Issroff <jemmaissroff@g...> --- bootstraptest/test_yjit.rb | 11 +++++++++++ yjit_codegen.c | 25 +++++-------------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index 140365ee0cb..e50d78a9dc5 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_yjit.rb#L1 +assert_equal '[nil, nil, nil, nil, nil, nil]', %q{ + [NilClass, TrueClass, FalseClass, Integer, Float, Symbol].each do |klass| + klass.class_eval("def foo = @foo") + end + + [nil, true, false, 0xFABCAFE, 0.42, :cake].map do |instance| + instance.foo + instance.foo + end +} + assert_equal '0', %q{ # This is a regression test for incomplete invalidation from # opt_setinlinecache. This test might be brittle, so diff --git a/yjit_codegen.c b/yjit_codegen.c index 9c603e240bf..3378f1500dd 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -1501,24 +1501,6 @@ gen_setlocal_wc1(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L1501 return gen_setlocal_generic(jit, ctx, idx, 1); } -// Check that `self` is a pointer to an object on the GC heap -static void -guard_self_is_heap(codeblock_t *cb, x86opnd_t self_opnd, uint8_t *side_exit, ctx_t *ctx) -{ - - // `self` is constant throughout the entire region, so we only need to do this check once. - if (!ctx->self_type.is_heap) { - ADD_COMMENT(cb, "guard self is heap"); - RUBY_ASSERT(Qfalse < Qnil); - test(cb, self_opnd, imm_opnd(RUBY_IMMEDIATE_MASK)); - jnz_ptr(cb, side_exit); - cmp(cb, self_opnd, imm_opnd(Qnil)); - jbe_ptr(cb, side_exit); - - ctx->self_type.is_heap = 1; - } -} - static void gen_jnz_to_target0(codeblock_t *cb, uint8_t *target0, uint8_t *target1, uint8_t shape) { @@ -1808,7 +1790,6 @@ gen_getinstancevariable(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L1790 // Guard that the receiver has the same class as the one from compile time. mov(cb, REG0, member_opnd(REG_CFP, rb_control_frame_t, self)); - guard_self_is_heap(cb, REG0, COUNTED_EXIT(jit, side_exit, getivar_se_self_not_heap), ctx); jit_guard_known_klass(jit, ctx, comptime_val_klass, OPND_SELF, comptime_val, GETIVAR_MAX_DEPTH, side_exit); @@ -2904,7 +2885,11 @@ gen_jump(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L2885 } /* -Guard that a stack operand has the same class as known_klass. +Guard that self or a stack operand has the same class as `known_klass`, using +`sample_instance` to speculate about the shape of the runtime value. +FIXNUM and on-heap integers are treated as if they have distinct classes, and +the guard generated for one will fail for the other. + Recompile as contingency if possible, or take side exit a last resort. */ static bool -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/