defaultvalue and enclosing instances

Srikanth srikanth.adayapalam at oracle.com
Fri Sep 14 06:32:13 UTC 2018


The section on defaultvalue opcode in the draft JVMS reads:

"The defaultvalue instruction does provide a completely initialized 
instance; known as the
default value of the value class."

This raises the question, if the value type happens to be an inner 
class, what is its enclosing instance field initialized to ?

If the source code used the canonical constructor notation (CCN), this 
will automatically be taken care of:
the call to new InnerValue() would have supplied an explicit/implicit 
enclosing instance of suitable type.

If the source code uses the recently introduced syntax (JDK-8207168 - 
which is really a cleaned up version of the older __MakeDefault VT() 
syntax) viz:

         InnerValue iv = InnerValue.default;

this gets lowered into the defaultvalue opcode which would not have any 
proper enclosing instance (and so will not be a "completely initialized 
instance")

So what do we do ?

Some options seem to be: (a) disallow InnerValue.default syntax if 
InnerValue is a nonstatic nested class and mandate that instances of 
such be created using CCN (b) allow InnerValue.default only where an 
implicit instance is available and somehow arrange for the proper 
initialization of the enclosing instance (c) Allow for explicit 
enclosing instance to be specified in the syntax itself and somehow 
arrange for the proper initialization of the enclosing instance ... (d) 
other solutions ...

Thanks in advance for comments.
Srikanth




More information about the valhalla-dev mailing list