I have seen a few bugs around this recently: of course its a bug in application code but a JVM crash is not good.
I think we should see if we can prevent the crashes better than the current weak map, e.g. make it a safer option.
I made an ugly prototype here: https://github.com/apache/lucene-solr/compare/master...rmuir:ace?expand=1
It has a test that crashes the JVM without the patch but passes with.
Hacky patch only implements readBytes() but has no problems with the luceneutil benchmark (1M):
We should do more testing. Maybe its totally the wrong tradeoff, maybe we only need handles for getters and everything inlines correctly, rather than needing a ton for every getXYZ() method...