@@ -275,6 +275,99 @@ def test_run_out_of_shape_for_class_ivar
275275 end;
276276 end
277277
278+ def test_evacuate_class_ivar_and_compaction
279+ assert_separately ( [ ] , "#{ <<~"begin;" } \n #{ <<~'end;' } " )
280+
281+ begin;
282+ count = 20
283+
284+ c = Class.new
285+ count.times do |ivar|
286+ c.instance_variable_set("@i#{ivar}", "ivar-#{ivar}")
287+ end
288+
289+ i = 0
290+ while RubyVM::Shape.shapes_available > 0
291+ o = Class.new
292+ o.instance_variable_set("@i#{i}", 1)
293+ i += 1
294+ end
295+
296+ GC.auto_compact = true
297+ GC.stress = true
298+
299+ # Cause evacuation
300+ c.instance_variable_set(:@a, o = Object.new)
301+ assert_equal(o, c.instance_variable_get(:@a))
302+
303+ count.times do |ivar|
304+ assert_equal "ivar-#{ivar}", c.instance_variable_get("@i#{ivar}")
305+ end
306+ end;
307+ end
308+
309+ def test_evacuate_generic_ivar_and_compaction
310+ assert_separately ( [ ] , "#{ <<~"begin;" } \n #{ <<~'end;' } " )
311+
312+ begin;
313+ count = 20
314+
315+ c = Hash.new
316+ count.times do |ivar|
317+ c.instance_variable_set("@i#{ivar}", "ivar-#{ivar}")
318+ end
319+
320+ i = 0
321+ while RubyVM::Shape.shapes_available > 0
322+ o = Class.new
323+ o.instance_variable_set("@i#{i}", 1)
324+ i += 1
325+ end
326+
327+ GC.auto_compact = true
328+ GC.stress = true
329+
330+ # Cause evacuation
331+ c.instance_variable_set(:@a, o = Object.new)
332+ assert_equal(o, c.instance_variable_get(:@a))
333+
334+ count.times do |ivar|
335+ assert_equal "ivar-#{ivar}", c.instance_variable_get("@i#{ivar}")
336+ end
337+ end;
338+ end
339+
340+ def test_evacuate_object_ivar_and_compaction
341+ assert_separately ( [ ] , "#{ <<~"begin;" } \n #{ <<~'end;' } " )
342+
343+ begin;
344+ count = 20
345+
346+ c = Object.new
347+ count.times do |ivar|
348+ c.instance_variable_set("@i#{ivar}", "ivar-#{ivar}")
349+ end
350+
351+ i = 0
352+ while RubyVM::Shape.shapes_available > 0
353+ o = Class.new
354+ o.instance_variable_set("@i#{i}", 1)
355+ i += 1
356+ end
357+
358+ GC.auto_compact = true
359+ GC.stress = true
360+
361+ # Cause evacuation
362+ c.instance_variable_set(:@a, o = Object.new)
363+ assert_equal(o, c.instance_variable_get(:@a))
364+
365+ count.times do |ivar|
366+ assert_equal "ivar-#{ivar}", c.instance_variable_get("@i#{ivar}")
367+ end
368+ end;
369+ end
370+
278371 def test_run_out_of_shape_for_module_ivar
279372 assert_separately ( [ ] , "#{ <<~"begin;" } \n #{ <<~'end;' } " )
280373 begin;
0 commit comments