< prev index next >

src/java.base/share/classes/jdk/internal/misc/Unsafe.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2017, 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


3095     @ForceInline
3096     public final int getAndBitwiseOrIntAcquire(Object o, long offset, int mask) {
3097         int current;
3098         do {
3099             // Plain read, the value is a hint, the acquire CAS does the work
3100             current = getInt(o, offset);
3101         } while (!weakCompareAndSetIntAcquire(o, offset,
3102                                                current, current | mask));
3103         return current;
3104     }
3105 
3106     /**
3107      * Atomically replaces the current value of a field or array element within
3108      * the given object with the result of bitwise AND between the current value
3109      * and mask.
3110      *
3111      * @param o object/array to update the field/element in
3112      * @param offset field/element offset
3113      * @param mask the mask value
3114      * @return the previous value
3115      * @since 1.9
3116      */
3117     @ForceInline
3118     public final int getAndBitwiseAndInt(Object o, long offset, int mask) {
3119         int current;
3120         do {
3121             current = getIntVolatile(o, offset);
3122         } while (!weakCompareAndSetInt(o, offset,
3123                                                 current, current & mask));
3124         return current;
3125     }
3126 
3127     @ForceInline
3128     public final int getAndBitwiseAndIntRelease(Object o, long offset, int mask) {
3129         int current;
3130         do {
3131             current = getInt(o, offset);
3132         } while (!weakCompareAndSetIntRelease(o, offset,
3133                                                current, current & mask));
3134         return current;
3135     }


3321     public final void loadLoadFence() {
3322         loadFence();
3323     }
3324 
3325     /**
3326      * Ensures that stores before the fence will not be reordered with
3327      * stores after the fence.
3328      */
3329     public final void storeStoreFence() {
3330         storeFence();
3331     }
3332 
3333 
3334     /**
3335      * Throws IllegalAccessError; for use by the VM for access control
3336      * error support.
3337      * @since 1.8
3338      */
3339     private static void throwIllegalAccessError() {
3340         throw new IllegalAccessError();








3341     }
3342 
3343     /**
3344      * @return Returns true if the native byte ordering of this
3345      * platform is big-endian, false if it is little-endian.
3346      */
3347     public final boolean isBigEndian() { return BE; }
3348 
3349     /**
3350      * @return Returns true if this platform is capable of performing
3351      * accesses at addresses which are not aligned for the type of the
3352      * primitive type being accessed, false otherwise.
3353      */
3354     public final boolean unalignedAccess() { return unalignedAccess; }
3355 
3356     /**
3357      * Fetches a value at some byte offset into a given Java object.
3358      * More specifically, fetches a value within the given object
3359      * <code>o</code> at the given offset, or (if <code>o</code> is
3360      * null) from the memory address whose numerical value is the


   1 /*
   2  * Copyright (c) 2000, 2019, 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


3095     @ForceInline
3096     public final int getAndBitwiseOrIntAcquire(Object o, long offset, int mask) {
3097         int current;
3098         do {
3099             // Plain read, the value is a hint, the acquire CAS does the work
3100             current = getInt(o, offset);
3101         } while (!weakCompareAndSetIntAcquire(o, offset,
3102                                                current, current | mask));
3103         return current;
3104     }
3105 
3106     /**
3107      * Atomically replaces the current value of a field or array element within
3108      * the given object with the result of bitwise AND between the current value
3109      * and mask.
3110      *
3111      * @param o object/array to update the field/element in
3112      * @param offset field/element offset
3113      * @param mask the mask value
3114      * @return the previous value
3115      * @since 9
3116      */
3117     @ForceInline
3118     public final int getAndBitwiseAndInt(Object o, long offset, int mask) {
3119         int current;
3120         do {
3121             current = getIntVolatile(o, offset);
3122         } while (!weakCompareAndSetInt(o, offset,
3123                                                 current, current & mask));
3124         return current;
3125     }
3126 
3127     @ForceInline
3128     public final int getAndBitwiseAndIntRelease(Object o, long offset, int mask) {
3129         int current;
3130         do {
3131             current = getInt(o, offset);
3132         } while (!weakCompareAndSetIntRelease(o, offset,
3133                                                current, current & mask));
3134         return current;
3135     }


3321     public final void loadLoadFence() {
3322         loadFence();
3323     }
3324 
3325     /**
3326      * Ensures that stores before the fence will not be reordered with
3327      * stores after the fence.
3328      */
3329     public final void storeStoreFence() {
3330         storeFence();
3331     }
3332 
3333 
3334     /**
3335      * Throws IllegalAccessError; for use by the VM for access control
3336      * error support.
3337      * @since 1.8
3338      */
3339     private static void throwIllegalAccessError() {
3340         throw new IllegalAccessError();
3341     }
3342 
3343     /**
3344      * Throws NoSuchMethodError; for use by the VM for redefinition support.
3345      * @since 13
3346      */
3347     private static void throwNoSuchMethodError() {
3348         throw new NoSuchMethodError();
3349     }
3350 
3351     /**
3352      * @return Returns true if the native byte ordering of this
3353      * platform is big-endian, false if it is little-endian.
3354      */
3355     public final boolean isBigEndian() { return BE; }
3356 
3357     /**
3358      * @return Returns true if this platform is capable of performing
3359      * accesses at addresses which are not aligned for the type of the
3360      * primitive type being accessed, false otherwise.
3361      */
3362     public final boolean unalignedAccess() { return unalignedAccess; }
3363 
3364     /**
3365      * Fetches a value at some byte offset into a given Java object.
3366      * More specifically, fetches a value within the given object
3367      * <code>o</code> at the given offset, or (if <code>o</code> is
3368      * null) from the memory address whose numerical value is the


< prev index next >