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