Add cleanup for unused code resource chunks

This cleans up chunks that are completely unused during GC. This makes
sure that if we have code that creates churn for code resources doens't
result in these lists growing all the time.
Fix deadlock when shutting down finalizers

There was a race here setting exit_ and waiting. We ensure we always
have the worker_lock when changing and checking exit_.