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