add `finalize` function to force finalization

ref #7721, #8891
add explicit cast in finalize_object
Merge pull request #9255 from JuliaLang/jb/finalize

RFC: add `finalize` function