backport r46144 from ruby/ruby trunk.
backport r46145 from ruby/ruby trunk.
backport r46636 from ruby/ruby trunk.
backport r46640 from ruby/ruby trunk.
backport r46641 from ruby/ruby trunk.