Imported code from Rubinius.