JVMS updates as well

John Rose john.r.rose at oracle.com
Wed Aug 31 15:49:03 UTC 2022


> http://cr.openjdk.java.net/~dlsmith/jep8277163/latest

I edited the URL to find the corresponding JVMS updates:

http://cr.openjdk.java.net/~dlsmith/jep8277163/jep8277163-20220830/specs/value-objects-jvms.html

I have a few unsystematic comments on the special subject of special 
methods.

In that draft JVMS, we say in 2.9.1
> An instance initialization method may not be declared in a value class 
> or an interface (4.6).

and in 2.9.4
> A value class instance creation method may not be declared in an 
> identity class, an abstract class, or an interface (4.6).

Then in 4.6 we reaffirm these restrictions on `<init>` and `<vnew>`, 
along with many similar pre-existing restrictions.  These are 
restrictions on *declaration* of special methods.

Then in 4.9.1 we have similar static constraints on *uses* of special 
methods, by bytecodes.  Such constraints also appear on constants in the 
constant pool, in 4.4.8.

Eventually in 5.3.5 we discover when and what we must throw if any of 
these conditions fail:
> If the purported representation is not a ClassFile structure (§4.1, 
> §4.8), loading throws an instance of ClassFormatError.

IIRC somewhere there is a place in chapter 4 that tells us that all of 
the many requirements will be enforced.  I don’t remember where that 
promise is made.  (Remind me?)

The phrases “instance initialization method ” and “value class 
instance creation method” are accompanied by  cross references to 
2.9.1 and 2.9.4.  I’m starting to think that the cross references 
should *also* mention the special method names `<init>` and `<vnew>`.  
That would be a new thing for the JVMS but makes more are more sense as 
we add more and more special method names.  Now we are at three such 
names; maybe it’s time to mention the names along with the cross 
references.  I think I should be able to grep the JVMS for `<vnew>` for 
mentions of this feature, not just the phrase “value class instance 
creation method” or the section number 2.9.4.  For example:

> Only the invokestatic instruction is allowed to invoke a value class 
> instance creation method (2.9.4 `<vnew>`).

At some time we will want to change JVMS language that says things like 
“not `<clinit>`, `<new>`, or `<vnew>`” to “not a special method 
name”.  Is that time now yet?  Places that allow some but not all 
would have to say “not a special method name other than `<clinit>`” 
or something of that nature.  I think that would expose some 
irregularities in our treatment of “surprising” names, but that’s 
all to the good, even if embarrassing.

You have this commentary:
> As an alternative naming scheme, we could re-use <init> but give the 
> method a non-void return type.

You could also say something like:
> An alternative implementation technique could use regular static 
> methods (presumably marked with a `Synthetic` attribute) of a standard 
> name to implement constructors of value classes.  This would be 
> convenient for some tools in that they could treat these factory 
> methods like all other factory methods, without learning the new rules 
> for `<vnew>` symbols, but would be inconvenient for other tools, 
> including the JVM, which need to make a clear distinction between 
> constructors and other methods.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-spec-observers/attachments/20220831/5b6a07c3/attachment.htm>


More information about the valhalla-spec-observers mailing list