Static value fields initialization

Frederic Parain frederic.parain at
Fri May 25 15:18:33 UTC 2018

The JVMS has to be modified to cover the initialization of
static value fields. However, the implications of the change
should be evaluated carefully before committing them.

The JVMS10, section 5.4.2 Preparation says:

"Preparation involves creating the static fields for a class or
interface and initializing such fields to their default values
(§2.3, §2.4). This does not require the execution of any Java
Virtual Machine code; explicit initializers for static fields are
executed as part of initialization (§5.5), not preparation.”

In the JVMS draft for Value types, section 2.4 Reference
Types and Values says:

"Value classes have a special value, called the default value,
which has all its instance variables set to their default value
according to their declaration (§4.5) and the initial default value
of each type (§2.3, §2.4). This default value for value classes is
a valid, fully initialized value. Any use of a default value of a value
type requires class initialization of the value class since a default
value is an instance and all instance bytecodes assume pre-initialization.
This is subject to the same exception all classes have, which is that
during <clinit> the initializing thread can create instances (including
default values) of themselves.”

Let’s consider the model for minimal L-world 1, where all value
fields are flattenable. Static value fields must be initialized to their
default value at preparation time, which implies the initialization
of their value class. Here’s the contradiction: the value class
initialization requires code execution, when previous statement
in the preparation specification says there’s no code execution.

How big would be the implications to allow code execution during
the preparation phase? Note that the code to be executed is not
the code of the class being prepared, but the code of the value
class used for one of its static fields. What could be consequences
on the current class life cycle if the initialization of the value class
fails to initialize?

Any though to help understanding this issue is welcome.

Thank you,


More information about the valhalla-spec-experts mailing list