Backport from ruby/ruby

I cherry-picked from ruby/ruby HEAD.

 * r46257
 * r46207
 * r46206
 * r46007
 * r43271