Code refactoring related to heap based eviction

Makes the code that uses `java.lang.Runtime` mockable for eviction tests.