JRuby ObjectSpace.each_object compatibility

[#50752269]

JRuby does not allow ObjectSpace.each_object to take any class by
default, it only allows Class and then you need to check the returned
instance for the specific class.