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