1 /*
   2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.invoke;
  27 
  28 import java.lang.annotation.*;
  29 
  30 /**
  31  * A field may be annotated as stable if all of its component variables
  32  * changes value at most once.
  33  * A field's value counts as its component value.
  34  * If the field is typed as an array, then all the non-null components
  35  * of the array, of depth up to the rank of the field's array type,
  36  * also count as component values.
  37  * By extension, any variable (either array or field) which has annotated
  38  * as stable is called a stable variable, and its non-null or non-zero
  39  * value is called a stable value.
  40  * <p>
  41  * Since all fields begin with a default value of null for references
  42  * (resp., zero for primitives), it follows that this annotation indicates
  43  * that the first non-null (resp., non-zero) value stored in the field
  44  * will never be changed.
  45  * <p>
  46  * If the field is not of an array type, there are no array elements,
  47  * then the value indicated as stable is simply the value of the field.
  48  * If the dynamic type of the field value is an array but the static type
  49  * is not, the components of the array are <em>not</em> regarded as stable.
  50  * <p>
  51  * If the field is an array type, then both the field value and
  52  * all the components of the field value (if the field value is non-null)
  53  * are indicated to be stable.
  54  * If the field type is an array type with rank {@code N &gt; 1},
  55  * then each component of the field value (if the field value is non-null),
  56  * is regarded as a stable array of rank {@code N-1}.
  57  * <p>
  58  * Fields which are declared {@code final} may also be annotated as stable.
  59  * Since final fields already behave as stable values, such an annotation
  60  * indicates no additional information, unless the type of the field is
  61  * an array type.
  62  * <p>
  63  * It is (currently) undefined what happens if a field annotated as stable
  64  * is given a third value.  In practice, if the JVM relies on this annotation
  65  * to promote a field reference to a constant, it may be that the Java memory
  66  * model would appear to be broken, if such a constant (the second value of the field)
  67  * is used as the value of the field even after the field value has changed.
  68  */
  69 public
  70 @Target(ElementType.FIELD)
  71 @Retention(RetentionPolicy.RUNTIME)
  72 @interface Stable {
  73 }