summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2021-12-07 15:37:32 -0500
committerAlan Wu <XrXr@users.noreply.github.com>2021-12-07 17:20:34 -0500
commit286c07f0dcd7999bfb9cb4889125ebce59dca4cc (patch)
tree7226c03d1e822ee1824a291588681c46fe977e0a
parente51d0d2853126322e8463508aabadc661f45fbe5 (diff)
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@gmail.com>
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5225
-rw-r--r--bootstraptest/test_yjit.rb11
-rw-r--r--yjit_codegen.c25
2 files changed, 16 insertions, 20 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index 140365ee0c..e50d78a9dc 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -1,3 +1,14 @@
+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 9c603e240b..3378f1500d 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)
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)
// 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)
}
/*
-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