--- /dev/null 2020-02-21 02:15:00.278539000 -0800 +++ new/src/java.base/share/classes/java/lang/NonTearable.java 2020-02-21 02:14:59.674881938 -0800 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + +/** + * An inline class implements the {@code NonTearable} interface to + * request that the JVM take extra care to avoid structure tearing + * when loading or storing any value of the class to a field or array + * element. Normally, only fields declared {@code volatile} are + * protected against structure tearing, but a class that implements + * this marker interface will never have its values torn, even when + * they are stored in array elements or in non-{@code volatile} + * fields, and even when multiple threads perform racing writes. + * + *

An inline instance of multiple components is said to be "torn" + * when two racing threads compete to update those components, and one + * thread updates some components while another thread updates other + * components. The resulting inline value stored in the heap might be + * a hybrid composed of field values from both racing writes. In + * extreme cases, this hybrid might be a value which is impossible + * to construct by normal means, and if data integrity or security + * depends on proper construction, the class should be declared as + * implementing {@code NonTearable}. + * + *

Non-inline classes can implement {@code NonTearable}, and + * interfaces can extend it, in the usual manner. The special effect + * on tearing applies to inline classes which implement this type, + * either directly, or indirectly via a supertype. Thus, it is not + * correct to assume that an object {@code x} for which {@code x + * instanceof NonTearable} is in fact an inline class instance. + * It is also not correct to assume that tearing is possible for + * classes which do not implement this marker interface, because + * the JVM may elect to make some inline values non-tearable if + * the cost of doing so is acceptable. The effect of declaring + * an inline type {@code NonTearable} is thus to override any + * heuristic the JVM may employ to control tearing, in favor + * of reliability, and possibly at the expense of performance. + * + * @author John Rose + * @since (valhalla) + */ +public interface NonTearable { +}