Static value fields initialization
john.r.rose at oracle.com
Wed May 30 20:32:58 UTC 2018
On May 30, 2018, at 1:14 PM, Karen Kinnear <karen.kinnear at oracle.com> wrote:
> Very much like the direction of your proposal, which I summarize as:
> 1. preparation: continue no code execution
> VM determines default value via size information from loaded class
> (flattened fields are pre-loaded, so we have that information at preparation time)
> 2. pre-<clinit>: <clinit> of the containing class requires <clinit> for all entries
> in the ValueTypes attribute prior to completing its own <clinit>
Yes. Point 2 expands slightly to be "ensure VT.<clinit> before any bytecode
usage of VT."
> I think we could optimize this to pre-<clinit> for entries in the ValueTypes attribute that
> are referenced by local flattenable fields, static or instance.
> Specifically: we have entries in the ValueTypes attribute for:
> 1. local fields
> 2. local method signatures
> 3. remote fields
> 4. remote method signatures
> I think we only need the pre-<clinit> for #1
I agree, and would prefer this.
> 3. I think we also need to ensure that other bytecodes that can return a default value instance
> of a value type would also require <clinit> of the value type:
> defaultvalue, anewarray, multianewarray (JVMS draft 4d already includes defaultvalue, but not yet array bytecodes)
Good catch on defaultvalue (what I meant by "vdefault").
The array bytecodes *do* load the array element class, so we are close
already. The missing bit, I think, is to inspect the loaded array class,
see if it is a value type, and run <clinit> before creating the array.
This will require us to adjust our initialization barriers a little.
> Still exploring to see if there are any holes in these assumptions, appreciate additional eyes on this.
> So far so good.
I'm very glad you think so. In our experiments, I'd like to lift restrictions
on static field types sooner rather than later. (A workaround for Java
coders would be to define a private static inner class to hold the
problematic statics, but I'd rather not have this sharp edge.)
More information about the valhalla-spec-experts