[runtime] Further reduce the usage of the loader lock in the metadata code by moving code out of locked regions and using the image lock instead.