< prev index next >

src/jdk.unsupported/share/classes/sun/misc/Unsafe.java

Print this page




  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 jdk.internal.vm.annotation.ForceInline;
  29 import jdk.internal.misc.VM;

  30 import jdk.internal.reflect.CallerSensitive;
  31 import jdk.internal.reflect.Reflection;

  32 
  33 import java.lang.reflect.Field;
  34 import java.security.ProtectionDomain;
  35 
  36 
  37 /**
  38  * A collection of methods for performing low-level, unsafe operations.
  39  * Although the class and all methods are public, use of this class is
  40  * limited because only trusted code can obtain instances of it.
  41  *
  42  * <em>Note:</em> It is the resposibility of the caller to make sure
  43  * arguments are checked before methods of this class are
  44  * called. While some rudimentary checks are performed on the input,
  45  * the checks are best effort and when performance is an overriding
  46  * priority, as when methods of this class are optimized by the
  47  * runtime compiler, some or all checks (if any) may be elided. Hence,
  48  * the caller must not rely on the checks and corresponding
  49  * exceptions!
  50  *
  51  * @author John R. Rose


1210      * provide a StoreStore barrier also provide a LoadStore barrier for free.
1211      * @since 1.8
1212      */
1213     @ForceInline
1214     public void storeFence() {
1215         theInternalUnsafe.storeFence();
1216     }
1217 
1218     /**
1219      * Ensures that loads and stores before the fence will not be reordered
1220      * with loads and stores after the fence.  Implies the effects of both
1221      * loadFence() and storeFence(), and in addition, the effect of a StoreLoad
1222      * barrier.
1223      *
1224      * Corresponds to C11 atomic_thread_fence(memory_order_seq_cst).
1225      * @since 1.8
1226      */
1227     @ForceInline
1228     public void fullFence() {
1229         theInternalUnsafe.fullFence();
























1230     }
1231 }


  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 jdk.internal.vm.annotation.ForceInline;
  29 import jdk.internal.misc.VM;
  30 import jdk.internal.ref.Cleaner;
  31 import jdk.internal.reflect.CallerSensitive;
  32 import jdk.internal.reflect.Reflection;
  33 import sun.nio.ch.DirectBuffer;
  34 
  35 import java.lang.reflect.Field;
  36 import java.security.ProtectionDomain;
  37 
  38 
  39 /**
  40  * A collection of methods for performing low-level, unsafe operations.
  41  * Although the class and all methods are public, use of this class is
  42  * limited because only trusted code can obtain instances of it.
  43  *
  44  * <em>Note:</em> It is the resposibility of the caller to make sure
  45  * arguments are checked before methods of this class are
  46  * called. While some rudimentary checks are performed on the input,
  47  * the checks are best effort and when performance is an overriding
  48  * priority, as when methods of this class are optimized by the
  49  * runtime compiler, some or all checks (if any) may be elided. Hence,
  50  * the caller must not rely on the checks and corresponding
  51  * exceptions!
  52  *
  53  * @author John R. Rose


1212      * provide a StoreStore barrier also provide a LoadStore barrier for free.
1213      * @since 1.8
1214      */
1215     @ForceInline
1216     public void storeFence() {
1217         theInternalUnsafe.storeFence();
1218     }
1219 
1220     /**
1221      * Ensures that loads and stores before the fence will not be reordered
1222      * with loads and stores after the fence.  Implies the effects of both
1223      * loadFence() and storeFence(), and in addition, the effect of a StoreLoad
1224      * barrier.
1225      *
1226      * Corresponds to C11 atomic_thread_fence(memory_order_seq_cst).
1227      * @since 1.8
1228      */
1229     @ForceInline
1230     public void fullFence() {
1231         theInternalUnsafe.fullFence();
1232     }
1233 
1234     /**
1235      * Invokes the given direct byte buffer's cleaner, if any.
1236      *
1237      * @param directBuffer a direct byte buffer
1238      * @throws NullPointerException if {@code directBuffer} is null
1239      * @throws IllegalArgumentException if {@code directBuffer} is non-direct,
1240      * or is a {@link java.nio.Buffer#slice slice}, or is a
1241      * {@link java.nio.Buffer#duplicate duplicate}
1242      * @since 9
1243      */
1244     public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
1245         if (!directBuffer.isDirect())
1246             throw new IllegalArgumentException("buffer is non-direct");
1247 
1248         DirectBuffer db = (DirectBuffer)directBuffer;
1249         if (db.attachment() != null)
1250             throw new IllegalArgumentException("duplicate or slice");
1251 
1252         Cleaner cleaner = db.cleaner();
1253         if (cleaner != null) {
1254             cleaner.clean();
1255         }
1256     }
1257 }
< prev index next >