JDK-8001107 : @Stable annotation for constant folding of lazily evaluated variables
  • Type: New Feature
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 8-pool
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Fix Versions: hs25
  • Submitted: 2012-10-18
  • Updated: 2018-10-02
  • Resolved: 2013-09-11
Related Reports
Blocks :  
Relates :  
Relates :  
Relates :  
Description
For trusted code, we need a way to overcome the nominally mutable character of Java arrays, so that (where requested) their elements can be constant-folded.

Perhaps this can be eventually done as a heroic optimization without any user request, but for current problems (MethodHandle optimization) we need a simple, trusted annotation.

Draft Javadoc:

Internal marker for some methods in the JSR 292 implementation.
A field may be annotated as stable if all of its component variables
changes value at most once.
A field's value counts as its component value.
If the field is typed as an array, then all the non-null components
of the array, of depth up to the rank of the field's array type,
also count as component values.
By extension, any variable (either array or field) which has annotated
as stable is called a stable variable, and its non-null or non-zero
value is called a stable value.

Since all fields begin with a default value of null for references
(resp., zero for primitives), it follows that this annotation indicates
that the first non-null (resp., non-zero) value stored in the field
will never be changed.

If the field is not of an array type, there are no array elements,
then the value indicated as stable is simply the value of the field.
If the dynamic type of the field value is an array but the static type
is not, the components of the array are <em>not</em> regarded as stable.

If the field is an array type, then both the field value and
all the components of the field value (if the field value is non-null)
are indicated to be stable.
If the field type is an array type with rank {@code N &gt; 1},
then each component of the field value (if the field value is non-null),
is regarded as a stable array of rank {@code N-1}.

Fields which are declared {@code final} may also be annotated as stable.
Since final fields already behave as stable values, such an annotation
indicates no additional information, unless the type of the field is
an array type.

It is (currently) undefined what happens if a field annotated as stable
is given a third value.  In practice, if the JVM relies on this annotation
to promote a field reference to a constant, it may be that the Java memory
model would appear to be broken, if such a constant (the second value of the field)
is used as the value of the field even after the field value has changed.
Comments
noreg-hard: hotspot part of the change, no @Stable annotation present on jdk side
23-10-2013

http://hg.openjdk.java.net/mlvm/mlvm/jdk/file/tip/anno-stable-8001107.patch http://hg.openjdk.java.net/mlvm/mlvm/hotspot/file/tip/anno-stable-8001107.patch
18-10-2012