From c178926fbe879045fa711444a1fd9e906af23e3b Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Thu, 16 Feb 2023 17:22:44 -0500 Subject: [PATCH] YJIT: jit_prepare_routine_call() for String#+@ missing We saw SEGVs due to this when running with StackProf, which needs a correct PC for RUBY_INTERNAL_EVENT_NEWOBJ, the same event used for ObjectSpace allocation tracing. [Bug #19444] --- test/ruby/test_yjit.rb | 27 +++++++++++++++++++++++++++ yjit/src/codegen.rs | 5 ++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb index 6627a78628..2428a401cf 100644 --- a/test/ruby/test_yjit.rb +++ b/test/ruby/test_yjit.rb @@ -1092,6 +1092,33 @@ class TestYJIT < Test::Unit::TestCase RUBY end + def test_tracing_str_uplus + assert_compiles(<<~RUBY, frozen_string_literal: true, result: :ok) + def str_uplus + _ = 1 + _ = 2 + ret = [+"frfr", __LINE__] + _ = 3 + _ = 4 + + ret + end + + str_uplus + require 'objspace' + ObjectSpace.trace_object_allocations_start + + str, expected_line = str_uplus + alloc_line = ObjectSpace.allocation_sourceline(str) + + if expected_line == alloc_line + :ok + else + [expected_line, alloc_line] + end + RUBY + end + private def code_gc_helpers diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 4e466a5564..be8a5ee4b9 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -4157,7 +4157,7 @@ fn jit_rb_int_equal( /// If string is frozen, duplicate it to get a non-frozen string. Otherwise, return it. fn jit_rb_str_uplus( - _jit: &mut JITState, + jit: &mut JITState, ctx: &mut Context, asm: &mut Assembler, _ocb: &mut OutlinedCb, @@ -4168,6 +4168,9 @@ fn jit_rb_str_uplus( _known_recv_class: *const VALUE, ) -> bool { + // We allocate when we dup the string + jit_prepare_routine_call(jit, ctx, asm); + asm.comment("Unary plus on string"); let recv_opnd = asm.load(ctx.stack_pop(1)); let flags_opnd = asm.load(Opnd::mem(64, recv_opnd, RUBY_OFFSET_RBASIC_FLAGS));