Draft JVMS changes for Nestmates
david.holmes at oracle.com
Thu Apr 20 03:56:51 UTC 2017
On 20/04/2017 7:58 AM, Dan Smith wrote:
>> On Apr 19, 2017, at 1:21 PM, Dan Smith <daniel.smith at oracle.com
>> <mailto:daniel.smith at oracle.com>> wrote:
>>> 5.4.4 Access Control
>>> I don't think you need to restate:
>>> "A class with a MemberOfNest attribute belongs to the nest hosted by
>>> the referenced host class.
>>> A class without a MemberOfNest attribute implicitly belongs to a nest
>>> hosted by the class itself. (If the class also lacks a NestMembers
>>> attribute, then the nest has only one member.)"
>>> The rule is simply stated as is: "belonging to the same nest as D" -
>>> belonging to the same nest is, or should be, already defined elsewhere.
>> My intent is that this *is* the definition. But sounds like you're
>> expecting that definition to be in 4.7.25/4.7.26, which is probably
>> more intuitive. I'll change that.
Thanks. Yes I was expecting a definition somewhere else, up front.
> Okay, here's another attempt at defining the attributes and the "nest"
> I've been uneasy about `NestMembers` being presented as the
> "declaration" of the nest, since it's not validated. Instead, I see
> `MemberOfNest` as really where nests are defined (as a cumulative result
> of many class declarations—like packages), and `NestMembers` as just a
> help for validation.
I can't decide whether that understates the importance of the
bi-directionality of membership, or not - both parties must agree on
membership for that membership to exist. It may not have any practical
> With that in mind, `MemberOfNest` ought to come first:
> **4.7.25 The `MemberOfNest` Attribute**
> **The `MemberOfNest` attribute is a fixed-length attribute in the
> `attributes` table of a `ClassFile` structure ([4.1]).**
> **A _nest_ is a set of classes and interfaces that share access to their
> `private` members ([5.4.4]).**
Aside: it is this basic definition of "nest" that I expected to appear
somewhere earlier in the spec. JVMS doesn't have any upfront "concepts
and definitions" section, so not sure where it would go.
> **A class or interface with a `MemberOfNest` attribute belongs to the
> nest hosted by a designated _host class_. The host class authorizes
> membership in the nest with a corresponding entry in its `NestMembers`
> attribute ([4.7.26], [4.10]).**
Only nit is I would say "claims membership of" rather than "belongs to".
That emphasises that membership must be ratified by the "host class",
and matches the following "authorizes membership" text.
> **A class or interface without a `MemberOfNest` attribute belongs to the
> nest hosted by itself. (Often, this nest is a singleton consisting only
> of the class itself.)**
> **There may be at most one `MemberOfNest` attribute in the `attributes`
> table of a `ClassFile` structure.**
> **The `MemberOfNest` attribute has the following format:**
> **4.7.26 The `NestMembers` Attribute**
> **The `NestMembers` attribute is a variable-length attribute in the
> `attributes` table of a `ClassFile` structure ([4.1]). It authorizes an
> enumerated set classes and interfaces to claim membership in a nest
> hosted by the current class or interface.**
> **There may be at most one `NestMembers` attribute in the `attributes`
> table of a `ClassFile` structure.**
> **The `attributes` table of a `ClassFile` structure must not contain
> both a `MemberOfNest` attribute and a `NestMembers` attribute.**
>> **This rule prevents a host class from claiming membership in a
> different nest. It is implicitly a member of the nest that it hosts.**
> **The `NestMembers` attribute has the following format:**
> 5.4.4 Access Control
> A class or interface _C_ is _accessible_ to a class or interface _D_ if
> and only if either of the following is true:
> - _R_ is `private` and is declared ~~in _D_~~ **by a class belonging to
> the same nest as _D_ ([4.7.25])**.
> And now to the bikeshedding game:
> `MemberOfNest`, as the key thing, could just be called `Nest` (imagine a
> `Package` attribute—we wouldn't call it `MemberOfPackage`). Or, since
> it's a reference to a class, `NestHost ` / `NestTop` / `NestMother` /
I like to distinguish the name of the attribute from the entity the
attribute represents. Given the names Maurizio chose are not terribly
wrong, and nothing else is significantly better, I'm quite content with
> `NestMembers` isn't horrible, but we could highlight its validation role
> with something like `AuthorizedNestMembers`.
To me the "authorized" is implicit. By calling it out explicitly it
suggests to me there are also UnauthorizedNestMembers. But to me this is
an oxymoron - if you are unauthorized you are not an
unauthorized-member, you are not any kind of member at all.
More information about the valhalla-spec-experts