src/java.base/share/classes/jdk/internal/misc/Unsafe.java
author mchung
Mon, 22 Oct 2018 17:00:04 -0700
changeset 52220 9c260a6b6471
parent 47866 39db80b32b69
child 52306 3a767a000aab
permissions -rw-r--r--
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference Reviewed-by: dholmes, thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
     1
/*
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
     2
 * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
     4
 *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    10
 *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    15
 * accompanied this code).
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    16
 *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    20
 *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    23
 * questions.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    24
 */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    25
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    26
package jdk.internal.misc;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    27
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
    28
import jdk.internal.HotSpotIntrinsicCandidate;
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
    29
import jdk.internal.vm.annotation.ForceInline;
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    30
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
    31
import java.lang.reflect.Field;
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
    32
import java.security.ProtectionDomain;
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    33
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    34
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    35
/**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    36
 * A collection of methods for performing low-level, unsafe operations.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    37
 * Although the class and all methods are public, use of this class is
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    38
 * limited because only trusted code can obtain instances of it.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    39
 *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
    40
 * <em>Note:</em> It is the resposibility of the caller to make sure
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
    41
 * arguments are checked before methods of this class are
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
    42
 * called. While some rudimentary checks are performed on the input,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
    43
 * the checks are best effort and when performance is an overriding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
    44
 * priority, as when methods of this class are optimized by the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
    45
 * runtime compiler, some or all checks (if any) may be elided. Hence,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
    46
 * the caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
    47
 * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
    48
 *
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    49
 * @author John R. Rose
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    50
 * @see #getUnsafe
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    51
 */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    52
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    53
public final class Unsafe {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    54
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    55
    private static native void registerNatives();
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    56
    static {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    57
        registerNatives();
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    58
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    59
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    60
    private Unsafe() {}
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    61
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    62
    private static final Unsafe theUnsafe = new Unsafe();
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    63
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    64
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    65
     * Provides the caller with the capability of performing unsafe
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    66
     * operations.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    67
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    68
     * <p>The returned {@code Unsafe} object should be carefully guarded
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    69
     * by the caller, since it can be used to read and write data at arbitrary
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    70
     * memory addresses.  It must never be passed to untrusted code.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    71
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    72
     * <p>Most methods in this class are very low-level, and correspond to a
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    73
     * small number of hardware instructions (on typical machines).  Compilers
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    74
     * are encouraged to optimize these methods accordingly.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    75
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    76
     * <p>Here is a suggested idiom for using unsafe operations:
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    77
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    78
     * <pre> {@code
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    79
     * class MyTrustedClass {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    80
     *   private static final Unsafe unsafe = Unsafe.getUnsafe();
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    81
     *   ...
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    82
     *   private long myCountAddress = ...;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    83
     *   public int getCount() { return unsafe.getByte(myCountAddress); }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    84
     * }}</pre>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    85
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    86
     * (It may assist compilers to make the local variable {@code final}.)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    87
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    88
    public static Unsafe getUnsafe() {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    89
        return theUnsafe;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    90
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    91
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    92
    /// peek and poke operations
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    93
    /// (compilers should optimize these to memory ops)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    94
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    95
    // These work on object fields in the Java heap.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    96
    // They will not work on elements of packed arrays.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    97
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    98
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
    99
     * Fetches a value from a given Java variable.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   100
     * More specifically, fetches a field or array element within the given
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   101
     * object {@code o} at the given offset, or (if {@code o} is null)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   102
     * from the memory address whose numerical value is the given offset.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   103
     * <p>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   104
     * The results are undefined unless one of the following cases is true:
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   105
     * <ul>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   106
     * <li>The offset was obtained from {@link #objectFieldOffset} on
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   107
     * the {@link java.lang.reflect.Field} of some Java field and the object
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   108
     * referred to by {@code o} is of a class compatible with that
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   109
     * field's class.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   110
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   111
     * <li>The offset and object reference {@code o} (either null or
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   112
     * non-null) were both obtained via {@link #staticFieldOffset}
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   113
     * and {@link #staticFieldBase} (respectively) from the
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   114
     * reflective {@link Field} representation of some Java field.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   115
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   116
     * <li>The object referred to by {@code o} is an array, and the offset
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   117
     * is an integer of the form {@code B+N*S}, where {@code N} is
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   118
     * a valid index into the array, and {@code B} and {@code S} are
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   119
     * the values obtained by {@link #arrayBaseOffset} and {@link
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   120
     * #arrayIndexScale} (respectively) from the array's class.  The value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   121
     * referred to is the {@code N}<em>th</em> element of the array.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   122
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   123
     * </ul>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   124
     * <p>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   125
     * If one of the above cases is true, the call references a specific Java
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   126
     * variable (field or array element).  However, the results are undefined
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   127
     * if that variable is not in fact of the type returned by this method.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   128
     * <p>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   129
     * This method refers to a variable by means of two parameters, and so
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   130
     * it provides (in effect) a <em>double-register</em> addressing mode
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   131
     * for Java variables.  When the object reference is null, this method
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   132
     * uses its offset as an absolute address.  This is similar in operation
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   133
     * to methods such as {@link #getInt(long)}, which provide (in effect) a
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   134
     * <em>single-register</em> addressing mode for non-Java variables.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   135
     * However, because Java variables may have a different layout in memory
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   136
     * from non-Java variables, programmers should not assume that these
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   137
     * two addressing modes are ever equivalent.  Also, programmers should
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   138
     * remember that offsets from the double-register addressing mode cannot
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   139
     * be portably confused with longs used in the single-register addressing
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   140
     * mode.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   141
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   142
     * @param o Java heap object in which the variable resides, if any, else
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   143
     *        null
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   144
     * @param offset indication of where the variable resides in a Java heap
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   145
     *        object, if any, else a memory address locating the variable
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   146
     *        statically
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   147
     * @return the value fetched from the indicated Java variable
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   148
     * @throws RuntimeException No defined exceptions are thrown, not even
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   149
     *         {@link NullPointerException}
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   150
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   151
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   152
    public native int getInt(Object o, long offset);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   153
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   154
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   155
     * Stores a value into a given Java variable.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   156
     * <p>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   157
     * The first two parameters are interpreted exactly as with
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   158
     * {@link #getInt(Object, long)} to refer to a specific
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   159
     * Java variable (field or array element).  The given value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   160
     * is stored into that variable.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   161
     * <p>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   162
     * The variable must be of the same type as the method
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   163
     * parameter {@code x}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   164
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   165
     * @param o Java heap object in which the variable resides, if any, else
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   166
     *        null
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   167
     * @param offset indication of where the variable resides in a Java heap
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   168
     *        object, if any, else a memory address locating the variable
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   169
     *        statically
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   170
     * @param x the value to store into the indicated Java variable
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   171
     * @throws RuntimeException No defined exceptions are thrown, not even
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   172
     *         {@link NullPointerException}
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   173
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   174
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   175
    public native void putInt(Object o, long offset, int x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   176
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   177
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   178
     * Fetches a reference value from a given Java variable.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   179
     * @see #getInt(Object, long)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   180
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   181
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
   182
    public native Object getReference(Object o, long offset);
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   183
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   184
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   185
     * Stores a reference value into a given Java variable.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   186
     * <p>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   187
     * Unless the reference {@code x} being stored is either null
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   188
     * or matches the field type, the results are undefined.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   189
     * If the reference {@code o} is non-null, card marks or
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   190
     * other store barriers for that object (if the VM requires them)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   191
     * are updated.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   192
     * @see #putInt(Object, long, int)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   193
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   194
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
   195
    public native void putReference(Object o, long offset, Object x);
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   196
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   197
    /** @see #getInt(Object, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   198
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   199
    public native boolean getBoolean(Object o, long offset);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   200
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   201
    /** @see #putInt(Object, long, int) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   202
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   203
    public native void    putBoolean(Object o, long offset, boolean x);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   204
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   205
    /** @see #getInt(Object, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   206
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   207
    public native byte    getByte(Object o, long offset);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   208
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   209
    /** @see #putInt(Object, long, int) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   210
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   211
    public native void    putByte(Object o, long offset, byte x);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   212
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   213
    /** @see #getInt(Object, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   214
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   215
    public native short   getShort(Object o, long offset);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   216
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   217
    /** @see #putInt(Object, long, int) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   218
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   219
    public native void    putShort(Object o, long offset, short x);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   220
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   221
    /** @see #getInt(Object, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   222
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   223
    public native char    getChar(Object o, long offset);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   224
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   225
    /** @see #putInt(Object, long, int) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   226
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   227
    public native void    putChar(Object o, long offset, char x);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   228
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   229
    /** @see #getInt(Object, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   230
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   231
    public native long    getLong(Object o, long offset);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   232
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   233
    /** @see #putInt(Object, long, int) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   234
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   235
    public native void    putLong(Object o, long offset, long x);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   236
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   237
    /** @see #getInt(Object, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   238
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   239
    public native float   getFloat(Object o, long offset);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   240
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   241
    /** @see #putInt(Object, long, int) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   242
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   243
    public native void    putFloat(Object o, long offset, float x);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   244
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   245
    /** @see #getInt(Object, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   246
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   247
    public native double  getDouble(Object o, long offset);
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   248
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   249
    /** @see #putInt(Object, long, int) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   250
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   251
    public native void    putDouble(Object o, long offset, double x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   252
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   253
    /**
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   254
     * Fetches a native pointer from a given memory address.  If the address is
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   255
     * zero, or does not point into a block obtained from {@link
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   256
     * #allocateMemory}, the results are undefined.
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   257
     *
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   258
     * <p>If the native pointer is less than 64 bits wide, it is extended as
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   259
     * an unsigned number to a Java long.  The pointer may be indexed by any
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   260
     * given byte offset, simply by adding that offset (as a simple integer) to
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   261
     * the long representing the pointer.  The number of bytes actually read
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   262
     * from the target address may be determined by consulting {@link
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   263
     * #addressSize}.
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   264
     *
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   265
     * @see #allocateMemory
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   266
     * @see #getInt(Object, long)
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   267
     */
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   268
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   269
    public long getAddress(Object o, long offset) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   270
        if (ADDRESS_SIZE == 4) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   271
            return Integer.toUnsignedLong(getInt(o, offset));
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   272
        } else {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   273
            return getLong(o, offset);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   274
        }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   275
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   276
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   277
    /**
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   278
     * Stores a native pointer into a given memory address.  If the address is
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   279
     * zero, or does not point into a block obtained from {@link
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   280
     * #allocateMemory}, the results are undefined.
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   281
     *
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   282
     * <p>The number of bytes actually written at the target address may be
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   283
     * determined by consulting {@link #addressSize}.
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   284
     *
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   285
     * @see #allocateMemory
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   286
     * @see #putInt(Object, long, int)
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   287
     */
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   288
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   289
    public void putAddress(Object o, long offset, long x) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   290
        if (ADDRESS_SIZE == 4) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   291
            putInt(o, offset, (int)x);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   292
        } else {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   293
            putLong(o, offset, x);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   294
        }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   295
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   296
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   297
    // These read VM internal data.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   298
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   299
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   300
     * Fetches an uncompressed reference value from a given native variable
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   301
     * ignoring the VM's compressed references mode.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   302
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   303
     * @param address a memory address locating the variable
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   304
     * @return the value fetched from the indicated native variable
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   305
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   306
    public native Object getUncompressedObject(long address);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   307
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   308
    // These work on values in the C heap.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   309
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   310
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   311
     * Fetches a value from a given memory address.  If the address is zero, or
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   312
     * does not point into a block obtained from {@link #allocateMemory}, the
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   313
     * results are undefined.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   314
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   315
     * @see #allocateMemory
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   316
     */
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   317
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   318
    public byte getByte(long address) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   319
        return getByte(null, address);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   320
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   321
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   322
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   323
     * Stores a value into a given memory address.  If the address is zero, or
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   324
     * does not point into a block obtained from {@link #allocateMemory}, the
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   325
     * results are undefined.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   326
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   327
     * @see #getByte(long)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   328
     */
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   329
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   330
    public void putByte(long address, byte x) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   331
        putByte(null, address, x);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   332
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   333
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   334
    /** @see #getByte(long) */
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   335
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   336
    public short getShort(long address) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   337
        return getShort(null, address);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   338
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   339
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   340
    /** @see #putByte(long, byte) */
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   341
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   342
    public void putShort(long address, short x) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   343
        putShort(null, address, x);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   344
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   345
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   346
    /** @see #getByte(long) */
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   347
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   348
    public char getChar(long address) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   349
        return getChar(null, address);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   350
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   352
    /** @see #putByte(long, byte) */
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   353
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   354
    public void putChar(long address, char x) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   355
        putChar(null, address, x);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   356
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   357
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   358
    /** @see #getByte(long) */
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   359
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   360
    public int getInt(long address) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   361
        return getInt(null, address);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   362
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   363
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   364
    /** @see #putByte(long, byte) */
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   365
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   366
    public void putInt(long address, int x) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   367
        putInt(null, address, x);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   368
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   369
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   370
    /** @see #getByte(long) */
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   371
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   372
    public long getLong(long address) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   373
        return getLong(null, address);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   374
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   375
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   376
    /** @see #putByte(long, byte) */
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   377
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   378
    public void putLong(long address, long x) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   379
        putLong(null, address, x);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   380
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   381
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   382
    /** @see #getByte(long) */
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   383
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   384
    public float getFloat(long address) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   385
        return getFloat(null, address);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   386
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   387
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   388
    /** @see #putByte(long, byte) */
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   389
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   390
    public void putFloat(long address, float x) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   391
        putFloat(null, address, x);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   392
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   393
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   394
    /** @see #getByte(long) */
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   395
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   396
    public double getDouble(long address) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   397
        return getDouble(null, address);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   398
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   399
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   400
    /** @see #putByte(long, byte) */
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   401
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   402
    public void putDouble(long address, double x) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   403
        putDouble(null, address, x);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   404
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   405
38351
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   406
    /** @see #getAddress(Object, long) */
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   407
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   408
    public long getAddress(long address) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   409
        return getAddress(null, address);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   410
    }
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   411
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   412
    /** @see #putAddress(Object, long, long) */
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   413
    @ForceInline
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   414
    public void putAddress(long address, long x) {
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   415
        putAddress(null, address, x);
20093694985b 8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents: 37363
diff changeset
   416
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   417
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   418
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   419
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   420
    /// helper methods for validating various types of objects/values
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   421
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   422
    /**
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   423
     * Create an exception reflecting that some of the input was invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   424
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   425
     * <em>Note:</em> It is the resposibility of the caller to make
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   426
     * sure arguments are checked before the methods are called. While
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   427
     * some rudimentary checks are performed on the input, the checks
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   428
     * are best effort and when performance is an overriding priority,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   429
     * as when methods of this class are optimized by the runtime
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   430
     * compiler, some or all checks (if any) may be elided. Hence, the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   431
     * caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   432
     * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   433
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   434
     * @return an exception object
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   435
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   436
    private RuntimeException invalidInput() {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   437
        return new IllegalArgumentException();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   438
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   439
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   440
    /**
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   441
     * Check if a value is 32-bit clean (32 MSB are all zero)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   442
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   443
     * @param value the 64-bit value to check
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   444
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   445
     * @return true if the value is 32-bit clean
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   446
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   447
    private boolean is32BitClean(long value) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   448
        return value >>> 32 == 0;
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   449
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   450
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   451
    /**
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   452
     * Check the validity of a size (the equivalent of a size_t)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   453
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   454
     * @throws RuntimeException if the size is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   455
     *         (<em>Note:</em> after optimization, invalid inputs may
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   456
     *         go undetected, which will lead to unpredictable
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   457
     *         behavior)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   458
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   459
    private void checkSize(long size) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   460
        if (ADDRESS_SIZE == 4) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   461
            // Note: this will also check for negative sizes
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   462
            if (!is32BitClean(size)) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   463
                throw invalidInput();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   464
            }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   465
        } else if (size < 0) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   466
            throw invalidInput();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   467
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   468
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   469
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   470
    /**
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   471
     * Check the validity of a native address (the equivalent of void*)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   472
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   473
     * @throws RuntimeException if the address is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   474
     *         (<em>Note:</em> after optimization, invalid inputs may
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   475
     *         go undetected, which will lead to unpredictable
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   476
     *         behavior)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   477
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   478
    private void checkNativeAddress(long address) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   479
        if (ADDRESS_SIZE == 4) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   480
            // Accept both zero and sign extended pointers. A valid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   481
            // pointer will, after the +1 below, either have produced
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   482
            // the value 0x0 or 0x1. Masking off the low bit allows
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   483
            // for testing against 0.
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   484
            if ((((address >> 32) + 1) & ~1) != 0) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   485
                throw invalidInput();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   486
            }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   487
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   488
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   489
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   490
    /**
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   491
     * Check the validity of an offset, relative to a base object
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   492
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   493
     * @param o the base object
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   494
     * @param offset the offset to check
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   495
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   496
     * @throws RuntimeException if the size is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   497
     *         (<em>Note:</em> after optimization, invalid inputs may
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   498
     *         go undetected, which will lead to unpredictable
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   499
     *         behavior)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   500
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   501
    private void checkOffset(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   502
        if (ADDRESS_SIZE == 4) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   503
            // Note: this will also check for negative offsets
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   504
            if (!is32BitClean(offset)) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   505
                throw invalidInput();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   506
            }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   507
        } else if (offset < 0) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   508
            throw invalidInput();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   509
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   510
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   511
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   512
    /**
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   513
     * Check the validity of a double-register pointer
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   514
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   515
     * Note: This code deliberately does *not* check for NPE for (at
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   516
     * least) three reasons:
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   517
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   518
     * 1) NPE is not just NULL/0 - there is a range of values all
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   519
     * resulting in an NPE, which is not trivial to check for
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   520
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   521
     * 2) It is the responsibility of the callers of Unsafe methods
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   522
     * to verify the input, so throwing an exception here is not really
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   523
     * useful - passing in a NULL pointer is a critical error and the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   524
     * must not expect an exception to be thrown anyway.
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   525
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   526
     * 3) the actual operations will detect NULL pointers anyway by
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   527
     * means of traps and signals (like SIGSEGV).
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   528
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   529
     * @param o Java heap object, or null
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   530
     * @param offset indication of where the variable resides in a Java heap
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   531
     *        object, if any, else a memory address locating the variable
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   532
     *        statically
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   533
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   534
     * @throws RuntimeException if the pointer is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   535
     *         (<em>Note:</em> after optimization, invalid inputs may
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   536
     *         go undetected, which will lead to unpredictable
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   537
     *         behavior)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   538
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   539
    private void checkPointer(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   540
        if (o == null) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   541
            checkNativeAddress(offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   542
        } else {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   543
            checkOffset(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   544
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   545
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   546
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   547
    /**
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   548
     * Check if a type is a primitive array type
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   549
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   550
     * @param c the type to check
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   551
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   552
     * @return true if the type is a primitive array type
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   553
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   554
    private void checkPrimitiveArray(Class<?> c) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   555
        Class<?> componentType = c.getComponentType();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   556
        if (componentType == null || !componentType.isPrimitive()) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   557
            throw invalidInput();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   558
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   559
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   560
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   561
    /**
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   562
     * Check that a pointer is a valid primitive array type pointer
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   563
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   564
     * Note: pointers off-heap are considered to be primitive arrays
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   565
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   566
     * @throws RuntimeException if the pointer is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   567
     *         (<em>Note:</em> after optimization, invalid inputs may
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   568
     *         go undetected, which will lead to unpredictable
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   569
     *         behavior)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   570
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   571
    private void checkPrimitivePointer(Object o, long offset) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   572
        checkPointer(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   573
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   574
        if (o != null) {
47866
39db80b32b69 8191632: Typos in comments due to duplicating words
igerasim
parents: 47216
diff changeset
   575
            // If on heap, it must be a primitive array
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   576
            checkPrimitiveArray(o.getClass());
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   577
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   578
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   579
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   580
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   581
    /// wrappers for malloc, realloc, free:
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   582
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   583
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   584
     * Allocates a new block of native memory, of the given size in bytes.  The
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   585
     * contents of the memory are uninitialized; they will generally be
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   586
     * garbage.  The resulting native pointer will never be zero, and will be
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   587
     * aligned for all value types.  Dispose of this memory by calling {@link
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   588
     * #freeMemory}, or resize it with {@link #reallocateMemory}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   589
     *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   590
     * <em>Note:</em> It is the resposibility of the caller to make
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   591
     * sure arguments are checked before the methods are called. While
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   592
     * some rudimentary checks are performed on the input, the checks
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   593
     * are best effort and when performance is an overriding priority,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   594
     * as when methods of this class are optimized by the runtime
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   595
     * compiler, some or all checks (if any) may be elided. Hence, the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   596
     * caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   597
     * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   598
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   599
     * @throws RuntimeException if the size is negative or too large
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   600
     *         for the native size_t type
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   601
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   602
     * @throws OutOfMemoryError if the allocation is refused by the system
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   603
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   604
     * @see #getByte(long)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   605
     * @see #putByte(long, byte)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   606
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   607
    public long allocateMemory(long bytes) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   608
        allocateMemoryChecks(bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   609
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   610
        if (bytes == 0) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   611
            return 0;
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   612
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   613
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   614
        long p = allocateMemory0(bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   615
        if (p == 0) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   616
            throw new OutOfMemoryError();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   617
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   618
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   619
        return p;
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   620
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   621
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   622
    /**
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   623
     * Validate the arguments to allocateMemory
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   624
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   625
     * @throws RuntimeException if the arguments are invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   626
     *         (<em>Note:</em> after optimization, invalid inputs may
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   627
     *         go undetected, which will lead to unpredictable
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   628
     *         behavior)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   629
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   630
    private void allocateMemoryChecks(long bytes) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   631
        checkSize(bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   632
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   633
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   634
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   635
     * Resizes a new block of native memory, to the given size in bytes.  The
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   636
     * contents of the new block past the size of the old block are
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   637
     * uninitialized; they will generally be garbage.  The resulting native
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   638
     * pointer will be zero if and only if the requested size is zero.  The
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   639
     * resulting native pointer will be aligned for all value types.  Dispose
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   640
     * of this memory by calling {@link #freeMemory}, or resize it with {@link
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   641
     * #reallocateMemory}.  The address passed to this method may be null, in
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   642
     * which case an allocation will be performed.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   643
     *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   644
     * <em>Note:</em> It is the resposibility of the caller to make
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   645
     * sure arguments are checked before the methods are called. While
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   646
     * some rudimentary checks are performed on the input, the checks
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   647
     * are best effort and when performance is an overriding priority,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   648
     * as when methods of this class are optimized by the runtime
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   649
     * compiler, some or all checks (if any) may be elided. Hence, the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   650
     * caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   651
     * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   652
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   653
     * @throws RuntimeException if the size is negative or too large
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   654
     *         for the native size_t type
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   655
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   656
     * @throws OutOfMemoryError if the allocation is refused by the system
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   657
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   658
     * @see #allocateMemory
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   659
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   660
    public long reallocateMemory(long address, long bytes) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   661
        reallocateMemoryChecks(address, bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   662
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   663
        if (bytes == 0) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   664
            freeMemory(address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   665
            return 0;
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   666
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   667
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   668
        long p = (address == 0) ? allocateMemory0(bytes) : reallocateMemory0(address, bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   669
        if (p == 0) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   670
            throw new OutOfMemoryError();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   671
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   672
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   673
        return p;
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   674
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   675
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   676
    /**
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   677
     * Validate the arguments to reallocateMemory
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   678
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   679
     * @throws RuntimeException if the arguments are invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   680
     *         (<em>Note:</em> after optimization, invalid inputs may
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   681
     *         go undetected, which will lead to unpredictable
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   682
     *         behavior)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   683
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   684
    private void reallocateMemoryChecks(long address, long bytes) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   685
        checkPointer(null, address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   686
        checkSize(bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   687
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   688
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   689
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   690
     * Sets all bytes in a given block of memory to a fixed value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   691
     * (usually zero).
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   692
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   693
     * <p>This method determines a block's base address by means of two parameters,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   694
     * and so it provides (in effect) a <em>double-register</em> addressing mode,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   695
     * as discussed in {@link #getInt(Object,long)}.  When the object reference is null,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   696
     * the offset supplies an absolute base address.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   697
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   698
     * <p>The stores are in coherent (atomic) units of a size determined
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   699
     * by the address and length parameters.  If the effective address and
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   700
     * length are all even modulo 8, the stores take place in 'long' units.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   701
     * If the effective address and length are (resp.) even modulo 4 or 2,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   702
     * the stores take place in units of 'int' or 'short'.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   703
     *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   704
     * <em>Note:</em> It is the resposibility of the caller to make
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   705
     * sure arguments are checked before the methods are called. While
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   706
     * some rudimentary checks are performed on the input, the checks
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   707
     * are best effort and when performance is an overriding priority,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   708
     * as when methods of this class are optimized by the runtime
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   709
     * compiler, some or all checks (if any) may be elided. Hence, the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   710
     * caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   711
     * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   712
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   713
     * @throws RuntimeException if any of the arguments is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   714
     *
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   715
     * @since 1.7
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   716
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   717
    public void setMemory(Object o, long offset, long bytes, byte value) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   718
        setMemoryChecks(o, offset, bytes, value);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   719
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   720
        if (bytes == 0) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   721
            return;
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   722
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   723
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   724
        setMemory0(o, offset, bytes, value);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   725
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   726
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   727
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   728
     * Sets all bytes in a given block of memory to a fixed value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   729
     * (usually zero).  This provides a <em>single-register</em> addressing mode,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   730
     * as discussed in {@link #getInt(Object,long)}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   731
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   732
     * <p>Equivalent to {@code setMemory(null, address, bytes, value)}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   733
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   734
    public void setMemory(long address, long bytes, byte value) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   735
        setMemory(null, address, bytes, value);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   736
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   737
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   738
    /**
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   739
     * Validate the arguments to setMemory
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   740
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   741
     * @throws RuntimeException if the arguments are invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   742
     *         (<em>Note:</em> after optimization, invalid inputs may
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   743
     *         go undetected, which will lead to unpredictable
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   744
     *         behavior)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   745
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   746
    private void setMemoryChecks(Object o, long offset, long bytes, byte value) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   747
        checkPrimitivePointer(o, offset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   748
        checkSize(bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   749
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   750
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   751
    /**
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   752
     * Sets all bytes in a given block of memory to a copy of another
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   753
     * block.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   754
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   755
     * <p>This method determines each block's base address by means of two parameters,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   756
     * and so it provides (in effect) a <em>double-register</em> addressing mode,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   757
     * as discussed in {@link #getInt(Object,long)}.  When the object reference is null,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   758
     * the offset supplies an absolute base address.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   759
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   760
     * <p>The transfers are in coherent (atomic) units of a size determined
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   761
     * by the address and length parameters.  If the effective addresses and
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   762
     * length are all even modulo 8, the transfer takes place in 'long' units.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   763
     * If the effective addresses and length are (resp.) even modulo 4 or 2,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   764
     * the transfer takes place in units of 'int' or 'short'.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   765
     *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   766
     * <em>Note:</em> It is the resposibility of the caller to make
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   767
     * sure arguments are checked before the methods are called. While
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   768
     * some rudimentary checks are performed on the input, the checks
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   769
     * are best effort and when performance is an overriding priority,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   770
     * as when methods of this class are optimized by the runtime
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   771
     * compiler, some or all checks (if any) may be elided. Hence, the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   772
     * caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   773
     * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   774
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   775
     * @throws RuntimeException if any of the arguments is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   776
     *
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   777
     * @since 1.7
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   778
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   779
    public void copyMemory(Object srcBase, long srcOffset,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   780
                           Object destBase, long destOffset,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   781
                           long bytes) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   782
        copyMemoryChecks(srcBase, srcOffset, destBase, destOffset, bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   783
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   784
        if (bytes == 0) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   785
            return;
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   786
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   787
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   788
        copyMemory0(srcBase, srcOffset, destBase, destOffset, bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   789
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   790
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   791
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   792
     * Sets all bytes in a given block of memory to a copy of another
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   793
     * block.  This provides a <em>single-register</em> addressing mode,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   794
     * as discussed in {@link #getInt(Object,long)}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   795
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   796
     * Equivalent to {@code copyMemory(null, srcAddress, null, destAddress, bytes)}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   797
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   798
    public void copyMemory(long srcAddress, long destAddress, long bytes) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   799
        copyMemory(null, srcAddress, null, destAddress, bytes);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   800
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   801
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   802
    /**
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   803
     * Validate the arguments to copyMemory
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   804
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   805
     * @throws RuntimeException if any of the arguments is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   806
     *         (<em>Note:</em> after optimization, invalid inputs may
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   807
     *         go undetected, which will lead to unpredictable
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   808
     *         behavior)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   809
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   810
    private void copyMemoryChecks(Object srcBase, long srcOffset,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   811
                                  Object destBase, long destOffset,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   812
                                  long bytes) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   813
        checkSize(bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   814
        checkPrimitivePointer(srcBase, srcOffset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   815
        checkPrimitivePointer(destBase, destOffset);
36122
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   816
    }
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   817
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   818
    /**
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   819
     * Copies all elements from one block of memory to another block,
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   820
     * *unconditionally* byte swapping the elements on the fly.
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   821
     *
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   822
     * <p>This method determines each block's base address by means of two parameters,
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   823
     * and so it provides (in effect) a <em>double-register</em> addressing mode,
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   824
     * as discussed in {@link #getInt(Object,long)}.  When the object reference is null,
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   825
     * the offset supplies an absolute base address.
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   826
     *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   827
     * <em>Note:</em> It is the resposibility of the caller to make
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   828
     * sure arguments are checked before the methods are called. While
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   829
     * some rudimentary checks are performed on the input, the checks
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   830
     * are best effort and when performance is an overriding priority,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   831
     * as when methods of this class are optimized by the runtime
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   832
     * compiler, some or all checks (if any) may be elided. Hence, the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   833
     * caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   834
     * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   835
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   836
     * @throws RuntimeException if any of the arguments is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   837
     *
36122
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   838
     * @since 9
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   839
     */
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   840
    public void copySwapMemory(Object srcBase, long srcOffset,
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   841
                               Object destBase, long destOffset,
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   842
                               long bytes, long elemSize) {
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   843
        copySwapMemoryChecks(srcBase, srcOffset, destBase, destOffset, bytes, elemSize);
36122
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   844
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   845
        if (bytes == 0) {
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   846
            return;
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   847
        }
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   848
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   849
        copySwapMemory0(srcBase, srcOffset, destBase, destOffset, bytes, elemSize);
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   850
    }
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   851
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   852
    private void copySwapMemoryChecks(Object srcBase, long srcOffset,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   853
                                      Object destBase, long destOffset,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   854
                                      long bytes, long elemSize) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   855
        checkSize(bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   856
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   857
        if (elemSize != 2 && elemSize != 4 && elemSize != 8) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   858
            throw invalidInput();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   859
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   860
        if (bytes % elemSize != 0) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   861
            throw invalidInput();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   862
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   863
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   864
        checkPrimitivePointer(srcBase, srcOffset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   865
        checkPrimitivePointer(destBase, destOffset);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   866
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   867
36122
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   868
   /**
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   869
     * Copies all elements from one block of memory to another block, byte swapping the
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   870
     * elements on the fly.
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   871
     *
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   872
     * This provides a <em>single-register</em> addressing mode, as
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   873
     * discussed in {@link #getInt(Object,long)}.
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   874
     *
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   875
     * Equivalent to {@code copySwapMemory(null, srcAddress, null, destAddress, bytes, elemSize)}.
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   876
     */
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   877
    public void copySwapMemory(long srcAddress, long destAddress, long bytes, long elemSize) {
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   878
        copySwapMemory(null, srcAddress, null, destAddress, bytes, elemSize);
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   879
    }
5fca9f908ca4 8141491: Unaligned memory access in Bits.c
mikael
parents: 35302
diff changeset
   880
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   881
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   882
     * Disposes of a block of native memory, as obtained from {@link
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   883
     * #allocateMemory} or {@link #reallocateMemory}.  The address passed to
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   884
     * this method may be null, in which case no action is taken.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   885
     *
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   886
     * <em>Note:</em> It is the resposibility of the caller to make
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   887
     * sure arguments are checked before the methods are called. While
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   888
     * some rudimentary checks are performed on the input, the checks
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   889
     * are best effort and when performance is an overriding priority,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   890
     * as when methods of this class are optimized by the runtime
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   891
     * compiler, some or all checks (if any) may be elided. Hence, the
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   892
     * caller must not rely on the checks and corresponding
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   893
     * exceptions!
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   894
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   895
     * @throws RuntimeException if any of the arguments is invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   896
     *
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   897
     * @see #allocateMemory
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   898
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   899
    public void freeMemory(long address) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   900
        freeMemoryChecks(address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   901
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   902
        if (address == 0) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   903
            return;
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   904
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   905
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   906
        freeMemory0(address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   907
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   908
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   909
    /**
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   910
     * Validate the arguments to freeMemory
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   911
     *
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   912
     * @throws RuntimeException if the arguments are invalid
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   913
     *         (<em>Note:</em> after optimization, invalid inputs may
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   914
     *         go undetected, which will lead to unpredictable
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   915
     *         behavior)
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   916
     */
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   917
    private void freeMemoryChecks(long address) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   918
        checkPointer(null, address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   919
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   920
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   921
    /// random queries
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   922
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   923
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   924
     * This constant differs from all results that will ever be returned from
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   925
     * {@link #staticFieldOffset}, {@link #objectFieldOffset},
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   926
     * or {@link #arrayBaseOffset}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   927
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   928
    public static final int INVALID_FIELD_OFFSET = -1;
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   929
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   930
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   931
     * Reports the location of a given field in the storage allocation of its
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   932
     * class.  Do not expect to perform any sort of arithmetic on this offset;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   933
     * it is just a cookie which is passed to the unsafe heap memory accessors.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   934
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   935
     * <p>Any given field will always have the same offset and base, and no
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   936
     * two distinct fields of the same class will ever have the same offset
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   937
     * and base.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   938
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   939
     * <p>As of 1.4.1, offsets for fields are represented as long values,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   940
     * although the Sun JVM does not use the most significant 32 bits.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   941
     * However, JVM implementations which store static fields at absolute
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   942
     * addresses can use long offsets and null base pointers to express
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   943
     * the field locations in a form usable by {@link #getInt(Object,long)}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   944
     * Therefore, code which will be ported to such JVMs on 64-bit platforms
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   945
     * must preserve all bits of static field offsets.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   946
     * @see #getInt(Object, long)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   947
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   948
    public long objectFieldOffset(Field f) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   949
        if (f == null) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   950
            throw new NullPointerException();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   951
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   952
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   953
        return objectFieldOffset0(f);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   954
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   955
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   956
    /**
46873
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   957
     * Reports the location of the field with a given name in the storage
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   958
     * allocation of its class.
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   959
     *
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   960
     * @throws NullPointerException if any parameter is {@code null}.
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   961
     * @throws InternalError if there is no field named {@code name} declared
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   962
     *         in class {@code c}, i.e., if {@code c.getDeclaredField(name)}
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   963
     *         would throw {@code java.lang.NoSuchFieldException}.
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   964
     *
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   965
     * @see #objectFieldOffset(Field)
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   966
     */
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   967
    public long objectFieldOffset(Class<?> c, String name) {
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   968
        if (c == null || name == null) {
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   969
            throw new NullPointerException();
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   970
        }
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   971
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   972
        return objectFieldOffset1(c, name);
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   973
    }
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   974
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
   975
    /**
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   976
     * Reports the location of a given static field, in conjunction with {@link
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   977
     * #staticFieldBase}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   978
     * <p>Do not expect to perform any sort of arithmetic on this offset;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   979
     * it is just a cookie which is passed to the unsafe heap memory accessors.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   980
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   981
     * <p>Any given field will always have the same offset, and no two distinct
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   982
     * fields of the same class will ever have the same offset.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   983
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   984
     * <p>As of 1.4.1, offsets for fields are represented as long values,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   985
     * although the Sun JVM does not use the most significant 32 bits.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   986
     * It is hard to imagine a JVM technology which needs more than
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   987
     * a few bits to encode an offset within a non-array object,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   988
     * However, for consistency with other methods in this class,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   989
     * this method reports its result as a long value.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   990
     * @see #getInt(Object, long)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   991
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   992
    public long staticFieldOffset(Field f) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   993
        if (f == null) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   994
            throw new NullPointerException();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   995
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   996
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   997
        return staticFieldOffset0(f);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
   998
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
   999
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1000
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1001
     * Reports the location of a given static field, in conjunction with {@link
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1002
     * #staticFieldOffset}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1003
     * <p>Fetch the base "Object", if any, with which static fields of the
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1004
     * given class can be accessed via methods like {@link #getInt(Object,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1005
     * long)}.  This value may be null.  This value may refer to an object
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1006
     * which is a "cookie", not guaranteed to be a real Object, and it should
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1007
     * not be used in any way except as argument to the get and put routines in
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1008
     * this class.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1009
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1010
    public Object staticFieldBase(Field f) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1011
        if (f == null) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1012
            throw new NullPointerException();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1013
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1014
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1015
        return staticFieldBase0(f);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1016
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1017
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1018
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1019
     * Detects if the given class may need to be initialized. This is often
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1020
     * needed in conjunction with obtaining the static field base of a
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1021
     * class.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1022
     * @return false only if a call to {@code ensureClassInitialized} would have no effect
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1023
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1024
    public boolean shouldBeInitialized(Class<?> c) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1025
        if (c == null) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1026
            throw new NullPointerException();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1027
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1028
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1029
        return shouldBeInitialized0(c);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1030
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1031
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1032
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1033
     * Ensures the given class has been initialized. This is often
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1034
     * needed in conjunction with obtaining the static field base of a
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1035
     * class.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1036
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1037
    public void ensureClassInitialized(Class<?> c) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1038
        if (c == null) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1039
            throw new NullPointerException();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1040
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1041
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1042
        ensureClassInitialized0(c);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1043
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1044
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1045
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1046
     * Reports the offset of the first element in the storage allocation of a
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1047
     * given array class.  If {@link #arrayIndexScale} returns a non-zero value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1048
     * for the same class, you may use that scale factor, together with this
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1049
     * base offset, to form new offsets to access elements of arrays of the
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1050
     * given class.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1051
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1052
     * @see #getInt(Object, long)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1053
     * @see #putInt(Object, long, int)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1054
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1055
    public int arrayBaseOffset(Class<?> arrayClass) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1056
        if (arrayClass == null) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1057
            throw new NullPointerException();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1058
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1059
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1060
        return arrayBaseOffset0(arrayClass);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1061
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1062
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1063
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1064
    /** The value of {@code arrayBaseOffset(boolean[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1065
    public static final int ARRAY_BOOLEAN_BASE_OFFSET
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1066
            = theUnsafe.arrayBaseOffset(boolean[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1067
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1068
    /** The value of {@code arrayBaseOffset(byte[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1069
    public static final int ARRAY_BYTE_BASE_OFFSET
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1070
            = theUnsafe.arrayBaseOffset(byte[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1071
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1072
    /** The value of {@code arrayBaseOffset(short[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1073
    public static final int ARRAY_SHORT_BASE_OFFSET
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1074
            = theUnsafe.arrayBaseOffset(short[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1075
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1076
    /** The value of {@code arrayBaseOffset(char[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1077
    public static final int ARRAY_CHAR_BASE_OFFSET
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1078
            = theUnsafe.arrayBaseOffset(char[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1079
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1080
    /** The value of {@code arrayBaseOffset(int[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1081
    public static final int ARRAY_INT_BASE_OFFSET
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1082
            = theUnsafe.arrayBaseOffset(int[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1083
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1084
    /** The value of {@code arrayBaseOffset(long[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1085
    public static final int ARRAY_LONG_BASE_OFFSET
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1086
            = theUnsafe.arrayBaseOffset(long[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1087
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1088
    /** The value of {@code arrayBaseOffset(float[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1089
    public static final int ARRAY_FLOAT_BASE_OFFSET
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1090
            = theUnsafe.arrayBaseOffset(float[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1091
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1092
    /** The value of {@code arrayBaseOffset(double[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1093
    public static final int ARRAY_DOUBLE_BASE_OFFSET
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1094
            = theUnsafe.arrayBaseOffset(double[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1095
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1096
    /** The value of {@code arrayBaseOffset(Object[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1097
    public static final int ARRAY_OBJECT_BASE_OFFSET
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1098
            = theUnsafe.arrayBaseOffset(Object[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1099
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1100
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1101
     * Reports the scale factor for addressing elements in the storage
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1102
     * allocation of a given array class.  However, arrays of "narrow" types
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1103
     * will generally not work properly with accessors like {@link
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1104
     * #getByte(Object, long)}, so the scale factor for such classes is reported
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1105
     * as zero.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1106
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1107
     * @see #arrayBaseOffset
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1108
     * @see #getInt(Object, long)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1109
     * @see #putInt(Object, long, int)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1110
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1111
    public int arrayIndexScale(Class<?> arrayClass) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1112
        if (arrayClass == null) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1113
            throw new NullPointerException();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1114
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1115
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1116
        return arrayIndexScale0(arrayClass);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1117
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1118
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1119
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1120
    /** The value of {@code arrayIndexScale(boolean[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1121
    public static final int ARRAY_BOOLEAN_INDEX_SCALE
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1122
            = theUnsafe.arrayIndexScale(boolean[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1123
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1124
    /** The value of {@code arrayIndexScale(byte[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1125
    public static final int ARRAY_BYTE_INDEX_SCALE
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1126
            = theUnsafe.arrayIndexScale(byte[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1127
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1128
    /** The value of {@code arrayIndexScale(short[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1129
    public static final int ARRAY_SHORT_INDEX_SCALE
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1130
            = theUnsafe.arrayIndexScale(short[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1131
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1132
    /** The value of {@code arrayIndexScale(char[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1133
    public static final int ARRAY_CHAR_INDEX_SCALE
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1134
            = theUnsafe.arrayIndexScale(char[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1135
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1136
    /** The value of {@code arrayIndexScale(int[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1137
    public static final int ARRAY_INT_INDEX_SCALE
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1138
            = theUnsafe.arrayIndexScale(int[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1139
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1140
    /** The value of {@code arrayIndexScale(long[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1141
    public static final int ARRAY_LONG_INDEX_SCALE
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1142
            = theUnsafe.arrayIndexScale(long[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1143
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1144
    /** The value of {@code arrayIndexScale(float[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1145
    public static final int ARRAY_FLOAT_INDEX_SCALE
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1146
            = theUnsafe.arrayIndexScale(float[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1147
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1148
    /** The value of {@code arrayIndexScale(double[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1149
    public static final int ARRAY_DOUBLE_INDEX_SCALE
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1150
            = theUnsafe.arrayIndexScale(double[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1151
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1152
    /** The value of {@code arrayIndexScale(Object[].class)} */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1153
    public static final int ARRAY_OBJECT_INDEX_SCALE
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1154
            = theUnsafe.arrayIndexScale(Object[].class);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1155
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1156
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1157
     * Reports the size in bytes of a native pointer, as stored via {@link
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1158
     * #putAddress}.  This value will be either 4 or 8.  Note that the sizes of
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1159
     * other primitive types (as stored in native memory blocks) is determined
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1160
     * fully by their information content.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1161
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1162
    public int addressSize() {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1163
        return ADDRESS_SIZE;
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1164
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1165
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1166
    /** The value of {@code addressSize()} */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1167
    public static final int ADDRESS_SIZE = theUnsafe.addressSize0();
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1168
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1169
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1170
     * Reports the size in bytes of a native memory page (whatever that is).
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1171
     * This value will always be a power of two.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1172
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1173
    public native int pageSize();
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1174
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1175
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1176
    /// random trusted operations from JNI:
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1177
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1178
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1179
     * Tells the VM to define a class, without security checks.  By default, the
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1180
     * class loader and protection domain come from the caller's class.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1181
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1182
    public Class<?> defineClass(String name, byte[] b, int off, int len,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1183
                                ClassLoader loader,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1184
                                ProtectionDomain protectionDomain) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1185
        if (b == null) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1186
            throw new NullPointerException();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1187
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1188
        if (len < 0) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1189
            throw new ArrayIndexOutOfBoundsException();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1190
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1191
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1192
        return defineClass0(name, b, off, len, loader, protectionDomain);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1193
    }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1194
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1195
    public native Class<?> defineClass0(String name, byte[] b, int off, int len,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1196
                                        ClassLoader loader,
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1197
                                        ProtectionDomain protectionDomain);
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1198
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1199
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1200
     * Defines a class but does not make it known to the class loader or system dictionary.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1201
     * <p>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1202
     * For each CP entry, the corresponding CP patch must either be null or have
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1203
     * the a format that matches its tag:
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1204
     * <ul>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1205
     * <li>Integer, Long, Float, Double: the corresponding wrapper object type from java.lang
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1206
     * <li>Utf8: a string (must have suitable syntax if used as signature or name)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1207
     * <li>Class: any java.lang.Class object
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1208
     * <li>String: any object (not just a java.lang.String)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1209
     * <li>InterfaceMethodRef: (NYI) a method handle to invoke on that call site's arguments
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1210
     * </ul>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1211
     * @param hostClass context for linkage, access control, protection domain, and class loader
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1212
     * @param data      bytes of a class file
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1213
     * @param cpPatches where non-null entries exist, they replace corresponding CP entries in data
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1214
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1215
    public Class<?> defineAnonymousClass(Class<?> hostClass, byte[] data, Object[] cpPatches) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1216
        if (hostClass == null || data == null) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1217
            throw new NullPointerException();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1218
        }
40964
c4a7c6d1cfb3 8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents: 39745
diff changeset
  1219
        if (hostClass.isArray() || hostClass.isPrimitive()) {
c4a7c6d1cfb3 8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents: 39745
diff changeset
  1220
            throw new IllegalArgumentException();
c4a7c6d1cfb3 8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents: 39745
diff changeset
  1221
        }
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1222
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1223
        return defineAnonymousClass0(hostClass, data, cpPatches);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  1224
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1225
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1226
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1227
     * Allocates an instance but does not run any constructor.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1228
     * Initializes the class if it has not yet been.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1229
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1230
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1231
    public native Object allocateInstance(Class<?> cls)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1232
        throws InstantiationException;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1233
36629
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1234
    /**
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1235
     * Allocates an array of a given type, but does not do zeroing.
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1236
     * <p>
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1237
     * This method should only be used in the very rare cases where a high-performance code
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1238
     * overwrites the destination array completely, and compilers cannot assist in zeroing elimination.
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1239
     * In an overwhelming majority of cases, a normal Java allocation should be used instead.
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1240
     * <p>
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1241
     * Users of this method are <b>required</b> to overwrite the initial (garbage) array contents
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1242
     * before allowing untrusted code, or code in other threads, to observe the reference
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1243
     * to the newly allocated array. In addition, the publication of the array reference must be
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1244
     * safe according to the Java Memory Model requirements.
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1245
     * <p>
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1246
     * The safest approach to deal with an uninitialized array is to keep the reference to it in local
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1247
     * variable at least until the initialization is complete, and then publish it <b>once</b>, either
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1248
     * by writing it to a <em>volatile</em> field, or storing it into a <em>final</em> field in constructor,
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1249
     * or issuing a {@link #storeFence} before publishing the reference.
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1250
     * <p>
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1251
     * @implnote This method can only allocate primitive arrays, to avoid garbage reference
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1252
     * elements that could break heap integrity.
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1253
     *
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1254
     * @param componentType array component type to allocate
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1255
     * @param length array size to allocate
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1256
     * @throws IllegalArgumentException if component type is null, or not a primitive class;
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1257
     *                                  or the length is negative
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1258
     */
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1259
    public Object allocateUninitializedArray(Class<?> componentType, int length) {
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1260
       if (componentType == null) {
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1261
           throw new IllegalArgumentException("Component type is null");
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1262
       }
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1263
       if (!componentType.isPrimitive()) {
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1264
           throw new IllegalArgumentException("Component type is not primitive");
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1265
       }
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1266
       if (length < 0) {
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1267
           throw new IllegalArgumentException("Negative length");
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1268
       }
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1269
       return allocateUninitializedArray0(componentType, length);
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1270
    }
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1271
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1272
    @HotSpotIntrinsicCandidate
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1273
    private Object allocateUninitializedArray0(Class<?> componentType, int length) {
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1274
       // These fallbacks provide zeroed arrays, but intrinsic is not required to
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1275
       // return the zeroed arrays.
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1276
       if (componentType == byte.class)    return new byte[length];
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1277
       if (componentType == boolean.class) return new boolean[length];
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1278
       if (componentType == short.class)   return new short[length];
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1279
       if (componentType == char.class)    return new char[length];
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1280
       if (componentType == int.class)     return new int[length];
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1281
       if (componentType == float.class)   return new float[length];
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1282
       if (componentType == long.class)    return new long[length];
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1283
       if (componentType == double.class)  return new double[length];
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1284
       return null;
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1285
    }
765906c6f2a7 8150465: Unsafe methods to produce uninitialized arrays
shade
parents: 36628
diff changeset
  1286
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1287
    /** Throws the exception without telling the verifier. */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1288
    public native void throwException(Throwable ee);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1289
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1290
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1291
     * Atomically updates Java variable to {@code x} if it is currently
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1292
     * holding {@code expected}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1293
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1294
     * <p>This operation has memory semantics of a {@code volatile} read
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1295
     * and write.  Corresponds to C11 atomic_compare_exchange_strong.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1296
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1297
     * @return {@code true} if successful
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1298
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1299
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1300
    public final native boolean compareAndSetReference(Object o, long offset,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1301
                                                       Object expected,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1302
                                                       Object x);
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1303
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1304
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1305
    public final native Object compareAndExchangeReference(Object o, long offset,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1306
                                                           Object expected,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1307
                                                           Object x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1308
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1309
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1310
    public final Object compareAndExchangeReferenceAcquire(Object o, long offset,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1311
                                                           Object expected,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1312
                                                           Object x) {
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1313
        return compareAndExchangeReference(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1314
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1315
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1316
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1317
    public final Object compareAndExchangeReferenceRelease(Object o, long offset,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1318
                                                           Object expected,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1319
                                                           Object x) {
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1320
        return compareAndExchangeReference(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1321
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1322
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1323
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1324
    public final boolean weakCompareAndSetReferencePlain(Object o, long offset,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1325
                                                         Object expected,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1326
                                                         Object x) {
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1327
        return compareAndSetReference(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1328
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1329
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1330
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1331
    public final boolean weakCompareAndSetReferenceAcquire(Object o, long offset,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1332
                                                           Object expected,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1333
                                                           Object x) {
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1334
        return compareAndSetReference(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1335
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1336
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1337
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1338
    public final boolean weakCompareAndSetReferenceRelease(Object o, long offset,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1339
                                                           Object expected,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1340
                                                           Object x) {
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1341
        return compareAndSetReference(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1342
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1343
38363
c96f11db6475 8155965: Unsafe.weakCompareAndSetVolatile entry points and intrinsics
shade
parents: 36936
diff changeset
  1344
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1345
    public final boolean weakCompareAndSetReference(Object o, long offset,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1346
                                                    Object expected,
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1347
                                                    Object x) {
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1348
        return compareAndSetReference(o, offset, expected, x);
38363
c96f11db6475 8155965: Unsafe.weakCompareAndSetVolatile entry points and intrinsics
shade
parents: 36936
diff changeset
  1349
    }
c96f11db6475 8155965: Unsafe.weakCompareAndSetVolatile entry points and intrinsics
shade
parents: 36936
diff changeset
  1350
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1351
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1352
     * Atomically updates Java variable to {@code x} if it is currently
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1353
     * holding {@code expected}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1354
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1355
     * <p>This operation has memory semantics of a {@code volatile} read
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1356
     * and write.  Corresponds to C11 atomic_compare_exchange_strong.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1357
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1358
     * @return {@code true} if successful
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1359
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1360
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1361
    public final native boolean compareAndSetInt(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1362
                                                 int expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1363
                                                 int x);
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1364
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1365
    @HotSpotIntrinsicCandidate
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1366
    public final native int compareAndExchangeInt(Object o, long offset,
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1367
                                                  int expected,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1368
                                                  int x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1369
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1370
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1371
    public final int compareAndExchangeIntAcquire(Object o, long offset,
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1372
                                                         int expected,
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1373
                                                         int x) {
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1374
        return compareAndExchangeInt(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1375
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1376
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1377
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1378
    public final int compareAndExchangeIntRelease(Object o, long offset,
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1379
                                                         int expected,
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1380
                                                         int x) {
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1381
        return compareAndExchangeInt(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1382
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1383
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1384
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1385
    public final boolean weakCompareAndSetIntPlain(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1386
                                                   int expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1387
                                                   int x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1388
        return compareAndSetInt(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1389
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1390
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1391
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1392
    public final boolean weakCompareAndSetIntAcquire(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1393
                                                     int expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1394
                                                     int x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1395
        return compareAndSetInt(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1396
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1397
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1398
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1399
    public final boolean weakCompareAndSetIntRelease(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1400
                                                     int expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1401
                                                     int x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1402
        return compareAndSetInt(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1403
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1404
38363
c96f11db6475 8155965: Unsafe.weakCompareAndSetVolatile entry points and intrinsics
shade
parents: 36936
diff changeset
  1405
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1406
    public final boolean weakCompareAndSetInt(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1407
                                              int expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1408
                                              int x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1409
        return compareAndSetInt(o, offset, expected, x);
38363
c96f11db6475 8155965: Unsafe.weakCompareAndSetVolatile entry points and intrinsics
shade
parents: 36936
diff changeset
  1410
    }
c96f11db6475 8155965: Unsafe.weakCompareAndSetVolatile entry points and intrinsics
shade
parents: 36936
diff changeset
  1411
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1412
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1413
    public final byte compareAndExchangeByte(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1414
                                             byte expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1415
                                             byte x) {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1416
        long wordOffset = offset & ~3;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1417
        int shift = (int) (offset & 3) << 3;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1418
        if (BE) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1419
            shift = 24 - shift;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1420
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1421
        int mask           = 0xFF << shift;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1422
        int maskedExpected = (expected & 0xFF) << shift;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1423
        int maskedX        = (x & 0xFF) << shift;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1424
        int fullWord;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1425
        do {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1426
            fullWord = getIntVolatile(o, wordOffset);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1427
            if ((fullWord & mask) != maskedExpected)
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1428
                return (byte) ((fullWord & mask) >> shift);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1429
        } while (!weakCompareAndSetInt(o, wordOffset,
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1430
                                                fullWord, (fullWord & ~mask) | maskedX));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1431
        return expected;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1432
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1433
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1434
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1435
    public final boolean compareAndSetByte(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1436
                                           byte expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1437
                                           byte x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1438
        return compareAndExchangeByte(o, offset, expected, x) == expected;
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1439
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1440
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1441
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1442
    public final boolean weakCompareAndSetByte(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1443
                                               byte expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1444
                                               byte x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1445
        return compareAndSetByte(o, offset, expected, x);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1446
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1447
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1448
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1449
    public final boolean weakCompareAndSetByteAcquire(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1450
                                                      byte expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1451
                                                      byte x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1452
        return weakCompareAndSetByte(o, offset, expected, x);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1453
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1454
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1455
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1456
    public final boolean weakCompareAndSetByteRelease(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1457
                                                      byte expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1458
                                                      byte x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1459
        return weakCompareAndSetByte(o, offset, expected, x);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1460
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1461
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1462
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1463
    public final boolean weakCompareAndSetBytePlain(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1464
                                                    byte expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1465
                                                    byte x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1466
        return weakCompareAndSetByte(o, offset, expected, x);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1467
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1468
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1469
    @HotSpotIntrinsicCandidate
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1470
    public final byte compareAndExchangeByteAcquire(Object o, long offset,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1471
                                                    byte expected,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1472
                                                    byte x) {
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1473
        return compareAndExchangeByte(o, offset, expected, x);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1474
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1475
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1476
    @HotSpotIntrinsicCandidate
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1477
    public final byte compareAndExchangeByteRelease(Object o, long offset,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1478
                                                    byte expected,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1479
                                                    byte x) {
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1480
        return compareAndExchangeByte(o, offset, expected, x);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1481
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1482
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1483
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1484
    public final short compareAndExchangeShort(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1485
                                               short expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1486
                                               short x) {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1487
        if ((offset & 3) == 3) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1488
            throw new IllegalArgumentException("Update spans the word, not supported");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1489
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1490
        long wordOffset = offset & ~3;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1491
        int shift = (int) (offset & 3) << 3;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1492
        if (BE) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1493
            shift = 16 - shift;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1494
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1495
        int mask           = 0xFFFF << shift;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1496
        int maskedExpected = (expected & 0xFFFF) << shift;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1497
        int maskedX        = (x & 0xFFFF) << shift;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1498
        int fullWord;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1499
        do {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1500
            fullWord = getIntVolatile(o, wordOffset);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1501
            if ((fullWord & mask) != maskedExpected) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1502
                return (short) ((fullWord & mask) >> shift);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1503
            }
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1504
        } while (!weakCompareAndSetInt(o, wordOffset,
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1505
                                                fullWord, (fullWord & ~mask) | maskedX));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1506
        return expected;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1507
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1508
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1509
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1510
    public final boolean compareAndSetShort(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1511
                                            short expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1512
                                            short x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1513
        return compareAndExchangeShort(o, offset, expected, x) == expected;
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1514
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1515
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1516
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1517
    public final boolean weakCompareAndSetShort(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1518
                                                short expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1519
                                                short x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1520
        return compareAndSetShort(o, offset, expected, x);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1521
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1522
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1523
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1524
    public final boolean weakCompareAndSetShortAcquire(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1525
                                                       short expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1526
                                                       short x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1527
        return weakCompareAndSetShort(o, offset, expected, x);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1528
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1529
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1530
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1531
    public final boolean weakCompareAndSetShortRelease(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1532
                                                       short expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1533
                                                       short x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1534
        return weakCompareAndSetShort(o, offset, expected, x);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1535
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1536
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1537
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1538
    public final boolean weakCompareAndSetShortPlain(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1539
                                                     short expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1540
                                                     short x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1541
        return weakCompareAndSetShort(o, offset, expected, x);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1542
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1543
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1544
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1545
    @HotSpotIntrinsicCandidate
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1546
    public final short compareAndExchangeShortAcquire(Object o, long offset,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1547
                                                     short expected,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1548
                                                     short x) {
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1549
        return compareAndExchangeShort(o, offset, expected, x);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1550
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1551
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1552
    @HotSpotIntrinsicCandidate
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1553
    public final short compareAndExchangeShortRelease(Object o, long offset,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1554
                                                    short expected,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1555
                                                    short x) {
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1556
        return compareAndExchangeShort(o, offset, expected, x);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1557
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1558
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1559
    @ForceInline
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1560
    private char s2c(short s) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1561
        return (char) s;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1562
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1563
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1564
    @ForceInline
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1565
    private short c2s(char s) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1566
        return (short) s;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1567
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1568
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1569
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1570
    public final boolean compareAndSetChar(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1571
                                           char expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1572
                                           char x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1573
        return compareAndSetShort(o, offset, c2s(expected), c2s(x));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1574
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1575
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1576
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1577
    public final char compareAndExchangeChar(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1578
                                             char expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1579
                                             char x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1580
        return s2c(compareAndExchangeShort(o, offset, c2s(expected), c2s(x)));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1581
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1582
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1583
    @ForceInline
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1584
    public final char compareAndExchangeCharAcquire(Object o, long offset,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1585
                                            char expected,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1586
                                            char x) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1587
        return s2c(compareAndExchangeShortAcquire(o, offset, c2s(expected), c2s(x)));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1588
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1589
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1590
    @ForceInline
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1591
    public final char compareAndExchangeCharRelease(Object o, long offset,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1592
                                            char expected,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1593
                                            char x) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1594
        return s2c(compareAndExchangeShortRelease(o, offset, c2s(expected), c2s(x)));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1595
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1596
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1597
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1598
    public final boolean weakCompareAndSetChar(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1599
                                               char expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1600
                                               char x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1601
        return weakCompareAndSetShort(o, offset, c2s(expected), c2s(x));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1602
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1603
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1604
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1605
    public final boolean weakCompareAndSetCharAcquire(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1606
                                                      char expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1607
                                                      char x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1608
        return weakCompareAndSetShortAcquire(o, offset, c2s(expected), c2s(x));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1609
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1610
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1611
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1612
    public final boolean weakCompareAndSetCharRelease(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1613
                                                      char expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1614
                                                      char x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1615
        return weakCompareAndSetShortRelease(o, offset, c2s(expected), c2s(x));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1616
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1617
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1618
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1619
    public final boolean weakCompareAndSetCharPlain(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1620
                                                    char expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1621
                                                    char x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1622
        return weakCompareAndSetShortPlain(o, offset, c2s(expected), c2s(x));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1623
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1624
41109
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1625
    /**
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1626
     * The JVM converts integral values to boolean values using two
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1627
     * different conventions, byte testing against zero and truncation
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1628
     * to least-significant bit.
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1629
     *
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1630
     * <p>The JNI documents specify that, at least for returning
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1631
     * values from native methods, a Java boolean value is converted
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1632
     * to the value-set 0..1 by first truncating to a byte (0..255 or
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1633
     * maybe -128..127) and then testing against zero. Thus, Java
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1634
     * booleans in non-Java data structures are by convention
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1635
     * represented as 8-bit containers containing either zero (for
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1636
     * false) or any non-zero value (for true).
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1637
     *
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1638
     * <p>Java booleans in the heap are also stored in bytes, but are
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1639
     * strongly normalized to the value-set 0..1 (i.e., they are
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1640
     * truncated to the least-significant bit).
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1641
     *
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1642
     * <p>The main reason for having different conventions for
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1643
     * conversion is performance: Truncation to the least-significant
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1644
     * bit can be usually implemented with fewer (machine)
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1645
     * instructions than byte testing against zero.
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1646
     *
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1647
     * <p>A number of Unsafe methods load boolean values from the heap
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1648
     * as bytes. Unsafe converts those values according to the JNI
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1649
     * rules (i.e, using the "testing against zero" convention). The
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1650
     * method {@code byte2bool} implements that conversion.
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1651
     *
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1652
     * @param b the byte to be converted to boolean
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1653
     * @return the result of the conversion
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1654
     */
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1655
    @ForceInline
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1656
    private boolean byte2bool(byte b) {
41109
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1657
        return b != 0;
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1658
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1659
41109
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1660
    /**
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1661
     * Convert a boolean value to a byte. The return value is strongly
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1662
     * normalized to the value-set 0..1 (i.e., the value is truncated
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1663
     * to the least-significant bit). See {@link #byte2bool(byte)} for
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1664
     * more details on conversion conventions.
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1665
     *
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1666
     * @param b the boolean to be converted to byte (and then normalized)
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1667
     * @return the result of the conversion
a2d5b18586fa 8161720: Better byte behavior for off-heap data
zmajo
parents: 39745
diff changeset
  1668
     */
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1669
    @ForceInline
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1670
    private byte bool2byte(boolean b) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1671
        return b ? (byte)1 : (byte)0;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1672
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1673
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1674
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1675
    public final boolean compareAndSetBoolean(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1676
                                              boolean expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1677
                                              boolean x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1678
        return compareAndSetByte(o, offset, bool2byte(expected), bool2byte(x));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1679
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1680
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1681
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1682
    public final boolean compareAndExchangeBoolean(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1683
                                                   boolean expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1684
                                                   boolean x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1685
        return byte2bool(compareAndExchangeByte(o, offset, bool2byte(expected), bool2byte(x)));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1686
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1687
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1688
    @ForceInline
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1689
    public final boolean compareAndExchangeBooleanAcquire(Object o, long offset,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1690
                                                    boolean expected,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1691
                                                    boolean x) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1692
        return byte2bool(compareAndExchangeByteAcquire(o, offset, bool2byte(expected), bool2byte(x)));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1693
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1694
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1695
    @ForceInline
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1696
    public final boolean compareAndExchangeBooleanRelease(Object o, long offset,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1697
                                                       boolean expected,
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1698
                                                       boolean x) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1699
        return byte2bool(compareAndExchangeByteRelease(o, offset, bool2byte(expected), bool2byte(x)));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1700
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1701
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1702
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1703
    public final boolean weakCompareAndSetBoolean(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1704
                                                  boolean expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1705
                                                  boolean x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1706
        return weakCompareAndSetByte(o, offset, bool2byte(expected), bool2byte(x));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1707
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1708
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1709
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1710
    public final boolean weakCompareAndSetBooleanAcquire(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1711
                                                         boolean expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1712
                                                         boolean x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1713
        return weakCompareAndSetByteAcquire(o, offset, bool2byte(expected), bool2byte(x));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1714
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1715
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1716
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1717
    public final boolean weakCompareAndSetBooleanRelease(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1718
                                                         boolean expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1719
                                                         boolean x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1720
        return weakCompareAndSetByteRelease(o, offset, bool2byte(expected), bool2byte(x));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1721
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1722
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1723
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1724
    public final boolean weakCompareAndSetBooleanPlain(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1725
                                                       boolean expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1726
                                                       boolean x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1727
        return weakCompareAndSetBytePlain(o, offset, bool2byte(expected), bool2byte(x));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1728
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  1729
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1730
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1731
     * Atomically updates Java variable to {@code x} if it is currently
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1732
     * holding {@code expected}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1733
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1734
     * <p>This operation has memory semantics of a {@code volatile} read
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1735
     * and write.  Corresponds to C11 atomic_compare_exchange_strong.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1736
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1737
     * @return {@code true} if successful
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1738
     */
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1739
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1740
    public final boolean compareAndSetFloat(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1741
                                            float expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1742
                                            float x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1743
        return compareAndSetInt(o, offset,
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1744
                                 Float.floatToRawIntBits(expected),
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1745
                                 Float.floatToRawIntBits(x));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1746
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1747
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1748
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1749
    public final float compareAndExchangeFloat(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1750
                                               float expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1751
                                               float x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1752
        int w = compareAndExchangeInt(o, offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1753
                                      Float.floatToRawIntBits(expected),
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1754
                                      Float.floatToRawIntBits(x));
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1755
        return Float.intBitsToFloat(w);
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1756
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1757
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1758
    @ForceInline
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1759
    public final float compareAndExchangeFloatAcquire(Object o, long offset,
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1760
                                                  float expected,
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1761
                                                  float x) {
39492
697da62a538a 8160885: Unsafe.compareAndExchangeDouble/FloatAcquire should defer to compareAndExchangeLong/IntAcquire
psandoz
parents: 39471
diff changeset
  1762
        int w = compareAndExchangeIntAcquire(o, offset,
697da62a538a 8160885: Unsafe.compareAndExchangeDouble/FloatAcquire should defer to compareAndExchangeLong/IntAcquire
psandoz
parents: 39471
diff changeset
  1763
                                             Float.floatToRawIntBits(expected),
697da62a538a 8160885: Unsafe.compareAndExchangeDouble/FloatAcquire should defer to compareAndExchangeLong/IntAcquire
psandoz
parents: 39471
diff changeset
  1764
                                             Float.floatToRawIntBits(x));
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1765
        return Float.intBitsToFloat(w);
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1766
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1767
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1768
    @ForceInline
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1769
    public final float compareAndExchangeFloatRelease(Object o, long offset,
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1770
                                                  float expected,
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1771
                                                  float x) {
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1772
        int w = compareAndExchangeIntRelease(o, offset,
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1773
                                             Float.floatToRawIntBits(expected),
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1774
                                             Float.floatToRawIntBits(x));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1775
        return Float.intBitsToFloat(w);
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1776
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1777
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1778
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1779
    public final boolean weakCompareAndSetFloatPlain(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1780
                                                     float expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1781
                                                     float x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1782
        return weakCompareAndSetIntPlain(o, offset,
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1783
                                     Float.floatToRawIntBits(expected),
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1784
                                     Float.floatToRawIntBits(x));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1785
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1786
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1787
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1788
    public final boolean weakCompareAndSetFloatAcquire(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1789
                                                       float expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1790
                                                       float x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1791
        return weakCompareAndSetIntAcquire(o, offset,
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1792
                                            Float.floatToRawIntBits(expected),
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1793
                                            Float.floatToRawIntBits(x));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1794
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1795
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1796
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1797
    public final boolean weakCompareAndSetFloatRelease(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1798
                                                       float expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1799
                                                       float x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1800
        return weakCompareAndSetIntRelease(o, offset,
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1801
                                            Float.floatToRawIntBits(expected),
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1802
                                            Float.floatToRawIntBits(x));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1803
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1804
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1805
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1806
    public final boolean weakCompareAndSetFloat(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1807
                                                float expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1808
                                                float x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1809
        return weakCompareAndSetInt(o, offset,
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1810
                                             Float.floatToRawIntBits(expected),
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1811
                                             Float.floatToRawIntBits(x));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1812
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1813
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1814
    /**
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1815
     * Atomically updates Java variable to {@code x} if it is currently
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1816
     * holding {@code expected}.
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1817
     *
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1818
     * <p>This operation has memory semantics of a {@code volatile} read
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1819
     * and write.  Corresponds to C11 atomic_compare_exchange_strong.
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1820
     *
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1821
     * @return {@code true} if successful
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1822
     */
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1823
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1824
    public final boolean compareAndSetDouble(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1825
                                             double expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1826
                                             double x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1827
        return compareAndSetLong(o, offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1828
                                 Double.doubleToRawLongBits(expected),
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1829
                                 Double.doubleToRawLongBits(x));
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1830
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1831
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1832
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1833
    public final double compareAndExchangeDouble(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1834
                                                 double expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1835
                                                 double x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1836
        long w = compareAndExchangeLong(o, offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1837
                                        Double.doubleToRawLongBits(expected),
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1838
                                        Double.doubleToRawLongBits(x));
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1839
        return Double.longBitsToDouble(w);
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1840
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1841
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1842
    @ForceInline
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1843
    public final double compareAndExchangeDoubleAcquire(Object o, long offset,
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1844
                                                        double expected,
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1845
                                                        double x) {
39492
697da62a538a 8160885: Unsafe.compareAndExchangeDouble/FloatAcquire should defer to compareAndExchangeLong/IntAcquire
psandoz
parents: 39471
diff changeset
  1846
        long w = compareAndExchangeLongAcquire(o, offset,
697da62a538a 8160885: Unsafe.compareAndExchangeDouble/FloatAcquire should defer to compareAndExchangeLong/IntAcquire
psandoz
parents: 39471
diff changeset
  1847
                                               Double.doubleToRawLongBits(expected),
697da62a538a 8160885: Unsafe.compareAndExchangeDouble/FloatAcquire should defer to compareAndExchangeLong/IntAcquire
psandoz
parents: 39471
diff changeset
  1848
                                               Double.doubleToRawLongBits(x));
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1849
        return Double.longBitsToDouble(w);
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1850
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1851
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1852
    @ForceInline
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1853
    public final double compareAndExchangeDoubleRelease(Object o, long offset,
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1854
                                                        double expected,
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1855
                                                        double x) {
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1856
        long w = compareAndExchangeLongRelease(o, offset,
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1857
                                               Double.doubleToRawLongBits(expected),
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1858
                                               Double.doubleToRawLongBits(x));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1859
        return Double.longBitsToDouble(w);
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1860
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1861
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1862
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1863
    public final boolean weakCompareAndSetDoublePlain(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1864
                                                      double expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1865
                                                      double x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1866
        return weakCompareAndSetLongPlain(o, offset,
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1867
                                     Double.doubleToRawLongBits(expected),
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1868
                                     Double.doubleToRawLongBits(x));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1869
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1870
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1871
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1872
    public final boolean weakCompareAndSetDoubleAcquire(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1873
                                                        double expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1874
                                                        double x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1875
        return weakCompareAndSetLongAcquire(o, offset,
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1876
                                             Double.doubleToRawLongBits(expected),
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1877
                                             Double.doubleToRawLongBits(x));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1878
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1879
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1880
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1881
    public final boolean weakCompareAndSetDoubleRelease(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1882
                                                        double expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1883
                                                        double x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1884
        return weakCompareAndSetLongRelease(o, offset,
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1885
                                             Double.doubleToRawLongBits(expected),
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1886
                                             Double.doubleToRawLongBits(x));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1887
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1888
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1889
    @ForceInline
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1890
    public final boolean weakCompareAndSetDouble(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1891
                                                 double expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1892
                                                 double x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1893
        return weakCompareAndSetLong(o, offset,
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1894
                                              Double.doubleToRawLongBits(expected),
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1895
                                              Double.doubleToRawLongBits(x));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1896
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1897
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1898
    /**
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1899
     * Atomically updates Java variable to {@code x} if it is currently
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1900
     * holding {@code expected}.
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1901
     *
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1902
     * <p>This operation has memory semantics of a {@code volatile} read
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1903
     * and write.  Corresponds to C11 atomic_compare_exchange_strong.
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1904
     *
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1905
     * @return {@code true} if successful
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  1906
     */
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1907
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1908
    public final native boolean compareAndSetLong(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1909
                                                  long expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1910
                                                  long x);
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1911
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1912
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1913
    public final native long compareAndExchangeLong(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1914
                                                    long expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1915
                                                    long x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1916
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1917
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1918
    public final long compareAndExchangeLongAcquire(Object o, long offset,
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1919
                                                           long expected,
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1920
                                                           long x) {
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1921
        return compareAndExchangeLong(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1922
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1923
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1924
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1925
    public final long compareAndExchangeLongRelease(Object o, long offset,
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1926
                                                           long expected,
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1927
                                                           long x) {
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1928
        return compareAndExchangeLong(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1929
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1930
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1931
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1932
    public final boolean weakCompareAndSetLongPlain(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1933
                                                    long expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1934
                                                    long x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1935
        return compareAndSetLong(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1936
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1937
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1938
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1939
    public final boolean weakCompareAndSetLongAcquire(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1940
                                                      long expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1941
                                                      long x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1942
        return compareAndSetLong(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1943
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1944
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1945
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1946
    public final boolean weakCompareAndSetLongRelease(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1947
                                                      long expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1948
                                                      long x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1949
        return compareAndSetLong(o, offset, expected, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1950
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  1951
38363
c96f11db6475 8155965: Unsafe.weakCompareAndSetVolatile entry points and intrinsics
shade
parents: 36936
diff changeset
  1952
    @HotSpotIntrinsicCandidate
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1953
    public final boolean weakCompareAndSetLong(Object o, long offset,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1954
                                               long expected,
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1955
                                               long x) {
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  1956
        return compareAndSetLong(o, offset, expected, x);
38363
c96f11db6475 8155965: Unsafe.weakCompareAndSetVolatile entry points and intrinsics
shade
parents: 36936
diff changeset
  1957
    }
c96f11db6475 8155965: Unsafe.weakCompareAndSetVolatile entry points and intrinsics
shade
parents: 36936
diff changeset
  1958
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1959
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1960
     * Fetches a reference value from a given Java variable, with volatile
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1961
     * load semantics. Otherwise identical to {@link #getReference(Object, long)}
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1962
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1963
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1964
    public native Object getReferenceVolatile(Object o, long offset);
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1965
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1966
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1967
     * Stores a reference value into a given Java variable, with
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1968
     * volatile store semantics. Otherwise identical to {@link #putReference(Object, long, Object)}
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1969
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1970
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  1971
    public native void putReferenceVolatile(Object o, long offset, Object x);
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1972
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1973
    /** Volatile version of {@link #getInt(Object, long)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1974
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1975
    public native int     getIntVolatile(Object o, long offset);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1976
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1977
    /** Volatile version of {@link #putInt(Object, long, int)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1978
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1979
    public native void    putIntVolatile(Object o, long offset, int x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1980
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1981
    /** Volatile version of {@link #getBoolean(Object, long)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1982
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1983
    public native boolean getBooleanVolatile(Object o, long offset);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1984
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1985
    /** Volatile version of {@link #putBoolean(Object, long, boolean)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1986
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1987
    public native void    putBooleanVolatile(Object o, long offset, boolean x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1988
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1989
    /** Volatile version of {@link #getByte(Object, long)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1990
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1991
    public native byte    getByteVolatile(Object o, long offset);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1992
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1993
    /** Volatile version of {@link #putByte(Object, long, byte)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1994
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1995
    public native void    putByteVolatile(Object o, long offset, byte x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1996
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1997
    /** Volatile version of {@link #getShort(Object, long)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1998
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  1999
    public native short   getShortVolatile(Object o, long offset);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2000
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2001
    /** Volatile version of {@link #putShort(Object, long, short)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2002
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2003
    public native void    putShortVolatile(Object o, long offset, short x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2004
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2005
    /** Volatile version of {@link #getChar(Object, long)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2006
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2007
    public native char    getCharVolatile(Object o, long offset);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2008
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2009
    /** Volatile version of {@link #putChar(Object, long, char)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2010
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2011
    public native void    putCharVolatile(Object o, long offset, char x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2012
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2013
    /** Volatile version of {@link #getLong(Object, long)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2014
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2015
    public native long    getLongVolatile(Object o, long offset);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2016
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2017
    /** Volatile version of {@link #putLong(Object, long, long)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2018
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2019
    public native void    putLongVolatile(Object o, long offset, long x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2020
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2021
    /** Volatile version of {@link #getFloat(Object, long)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2022
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2023
    public native float   getFloatVolatile(Object o, long offset);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2024
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2025
    /** Volatile version of {@link #putFloat(Object, long, float)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2026
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2027
    public native void    putFloatVolatile(Object o, long offset, float x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2028
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2029
    /** Volatile version of {@link #getDouble(Object, long)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2030
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2031
    public native double  getDoubleVolatile(Object o, long offset);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2032
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2033
    /** Volatile version of {@link #putDouble(Object, long, double)}  */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2034
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2035
    public native void    putDoubleVolatile(Object o, long offset, double x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2036
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2037
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2038
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2039
    /** Acquire version of {@link #getReferenceVolatile(Object, long)} */
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2040
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2041
    public final Object getReferenceAcquire(Object o, long offset) {
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2042
        return getReferenceVolatile(o, offset);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2043
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2044
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2045
    /** Acquire version of {@link #getBooleanVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2046
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2047
    public final boolean getBooleanAcquire(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2048
        return getBooleanVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2049
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2050
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2051
    /** Acquire version of {@link #getByteVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2052
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2053
    public final byte getByteAcquire(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2054
        return getByteVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2055
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2056
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2057
    /** Acquire version of {@link #getShortVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2058
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2059
    public final short getShortAcquire(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2060
        return getShortVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2061
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2062
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2063
    /** Acquire version of {@link #getCharVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2064
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2065
    public final char getCharAcquire(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2066
        return getCharVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2067
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2068
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2069
    /** Acquire version of {@link #getIntVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2070
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2071
    public final int getIntAcquire(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2072
        return getIntVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2073
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2074
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2075
    /** Acquire version of {@link #getFloatVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2076
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2077
    public final float getFloatAcquire(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2078
        return getFloatVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2079
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2080
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2081
    /** Acquire version of {@link #getLongVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2082
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2083
    public final long getLongAcquire(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2084
        return getLongVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2085
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2086
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2087
    /** Acquire version of {@link #getDoubleVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2088
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2089
    public final double getDoubleAcquire(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2090
        return getDoubleVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2091
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2092
36936
bfcdf736a998 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36629
diff changeset
  2093
    /*
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2094
      * Versions of {@link #putReferenceVolatile(Object, long, Object)}
36936
bfcdf736a998 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36629
diff changeset
  2095
      * that do not guarantee immediate visibility of the store to
bfcdf736a998 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36629
diff changeset
  2096
      * other threads. This method is generally only useful if the
bfcdf736a998 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36629
diff changeset
  2097
      * underlying field is a Java volatile (or if an array cell, one
bfcdf736a998 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36629
diff changeset
  2098
      * that is otherwise only accessed using volatile accesses).
bfcdf736a998 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36629
diff changeset
  2099
      *
bfcdf736a998 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36629
diff changeset
  2100
      * Corresponds to C11 atomic_store_explicit(..., memory_order_release).
bfcdf736a998 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36629
diff changeset
  2101
      */
bfcdf736a998 8152698: Remove obsolete Unsafe.putOrdered{X} methods, usages, runtime and compiler support
shade
parents: 36629
diff changeset
  2102
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2103
    /** Release version of {@link #putReferenceVolatile(Object, long, Object)} */
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2104
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2105
    public final void putReferenceRelease(Object o, long offset, Object x) {
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2106
        putReferenceVolatile(o, offset, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2107
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2108
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2109
    /** Release version of {@link #putBooleanVolatile(Object, long, boolean)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2110
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2111
    public final void putBooleanRelease(Object o, long offset, boolean x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2112
        putBooleanVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2113
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2114
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2115
    /** Release version of {@link #putByteVolatile(Object, long, byte)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2116
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2117
    public final void putByteRelease(Object o, long offset, byte x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2118
        putByteVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2119
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2120
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2121
    /** Release version of {@link #putShortVolatile(Object, long, short)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2122
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2123
    public final void putShortRelease(Object o, long offset, short x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2124
        putShortVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2125
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2126
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2127
    /** Release version of {@link #putCharVolatile(Object, long, char)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2128
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2129
    public final void putCharRelease(Object o, long offset, char x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2130
        putCharVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2131
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2132
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2133
    /** Release version of {@link #putIntVolatile(Object, long, int)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2134
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2135
    public final void putIntRelease(Object o, long offset, int x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2136
        putIntVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2137
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2138
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2139
    /** Release version of {@link #putFloatVolatile(Object, long, float)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2140
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2141
    public final void putFloatRelease(Object o, long offset, float x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2142
        putFloatVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2143
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2144
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2145
    /** Release version of {@link #putLongVolatile(Object, long, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2146
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2147
    public final void putLongRelease(Object o, long offset, long x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2148
        putLongVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2149
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2150
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2151
    /** Release version of {@link #putDoubleVolatile(Object, long, double)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2152
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2153
    public final void putDoubleRelease(Object o, long offset, double x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2154
        putDoubleVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2155
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2156
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2157
    // ------------------------------ Opaque --------------------------------------
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2158
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2159
    /** Opaque version of {@link #getReferenceVolatile(Object, long)} */
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2160
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2161
    public final Object getReferenceOpaque(Object o, long offset) {
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2162
        return getReferenceVolatile(o, offset);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2163
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2164
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2165
    /** Opaque version of {@link #getBooleanVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2166
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2167
    public final boolean getBooleanOpaque(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2168
        return getBooleanVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2169
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2170
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2171
    /** Opaque version of {@link #getByteVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2172
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2173
    public final byte getByteOpaque(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2174
        return getByteVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2175
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2176
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2177
    /** Opaque version of {@link #getShortVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2178
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2179
    public final short getShortOpaque(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2180
        return getShortVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2181
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2182
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2183
    /** Opaque version of {@link #getCharVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2184
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2185
    public final char getCharOpaque(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2186
        return getCharVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2187
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2188
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2189
    /** Opaque version of {@link #getIntVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2190
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2191
    public final int getIntOpaque(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2192
        return getIntVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2193
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2194
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2195
    /** Opaque version of {@link #getFloatVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2196
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2197
    public final float getFloatOpaque(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2198
        return getFloatVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2199
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2200
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2201
    /** Opaque version of {@link #getLongVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2202
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2203
    public final long getLongOpaque(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2204
        return getLongVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2205
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2206
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2207
    /** Opaque version of {@link #getDoubleVolatile(Object, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2208
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2209
    public final double getDoubleOpaque(Object o, long offset) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2210
        return getDoubleVolatile(o, offset);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2211
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2212
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2213
    /** Opaque version of {@link #putReferenceVolatile(Object, long, Object)} */
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2214
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2215
    public final void putReferenceOpaque(Object o, long offset, Object x) {
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2216
        putReferenceVolatile(o, offset, x);
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2217
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2218
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2219
    /** Opaque version of {@link #putBooleanVolatile(Object, long, boolean)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2220
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2221
    public final void putBooleanOpaque(Object o, long offset, boolean x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2222
        putBooleanVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2223
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2224
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2225
    /** Opaque version of {@link #putByteVolatile(Object, long, byte)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2226
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2227
    public final void putByteOpaque(Object o, long offset, byte x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2228
        putByteVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2229
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2230
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2231
    /** Opaque version of {@link #putShortVolatile(Object, long, short)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2232
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2233
    public final void putShortOpaque(Object o, long offset, short x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2234
        putShortVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2235
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2236
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2237
    /** Opaque version of {@link #putCharVolatile(Object, long, char)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2238
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2239
    public final void putCharOpaque(Object o, long offset, char x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2240
        putCharVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2241
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2242
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2243
    /** Opaque version of {@link #putIntVolatile(Object, long, int)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2244
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2245
    public final void putIntOpaque(Object o, long offset, int x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2246
        putIntVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2247
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2248
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2249
    /** Opaque version of {@link #putFloatVolatile(Object, long, float)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2250
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2251
    public final void putFloatOpaque(Object o, long offset, float x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2252
        putFloatVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2253
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2254
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2255
    /** Opaque version of {@link #putLongVolatile(Object, long, long)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2256
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2257
    public final void putLongOpaque(Object o, long offset, long x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2258
        putLongVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2259
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2260
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2261
    /** Opaque version of {@link #putDoubleVolatile(Object, long, double)} */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2262
    @HotSpotIntrinsicCandidate
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2263
    public final void putDoubleOpaque(Object o, long offset, double x) {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2264
        putDoubleVolatile(o, offset, x);
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2265
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  2266
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2267
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2268
     * Unblocks the given thread blocked on {@code park}, or, if it is
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2269
     * not blocked, causes the subsequent call to {@code park} not to
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2270
     * block.  Note: this operation is "unsafe" solely because the
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2271
     * caller must somehow ensure that the thread has not been
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2272
     * destroyed. Nothing special is usually required to ensure this
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2273
     * when called from Java (in which there will ordinarily be a live
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2274
     * reference to the thread) but this is not nearly-automatically
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2275
     * so when calling from native code.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2276
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2277
     * @param thread the thread to unpark.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2278
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2279
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2280
    public native void unpark(Object thread);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2281
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2282
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2283
     * Blocks current thread, returning when a balancing
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2284
     * {@code unpark} occurs, or a balancing {@code unpark} has
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2285
     * already occurred, or the thread is interrupted, or, if not
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2286
     * absolute and time is not zero, the given time nanoseconds have
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2287
     * elapsed, or if absolute, the given deadline in milliseconds
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2288
     * since Epoch has passed, or spuriously (i.e., returning for no
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2289
     * "reason"). Note: This operation is in the Unsafe class only
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2290
     * because {@code unpark} is, so it would be strange to place it
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2291
     * elsewhere.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2292
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2293
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2294
    public native void park(boolean isAbsolute, long time);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2295
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2296
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2297
     * Gets the load average in the system run queue assigned
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2298
     * to the available processors averaged over various periods of time.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2299
     * This method retrieves the given {@code nelem} samples and
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2300
     * assigns to the elements of the given {@code loadavg} array.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2301
     * The system imposes a maximum of 3 samples, representing
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2302
     * averages over the last 1,  5,  and  15 minutes, respectively.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2303
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2304
     * @param loadavg an array of double of size nelems
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2305
     * @param nelems the number of samples to be retrieved and
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2306
     *        must be 1 to 3.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2307
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2308
     * @return the number of samples actually retrieved; or -1
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2309
     *         if the load average is unobtainable.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2310
     */
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  2311
    public int getLoadAverage(double[] loadavg, int nelems) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  2312
        if (nelems < 0 || nelems > 3 || nelems > loadavg.length) {
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  2313
            throw new ArrayIndexOutOfBoundsException();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  2314
        }
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  2315
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  2316
        return getLoadAverage0(loadavg, nelems);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  2317
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2318
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2319
    // The following contain CAS-based Java implementations used on
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2320
    // platforms not supporting native instructions
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2321
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2322
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2323
     * Atomically adds the given value to the current value of a field
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2324
     * or array element within the given object {@code o}
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2325
     * at the given {@code offset}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2326
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2327
     * @param o object/array to update the field/element in
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2328
     * @param offset field/element offset
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2329
     * @param delta the value to add
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2330
     * @return the previous value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2331
     * @since 1.8
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2332
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2333
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2334
    public final int getAndAddInt(Object o, long offset, int delta) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2335
        int v;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2336
        do {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2337
            v = getIntVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2338
        } while (!weakCompareAndSetInt(o, offset, v, v + delta));
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2339
        return v;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2340
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2341
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2342
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2343
    public final int getAndAddIntRelease(Object o, long offset, int delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2344
        int v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2345
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2346
            v = getInt(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2347
        } while (!weakCompareAndSetIntRelease(o, offset, v, v + delta));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2348
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2349
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2350
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2351
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2352
    public final int getAndAddIntAcquire(Object o, long offset, int delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2353
        int v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2354
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2355
            v = getIntAcquire(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2356
        } while (!weakCompareAndSetIntAcquire(o, offset, v, v + delta));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2357
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2358
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2359
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2360
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2361
     * Atomically adds the given value to the current value of a field
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2362
     * or array element within the given object {@code o}
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2363
     * at the given {@code offset}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2364
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2365
     * @param o object/array to update the field/element in
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2366
     * @param offset field/element offset
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2367
     * @param delta the value to add
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2368
     * @return the previous value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2369
     * @since 1.8
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2370
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2371
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2372
    public final long getAndAddLong(Object o, long offset, long delta) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2373
        long v;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2374
        do {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2375
            v = getLongVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2376
        } while (!weakCompareAndSetLong(o, offset, v, v + delta));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2377
        return v;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2378
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2379
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2380
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2381
    public final long getAndAddLongRelease(Object o, long offset, long delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2382
        long v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2383
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2384
            v = getLong(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2385
        } while (!weakCompareAndSetLongRelease(o, offset, v, v + delta));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2386
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2387
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2388
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2389
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2390
    public final long getAndAddLongAcquire(Object o, long offset, long delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2391
        long v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2392
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2393
            v = getLongAcquire(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2394
        } while (!weakCompareAndSetLongAcquire(o, offset, v, v + delta));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2395
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2396
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2397
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2398
    @HotSpotIntrinsicCandidate
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2399
    public final byte getAndAddByte(Object o, long offset, byte delta) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2400
        byte v;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2401
        do {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2402
            v = getByteVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2403
        } while (!weakCompareAndSetByte(o, offset, v, (byte) (v + delta)));
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2404
        return v;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2405
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2406
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2407
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2408
    public final byte getAndAddByteRelease(Object o, long offset, byte delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2409
        byte v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2410
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2411
            v = getByte(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2412
        } while (!weakCompareAndSetByteRelease(o, offset, v, (byte) (v + delta)));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2413
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2414
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2415
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2416
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2417
    public final byte getAndAddByteAcquire(Object o, long offset, byte delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2418
        byte v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2419
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2420
            v = getByteAcquire(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2421
        } while (!weakCompareAndSetByteAcquire(o, offset, v, (byte) (v + delta)));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2422
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2423
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2424
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2425
    @HotSpotIntrinsicCandidate
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2426
    public final short getAndAddShort(Object o, long offset, short delta) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2427
        short v;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2428
        do {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2429
            v = getShortVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2430
        } while (!weakCompareAndSetShort(o, offset, v, (short) (v + delta)));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2431
        return v;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2432
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2433
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2434
    @ForceInline
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2435
    public final short getAndAddShortRelease(Object o, long offset, short delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2436
        short v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2437
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2438
            v = getShort(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2439
        } while (!weakCompareAndSetShortRelease(o, offset, v, (short) (v + delta)));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2440
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2441
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2442
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2443
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2444
    public final short getAndAddShortAcquire(Object o, long offset, short delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2445
        short v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2446
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2447
            v = getShortAcquire(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2448
        } while (!weakCompareAndSetShortAcquire(o, offset, v, (short) (v + delta)));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2449
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2450
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2451
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2452
    @ForceInline
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2453
    public final char getAndAddChar(Object o, long offset, char delta) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2454
        return (char) getAndAddShort(o, offset, (short) delta);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2455
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2456
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2457
    @ForceInline
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2458
    public final char getAndAddCharRelease(Object o, long offset, char delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2459
        return (char) getAndAddShortRelease(o, offset, (short) delta);
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2460
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2461
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2462
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2463
    public final char getAndAddCharAcquire(Object o, long offset, char delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2464
        return (char) getAndAddShortAcquire(o, offset, (short) delta);
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2465
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2466
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2467
    @ForceInline
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2468
    public final float getAndAddFloat(Object o, long offset, float delta) {
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2469
        int expectedBits;
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2470
        float v;
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2471
        do {
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2472
            // Load and CAS with the raw bits to avoid issues with NaNs and
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2473
            // possible bit conversion from signaling NaNs to quiet NaNs that
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2474
            // may result in the loop not terminating.
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2475
            expectedBits = getIntVolatile(o, offset);
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2476
            v = Float.intBitsToFloat(expectedBits);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2477
        } while (!weakCompareAndSetInt(o, offset,
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2478
                                                expectedBits, Float.floatToRawIntBits(v + delta)));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2479
        return v;
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2480
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2481
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2482
    @ForceInline
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2483
    public final float getAndAddFloatRelease(Object o, long offset, float delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2484
        int expectedBits;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2485
        float v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2486
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2487
            // Load and CAS with the raw bits to avoid issues with NaNs and
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2488
            // possible bit conversion from signaling NaNs to quiet NaNs that
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2489
            // may result in the loop not terminating.
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2490
            expectedBits = getInt(o, offset);
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2491
            v = Float.intBitsToFloat(expectedBits);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2492
        } while (!weakCompareAndSetIntRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2493
                                               expectedBits, Float.floatToRawIntBits(v + delta)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2494
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2495
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2496
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2497
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2498
    public final float getAndAddFloatAcquire(Object o, long offset, float delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2499
        int expectedBits;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2500
        float v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2501
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2502
            // Load and CAS with the raw bits to avoid issues with NaNs and
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2503
            // possible bit conversion from signaling NaNs to quiet NaNs that
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2504
            // may result in the loop not terminating.
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2505
            expectedBits = getIntAcquire(o, offset);
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2506
            v = Float.intBitsToFloat(expectedBits);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2507
        } while (!weakCompareAndSetIntAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2508
                                               expectedBits, Float.floatToRawIntBits(v + delta)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2509
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2510
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2511
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2512
    @ForceInline
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2513
    public final double getAndAddDouble(Object o, long offset, double delta) {
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2514
        long expectedBits;
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2515
        double v;
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2516
        do {
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2517
            // Load and CAS with the raw bits to avoid issues with NaNs and
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2518
            // possible bit conversion from signaling NaNs to quiet NaNs that
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2519
            // may result in the loop not terminating.
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2520
            expectedBits = getLongVolatile(o, offset);
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2521
            v = Double.longBitsToDouble(expectedBits);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2522
        } while (!weakCompareAndSetLong(o, offset,
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2523
                                                 expectedBits, Double.doubleToRawLongBits(v + delta)));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2524
        return v;
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2525
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2526
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2527
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2528
    public final double getAndAddDoubleRelease(Object o, long offset, double delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2529
        long expectedBits;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2530
        double v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2531
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2532
            // Load and CAS with the raw bits to avoid issues with NaNs and
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2533
            // possible bit conversion from signaling NaNs to quiet NaNs that
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2534
            // may result in the loop not terminating.
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2535
            expectedBits = getLong(o, offset);
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2536
            v = Double.longBitsToDouble(expectedBits);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2537
        } while (!weakCompareAndSetLongRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2538
                                                expectedBits, Double.doubleToRawLongBits(v + delta)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2539
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2540
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2541
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2542
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2543
    public final double getAndAddDoubleAcquire(Object o, long offset, double delta) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2544
        long expectedBits;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2545
        double v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2546
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2547
            // Load and CAS with the raw bits to avoid issues with NaNs and
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2548
            // possible bit conversion from signaling NaNs to quiet NaNs that
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2549
            // may result in the loop not terminating.
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2550
            expectedBits = getLongAcquire(o, offset);
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2551
            v = Double.longBitsToDouble(expectedBits);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2552
        } while (!weakCompareAndSetLongAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2553
                                                expectedBits, Double.doubleToRawLongBits(v + delta)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2554
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2555
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2556
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2557
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2558
     * Atomically exchanges the given value with the current value of
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2559
     * a field or array element within the given object {@code o}
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2560
     * at the given {@code offset}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2561
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2562
     * @param o object/array to update the field/element in
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2563
     * @param offset field/element offset
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2564
     * @param newValue new value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2565
     * @return the previous value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2566
     * @since 1.8
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2567
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2568
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2569
    public final int getAndSetInt(Object o, long offset, int newValue) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2570
        int v;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2571
        do {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2572
            v = getIntVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2573
        } while (!weakCompareAndSetInt(o, offset, v, newValue));
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2574
        return v;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2575
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2576
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2577
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2578
    public final int getAndSetIntRelease(Object o, long offset, int newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2579
        int v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2580
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2581
            v = getInt(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2582
        } while (!weakCompareAndSetIntRelease(o, offset, v, newValue));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2583
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2584
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2585
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2586
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2587
    public final int getAndSetIntAcquire(Object o, long offset, int newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2588
        int v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2589
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2590
            v = getIntAcquire(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2591
        } while (!weakCompareAndSetIntAcquire(o, offset, v, newValue));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2592
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2593
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2594
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2595
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2596
     * Atomically exchanges the given value with the current value of
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2597
     * a field or array element within the given object {@code o}
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2598
     * at the given {@code offset}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2599
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2600
     * @param o object/array to update the field/element in
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2601
     * @param offset field/element offset
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2602
     * @param newValue new value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2603
     * @return the previous value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2604
     * @since 1.8
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2605
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2606
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2607
    public final long getAndSetLong(Object o, long offset, long newValue) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2608
        long v;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2609
        do {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2610
            v = getLongVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2611
        } while (!weakCompareAndSetLong(o, offset, v, newValue));
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2612
        return v;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2613
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2614
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2615
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2616
    public final long getAndSetLongRelease(Object o, long offset, long newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2617
        long v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2618
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2619
            v = getLong(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2620
        } while (!weakCompareAndSetLongRelease(o, offset, v, newValue));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2621
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2622
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2623
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2624
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2625
    public final long getAndSetLongAcquire(Object o, long offset, long newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2626
        long v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2627
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2628
            v = getLongAcquire(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2629
        } while (!weakCompareAndSetLongAcquire(o, offset, v, newValue));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2630
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2631
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2632
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2633
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2634
     * Atomically exchanges the given reference value with the current
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2635
     * reference value of a field or array element within the given
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2636
     * object {@code o} at the given {@code offset}.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2637
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2638
     * @param o object/array to update the field/element in
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2639
     * @param offset field/element offset
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2640
     * @param newValue new value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2641
     * @return the previous value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2642
     * @since 1.8
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2643
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2644
    @HotSpotIntrinsicCandidate
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2645
    public final Object getAndSetReference(Object o, long offset, Object newValue) {
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2646
        Object v;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2647
        do {
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2648
            v = getReferenceVolatile(o, offset);
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2649
        } while (!weakCompareAndSetReference(o, offset, v, newValue));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2650
        return v;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2651
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2652
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2653
    @ForceInline
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2654
    public final Object getAndSetReferenceRelease(Object o, long offset, Object newValue) {
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2655
        Object v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2656
        do {
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2657
            v = getReference(o, offset);
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2658
        } while (!weakCompareAndSetReferenceRelease(o, offset, v, newValue));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2659
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2660
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2661
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2662
    @ForceInline
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2663
    public final Object getAndSetReferenceAcquire(Object o, long offset, Object newValue) {
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2664
        Object v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2665
        do {
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2666
            v = getReferenceAcquire(o, offset);
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 47866
diff changeset
  2667
        } while (!weakCompareAndSetReferenceAcquire(o, offset, v, newValue));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2668
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2669
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2670
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2671
    @HotSpotIntrinsicCandidate
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2672
    public final byte getAndSetByte(Object o, long offset, byte newValue) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2673
        byte v;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2674
        do {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2675
            v = getByteVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2676
        } while (!weakCompareAndSetByte(o, offset, v, newValue));
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2677
        return v;
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2678
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2679
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2680
    @ForceInline
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2681
    public final byte getAndSetByteRelease(Object o, long offset, byte newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2682
        byte v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2683
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2684
            v = getByte(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2685
        } while (!weakCompareAndSetByteRelease(o, offset, v, newValue));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2686
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2687
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2688
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2689
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2690
    public final byte getAndSetByteAcquire(Object o, long offset, byte newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2691
        byte v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2692
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2693
            v = getByteAcquire(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2694
        } while (!weakCompareAndSetByteAcquire(o, offset, v, newValue));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2695
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2696
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2697
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2698
    @ForceInline
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2699
    public final boolean getAndSetBoolean(Object o, long offset, boolean newValue) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2700
        return byte2bool(getAndSetByte(o, offset, bool2byte(newValue)));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2701
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2702
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2703
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2704
    public final boolean getAndSetBooleanRelease(Object o, long offset, boolean newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2705
        return byte2bool(getAndSetByteRelease(o, offset, bool2byte(newValue)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2706
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2707
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2708
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2709
    public final boolean getAndSetBooleanAcquire(Object o, long offset, boolean newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2710
        return byte2bool(getAndSetByteAcquire(o, offset, bool2byte(newValue)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2711
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2712
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2713
    @HotSpotIntrinsicCandidate
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2714
    public final short getAndSetShort(Object o, long offset, short newValue) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2715
        short v;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2716
        do {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2717
            v = getShortVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2718
        } while (!weakCompareAndSetShort(o, offset, v, newValue));
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2719
        return v;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2720
    }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2721
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2722
    @ForceInline
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2723
    public final short getAndSetShortRelease(Object o, long offset, short newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2724
        short v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2725
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2726
            v = getShort(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2727
        } while (!weakCompareAndSetShortRelease(o, offset, v, newValue));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2728
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2729
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2730
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2731
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2732
    public final short getAndSetShortAcquire(Object o, long offset, short newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2733
        short v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2734
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2735
            v = getShortAcquire(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2736
        } while (!weakCompareAndSetShortAcquire(o, offset, v, newValue));
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2737
        return v;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2738
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2739
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2740
    @ForceInline
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2741
    public final char getAndSetChar(Object o, long offset, char newValue) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2742
        return s2c(getAndSetShort(o, offset, c2s(newValue)));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 39323
diff changeset
  2743
    }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  2744
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2745
    @ForceInline
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2746
    public final char getAndSetCharRelease(Object o, long offset, char newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2747
        return s2c(getAndSetShortRelease(o, offset, c2s(newValue)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2748
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2749
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2750
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2751
    public final char getAndSetCharAcquire(Object o, long offset, char newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2752
        return s2c(getAndSetShortAcquire(o, offset, c2s(newValue)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2753
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2754
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2755
    @ForceInline
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2756
    public final float getAndSetFloat(Object o, long offset, float newValue) {
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2757
        int v = getAndSetInt(o, offset, Float.floatToRawIntBits(newValue));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2758
        return Float.intBitsToFloat(v);
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2759
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2760
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2761
    @ForceInline
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2762
    public final float getAndSetFloatRelease(Object o, long offset, float newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2763
        int v = getAndSetIntRelease(o, offset, Float.floatToRawIntBits(newValue));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2764
        return Float.intBitsToFloat(v);
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2765
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2766
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2767
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2768
    public final float getAndSetFloatAcquire(Object o, long offset, float newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2769
        int v = getAndSetIntAcquire(o, offset, Float.floatToRawIntBits(newValue));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2770
        return Float.intBitsToFloat(v);
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2771
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2772
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2773
    @ForceInline
39471
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2774
    public final double getAndSetDouble(Object o, long offset, double newValue) {
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2775
        long v = getAndSetLong(o, offset, Double.doubleToRawLongBits(newValue));
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2776
        return Double.longBitsToDouble(v);
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2777
    }
6622892a347a 8158039: VarHandle float/double field/array access should support CAS/set/add atomics
psandoz
parents: 39470
diff changeset
  2778
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2779
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2780
    public final double getAndSetDoubleRelease(Object o, long offset, double newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2781
        long v = getAndSetLongRelease(o, offset, Double.doubleToRawLongBits(newValue));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2782
        return Double.longBitsToDouble(v);
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2783
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2784
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2785
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2786
    public final double getAndSetDoubleAcquire(Object o, long offset, double newValue) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2787
        long v = getAndSetLongAcquire(o, offset, Double.doubleToRawLongBits(newValue));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2788
        return Double.longBitsToDouble(v);
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2789
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2790
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2791
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2792
    // The following contain CAS-based Java implementations used on
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2793
    // platforms not supporting native instructions
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2794
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2795
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2796
    public final boolean getAndBitwiseOrBoolean(Object o, long offset, boolean mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2797
        return byte2bool(getAndBitwiseOrByte(o, offset, bool2byte(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2798
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2799
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2800
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2801
    public final boolean getAndBitwiseOrBooleanRelease(Object o, long offset, boolean mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2802
        return byte2bool(getAndBitwiseOrByteRelease(o, offset, bool2byte(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2803
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2804
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2805
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2806
    public final boolean getAndBitwiseOrBooleanAcquire(Object o, long offset, boolean mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2807
        return byte2bool(getAndBitwiseOrByteAcquire(o, offset, bool2byte(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2808
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2809
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2810
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2811
    public final boolean getAndBitwiseAndBoolean(Object o, long offset, boolean mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2812
        return byte2bool(getAndBitwiseAndByte(o, offset, bool2byte(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2813
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2814
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2815
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2816
    public final boolean getAndBitwiseAndBooleanRelease(Object o, long offset, boolean mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2817
        return byte2bool(getAndBitwiseAndByteRelease(o, offset, bool2byte(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2818
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2819
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2820
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2821
    public final boolean getAndBitwiseAndBooleanAcquire(Object o, long offset, boolean mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2822
        return byte2bool(getAndBitwiseAndByteAcquire(o, offset, bool2byte(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2823
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2824
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2825
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2826
    public final boolean getAndBitwiseXorBoolean(Object o, long offset, boolean mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2827
        return byte2bool(getAndBitwiseXorByte(o, offset, bool2byte(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2828
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2829
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2830
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2831
    public final boolean getAndBitwiseXorBooleanRelease(Object o, long offset, boolean mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2832
        return byte2bool(getAndBitwiseXorByteRelease(o, offset, bool2byte(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2833
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2834
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2835
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2836
    public final boolean getAndBitwiseXorBooleanAcquire(Object o, long offset, boolean mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2837
        return byte2bool(getAndBitwiseXorByteAcquire(o, offset, bool2byte(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2838
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2839
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2840
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2841
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2842
    public final byte getAndBitwiseOrByte(Object o, long offset, byte mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2843
        byte current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2844
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2845
            current = getByteVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2846
        } while (!weakCompareAndSetByte(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2847
                                                  current, (byte) (current | mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2848
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2849
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2850
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2851
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2852
    public final byte getAndBitwiseOrByteRelease(Object o, long offset, byte mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2853
        byte current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2854
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2855
            current = getByte(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2856
        } while (!weakCompareAndSetByteRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2857
                                                 current, (byte) (current | mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2858
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2859
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2860
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2861
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2862
    public final byte getAndBitwiseOrByteAcquire(Object o, long offset, byte mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2863
        byte current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2864
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2865
            // Plain read, the value is a hint, the acquire CAS does the work
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2866
            current = getByte(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2867
        } while (!weakCompareAndSetByteAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2868
                                                 current, (byte) (current | mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2869
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2870
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2871
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2872
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2873
    public final byte getAndBitwiseAndByte(Object o, long offset, byte mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2874
        byte current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2875
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2876
            current = getByteVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2877
        } while (!weakCompareAndSetByte(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2878
                                                  current, (byte) (current & mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2879
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2880
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2881
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2882
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2883
    public final byte getAndBitwiseAndByteRelease(Object o, long offset, byte mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2884
        byte current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2885
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2886
            current = getByte(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2887
        } while (!weakCompareAndSetByteRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2888
                                                 current, (byte) (current & mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2889
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2890
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2891
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2892
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2893
    public final byte getAndBitwiseAndByteAcquire(Object o, long offset, byte mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2894
        byte current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2895
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2896
            // Plain read, the value is a hint, the acquire CAS does the work
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2897
            current = getByte(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2898
        } while (!weakCompareAndSetByteAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2899
                                                 current, (byte) (current & mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2900
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2901
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2902
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2903
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2904
    public final byte getAndBitwiseXorByte(Object o, long offset, byte mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2905
        byte current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2906
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2907
            current = getByteVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2908
        } while (!weakCompareAndSetByte(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2909
                                                  current, (byte) (current ^ mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2910
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2911
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2912
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2913
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2914
    public final byte getAndBitwiseXorByteRelease(Object o, long offset, byte mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2915
        byte current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2916
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2917
            current = getByte(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2918
        } while (!weakCompareAndSetByteRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2919
                                                 current, (byte) (current ^ mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2920
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2921
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2922
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2923
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2924
    public final byte getAndBitwiseXorByteAcquire(Object o, long offset, byte mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2925
        byte current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2926
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2927
            // Plain read, the value is a hint, the acquire CAS does the work
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2928
            current = getByte(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2929
        } while (!weakCompareAndSetByteAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2930
                                                 current, (byte) (current ^ mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2931
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2932
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2933
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2934
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2935
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2936
    public final char getAndBitwiseOrChar(Object o, long offset, char mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2937
        return s2c(getAndBitwiseOrShort(o, offset, c2s(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2938
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2939
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2940
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2941
    public final char getAndBitwiseOrCharRelease(Object o, long offset, char mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2942
        return s2c(getAndBitwiseOrShortRelease(o, offset, c2s(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2943
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2944
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2945
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2946
    public final char getAndBitwiseOrCharAcquire(Object o, long offset, char mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2947
        return s2c(getAndBitwiseOrShortAcquire(o, offset, c2s(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2948
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2949
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2950
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2951
    public final char getAndBitwiseAndChar(Object o, long offset, char mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2952
        return s2c(getAndBitwiseAndShort(o, offset, c2s(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2953
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2954
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2955
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2956
    public final char getAndBitwiseAndCharRelease(Object o, long offset, char mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2957
        return s2c(getAndBitwiseAndShortRelease(o, offset, c2s(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2958
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2959
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2960
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2961
    public final char getAndBitwiseAndCharAcquire(Object o, long offset, char mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2962
        return s2c(getAndBitwiseAndShortAcquire(o, offset, c2s(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2963
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2964
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2965
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2966
    public final char getAndBitwiseXorChar(Object o, long offset, char mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2967
        return s2c(getAndBitwiseXorShort(o, offset, c2s(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2968
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2969
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2970
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2971
    public final char getAndBitwiseXorCharRelease(Object o, long offset, char mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2972
        return s2c(getAndBitwiseXorShortRelease(o, offset, c2s(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2973
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2974
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2975
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2976
    public final char getAndBitwiseXorCharAcquire(Object o, long offset, char mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2977
        return s2c(getAndBitwiseXorShortAcquire(o, offset, c2s(mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2978
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2979
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2980
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2981
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2982
    public final short getAndBitwiseOrShort(Object o, long offset, short mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2983
        short current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2984
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2985
            current = getShortVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2986
        } while (!weakCompareAndSetShort(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2987
                                                current, (short) (current | mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2988
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2989
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2990
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2991
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2992
    public final short getAndBitwiseOrShortRelease(Object o, long offset, short mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2993
        short current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2994
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2995
            current = getShort(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  2996
        } while (!weakCompareAndSetShortRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2997
                                               current, (short) (current | mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2998
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  2999
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3000
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3001
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3002
    public final short getAndBitwiseOrShortAcquire(Object o, long offset, short mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3003
        short current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3004
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3005
            // Plain read, the value is a hint, the acquire CAS does the work
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3006
            current = getShort(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3007
        } while (!weakCompareAndSetShortAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3008
                                               current, (short) (current | mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3009
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3010
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3011
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3012
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3013
    public final short getAndBitwiseAndShort(Object o, long offset, short mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3014
        short current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3015
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3016
            current = getShortVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3017
        } while (!weakCompareAndSetShort(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3018
                                                current, (short) (current & mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3019
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3020
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3021
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3022
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3023
    public final short getAndBitwiseAndShortRelease(Object o, long offset, short mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3024
        short current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3025
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3026
            current = getShort(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3027
        } while (!weakCompareAndSetShortRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3028
                                               current, (short) (current & mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3029
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3030
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3031
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3032
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3033
    public final short getAndBitwiseAndShortAcquire(Object o, long offset, short mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3034
        short current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3035
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3036
            // Plain read, the value is a hint, the acquire CAS does the work
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3037
            current = getShort(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3038
        } while (!weakCompareAndSetShortAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3039
                                               current, (short) (current & mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3040
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3041
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3042
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3043
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3044
    public final short getAndBitwiseXorShort(Object o, long offset, short mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3045
        short current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3046
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3047
            current = getShortVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3048
        } while (!weakCompareAndSetShort(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3049
                                                current, (short) (current ^ mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3050
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3051
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3052
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3053
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3054
    public final short getAndBitwiseXorShortRelease(Object o, long offset, short mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3055
        short current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3056
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3057
            current = getShort(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3058
        } while (!weakCompareAndSetShortRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3059
                                               current, (short) (current ^ mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3060
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3061
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3062
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3063
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3064
    public final short getAndBitwiseXorShortAcquire(Object o, long offset, short mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3065
        short current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3066
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3067
            // Plain read, the value is a hint, the acquire CAS does the work
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3068
            current = getShort(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3069
        } while (!weakCompareAndSetShortAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3070
                                               current, (short) (current ^ mask)));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3071
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3072
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3073
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3074
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3075
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3076
    public final int getAndBitwiseOrInt(Object o, long offset, int mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3077
        int current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3078
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3079
            current = getIntVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3080
        } while (!weakCompareAndSetInt(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3081
                                                current, current | mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3082
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3083
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3084
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3085
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3086
    public final int getAndBitwiseOrIntRelease(Object o, long offset, int mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3087
        int current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3088
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3089
            current = getInt(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3090
        } while (!weakCompareAndSetIntRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3091
                                               current, current | mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3092
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3093
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3094
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3095
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3096
    public final int getAndBitwiseOrIntAcquire(Object o, long offset, int mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3097
        int current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3098
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3099
            // Plain read, the value is a hint, the acquire CAS does the work
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3100
            current = getInt(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3101
        } while (!weakCompareAndSetIntAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3102
                                               current, current | mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3103
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3104
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3105
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3106
    /**
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3107
     * Atomically replaces the current value of a field or array element within
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3108
     * the given object with the result of bitwise AND between the current value
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3109
     * and mask.
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3110
     *
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3111
     * @param o object/array to update the field/element in
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3112
     * @param offset field/element offset
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3113
     * @param mask the mask value
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3114
     * @return the previous value
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3115
     * @since 1.9
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3116
     */
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3117
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3118
    public final int getAndBitwiseAndInt(Object o, long offset, int mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3119
        int current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3120
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3121
            current = getIntVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3122
        } while (!weakCompareAndSetInt(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3123
                                                current, current & mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3124
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3125
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3126
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3127
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3128
    public final int getAndBitwiseAndIntRelease(Object o, long offset, int mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3129
        int current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3130
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3131
            current = getInt(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3132
        } while (!weakCompareAndSetIntRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3133
                                               current, current & mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3134
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3135
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3136
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3137
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3138
    public final int getAndBitwiseAndIntAcquire(Object o, long offset, int mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3139
        int current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3140
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3141
            // Plain read, the value is a hint, the acquire CAS does the work
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3142
            current = getInt(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3143
        } while (!weakCompareAndSetIntAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3144
                                               current, current & mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3145
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3146
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3147
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3148
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3149
    public final int getAndBitwiseXorInt(Object o, long offset, int mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3150
        int current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3151
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3152
            current = getIntVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3153
        } while (!weakCompareAndSetInt(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3154
                                                current, current ^ mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3155
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3156
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3157
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3158
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3159
    public final int getAndBitwiseXorIntRelease(Object o, long offset, int mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3160
        int current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3161
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3162
            current = getInt(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3163
        } while (!weakCompareAndSetIntRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3164
                                               current, current ^ mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3165
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3166
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3167
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3168
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3169
    public final int getAndBitwiseXorIntAcquire(Object o, long offset, int mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3170
        int current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3171
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3172
            // Plain read, the value is a hint, the acquire CAS does the work
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3173
            current = getInt(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3174
        } while (!weakCompareAndSetIntAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3175
                                               current, current ^ mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3176
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3177
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3178
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3179
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3180
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3181
    public final long getAndBitwiseOrLong(Object o, long offset, long mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3182
        long current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3183
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3184
            current = getLongVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3185
        } while (!weakCompareAndSetLong(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3186
                                                current, current | mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3187
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3188
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3189
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3190
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3191
    public final long getAndBitwiseOrLongRelease(Object o, long offset, long mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3192
        long current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3193
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3194
            current = getLong(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3195
        } while (!weakCompareAndSetLongRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3196
                                               current, current | mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3197
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3198
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3199
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3200
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3201
    public final long getAndBitwiseOrLongAcquire(Object o, long offset, long mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3202
        long current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3203
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3204
            // Plain read, the value is a hint, the acquire CAS does the work
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3205
            current = getLong(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3206
        } while (!weakCompareAndSetLongAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3207
                                               current, current | mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3208
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3209
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3210
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3211
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3212
    public final long getAndBitwiseAndLong(Object o, long offset, long mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3213
        long current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3214
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3215
            current = getLongVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3216
        } while (!weakCompareAndSetLong(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3217
                                                current, current & mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3218
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3219
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3220
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3221
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3222
    public final long getAndBitwiseAndLongRelease(Object o, long offset, long mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3223
        long current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3224
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3225
            current = getLong(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3226
        } while (!weakCompareAndSetLongRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3227
                                               current, current & mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3228
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3229
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3230
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3231
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3232
    public final long getAndBitwiseAndLongAcquire(Object o, long offset, long mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3233
        long current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3234
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3235
            // Plain read, the value is a hint, the acquire CAS does the work
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3236
            current = getLong(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3237
        } while (!weakCompareAndSetLongAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3238
                                               current, current & mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3239
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3240
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3241
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3242
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3243
    public final long getAndBitwiseXorLong(Object o, long offset, long mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3244
        long current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3245
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3246
            current = getLongVolatile(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3247
        } while (!weakCompareAndSetLong(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3248
                                                current, current ^ mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3249
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3250
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3251
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3252
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3253
    public final long getAndBitwiseXorLongRelease(Object o, long offset, long mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3254
        long current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3255
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3256
            current = getLong(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3257
        } while (!weakCompareAndSetLongRelease(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3258
                                               current, current ^ mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3259
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3260
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3261
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3262
    @ForceInline
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3263
    public final long getAndBitwiseXorLongAcquire(Object o, long offset, long mask) {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3264
        long current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3265
        do {
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3266
            // Plain read, the value is a hint, the acquire CAS does the work
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3267
            current = getLong(o, offset);
45518
4a116dd82fb5 8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents: 41115
diff changeset
  3268
        } while (!weakCompareAndSetLongAcquire(o, offset,
40732
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3269
                                               current, current ^ mask));
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3270
        return current;
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3271
    }
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3272
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3273
2fd9cf42bb3c 8161444: VarHandles should provide access bitwise atomics
psandoz
parents: 39745
diff changeset
  3274
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3275
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3276
     * Ensures that loads before the fence will not be reordered with loads and
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3277
     * stores after the fence; a "LoadLoad plus LoadStore barrier".
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3278
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3279
     * Corresponds to C11 atomic_thread_fence(memory_order_acquire)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3280
     * (an "acquire fence").
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3281
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3282
     * A pure LoadLoad fence is not provided, since the addition of LoadStore
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3283
     * is almost always desired, and most current hardware instructions that
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3284
     * provide a LoadLoad barrier also provide a LoadStore barrier for free.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3285
     * @since 1.8
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3286
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3287
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3288
    public native void loadFence();
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3289
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3290
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3291
     * Ensures that loads and stores before the fence will not be reordered with
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3292
     * stores after the fence; a "StoreStore plus LoadStore barrier".
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3293
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3294
     * Corresponds to C11 atomic_thread_fence(memory_order_release)
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3295
     * (a "release fence").
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3296
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3297
     * A pure StoreStore fence is not provided, since the addition of LoadStore
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3298
     * is almost always desired, and most current hardware instructions that
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3299
     * provide a StoreStore barrier also provide a LoadStore barrier for free.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3300
     * @since 1.8
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3301
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3302
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3303
    public native void storeFence();
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3304
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3305
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3306
     * Ensures that loads and stores before the fence will not be reordered
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3307
     * with loads and stores after the fence.  Implies the effects of both
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3308
     * loadFence() and storeFence(), and in addition, the effect of a StoreLoad
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3309
     * barrier.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3310
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3311
     * Corresponds to C11 atomic_thread_fence(memory_order_seq_cst).
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3312
     * @since 1.8
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3313
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3314
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3315
    public native void fullFence();
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3316
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3317
    /**
36414
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3318
     * Ensures that loads before the fence will not be reordered with
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3319
     * loads after the fence.
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3320
     */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3321
    public final void loadLoadFence() {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3322
        loadFence();
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3323
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3324
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3325
    /**
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3326
     * Ensures that stores before the fence will not be reordered with
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3327
     * stores after the fence.
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3328
     */
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3329
    public final void storeStoreFence() {
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3330
        storeFence();
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3331
    }
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3332
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3333
c0e3caef7d78 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36125
diff changeset
  3334
    /**
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3335
     * Throws IllegalAccessError; for use by the VM for access control
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3336
     * error support.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3337
     * @since 1.8
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3338
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3339
    private static void throwIllegalAccessError() {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3340
        throw new IllegalAccessError();
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3341
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3342
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3343
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3344
     * @return Returns true if the native byte ordering of this
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3345
     * platform is big-endian, false if it is little-endian.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3346
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3347
    public final boolean isBigEndian() { return BE; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3348
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3349
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3350
     * @return Returns true if this platform is capable of performing
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3351
     * accesses at addresses which are not aligned for the type of the
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3352
     * primitive type being accessed, false otherwise.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3353
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3354
    public final boolean unalignedAccess() { return unalignedAccess; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3355
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3356
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3357
     * Fetches a value at some byte offset into a given Java object.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3358
     * More specifically, fetches a value within the given object
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3359
     * <code>o</code> at the given offset, or (if <code>o</code> is
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3360
     * null) from the memory address whose numerical value is the
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3361
     * given offset.  <p>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3362
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3363
     * The specification of this method is the same as {@link
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3364
     * #getLong(Object, long)} except that the offset does not need to
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3365
     * have been obtained from {@link #objectFieldOffset} on the
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3366
     * {@link java.lang.reflect.Field} of some Java field.  The value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3367
     * in memory is raw data, and need not correspond to any Java
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3368
     * variable.  Unless <code>o</code> is null, the value accessed
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3369
     * must be entirely within the allocated object.  The endianness
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3370
     * of the value in memory is the endianness of the native platform.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3371
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3372
     * <p> The read will be atomic with respect to the largest power
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3373
     * of two that divides the GCD of the offset and the storage size.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3374
     * For example, getLongUnaligned will make atomic reads of 2-, 4-,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3375
     * or 8-byte storage units if the offset is zero mod 2, 4, or 8,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3376
     * respectively.  There are no other guarantees of atomicity.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3377
     * <p>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3378
     * 8-byte atomicity is only guaranteed on platforms on which
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3379
     * support atomic accesses to longs.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3380
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3381
     * @param o Java heap object in which the value resides, if any, else
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3382
     *        null
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3383
     * @param offset The offset in bytes from the start of the object
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3384
     * @return the value fetched from the indicated object
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3385
     * @throws RuntimeException No defined exceptions are thrown, not even
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3386
     *         {@link NullPointerException}
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 34882
diff changeset
  3387
     * @since 9
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3388
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3389
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3390
    public final long getLongUnaligned(Object o, long offset) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3391
        if ((offset & 7) == 0) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3392
            return getLong(o, offset);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3393
        } else if ((offset & 3) == 0) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3394
            return makeLong(getInt(o, offset),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3395
                            getInt(o, offset + 4));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3396
        } else if ((offset & 1) == 0) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3397
            return makeLong(getShort(o, offset),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3398
                            getShort(o, offset + 2),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3399
                            getShort(o, offset + 4),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3400
                            getShort(o, offset + 6));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3401
        } else {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3402
            return makeLong(getByte(o, offset),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3403
                            getByte(o, offset + 1),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3404
                            getByte(o, offset + 2),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3405
                            getByte(o, offset + 3),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3406
                            getByte(o, offset + 4),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3407
                            getByte(o, offset + 5),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3408
                            getByte(o, offset + 6),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3409
                            getByte(o, offset + 7));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3410
        }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3411
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3412
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3413
     * As {@link #getLongUnaligned(Object, long)} but with an
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3414
     * additional argument which specifies the endianness of the value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3415
     * as stored in memory.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3416
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3417
     * @param o Java heap object in which the variable resides
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3418
     * @param offset The offset in bytes from the start of the object
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3419
     * @param bigEndian The endianness of the value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3420
     * @return the value fetched from the indicated object
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 34882
diff changeset
  3421
     * @since 9
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3422
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3423
    public final long getLongUnaligned(Object o, long offset, boolean bigEndian) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3424
        return convEndian(bigEndian, getLongUnaligned(o, offset));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3425
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3426
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3427
    /** @see #getLongUnaligned(Object, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3428
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3429
    public final int getIntUnaligned(Object o, long offset) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3430
        if ((offset & 3) == 0) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3431
            return getInt(o, offset);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3432
        } else if ((offset & 1) == 0) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3433
            return makeInt(getShort(o, offset),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3434
                           getShort(o, offset + 2));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3435
        } else {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3436
            return makeInt(getByte(o, offset),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3437
                           getByte(o, offset + 1),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3438
                           getByte(o, offset + 2),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3439
                           getByte(o, offset + 3));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3440
        }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3441
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3442
    /** @see #getLongUnaligned(Object, long, boolean) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3443
    public final int getIntUnaligned(Object o, long offset, boolean bigEndian) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3444
        return convEndian(bigEndian, getIntUnaligned(o, offset));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3445
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3446
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3447
    /** @see #getLongUnaligned(Object, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3448
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3449
    public final short getShortUnaligned(Object o, long offset) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3450
        if ((offset & 1) == 0) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3451
            return getShort(o, offset);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3452
        } else {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3453
            return makeShort(getByte(o, offset),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3454
                             getByte(o, offset + 1));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3455
        }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3456
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3457
    /** @see #getLongUnaligned(Object, long, boolean) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3458
    public final short getShortUnaligned(Object o, long offset, boolean bigEndian) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3459
        return convEndian(bigEndian, getShortUnaligned(o, offset));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3460
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3461
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3462
    /** @see #getLongUnaligned(Object, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3463
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3464
    public final char getCharUnaligned(Object o, long offset) {
36121
ba46027ccfb5 8148518: Unsafe.getCharUnaligned() loads aren't folded in case of -XX:-UseUnalignedAccesses
vlivanov
parents: 35302
diff changeset
  3465
        if ((offset & 1) == 0) {
ba46027ccfb5 8148518: Unsafe.getCharUnaligned() loads aren't folded in case of -XX:-UseUnalignedAccesses
vlivanov
parents: 35302
diff changeset
  3466
            return getChar(o, offset);
ba46027ccfb5 8148518: Unsafe.getCharUnaligned() loads aren't folded in case of -XX:-UseUnalignedAccesses
vlivanov
parents: 35302
diff changeset
  3467
        } else {
ba46027ccfb5 8148518: Unsafe.getCharUnaligned() loads aren't folded in case of -XX:-UseUnalignedAccesses
vlivanov
parents: 35302
diff changeset
  3468
            return (char)makeShort(getByte(o, offset),
ba46027ccfb5 8148518: Unsafe.getCharUnaligned() loads aren't folded in case of -XX:-UseUnalignedAccesses
vlivanov
parents: 35302
diff changeset
  3469
                                   getByte(o, offset + 1));
ba46027ccfb5 8148518: Unsafe.getCharUnaligned() loads aren't folded in case of -XX:-UseUnalignedAccesses
vlivanov
parents: 35302
diff changeset
  3470
        }
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3471
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3472
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3473
    /** @see #getLongUnaligned(Object, long, boolean) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3474
    public final char getCharUnaligned(Object o, long offset, boolean bigEndian) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3475
        return convEndian(bigEndian, getCharUnaligned(o, offset));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3476
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3477
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3478
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3479
     * Stores a value at some byte offset into a given Java object.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3480
     * <p>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3481
     * The specification of this method is the same as {@link
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3482
     * #getLong(Object, long)} except that the offset does not need to
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3483
     * have been obtained from {@link #objectFieldOffset} on the
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3484
     * {@link java.lang.reflect.Field} of some Java field.  The value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3485
     * in memory is raw data, and need not correspond to any Java
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3486
     * variable.  The endianness of the value in memory is the
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3487
     * endianness of the native platform.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3488
     * <p>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3489
     * The write will be atomic with respect to the largest power of
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3490
     * two that divides the GCD of the offset and the storage size.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3491
     * For example, putLongUnaligned will make atomic writes of 2-, 4-,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3492
     * or 8-byte storage units if the offset is zero mod 2, 4, or 8,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3493
     * respectively.  There are no other guarantees of atomicity.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3494
     * <p>
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3495
     * 8-byte atomicity is only guaranteed on platforms on which
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3496
     * support atomic accesses to longs.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3497
     *
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3498
     * @param o Java heap object in which the value resides, if any, else
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3499
     *        null
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3500
     * @param offset The offset in bytes from the start of the object
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3501
     * @param x the value to store
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3502
     * @throws RuntimeException No defined exceptions are thrown, not even
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3503
     *         {@link NullPointerException}
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 34882
diff changeset
  3504
     * @since 9
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3505
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3506
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3507
    public final void putLongUnaligned(Object o, long offset, long x) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3508
        if ((offset & 7) == 0) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3509
            putLong(o, offset, x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3510
        } else if ((offset & 3) == 0) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3511
            putLongParts(o, offset,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3512
                         (int)(x >> 0),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3513
                         (int)(x >>> 32));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3514
        } else if ((offset & 1) == 0) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3515
            putLongParts(o, offset,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3516
                         (short)(x >>> 0),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3517
                         (short)(x >>> 16),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3518
                         (short)(x >>> 32),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3519
                         (short)(x >>> 48));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3520
        } else {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3521
            putLongParts(o, offset,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3522
                         (byte)(x >>> 0),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3523
                         (byte)(x >>> 8),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3524
                         (byte)(x >>> 16),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3525
                         (byte)(x >>> 24),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3526
                         (byte)(x >>> 32),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3527
                         (byte)(x >>> 40),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3528
                         (byte)(x >>> 48),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3529
                         (byte)(x >>> 56));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3530
        }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3531
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3532
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3533
    /**
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3534
     * As {@link #putLongUnaligned(Object, long, long)} but with an additional
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3535
     * argument which specifies the endianness of the value as stored in memory.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3536
     * @param o Java heap object in which the value resides
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3537
     * @param offset The offset in bytes from the start of the object
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3538
     * @param x the value to store
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3539
     * @param bigEndian The endianness of the value
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3540
     * @throws RuntimeException No defined exceptions are thrown, not even
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3541
     *         {@link NullPointerException}
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 34882
diff changeset
  3542
     * @since 9
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3543
     */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3544
    public final void putLongUnaligned(Object o, long offset, long x, boolean bigEndian) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3545
        putLongUnaligned(o, offset, convEndian(bigEndian, x));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3546
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3547
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3548
    /** @see #putLongUnaligned(Object, long, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3549
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3550
    public final void putIntUnaligned(Object o, long offset, int x) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3551
        if ((offset & 3) == 0) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3552
            putInt(o, offset, x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3553
        } else if ((offset & 1) == 0) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3554
            putIntParts(o, offset,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3555
                        (short)(x >> 0),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3556
                        (short)(x >>> 16));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3557
        } else {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3558
            putIntParts(o, offset,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3559
                        (byte)(x >>> 0),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3560
                        (byte)(x >>> 8),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3561
                        (byte)(x >>> 16),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3562
                        (byte)(x >>> 24));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3563
        }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3564
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3565
    /** @see #putLongUnaligned(Object, long, long, boolean) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3566
    public final void putIntUnaligned(Object o, long offset, int x, boolean bigEndian) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3567
        putIntUnaligned(o, offset, convEndian(bigEndian, x));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3568
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3569
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3570
    /** @see #putLongUnaligned(Object, long, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3571
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3572
    public final void putShortUnaligned(Object o, long offset, short x) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3573
        if ((offset & 1) == 0) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3574
            putShort(o, offset, x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3575
        } else {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3576
            putShortParts(o, offset,
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3577
                          (byte)(x >>> 0),
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3578
                          (byte)(x >>> 8));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3579
        }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3580
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3581
    /** @see #putLongUnaligned(Object, long, long, boolean) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3582
    public final void putShortUnaligned(Object o, long offset, short x, boolean bigEndian) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3583
        putShortUnaligned(o, offset, convEndian(bigEndian, x));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3584
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3585
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3586
    /** @see #putLongUnaligned(Object, long, long) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3587
    @HotSpotIntrinsicCandidate
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3588
    public final void putCharUnaligned(Object o, long offset, char x) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3589
        putShortUnaligned(o, offset, (short)x);
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3590
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3591
    /** @see #putLongUnaligned(Object, long, long, boolean) */
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3592
    public final void putCharUnaligned(Object o, long offset, char x, boolean bigEndian) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3593
        putCharUnaligned(o, offset, convEndian(bigEndian, x));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3594
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3595
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3596
    // JVM interface methods
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3597
    // BE is true iff the native endianness of this platform is big.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3598
    private static final boolean BE = theUnsafe.isBigEndian0();
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3599
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3600
    // unalignedAccess is true iff this platform can perform unaligned accesses.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3601
    private static final boolean unalignedAccess = theUnsafe.unalignedAccess0();
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3602
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3603
    private static int pickPos(int top, int pos) { return BE ? top - pos : pos; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3604
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3605
    // These methods construct integers from bytes.  The byte ordering
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3606
    // is the native endianness of this platform.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3607
    private static long makeLong(byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3608
        return ((toUnsignedLong(i0) << pickPos(56, 0))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3609
              | (toUnsignedLong(i1) << pickPos(56, 8))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3610
              | (toUnsignedLong(i2) << pickPos(56, 16))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3611
              | (toUnsignedLong(i3) << pickPos(56, 24))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3612
              | (toUnsignedLong(i4) << pickPos(56, 32))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3613
              | (toUnsignedLong(i5) << pickPos(56, 40))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3614
              | (toUnsignedLong(i6) << pickPos(56, 48))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3615
              | (toUnsignedLong(i7) << pickPos(56, 56)));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3616
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3617
    private static long makeLong(short i0, short i1, short i2, short i3) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3618
        return ((toUnsignedLong(i0) << pickPos(48, 0))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3619
              | (toUnsignedLong(i1) << pickPos(48, 16))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3620
              | (toUnsignedLong(i2) << pickPos(48, 32))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3621
              | (toUnsignedLong(i3) << pickPos(48, 48)));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3622
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3623
    private static long makeLong(int i0, int i1) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3624
        return (toUnsignedLong(i0) << pickPos(32, 0))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3625
             | (toUnsignedLong(i1) << pickPos(32, 32));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3626
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3627
    private static int makeInt(short i0, short i1) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3628
        return (toUnsignedInt(i0) << pickPos(16, 0))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3629
             | (toUnsignedInt(i1) << pickPos(16, 16));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3630
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3631
    private static int makeInt(byte i0, byte i1, byte i2, byte i3) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3632
        return ((toUnsignedInt(i0) << pickPos(24, 0))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3633
              | (toUnsignedInt(i1) << pickPos(24, 8))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3634
              | (toUnsignedInt(i2) << pickPos(24, 16))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3635
              | (toUnsignedInt(i3) << pickPos(24, 24)));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3636
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3637
    private static short makeShort(byte i0, byte i1) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3638
        return (short)((toUnsignedInt(i0) << pickPos(8, 0))
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3639
                     | (toUnsignedInt(i1) << pickPos(8, 8)));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3640
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3641
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3642
    private static byte  pick(byte  le, byte  be) { return BE ? be : le; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3643
    private static short pick(short le, short be) { return BE ? be : le; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3644
    private static int   pick(int   le, int   be) { return BE ? be : le; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3645
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3646
    // These methods write integers to memory from smaller parts
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3647
    // provided by their caller.  The ordering in which these parts
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3648
    // are written is the native endianness of this platform.
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3649
    private void putLongParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3650
        putByte(o, offset + 0, pick(i0, i7));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3651
        putByte(o, offset + 1, pick(i1, i6));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3652
        putByte(o, offset + 2, pick(i2, i5));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3653
        putByte(o, offset + 3, pick(i3, i4));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3654
        putByte(o, offset + 4, pick(i4, i3));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3655
        putByte(o, offset + 5, pick(i5, i2));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3656
        putByte(o, offset + 6, pick(i6, i1));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3657
        putByte(o, offset + 7, pick(i7, i0));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3658
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3659
    private void putLongParts(Object o, long offset, short i0, short i1, short i2, short i3) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3660
        putShort(o, offset + 0, pick(i0, i3));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3661
        putShort(o, offset + 2, pick(i1, i2));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3662
        putShort(o, offset + 4, pick(i2, i1));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3663
        putShort(o, offset + 6, pick(i3, i0));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3664
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3665
    private void putLongParts(Object o, long offset, int i0, int i1) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3666
        putInt(o, offset + 0, pick(i0, i1));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3667
        putInt(o, offset + 4, pick(i1, i0));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3668
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3669
    private void putIntParts(Object o, long offset, short i0, short i1) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3670
        putShort(o, offset + 0, pick(i0, i1));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3671
        putShort(o, offset + 2, pick(i1, i0));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3672
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3673
    private void putIntParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3674
        putByte(o, offset + 0, pick(i0, i3));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3675
        putByte(o, offset + 1, pick(i1, i2));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3676
        putByte(o, offset + 2, pick(i2, i1));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3677
        putByte(o, offset + 3, pick(i3, i0));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3678
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3679
    private void putShortParts(Object o, long offset, byte i0, byte i1) {
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3680
        putByte(o, offset + 0, pick(i0, i1));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3681
        putByte(o, offset + 1, pick(i1, i0));
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3682
    }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3683
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3684
    // Zero-extend an integer
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3685
    private static int toUnsignedInt(byte n)    { return n & 0xff; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3686
    private static int toUnsignedInt(short n)   { return n & 0xffff; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3687
    private static long toUnsignedLong(byte n)  { return n & 0xffl; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3688
    private static long toUnsignedLong(short n) { return n & 0xffffl; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3689
    private static long toUnsignedLong(int n)   { return n & 0xffffffffl; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3690
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3691
    // Maybe byte-reverse an integer
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3692
    private static char convEndian(boolean big, char n)   { return big == BE ? n : Character.reverseBytes(n); }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3693
    private static short convEndian(boolean big, short n) { return big == BE ? n : Short.reverseBytes(n)    ; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3694
    private static int convEndian(boolean big, int n)     { return big == BE ? n : Integer.reverseBytes(n)  ; }
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3695
    private static long convEndian(boolean big, long n)   { return big == BE ? n : Long.reverseBytes(n)     ; }
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3696
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3697
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3698
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3699
    private native long allocateMemory0(long bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3700
    private native long reallocateMemory0(long address, long bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3701
    private native void freeMemory0(long address);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3702
    private native void setMemory0(Object o, long offset, long bytes, byte value);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3703
    @HotSpotIntrinsicCandidate
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3704
    private native void copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3705
    private native void copySwapMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3706
    private native long objectFieldOffset0(Field f);
46873
7ac2f551b0d6 8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents: 45518
diff changeset
  3707
    private native long objectFieldOffset1(Class<?> c, String name);
36628
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3708
    private native long staticFieldOffset0(Field f);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3709
    private native Object staticFieldBase0(Field f);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3710
    private native boolean shouldBeInitialized0(Class<?> c);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3711
    private native void ensureClassInitialized0(Class<?> c);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3712
    private native int arrayBaseOffset0(Class<?> arrayClass);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3713
    private native int arrayIndexScale0(Class<?> arrayClass);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3714
    private native int addressSize0();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3715
    private native Class<?> defineAnonymousClass0(Class<?> hostClass, byte[] data, Object[] cpPatches);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3716
    private native int getLoadAverage0(double[] loadavg, int nelems);
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3717
    private native boolean unalignedAccess0();
2cb0af1c4351 8149159: Clean up Unsafe
mikael
parents: 36414
diff changeset
  3718
    private native boolean isBigEndian0();
33656
ef901bc43f7a 8139891: Prepare Unsafe for true encapsulation
chegar
parents:
diff changeset
  3719
}