Path: blob/master/src/java.base/share/classes/jdk/internal/vm/annotation/Stable.java
41161 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.internal.vm.annotation;2627import java.lang.annotation.*;2829/**30* A field may be annotated as stable if all of its component variables31* changes value at most once.32* A field's value counts as its component value.33* If the field is typed as an array, then all the non-null components34* of the array, of depth up to the rank of the field's array type,35* also count as component values.36* By extension, any variable (either array or field) which has annotated37* as stable is called a stable variable, and its non-null or non-zero38* value is called a stable value.39* <p>40* Since all fields begin with a default value of null for references41* (resp., zero for primitives), it follows that this annotation indicates42* that the first non-null (resp., non-zero) value stored in the field43* will never be changed.44* <p>45* If the field is not of an array type, there are no array elements,46* then the value indicated as stable is simply the value of the field.47* If the dynamic type of the field value is an array but the static type48* is not, the components of the array are <em>not</em> regarded as stable.49* <p>50* If the field is an array type, then both the field value and51* all the components of the field value (if the field value is non-null)52* are indicated to be stable.53* If the field type is an array type with rank {@code N > 1},54* then each component of the field value (if the field value is non-null),55* is regarded as a stable array of rank {@code N-1}.56* <p>57* Fields which are declared {@code final} may also be annotated as stable.58* Since final fields already behave as stable values, such an annotation59* conveys no additional information regarding change of the field's value, but60* still conveys information regarding change of additional components values if61* the type of the field is an array type (as described above).62* <p>63* The HotSpot VM relies on this annotation to promote a non-null (resp.,64* non-zero) component value to a constant, thereby enabling superior65* optimizations of code depending on such a value (such as constant folding).66* More specifically, the HotSpot VM will process non-null stable fields (final67* or otherwise) in a similar manner to static final fields with respect to68* promoting the field's value to a constant. Thus, placing aside the69* differences for null/non-null values and arrays, a final stable field is70* treated as if it is really final from both the Java language and the HotSpot71* VM.72* <p>73* It is (currently) undefined what happens if a field annotated as stable74* is given a third value (by explicitly updating a stable field, a component of75* a stable array, or a final stable field via reflection or other means).76* Since the HotSpot VM promotes a non-null component value to constant, it may77* be that the Java memory model would appear to be broken, if such a constant78* (the second value of the field) is used as the value of the field even after79* the field value has changed (to a third value).80*81* @implNote82* This annotation only takes effect for fields of classes loaded by the boot83* loader. Annotations on fields of classes loaded outside of the boot loader84* are ignored.85*/86@Target(ElementType.FIELD)87@Retention(RetentionPolicy.RUNTIME)88public @interface Stable {89}909192