Path: blob/master/src/java.base/share/classes/jdk/internal/vm/annotation/Contended.java
41161 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.internal.vm.annotation;2627import java.lang.annotation.ElementType;28import java.lang.annotation.Retention;29import java.lang.annotation.RetentionPolicy;30import java.lang.annotation.Target;3132/**33* <p>An annotation expressing that objects and/or their fields are34* expected to encounter memory contention, generally in the form of35* "false sharing". This annotation serves as a hint that such objects36* and fields should reside in locations isolated from those of other37* objects or fields. Susceptibility to memory contention is a38* property of the intended usages of objects and fields, not their39* types or qualifiers. The effects of this annotation will nearly40* always add significant space overhead to objects. The use of41* {@code @Contended} is warranted only when the performance impact of42* this time/space tradeoff is intrinsically worthwhile; for example,43* in concurrent contexts in which each instance of the annotated44* class is often accessed by a different thread.45*46* <p>A {@code @Contended} field annotation may optionally include a47* <i>contention group</i> tag. A contention group defines a set of one48* or more fields that collectively must be isolated from all other49* contention groups. The fields in the same contention group may not be50* pairwise isolated. With no contention group tag (or with the default51* empty tag: "") each {@code @Contended} field resides in its own52* <i>distinct</i> and <i>anonymous</i> contention group.53*54* <p>When the annotation is used at the class level, the effect is55* equivalent to grouping all the declared fields not already having the56* {@code @Contended} annotation into the same anonymous group.57* With the class level annotation, implementations may choose different58* isolation techniques, such as isolating the entire object, rather than59* isolating distinct fields. A contention group tag has no meaning60* in a class level {@code @Contended} annotation, and is ignored.61*62* <p>The class level {@code @Contended} annotation is not inherited and has63* no effect on the fields declared in any sub-classes. The effects of all64* {@code @Contended} annotations, however, remain in force for all65* subclass instances, providing isolation of all the defined contention66* groups. Contention group tags are not inherited, and the same tag used67* in a superclass and subclass, represent distinct contention groups.68*69* @since 1.870*/71@Retention(RetentionPolicy.RUNTIME)72@Target({ElementType.FIELD, ElementType.TYPE})73public @interface Contended {7475/**76* The (optional) contention group tag.77* This tag is only meaningful for field level annotations.78*79* @return contention group tag.80*/81String value() default "";82}838485