jdk/src/java.base/share/classes/sun/misc/Contended.java
author lana
Mon, 30 Nov 2015 13:27:19 -0800
changeset 34353 162c793224d1
parent 25859 3317bb8137f4
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15336
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
     1
/*
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
     4
 *
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    10
 *
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    15
 * accompanied this code).
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    16
 *
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    20
 *
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    23
 * questions.
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    24
 */
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    25
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    26
package sun.misc;
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    27
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    28
import java.lang.annotation.ElementType;
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    29
import java.lang.annotation.Retention;
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    30
import java.lang.annotation.RetentionPolicy;
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    31
import java.lang.annotation.Target;
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    32
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    33
/**
17935
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    34
 * <p>An annotation expressing that objects and/or their fields are
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    35
 * expected to encounter memory contention, generally in the form of
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    36
 * "false sharing". This annotation serves as a hint that such objects
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    37
 * and fields should reside in locations isolated from those of other
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    38
 * objects or fields. Susceptibility to memory contention is a
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    39
 * property of the intended usages of objects and fields, not their
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    40
 * types or qualifiers. The effects of this annotation will nearly
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    41
 * always add significant space overhead to objects. The use of
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    42
 * {@code @Contended} is warranted only when the performance impact of
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    43
 * this time/space tradeoff is intrinsically worthwhile; for example,
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    44
 * in concurrent contexts in which each instance of the annotated
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    45
 * class is often accessed by a different thread.
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    46
 *
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    47
 * <p>A {@code @Contended} field annotation may optionally include a
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    48
 * <i>contention group</i> tag. A contention group defines a set of one
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    49
 * or more fields that collectively must be isolated from all other
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    50
 * contention groups. The fields in the same contention group may not be
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    51
 * pairwise isolated. With no contention group tag (or with the default
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    52
 * empty tag: "") each {@code @Contended} field resides in its own
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    53
 * <i>distinct</i> and <i>anonymous</i> contention group.
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    54
 *
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    55
 * <p>When the annotation is used at the class level, the effect is
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    56
 * equivalent to grouping all the declared fields not already having the
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    57
 * {@code @Contended} annotation into the same anonymous group.
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    58
 * With the class level annotation, implementations may choose different
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    59
 * isolation techniques, such as isolating the entire object, rather than
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    60
 * isolating distinct fields. A contention group tag has no meaning
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    61
 * in a class level {@code @Contended} annotation, and is ignored.
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    62
 *
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    63
 * <p>The class level {@code @Contended} annotation is not inherited and has
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    64
 * no effect on the fields declared in any sub-classes. The effects of all
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    65
 * {@code @Contended} annotations, however, remain in force for all
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    66
 * subclass instances, providing isolation of all the defined contention
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    67
 * groups. Contention group tags are not inherited, and the same tag used
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    68
 * in a superclass and subclass, represent distinct contention groups.
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    69
 *
15336
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    70
 * @since 1.8
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    71
 */
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    72
@Retention(RetentionPolicy.RUNTIME)
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    73
@Target({ElementType.FIELD, ElementType.TYPE})
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    74
public @interface Contended {
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    75
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    76
    /**
17935
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    77
     * The (optional) contention group tag.
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    78
     * This tag is only meaningful for field level annotations.
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    79
     *
58ede13b724e 8014966: Add the proper Javadoc to @Contended
shade
parents: 15336
diff changeset
    80
     * @return contention group tag.
15336
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    81
     */
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    82
    String value() default "";
c6790ea8d397 8006123: Support @Contended Annotation - JEP 142 (jdk part)
dl
parents:
diff changeset
    83
}