I have a simpler and more secure solution. I just need one method on
ClassLoader:
public class ClassLoader {
public void keepReferenceTo(Object o) { ... }
...
}
The ClassLoader would keep a strong reference to the passed reference
indefinitely (using some sort of minimal memory footprint, wait-free
data structure internally). We could add a convenience method to
Class, too, but it would just delegate to the same method on the
Class's loader.
Now, my library code can just keep a weak reference to the object, and
I know it won't be cleared until the class loader is reclaimed.
Bob