backport r46711, r46710, r46709, r46027, r44502, r46143, r46142 from ruby/ruby trunk.
Merge pull request #314 from hsbt/backport-ruby-trunk

backport commits from ruby/ruby trunk.