jdk/src/java.base/share/classes/sun/misc/Contended.java
changeset 34377 88b91bf5db89
parent 34353 162c793224d1
parent 34376 e90592286aa0
child 34378 129633be5db2
child 34518 b46a55b62834
child 34698 7e09aed69592
equal deleted inserted replaced
34353:162c793224d1 34377:88b91bf5db89
     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 sun.misc;
       
    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 /**
       
    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  *
       
    70  * @since 1.8
       
    71  */
       
    72 @Retention(RetentionPolicy.RUNTIME)
       
    73 @Target({ElementType.FIELD, ElementType.TYPE})
       
    74 public @interface Contended {
       
    75 
       
    76     /**
       
    77      * The (optional) contention group tag.
       
    78      * This tag is only meaningful for field level annotations.
       
    79      *
       
    80      * @return contention group tag.
       
    81      */
       
    82     String value() default "";
       
    83 }