1 /*
2  * Copyright (c) 2013, 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 jdk.internal.vm.annotation;
27 
28 import java.lang.annotation.ElementType;
29 import java.lang.annotation.Retention;
30 import java.lang.annotation.RetentionPolicy;
31 import java.lang.annotation.Target;
32 
33 // Android-note: Contended-specific implementation notes not relevant for Android.
34 /**
35  * <p>An annotation expressing that objects and/or their fields are
36  * expected to encounter memory contention, generally in the form of
37  * "false sharing". This annotation serves as a hint that such objects
38  * and fields should reside in locations isolated from those of other
39  * objects or fields. Susceptibility to memory contention is a
40  * property of the intended usages of objects and fields, not their
41  * types or qualifiers. The effects of this annotation will nearly
42  * always add significant space overhead to objects. The use of
43  * {@code @Contended} is warranted only when the performance impact of
44  * this time/space tradeoff is intrinsically worthwhile; for example,
45  * in concurrent contexts in which each instance of the annotated
46  * class is often accessed by a different thread.
47  *
48  * <p>A {@code @Contended} field annotation may optionally include a
49  * <i>contention group</i> tag. A contention group defines a set of one
50  * or more fields that collectively must be isolated from all other
51  * contention groups. The fields in the same contention group may not be
52  * pairwise isolated. With no contention group tag (or with the default
53  * empty tag: "") each {@code @Contended} field resides in its own
54  * <i>distinct</i> and <i>anonymous</i> contention group.
55  *
56  * <p>When the annotation is used at the class level, the effect is
57  * equivalent to grouping all the declared fields not already having the
58  * {@code @Contended} annotation into the same anonymous group.
59  * With the class level annotation, implementations may choose different
60  * isolation techniques, such as isolating the entire object, rather than
61  * isolating distinct fields. A contention group tag has no meaning
62  * in a class level {@code @Contended} annotation, and is ignored.
63  *
64  * <p>The class level {@code @Contended} annotation is not inherited and has
65  * no effect on the fields declared in any sub-classes. The effects of all
66  * {@code @Contended} annotations, however, remain in force for all
67  * subclass instances, providing isolation of all the defined contention
68  * groups. Contention group tags are not inherited, and the same tag used
69  * in a superclass and subclass, represent distinct contention groups.
70  *
71  * @since 1.8
72  */
73 // Android-changed: RetentionPolicy.SOURCE is sufficient as this is no-op on Android.
74 // @Retention(RetentionPolicy.RUNTIME)
75 @Retention(RetentionPolicy.SOURCE)
76 @Target({ElementType.FIELD, ElementType.TYPE})
77 public @interface Contended {
78 
79     /**
80      * The (optional) contention group tag.
81      * This tag is only meaningful for field level annotations.
82      *
83      * @return contention group tag.
84      */
value()85     String value() default "";
86 }
87