Nest host validation vs NestHost attribute performed by Lookup::defineHiddenClass

John Rose john.r.rose at
Tue Oct 1 21:38:31 UTC 2019

On Oct 1, 2019, at 3:42 AM, Peter Levart <peter.levart at> wrote:
> ...what is the reason for Class.getNestMembers() for not being dynamic?

I think you answer your own question in the next sentences:  It’s an expensive luxury.

> It is true that that method throws LinkageError in case the list of static members can not be validated. And if a hidden class HC is added to a nest whose static members can not be validated (by using a LC that is a validated part of that nest), then HC.getNestMembers() will also throw LinkageError. But in case when the static members can be validated, the returned array could contain all the validated static members plus the so far added hidden members which have not been unloaded yet. If that is possible to implement, of course. It would work similar to WeakReference: If the WeakReference has not been "cleared" by GC, the referent can still be obtained.
> To make a consistent API, getNestMembers() would have to either "never" or "always" return hidden members.

Sometimes consistency is not worth the cost.  The alternative “consistency” is that getNMs provides
a validated but restricted static model, while getNH provides a dynamic one.  The static stuff is what’s
in the class files, the dynamic stuff is what the JVM uses to make access decisions.

More information about the valhalla-dev mailing list