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

John Rose john.r.rose at
Tue Oct 1 22:24:01 UTC 2019

On Oct 1, 2019, at 3:13 PM, Peter Levart <peter.levart at> wrote:
> I'm not for or against Class.getNestMembers() returning hidden classes. Merely pointing out that it could return even weak hidden classes by not keeping them strongly reachable - just weakly. If getNestMembers() was specified to be dynamic, then returned members could come and go over time.

Sure, I understand, you are shaking out the alternatives.  My point is that it is about 100x more expensive
to support the dynamic view than the static view.

A second reason getNMs should not include hidden classes:  They are sometimes hidden for a reason that
is incompatible with making them discoverable by some sort of global enumeration.  Perhaps a HC holds
a secret that it provides to “those in the know” via a public interface (Supplier<MySecret>).  In such a case,
getting your hands on someone else’s HC might expose the secret.

> But a more concerning issue is what to do with a weak hidden class appointed to act as a nest host in a multi member nest. Such nest host can not simply be unloaded until all members can be.

This is a case of “Doctor, it hurts when I do X… Doctor: Then don’t do X.”

Users of hidden classes can choose whatever configuration they like.
One feature of the host-based nest design is that the nest host can be
as small as you like.  (We intentionally did *not* require that the NH be
the top-level package member containing all NMs.)  In the case of HCs,
the NH can be an empty holder who stays around as long as any of
his NMs are alive.  As an empty holder, the NH contributes a small
overhead to any of the remaining (non-empty) HCs in its nest.

That’s the right way to build an all-hidden nest, if you have doubts about
the overhead of “pinning” the NH.  Should we allow all-hidden nests?
Of course, for the same reason we should allow singleton non-nesting
HCs:  Sometimes you have to keep secrets that even the system dictionary
can’t see.  A singleton HC can quickly grow into a nest of all-hidden HCs
if it has code with a lambda expression.

— John

More information about the valhalla-dev mailing list