From 9d5b3e1d0f3d44a52dffb6ec1f09c361c3b419c7 Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Tue, 31 Aug 2021 14:26:18 -0400 Subject: Add a small test for the code GC --- bootstraptest/test_yjit.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index ea20224ec2..d91daea8ac 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -441,6 +441,29 @@ assert_equal '7', %q{ foo(4)[1] } +# Method redefinition while the method is on the stack +assert_equal '[777, 1]', %q{ + def foo + redef() + 777 + end + + def redef + # Redefine the global foo + eval("def foo; 1; end", TOPLEVEL_BINDING) + + # Collect dead code + GC.stress = true + GC.start + + # But we will return to the original foo, + # which remains alive because it's on the stack + end + + # Must produce [777, 1] + [foo, foo] +} + # Test for GC safety. Don't invalidate dead iseqs. assert_normal_exit %q{ Class.new do -- cgit v1.2.3