1 /*
   2  * Copyright (c) 2020, 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 java.lang;
  27 
  28 /**
  29  * An inline class implements the {@code NonTearable} interface to
  30  * request that the JVM take extra care to avoid structure tearing
  31  * when loading or storing any value of the class to a field or array
  32  * element.  Normally, only fields declared {@code volatile} are
  33  * protected against structure tearing, but a class that implements
  34  * this marker interface will never have its values torn, even when
  35  * they are stored in array elements or in non-{@code volatile}
  36  * fields, and even when multiple threads perform racing writes.
  37  *
  38  * <p> An inline instance of multiple components is said to be "torn"
  39  * when two racing threads compete to update those components, and one
  40  * thread updates some components while another thread updates other
  41  * components.  The resulting inline value stored in the heap might be
  42  * a hybrid composed of field values from both racing writes.  In
  43  * extreme cases, this hybrid might be a value which is impossible
  44  * to construct by normal means, and if data integrity or security
  45  * depends on proper construction, the class should be declared as
  46  * implementing {@code NonTearable}.
  47  *
  48  * <p> Non-inline classes can implement {@code NonTearable}, and
  49  * interfaces can extend it, in the usual manner.  The special effect
  50  * on tearing applies to inline classes which implement this type,
  51  * either directly, or indirectly via a supertype.  Thus, it is not
  52  * correct to assume that an object {@code x} for which {@code x
  53  * instanceof NonTearable} is in fact an inline class instance.
  54  * It is also not correct to assume that tearing is possible for
  55  * classes which do not implement this marker interface, because
  56  * the JVM may elect to make some inline values non-tearable if
  57  * the cost of doing so is acceptable.  The effect of declaring
  58  * an inline type {@code NonTearable} is thus to override any
  59  * heuristic the JVM may employ to control tearing, in favor
  60  * of reliability, and possibly at the expense of performance.
  61  *
  62  * @author  John Rose
  63  * @since   (valhalla)
  64  */
  65 public interface NonTearable {
  66 }